The -iteration
DefinitionMSKleene_IterationThe -iteration of a language (Definition 3.26; many-sorted counterpart of Gécseg–Steinby 1984, Definition 4.7).
For a sort s, a variable z ∈ X_s, and a language L ⊆ T_Σ(X)_s, the finite stages are
and iterate z L is . Intuitively, one starts from z and repeatedly substitutes, at every occurrence of z in a term of L, a term already known to lie in .
The simp lemmas iterStage_zero and iterStage_succ expose the recursion.
/-
The `z`-iteration of a language (Definition 3.26; many-sorted counterpart of
Gécseg–Steinby 1984, Definition 4.7).
For a sort `s`, a variable `z ∈ X_s`, and a language `L ⊆ T_Σ(X)_s`:
`L^{0 z} = {z}`, `L^{(i+1) z} = L^{i z} ∪ ⟨z/L^{i z}⟩^♯ᵖ_s (L)`,
`L^{⋆ z} = ⋃_{i ∈ ℕ} L^{i z}`.
New members of `L^{⋆z}` are obtained by substituting, at every occurrence of `z`
in some term of `L`, a term already known to be in `L^{⋆z}`.
-/
import Definitions.Def_MSKleene_Subst
namespace MSKleene
universe u
variable {S : Type u} {sig : Signature S} {X : SSet S}
/-- The finite stages `L^{i z}` of the `z`-iteration (Definition 3.26). -/
noncomputable def iterStage {s : S} (z : X s) (L : Set (Term sig X s)) :
ℕ → Set (Term sig X s)
| 0 => {Term.var z}
| i + 1 => iterStage z L i ∪ substP z (iterStage z L i) s L
/-- The `z`-iteration `L^{⋆ z} = ⋃_{i} L^{i z}` (Definition 3.26). -/
noncomputable def iterate {s : S} (z : X s) (L : Set (Term sig X s)) :
Set (Term sig X s) :=
⋃ i : ℕ, iterStage z L i
@[simp] theorem iterStage_zero {s : S} (z : X s) (L : Set (Term sig X s)) :
iterStage z L 0 = {Term.var z} := rfl
theorem iterStage_succ {s : S} (z : X s) (L : Set (Term sig X s)) (i : ℕ) :
iterStage z L (i + 1) = iterStage z L i ∪ substP z (iterStage z L i) s L := rfl
end MSKleene
Read-back
What the Lean code literally says, in plain math · claude-sonnet-5
iterStage (noncomputable definition)
Fix a universe , a type of sorts, an implicit signature over (which assigns to each finite list of sorts and each sort a type of operation symbols), and an implicit -indexed family of variable sets , with the variables of sort . Let denote the type of -terms of sort over : each gives a term , and each operation symbol applied to a matching tuple of subterms gives a term .
For a sort , a variable , and a set of terms of sort , iterStage defines a function by recursion on the natural-number argument:
- , the singleton set whose only element is the term consisting of the bare variable ;
- .
Here , for and , is
where is the "replace occurrences of by members of " operator: it is the homomorphic extension to terms of the assignment sending the variable (of sort ) to the set and every other variable to the singleton , evaluated in the power algebra of the term algebra. Concretely: ; whenever is a different variable from (or of a different sort); and
each argument position choosing its replacement independently.
Thus in the successor clause the set iterated over is itself (the role of ), while the set spliced in for occurrences of is the previously built stage (the role of ): stage is stage together with every term obtainable from some by replacing each occurrence of in with an independently chosen element of stage , all other variables left fixed. By construction each stage contains the previous one (the left summand of the union). Edge cases: if then the second summand is empty for every , so every stage equals ; if contains no occurrence of , then for every ; if contains at least one occurrence of and , then . The result set always consists of terms of the same sort as . The definition is marked noncomputable, and the underlying substitution assignment is built with classical logic for the sort- and variable-equality tests.
iterate (noncomputable definition)
With the same ambient data (, , , term types ) as above, for a sort , a variable , and a set , iterate is defined as the countable union of all iteration stages:
where is the family from iterStage: and , with the set of all terms obtained from by replacing every occurrence of the variable with independently chosen elements of and leaving all other variables unchanged. Since ranges over all of , including , the term always belongs to ; in particular if then . The definition is marked noncomputable.
iterStage_zero (theorem, @[simp])
For every sort , every variable , and every set of terms of sort (with , , the ambient implicit data), the zeroth iteration stage equals the singleton containing the bare variable term:
The equality is asserted to hold by definitional unfolding (its proof is rfl) and is registered as a simp lemma. The set is universally quantified but does not occur on the right-hand side.
iterStage_succ (theorem)
For every sort , every variable , every set , and every natural number , the -st iteration stage satisfies
where , is the set of all terms produced from by replacing each occurrence of the variable with an independently chosen element of (all other variables untouched), and here . Equivalently: stage is stage together with every result of substituting elements of stage for the occurrences of in the terms of . The equality is asserted to hold by definitional unfolding (proof rfl). It is quantified over all , including , in which case it reads .
Confirmed by the mission captain (proposal self-audit).