Skip to content

feat(formal): Wave 3 capstone — quantitative typing tracks usage soundly#634

Merged
hyperpolymath merged 1 commit into
mainfrom
claude/lucid-cray-4a22dp
Jun 21, 2026
Merged

feat(formal): Wave 3 capstone — quantitative typing tracks usage soundly#634
hyperpolymath merged 1 commit into
mainfrom
claude/lucid-cray-4a22dp

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

What

Wave 3 (capstone): a quantitative type system. Fuses the three Wave-1/2 pieces — the term/typing structure of P2_Stlc, the multiplicity semiring of QttSemiring, and the occurrence-count usage of AffineUsage — into one judgment whose context tracks quantities.

Inductive qtt : uctx -> tm -> qty -> Prop :=   (* uctx = var -> quant *)
| Q_Var : qtt (usingle x) (var x) A                         (* one var, once *)
| Q_App : qtt G1 f (QArr q A B) -> qtt G2 a A ->
          qtt (uadd G1 G2) (app f a) B                       (* Γ₁ + Γ₂ *)
| Q_Lam : G x = Zero -> qtt (uext G x q) b B ->
          qtt G (lam x b) (QArr q A B).                      (* bind at multiplicity q *)

Capstone theorem

Theorem usage_soundness : qtt G t A -> forall x, usage x t = G x.

The typing context records exactly the QTT usage of every variable — so the static quantity bookkeeping is sound w.r.t. actual occurrence counts. Corollary linear_uses_once: a term typed in a singleton context uses that one variable exactly once — linearity, read straight off the typing.

Axiom-free, no Admitted — both Print Assumptions closed.

Scope (honest)

This is the static quantity discipline, now unified and proven sound against usage. The dynamic half — operational progress + preservation that preserves the quantity accounting under reduction (a quantitative substitution lemma over P2_Stlc.v) — is the remaining step.

Track status

13 files, 20 closure reports, zero axioms. justfile/_CoqProject build it; .hypatia-ignore extends the Coq-.v-isn't-V-lang carve-out; README gains the Wave-3 capstone; PROOF-NEEDS.adoc P-4 row updated.

just -f formal/justfile check

🤖 Generated with Claude Code

https://claude.ai/code/session_01KPG9mEQXFyA3k7NWAzMNMr


Generated by Claude Code

…dly (QttTyping.v)

Fuses the three Wave-1/2 pieces — the term/typing structure of P2_Stlc, the
multiplicity semiring of QttSemiring, and the occurrence-count usage of
AffineUsage — into one judgment whose context tracks quantities:

  qtt Γ t A   (Γ : uctx = var ↦ quantity)
    Q_Var consumes one variable once (usingle x);
    Q_App ADDS the two subcontexts (Γ₁ + Γ₂, context-splitting read backwards);
    Q_Lam binds a variable at the multiplicity it is used.

Capstone theorem usage_soundness: the typing context records EXACTLY the QTT
usage of every variable —

    qtt Γ t A  →  ∀ x, usage x t = Γ x

— so the static quantity bookkeeping is sound w.r.t. actual occurrence counts.
Corollary linear_uses_once: a term typed in a singleton context uses that one
variable exactly once (linearity, read off the typing). Axiom-free, no Admitted.

Scope: the static quantity discipline is now unified and proven sound against
usage. The dynamic half — operational progress+preservation preserving the
quantity accounting under reduction (a quantitative substitution lemma over
P2_Stlc) — is the remaining step.

Track now 13 files, 20 closure reports, no axioms. justfile/_CoqProject build
QttTyping; .hypatia-ignore extends the Coq-not-V-lang carve-out; README gains
the Wave-3 capstone; PROOF-NEEDS P-4 row updated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPG9mEQXFyA3k7NWAzMNMr
@hyperpolymath hyperpolymath marked this pull request as ready for review June 21, 2026 14:18
@hyperpolymath hyperpolymath merged commit 874e36c into main Jun 21, 2026
12 of 13 checks passed
@hyperpolymath hyperpolymath deleted the claude/lucid-cray-4a22dp branch June 21, 2026 14:18
@github-actions

Copy link
Copy Markdown

🔍 Hypatia Security Scan

Findings: 41 issues detected

Severity Count
🔴 Critical 2
🟠 High 23
🟡 Medium 16

⚠️ Action Required: Critical security issues found!

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant