Prove2Me
Navigate
DiscoverFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

The sss-regular languages Regs(TΣ(X))\mathrm{Reg}_s(\mathbf{T}_\Sigma(X))Regs​(TΣ​(X))

Definition
MSKleene_Regular

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

formal-languagesmany-sorted-algebratree-automatauniversal-algebra

The sss-regular languages of the free many-sorted algebra (Definition 4.6).

A language L ⊆ T_Σ(X)_s is sss-regular (sRegular sig X s L) when there is a finite SSS-sorted set Z⊇XZ \supseteq XZ⊇X and a regular expression R of type s over (S,Σ,Z)(S,\Sigma,Z)(S,Σ,Z) with

L={R}sZ♯L = \{R\}^{Z\sharp}_sL={R}sZ♯​

as subsets of TΣ(Z)s\mathrm{T}_\Sigma(Z)_sTΣ​(Z)s​. The extension Z⊇XZ \supseteq XZ⊇X is modelled as Zs=Xs⊕EsZ_s = X_s \oplus E_sZs​=Xs​⊕Es​ for an SSS-sorted set E of auxiliary variables (extVars), with the canonical inclusion Sum.inl (extIncl); L is transported into TΣ(Z)s\mathrm{T}_\Sigma(Z)_sTΣ​(Z)s​ by relabelling along that inclusion.

RegS sig X s collects the sss-regular languages; this is Regs(TΣ(X))\mathrm{Reg}_s(\mathbf{T}_\Sigma(X))Regs​(TΣ​(X)), one side of the mission goal.

Formalization Note The auxiliary variables of Z−XZ - XZ−X play a purely bookkeeping role: they carry the iteration and substitution steps and vanish when the regular expression is interpreted as a language.

Definition code
/-
The `s`-regular languages of the free many-sorted algebra (Definition 4.6).

`L ⊆ T_Σ(X)_s` is **`s`-regular** when there is a finite `S`-sorted set `Z ⊇ X`
and a regular expression `R` of type `s` over `(S,Σ,Z)` with `L = {R}^{Z♯}_s`
(the equality taken inside `T_Σ(Z)_s`).

Here the extension `Z ⊇ X` is modelled as `Z_s = X_s ⊕ E_s` for an `S`-sorted
set `E` of auxiliary variables, with the canonical inclusion `Sum.inl`; `L` is
transported into `T_Σ(Z)_s` by relabelling along that inclusion.
-/
import Definitions.Def_MSKleene_RegAlgebra
import Definitions.Def_MSKleene_Recognizable
import Mathlib.Data.Set.Image

namespace MSKleene

universe u

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

/-- The `S`-sorted set `X` extended by the auxiliary variables `E`. -/
def extVars (X E : SSet S) : SSet S := fun s => X s ⊕ E s

/-- The canonical inclusion `X ↪ X ⊕ E`. -/
def extIncl (X E : SSet S) : SMap X (extVars X E) := fun _ x => Sum.inl x

/-- `L ⊆ T_Σ(X)_s` is **`s`-regular** (Definition 4.6). -/
def sRegular (sig : Signature S) (X : SSet S) (s : S) (L : Set (Term sig X s)) :
    Prop :=
  ∃ E : SSet S, SFinite (extVars X E) ∧
    ∃ R : RegExpr sig (extVars X E) s,
      interpExpr sig (extVars X E) s R
        = (fun t : Term sig X s => Term.relabel (extIncl X E) t) '' L

/-- `Reg_s(𝐓_Σ(X))` — the set of `s`-regular languages of `T_Σ(X)` at sort `s`. -/
def RegS (sig : Signature S) (X : SSet S) (s : S) : Set (Set (Term sig X s)) :=
  { L | sRegular sig X s L }

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

extVars

Working over an implicit type of sorts SSS, this defines, from two SSS-indexed families of types X,E:S→TypeX, E : S \to \mathrm{Type}X,E:S→Type (each is a "sorted set" over SSS, both passed as explicit arguments), a new sorted set extVars X E:S→Type\mathrm{extVars}\ X\ E : S \to \mathrm{Type}extVars X E:S→Type. Its value at a sort sss is the disjoint-sum (coproduct) type Xs⊕EsX_s \oplus E_sXs​⊕Es​. Intuitively it enlarges the variable family XXX by adjoining, sort by sort, the extra variables EEE.

extIncl

Again over an implicit sort type SSS, and given two sorted sets X,E:S→TypeX, E : S \to \mathrm{Type}X,E:S→Type (both explicit), this defines a sorted map extIncl X E\mathrm{extIncl}\ X\ EextIncl X E from XXX to extVars X E\mathrm{extVars}\ X\ EextVars X E, i.e. a family of functions indexed by sorts. At every sort sss it is the function x↦inl xx \mapsto \mathrm{inl}\ xx↦inl x sending each x:Xsx : X_sx:Xs​ to the left injection inl x:Xs⊕Es\mathrm{inl}\ x : X_s \oplus E_sinl x:Xs​⊕Es​. The sort index is not otherwise used. This is the canonical inclusion of the original variables into the enlarged family, and it is injective.

sRegular

Over an implicit sort type SSS, this defines a predicate sRegular sig X s L\mathrm{sRegular}\ sig\ X\ s\ LsRegular sig X s L of four explicit arguments: a signature sig:List S→S→Typesig : \mathrm{List}\ S \to S \to \mathrm{Type}sig:List S→S→Type (which assigns to each input word www and output sort s′s's′ a type of operation symbols of that arity), a sorted set of variables X:S→TypeX : S \to \mathrm{Type}X:S→Type, a distinguished sort s:Ss : Ss:S, and a set LLL of terms of sort sss built from sigsigsig with variables taken from XXX, i.e. L⊆Term sig X sL \subseteq \mathrm{Term}\ sig\ X\ sL⊆Term sig X s (a set given by an arbitrary total predicate, so it may be empty or the whole type). The predicate asserts that there exists a sorted set E:S→TypeE : S \to \mathrm{Type}E:S→Type of "extension variables" satisfying both of the following.

Finiteness. SFinite(extVars X E)\mathrm{SFinite}(\mathrm{extVars}\ X\ E)SFinite(extVars X E) holds, which unfolds to: the dependent sum

∑s′:S(Xs′⊕Es′)\sum_{s' : S}\bigl(X_{s'} \oplus E_{s'}\bigr)s′:S∑​(Xs′​⊕Es′​)

is a finite type. That is, the disjoint union over all sorts of the original variables together with the extension variables is finite. Consequently ∑s′:SXs′\sum_{s':S} X_{s'}∑s′:S​Xs′​ must itself be finite; if the original variable space is infinite, no witness EEE exists and the predicate is false for every LLL. The sort type SSS need not be finite.

Denotation by a regular expression. There exists an expression

R:RegExpr sig (extVars X E) s,R : \mathrm{RegExpr}\ sig\ (\mathrm{extVars}\ X\ E)\ s,R:RegExpr sig (extVars X E) s,

which by definition is a term of sort sss over the enlarged signature regSig sig (extVars X E)\mathrm{regSig}\ sig\ (\mathrm{extVars}\ X\ E)regSig sig (extVars X E) with variables in extVars X E\mathrm{extVars}\ X\ EextVars X E. The operation symbols of this enlarged signature, at input word www and output sort s′s's′, are: every original symbol of sig w s′sig\ w\ s'sig w s′ ("base"); one nullary symbol at each sort ("empty"); for each variable z:(extVars X E)s′z : (\mathrm{extVars}\ X\ E)_{s'}z:(extVars X E)s′​ a unary symbol [s′]→s′[s'] \to s'[s′]→s′ ("iter"); one binary symbol [s′,s′]→s′[s', s'] \to s'[s′,s′]→s′ ("plus"); and for every pair of sorts t,s′t, s't,s′ and every variable z:(extVars X E)tz : (\mathrm{extVars}\ X\ E)_tz:(extVars X E)t​ a binary symbol [t,s′]→s′[t, s'] \to s'[t,s′]→s′ ("subst"). This expression RRR must satisfy

interpExpr sig (extVars X E) s R  =  { relabel(ι)(t)  ∣  t∈L },\mathrm{interpExpr}\ sig\ (\mathrm{extVars}\ X\ E)\ s\ R \;=\; \bigl\{\, \mathrm{relabel}(\iota)(t) \;\bigm|\; t \in L \,\bigr\},interpExpr sig (extVars X E) s R={relabel(ι)(t)​t∈L},

an equality of subsets of Term sig (extVars X E) s\mathrm{Term}\ sig\ (\mathrm{extVars}\ X\ E)\ sTerm sig (extVars X E) s. Here ι=extIncl X E\iota = \mathrm{extIncl}\ X\ Eι=extIncl X E, and relabel(ι)(t)\mathrm{relabel}(\iota)(t)relabel(ι)(t) is the term obtained from ttt by replacing every variable occurrence xxx (at any sort) by inl x\mathrm{inl}\ xinl x, while leaving all applied-operation structure unchanged; the right-hand side is the set-image of LLL under this relabeling. Because ι\iotaι is injective, the right-hand side is a faithful copy of LLL with all its variables re-tagged as "left". EEE is permitted to be the empty family (each Es′E_{s'}Es′​ an empty type), in which case extVars X E\mathrm{extVars}\ X\ EextVars X E is essentially XXX itself.

Meaning of the left-hand side. interpExpr sig Z s R\mathrm{interpExpr}\ sig\ Z\ s\ RinterpExpr sig Z s R, with Z=extVars X EZ = \mathrm{extVars}\ X\ EZ=extVars X E, is the subset of Term sig Z s\mathrm{Term}\ sig\ Z\ sTerm sig Z s obtained by recursively evaluating the expression tree RRR in the power-set algebra over the free sigsigsig-algebra on ZZZ (carrier at sort s′s's′ equal to { \{\,{subsets of Term sig Z s′ }\mathrm{Term}\ sig\ Z\ s'\,\}Term sig Z s′}), under the assignment sending each variable z:Zs′z : Z_{s'}z:Zs′​ to the singleton {var z}\{\mathrm{var}\ z\}{var z}. The node symbols are interpreted as follows:

  • a "base" node with original symbol σ:sig w s′\sigma : sig\ w\ s'σ:sig w s′ applied to argument sets L1,…,LkL_1, \dots, L_kL1​,…,Lk​ yields { app σ (t1,…,tk)∣ti∈Li for all i }\{\, \mathrm{app}\ \sigma\ (t_1, \dots, t_k) \mid t_i \in L_i \text{ for all } i \,\}{app σ (t1​,…,tk​)∣ti​∈Li​ for all i};
  • an "empty" node at sort s′s's′ yields ∅\varnothing∅;
  • a "plus" node applied to sets AAA and BBB yields A∪BA \cup BA∪B;
  • an "iter" node carrying variable z:Zs′z : Z_{s'}z:Zs′​ applied to a set A⊆Term sig Z s′A \subseteq \mathrm{Term}\ sig\ Z\ s'A⊆Term sig Z s′ yields ⋃i∈NiterStage(z,A,i)\bigcup_{i \in \mathbb{N}} \mathrm{iterStage}(z, A, i)⋃i∈N​iterStage(z,A,i), where iterStage(z,A,0)={var z}\mathrm{iterStage}(z, A, 0) = \{\mathrm{var}\ z\}iterStage(z,A,0)={var z} and iterStage(z,A,i+1)=iterStage(z,A,i) ∪ substP(z, iterStage(z,A,i), s′, A)\mathrm{iterStage}(z, A, i{+}1) = \mathrm{iterStage}(z, A, i)\ \cup\ \mathrm{substP}\bigl(z,\, \mathrm{iterStage}(z, A, i),\, s',\, A\bigr)iterStage(z,A,i+1)=iterStage(z,A,i) ∪ substP(z,iterStage(z,A,i),s′,A);
  • a "subst" node carrying variable z:Ztz : Z_tz:Zt​ applied to a set A⊆Term sig Z tA \subseteq \mathrm{Term}\ sig\ Z\ tA⊆Term sig Z t and a set K⊆Term sig Z s′K \subseteq \mathrm{Term}\ sig\ Z\ s'K⊆Term sig Z s′ yields substP(z,A,s′,K)=⋃P∈KsubstHom(z,A)(P)\mathrm{substP}(z, A, s', K) = \bigcup_{P \in K} \mathrm{substHom}(z, A)(P)substP(z,A,s′,K)=⋃P∈K​substHom(z,A)(P), i.e. the union over P∈KP \in KP∈K of all terms obtained from PPP by replacing every occurrence of the variable zzz with (members of) AAA, other variables being left as themselves.

RegS

Over an implicit sort type SSS, and given explicit arguments a signature sigsigsig, a sorted set of variables XXX, and a sort s:Ss : Ss:S, this defines RegS sig X s\mathrm{RegS}\ sig\ X\ sRegS sig X s as the set of all sets LLL of sigsigsig-terms of sort sss with variables in XXX — that is, all L⊆Term sig X sL \subseteq \mathrm{Term}\ sig\ X\ sL⊆Term sig X s — for which sRegular sig X s L\mathrm{sRegular}\ sig\ X\ s\ LsRegular sig X s L holds. It is thus a subset of the powerset of Term sig X s\mathrm{Term}\ sig\ X\ sTerm sig X s: the collection of those term-languages at sort sss that are "sss-regular" in the sense of the predicate above.

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