Typing Soundness of Coherent Flexible Substitutions (Theorem 13) and Coherence of Algorithm 1 (Theorem 14 & Corollary)
DisprovedNishtAbel2024.theorems_13_and_14Theorems 13, 14, and Corollary (Section 6.4, pp. 56–58): (1) any coherent flexible substitution CoherentSubst (Ψ₁ ++ Ψ₂) Cs φ whose call sites satisfy LocalCallsConform turns the elaborated term t'.applyFlex φ into a well-typed System F_ω^{cop, SCT} expression (ExprCheck); (2) the substitution φ* := solveConstraintGraph (Ψ₁ ++ Ψ₂) Cs T computed by Algorithm 1 is coherent; and (3) consequently t'.applyFlex φ* is well-typed in System F_ω^{cop, SCT}.
Superseded. This is the first formalization of Theorems 13–14 and the
Corollary (pp. 56–58) of the thesis. It is refuted through its Theorem 13
conjunct by the accepted disproof 2d3a98aa-2e6e-4f98-9bc3-07dadd583b31. A global
function has a size parameter bounded by itself, . Call
inference instantiates that parameter with a fresh flexible size, Algorithm 1
assigns , and the resulting substitution is coherent, but the annotated
call cannot be typed, because is not derivable. The thesis assumes
well-formed global signatures, while the formal statement does not. The
Theorem 14 conjunct is not refuted. Corrected statement:
NishtAbel2024V2.theorems_13_and_14. It is weaker than the thesis's Theorem 13:
it takes the type-checking of each size-instantiated clause body as a hypothesis
(a final check added to Algorithm 2), and its Theorem 14 concerns a solver that
returns only substitutions passing a finite coherence check. Proving that
inference always yields well-typed output from a well-formed signature remains
open.
import Definitions.Def_NishtAbel2024_Syntax import Definitions.Def_NishtAbel2024_Inference
namespace NishtAbel2024
/-- Theorem 13 (Soundness of coherent substitutions, pp. 56–57),
Theorem 14 (Soundness of `φ*`, p. 58), and
Corollary (Correctness of Algorithm 1, p. 58):
1. (**Theorem 13**) Any coherent flexible substitution `φ` (`CoherentSubst (Ψ₁ ++ Ψ₂) Cs φ`)
satisfying `LocalCallsConform` turns the size-inferred term `t'` into a well-typed System
`F_ω^{cop, SCT}` term `ExprCheck ⟨sig, Ξ, 𝒢, f, Ψ₁⟩ ((Δ₀.extSizes Ψ₁).extDecls Δ) Γ (t'.applyFlex φ) C`.
2. (**Theorem 14**) Under the conditions of Theorem 12, the substitution
`φ* := solveConstraintGraph (Ψ₁ ++ Ψ₂) Cs T` computed by Algorithm 1 satisfies
`CoherentSubst (Ψ₁ ++ Ψ₂) Cs φ*`.
3. (**Corollary**) Combining Theorems 13 and 14, when `φ*(t')` satisfies `LocalCallsConform`,
`φ*(t')` is well-typed in System `F_ω^{cop, SCT}`. -/
theorem theorems_13_and_14 :
(∀ (sig : GlobalSig) (Ξ : MutualBlock) (𝒢 : InvGraphFamily) (f : FunName)
(Δ₀ : KindingCtx) (Ψ₁ Ψ₂ : SizeCtx) (A A₀ C : TypeExpr)
(qs qs' : PatSpine) (Γ : TermCtx) (Δ : List TyDecl)
(t t' : Term) (Φ : FlexVars) (Cs : List SizeConstraint) (T : List SizeVar)
(φ : FlexSubst),
EncodeType .neg .pos Δ₀ A Ψ₁ A₀ →
InferSpine (Δ₀.extSizes Ψ₁) qs A₀ C Γ Δ Ψ₂ qs' →
CheckTerm sig Ξ ((Ψ₁ ++ Ψ₂).map (fun d => (d.var, d.pol)))
Γ ((Δ₀.extSizes Ψ₁).append ⟨Ψ₂, Δ⟩) C t Φ Cs T t' →
CoherentSubst (Ψ₁ ++ Ψ₂) Cs φ →
LocalCallsConform Ξ 𝒢 f Ψ₁ (Ψ₁ ++ Ψ₂) (t'.applyFlex φ) →
ExprCheck ⟨sig, Ξ, 𝒢, f, Ψ₁⟩ ((Δ₀.extSizes Ψ₁).extDecls Δ) Γ (t'.applyFlex φ) C) ∧
(∀ (sig : GlobalSig) (Ξ : MutualBlock) (Δ₀ : KindingCtx)
(Ψ₁ Ψ₂ : SizeCtx) (A A₀ A'' : TypeExpr) (qs qs' : PatSpine)
(Γ : TermCtx) (Δ : List TyDecl) (t t' : Term)
(Φ : FlexVars) (Cs : List SizeConstraint) (T : List SizeVar),
SizeCtxWf (Ψ₁ ++ Ψ₂) →
EncodeType .neg .pos Δ₀ A Ψ₁ A₀ →
SignatureFixpointHygiene (Δ₀.extSizes Ψ₁) A₀ →
InferSpine (Δ₀.extSizes Ψ₁) qs A₀ A'' Γ Δ Ψ₂ qs' →
CheckTerm sig Ξ ((Ψ₁ ++ Ψ₂).map (fun d => (d.var, d.pol)))
Γ ((Δ₀.extSizes Ψ₁).append ⟨Ψ₂, Δ⟩) A'' t Φ Cs T t' →
CoherentSubst (Ψ₁ ++ Ψ₂) Cs (solveConstraintGraph (Ψ₁ ++ Ψ₂) Cs T)) ∧
(∀ (sig : GlobalSig) (Ξ : MutualBlock) (𝒢 : InvGraphFamily) (f : FunName)
(Δ₀ : KindingCtx) (Ψ₁ Ψ₂ : SizeCtx) (A A₀ C : TypeExpr)
(qs qs' : PatSpine) (Γ : TermCtx) (Δ : List TyDecl)
(t t' : Term) (Φ : FlexVars) (Cs : List SizeConstraint) (T : List SizeVar),
let φstar := solveConstraintGraph (Ψ₁ ++ Ψ₂) Cs T
SizeCtxWf (Ψ₁ ++ Ψ₂) →
EncodeType .neg .pos Δ₀ A Ψ₁ A₀ →
SignatureFixpointHygiene (Δ₀.extSizes Ψ₁) A₀ →
InferSpine (Δ₀.extSizes Ψ₁) qs A₀ C Γ Δ Ψ₂ qs' →
CheckTerm sig Ξ ((Ψ₁ ++ Ψ₂).map (fun d => (d.var, d.pol)))
Γ ((Δ₀.extSizes Ψ₁).append ⟨Ψ₂, Δ⟩) C t Φ Cs T t' →
LocalCallsConform Ξ 𝒢 f Ψ₁ (Ψ₁ ++ Ψ₂) (t'.applyFlex φstar) →
ExprCheck ⟨sig, Ξ, 𝒢, f, Ψ₁⟩ ((Δ₀.extSizes Ψ₁).extDecls Δ) Γ (t'.applyFlex φstar) C) := by
sorry
end NishtAbel2024Read-back
What the Lean code literally says, in plain math · Gemini 3.1 Pro (Independent Blind Auditor)
Independent Mathematical Read-Back: Thm_NishtAbel2024_theorems_13_and_14.lean
The declaration theorems_13_and_14 asserts the conjunction of three universally quantified implications concerning the soundness of applying a coherent flexible-variable substitution to an elaborated clause body, the coherence of the concrete constraint-graph solver solveConstraintGraph, and their combination.
Underlying data and judgments unfolded across the three conjuncts:
- Flexible substitutions (
FlexSubst), validity (ValidFlexSubst), and coherence (CoherentSubst): A flexible substitution is applied to a size expression (a.applyFlex φ) by replacing every variable with shifted by the variable's shift in and foldingmeetExp(which concatenatesSizeMinlists and takes the minimum of finite infinity offsets). Applying to a term (t'.applyFlex φ) substitutes into all size arguments of function callsfunRef, constructor size annotations, projection size annotations, and all size variables inside the type expressions ofpack,ascr, andtyArg.ValidFlexSubst Ψ φholds iff (1) for every , and (2)SizeWf Ψ (φ k)holds for every (every size variable occurring in is declared in with polarity or ).CoherentSubst Ψ Cs φholds iffValidFlexSubst Ψ φholds and for every constraint :- if , then
SizeLt Ψ (c.lhs.applyFlex φ) (c.rhs.applyFlex φ).boundNorm; - if , then
SizeLe Ψ (c.lhs.applyFlex φ) (c.rhs.applyFlex φ).boundNorm, whereSizeLe Ψ x yis defined asSizeLt Ψ x (y.shift 1)andSizeLt Ψis the syntactic size-inequality judgment generated by infinity comparison, shift comparison on bound variables, bound-stepping (var_bound_step), andmeetleft/right rules.
- if , then
- Concrete constraint solver (
solveConstraintGraph Ψ C T): Given a size context , constraint list , and tracked variable list :baseSubstmaps if , and (.inf 0) otherwise.candidateSubstmaps if ; otherwise, if contains a strict constraint () mentioning on both sides, it maps ; otherwise it collectsincoming, prependsrigidMeetAll Ψ(the formalmeetof all variables in ) if and , and applieslubSizes(which returns if the list is non-empty and all its elements are syntactically identical to , and otherwise).- A boolean check
candidateOktests every after applyingcandidateSubst(and.boundNormon the RHS): if the normalized RHS is , it checks (for ) or (for ) when the LHS is , and returnstruewhenever the LHS is ameet; if the normalized RHS is ameet, it checks thatlhs' == rhs'andc.rel == .le. solveConstraintGraph Ψ C TreturnscandidateSubstifcandidateOk = true, and falls back tobaseSubstotherwise.
- Local call conformance (
LocalCallsConform Ξ 𝒢 f Ψ₁ Ψclause u) and target typing (ExprCheck):LocalCallsConformtraverses the term and requires that at every subterm.funRef g asand for every declaration with :SizeSubstWf Ψclause as decl.sizeParamsholds (meaning and each -th size argument satisfiesSizeLt Ψclauseagainst the -th parameter's bound with the preceding arguments substituted), and- there exists an invocation graph such that
SyntacticConforms Ψclause G as Ψ₁holds (meaning , , and every or edge in is witnessed bySizeLtorSizeLein between and ).ExprCheck Ω Δ Γ u Cis the target bidirectional type-checking judgment in typing environment , where global calls insigrequireSizeSubstWfand local recursive calls in require bothSizeSubstWfandSyntacticConformsfor some graph .
The three conjuncts literally state:
-
Target type-checking from any coherent substitution (Conjunct 1): For all global signatures
sig, mutual blocks , invocation graph families , function names , kinding contexts , size contexts , types , copattern spines , term contexts , type declaration lists , terms , flexible variable contexts , constraint lists , tracked variable lists , and flexible substitutions , if:EncodeType .neg .pos Δ₀ A Ψ₁ A₀,InferSpine (Δ₀.extSizes Ψ₁) qs A₀ C Γ Δ Ψ₂ qs',CheckTerm sig Ξ ((Ψ₁ ++ Ψ₂).map (fun d => (d.var, d.pol))) Γ ((Δ₀.extSizes Ψ₁).append ⟨Ψ₂, Δ⟩) C t Φ Cs T t',CoherentSubst (Ψ₁ ++ Ψ₂) Cs φ, andLocalCallsConform Ξ 𝒢 f Ψ₁ (Ψ₁ ++ Ψ₂) (t'.applyFlex φ), thenExprCheck ⟨sig, Ξ, 𝒢, f, Ψ₁⟩ ((Δ₀.extSizes Ψ₁).extDecls Δ) Γ (t'.applyFlex φ) Cholds.
-
Coherence of
solveConstraintGraph(Conjunct 2): For allsig, , , , , , , , , , , , if:SizeCtxWf (Ψ₁ ++ Ψ₂),EncodeType .neg .pos Δ₀ A Ψ₁ A₀,SignatureFixpointHygiene (Δ₀.extSizes Ψ₁) A₀,InferSpine (Δ₀.extSizes Ψ₁) qs A₀ A'' Γ Δ Ψ₂ qs', andCheckTerm sig Ξ ((Ψ₁ ++ Ψ₂).map (fun d => (d.var, d.pol))) Γ ((Δ₀.extSizes Ψ₁).append ⟨Ψ₂, Δ⟩) A'' t Φ Cs T t', thenCoherentSubst (Ψ₁ ++ Ψ₂) Cs (solveConstraintGraph (Ψ₁ ++ Ψ₂) Cs T)holds.
-
Target type-checking using
solveConstraintGraph(Conjunct 3): For allsig, , , , , , , , , , , , , , letting , if:SizeCtxWf (Ψ₁ ++ Ψ₂),EncodeType .neg .pos Δ₀ A Ψ₁ A₀,SignatureFixpointHygiene (Δ₀.extSizes Ψ₁) A₀,InferSpine (Δ₀.extSizes Ψ₁) qs A₀ C Γ Δ Ψ₂ qs',CheckTerm sig Ξ ((Ψ₁ ++ Ψ₂).map (fun d => (d.var, d.pol))) Γ ((Δ₀.extSizes Ψ₁).append ⟨Ψ₂, Δ⟩) C t Φ Cs T t', andLocalCallsConform Ξ 𝒢 f Ψ₁ (Ψ₁ ++ Ψ₂) (t'.applyFlex φstar), thenExprCheck ⟨sig, Ξ, 𝒢, f, Ψ₁⟩ ((Δ₀.extSizes Ψ₁).extDecls Δ) Γ (t'.applyFlex φstar) Cholds.
Degenerate cases, vacuous hypotheses, and anomalies:
- Fallback behavior of
solveConstraintGraphandboundNormon : InCoherentSubst, every constraint's right-hand side is normalized via.boundNorm, which sends to (). InsolveConstraintGraph, ifcandidateOkis false, it falls back tobaseSubst, which sends every flexible variable outside to ; under.boundNorm, any right-hand side equal to becomes , which satisfies underSizeLt. - Context correspondence in Conjuncts 1 and 3:
CheckTermis hypothesized under the kinding context , whereas the conclusionExprCheckis stated under ; these two contexts coincide when the< adeclarations in match (as produced byInferSpine).
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.