WIP: discharge substTop_preserves_typing axiom (Refs #23)#27
Merged
Conversation
Origin/main (aa65b23) failed `lean proofs/BetLang.lean` with four pre-existing errors that block any further proof work: 1. `progress` (line 304): `induction ht` failed with "index in target's type is not a variable" because `HasType [] e T` carries the concrete `[]` index. Refactored to `generalize hΓ : ([] : Ctx) = Γ at ht`, then `subst hΓ` in branches that need the closed-context invariant (`tVar` for the empty-lookup contradiction; `tApp`/`tIf`/`tSample`/ `tDistBind` for the canonical-forms lemmas). Used non-`@` patterns where possible to avoid having to know the constructor's implicit- argument order; `tIf` still needs `@tIf Γ c t T e ...` because the two if-branches `t` and `e` are positional witnesses in the goal. 2. `lookup_extend_ge` (line 367): broken `omega` + `rw` chain (IH was over the wrong index because `induction Γ` didn't generalize `n`). Deleted as unused — the substitution machinery in the next commit will use a cleaner `Ctx.insertAt`-based formulation, so this lemma has no caller now and won't have one later. 3. Two orphan `/-- … -/` doc-comment blocks (lines 386-391 and 393-399) not attached to any declaration. Both were stale guidance about the not-yet-discharged substitution lemma. Replaced with a single line comment pointing at the upcoming Section 8.5. Verified: `lean proofs/BetLang.lean` exits 0 with no errors (seven unused-variable warnings remain in `preservation`, all pre-existing and untouched by this commit). The `substTop_preserves_typing` axiom (line 420 pre-edit) is still in place; discharging it is the next commit on this branch (Refs #23). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
🔍 Hypatia Security ScanFindings: 56 issues detected
View findings[
{
"reason": "Merge artifact in root",
"type": "stale",
"file": "SPEC.core.scm.orig",
"action": "delete",
"rule_module": "root_hygiene",
"severity": "medium"
},
{
"reason": "Issue in quality.yml",
"type": "missing_workflow",
"file": "quality.yml",
"action": "create",
"rule_module": "workflow_audit",
"severity": "high"
},
{
"reason": "Issue in security-policy.yml",
"type": "missing_workflow",
"file": "security-policy.yml",
"action": "create",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Action hyperpolymath/standards/.github/workflows/governance-reusable.yml@main needs attention",
"type": "unpinned_action",
"file": "governance.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "high"
},
{
"reason": "No permissions declaration -- add permissions: read-all",
"type": "missing_permissions",
"file": "comprehensive-quality.yml",
"action": "add_permissions",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "TypeScript file detected -- banned language",
"type": "banned_language_file",
"file": "/home/runner/work/betlang/betlang/playground/src/main.ts",
"action": "flag",
"rule_module": "cicd_rules",
"severity": "critical"
},
{
"reason": "TypeScript file detected -- banned language",
"type": "banned_language_file",
"file": "/home/runner/work/betlang/betlang/playground/src/probability.ts",
"action": "flag",
"rule_module": "cicd_rules",
"severity": "critical"
},
{
"reason": "TypeScript file detected -- banned language",
"type": "banned_language_file",
"file": "/home/runner/work/betlang/betlang/playground/src/ternary.ts",
"action": "flag",
"rule_module": "cicd_rules",
"severity": "critical"
},
{
"reason": "TypeScript file detected -- banned language",
"type": "banned_language_file",
"file": "/home/runner/work/betlang/betlang/playground/test/probability_test.ts",
"action": "flag",
"rule_module": "cicd_rules",
"severity": "critical"
},
{
"reason": "TypeScript file detected -- banned language",
"type": "banned_language_file",
"file": "/home/runner/work/betlang/betlang/playground/test/ternary_test.ts",
"action": "flag",
"rule_module": "cicd_rules",
"severity": "critical"
}
]Powered by Hypatia Neurosymbolic CI/CD Intelligence |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DRAFT — discharging the
substTop_preserves_typingaxiom (#23).What landed (commit 1:
ac6c44d)origin/main(aa65b23) didn't build.lean proofs/BetLang.leanfailed with 4 pre-existing errors that blocked any further proof work:progress(L304) —induction htfailed with "index in target's type is not a variable" becauseHasType [] e Thas the concrete[]index. Refactored withgeneralize hΓ : ([] : Ctx) = Γ at ht+subst hΓin the branches that need the closed-context invariant (tVar,tApp,tIf,tSample,tDistBind). Used non-@patterns where possible;tIfstill needs@tIf Γ c t T e ...because Lean's auto-bound-implicit order isΓ, c, t, T, e(T appears in the type oft's premise, so it's bound beforee).lookup_extend_ge(L367) — brokenomega+rwchain (IH over wrong index becauseinduction Γdidn't generalizen). Deleted as unused — the substitution machinery to come will use a cleanerCtx.insertAt-based formulation, so this had no caller and won't have one./-- ... -/doc-comments (L386-391, L393-399) not attached to any declaration. Replaced with a one-line pointer to the upcoming Section 8.5.lean proofs/BetLang.leannow exits 0 with no errors (7 pre-existing unused-variable warnings inpreservationremain, untouched).What's NOT done yet
The actual discharge of
substTop_preserves_typing. The axiom is still in place at L420. Attempted to write Section 8.5 in this session but hit a budget wall — the proof structure requires careful TAPL Ch. 9-style infrastructure, and several attempts at the foundationallookup_ctxInsertAt_ltlemma revealed that the natural statement needs an additionalk ≤ Γ.lengthhypothesis (otherwise it's false at empty Γ with k > 0). The deeper friction isInt.toNat (↑n + amount)reasoning at theExpr.varcase ofshift, especially foramount = -1(the shift-down insubstTopis only sound when no freevar 0survives — needs an auxiliary tracking lemma).Recipe for the next session
ctxInsertAt(non-dot-notation —Ctx := List Tyis anabbrevsoΓ.insertAtresolves toList.insertAtwhich doesn't exist):def ctxInsertAt (Γ : Ctx) (k : Nat) (U : Ty) : Ctx := Γ.take k ++ U :: Γ.drop k.k ≤ Γ.length:lookup_ctxInsertAt_lt: n < k → Ctx.lookup (ctxInsertAt Γ k U) n = Ctx.lookup Γ nlookup_ctxInsertAt_eq: Ctx.lookup (ctxInsertAt Γ k U) k = some Ulookup_ctxInsertAt_gt: n > k → Ctx.lookup (ctxInsertAt Γ k U) n = Ctx.lookup Γ (n - 1)shift_preserves_typing(weakening,amount = 1only):HasType Γ e T → ∀ k U, k ≤ Γ.length → HasType (ctxInsertAt Γ k U) (shift 1 k e) T. Induction onHasType; binder cases (tLam,tLet) bumpkby 1 and recurse. Variable case needsInt.toNat (↑n + 1) = n + 1.subst_preserves_typing(generalised):HasType (ctxInsertAt Γ k S) e T → HasType Γ v S → HasType (ctxInsertAt Γ k S) (subst k (shift (k+1 : Int) 0 v) e) T. Induction one. Binder cases recurse withk+1after pulling in the extrashift 1 0.subst k v e, define a predicatefreeVarNotIn k eand prove it holds. Then proveshift_downpreserves typing when this predicate holds.substTop_preserves_typing Γ S T body v hb hv := ...combining the chain. Then deleteaxiom substTop_preserves_typingat L420 (was 420, may be a few lines off after commit 1). Verifypreservationstill typechecks.Estimated ~300-400 LoC remaining. Standard TAPL Ch. 9 mechanisation, but the
Int.toNatclamping in BetLang'sshift(signed amount) adds non-trivial arithmetic friction at everyvarcase.Closes #23 once the discharge is complete and the axiom is deleted.
🤖 Generated with Claude Code