as a regular algebra; interpretation
DefinitionMSKleene_RegAlgebraThe -algebra structure on (Proposition 4.3) and the interpretation homomorphism (Remark 4.5).
On the carrier , regPowerAlgebra interprets the extra symbols as
while every acts as . interp is the homomorphism from the free regular-expression algebra induced by the assignment z ↦ {z}, and interpExpr sig Z s R is the language denoted by a regular expression R of type s.
/-
The `Reg(S,Σ,Z)`-algebra structure on the power algebra `T_Σ(Z)^℘`
(Proposition 4.3), and the interpretation homomorphism `{·}^{Z♯}` sending a
regular expression to the language it denotes (Remark 4.5).
Interpretation of the extra symbols on `T_Σ(Z)^℘`:
`∅_s ↦ ∅`, `+_s ↦ (∪)`, `(·)^{⋆z} ↦ z`-iteration,
`⟨z/·⟩^♯ᵖ_s(·) ↦ z`-substitution; every `σ ∈ Σ` acts as `σ^{T_Σ(Z)^℘}`.
-/
import Definitions.Def_MSKleene_RegSig
import Definitions.Def_MSKleene_Power
import Definitions.Def_MSKleene_Subst
import Definitions.Def_MSKleene_Iteration
namespace MSKleene
universe u
variable {S : Type u} {sig : Signature S}
/-- `T_Σ(Z)^℘` as a `Reg(S,Σ,Z)`-algebra (Proposition 4.3). -/
noncomputable def regPowerAlgebra (sig : Signature S) (Z : SSet S) :
Algebra (regSig sig Z) where
carrier := fun s => Set (Term sig Z s)
op := fun {w s} sym args =>
match w, s, sym, args with
| _, _, .base σ, args => powerOp (freeAlgebra sig Z) σ args
| _, s, .empty _, _ => (∅ : Set (Term sig Z s))
| _, _, .iter _ z, args => iterate z args.1
| _, _, .plus _, args => args.1 ∪ args.2.1
| _, _, .subst _ s z, args => substP z args.1 s args.2.1
/-- The generator assignment `{·}^Z : Z → T_Σ(Z)^℘`, `z ↦ {z}` (Remark 4.5). -/
noncomputable def regGenAssign (sig : Signature S) (Z : SSet S) :
SMap Z (regPowerAlgebra sig Z).carrier :=
fun s z => ({Term.var z} : Set (Term sig Z s))
/-- The interpretation homomorphism `{·}^{Z♯} : T_{Reg(S,Σ,Z)}(Z) → T_Σ(Z)^℘`
(Remark 4.5). -/
noncomputable def interp (sig : Signature S) (Z : SSet S) :
Hom (freeAlgebra (regSig sig Z) Z) (regPowerAlgebra sig Z) :=
evalHom (regPowerAlgebra sig Z) (regGenAssign sig Z)
/-- `{R}^{Z♯}_s` — the language of `T_Σ(Z)_s` denoted by the regular expression
`R` of type `s`. -/
noncomputable def interpExpr (sig : Signature S) (Z : SSet S) (s : S)
(R : RegExpr sig Z s) : Set (Term sig Z s) :=
(interp sig Z).toFun s R
end MSKleene
Read-back
What the Lean code literally says, in plain math · claude-sonnet-5
regPowerAlgebra
This is a noncomputable definition. Fix an implicit type of sorts, an explicit signature over (so for every list of sorts and every sort , is the type of operation symbols with input-sort-list and output sort ), and an explicit sort-indexed family of variables . Write for the type of terms of sort built from -operations and from variables taken from the families ; a term is either for some variable , or applying an operation symbol to a tuple of subterms matching . The definition produces an algebra for the extended signature , whose operation-symbol type at arity is the inductive type with exactly five constructors:
- for any , of arity ;
- , of arity ;
- carrying a variable , of arity ;
- , of arity ;
- carrying a variable , of arity .
The carrier of at sort is , the type of arbitrary sets of -terms of sort with variables in . The operation map takes an operation symbol of of arity together with an argument tuple that supplies, for each sort listed in , a set of terms of that sort, and is defined by case analysis on the symbol:
- with : the result is i.e. the set of all terms whose -th immediate subterm ranges independently over the -th argument set. (Membership of the tuple in the product is checked componentwise; for the condition is vacuously true, so the result is the singleton .)
- at output sort (here ): the result is the empty set ; the argument tuple is discarded.
- carrying a variable (arity ): the result is , where is the single argument set (a set of -sorted terms). By definition
where is the substitution operator described in the bullet below (each stage adds all terms obtained by replacing occurrences of in terms of by elements of ). Because is always included, contains the bare-variable term for every , including .
- (arity ): the result is , the ordinary set-theoretic union of the two argument sets (both sets of -sorted terms).
- carrying a variable (arity , with the first sort recovered implicitly from the symbol): the result is , where and . Here
where is the underlying sorted map of the evaluation homomorphism from the free (term) algebra on into the "power algebra" of that free algebra, induced by the assignment that sends a variable of sort to the set when and , and to the singleton in every other case. Concretely is the set of all terms obtained from by replacing each occurrence of the variable (of sort ) by some element of , with the choice made independently at each occurrence, and leaving all other variables unchanged; then unions these sets over all in (so if the result is ).
regGenAssign
This is a noncomputable definition with the same fixed data: an implicit sort type , an explicit signature over , and an explicit variable family . It defines a sorted map from the variable family into the carrier family of the algebra (whose value at sort is ). For each sort and each variable , the map returns the one-element set , i.e. the singleton whose only member is the term consisting solely of the variable . If is empty for some , the map at that sort is vacuous.
interp
This is a noncomputable definition with fixed data: an implicit sort type , an explicit signature over , and an explicit variable family . It defines a homomorphism of algebras over the signature , with:
- domain — the free (term) algebra over the extended signature with variable family , whose carrier at sort is (the terms of sort over the extended signature, i.e. the "regular expressions" of sort ), and whose operation on symbol and argument tuple is ;
- codomain , the algebra of the previous definition (carrier , operations as spelled out there).
It is defined as : the evaluation homomorphism whose underlying sorted map sends a regular-expression term of sort to its value obtained by structural term-evaluation in under the generator assignment . Unfolding the recursion: a variable is sent to the singleton ; an application , with an operation symbol of , is sent to the -interpretation of (elementwise application for , for , the union for , set union for , the operator for — exactly as described for regPowerAlgebra) applied to the recursively computed value-sets of . The value produced is a full homomorphism structure, and hence also bundles the proof that this sorted map commutes with every operation symbol of .
interpExpr
This is a noncomputable definition. It takes an implicit sort type , an explicit signature over , an explicit variable family , an explicit sort , and an explicit argument , where is by definition — a term of sort over the extended signature with variables drawn from . It returns
i.e. the image of under the underlying sorted map of the homomorphism at sort . Concretely this is the set of -terms of sort over obtained by recursively interpreting as in interp: singletons for variables, elementwise application for symbols, for , set union for , the iterate-union for , and the substitution operator for , applied bottom-up over the structure of .
Confirmed by the mission captain (proposal self-audit).