Prove2Me
Navigate
DiscoverFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

The regular signature Reg(S,Σ,Z)\mathrm{Reg}(S,\Sigma,Z)Reg(S,Σ,Z)

Definition
MSKleene_RegSig

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

formal-languagesmany-sorted-algebratree-automatauniversal-algebra

(updated) The regular signature Reg(S,Σ,Z)\mathrm{Reg}(S,\Sigma,Z)Reg(S,Σ,Z). See the mission's other definition items for the surrounding development.

Definition code
/-
The regular signature `Reg(S,Σ,Z)` (Definition 4.1) and regular expressions
(Definition 4.2).

`Reg(S,Σ,Z)` expands `Σ`, for a fixed `S`-sorted set `Z`, by:
  * an empty constant `∅_s` of coarity `s`               (rank `([], s)`);
  * a binary sum `+_s` of coarity `s`                    (rank `([s,s], s)`);
  * a unary `z`-iteration `(·)^{⋆z}` for each `z ∈ Z_s`  (rank `([s], s)`);
  * a `z`-substitution `⟨z/·⟩^♯ᵖ_s(·)` for each `z ∈ Z_t` (rank `([t,s], s)`).

A **regular expression over `(S,Σ,Z)` of type `s`** is a term of the free
`Reg(S,Σ,Z)`-algebra on `Z`, i.e. an element of `Term (regSig sig Z) Z s`.

Also here: `Term.relabel`, the action of `T_Σ(-)` on an `S`-sorted map of
variables, used to view `T_Σ(X)` inside `T_Σ(Z)` when `X ⊆ Z`.
-/
import Definitions.Def_MSKleene_Term

namespace MSKleene

universe u

variable {S : Type u}

/-- The operation symbols of the regular signature `Reg(S,Σ,Z)` (Definition 4.1),
indexed by rank `(w, s)`. `base` re-uses every symbol of `Σ`; the four extra
constructors are `∅_s`, `+_s`, `(·)^{⋆z}`, and `⟨z/·⟩^♯ᵖ_s(·)`. -/
inductive RegSym (sig : Signature S) (Z : SSet S) : List S → S → Type u where
  | base {w : List S} {s : S} : sig w s → RegSym sig Z w s
  | empty (s : S) : RegSym sig Z [] s
  | iter (s : S) : Z s → RegSym sig Z [s] s
  | plus (s : S) : RegSym sig Z [s, s] s
  | subst (t s : S) : Z t → RegSym sig Z [t, s] s

/-- The regular signature `Reg(S,Σ,Z)` as an `S`-sorted signature. -/
def regSig (sig : Signature S) (Z : SSet S) : Signature S := RegSym sig Z

/-- A regular expression over `(S,Σ,Z)` of type `s` (Definition 4.2). -/
abbrev RegExpr (sig : Signature S) (Z : SSet S) (s : S) : Type u :=
  Term (regSig sig Z) Z s

-- Relabel the variables of a term along an `S`-sorted map `ι : X → Y`
-- (functoriality of `T_Σ(-)`). Used with an inclusion `X ↪ Z`.
mutual
def Term.relabel {sig : Signature S} {X Y : SSet S} (ι : SMap X Y) :
    {s : S} → Term sig X s → Term sig Y s
  | _, .var x => Term.var (ι _ x)
  | _, .app σ ts => Term.app σ (TermVec.relabel ι ts)
def TermVec.relabel {sig : Signature S} {X Y : SSet S} (ι : SMap X Y) :
    {w : List S} → TermVec sig X w → TermVec sig Y w
  | _, .nil => .nil
  | _, .cons t ts => .cons (Term.relabel ι t) (TermVec.relabel ι ts)
end

-- Embed a `Σ`-term as a regular expression over `(S,Σ,Z)` of the same type:
-- every operation symbol `σ` becomes `RegSym.base σ` (Lemma 4.9).
mutual
def Term.toReg {sig : Signature S} {Z : SSet S} :
    {s : S} → Term sig Z s → RegExpr sig Z s
  | _, .var x => Term.var x
  | _, .app σ ts => Term.app (RegSym.base σ) (TermVec.toReg ts)
def TermVec.toReg {sig : Signature S} {Z : SSet S} :
    {w : List S} → TermVec sig Z w → TermVec (regSig sig Z) Z w
  | _, .nil => .nil
  | _, .cons t ts => .cons (Term.toReg t) (TermVec.toReg ts)
end

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

RegSym

RegSym is an inductive family of types. Its ambient data are: an implicit sort type SSS in universe uuu; an explicit sig : Signature S, where Signature S unfolds by definition to List S→S→Type u\mathrm{List}\,S \to S \to \mathrm{Type}\,uListS→S→Typeu (so sig assigns to each arity www — a finite list of sorts — and each result sort sss a type sig  w  ssig\;w\;ssigws of operation symbols); and an explicit Z : SSet S, where SSet S unfolds to S→Type uS \to \mathrm{Type}\,uS→Typeu (so ZZZ assigns a type ZsZ_sZs​ to each sort sss). For fixed sig and Z, the family RegSym sig Z has type List S→S→Type u\mathrm{List}\,S \to S \to \mathrm{Type}\,uListS→S→Typeu, i.e. it is itself a signature over SSS; for an arity www and result sort sss the type RegSym sig Z w s is generated by exactly the following constructors:

  • base: from an implicit w:List Sw : \mathrm{List}\,Sw:ListS, an implicit s:Ss : Ss:S, and an element of sig  w  ssig\;w\;ssigws, produces an element of RegSym sig Z w s — same arity www, same result sort sss.
  • empty: for every explicit s:Ss : Ss:S, an element of RegSym sig Z [] s — arity the empty list [ ][\,][], result sort sss.
  • iter: for every explicit s:Ss : Ss:S and every element of ZsZ_sZs​, an element of RegSym sig Z [s] s — arity the one-element list [s][s][s], result sort sss.
  • plus: for every explicit s:Ss : Ss:S, an element of RegSym sig Z [s, s] s — arity the two-element list [s,s][s,s][s,s], result sort sss.
  • subst: for every pair of explicit sorts t,s:St, s : St,s:S and every element of ZtZ_tZt​, an element of RegSym sig Z [t, s] s — arity the two-element list [t,s][t,s][t,s], result sort sss.

There are no other constructors. Note the edge behavior: empty and plus produce a symbol for every sort unconditionally; iter at sort sss produces symbols only insofar as ZsZ_sZs​ has elements (none if ZsZ_sZs​ is empty); subst with argument sorts (t,s)(t,s)(t,s) produces symbols only insofar as ZtZ_tZt​ has elements; and base embeds the symbols of sig at every arity and result sort, one base-symbol per sig-symbol.

regSig

regSig takes an implicit sort type SSS, an explicit sig : Signature S (assigning a type of operation symbols to each arity www and result sort sss), and an explicit Z : SSet S (assigning a type ZsZ_sZs​ to each sort sss), and returns a term of type Signature S, namely the family RegSym  sig  Z\mathrm{RegSym}\;sig\;ZRegSymsigZ. Thus regSig  sig  Z\mathrm{regSig}\;sig\;ZregSigsigZ is the signature whose symbols of arity www and result sort sss are precisely the elements of RegSym sig Z w s as described above (the base copies of sig's symbols together with the empty, iter, plus, and subst symbols). This is a purely definitional repackaging: no data is added or removed.

RegExpr

RegExpr is an abbreviation. Given an implicit sort type SSS, an explicit sig : Signature S, an explicit Z : SSet S, and an explicit sort s : S, the type RegExpr sig Z s (in Type u\mathrm{Type}\,uTypeu) unfolds to Term (regSig sig Z) Z s. Here Term σ X is the mutually-inductive family of terms over a signature σ\sigmaσ with variables drawn from a sorted set XXX: a value at sort sss is either a variable var x with x∈Xsx \in X_sx∈Xs​, or an application app f ts of a symbol fff of σ\sigmaσ of arity www and result sort sss to a vector ts of subterms whose sorts match the list www. Therefore a RegExpr sig Z s is a term of result sort sss whose variables are elements of the ZsZ_sZs​ families and whose operation nodes are labelled by regular symbols of regSig  sig  Z=RegSym  sig  Z\mathrm{regSig}\;sig\;Z = \mathrm{RegSym}\;sig\;ZregSigsigZ=RegSymsigZ (i.e. base σ, empty, iter, plus, or subst).

Term.relabel

Term.relabel is one of two functions defined together by mutual structural recursion (with TermVec.relabel). It takes an implicit sort type SSS, an implicit sig : Signature S, two implicit sorted sets X Y : SSet S, and an explicit ι : SMap X Y, where SMap X Y unfolds to (s:S)→Xs→Ys(s : S) \to X_s \to Y_s(s:S)→Xs​→Ys​ — a family of functions ιs:Xs→Ys\iota_s : X_s \to Y_sιs​:Xs​→Ys​, one per sort. It then takes an implicit sort s:Ss : Ss:S and a value of Term sig X s, and returns a value of Term sig Y s (same signature sig, same result sort sss, but with variables now taken from YYY). It is defined by cases on the input term:

  • on a variable var x with x∈Xsx \in X_sx∈Xs​, it returns var (ι s x), the variable ιs(x)∈Ys\iota_s(x) \in Y_sιs​(x)∈Ys​;
  • on an application app σ ts, where σ\sigmaσ is a symbol of sig of arity www and result sort sss and ts is of type TermVec sig X w, it returns app σ (TermVec.relabel ι ts) — the same symbol σ\sigmaσ applied to the argument vector obtained by recursively relabelling ts.

TermVec.relabel

TermVec.relabel is the companion of Term.relabel in the same mutual block. With the same implicit data (sort type SSS, sig : Signature S, sorted sets X Y : SSet S) and the same explicit ι : SMap X Y (the family ιs:Xs→Ys\iota_s : X_s \to Y_sιs​:Xs​→Ys​), it takes an implicit arity w : List S and a value of TermVec sig X w, and returns a value of TermVec sig Y w. Here TermVec sig X w is the type of finite tuples of terms indexed by the list of sorts www: the constructor nil gives the empty tuple at arity [ ][\,][], and cons t ts gives, at arity s::ws :: ws::w, a tuple whose head t has type Term sig X s and whose tail ts has type TermVec sig X w. The definition:

  • on nil, it returns nil;
  • on cons t ts, it returns cons (Term.relabel ι t) (TermVec.relabel ι ts) — relabel the head term via Term.relabel and recursively relabel the tail vector.

Term.toReg

Term.toReg is one of two functions defined together by mutual structural recursion (with TermVec.toReg). It takes an implicit sort type SSS, an implicit sig : Signature S, and an implicit Z : SSet S; then an implicit sort s:Ss : Ss:S and a value of Term sig Z s — a term over the signature sig whose variables are elements of the ZsZ_sZs​ families, of result sort sss. It returns a value of RegExpr sig Z s, which unfolds to Term (regSig sig Z) Z s — a term over the signature regSig  sig  Z=RegSym  sig  Z\mathrm{regSig}\;sig\;Z = \mathrm{RegSym}\;sig\;ZregSigsigZ=RegSymsigZ, with the same variable family ZZZ and the same result sort sss. It is defined by cases:

  • on a variable var x with x∈Zsx \in Z_sx∈Zs​, it returns var x — the same variable, now regarded as a variable in the term family over regSig  sig  Z\mathrm{regSig}\;sig\;ZregSigsigZ;
  • on an application app σ ts, where σ\sigmaσ is a symbol of sig of arity www and result sort sss and ts is of type TermVec sig Z w, it returns app (RegSym.base σ) (TermVec.toReg ts) — the symbol σ\sigmaσ re-tagged through the base constructor as a symbol of RegSym sig Z w s, applied to the argument vector obtained by recursively converting ts.

TermVec.toReg

TermVec.toReg is the companion of Term.toReg in the same mutual block. With implicit sort type SSS, implicit sig : Signature S, and implicit Z : SSet S, it takes an implicit arity w : List S and a value of TermVec sig Z w, and returns a value of TermVec (regSig sig Z) Z w — the argument-vector type over the regular signature regSig  sig  Z\mathrm{regSig}\;sig\;ZregSigsigZ, with the same list of sorts www and the same variable family ZZZ. It is defined by cases:

  • on nil, it returns nil;
  • on cons t ts, it returns cons (Term.toReg t) (TermVec.toReg ts) — convert the head term via Term.toReg and recursively convert the tail vector.
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