The -regular languages
DefinitionMSKleene_RegularThe -regular languages of the free many-sorted algebra (Definition 4.6).
A language L ⊆ T_Σ(X)_s is -regular (sRegular sig X s L) when there is a finite -sorted set and a regular expression R of type s over with
as subsets of . The extension is modelled as for an -sorted set E of auxiliary variables (extVars), with the canonical inclusion Sum.inl (extIncl); L is transported into by relabelling along that inclusion.
RegS sig X s collects the -regular languages; this is , one side of the mission goal.
Formalization Note The auxiliary variables of play a purely bookkeeping role: they carry the iteration and substitution steps and vanish when the regular expression is interpreted as a language.
/-
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
Read-back
What the Lean code literally says, in plain math · claude-sonnet-5
extVars
Working over an implicit type of sorts , this defines, from two -indexed families of types (each is a "sorted set" over , both passed as explicit arguments), a new sorted set . Its value at a sort is the disjoint-sum (coproduct) type . Intuitively it enlarges the variable family by adjoining, sort by sort, the extra variables .
extIncl
Again over an implicit sort type , and given two sorted sets (both explicit), this defines a sorted map from to , i.e. a family of functions indexed by sorts. At every sort it is the function sending each to the left injection . 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 , this defines a predicate of four explicit arguments: a signature (which assigns to each input word and output sort a type of operation symbols of that arity), a sorted set of variables , a distinguished sort , and a set of terms of sort built from with variables taken from , i.e. (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 of "extension variables" satisfying both of the following.
Finiteness. holds, which unfolds to: the dependent sum
is a finite type. That is, the disjoint union over all sorts of the original variables together with the extension variables is finite. Consequently must itself be finite; if the original variable space is infinite, no witness exists and the predicate is false for every . The sort type need not be finite.
Denotation by a regular expression. There exists an expression
which by definition is a term of sort over the enlarged signature with variables in . The operation symbols of this enlarged signature, at input word and output sort , are: every original symbol of ("base"); one nullary symbol at each sort ("empty"); for each variable a unary symbol ("iter"); one binary symbol ("plus"); and for every pair of sorts and every variable a binary symbol ("subst"). This expression must satisfy
an equality of subsets of . Here , and is the term obtained from by replacing every variable occurrence (at any sort) by , while leaving all applied-operation structure unchanged; the right-hand side is the set-image of under this relabeling. Because is injective, the right-hand side is a faithful copy of with all its variables re-tagged as "left". is permitted to be the empty family (each an empty type), in which case is essentially itself.
Meaning of the left-hand side. , with , is the subset of obtained by recursively evaluating the expression tree in the power-set algebra over the free -algebra on (carrier at sort equal to subsets of ), under the assignment sending each variable to the singleton . The node symbols are interpreted as follows:
- a "base" node with original symbol applied to argument sets yields ;
- an "empty" node at sort yields ;
- a "plus" node applied to sets and yields ;
- an "iter" node carrying variable applied to a set yields , where and ;
- a "subst" node carrying variable applied to a set and a set yields , i.e. the union over of all terms obtained from by replacing every occurrence of the variable with (members of) , other variables being left as themselves.
RegS
Over an implicit sort type , and given explicit arguments a signature , a sorted set of variables , and a sort , this defines as the set of all sets of -terms of sort with variables in — that is, all — for which holds. It is thus a subset of the powerset of : the collection of those term-languages at sort that are "-regular" in the sense of the predicate above.
Confirmed by the mission captain (proposal self-audit).