Prove2Me
Navigate
DiscoverFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Corollary 4.4: Rec is a closed subset of the regular algebra

Proved
MSKleene.rec_closed_reg

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

formal-languagesmany-sorted-algebratree-automatauniversal-algebra

Rec is a closed subset of the regular algebra (Corollary 4.4).

Let ZZZ be a finite SSS-sorted set. The SSS-sorted set (Recs(TΣ(Z)))s∈S(\mathrm{Rec}_{s}(\mathbf{T}_{\Sigma}(Z)))_{s\in S}(Recs​(TΣ​(Z)))s∈S​ is a closed subset of the Reg(S,Σ,Z)\mathrm{Reg}(S,\Sigma,Z)Reg(S,Σ,Z)-algebra TΣReg(Z)℘\mathbf{T}^{\mathrm{Reg}}_{\Sigma}(Z)^{\wp}TΣReg​(Z)℘: it is closed under every operation of Reg(S,Σ,Z)\mathrm{Reg}(S,\Sigma,Z)Reg(S,Σ,Z) — the empty constant, union, zzz-iteration, zzz-substitution, and every σ∈Σ\sigma\in\Sigmaσ∈Σ.

Preamble
import Definitions.Def_MSKleene_Recognizable
import Definitions.Def_MSKleene_RegAlgebra
Formal statement
namespace MSKleene

/-- **`Rec` is a closed subset of the regular algebra** (Corollary 4.4).

With `S` finite and `Z` a finite `S`-sorted set: for every symbol of
`Reg(S,Σ,Z)` and every tuple of `Z`-languages that are componentwise
recognizable, the interpreted regular operation on `T_Σ(Z)^℘` yields a
recognizable language. In particular `(Rec_s(T_Σ(Z)))_s` is closed under
`∅`, `+`, `z`-iteration, `z`-substitution, and every `σ ∈ Σ`. -/
theorem rec_closed_reg {S : Type} [Finite S] (sig : Signature S) (Z : SSet S)
    (hZ : SFinite Z) {w : List S} {s : S} (sym : regSig sig Z w s)
    (Ls : Args (fun s => Set (Term sig Z s)) w)
    (hLs : Args.All (fun s L => sRecognizable (freeAlgebra sig Z) s L) Ls) :
    sRecognizable (freeAlgebra sig Z) s ((regPowerAlgebra sig Z).op sym Ls) := by
  sorry

end MSKleene
Source
Gong, Ruiz Mora, Sanmartín Vich, Cosme Llópez, "A Kleene theorem for free many-sorted algebras", 2026
Read-back

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

Read-back of MSKleene.rec_closed_reg

Fix a type SSS that carries a Finite instance (so there are only finitely many "sorts"). A signature sig\mathrm{sig}sig assigns to every pair (w,s)(w,s)(w,s) — with w=[s1,…,sk]w=[s_1,\dots,s_k]w=[s1​,…,sk​] a finite list of sorts and sss a sort — a type sig(w,s)\mathrm{sig}(w,s)sig(w,s) of operation symbols of input arity www and result sort sss; no finiteness whatsoever is assumed of sig\mathrm{sig}sig. Let ZZZ be an SSS-indexed family of types (Zs)s∈S(Z_s)_{s\in S}(Zs​)s∈S​ ("generators"), and let hZhZhZ be the hypothesis that the dependent sum ∑s∈SZs\sum_{s\in S} Z_s∑s∈S​Zs​ is a finite type. Write Term(r)\mathrm{Term}(r)Term(r) for the type of many-sorted terms of sort rrr built from these generators and the symbols of sig\mathrm{sig}sig: each z:Zrz:Z_rz:Zr​ yields a term var(z):Term(r)\mathrm{var}(z):\mathrm{Term}(r)var(z):Term(r), and each σ:sig(w,r)\sigma:\mathrm{sig}(w,r)σ:sig(w,r) together with terms ti:Term(si)t_i:\mathrm{Term}(s_i)ti​:Term(si​) yields a term σ(t1,…,tk):Term(r)\sigma(t_1,\dots,t_k):\mathrm{Term}(r)σ(t1​,…,tk​):Term(r). Let T\mathcal TT be the free sig\mathrm{sig}sig-algebra on ZZZ: its carrier at sort rrr is Term(r)\mathrm{Term}(r)Term(r) and its interpretation of a symbol σ\sigmaσ is formal application.

Recognizability. For a sort rrr and a set L⊆Term(r)L\subseteq\mathrm{Term}(r)L⊆Term(r), "LLL is rrr-recognizable in T\mathcal TT" means that there exist

  • a sig\mathrm{sig}sig-algebra BBB (a carrier family (Br)r∈S(B_r)_{r\in S}(Br​)r∈S​ with an interpretation of every symbol of sig\mathrm{sig}sig) such that the dependent sum ∑r∈SBr\sum_{r\in S} B_r∑r∈S​Br​ is a finite type;
  • a homomorphism of sig\mathrm{sig}sig-algebras f:T→Bf:\mathcal T\to Bf:T→B, i.e. a family of maps fr:Term(r)→Brf_r:\mathrm{Term}(r)\to B_rfr​:Term(r)→Br​ satisfying fr(σ(t1,…,tk))=B.op σ (fs1(t1),…,fsk(tk))f_r\big(\sigma(t_1,\dots,t_k)\big)=B.\mathrm{op}\,\sigma\,\big(f_{s_1}(t_1),\dots,f_{s_k}(t_k)\big)fr​(σ(t1​,…,tk​))=B.opσ(fs1​​(t1​),…,fsk​​(tk​)) for every symbol σ\sigmaσ of sig\mathrm{sig}sig;
  • a set M⊆BrM\subseteq B_rM⊆Br​;

such that

L  =  fr−1(M)  =  { t:Term(r) ∣ fr(t)∈M }.L \;=\; f_r^{-1}(M)\;=\;\{\, t:\mathrm{Term}(r)\ \mid\ f_r(t)\in M \,\}.L=fr−1​(M)={t:Term(r) ∣ fr​(t)∈M}.

Nothing further is required of BBB, fff, or MMM.

The statement. Given the finite sort type SSS, the signature sig\mathrm{sig}sig, the family ZZZ, the hypothesis hZhZhZ (∑sZs\sum_s Z_s∑s​Zs​ finite), an implicit list of sorts w=[s1,…,sk]w=[s_1,\dots,s_k]w=[s1​,…,sk​] (with k≥0k\ge 0k≥0), an implicit result sort sss, an element sym\mathrm{sym}sym of the type RegSym sig Z w s\mathrm{RegSym}\,\mathrm{sig}\,Z\,w\,sRegSymsigZws of "regular" symbols, a tuple Ls=(L1,…,Lk)Ls=(L_1,\dots,L_k)Ls=(L1​,…,Lk​) with Li⊆Term(si)L_i\subseteq\mathrm{Term}(s_i)Li​⊆Term(si​) for each iii, and a hypothesis hLshLshLs stating that for every i∈{1,…,k}i\in\{1,\dots,k\}i∈{1,…,k} the set LiL_iLi​ is sis_isi​-recognizable in T\mathcal TT (when k=0k=0k=0 this hypothesis holds vacuously), the theorem asserts:

Λ  is s-recognizable in T,where  Λ  :=  (regPowerAlgebra sig Z).op sym Ls ⊆ Term(s).\Lambda \ \text{ is } s\text{-recognizable in } \mathcal T, \qquad \text{where } \ \Lambda \;:=\; (\mathrm{regPowerAlgebra}\,\mathrm{sig}\,Z).\mathrm{op}\ \mathrm{sym}\ Ls \ \subseteq\ \mathrm{Term}(s).Λ  is s-recognizable in T,where  Λ:=(regPowerAlgebrasigZ).op sym Ls ⊆ Term(s).

The set Λ\LambdaΛ is defined by cases on which of the five constructors sym\mathrm{sym}sym is (each case constrains the implicit www and sss):

  • sym=base(σ)\mathrm{sym}=\mathrm{base}(\sigma)sym=base(σ) for a symbol σ:sig(w,s)\sigma:\mathrm{sig}(w,s)σ:sig(w,s) of the original signature, with www arbitrary:
Λ={ σ(t1,…,tk) ∣ ti∈Li for all i }\Lambda=\{\,\sigma(t_1,\dots,t_k)\ \mid\ t_i\in L_i \text{ for all } i\,\}Λ={σ(t1​,…,tk​) ∣ ti​∈Li​ for all i}

(the elementwise application of σ\sigmaσ to the argument sets; if w=[ ]w=[\,]w=[] then Λ={σ()}\Lambda=\{\sigma()\}Λ={σ()} is a singleton and hLshLshLs says nothing).

  • sym=empty(s)\mathrm{sym}=\mathrm{empty}(s)sym=empty(s): this constructor forces w=[ ]w=[\,]w=[], so LsLsLs is the empty tuple and hLshLshLs is vacuous; then
Λ=∅.\Lambda=\varnothing.Λ=∅.
  • sym=iter(s,z)\mathrm{sym}=\mathrm{iter}(s,z)sym=iter(s,z) carrying a generator z:Zsz:Z_sz:Zs​: this forces w=[s]w=[s]w=[s], so Ls=(L1)Ls=(L_1)Ls=(L1​) with L1⊆Term(s)L_1\subseteq\mathrm{Term}(s)L1​⊆Term(s) and hLshLshLs says L1L_1L1​ is sss-recognizable; then
Λ=⋃i∈NΣi,Σ0={var(z)},Σi+1=Σi ∪ substP ⁣(z, Σi, s, L1),\Lambda=\bigcup_{i\in\mathbb N}\Sigma_i,\qquad \Sigma_0=\{\mathrm{var}(z)\},\qquad \Sigma_{i+1}=\Sigma_i\ \cup\ \mathrm{substP}\!\left(z,\ \Sigma_i,\ s,\ L_1\right),Λ=i∈N⋃​Σi​,Σ0​={var(z)},Σi+1​=Σi​ ∪ substP(z, Σi​, s, L1​),

i.e. Σi+1\Sigma_{i+1}Σi+1​ adjoins to Σi\Sigma_iΣi​ every term obtained from some P∈L1P\in L_1P∈L1​ by replacing each occurrence of var(z)\mathrm{var}(z)var(z) in PPP, independently, by a term of Σi\Sigma_iΣi​.

  • sym=plus(s)\mathrm{sym}=\mathrm{plus}(s)sym=plus(s): this forces w=[s,s]w=[s,s]w=[s,s], so Ls=(L1,L2)Ls=(L_1,L_2)Ls=(L1​,L2​) with L1,L2⊆Term(s)L_1,L_2\subseteq\mathrm{Term}(s)L1​,L2​⊆Term(s) and hLshLshLs says both are sss-recognizable; then
Λ=L1∪L2.\Lambda=L_1\cup L_2.Λ=L1​∪L2​.
  • sym=subst(t,s,z)\mathrm{sym}=\mathrm{subst}(t,s,z)sym=subst(t,s,z) carrying a generator z:Ztz:Z_tz:Zt​ (the constructor's two sort arguments are ttt and the result sort sss): this forces w=[t,s]w=[t,s]w=[t,s], so Ls=(L1,L2)Ls=(L_1,L_2)Ls=(L1​,L2​) with L1⊆Term(t)L_1\subseteq\mathrm{Term}(t)L1​⊆Term(t) and L2⊆Term(s)L_2\subseteq\mathrm{Term}(s)L2​⊆Term(s), and hLshLshLs says L1L_1L1​ is ttt-recognizable and L2L_2L2​ is sss-recognizable; then
Λ=substP(z,L1,s,L2)=⋃P∈L2h^ z,L1(P),\Lambda=\mathrm{substP}(z,L_1,s,L_2)=\bigcup_{P\in L_2}\widehat h_{\,z,L_1}(P),Λ=substP(z,L1​,s,L2​)=P∈L2​⋃​hz,L1​​(P),

the set of all terms obtained from some P∈L2P\in L_2P∈L2​ by independently replacing every occurrence of var(z)\mathrm{var}(z)var(z) by a term of L1L_1L1​.

Throughout, substP(z,A,r,K)\mathrm{substP}(z,A,r,K)substP(z,A,r,K) — for z:Zvz:Z_vz:Zv​, A⊆Term(v)A\subseteq\mathrm{Term}(v)A⊆Term(v), K⊆Term(r)K\subseteq\mathrm{Term}(r)K⊆Term(r) — denotes ⋃P∈Kh^ z,A(P)\bigcup_{P\in K}\widehat h_{\,z,A}(P)⋃P∈K​hz,A​(P), where h^ z,A\widehat h_{\,z,A}hz,A​ is the evaluation homomorphism from T\mathcal TT into the power algebra of T\mathcal TT (carrier Set(Term(r))\mathrm{Set}(\mathrm{Term}(r))Set(Term(r)) at each sort rrr, every symbol interpreted by elementwise application) induced by the assignment that sends the generator zzz to the set AAA and every other generator y:Zuy:Z_uy:Zu​ to the singleton {var(y)}\{\mathrm{var}(y)\}{var(y)}; concretely, h^ z,A(P)\widehat h_{\,z,A}(P)hz,A​(P) is the set of terms produced from PPP by substituting, independently at each occurrence of var(z)\mathrm{var}(z)var(z), an arbitrary term of AAA, leaving all other variables unchanged.

The algebra regPowerAlgebra sig Z\mathrm{regPowerAlgebra}\,\mathrm{sig}\,ZregPowerAlgebrasigZ is an algebra over the extended signature RegSym sig Z\mathrm{RegSym}\,\mathrm{sig}\,ZRegSymsigZ and is used only to produce the set Λ\LambdaΛ; the witnessing algebra BBB, homomorphism fff, and set MMM in both the hypothesis hLshLshLs and the conclusion are for the original signature sig\mathrm{sig}sig and the free term algebra T\mathcal TT. "Finite" in "∑sZs\sum_s Z_s∑s​Zs​ finite" and in "∑rBr\sum_r B_r∑r​Br​ finite" means finiteness of the single dependent-sum type ranging over all sorts.

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