The subterm order
DefinitionMSKleene_SubtermThe subterm order on the free many-sorted algebra (Definitions 2.30, 3.7, 3.8).
ImmSub a b holds when the sorted term a (an element of the coproduct , STerm) is an immediate argument of b in b's unique decomposition. Its transitive closure SubtermLT is the strict proper-subterm order <; its reflexive–transitive closure SubtermLE is ≤; Min b says b has no proper subterm; Subt P is the -sorted set of subterms of P. TermVec.Mem is entry membership in an argument vector.
Proposition 3.6 (a milestone) states that SubtermLT is Artinian and that its minimal elements are exactly the variables and the constant symbols.
/-
The subterm order on the free many-sorted algebra (Definitions 2.30, 3.7).
`ImmSub a b` holds when the sorted term `a` is an immediate argument of `b`
(one decomposition step). Its transitive closure `SubtermLT` is the strict
proper-subterm order `<`, its reflexive–transitive closure `SubtermLE` is `≤`,
and `Min` picks out the minimal sorted terms.
Proposition 3.6 (`PArtOrd`) — proved as a milestone — states that `SubtermLT` is
Artinian (well-founded) on the free algebra and that its minimal elements are
exactly the variables and the constant symbols.
-/
import Definitions.Def_MSKleene_Term
import Mathlib.Logic.Relation
namespace MSKleene
universe u
variable {S : Type u} {sig : Signature S} {X : SSet S}
/-- A **sorted term**: an element of the coproduct `∐_s T_Σ(X)_s`. -/
def STerm (sig : Signature S) (X : SSet S) : Type u := Σ s : S, Term sig X s
/-- `p` occurs as one of the entries of the term vector `ts`. -/
inductive TermVec.Mem {sig : Signature S} {X : SSet S} :
{t : S} → {w : List S} → Term sig X t → TermVec sig X w → Prop
| head {t : S} {w : List S} (p : Term sig X t) (ps : TermVec sig X w) :
TermVec.Mem p (.cons p ps)
| tail {t s : S} {w : List S} {p : Term sig X t} (q : Term sig X s)
{ps : TermVec sig X w} : TermVec.Mem p ps → TermVec.Mem p (.cons q ps)
/-- The immediate-subterm relation `<_{T_Σ(X)}` (Definition 2.30): `a` is an
immediate argument of `b` in `b`'s unique decomposition. -/
def ImmSub (a b : STerm sig X) : Prop :=
∃ (w : List S) (σ : sig w b.1) (ts : TermVec sig X w),
b.2 = Term.app σ ts ∧ TermVec.Mem a.2 ts
/-- The strict proper-subterm order `<` — the transitive closure of `ImmSub`. -/
def SubtermLT (a b : STerm sig X) : Prop := Relation.TransGen ImmSub a b
/-- The subterm order `≤` — the reflexive–transitive closure of `ImmSub`. -/
def SubtermLE (a b : STerm sig X) : Prop := Relation.ReflTransGen ImmSub a b
/-- A sorted term is **minimal** when it has no proper subterm. -/
def Min (b : STerm sig X) : Prop := ∀ a : STerm sig X, ¬ ImmSub a b
/-- `Subt P` — the `S`-sorted set of subterms of `P` (Definition 3.8). -/
def Subt {s : S} (P : Term sig X s) : SSub (Term sig X) :=
fun t => { Q : Term sig X t | SubtermLE ⟨t, Q⟩ ⟨s, P⟩ }
end MSKleene
Read-back
What the Lean code literally says, in plain math · claude-sonnet-5
Setup common to every declaration. A type is fixed (the sorts); its elements are drawn from universe . A signature over is a family that assigns to every pair , where is a finite list of sorts and is a single sort, a type whose elements are operation symbols of input profile and output sort . An object of type is a family assigning to each sort a type of variables of sort . The type family and the type family are defined by mutual induction: a term of sort is either for some variable , or where is an operation symbol and is a term-vector over ; a term-vector over a list is either (over the empty list ) or (over ), formed from a term of sort and a term-vector over . In the file, and are implicit parameters of every declaration below (except where re-declared explicitly).
. Given an explicit signature over and an explicit variable family , the type is defined to be the dependent sum
that is, the type of pairs consisting of a sort together with a term of sort (over signature with variables in ). It is placed in universe . For an element , its first component is the sort and its second component is the term.
. This defines, for the fixed , , , an inductive proposition-valued relation. Its full argument list is: an implicit sort , an implicit list of sorts , an (explicit) term of sort , and an (explicit) term-vector over ; the statement asserts that occurs as an entry of the term-vector . It is generated by exactly two constructors:
- head: for every sort , every list , every term of sort , and every term-vector over , one has — the vector obtained by prepending (the same term , so this is the strict/heterogeneous equality forced by the constructor) to , which is a term-vector over .
- tail: for all sorts , every list , every term of sort (implicit), every term of sort (explicit), and every term-vector over (implicit), if holds then holds, where is a term-vector over .
In particular no term is a member of , and membership of (of sort ) in a vector over is derivable only when actually occurs among the sorts listed in at a position holding a term equal to .
. For two sorted terms , the proposition (" is an immediate subterm of ") is defined to hold iff there exist a list of sorts , an operation symbol (input profile , output sort equal to the sort of ), and a term-vector over , such that both:
The first conjunct is an equality of terms of sort stating that the term component of is literally the application of to ; the second conjunct states that the term component of (a term of sort ) occurs as an entry of the vector . Nothing constrains except through this membership. If is a variable, or an application whose argument vector is , then no such with a member exist and is false for every .
. For sorted terms , the proposition is defined to be the transitive closure of the relation : there is a finite chain with and for each . At least one step is required; this relation is not reflexive.
. For sorted terms , the proposition is defined to be the reflexive–transitive closure of the relation : either , or there is a finite chain of one or more steps from to . Equivalently, a chain of zero or more steps connects to .
. For a sorted term , the proposition is defined as
i.e. no sorted term is an immediate subterm of . Given the definition of , this holds exactly when the term component of is a variable, or is an application whose argument term-vector has no entries (is ).
. Given an implicit sort and a term of sort , the object has type , which unfolds to : an -indexed family of sets of terms. It is defined by
that is, for each sort , the set of all terms of sort such that the sorted term stands in the relation to the sorted term — i.e. is reachable from... reachable to by zero or more steps (a non-strict subterm of , allowing when ).
Confirmed by the mission captain (proposal self-audit).