Prove2Me
Navigate
DiscoverFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

The zzz-substitution operators

Definition
MSKleene_Subst

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

formal-languagesmany-sorted-algebratree-automatauniversal-algebra

The zzz-substitution operators on languages of the free many-sorted algebra (Definition 3.20).

Given a sort v, a variable z ∈ X_v, and a language L ⊆ T_Σ(X)_v:

  1. substAssign z L is the SSS-sorted map ⟨z/L⟩:X→TΣ(X)℘\langle z/L\rangle : X \to \mathbf{T}_\Sigma(X)^{\wp}⟨z/L⟩:X→TΣ​(X)℘ sending z ↦ L and every other variable y ↦ {y};
  2. substHom z L is the induced homomorphism ⟨z/L⟩♯:TΣ(X)→TΣ(X)℘\langle z/L\rangle^{\sharp} : \mathbf{T}_\Sigma(X) \to \mathbf{T}_\Sigma(X)^{\wp}⟨z/L⟩♯:TΣ​(X)→TΣ​(X)℘;
  3. substP z L s K is its completely additive extension ⟨z/L⟩s♯p(K)=⋃P∈K⟨z/L⟩s♯(P)\langle z/L\rangle^{\sharp\mathsf{p}}_s(K) = \bigcup_{P \in K} \langle z/L\rangle^{\sharp}_s(P)⟨z/L⟩s♯p​(K)=⋃P∈K​⟨z/L⟩s♯​(P).

Formalization Note substAssign uses classical decidability for the sort- and variable-equality tests, so the definitions are noncomputable; this is immaterial to the mathematics.

Definition code
/-
The `z`-substitution operators on languages of the free many-sorted algebra
(Definition 3.20).

Given a sort `v`, a variable `z ∈ X_v`, and a language `L ⊆ T_Σ(X)_v`:
  * `substAssign z L` is the `S`-sorted map `X → T_Σ(X)^℘` sending `z ↦ L` and
    every other variable `y ↦ {y}`;
  * `substHom z L = (substAssign z L)^♯` is the induced homomorphism
    `T_Σ(X) → T_Σ(X)^℘`  (written `⟨z/L⟩^♯` in the paper);
  * `substP z L s K` is its completely additive extension
    `⟨z/L⟩^♯ᵖ_s (K) = ⋃_{P ∈ K} ⟨z/L⟩^♯_s(P)`.
-/
import Definitions.Def_MSKleene_Term
import Definitions.Def_MSKleene_Power
import Mathlib.Data.Set.Lattice

namespace MSKleene

universe u

variable {S : Type u} {sig : Signature S} {X : SSet S}

open scoped Classical in
/-- The substitution assignment `⟨z/L⟩ : X → T_Σ(X)^℘` (Definition 3.20):
`z ↦ L`, and `y ↦ {y}` for every other variable. -/
noncomputable def substAssign {v : S} (z : X v) (L : Set (Term sig X v)) :
    SMap X (powerAlgebra (freeAlgebra sig X)).carrier := fun t y =>
  show Set (Term sig X t) from
  if h : t = v then
    (by subst h; exact if y = z then L else {(Term.var y : Term sig X t)})
  else ({(Term.var y : Term sig X t)} : Set (Term sig X t))

/-- The homomorphism `⟨z/L⟩^♯ : T_Σ(X) → T_Σ(X)^℘` induced by `substAssign`
(Definition 3.20). -/
noncomputable def substHom {v : S} (z : X v) (L : Set (Term sig X v)) :
    Hom (freeAlgebra sig X) (powerAlgebra (freeAlgebra sig X)) :=
  evalHom (powerAlgebra (freeAlgebra sig X)) (substAssign z L)

/-- The completely additive extension `⟨z/L⟩^♯ᵖ_s : T_Σ(X)^℘_s → T_Σ(X)^℘_s`,
`K ↦ ⋃_{P ∈ K} ⟨z/L⟩^♯_s(P)` (Definition 3.20). -/
noncomputable def substP {v : S} (z : X v) (L : Set (Term sig X v)) (s : S)
    (K : Set (Term sig X s)) : Set (Term sig X s) :=
  ⋃ P ∈ K, (substHom z L).toFun s P

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

substAssign

Fix a universe level, a type SSS whose elements are called sorts, a signature Σ\SigmaΣ over SSS (for every list www of argument sorts and every result sort sss, Σw,s\Sigma_{w,s}Σw,s​ is the type of operation symbols of that profile), and an SSS-indexed family of types X=(Xs)s∈SX=(X_s)_{s\in S}X=(Xs​)s∈S​ playing the role of typed variables (XsX_sXs​ is the type of variables of sort sss). Write TermΣ,X(s)\mathrm{Term}_{\Sigma,X}(s)TermΣ,X​(s) for the type of well-sorted terms of sort sss: a term is either var(y)\mathrm{var}(y)var(y) for some y∈Xsy\in X_sy∈Xs​, or app(σ; t1,…,tk)\mathrm{app}(\sigma;\,t_1,\dots,t_k)app(σ;t1​,…,tk​) where σ∈Σw,s\sigma\in\Sigma_{w,s}σ∈Σw,s​ with w=[w1,…,wk]w=[w_1,\dots,w_k]w=[w1​,…,wk​] and each tit_iti​ is a term of sort wiw_iwi​. The data SSS, Σ\SigmaΣ, XXX and a further sort v∈Sv\in Sv∈S are implicit arguments; the explicit arguments are a variable z∈Xvz\in X_vz∈Xv​ and an arbitrary set LLL of terms of sort vvv (no restriction: LLL may be empty, may contain var(z)\mathrm{var}(z)var(z), etc.). The declaration substAssign z L is a sort-indexed function that assigns, to every sort t∈St\in St∈S and every variable y∈Xty\in X_ty∈Xt​, a set of terms of sort ttt, namely

substAssign⁡(z,L)t(y)={L,if t=v and y=z,{ var(y) },otherwise.\operatorname{substAssign}(z,L)_t(y)= \begin{cases} L, & \text{if } t=v \text{ and } y=z,\\[4pt] \{\,\mathrm{var}(y)\,\}, & \text{otherwise.} \end{cases}substAssign(z,L)t​(y)={L,{var(y)},​if t=v and y=z,otherwise.​

The two comparisons involved (the sort equality t=vt=vt=v, and after identifying ttt with vvv the variable equality y=zy=zy=z) are decided using classical logic, and the definition is marked noncomputable. Its stated codomain is the carrier, at sort ttt, of the power algebra of the free term algebra, which is definitionally Set(TermΣ,X(t))\mathrm{Set}\big(\mathrm{Term}_{\Sigma,X}(t)\big)Set(TermΣ,X​(t)).

substHom

With the same implicit data S,Σ,X,vS,\Sigma,X,vS,Σ,X,v and the same explicit arguments z∈Xvz\in X_vz∈Xv​ and L⊆TermΣ,X(v)L\subseteq\mathrm{Term}_{\Sigma,X}(v)L⊆TermΣ,X​(v), this declaration produces a homomorphism of Σ\SigmaΣ-algebras

substHom⁡(z,L): Free(Σ,X) ⟶ P(Free(Σ,X)),\operatorname{substHom}(z,L):\ \mathrm{Free}(\Sigma,X)\ \longrightarrow\ \mathcal P\big(\mathrm{Free}(\Sigma,X)\big),substHom(z,L): Free(Σ,X) ⟶ P(Free(Σ,X)),

where Free(Σ,X)\mathrm{Free}(\Sigma,X)Free(Σ,X) is the free term algebra (carrier s↦TermΣ,X(s)s\mapsto\mathrm{Term}_{\Sigma,X}(s)s↦TermΣ,X​(s), with operation op(σ; t1,…,tk)=app(σ; t1,…,tk)\mathrm{op}(\sigma;\,t_1,\dots,t_k)=\mathrm{app}(\sigma;\,t_1,\dots,t_k)op(σ;t1​,…,tk​)=app(σ;t1​,…,tk​)), and P(Free(Σ,X))\mathcal P\big(\mathrm{Free}(\Sigma,X)\big)P(Free(Σ,X)) is the power algebra over it: its carrier at sort sss is Set(TermΣ,X(s))\mathrm{Set}\big(\mathrm{Term}_{\Sigma,X}(s)\big)Set(TermΣ,X​(s)), and for σ∈Σw,s\sigma\in\Sigma_{w,s}σ∈Σw,s​ with w=[w1,…,wk]w=[w_1,\dots,w_k]w=[w1​,…,wk​] and a tuple of sets (M1,…,Mk)(M_1,\dots,M_k)(M1​,…,Mk​) with Mi⊆TermΣ,X(wi)M_i\subseteq\mathrm{Term}_{\Sigma,X}(w_i)Mi​⊆TermΣ,X​(wi​) its operation is the complex product

op(σ; M1,…,Mk)={ u ∣ ∃ x1∈M1,…,∃ xk∈Mk,  u=app(σ; x1,…,xk) }.\mathrm{op}(\sigma;\,M_1,\dots,M_k)=\big\{\,u \ \big|\ \exists\, x_1\in M_1,\dots,\exists\, x_k\in M_k,\ \ u=\mathrm{app}(\sigma;\,x_1,\dots,x_k)\,\big\}.op(σ;M1​,…,Mk​)={u ​ ∃x1​∈M1​,…,∃xk​∈Mk​,  u=app(σ;x1​,…,xk​)}.

The homomorphism is defined as the canonical evaluation homomorphism out of the free algebra induced by the assignment substAssign⁡(z,L)\operatorname{substAssign}(z,L)substAssign(z,L). It bundles two pieces of data. First, an underlying sort-indexed function Φs:TermΣ,X(s)→Set(TermΣ,X(s))\Phi_s:\mathrm{Term}_{\Sigma,X}(s)\to\mathrm{Set}\big(\mathrm{Term}_{\Sigma,X}(s)\big)Φs​:TermΣ,X​(s)→Set(TermΣ,X​(s)), characterized by structural recursion:

  • Φs(var(y))=substAssign⁡(z,L)s(y)\Phi_s(\mathrm{var}(y))=\operatorname{substAssign}(z,L)_s(y)Φs​(var(y))=substAssign(z,L)s​(y), i.e. LLL when s=vs=vs=v and y=zy=zy=z, and {var(y)}\{\mathrm{var}(y)\}{var(y)} otherwise;
  • Φs(app(σ; t1,…,tk))={ u ∣ ∃ x1∈Φw1(t1),…,∃ xk∈Φwk(tk),  u=app(σ; x1,…,xk) }\displaystyle\Phi_s\big(\mathrm{app}(\sigma;\,t_1,\dots,t_k)\big)=\big\{\,u \ \big|\ \exists\, x_1\in\Phi_{w_1}(t_1),\dots,\exists\, x_k\in\Phi_{w_k}(t_k),\ \ u=\mathrm{app}(\sigma;\,x_1,\dots,x_k)\,\big\}Φs​(app(σ;t1​,…,tk​))={u ​ ∃x1​∈Φw1​​(t1​),…,∃xk​∈Φwk​​(tk​),  u=app(σ;x1​,…,xk​)} for σ∈Σw,s\sigma\in\Sigma_{w,s}σ∈Σw,s​, w=[w1,…,wk]w=[w_1,\dots,w_k]w=[w1​,…,wk​].

Second, a proof of the homomorphism law: for every operation symbol σ∈Σw,s\sigma\in\Sigma_{w,s}σ∈Σw,s​ and every tuple of argument terms (t1,…,tk)(t_1,\dots,t_k)(t1​,…,tk​), Φs(app(σ; t1,…,tk))\Phi_s\big(\mathrm{app}(\sigma;\,t_1,\dots,t_k)\big)Φs​(app(σ;t1​,…,tk​)) equals the power-algebra operation applied to the tuple of images (Φw1(t1),…,Φwk(tk))(\Phi_{w_1}(t_1),\dots,\Phi_{w_k}(t_k))(Φw1​​(t1​),…,Φwk​​(tk​)). The construction is noncomputable and uses classical logic (inherited from substAssign⁡\operatorname{substAssign}substAssign).

substP

With the same implicit data S,Σ,X,vS,\Sigma,X,vS,Σ,X,v, the explicit arguments are a variable z∈Xvz\in X_vz∈Xv​, a set L⊆TermΣ,X(v)L\subseteq\mathrm{Term}_{\Sigma,X}(v)L⊆TermΣ,X​(v), a sort s∈Ss\in Ss∈S, and a set K⊆TermΣ,X(s)K\subseteq\mathrm{Term}_{\Sigma,X}(s)K⊆TermΣ,X​(s). The result substP z L s K is the set of terms of sort sss obtained as the indexed union, over all terms PPP lying in KKK, of the sets produced by the map Φs\Phi_sΦs​ from substHom:

substP⁡(z,L,s,K) = ⋃P∈K (substHom⁡(z,L)).toFuns(P) = { t ∣ ∃ P, P∈K ∧ t∈(substHom⁡(z,L)).toFuns(P) },\operatorname{substP}(z,L,s,K)\ =\ \bigcup_{P\in K}\ (\operatorname{substHom}(z,L)).\mathrm{toFun}_s(P)\ =\ \big\{\,t \ \big|\ \exists\, P,\ P\in K \ \wedge\ t\in (\operatorname{substHom}(z,L)).\mathrm{toFun}_s(P)\,\big\},substP(z,L,s,K) = P∈K⋃​ (substHom(z,L)).toFuns​(P) = {t ​ ∃P, P∈K ∧ t∈(substHom(z,L)).toFuns​(P)},

where (substHom⁡(z,L)).toFuns=Φs(\operatorname{substHom}(z,L)).\mathrm{toFun}_s=\Phi_s(substHom(z,L)).toFuns​=Φs​ is the recursively-defined function described above. In particular, if K=∅K=\emptysetK=∅ the union is the empty set. No hypotheses beyond the stated typing are imposed on any argument, and the definition is noncomputable.

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