Theorems 2 and 3 (Sections 5.4.1 & 5.4.3, pp. 35–37): (1) semantic monotonicity and soundness of syntactic size well-formedness (SizeWf), weak inequality (SizeLe), and strict inequality (SizeLt) under ordered size valuations SizeValLe Ψ ρ ρ'; and (2) the Fundamental Theorem of Reducibility (SemExprTyping and SemClausesTyping) for well-typed expressions and copattern clauses under guarded recursive block validity.
Superseded. This is the first formalization of Theorems 2–3 (pp. 36–37) of
the thesis. It is refuted through its Theorem 3 conjunct by the disproof
33af96b2-4760-46a4-b568-514c51eb7ee9: the existing signature declares a function of unit type
with no clauses, and the new block declares a function with the same name whose
clause calls it. The signature alone is valid and the reference is typable, but
with the block present the reference reduces to itself forever, so it is not in
the interpretation of the unit type. The thesis assumes that existing functions
were checked earlier and cannot refer to the current block (§5.4.2); the formal
statement does not. Corrected statement: NishtAbel2024V2.theorems_2_and_3. It
assumes a well-scoped block extension (scopeBlockExtension) and uses revised
semantics for quantifiers and inductive types, which also resolve two further
checked counterexamples to the original Theorem 3.
namespace NishtAbel2024
/-- Theorem 2 (Soundness of kind-level judgments, p. 36) and
Theorem 3 (Soundness of expression typing in System `F_ω^{cop, SCT}`, pp. 36–37):
1. (**Theorem 2**) For any well-formed size context `⊢ Ψ` and ordered valuations
`ρ ≤ ρ' ∈ ⟦Ψ⟧`:
- `Ψ ⊢ a ⟹ ⟦a⟧_ρ ≤ ⟦a⟧_{ρ'}`
- `Ψ ⊢ a ≤ b ⟹ ⟦a⟧_ρ ≤ ⟦b⟧_{ρ'}`
- `Ψ ⊢ a < b ⟹ ⟦a⟧_ρ < ⟦b⟧_{ρ'}`.
2. (**Theorem 3**) Under semantic validity `⊨ Σ`, well-formed contexts `⊢ Δ`, `Δ ⊢ Γ`,
`Δ ⊢ C ⇐ *`, `⊢ G`, and guarded block validity `G, ⟦Ψ_f⟧ ⊨ Ξ`, bidirectional expression
inference, expression checking, and clause checking imply semantic membership in the
reducibility candidate `⟦C⟧`. -/
theorem theorems_2_and_3 :
(∀ (Ψ : SizeCtx) (ρ ρ' : SizeVal),
SizeCtxWf Ψ →
SizeValLe Ψ ρ ρ' →
(∀ a : SizeExp, SizeWf Ψ a → SizeOrd.le (evalSizeExp ρ a) (evalSizeExp ρ' a)) ∧
(∀ a b : SizeExp, SizeLe Ψ a b → SizeOrd.le (evalSizeExp ρ a) (evalSizeExp ρ' b)) ∧
(∀ a b : SizeExp, SizeLt Ψ a b → SizeOrd.lt (evalSizeExp ρ a) (evalSizeExp ρ' b))) ∧
(∀ (Ω : TypingEnv) (Δ : KindingCtx) (Γ : TermCtx) (C : TypeExpr),
SemSigValid Ω.sig →
SizeCtxWf Δ.sizes →
TermCtxWf Δ Γ →
KindCheck Δ C .star →
SCTValid Ω.graphs →
(∀ ρ ∈ evalKindingCtx Δ,
SemBlockGuardedValid Ω.sig Ω.block Ω.graphs Ω.caller Ω.callerSizes ρ) →
(∀ r : Term, ExprInfer Ω Δ Γ r C → SemExprTyping Ω.sig Ω.block Δ Γ r C) ∧
(∀ r : Term, ExprCheck Ω Δ Γ r C → SemExprTyping Ω.sig Ω.block Δ Γ r C) ∧
(∀ Ds : List Clause,
(∀ D ∈ Ds, ClauseCheck Ω Δ Γ D C) →
SemClausesTyping Ω.sig Ω.block Δ Γ Ds C)) := by
sorry
end NishtAbel2024
Source
Kanstantsin Nisht, 'Type-Based Termination Checking in Agda', Master's Thesis in Computer Science and Engineering, Chalmers University of Technology and University of Gothenburg (supervised by Andreas Abel), 2024; extended abstract by Kanstantsin Nisht and Andreas Abel, 30th International Conference on Types for Proofs and Programs (TYPES 2024). Section 5.4, Theorem 2 (p. 35) and Theorem 3 (pp. 36–37).
Read-back
What the Lean code literally says, in plain math · Gemini 3.1 Pro (Independent Blind Auditor)
The declaration NishtAbel2024.theorems_2_and_3 asserts the conjunction T2∧T3 of two propositions: semantic monotonicity and soundness of syntactic size judgments (T2), and semantic soundness of syntactic expression and clause typing with respect to reducibility candidates (T3).
Definitions for T2 (Polarities, Size Expressions, and Size Valuations).
Polarities: The set of polarities is Polarity={∘,+,−,⊤} (mixed, pos, neg, top), ordered by ∘≤π, π≤⊤, +≤+, and −≤− (all other pairs false). Composition π1⋅π2 (Polarity.comp) satisfies ⊤⋅π=π⋅⊤=⊤, ∘⋅π=π⋅∘=∘, +⋅π=π⋅+=π, and −⋅−=+. Left-inverse composition π−1π′ (Polarity.invComp) is defined by ⊤−1π′=∘, ∘−1∘=∘, ∘−1π′=⊤ for π′=∘, +−1π′=π′, and −−1π′=−⋅π′.
Size expressions: Size variables are natural numbers (SizeVar=N). A shifted size variable (i,n) represents i+n (i,n∈N). A formal minimum m∈SizeMin is a non-empty list of shifted size variables (i0,n0),…,(ik,nk). A size expression a∈SizeExp is either inf(n) for n∈N (representing ∞+n, with ∞=inf(0)) or meet(m) for m∈SizeMin (representing min(i,n)∈m(i+n), with var(i,n)=meet([(i,n)])). Shifting a.shift(k) maps inf(n) to inf(n+k) and adds k to every shift in meet(m). Bound normalization a.boundNorm maps inf(n) to inf(1) for all n∈N and leaves meet(m) unchanged.
Size contexts and syntactic size relations: A size context Ψ∈SizeCtx is a list of declarations (i,π,a)∈N×Polarity×SizeExp. Its domain Ψ.dom is the list of declared variables; Ψ.scalePol(π) replaces each declaration's polarity πd with π⋅πd; and Ψ.invScalePol(π) replaces πd with π−1πd.
SizeVarBound(Ψ,i,a) holds iff there exists π∈{∘,+} such that (i,π,a)∈Ψ.
SizeWf(Ψ,a) holds trivially if a=inf(n), and for a=meet(m) iff every (i,n)∈m has some b with SizeVarBound(Ψ,i,b).
SizeCtxWf(Ψ) holds inductively for [], and for Ψ++[(i,π,a)] when SizeCtxWf(Ψ), i∈/Ψ.dom, and SizeWf(Ψ.invScalePol(∘),a) (meaning every size variable in a occurs in Ψ with polarity ∘).
SizeLt(Ψ,a,b) (Ψ⊢a<b) is the inductive relation generated by:
SizeLe(Ψ,a,b) (Ψ⊢a≤b) is defined as SizeLt(Ψ,a,b.shift(1)).
Semantic evaluation of sizes: A size valuation is a function ρ:N→SizeOrd. The evaluation [[a]]ρ (evalSizeExp ρ a) maps inf(n) to (1,n) and meet(m) to the <ord-minimum over (i,n)∈m of (ρ(i).tier,ρ(i).offset+n).
ValidSizeVal(Ψ,ρ) holds iff for every (i,π,a)∈Ψ, ρ(i)<ord[[a]]ρ.
SizeValLe(Ψ,ρ,ρ′) holds iff ValidSizeVal(Ψ,ρ), ValidSizeVal(Ψ,ρ′), and for every (i,π,a)∈Ψ: ρ(i)=ρ′(i) if π=∘; ρ(i)≤ordρ′(i) if π=+; ρ′(i)≤ordρ(i) if π=−; and no constraint if π=⊤.
Statement of First Conjunct (T2).
For every size context Ψ∈SizeCtx and all size valuations ρ,ρ′:N→SizeOrd, if SizeCtxWf(Ψ) and SizeValLe(Ψ,ρ,ρ′) hold, then:
For all a∈SizeExp, if SizeWf(Ψ,a), then [[a]]ρ≤ord[[a]]ρ′.
For all a,b∈SizeExp, if SizeLe(Ψ,a,b), then [[a]]ρ≤ord[[b]]ρ′.
For all a,b∈SizeExp, if SizeLt(Ψ,a,b), then [[a]]ρ<ord[[b]]ρ′.
Definitions for T3 (Types, Terms, Reduction, Reducibility Candidates, and Typing).
Kinds and types: Kinds are generated by κ::=⋆∣<a∣κ1πκ2 (Kind), with simple kinds ι::=⋆∣prop∣ι1πι2 (SKind). Subkinding Ψ⊢κ≤κ′ (SubKind) is reflexive on ⋆, covariant in a via SizeLe on <a, contravariant in the polarity (π′≤π) and domain kind (in Ψ.scalePol(−)) and covariant in the codomain kind on κ1πκ2. A kinding context Δ=(Δ.sizes,Δ.types) consists of a SizeCtx and a list of type declarations (X,π,κ)∈N×Polarity×Kind. Extending Δ with (X,π,κ) via Δ.extType(X,π,κ) appends (X,π,κ) to Δ.types and, when κ=<a, also appends (X,π,a) to Δ.sizes.
Type expressions A,B,C,F,G∈TypeExpr are generated by atoms (unit, prod, arr, all(κ), ex(κ), size(a), var(X)), type abstraction lam(X,ι,F), type application app(F,G), inductive types μa.S (S∈List(N×TypeExpr)), and coinductive types νa.R (R∈List(N×TypeExpr)). Normalized application F.normApp(G) substitutes G for free var(X) in B if F=lam(X,ι,B) (without renaming bound variables of B that may be free in G), and otherwise forms app(F,G). KindInfer, KindCheck, SubTypeInfer, SubTypeCheck, and SubType (SubType(Δ,A,C)⟺SubTypeInfer(Δ,+,A,C,⋆)) define bidirectional kinding and polarized higher-kinded subtyping.
Terms and operational semantics: Terms r,s,t∈Term consist of variables var(x), function references funRef(f,as) (f∈N,as∈ListSizeExp), elimination applications app(r,e) where e∈Elim is term(s), tyArg(G), or proj(d,ma) (d∈N,ma∈OptionSizeExp), unit unit, pairs pair(t1,t2), constructors cons(c,ma,t), existential packages pack(G,t), pattern-matching clause lists lamClauses(Ds) (Ds∈ListClause, each clause mk(qs,t) pairing a copattern spine qs with a right-hand side term t), and type ascriptions ascr(t,A).
Given a global signature sig∈ListFunDecl and mutual block Ξ∈ListFunDecl, weak head reduction WhdStep(sig,Ξ,t,t′) strips head ascriptions ascr(t0,A) under any elimination spine es, reduces lamClauses(Ds) applied to es++es′ when some clause mk(qs,t0)∈Ds matches es via MatchSpine yielding substitutions (τ,σ) (producing ((t0.substTypes(τ)).substTerms(σ)) applied to es′), and similarly unfolds funRef(decl.name,as) for any decl∈sig++Ξ by also substituting decl.sizeParams.dom.zip(as).
Full one-step reduction RedStep(sig,Ξ,t,t′) is the compatible closure of WhdStep under pairs, constructors, existential packages, applications (function and term argument), ascriptions, and clause bodies inside lamClauses. SN(sig,Ξ,t) asserts that t is accessible (strongly normalizing) under RedStep(sig,Ξ).
Reducibility candidates and semantic types:
A term t is an introduction form (IsIntro(t)) iff t is unit, pair, cons, or pack.
A term t is neutral (IsNeutral(sig,Ξ,t)) iff ¬IsIntro(t) and either (∃t′,WhdStep(sig,Ξ,t,t′)) or (∀es,t′,¬WhdStep(sig,Ξ,appSpine(t,es),t′)).
A set of terms A⊆Term is a candidate (IsCandidate(sig,Ξ,A)) iff: (1) A⊆SN(sig,Ξ); (2) A is closed under RedStep(sig,Ξ); (3) every neutral term t whose one-step reducts all lie in A is in A; and (4) every non-introduction term t whose one-step reducts lie in A and whose weak head steps under any spine es are simulated by some rk in a finite list ts⊆A is in A.
candClosure(sig,Ξ,X) is the intersection of all candidates C containing X∩SN(sig,Ξ) (intersected with SN(sig,Ξ)).
Semantic type evaluation [[C]]ρ,ηsig,Ξ (evalTypeWith) interprets types as sets of terms by structural recursion on C (and well-founded recursion on [[a.boundNorm]]ρ under <ord for μa.S and νa.R), closing each base/constructor case under candClosure(sig,Ξ,−) and evaluating app(lam(X,ι,B),G) as [[B]]ρ,η[X↦[[G]]ρ,η]sig,Ξ. In particular, [[C]]ρsig,Ξ (evalType sig Ξ ρ C) evaluates C with the empty candidate environment η0 mapping every type variable X∈N to candClosure(sig,Ξ,∅).
Syntactic and semantic typing judgments:
A typing environment Ω=(sig,block,graphs,caller,callerSizes) bundles a global signature, a local mutual block, an invocation graph family, a caller function name, and a caller size context.
ExprInfer, ExprCheck, and ClauseCheck are mutually defined syntactic typing judgments Ω;Δ;Γ⊢r⇒C, Ω;Δ;Γ⊢r⇐C, and Ω;Δ;Γ⊢D⇐C.
ValidSizeTuple(Ψ,αs) holds iff ∣αs∣=∣Ψ∣ and ValidSizeVal(Ψ,SizeVal.ofList(Ψ.dom.zip(αs))).
SemSigValid(sig) holds iff for every decl∈sig, SN(sig,[],lamClauses(decl.clauses)) holds and for all as∈ListSizeExp and ρ:N→SizeOrd with ValidSizeTuple(decl.sizeParams,as.map([[−]]ρ)), we have funRef(decl.name,as)∈[[decl.ty]]ρdeclsig,[], where ρdecl=SizeVal.ofList(decl.sizeParams.dom.zip(as.map([[−]]ρ))).
SemBlockGuardedValid(sig,Ξ,G,fcaller,Ψcaller,ρcaller) holds iff for every decl∈Ξ, as∈ListSizeExp, and ρ, letting αcaller=Ψcaller.map(λd⇒ρcaller(d.var)) and αcallee=as.map([[−]]ρ), if ValidSizeTuple(decl.sizeParams,αcallee) and ∃G∈G.graphs(fcaller,decl.name) with OrdConformsToGraph(G,αcallee,αcaller), then funRef(decl.name,as)∈[[decl.ty]]SizeVal.ofList(decl.sizeParams.dom.zip(αcallee))sig,Ξ.
SemExprTyping(sig,Ξ,Δ,Γ,r,C) holds iff for all ρ∈evalKindingCtx(Δ) and all σ∈evalTermCtx(sig,Ξ,Γ,ρ), we have r.substTerms(σ)∈[[C]]ρsig,Ξ.
SemClausesTyping(sig,Ξ,Δ,Γ,Ds,C) is defined as SemExprTyping(sig,Ξ,Δ,Γ,lamClauses(Ds),C).
Statement of Second Conjunct (T3).
For every typing environment Ω∈TypingEnv, kinding context Δ∈KindingCtx, term context Γ∈TermCtx (where TermCtxWf(Δ,Γ) means KindCheck(Δ,A,⋆) holds for every (x,A)∈Γ), and type expression C∈TypeExpr, if:
SemSigValid(Ω.sig),
SizeCtxWf(Δ.sizes),
TermCtxWf(Δ,Γ),
KindCheck(Δ,C,⋆),
SCTValid(Ω.graphs), and
for every ρ∈evalKindingCtx(Δ), SemBlockGuardedValid(Ω.sig,Ω.block,Ω.graphs,Ω.caller,Ω.callerSizes,ρ),
then all three of the following hold:
For every term r∈Term, if ExprInfer(Ω,Δ,Γ,r,C), then SemExprTyping(Ω.sig,Ω.block,Δ,Γ,r,C).
For every term r∈Term, if ExprCheck(Ω,Δ,Γ,r,C), then SemExprTyping(Ω.sig,Ω.block,Δ,Γ,r,C).
For every list of clauses Ds∈ListClause, if ClauseCheck(Ω,Δ,Γ,D,C) holds for every D∈Ds, then SemClausesTyping(Ω.sig,Ω.block,Δ,Γ,Ds,C).
Edge Cases and Anomalies.
Fixed empty candidate environment in SemExprTyping:SemExprTyping substitutes only term variables (r.substTerms(σ)) and evaluates [[C]]ρsig,Ξ and [[A]]ρsig,Ξ in the fixed empty candidate environment η0 (mapping every free type variable X∈Δ.types to candClosure(sig,Ξ,∅)) rather than quantifying over candidate environments η and type/size substitutions for Δ.
Unrestricted bound variable j in ExprInfer.proj, ExprCheck.cons, PatTyping.cons, and SpineTyping.proj: In these rules, the size variable j∈N used to form ∀j<a.boundNorm or ∃j<a.boundNorm has no freshness side condition j∈/FV(Rd,R) or j∈/FV(Sc,S).
Confirmed by the moderator at approval.