feat(formal): Wave 2 — the affine/QTT quantity semiring + affine usage#632
Merged
Conversation
Mechanizes the algebraic core that makes AffineScript *affine*, advancing P-4
(docs/PROOF-NEEDS.adoc) from prose. Axiom-free (Print Assumptions closed; lia
introduces no axioms); no Admitted.
QttSemiring.v — the QTT quantity semiring {0,1,ω}:
qplus (context addition; 1+1 = ω), qmult (scaling), all semiring laws
(assoc/comm/identity/distributivity) + the usage order 0 ≤ 1 ≤ ω, by
exhaustive case analysis. Plus the bridge `qof (m+n) = qplus (qof m) (qof n)`
— occurrence counts add under QTT addition — and the affine fact
`qplus One One = Omega` with `~ qle (qplus One One) One`.
AffineUsage.v — affine usage over the semiring:
usage x t := qof (count x t); proves usage composes through application
(usage x (app f a) = qplus (usage x f) (usage x a), from qof_plus); defines
affine well-formedness (every binder consumes its var at most once). Payoff:
`λx.x` is affine, `λx. x x` is NOT (its variable totals ω, exceeding the
affine bound) — the mechanized statement of "a linear value may not be
duplicated".
Scope: the full *typed* QTT calculus (context splitting Γ = Γ₁ + Γ₂,
progress+preservation tracking quantities, on top of P2_Stlc) is the next
increment.
Track now 12 files, 18 closure reports, no axioms. justfile/_CoqProject build
both; .hypatia-ignore extends the Coq-not-V-lang carve-out; README gains a
"Wave 2" section; PROOF-NEEDS P-4 row prose → partial.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPG9mEQXFyA3k7NWAzMNMr
🔍 Hypatia Security ScanFindings: 41 issues detected
View findings[
{
"reason": "Action denoland/setup-deno@v2 needs attention",
"type": "unpinned_action",
"file": "publish-jsr.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in instant-sync.yml",
"type": "secret_action_without_presence_gate",
"file": "instant-sync.yml",
"action": "peter-evans/repository-dispatch",
"rule_module": "workflow_audit",
"severity": "high"
},
{
"reason": "Shell execution -- validate input before passing to shell (1 occurrences, CWE-78)",
"type": "js_exec_sync",
"file": "/home/runner/work/affinescript/affinescript/packages/affinescript-cli/mod.js",
"action": "flag",
"rule_module": "code_safety",
"severity": "high"
},
{
"reason": "Shell execution -- validate input before passing to shell (2 occurrences, CWE-78)",
"type": "js_exec_sync",
"file": "/home/runner/work/affinescript/affinescript/packages/affine-vscode/mod.js",
"action": "flag",
"rule_module": "code_safety",
"severity": "high"
},
{
"reason": "Shell execution -- validate input before passing to shell (1 occurrences, CWE-78)",
"type": "js_exec_sync",
"file": "/home/runner/work/affinescript/affinescript/affinescript-vite/src/affine-plugin-improved.js",
"action": "flag",
"rule_module": "code_safety",
"severity": "high"
},
{
"reason": "expect() in hot path (32 occurrences, CWE-754)",
"type": "expect_in_hot_path",
"file": "/home/runner/work/affinescript/affinescript/affinescriptiser/src/codegen/wasm_gen.rs",
"action": "flag",
"rule_module": "code_safety",
"severity": "medium"
},
{
"reason": "expect() in hot path (29 occurrences, CWE-754)",
"type": "expect_in_hot_path",
"file": "/home/runner/work/affinescript/affinescript/affinescriptiser/src/codegen/affine_gen.rs",
"action": "flag",
"rule_module": "code_safety",
"severity": "medium"
},
{
"reason": "unsafe block -- requires SAFETY comment (2 occurrences, CWE-676)",
"type": "unsafe_block",
"file": "/home/runner/work/affinescript/affinescript/runtime/src/panic.rs",
"action": "flag",
"rule_module": "code_safety",
"severity": "medium"
},
{
"reason": "unsafe block -- requires SAFETY comment (1 occurrences, CWE-676)",
"type": "unsafe_block",
"file": "/home/runner/work/affinescript/affinescript/runtime/src/alloc.rs",
"action": "flag",
"rule_module": "code_safety",
"severity": "medium"
},
{
"reason": "unsafe block -- requires SAFETY comment (3 occurrences, CWE-676)",
"type": "unsafe_block",
"file": "/home/runner/work/affinescript/affinescript/runtime/src/ffi.rs",
"action": "flag",
"rule_module": "code_safety",
"severity": "medium"
}
]Powered by Hypatia Neurosymbolic CI/CD Intelligence |
hyperpolymath
added a commit
that referenced
this pull request
Jun 21, 2026
…ve 1–3 (#636) ## What `docs/PROOF-NEEDS.adoc`'s **status tables were already correct** (§2 P-rows, §4 F-rows track every obligation accurately), but two **narrative sections went stale** during the Wave 1/2/3 mechanization that landed in #632 / #634. This refresh re-grounds them against the live `formal/` tree. Ground truth at time of writing: **13 `.v` files, 22 `Print Assumptions` closure reports, all axiom-free** (verified by recompiling the whole track with `coqc -Q . ASFormal` and auditing for `Axioms:`). ## Changes (docs only) - **§1 `formal/` baseline** listed only **8 of the 13** proof files — it predated `P2_Stlc`, `P3_BorrowGraph`, and the QTT trio (`QttSemiring` / `AffineUsage` / `QttTyping`). Now lists all 13 with the true count. - **§6 sequencing table** reframed: the doc described Waves 1–3 as *future* and cited "11 closure reports". Waves 1 (model growth) and 2 (static QTT) are **done**; Wave 3 is now correctly stated as **the real lift** — formalise the real AffineScript AST + real typed-WASM operational semantics, then the remaining prose/absent obligations. - **K-1 bullet** now notes `K1Let_CodegenPreservation.v` grows the seed with de Bruijn variables / `let` / environment. - **K-3 bullet** now notes `P3_BorrowSound.v` / `P3_BorrowGraph.v` already reject the #554 witness in-model (was "should be written"). - **Intro** "almost none mechanized" → "a growing axiom-free Coq core (small models; no full-language theorem discharged yet)". No proof content changes; no status-column downgrades. This only makes the prose match the tables and the tree. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01KPG9mEQXFyA3k7NWAzMNMr --- _Generated by [Claude Code](https://claude.ai/code/session_01KPG9mEQXFyA3k7NWAzMNMr)_ Co-authored-by: hyperpolymath <paraordinate@yahoo.co.uk> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
Wave 2: the affine/QTT layer — the algebraic core that makes AffineScript actually affine. Advances P-4 from prose to mechanized. Axiom-free (
Print Assumptionsclosed;liaintroduces no axioms), noAdmitted.QttSemiring.v— the quantity semiring{0,1,ω}qplus(context addition, with the crux1 + 1 = ω) andqmult(scaling)0 ≤ 1 ≤ ω, by exhaustive case analysisqof (m + n) = qplus (qof m) (qof n)— occurrence counts add under QTT additionqplus One One = Omegaand~ qle (qplus One One) OneAffineUsage.v— affine usage over the semiringusage x t := qof (count x t); proves usage composes through application:usage x (app f a) = qplus (usage x f) (usage x a)(fromqof_plus)λx.xis affine;λx. x xis not — its variable totalsω, exceeding the affine bound. The mechanized statement of "a linear value may not be duplicated."Scope (honest)
The full typed QTT calculus — context splitting
Γ = Γ₁ + Γ₂, progress + preservation tracking quantities, on top ofP2_Stlc.v— is the next increment. This PR lands the algebra + usage reading it rests on.Track status
12 files, 18 closure reports, zero axioms.
justfile/_CoqProjectbuild both new files;.hypatia-ignoreextends the Coq-.v-isn't-V-lang carve-out; README gains a "Wave 2" section;PROOF-NEEDS.adocP-4 →partial.🤖 Generated with Claude Code
https://claude.ai/code/session_01KPG9mEQXFyA3k7NWAzMNMr
Generated by Claude Code