Skip to content

feat(formal): Wave 2 — the affine/QTT quantity semiring + affine usage#632

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

feat(formal): Wave 2 — the affine/QTT quantity semiring + affine usage#632
hyperpolymath merged 1 commit into
mainfrom
claude/lucid-cray-4a22dp

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

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 Assumptions closed; lia introduces no axioms), no Admitted.

QttSemiring.v — the quantity semiring {0,1,ω}

  • qplus (context addition, with the crux 1 + 1 = ω) and qmult (scaling)
  • All semiring laws (assoc/comm/identity/distributivity) + the usage order 0 ≤ 1 ≤ ω, by exhaustive case analysis
  • The bridge qof (m + n) = qplus (qof m) (qof n)occurrence counts add under QTT addition
  • The affine fact: qplus One One = Omega and ~ 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 variable 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 (honest)

The full typed QTT calculus — context splitting Γ = Γ₁ + Γ₂, progress + preservation tracking quantities, on top of P2_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/_CoqProject build both new files; .hypatia-ignore extends the Coq-.v-isn't-V-lang carve-out; README gains a "Wave 2" section; PROOF-NEEDS.adoc P-4 → partial.

just -f formal/justfile check

🤖 Generated with Claude Code

https://claude.ai/code/session_01KPG9mEQXFyA3k7NWAzMNMr


Generated by Claude Code

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
@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 hyperpolymath marked this pull request as ready for review June 21, 2026 14:06
@hyperpolymath hyperpolymath merged commit 381ca17 into main Jun 21, 2026
15 of 16 checks passed
@hyperpolymath hyperpolymath deleted the claude/lucid-cray-4a22dp branch June 21, 2026 14:06
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