interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / spec / mixed-algebra-digital-v1.md

316 lines · 17524 bytes Raw Blame History Rendered
1# MIXED_ALGEBRA_DIGITAL_V1: closure gate (pre-registration)
2
3Status: PRE-REGISTERED. This file is committed before any timed run of the
4gate. Every threshold, query, receipt rule and PASS/FAIL condition below is
5fixed here; the gate implementation (`make gate-mixed-algebra-digital-v1`)
6checks exactly these and nothing looser. Results are written to a
7digest-named wrapper receipt, never back into this file.
8
9Scope: the digital (CPU) leg of the mixed-algebra program. It closes the
10question "do I have several verified, exact, differently-built realizations
11of one operation, measured, and a recorded, reproducible selection among them
12that can say why a realization was not chosen". It does not claim energy
13results and does not introduce any new realization.
14
15## 1. Operation (no redefinition)
16
17Omega-X is the existing exact ternary GEMV contract, unchanged:
18`spec/mixed-algebra-ma2.md`, section "Operation Omega-X", and
19`src/algebra/realize_common.h`:
20
21 y = W . x, W in {-1,0,+1}^(m x n) (row-major int8), x in int8^n,
22 y in int32^m, EXACT (bit-identical to oma_rz_oracle), n <= 16,777,215.
23
24The TURING contract digest used by the selector is the PROVISIONAL digest of
25this same contract (`turing_contract_omega_x`, `src/turing/field.h`).
26
27## 2. Realization families (R1 / R2 / R3)
28
29Families are counted by the registry `family` string of `oma_rz_impl`,
30literally (7 distinct values over 10 realizations, `oma_rz_get` order):
31
32| class | family string | realizations | max_n |
33|---|---|---|---|
34| R1 conventional binary / int8 | `binary` | R1_plain (weak baseline), R1_sdot, R1_sdot_il, R1_smmla | 16,777,215 |
35| R2 packed ternary | `bitplane` | R2_bitplane (H1 two-bitplane code) | 16,777,215 |
36| R2 packed ternary | `lut` | R2b_lut | 16,777,215 |
37| R2 packed ternary | `crumb2` | R2c_crumb (2-bit two's-complement crumb code) | 16,777,215 |
38| R2 packed ternary | `dense5` | R5_dense5 (5 trits / byte) | 16,777,215 |
39| R3 residue | `rns` | R4_rns (RNS {256,255,253}) | 64,512 |
40| (sparse, counted as its own family) | `sparse` | R3_sparse (uint16 index lists) | 65,536 |
41
42Note on names: the registry id `R3_sparse` is unrelated to class R3; class R3
43here means residue arithmetic (`R4_rns`). The class column is only a
44grouping for the >= 3-class check in section 7; the family string is what the
45gate counts.
46
47### Two distinct 2-bit trit encodings (both retained)
48
49- H1 two-bitplane code (`src/algebra/oma_trit.h`, reference spec "Encoding
50 (H1)"; used by the reference library and by R2_bitplane): a trit is a
51 (pos, neg) bit pair. (0,0) = 0, (1,0) = +1, (0,1) = -1, (1,1) = ⊥ (invalid).
52 As the 2-bit code value (bit0 = pos, bit1 = neg): 0 = 0, 1 = +1, 2 = -1,
53 3 = ⊥.
54- Crumb code (R2c_crumb, `src/algebra/realize_bitplane.c`): 2-bit two's
55 complement, 00 = 0, 01 = +1, 11 = -1; 10 is never written (it would decode
56 to -2, outside the contract). 10 is the crumb code's ⊥.
57
58The ⊥ rule, explicit: ⊥ is never a value. In the reference library every
59operation (per-trit neg/add/mul, block validate/decode/neg/add/mul/dot,
60pack/unpack, serialize) given ⊥ returns an error code
61(`OMA_E_INVALID_CODE` / `OMA_E_INVALID_PLANES`) and leaves its outputs
62untouched; ⊥ does not "propagate" as a result value, it stops the operation.
63Realizations take the canonical int8 matrix; any weight outside {-1,0,+1}
64(which is the only way ⊥ could reach them) is refused at pack time with
65`OMA_RZ_E_TRIT`, and no realization's packed form may contain its own ⊥
66pattern.
67
68## 3. Correctness leg
69
70All of these must pass (plain build and ASan+UBSan build where listed):
71
721. `make test-algebra` and `make test-algebra-asan` (reference library;
73 sections include "invalid (1,1) rejection", "per-trit truth tables",
74 "pack/unpack random", "errors leave outputs").
752. `make test-realize` (plain + ASan/UBSan): every realization bit-identical
76 to `oma_rz_oracle` on the same corpus: structured tail shapes x
77 deterministic W kinds (all 0, all +1, all -1) x x kinds (all -128, all 127,
78 alternating), random sparsity; 400 random shapes; magnitude and boundary
79 cases (n = 16,384, 64,512, 64,513 refused by RNS, 65,536, 65,537 refused
80 by sparse, 100,003); each plan run twice; rejections.
813. `make test-turing` (the selector the gate uses; plain + ASan/UBSan).
824. NEW `tests/algebra/test_ma_digital_bottom.c` (plain + ASan/UBSan), ⊥
83 coverage at the realization layer, which no existing test covers:
84 - H1 code: ⊥ round trip is refused (encode of every invalid int8 value,
85 decode/unpack of a (1,1) block) and add/mul with ⊥ on either side
86 return the error code with outputs untouched (re-asserted at the gate
87 level);
88 - every one of the 253 int8 values outside {-1,0,+1}, placed at a random
89 position of an otherwise valid W, is refused by every realization's pack
90 with `OMA_RZ_E_TRIT`;
91 - R2_bitplane packed planes never contain (pos=1, neg=1) at any bit, and
92 decode back to W (layout: 128-weight chunks, 16 bytes pos then 16 bytes
93 neg, bit k of byte j = column 128c + 16k + j);
94 - R2c_crumb packed bytes never contain crumb 10, and decode back to W
95 (layout: 64-weight chunks of 16 bytes, bits 2k..2k+1 of byte j = column
96 64c + 16k + j);
97 over deterministic, random, all +1, all -1 and boundary (tail) shapes.
985. The benchmark re-verifies every realization bit-exact against the oracle
99 on every grid cell; each fresh receipt must report
100 `correctness.mismatches == 0`.
101
102## 4. Measurement leg
103
104Receipts that feed the decision (primary): exactly the two FRESH receipts
105written by `make bench-mixed-algebra MA2_RUN_ID=<id>` during the gate run:
106`evidence/MIXED_ALGEBRA/runs/<id>/ma2_bench_run1.json` then
107`.../ma2_bench_run2.json`, ingested in that order (store order is part of the
108decision digest: ties break on lowest spec index and cites are in store
109order). Their schema is `OMEGA_MIXED_ALGEBRA_MA2_BENCH_V1` (the bench's
110current writer); the committed `ma3_bench_run{1,2}.json` carry
111`OMEGA_MIXED_ALGEBRA_MA3_BENCH_V1`. `turing_ingest_receipt` accepts both
112(prefix `OMEGA_MIXED_ALGEBRA_MA` + `_BENCH_V1`).
113
114The committed `ma3_bench_run{1,2}.json` do NOT feed the primary decision. The
115gate also computes a continuity decision per query from those two committed
116receipts alone and records whether its winner agrees; this is informational
117and never affects PASS.
118
119Tier guard (so the decision cannot silently cite old evidence): ingest gives
120a row tier E2 only when its receipt reports `mismatches == 0` and the row is
121oracle-verified, else E0, and the selector drops non-E2/E3/E4 rows with
122`TURING_R_TIER`. The gate additionally asserts that every evidence digest
123cited by every primary decision resolves to a row whose receipt digest is one
124of the two fresh receipt digests, and that each fresh receipt has
125`run_commit` = the gate's HEAD and `tree_dirty` = false.
126
127Fresh-run requirements: not `OMA_BENCH_QUICK`; the quiet flag
128`~/workspace/.spark-quiet` must be absent before the run (the gate refuses to
129start the timed leg otherwise), is created for the timed leg and removed on
130exit, success or failure. One heavy test at a time.
131
132Reuse mode: `MA_DV1_REUSE_RUN=<id>` skips the bench and uses the existing
133receipts of `runs/<id>/`. The wrapper receipt records `mode: reuse`; all
134other checks (including run_commit, tree_dirty and cite checks) apply
135unchanged, so reuse can only reproduce the decision of the run that made
136those receipts at the same commit.
137
138Measured (from the bench, per realization and grid cell): per-call latency
139(median and best of >= 9 interleaved blocks, q25/q75), pack cost, within-run
140spread (noise_rel, pack_noise_rel), weight bytes read per call, working-set
141bytes. Grid: n in {1024, 4096, 16384} x m in {1, 64, 4096} x sparsity
142{0, 0.3, 0.6, 0.9}, one pinned Cortex-X925 core.
143
144NOT measured in this gate: energy. The bench writes indicative whole-cluster
145energy rows into its receipt, but ingest stops at the `"energy"` section, so
146no energy number reaches any decision; energy is pending omega#86. Also not
147measured: multi-core, GPU, cold-cache, x-vector batching.
148
149The bench target also runs the RETIRED MA-2 selector and writes
150`ma2_select_receipt.json` into the run directory; it is kept as the bench
151writes it and is not used by this gate.
152
153## 5. Selection leg
154
155Selector: the EXISTING TURING Field selector v1 (`turing_field_select`,
156`src/turing/field_select.c`), unchanged. The `turing-field` CLI cannot express
157these queries (it hardcodes shapes S1-S4, has no n/m/pack arguments and no
158query above any max_n), so the gate uses a small new C driver
159(`tests/algebra/ma_digital_v1_gate.c`) that calls only public `turing_*`
160functions: `turing_ingest_registry`, `turing_ingest_receipt`,
161`turing_field_select` (no supersedes), `turing_decision_digest`,
162`turing_decision_verify`.
163
164Pre-registered queries (sparsity 0.30, a measured grid value; sparsity does
165not change the footprint):
166
167| id | shape | n | m | pack | expected cell |
168|---|---|---|---|---|---|
169| Q1 | L2-resident (256 KiB int8 W) | 4096 | 64 | once | exact |
170| Q2 | L2-resident | 4096 | 64 | per_call | exact |
171| Q3 | DRAM-bound (64 MiB int8 W) | 16384 | 4096 | once | exact |
172| Q4 | DRAM-bound | 16384 | 4096 | per_call | exact |
173| Q5 | above RNS and sparse max_n | 65537 | 64 | once | nearest (16384 x 64) |
174| Q6 | above RNS and sparse max_n | 65537 | 64 | per_call | nearest (16384 x 64) |
175
176Q5/Q6 are the named-rejection queries: from the real registry, R4_rns
177(max_n 64,512) and R3_sparse (max_n 65,536) must be recorded with
178`TURING_R_MAX_N`. Their other 8 candidates are ranked on the nearest measured
179footprint, so the decision records `exact_cell = 0`; this is expected and is
180not an extrapolation claim about n = 65,537 timings. No broken or non-exact
181realization is added.
182
183"Verified-eligible" = candidate reason in {CHOSEN, RANKED, TIED}, i.e. it
184passed the contract, exactness, max_n, receipt-verify, oracle-verified-run,
185contention and tier filters and has E2 evidence in the footprint. The weak
186baseline R1_plain is not filtered (Field v1 has no weak-baseline reason code)
187and ranks like any other candidate.
188
189## 6. Reproducibility
190
191- The decision digests (`turing_decision_digest`, domain
192 `turing.decision.v1`) must be bit-identical when selection is re-run from
193 the stored receipts: (a) a second, independently ingested store in the same
194 process; (b) a separate process of the driver; (c) a separate process of an
195 ASan+UBSan build of the driver. Receipt paths are not part of any digest.
196- Oracle checks are bit-identical by construction (section 3).
197- Timings are NOT expected to reproduce. The wrapper receipt records, per
198 query, the winner's and runner-up's mean cost, the margin, the selector's
199 noise band (largest within-run spread of winner and runner-up rows) and the
200 run1-vs-run2 relative difference of the winner's footprint cost. A winner
201 whose margin is inside the band is reported as such (not a stable win).
202
203## 7. PASS criteria (all required)
204
2051. Every correctness command in section 3 passes; both fresh receipts report
206 0 mismatches.
2072. Clean tree: no modified or deleted tracked file anywhere
208 (`git status --porcelain --untracked-files=no` empty) and no untracked file
209 under `src tests tools spec Makefile`; untracked fresh receipts under
210 `evidence/MIXED_ALGEBRA/runs/<id>/` are expected and listed by path and
211 digest. Recorded as `tree_dirty`; must be false. Both fresh receipts have
212 `run_commit` = HEAD and `tree_dirty` = false.
2133. Every query returns a chosen realization (verdict CHOSEN) and
214 `turing_decision_verify` succeeds (every cited receipt re-hashes).
2154. Every cited evidence row of every primary decision comes from a fresh
216 receipt (section 4 tier guard).
2175. Families: in Q1-Q4 all 10 realizations are verified-eligible, spanning all
218 three classes R1 (binary), R2 (bitplane/lut/crumb2/dense5), R3 (rns); in
219 every query the verified-eligible set spans >= 3 distinct family strings.
2206. Named rejections: in Q5 and Q6 exactly R3_sparse and R4_rns carry
221 `TURING_R_MAX_N` and nothing else is filtered; at least one named
222 rejection overall.
2237. Reproducibility (a), (b) and (c) of section 6 all give identical digests.
2248. The wrapper receipt is written to
225 `evidence/MIXED_ALGEBRA/digital_v1/<sha256 of its bytes>.json`, never over
226 an existing file, and records: run_commit, tree_dirty, mode, run id, every
227 receipt path + digest, per-query decision digest, chosen realization,
228 reason + cost for every candidate, margin, band, families, rejections,
229 continuity result, correctness totals, reproduction results and the
230 verdict `MIXED_ALGEBRA_DIGITAL_V1 PASS` or `MIXED_ALGEBRA_DIGITAL_V1 FAIL`.
231
232FAIL: any of 1-7 not met. A FAIL receipt is still written (from a clean tree)
233with the failing checks named. A dirty tree never publishes a receipt into
234`evidence/`; its receipt stays under `build/`. The quiet flag being present is
235not a FAIL: the gate refuses to start the timed leg and writes nothing.
236
237## 8. What PASS does not claim
238
239No energy result; no claim that ternary beats int8 in general (earlier
240MA-2/MA-3 results: ternary wins only when DRAM-bound); Q5/Q6 timings are the
241nearest footprint's; the selector's rule is the control arm's minimum-mean
242rule (TURING K.7), not a novel selector.
243
244## Post-run addenda (2026-09-29, after independent review)
245
246Added after the PASS receipt
247`evidence/MIXED_ALGEBRA/digital_v1/04f0f9ab01fc55fcc94391fe5032b18f3ca8c039e00b9f4be66cfb05ec28ddc1.json`
248(run commit d51a893, bench run `20260929T213551Z`). Sections 1 to 8 above are
249unchanged; nothing here alters a PASS/FAIL criterion or the recorded result.
250
251### A1. What the PASS shows, and what it does not
252
253- The PASS shows a verified, reproducible selection: every decision digest
254 re-derives bit-identically from the stored receipts, every cited receipt
255 re-hashes, and every rejection is named. It does not show stable winners.
256- Q2, Q4, Q5 and Q6 have margins inside the selector's noise band
257 (Q2 1.58% vs band 7.02%, Q4 0.17% vs 5.16%, Q5 1.81% vs 3.54%, Q6 1.54% vs
258 4.80%). Their winners are ties within noise. The Q4 winner (R1_plain)
259 disagrees with the continuity MA-3 receipts, which pick R1_sdot; this is
260 the expected behaviour of a within-noise tie, not a contradiction.
261- Only two winners are clear: Q1 R1_smmla (margin 5.30% vs band 1.63%) and
262 Q3 R2c_crumb (margin 18.85% vs band 2.42%, the DRAM-bound packed-ternary
263 win).
264- Energy is not part of any decision; bench energy rows are not ingested
265 (pending omega#86).
266
267### A2. Receipt tamper checks (review follow-up)
268
269- `make check-mixed-algebra-digital-v1-evidence`
270 (`tests/algebra/ma_digital_v1_check_evidence.sh`): every
271 `digital_v1/<name>.json` must hash (sha256 of its bytes) to `<name>`, and
272 every receipt it cites must exist and re-hash to the digest recorded in the
273 wrapper. Unlike `check-mixed-algebra-evidence` (a diff against git HEAD),
274 this also catches an edited receipt that was committed.
275- The gate script now pins the two fresh receipts (and the two continuity
276 receipts) by sha256 immediately after the bench writes them, or when a
277 reuse run is chosen, and passes the pins to the driver as
278 `DV1_EXPECT_SHA256`. The driver re-hashes every pinned file before ingest
279 and again just before writing the wrapper. A mismatch stops the gate with
280 exit 2 and writes no receipt. This is an input-integrity error, not an
281 added section 7 criterion; the PASS/FAIL criteria are unchanged. In reuse
282 mode, `MA_DV1_REUSE_SHA256="<run1 sha256> <run2 sha256>"` pins the reused
283 receipts to externally recorded digests (for example, the ones in a
284 published wrapper).
285- `test_ma_digital_bottom.c` now also checks R2b_lut's packed form (H1 per
286 lane: pos nibble low, neg nibble high): no lane sets the same bit in both
287 nibbles, and every lane decodes back to W (padding lanes to 0), over the
288 same shape set as R2_bitplane and R2c_crumb. The bottom check count rises
289 from 6255 (in the PASS receipt) to 8259.
290
291### A3. Reproducing the PASS
292
293The gate requires every fresh receipt's `run_commit` to equal HEAD, so it
294must be reproduced at the run commit, reusing the stored bench output:
295
2961. `git worktree add --detach /tmp/ma-repro d51a893`
2972. Copy `evidence/MIXED_ALGEBRA/runs/20260929T213551Z/` (all three files)
298 from this branch into the same path in that worktree.
2993. In the worktree root:
300 `MA_DV1_REUSE_RUN=20260929T213551Z make gate-mixed-algebra-digital-v1`
301
302Result (done 2026-09-29 in a throwaway worktree, exactly as above): every
303correctness command PASS (test-algebra plain and ASan 25672462 checks,
304test-realize 179746, test-turing 85, bottom 6255, all 0 failures), verdict
305`MIXED_ALGEBRA_DIGITAL_V1 PASS`, 0 failed checks. All six decision digests
306are bit-identical to the ones in the published receipt 04f0f9ab..., with the
307same winners (Q1 R1_smmla, Q2 R1_sdot, Q3 R2c_crumb, Q4 R1_plain,
308Q5 R1_sdot_il, Q6 R1_sdot). The reproduced wrapper hashes to d102c8d5...,
309not 04f0f9ab...: it records `"mode": "reuse"` and a different untracked
310list, so its bytes differ by design. Compare decision digests, not wrapper
311hashes. The reproduced wrapper stays in the throwaway worktree and is never
312copied into this repository's evidence/. Run at d51a893, the gate predates
313the A2 pinning; at a later commit `MA_DV1_REUSE_SHA256` can pin the reused
314receipts to the digests in 04f0f9ab..., but `run_commit` = HEAD then fails
315criterion 2 by design, so a later-commit reuse run is a check of the
316selection, not a re-issue of the PASS.