Let S be a finite set of sorts, Σ a finite S-sorted signature, and X a finite S-sorted set of variables. Then for every sort s∈S,
Recs(TΣ(X))=Regs(TΣ(X)),
that is, a language of sort s in the free many-sorted algebra TΣ(X) is s-recognizable — the preimage of a subset of a finite Σ-algebra under a homomorphism — if and only if it is s-regular — denoted by a regular expression built from the operations of Σ together with empty language, union, sortwise substitution, and sortwise iteration.
The inclusion Regs⊆Recs follows from the closure properties of recognizability (Corollary 4.8); the converse Recs⊆Regs (Proposition 4.10) is proved by a constructive state-elimination argument carrying a sortwise budget (Main Claim 4.13).
namespace MSKleene
theorem kleene_theorem {S : Type} [Finite S] (sig : Signature S) (X : SSet S)
(hsig : SigFinite sig) (hX : SFinite X) (s : S) :
RecS (freeAlgebra sig X) s = RegS sig X s := by
sorry
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
Ambient data and hypotheses.
Fix a type S of sorts carrying a Finite instance, so S has finitely many elements; it is moreover nonempty, since a sort s:S is supplied as the last argument. A signature over S is a family
sig:ListS→S→Type,
so that for an argument–sort list w=[w1,…,wk] and a result sort r, the type sigwr is the collection of operation symbols of that profile. A sorted variable family is X:S→Type, where Xr is the type of variables of sort r. Two finiteness hypotheses are assumed:
hsig:SigFinitesig, which unfolds to: the type ∑w:ListS∑r:Ssigwr of all triples (argument–sort list, result sort, operation symbol) is a finite type. Since ListS is infinite, this forces sigwr to be empty for all but finitely many pairs (w,r).
hX:SFiniteX, which unfolds to: the type ∑r:SXr of all (sort, variable-of-that-sort) pairs is a finite type.
Finally a specific sort s:S is fixed.
Terms and the free algebra.TermsigX is the S-indexed inductive family of well-sorted terms (defined mutually with tuples of terms): a term of sort r is either var(x) for a variable x:Xr, or app(σ;t1,…,tk) where σ:sigwr with w=[w1,…,wk] and each ti:TermsigXwi. Write TermsigXr for the type of sort-r terms. The free (term) algebraF:=freeAlgebrasigX is the sig-algebra whose carrier at sort r is TermsigXr and which interprets every symbol σ by term formation: σF(t1,…,tk)=app(σ;t1,…,tk).
The objects being compared.
Both sides of the asserted equation are subsets of the powerset P(TermsigXs), i.e. sets of languages of sort-s terms. The theorem asserts that, for this fixed s, the two sets of languages coincide.
Left side — RecS(F,s).
This is
{L⊆TermsigXssRecognizable(F,s,L)},
and sRecognizable(F,s,L) holds iff there exist:
a sig-algebra B: a carrier B∙:S→Type together with, for every w,r and every σ:sigwr, an operation σB:Bw1×⋯×Bwk→Br;
a proof that B is finite, meaning ∑r:SBr is a finite type;
a homomorphism f:F→B, i.e. a family of maps fr:TermsigXr→Br satisfying, for every σ:sigwr and all arguments,
The condition on f constrains only its behaviour on app-nodes; its values on variable terms var(x) are otherwise unconstrained.
Right side — RegS(sig,X,s).
This is
{L⊆TermsigXssRegular(sig,X,s,L)},
and sRegular(sig,X,s,L) holds iff there exist:
a sorted family of extra variablesE:S→Type; put Z:=X⊕E, the sortwise disjoint sum, Zr=Xr⊔Er;
a proof of SFinite(Z), i.e. ∑r:S(Xr⊔Er) is a finite type;
a regular expressionR:RegExprsigZs, which is by definition an ordinary term R:Term(regSigsigZ)Zs of sort s over the variable family Z and the regular signatureregSigsigZ=RegSymsigZ, whose operation symbols of profile (w,r) are exactly:
base(σ) for each σ:sigwr (same profile (w,r)),
empty(r), of profile ([],r) — a nullary symbol, one for every sort r,
iter(r,z), of profile ([r],r), parameterised by a chosen variable z:Zr,
plus(r), of profile ([r,r],r),
subst(t,r,z), of profile ([t,r],r), parameterised by a chosen variable z:Zt;
such that
interpExprsigZs(R)={relabel(ι)(t)t∈L},
where ι:=extInclXE is the sortwise left injection x↦inl(x):Xr→Zr, and relabel(ι) renames every variable occurring in a term along ι while leaving the operation structure unchanged. Both sides of this equality are subsets of TermsigZs (terms over the extended variable family Z); L enters only through its relabelled image.
Interpretation of regular expressions.interpExprsigZs(R) is (interpsigZ)s(R), the value at R of the evaluation homomorphism from the free algebra over regSigsigZ with variables Z into the algebra regPowerAlgebrasigZ, whose carrier at sort r is P(TermsigZr) and which sends each variable z:Zr to the singleton language {var(z)}. Unfolding the recursion, interpExpr(R)⊆TermsigZs is:
R=var(z) with z:Zs: value {var(z)};
R=base(σ)(R1,…,Rk) with σ:sigws: value {app(σ;u1,…,uk)∣ui∈interpExpr(Ri) for each i};
R=empty(s): value ∅;
R=plus(s)(R1,R2): value interpExpr(R1)∪interpExpr(R2);
R=iter(s,z)(R1) with z:Zs: value iterate(z,interpExpr(R1));
R=subst(t,s,z)(R1,R2) with z:Zt, R1 of sort t, R2 of sort s: value substP(z,interpExpr(R1),s,interpExpr(R2)).
The substitution operation.
For z:Zt, a language Λ⊆TermsigZt, a sort r, and a language K⊆TermsigZr,
substP(z,Λ,r,K)=P∈K⋃Θz,Λ(P),
where Θz,Λ(P)⊆TermsigZr is the evaluation of the term P in the powerset algebra of the term algebra under the variable assignment that sends the parameter variable z to Λ and every other variable y to {var(y)}. Concretely, Θz,Λ(P) is the set of all terms obtained from P by replacing each occurrence of z independently by some term of Λ and leaving all other variables fixed; thus Θz,Λ(var(z))=Λ, Θz,Λ(var(y))={var(y)} for y=z, and Θz,Λ distributes elementwise through app.
The iteration operation.
For z:Zs and Λ⊆TermsigZs, define stages over i∈N by
and set iterate(z,Λ)=⋃i∈NiterStage(z,Λ,i). In words: start from {var(z)}; at each stage, for every term P∈Λ, substitute the terms produced so far into the z-occurrences of P, and accumulate.
The full assertion.
For the fixed sort s, the theorem states equality of the following two subsets of P(TermsigXs): a language L of sort-s terms belongs to the left side iff there exist a sig-algebra B with finite total carrier, a homomorphism f:F→B, and a subset M⊆Bs with L=fs−1(M); and L belongs to the right side iff there exist an extra-variable family E making X⊕E have finite total variable type, together with a regular expression R over regSigsig(X⊕E) of sort s whose interpreted language equals the ι-relabelled image {relabel(ι)(t):t∈L}. The equation asserts that membership in the left side holds precisely when membership in the right side does, with no further relationship imposed between the data (E,R) and the data (B,f,M).
Degenerate and edge cases.
S is finite and, because s:S is given, nonempty.
hX allows ∑rXr to be empty, and hsig allows sig to have no operation symbols at all. If in addition no term of sort s exists, then TermsigXs is empty, P(TermsigXs)={∅}, and the claim reduces to "∅ lies on the left side iff it lies on the right side".
In sRegular the family E is unconstrained except that SFinite(X⊕E) must hold; given hX this amounts to ∑rEr being finite. Every Er may be empty, in which case Z is X up to the left injection ι.
The symbols empty, plus, iter, subst are present in regSigsigZ for every sort (respectively sort pair), independently of sig. plus only ever combines two languages whose common sort equals the result sort.
R may be a bare variable var(z) with z:Zs, whose interpretation is the singleton {var(z)}.
iterate(z,Λ) always contains var(z) (from stage 0), regardless of Λ; if Λ=∅ then substP(z,⋅,s,∅)=∅ and iterate(z,∅)={var(z)}.
B ranges over all sig-algebras with finite total carrier (not only quotients of F); f is any homomorphism from the term algebra, its values on variable terms free.
The equality inside sRegular is between subsets of Termsig(X⊕E)s, i.e. terms over the extended variables, not over X.
Confirmed by the mission captain (proposal self-audit).