Recognition context and the auxiliary languages
DefinitionMSKleene_AuxLangThe recognition context KleeneCtx and the auxiliary languages of the proof of Proposition 4.10; the object of the Main Claim (Claim 4.13).
A KleeneCtx packages the data produced at the start of that proof: a state-count function so the finite recognizing algebra has carrier with operations Nop; the recognizing map fgen on generators, extending to ; and, derived from these, (extVars), the map that is on and the identity on , and .
For , a set of leaf-admissible states, a sortwise budget (where is read as the set of state values still admissible at internal subterms), and a target state , auxLang u C K l is the set of terms such that (a) ; (b) every proper non-minimal subterm of with variables in has at its sort; (c) .
Term.varsIn is the predicate 'every variable of the term satisfies a given condition'.
/-
The recognition context and the auxiliary languages `L_u(C,K,l)` of the proof
of Proposition 4.10 (`PRectoReg`); the object of the Main Claim (Claim 4.13).
A `KleeneCtx` packages the data produced at the start of that proof:
* `n : S → ℕ`, so the finite recognizing algebra `N` has carrier
`s ↦ Fin (n s)` and operations `Nop`;
* `fgen`, the recognizing map on generators, extending to `f^♯ : T_Σ(X) → N`;
* from these, `Z = X ∪ N` (`extVars`), the map `h : Z → N` with
`h(x) = f^♯(x)` on `X` and `h = id` on `N`, and `h^♯ : T_Σ(Z) → N`.
For `u ∈ S`, `C ⊆ N` (states allowed at leaves), a sortwise budget
`K ≤ N` (`K t` = the set `{0,…,K t−1}` of state values still admissible at
internal subterms), and `l ∈ N_u`, `auxLang u C K l` is the set of terms
`P ∈ T_Σ(Z)_u` with: (a) `P ∈ T_Σ(X ∪ C)`; (b) every proper non-minimal
subterm `Q` of `P` (with variables in `X ∪ C`) has `h^♯(Q) < K`; (c) `h^♯(P) = l`.
The whole file works at sort universe `0`, matching the mission's theorem
statements (`S : Type`), because the recognizing algebra has carrier `Fin (n s)`.
-/
import Definitions.Def_MSKleene_Subterm
import Definitions.Def_MSKleene_RegAlgebra
import Definitions.Def_MSKleene_Regular
namespace MSKleene
variable {S : Type} {sig : Signature S} {X : SSet S}
-- `Term.varsIn pred P` — every variable occurring in `P` satisfies `pred`.
mutual
def Term.varsIn (pred : (t : S) → X t → Prop) : {s : S} → Term sig X s → Prop
| _, .var x => pred _ x
| _, .app _ ts => TermVec.varsAllIn pred ts
def TermVec.varsAllIn (pred : (t : S) → X t → Prop) :
{w : List S} → TermVec sig X w → Prop
| _, .nil => True
| _, .cons t ts => Term.varsIn pred t ∧ TermVec.varsAllIn pred ts
end
/-- The data extracted at the start of the proof of Proposition 4.10: a finite
recognizing algebra `N` with carrier `s ↦ Fin (n s)`, and a recognizing map
`fgen` on the generators. -/
structure KleeneCtx (sig : Signature S) (X : SSet S) where
/-- state counts: `N_s = Fin (n s)`. -/
n : S → ℕ
/-- operations of the finite recognizing algebra `N`. -/
Nop : {w : List S} → {s : S} → sig w s → Args (fun s => Fin (n s)) w → Fin (n s)
/-- the recognizing map on generators, `X → N`. -/
fgen : SMap X (fun s => Fin (n s))
namespace KleeneCtx
variable (ctx : KleeneCtx sig X)
/-- The finite recognizing algebra `N`. -/
def NAlg : Algebra sig := ⟨fun s => Fin (ctx.n s), ctx.Nop⟩
/-- The set of variables `Z = X ∪ N` of the proof. -/
def Z : SSet S := extVars X (fun s => Fin (ctx.n s))
/-- The recognizing homomorphism `f^♯ : T_Σ(X) → N`. -/
def fHom : Hom (freeAlgebra sig X) ctx.NAlg := evalHom ctx.NAlg ctx.fgen
/-- The assignment `h : Z → N`: `h(x) = f^♯(x)` on `X`, `h = id` on `N`. -/
def hAssign : SMap ctx.Z (fun s => Fin (ctx.n s)) :=
fun s z => Sum.elim (ctx.fgen s) id z
/-- The homomorphism `h^♯ : T_Σ(Z) → N`. -/
def hHom : Hom (freeAlgebra sig ctx.Z) ctx.NAlg := evalHom ctx.NAlg ctx.hAssign
/-- `h^♯` of a sorted term, as a natural number (its state value). -/
def hVal (Q : STerm sig ctx.Z) : ℕ := (ctx.hHom.toFun Q.1 Q.2).val
/-- `P` has variables only in `X ∪ C` (states from `C` allowed at leaves). -/
def inXC (C : (s : S) → Set (Fin (ctx.n s))) (t : S) (z : ctx.Z t) : Prop :=
Sum.elim (fun _ => True) (fun m => m ∈ C t) z
/-- The auxiliary language `L_u(C,K,l)` (proof of Proposition 4.10). -/
def auxLang (u : S) (C : (s : S) → Set (Fin (ctx.n s))) (K : S → ℕ)
(l : Fin (ctx.n u)) : Set (Term sig ctx.Z u) :=
{ P |
Term.varsIn (ctx.inXC C) P ∧
(∀ Q : STerm sig ctx.Z, SubtermLT Q ⟨u, P⟩ → ¬ Min Q →
Term.varsIn (ctx.inXC C) Q.2 → ctx.hVal Q < K Q.1) ∧
ctx.hHom.toFun u P = l }
end KleeneCtx
end MSKleene
Read-back
What the Lean code literally says, in plain math · claude-sonnet-5
Term.varsIn and TermVec.varsAllIn (mutual)
These two mutually recursive predicates are parameterized by a fixed sort type , a signature over , an -sorted family of variable sets (so is the set of variables of sort ), and a predicate that assigns to every sort and every variable a proposition . Given an implicit sort and a term of sort built over with variables drawn from , the proposition is defined by structural recursion: if is a variable leaf (with ), then is ; if is an operator application (an operation symbol applied to an argument vector ), then is . The companion acts on a term-vector of type (a list of sorts): it is when is the empty vector, and when is a cons cell . Consequently holds exactly when every variable occurrence appearing anywhere in the tree of satisfies at its sort; for a term with no variable leaves (all leaves being nullary operator applications) the predicate is vacuously .
KleeneCtx
is a structure (record), parameterized by a signature over the sort type and an -sorted variable family , that bundles three fields. The first field is a function assigning a natural number to each sort. The second field is, for every list of sorts , every sort , and every operation symbol , a function that takes an argument tuple whose -th component lies in (the type , empty when ) — one component per sort listed in — and returns an element of . The third field is an -indexed map that assigns to each sort and each variable an element of . Nothing in the structure forbids for some sorts. Throughout the remaining declarations, denotes an arbitrary term of this structure type.
KleeneCtx.NAlg
For a context , is the -algebra whose carrier at each sort is the finite type and whose interpretation of operation symbols is the field . In other words it packages together with into an .
KleeneCtx.Z
is the -sorted family defined by , the disjoint-sum (tagged union) of the original variable set at sort with the finite type . This uses , whose value at sort is . Thus an element of is either a left-tagged original variable with , or a right-tagged numeral with .
KleeneCtx.fHom
is the -algebra homomorphism from the free -algebra on the variable family (whose carrier at sort is the set of terms ) to the algebra , obtained as the evaluation homomorphism induced by the assignment . Its underlying map sends a term of sort to : each variable leaf is sent to , and each application is sent to applied to the recursively evaluated arguments. It also carries the proof that this map commutes with all operations.
KleeneCtx.hAssign
is the -indexed map from to the family defined case-wise on the sum: for a sort and an element , if it returns , and if it returns itself (the identity on the numeral component).
KleeneCtx.hHom
is the -algebra homomorphism from the free -algebra on the family (carrier at sort equal to the terms ) to , obtained as the evaluation homomorphism induced by . Its underlying map sends a term of sort over the variable family to its value in , where a left-tagged leaf is evaluated via , a right-tagged leaf is evaluated to , and applications are evaluated via .
KleeneCtx.hVal
takes a sorted term over the family — that is, an element of , a dependent pair consisting of a sort and a term of sort over — and returns the natural number , i.e. the underlying of the element (its representative in ).
KleeneCtx.inXC
takes a family assigning to each sort a subset , a sort , and an element , and returns a proposition by case analysis on the sum: if (an original variable) the proposition is ; if (a numeral) the proposition is .
KleeneCtx.auxLang
Fix a context (with , , implicit). Given a sort , a family with for every sort , a function , and a target element , the term is a subset of the terms of sort over the signature with variables in the family (where ). It consists of exactly those terms of sort over satisfying the conjunction of all three of the following conditions.
(1) Variable-membership condition. holds: every variable leaf occurring in satisfies at its sort; equivalently, every numeral leaf of some sort appearing in has , while original-variable leaves impose no constraint.
(2) Strict-subterm value bound. For every sorted term over (an element of , with sort and term ) such that
it must hold that
that is, the natural number is strictly less than evaluated at the sort of . Here:
- is the transitive closure (one or more steps) of the immediate-subterm relation applied to the pair and the sorted term ; holds when 's term component is an application for some symbol and argument vector , and 's term component occurs as one of the entries of . So ranges over the proper subterms of (paired with their sorts) reachable by at least one descent step.
- is the negation of the statement "", where means that no sorted term satisfies ; i.e. says it is not the case that has no immediate subterm, so is an application to a non-empty argument vector (it is not a variable leaf and not a nullary application).
- says every variable leaf of satisfies , as in condition (1).
If no meets all three antecedents (for instance when is itself a variable or a shallow term), condition (2) is vacuously satisfied. If for some qualifying one has , then is impossible (values are natural numbers), so any admitting such a is excluded.
(3) Evaluation target condition. : evaluating through the homomorphism into (numeral leaves interpreted as themselves, original-variable leaves via , operations via ) yields exactly the prescribed element of .
Confirmed by the mission captain (proposal self-audit).