Prove2Me
Navigate
DiscoverFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

The zzz-iteration L⋆zL^{\star z}L⋆z

Definition
MSKleene_Iteration

by Cosme · Sep 8, 2026 · Mathlib 0df444a (Lean v4.33.1)

formal-languagesmany-sorted-algebratree-automatauniversal-algebra

The zzz-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

L0 z={z},L(i+1) z=Li z∪⟨z/Li z⟩s♯p(L),L^{0\,z} = \{z\}, \qquad L^{(i+1)\,z} = L^{i\,z} \cup \langle z/L^{i\,z}\rangle^{\sharp\mathsf{p}}_s(L),L0z={z},L(i+1)z=Liz∪⟨z/Liz⟩s♯p​(L),

and iterate z L is L⋆z=⋃i∈NLi zL^{\star z} = \bigcup_{i \in \mathbb{N}} L^{i\,z}L⋆z=⋃i∈N​Liz. 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 L⋆zL^{\star z}L⋆z.

The simp lemmas iterStage_zero and iterStage_succ expose the recursion.

Definition code
/-
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
Source
Gong, Ruiz Mora, Sanmartín Vich, Cosme Llópez, "A Kleene theorem for free many-sorted algebras", 2026, https://arxiv.org/abs/1808.08217 (predecessor CVCL20)
Read-back

What the Lean code literally says, in plain math · claude-sonnet-5

iterStage (noncomputable definition)

Fix a universe uuu, a type SSS of sorts, an implicit signature Σ\SigmaΣ over SSS (which assigns to each finite list of sorts www and each sort sss a type Σw,s\Sigma_{w,s}Σw,s​ of operation symbols), and an implicit SSS-indexed family of variable sets XXX, with XsX_sXs​ the variables of sort sss. Let TsT_sTs​ denote the type of Σ\SigmaΣ-terms of sort sss over XXX: each x∈Xsx \in X_sx∈Xs​ gives a term var(x)∈Ts\mathrm{var}(x) \in T_svar(x)∈Ts​, and each operation symbol σ∈Σw,s\sigma \in \Sigma_{w,s}σ∈Σw,s​ applied to a matching tuple of subterms gives a term app(σ,… )∈Ts\mathrm{app}(\sigma,\dots) \in T_sapp(σ,…)∈Ts​.

For a sort sss, a variable z∈Xsz \in X_sz∈Xs​, and a set L⊆TsL \subseteq T_sL⊆Ts​ of terms of sort sss, iterStage defines a function iterStage(z,L,−):N→P(Ts)\mathrm{iterStage}(z,L,-) : \mathbb{N} \to \mathcal{P}(T_s)iterStage(z,L,−):N→P(Ts​) by recursion on the natural-number argument:

  • iterStage(z,L,0)={var(z)}\mathrm{iterStage}(z,L,0) = \{\mathrm{var}(z)\}iterStage(z,L,0)={var(z)}, the singleton set whose only element is the term consisting of the bare variable zzz;
  • iterStage(z,L,i+1)=iterStage(z,L,i) ∪ substP(z, iterStage(z,L,i), s, L)\mathrm{iterStage}(z,L,i+1) = \mathrm{iterStage}(z,L,i)\ \cup\ \mathrm{substP}\big(z,\ \mathrm{iterStage}(z,L,i),\ s,\ L\big)iterStage(z,L,i+1)=iterStage(z,L,i) ∪ substP(z, iterStage(z,L,i), s, L).

Here substP(z,M,s,K)\mathrm{substP}(z,M,s,K)substP(z,M,s,K), for M⊆TsM \subseteq T_sM⊆Ts​ and K⊆TsK \subseteq T_sK⊆Ts​, is

substP(z,M,s,K)  =  ⋃P∈KΦz,M(P),\mathrm{substP}(z,M,s,K) \;=\; \bigcup_{P \in K} \Phi_{z,M}(P),substP(z,M,s,K)=P∈K⋃​Φz,M​(P),

where Φz,M\Phi_{z,M}Φz,M​ is the "replace occurrences of zzz by members of MMM" operator: it is the homomorphic extension to terms of the assignment sending the variable zzz (of sort sss) to the set MMM and every other variable y∈Xty \in X_ty∈Xt​ to the singleton {var(y)}\{\mathrm{var}(y)\}{var(y)}, evaluated in the power algebra of the term algebra. Concretely: Φz,M(var(z))=M\Phi_{z,M}(\mathrm{var}(z)) = MΦz,M​(var(z))=M; Φz,M(var(y))={var(y)}\Phi_{z,M}(\mathrm{var}(y)) = \{\mathrm{var}(y)\}Φz,M​(var(y))={var(y)} whenever yyy is a different variable from zzz (or of a different sort); and

Φz,M(app(σ,(t1,…,tn)))={ app(σ,(u1,…,un))  ∣  uk∈Φz,M(tk) for each k },\Phi_{z,M}\big(\mathrm{app}(\sigma,(t_1,\dots,t_n))\big) = \big\{\, \mathrm{app}(\sigma,(u_1,\dots,u_n)) \;\big|\; u_k \in \Phi_{z,M}(t_k)\ \text{for each } k \,\big\},Φz,M​(app(σ,(t1​,…,tn​)))={app(σ,(u1​,…,un​))​uk​∈Φz,M​(tk​) for each k},

each argument position choosing its replacement independently.

Thus in the successor clause the set iterated over is LLL itself (the role of KKK), while the set spliced in for occurrences of zzz is the previously built stage iterStage(z,L,i)\mathrm{iterStage}(z,L,i)iterStage(z,L,i) (the role of MMM): stage i+1i+1i+1 is stage iii together with every term obtainable from some P∈LP \in LP∈L by replacing each occurrence of zzz in PPP with an independently chosen element of stage iii, all other variables left fixed. By construction each stage contains the previous one (the left summand of the union). Edge cases: if L=∅L = \emptysetL=∅ then the second summand is empty for every iii, so every stage equals {var(z)}\{\mathrm{var}(z)\}{var(z)}; if P∈LP \in LP∈L contains no occurrence of zzz, then Φz,M(P)={P}\Phi_{z,M}(P) = \{P\}Φz,M​(P)={P} for every MMM; if PPP contains at least one occurrence of zzz and M=∅M = \emptysetM=∅, then Φz,M(P)=∅\Phi_{z,M}(P) = \emptysetΦz,M​(P)=∅. The result set always consists of terms of the same sort sss as zzz. 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 (SSS, Σ\SigmaΣ, XXX, term types TsT_sTs​) as above, for a sort sss, a variable z∈Xsz \in X_sz∈Xs​, and a set L⊆TsL \subseteq T_sL⊆Ts​, iterate is defined as the countable union of all iteration stages:

iterate(z,L)  =  ⋃i∈NiterStage(z,L,i)  ⊆  Ts,\mathrm{iterate}(z,L) \;=\; \bigcup_{i \in \mathbb{N}} \mathrm{iterStage}(z,L,i) \;\subseteq\; T_s,iterate(z,L)=i∈N⋃​iterStage(z,L,i)⊆Ts​,

where iterStage(z,L,i)\mathrm{iterStage}(z,L,i)iterStage(z,L,i) is the family from iterStage: iterStage(z,L,0)={var(z)}\mathrm{iterStage}(z,L,0) = \{\mathrm{var}(z)\}iterStage(z,L,0)={var(z)} and iterStage(z,L,i+1)=iterStage(z,L,i)∪⋃P∈LΦz, iterStage(z,L,i)(P)\mathrm{iterStage}(z,L,i+1) = \mathrm{iterStage}(z,L,i) \cup \bigcup_{P \in L} \Phi_{z,\ \mathrm{iterStage}(z,L,i)}(P)iterStage(z,L,i+1)=iterStage(z,L,i)∪⋃P∈L​Φz, iterStage(z,L,i)​(P), with Φz,M(P)\Phi_{z,M}(P)Φz,M​(P) the set of all terms obtained from PPP by replacing every occurrence of the variable zzz with independently chosen elements of MMM and leaving all other variables unchanged. Since iii ranges over all of N\mathbb{N}N, including 000, the term var(z)\mathrm{var}(z)var(z) always belongs to iterate(z,L)\mathrm{iterate}(z,L)iterate(z,L); in particular if L=∅L = \emptysetL=∅ then iterate(z,L)={var(z)}\mathrm{iterate}(z,L) = \{\mathrm{var}(z)\}iterate(z,L)={var(z)}. The definition is marked noncomputable.

iterStage_zero (theorem, @[simp])

For every sort sss, every variable z∈Xsz \in X_sz∈Xs​, and every set L⊆TsL \subseteq T_sL⊆Ts​ of terms of sort sss (with SSS, Σ\SigmaΣ, XXX the ambient implicit data), the zeroth iteration stage equals the singleton containing the bare variable term:

iterStage(z,L,0)  =  {var(z)}.\mathrm{iterStage}(z,L,0) \;=\; \{\mathrm{var}(z)\}.iterStage(z,L,0)={var(z)}.

The equality is asserted to hold by definitional unfolding (its proof is rfl) and is registered as a simp lemma. The set LLL is universally quantified but does not occur on the right-hand side.

iterStage_succ (theorem)

For every sort sss, every variable z∈Xsz \in X_sz∈Xs​, every set L⊆TsL \subseteq T_sL⊆Ts​, and every natural number iii, the (i+1)(i+1)(i+1)-st iteration stage satisfies

iterStage(z,L,i+1)  =  iterStage(z,L,i) ∪ substP(z, iterStage(z,L,i), s, L),\mathrm{iterStage}(z,L,i+1) \;=\; \mathrm{iterStage}(z,L,i)\ \cup\ \mathrm{substP}\big(z,\ \mathrm{iterStage}(z,L,i),\ s,\ L\big),iterStage(z,L,i+1)=iterStage(z,L,i) ∪ substP(z, iterStage(z,L,i), s, L),

where substP(z,M,s,L)=⋃P∈LΦz,M(P)\mathrm{substP}(z,M,s,L) = \bigcup_{P \in L} \Phi_{z,M}(P)substP(z,M,s,L)=⋃P∈L​Φz,M​(P), Φz,M(P)\Phi_{z,M}(P)Φz,M​(P) is the set of all terms produced from PPP by replacing each occurrence of the variable zzz with an independently chosen element of MMM (all other variables untouched), and here M=iterStage(z,L,i)M = \mathrm{iterStage}(z,L,i)M=iterStage(z,L,i). Equivalently: stage i+1i+1i+1 is stage iii together with every result of substituting elements of stage iii for the occurrences of zzz in the terms of LLL. The equality is asserted to hold by definitional unfolding (proof rfl). It is quantified over all i∈Ni \in \mathbb{N}i∈N, including i=0i = 0i=0, in which case it reads iterStage(z,L,1)={var(z)}∪⋃P∈LΦz,{var(z)}(P)\mathrm{iterStage}(z,L,1) = \{\mathrm{var}(z)\} \cup \bigcup_{P \in L} \Phi_{z,\{\mathrm{var}(z)\}}(P)iterStage(z,L,1)={var(z)}∪⋃P∈L​Φz,{var(z)}​(P).

Human review
  • Endorsed by Shuze Chen · Sep 9, 2026

  • Endorsed by Cosme · Sep 9, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me