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

GitHub aien-dev/omega-mv#891 (code only)

closed derived 9d33945266101205 #891

Imported from GitHub aien-dev/omega-mv#891 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base 62d1d0d668f897386a0e311374f8dbcc5c32dde8 · Head 763300780709fc21785caa421a8359f222f7c30e

Fetch it

A git bundle of the pull request's head, 32910 bytes.

curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/9d33945266101205.bundle -o 9d33945266101205.bundle
git fetch 9d33945266101205.bundle refs/pull/891/head

Raw bundle · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/omega-mv
891
763300780709fc21785caa421a8359f222f7c30e
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":891,"url":"https://github.com/aien-dev/omega-mv/pull/891","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:39:11Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/.crumb b/.crumb
index f3e51fe46..95efcdd79 100644
--- a/.crumb
+++ b/.crumb
@@ -71,8 +71,8 @@
           "purpose": "Directory research. Purpose not yet described by a human."
         },
         {
-          "digest": "f765ad87fdddd9b47f690b07298c951a0f7e7675dc5de4ffe44e33a0c14b1986",
-          "last_commit": "a8a6a3d3c",
+          "digest": "de6bbe151f93066995ce70103d3477870f39b1b6a0872a16270915f56a0b1f44",
+          "last_commit": "8bda54965",
           "name": "spec",
           "purpose": "Directory spec. Purpose not yet described by a human."
         },
@@ -84,26 +84,26 @@
         },
         {
           "digest": "5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874",
-          "last_commit": "a8a6a3d3c",
+          "last_commit": "dcccc0211",
           "name": "tests",
           "purpose": "Directory tests. Purpose not yet described by a human."
         },
         {
           "digest": "308db0e6cf45c0a48f01f5f5f228450f191389de68006915b9ecf9c65b9a2e29",
-          "last_commit": "a8a6a3d3c",
+          "last_commit": "a50c3bd41",
           "name": "tools",
           "purpose": "Directory tools. Purpose not yet described by a human."
         }
       ],
-      "children_root": "sha256:07bf1706dcffbad66c0353871ff67a6749055da03cee8d8ebdf9a4c91e36bddc",
-      "compiled_at": "2026-10-30T12:31:50Z",
+      "children_root": "sha256:6c7fc05cc39892625b329bacad8fc34a3f785f1ae63b0500673fb3322f9cc211",
+      "compiled_at": "2026-10-30T16:31:35Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:904fca8c0e0cf3e3a5e5adb73393e01c7018b920bb542d289904240f70e400d6",
-      "evidence_files": 12622,
-      "evidence_root": "sha256:b1a08e2ce56e6feada0d8a31f06fbd7adee57adc1c1ad8dec220293ee5d439f9",
-      "files": 17849,
-      "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06",
-      "source_tree": "sha256:75458da6553a0ee5ea2af95f46afb658e8a3f6e53cca6e3b4b9874035f78c2ed"
+      "digest": "sha256:4caf8fe2e1bc8cfa2d8d40080e9c7b100b55ff08abef354247ce715c35311bae",
+      "evidence_files": 12624,
+      "evidence_root": "sha256:113b4530fafb2c870dff8c8b96eed285dd97175b0fe625788d6ba355e83c3c7e",
+      "files": 17855,
+      "generated_at_commit": "9c563f6c364ccb0416cc029dcffacd8d9c7e3d84",
+      "source_tree": "sha256:425cbd31a5f07231196248d64fb07f2d57858a1085e33acb292b96b170bb26fb"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index dda6d20b5..fc88fdf89 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -48,4 +48,5 @@ Update this table in the same commit as the work it credits.
 
 | Codex | Integrated FR-9 with compiler batch 3 and the latest quantity/diagnostic audit; preserved empty text and integer-bitcast behavior on x86 and kept seed bootstrap within its function budget by removing unused helpers and inlining one single-use helper. |
 | Codex | Fixed x86 quantity unary refusals and empty-text emission; added explicit per-target acceptance contracts, preserved historical failed experiments, and exercised missing diagnostic callers and stale-binding controls. |
+| Claude Opus 5.5 | FUNCTION_ID (`omega.function.v1`, canonical falling-factorial form over the polynomial fragment modulo 2^w) and the graph of meaning (`om/meaning/`): receipt-backed equivalence edges, canonical storage, queries, randomized differential and mutant suite, spec sections 9-10 |
 | Grok 4.7 | Merged current main (b3dca0f1) into #514. The only conflict was the generated root `.crumb`; regenerated crumbs with the crumb.lock tool (d0f0b95d). |
diff --git a/README.md b/README.md
index 1cfed2960..115a26d12 100644
--- a/README.md
+++ b/README.md
@@ -42,7 +42,7 @@ The live status is owned by [aien-architecture](https://github.com/aien-spark/ai
 ## Core ideas
 
 - **SMART is not TRUSTED, INTELLIGENCE is not AUTHORITY.** Trust comes from verified invariants, never from capability.
-- **Meaning is permanent; representation is disposable.** Equivalent programs collapse to one `SEMANTIC_ID` (SHA-256 of the canonical encoding); different programs get different ones.
+- **Meaning is permanent; representation is disposable.** A program's `SEMANTIC_ID` (SHA-256 of the canonical encoding) names its canonical body, so respellings of one body (whitespace, parameter name, operand order) share it, but `x + 1 + 1` and `x + 2` do not. The separate `FUNCTION_ID` names the function: inside the polynomial fragment (`+ - *` and exact `and`/`or` identities modulo 2^w, w = 1..64) two programs get the same `FUNCTION_ID` exactly when they compute the same function; outside it the id falls back to the body and says so. Equality of arbitrary programs is undecidable, so no id is extensional for every program. Nodes, typed relations and receipt-backed equivalences form the graph of meaning ([spec/program-identity.md](spec/program-identity.md) sections 9-10, `om/meaning/`; host-exercised, not yet wired into the C library or Visor).
 - **Pure computation is separate from effects**, and effects need capability-bounded, receipt-producing transactions.
 
 ## How this fits with the other repositories
diff --git a/evidence/MEANING_GRAPH/cecf90844bd9218cffd1365a6ae379fa13177a4d63e1a07db5467c85073e9167.json b/evidence/MEANING_GRAPH/cecf90844bd9218cffd1365a6ae379fa13177a4d63e1a07db5467c85073e9167.json
new file mode 100644
index 000000000..d03356a60
--- /dev/null
+++ b/evidence/MEANING_GRAPH/cecf90844bd9218cffd1365a6ae379fa13177a4d63e1a07db5467c85073e9167.json
@@ -0,0 +1,45 @@
+{
+  "schema": "omega.meaning.run.v1",
+  "label": "EXERCISED (host, arm64); not QUALIFIED, not MERGED",
+  "source_commit": "846f857736f319defd584bfd084556078f2fd24b",
+  "branch": "meaning-graph",
+  "clean_tree": true,
+  "command": "taskset -c 10-14 sh om/meaning/test/run.sh seed/out/omc",
+  "run_sh_sha256": "f5ac0b4bed6f47050c9a6b9ac07ee3b5196e8e155ef4f20666ec5fff63f3a4b3",
+  "host": "Linux 7.0.0-1019-nvidia aarch64",
+  "finished_utc": "2026-10-27T07:37:20Z",
+  "exit_code": 0,
+  "verdict": "MEANING PASS checks=92883 mutants=10/10",
+  "output": [
+    "omc        sha256 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f",
+    "sha2.om    sha256 5cf0f98116def6917d3a373f2bd4c3932d46e3ff84d9567bbae9e720366fdb33",
+    "meaning.om sha256 ac30a227d9384b61bc3c3500b8c4ed70d3e49012af953469c4ae60a1c22268f4",
+    "driver.om  sha256 379e9226822b18d6f31e5c86cc623f362903d1cb7a62202382c45b6a6fcdc990",
+    "vectors    sha256 f4d9e0114d2f276389a7b799b796859b87977283479a5679eb8a0adc5549092f",
+    "PASS golden: H 0 11b8858ec5c305c0160d84eb2f30786c9429731bc6a88516d530ecefc819bef2",
+    "PASS golden: H 2 11b8858ec5c305c0160d84eb2f30786c9429731bc6a88516d530ecefc819bef2",
+    "PASS golden: H 8 96cb6ace92436b94aa6f49967d967b900f069c6c34b9cf73f7ce2d7d773cc1fa",
+    "PASS golden: H 9 96cb6ace92436b94aa6f49967d967b900f069c6c34b9cf73f7ce2d7d773cc1fa",
+    "PASS golden: H 19 89877bca66e566c52e7dbc92df7fc3bacb25542066df417a3641f504e1d216eb",
+    "  R w=1 programs=64 pairs=2016 equal_id_pairs=514 canonical=58",
+    "  R w=3 programs=300 pairs=44850 equal_id_pairs=1197 canonical=225",
+    "  R w=8 programs=300 pairs=44850 equal_id_pairs=1053 canonical=244",
+    "  R w=16 programs=120 pairs=7140 equal_id_pairs=105 canonical=99",
+    "  R w=64 programs=300 pairs=44850 equal_id_pairs=785 canonical=239",
+    "  G nodes=121 edges=126 receipts=33 bytes=34896 tampered=945",
+    "PASS vectors: meaning driver: 92883 checks, 0 failed",
+    "PASS mutant-kof-minus-1: detected (549 FAIL lines, first: FAIL line 96 code 22)",
+    "PASS mutant-inverse-4-steps: detected (4 FAIL lines, first: FAIL line 229 code 9)",
+    "PASS mutant-inverse-start-1: detected (4 FAIL lines, first: FAIL line 229 code 9)",
+    "PASS mutant-and-ones-dropped: detected (4 FAIL lines, first: FAIL line 80 code 21)",
+    "PASS mutant-and-one-accepted: detected (6 FAIL lines, first: FAIL line 80 code 21)",
+    "PASS mutant-apply-payload-160: detected (2 FAIL lines, first: FAIL line 129 code 6)",
+    "PASS mutant-sort-cmp-never: detected (4 FAIL lines, first: FAIL line 230 code 13)",
+    "PASS mutant-fid-domain: detected (5 FAIL lines, first: FAIL line 132 code 27)",
+    "PASS mutant-expect-c: detected (1 FAIL lines, first: FAIL line 93 code 21)",
+    "PASS mutant-expect-n: detected (1 FAIL lines, first: FAIL line 72 code 22)",
+    "PASS neg-define: detected (1 FAIL lines, first: FAIL line 1 code 1)",
+    "MEANING PASS checks=92883 mutants=10/10",
+    "rc=0"
+  ]
+}
diff --git a/evidence/MEANING_GRAPH/f451759e3d02fd7eb737cf7a4aa1b39fcf745e700653abc5797e1e658935544e.json b/evidence/MEANING_GRAPH/f451759e3d02fd7eb737cf7a4aa1b39fcf745e700653abc5797e1e658935544e.json
new file mode 100644
index 000000000..6ece69169
--- /dev/null
+++ b/evidence/MEANING_GRAPH/f451759e3d02fd7eb737cf7a4aa1b39fcf745e700653abc5797e1e658935544e.json
@@ -0,0 +1,44 @@
+{
+  "schema": "omega.meaning.run.v1",
+  "label": "EXERCISED (host, arm64); not QUALIFIED, not MERGED",
+  "source_commit": "8bda54965e3fbebbbb0a8918867546bff2d2e796",
+  "branch": "meaning-graph",
+  "clean_tree": true,
+  "command": "taskset -c 10-14 nice -n 19 ionice -c3 sh om/meaning/test/run.sh seed/out/omc",
+  "run_sh_sha256": "f5ac0b4bed6f47050c9a6b9ac07ee3b5196e8e155ef4f20666ec5fff63f3a4b3",
+  "host": "Linux 7.0.0-1019-nvidia aarch64",
+  "finished_utc": "2026-10-30T03:00:34Z",
+  "exit_code": 0,
+  "verdict": "MEANING PASS checks=92883 mutants=10/10",
+  "output": [
+    "omc        sha256 62775d2a391cfef7cde64e387655caa9809a267093112910ec76bfa568f3712b",
+    "sha2.om    sha256 5cf0f98116def6917d3a373f2bd4c3932d46e3ff84d9567bbae9e720366fdb33",
+    "meaning.om sha256 ac30a227d9384b61bc3c3500b8c4ed70d3e49012af953469c4ae60a1c22268f4",
+    "driver.om  sha256 379e9226822b18d6f31e5c86cc623f362903d1cb7a62202382c45b6a6fcdc990",
+    "vectors    sha256 f4d9e0114d2f276389a7b799b796859b87977283479a5679eb8a0adc5549092f",
+    "PASS golden: H 0 11b8858ec5c305c0160d84eb2f30786c9429731bc6a88516d530ecefc819bef2",
+    "PASS golden: H 2 11b8858ec5c305c0160d84eb2f30786c9429731bc6a88516d530ecefc819bef2",
+    "PASS golden: H 8 96cb6ace92436b94aa6f49967d967b900f069c6c34b9cf73f7ce2d7d773cc1fa",
+    "PASS golden: H 9 96cb6ace92436b94aa6f49967d967b900f069c6c34b9cf73f7ce2d7d773cc1fa",
+    "PASS golden: H 19 89877bca66e566c52e7dbc92df7fc3bacb25542066df417a3641f504e1d216eb",
+    "  R w=1 programs=64 pairs=2016 equal_id_pairs=514 canonical=58",
+    "  R w=3 programs=300 pairs=44850 equal_id_pairs=1197 canonical=225",
+    "  R w=8 programs=300 pairs=44850 equal_id_pairs=1053 canonical=244",
+    "  R w=16 programs=120 pairs=7140 equal_id_pairs=105 canonical=99",
+    "  R w=64 programs=300 pairs=44850 equal_id_pairs=785 canonical=239",
+    "  G nodes=121 edges=126 receipts=33 bytes=34896 tampered=945",
+    "PASS vectors: meaning driver: 92883 checks, 0 failed",
+    "PASS mutant-kof-minus-1: detected (549 FAIL lines, first: FAIL line 96 code 22)",
+    "PASS mutant-inverse-4-steps: detected (4 FAIL lines, first: FAIL line 229 code 9)",
+    "PASS mutant-inverse-start-1: detected (4 FAIL lines, first: FAIL line 229 code 9)",
+    "PASS mutant-and-ones-dropped: detected (4 FAIL lines, first: FAIL line 80 code 21)",
+    "PASS mutant-and-one-accepted: detected (6 FAIL lines, first: FAIL line 80 code 21)",
+    "PASS mutant-apply-payload-160: detected (2 FAIL lines, first: FAIL line 129 code 6)",
+    "PASS mutant-sort-cmp-never: detected (4 FAIL lines, first: FAIL line 230 code 13)",
+    "PASS mutant-fid-domain: detected (5 FAIL lines, first: FAIL line 132 code 27)",
+    "PASS mutant-expect-c: detected (1 FAIL lines, first: FAIL line 93 code 21)",
+    "PASS mutant-expect-n: detected (1 FAIL lines, first: FAIL line 72 code 22)",
+    "PASS neg-define: detected (1 FAIL lines, first: FAIL line 1 code 1)",
+    "MEANING PASS checks=92883 mutants=10/10"
+  ]
+}
diff --git a/om/meaning/meaning.om b/om/meaning/meaning.om
new file mode 100644
index 000000000..014e917c1
--- /dev/null
+++ b/om/meaning/meaning.om
@@ -0,0 +1,1798 @@
+note SPDX-License-Identifier: Apache-2.0
+note om/meaning/meaning.om: FUNCTION_ID (omega.function.v1) and the graph of meaning, as an OM-2
+note library unit for program mode (no om2 line, no main; it keeps its state in mg* globals, so it
+note links only into a program, not into function mode). Needs om/tls/sha2.om before it.
+note Specification: spec/program-identity.md section 9 (FUNCTION_ID) and section 10 (graph).
+note
+note Programs. A program is a width w (1..64) and a postfix (RPN) token list over
+note   1 x (the parameter)   2 c (a constant below 2^w)   3 add  4 sub  5 mul  9 and  10 or
+note (the token codes are the OpCode numbers of src/omega_types.h; 1 and 2 are OP_IDENTITY and
+note OP_CONSTANT read as "parameter" and "literal"). Arithmetic wraps modulo 2^w. The V0 program
+note body of spec/program-identity.md 2.1, f(x) = op_n(...op_1(x, c_1)..., c_n), is the token list
+note x c_1 op_1 c_2 op_2 ... c_n op_n.
+note
+note API (p is a program index, n a node index, slot a 32-byte id slot in mgi)
+note   mg_reset                         empty programs, ids and graph
+note   mg_pnew w -> p; mg_ptok p op v   build a program token by token
+note   mg_pchk p -> 0 | code            0 = well formed (see the function for codes)
+note   mg_eval p x -> f(x)              the semantics: wrap arithmetic modulo 2^w
+note   mg_frag p -> 1 | 0               1 = the polynomial fragment (FUNCTION_ID is canonical)
+note   mg_canon p -> K                  canonical falling-factorial coefficients into mgc[0..K)
+note   mg_fid p slot -> 1 | 2           FUNCTION_ID into slot: 1 canonical, 2 intensional fallback
+note   mg_body p slot                   the body's SEMANTIC_ID (OMG0 apply graph, as the C builders)
+note   mg_pid bs w po pl qo ql          program_id v2 (omega.program.v2) into slot 102
+note   mg_addprog p po pl qo ql -> n    add the program, its body and its function to the graph
+note   mg_exh a b, mg_wit a b           prove two body nodes equal (exhaustive, w <= 32) or not
+note   mg_nbr n rel, mg_class n, mg_prov n   queries into mgq; return the count
+note   mg_verify -> failures            recheck every node id and every edge receipt
+note   mg_ser -> length, mg_gdig slot, mg_load length   canonical storage in mgo, its digest, reading
+note Contract texts (pre/post) are byte runs in the heap mgh, written with mg_hpush.
+
+const MGNMAX ulong 4096
+const MGRMAX ulong 8192
+const MGEMAX ulong 16384
+const MGNONE ulong 18446744073709551615
+
+global mgs ulong 64
+global mgtk ulong 2097152
+global mgpr ulong 262144
+global mgst ulong 64
+global mgcl ulong 64
+global mgcv ulong 64
+global mgc ulong 80
+global mgd ulong 80
+global mgb uchar 4096
+global mgi uchar 1048576
+global mgh uchar 4194304
+global mgnd ulong 16384
+global mgrc ulong 16384
+global mged ulong 65536
+global mgq ulong 16384
+global mgsn ulong 4096
+global mgsr ulong 8192
+global mgse ulong 16384
+global mgvp ulong 4096
+global mgo uchar 4194304
+text mgtfd "omega.function.v1"
+text mgtpd "omega.program.v2"
+text mgtrd "omega.meaning.receipt.v1"
+text mgtgd "omega.meaning.graph.v1"
+text mgtpa "omega.param"
+
+note mgs cells: 0 tokens used, 1 programs, 2 mgb cursor, 3 nodes, 4 receipts, 5 edges, 6 heap used,
+note 8 mgo cursor, 9 mgo read cursor, 10 read error flag, 11 read limit
+note id slots: 0 type, 1 param, 2 operation, 3 pre, 4 post, 5 fallback body, 16..79 body stack,
+note 100 body, 101 function, 102 program, 103 receipt, 104..109 verify and load scratch,
+note 1024 + n node n, 8192 + r receipt r, 16384.. free for callers
+
+fn mg_reset to void
+for i ulong 16
+put mgs i 0
+end
+end
+
+fn mg_mask w ulong to ulong
+if ge w 64
+ret not ulong 0
+end
+ret sub shl ulong 1 w 1
+end
+
+note ---- programs ----
+
+fn mg_pnew w ulong to ulong
+p = get mgs 1
+if ge p 65536
+trap 12
+end
+put mgpr mul p 4 get mgs 0
+put mgpr add mul p 4 1 0
+put mgpr add mul p 4 2 w
+put mgs 1 add p 1
+ret p
+end
+
+fn mg_ptok p ulong o ulong v ulong to void
+t = get mgs 0
+if ge t 1048576
+trap 12
+end
+put mgtk mul t 2 o
+put mgtk add mul t 2 1 v
+put mgs 0 add t 1
+q = add mul p 4 1
+put mgpr q add get mgpr q 1
+end
+
+fn mg_top t ulong to ulong
+ret get mgtk mul t 2
+end
+
+fn mg_tv t ulong to ulong
+ret get mgtk add mul t 2 1
+end
+
+fn mg_pw p ulong to ulong
+ret get mgpr add mul p 4 2
+end
+
+note 0 well formed; 1 width not 1..64; 2 no tokens or over 4096; 3 unknown token; 4 constant not
+note below 2^w; 5 operation without two operands; 6 stack over 64; 7 not exactly one result
+fn mg_pchk p ulong to ulong
+b = get mgpr mul p 4
+n = get mgpr add mul p 4 1
+w = mg_pw p
+if eq w 0
+ret 1
+end
+if gt w 64
+ret 1
+end
+if eq n 0
+ret 2
+end
+if gt n 4096
+ret 2
+end
+m = mg_mask w
+sp = ulong 0
+for i ulong n
+o = mg_top add b i
+v = mg_tv add b i
+if le o 2
+if eq o 0
+ret 3
+end
+if eq o 2
+if ne and v not m 0
+ret 4
+end
+end
+if ge sp 64
+ret 6
+end
+sp = add sp 1
+continue
+end
+if ne o 3
+if ne o 4
+if ne o 5
+if ne o 9
+if ne o 10
+ret 3
+end
+end
+end
+end
+end
+if lt sp 2
+ret 5
+end
+sp = sub sp 1
+end
+if ne sp 1
+ret 7
+end
+ret 0
+end
+
+fn mg_op o ulong l ulong r ulong m ulong to ulong
+if eq o 3
+ret and add l r m
+end
+if eq o 4
+ret and sub l r m
+end
+if eq o 5
+ret and mul l r m
+end
+if eq o 9
+ret and l r
+end
+if eq o 10
+ret and or l r m
+end
+trap 9
+end
+
+fn mg_eval p ulong x ulong to ulong
+b = get mgpr mul p 4
+n = get mgpr add mul p 4 1
+m = mg_mask mg_pw p
+sp = ulong 0
+for i ulong n
+o = mg_top add b i
+if eq o 1
+put mgst sp and x m
+sp = add sp 1
+continue
+end
+if eq o 2
+put mgst sp mg_tv add b i
+sp = add sp 1
+continue
+end
+sp = sub sp 1
+put mgst sub sp 1 mg_op o get mgst sub sp 1 get mgst sp m
+end
+ret get mgst 0
+end
+
+note ---- the polynomial fragment ----
+note Abstract evaluation, one class per stack entry: 0 constant (value in mgcv), 1 polynomial in x,
+note 2 outside. add sub mul of classes 0/1 stay polynomial; mul by the constant 0 is the constant 0.
+note and/or with a constant side: and all-ones = the other side, and 0 = constant 0, or 0 = the other
+note side, or all-ones = constant all-ones (exact identities modulo 2^w). Everything else is class 2.
+
+fn mg_fset j ulong c ulong v ulong to void
+put mgcl j c
+put mgcv j v
+end
+
+fn mg_fstep o ulong j ulong m ulong to void
+lc = get mgcl j
+rc = get mgcl add j 1
+lv = get mgcv j
+rv = get mgcv add j 1
+if eq lc 0
+if eq rc 0
+mg_fset j 0 mg_op o lv rv m
+ret
+end
+end
+if le o 5
+if eq o 5
+if eq lc 0
+if eq lv 0
+mg_fset j 0 0
+ret
+end
+end
+if eq rc 0
+if eq rv 0
+mg_fset j 0 0
+ret
+end
+end
+end
+if eq lc 2
+mg_fset j 2 0
+ret
+end
+if eq rc 2
+mg_fset j 2 0
+ret
+end
+mg_fset j 1 0
+ret
+end
+c = ulong 0
+oc = ulong 2
+ov = ulong 0
+if eq lc 0
+c = lv
+oc = rc
+ov = rv
+else
+if eq rc 0
+c = rv
+oc = lc
+ov = lv
+else
+mg_fset j 2 0
+ret
+end
+end
+if eq o 9
+if eq c m
+mg_fset j oc ov
+ret
+end
+if eq c 0
+mg_fset j 0 0
+ret
+end
+mg_fset j 2 0
+ret
+end
+if eq c 0
+mg_fset j oc ov
+ret
+end
+if eq c m
+mg_fset j 0 m
+ret
+end
+mg_fset j 2 0
+end
+
+fn mg_frag p ulong to ulong
+b = get mgpr mul p 4
+n = get mgpr add mul p 4 1
+m = mg_mask mg_pw p
+sp = ulong 0
+for i ulong n
+o = mg_top add b i
+if eq o 1
+mg_fset sp 1 0
+sp = add sp 1
+continue
+end
+if eq o 2
+mg_fset sp 0 mg_tv add b i
+sp = add sp 1
+continue
+end
+sp = sub sp 1
+mg_fstep o sub sp 1 m
+end
+if eq get mgcl 0 2
+ret 0
+end
+ret 1
+end
+
+note ---- canonical form (spec/program-identity.md 9.2) ----
+
+fn mg_tz k ulong to ulong
+t = k
+z = ulong 0
+while eq and t 1 0 bound 64
+t = shr t 1
+z = add z 1
+end
+ret z
+end
+
+note K(w): the least k with v2(k!) >= w (Wolfram table in the spec: K(8) = 10, K(64) = 66)
+fn mg_kof w ulong to ulong
+v = ulong 0
+k = ulong 0
+while lt v w bound 200
+k = add k 1
+v = add v mg_tz k
+end
+ret k
+end
+
+note inverse of an odd u modulo 2^64: Newton y <- y (2 - u y), 3 -> 6 -> 12 -> 24 -> 48 -> 96 bits
+fn mg_inv u ulong to ulong
+y = u
+for i ulong 5
+y = mul y sub 2 mul u y
+end
+ret y
+end
+
+note f(0..K-1), forward differences d_k = Delta^k f(0) mod 2^w = k! b_k, then with k! = 2^v u (u odd)
+note a_k = (d_k / 2^v) u^-1 mod 2^(w - v): the unique coefficients with 0 <= a_k < 2^(w - v2(k!)) and
+note f(x) = sum a_k x(x-1)...(x-k+1) mod 2^w. A d_k not divisible by 2^v means f is not a polynomial
+note function: trap 9 (the fragment check makes this unreachable).
+fn mg_canon p ulong to ulong
+w = mg_pw p
+m = mg_mask w
+kk = mg_kof w
+for t ulong kk
+put mgd t mg_eval p t
+end
+k = ulong 1
+while lt k kk bound 100
+j = sub kk 1
+while ge j k bound 100
+put mgd j and sub get mgd j get mgd sub j 1 m
+j = sub j 1
+end
+k = add k 1
+end
+u = ulong 1
+v = ulong 0
+for i ulong kk
+if gt i 0
+u = mul u shr i mg_tz i
+v = add v mg_tz i
+end
+dk = get mgd i
+if ne and dk sub shl ulong 1 v 1 0
+trap 9
+end
+a = mul shr dk v mg_inv u
+put mgc i and a mg_mask sub w v
+end
+ret kk
+end
+
+note ---- byte building and hashing ----
+
+fn mg_b0 to void
+put mgs 2 0
+end
+
+fn mg_b8 v ulong to void
+c = get mgs 2
+put mgb c uchar and v 255
+put mgs 2 add c 1
+end
+
+fn mg_b16 v ulong to void
+mg_b8 shr v 8
+mg_b8 v
+end
+
+fn mg_b32 v ulong to void
+mg_b16 shr v 16
+mg_b16 and v 65535
+end
+
+fn mg_b64 v ulong to void
+mg_b32 shr v 32
+mg_b32 and v 4294967295
+end
+
+fn mg_bz n ulong to void
+for i ulong n
+mg_b8 0
+end
+end
+
+fn mg_bid s ulong to void
+o = mul s 32
+for i ulong 32
+mg_b8 ulong get mgi add o i
+end
+end
+
+fn mg_bh o ulong n ulong to void
+for i ulong n
+mg_b8 ulong get mgh add o i
+end
+end
+
+note domain tags (always followed by 0x00): 1 function, 2 program v2, 3 receipt, 4 graph
+fn mg_bdom k ulong to void
+mg_b0
+if eq k 1
+for i ulong len mgtfd
+mg_b8 ulong get mgtfd i
+end
+end
+if eq k 2
+for i ulong len mgtpd
+mg_b8 ulong get mgtpd i
+end
+end
+if eq k 3
+for i ulong len mgtrd
+mg_b8 ulong get mgtrd i
+end
+end
+mg_b8 0
+end
+
+fn mg_hash s ulong to void
+n = get mgs 2
+a = new uchar 4096 0
+o = new uchar 32 0
+for i ulong n
+put a i get mgb i
+end
+k = sha2_digest 256 part a 0 n o
+if ne k 32
+trap 10
+end
+for j ulong 32
+put mgi add mul s 32 j get o j
+end
+end
+
+fn mg_idcp s ulong d ulong to void
+for i ulong 32
+put mgi add mul d 32 i get mgi add mul s 32 i
+end
+end
+
+note 0 equal, 1 a < b, 2 a > b (bytewise, as memcmp)
+fn mg_idcmp a ulong b ulong to ulong
+for i ulong 32
+x = get mgi add mul a 32 i
+y = get mgi add mul b 32 i
+if lt x y
+ret 1
+end
+if gt x y
+ret 2
+end
+end
+ret 0
+end
+
+fn mg_idz s ulong to void
+for i ulong 32
+put mgi add mul s 32 i 0
+end
+end
+
+note ---- OMG0 objects (spec/canonical-encoding.md; payloads are the C host-struct images of
+note src/omega_types.h on LP64 little-endian, zero padded, exactly as src/omega_core.c hashes them) ----
+
+fn mg_bhdr k ulong to void
+mg_b0
+mg_b8 79
+mg_b8 77
+mg_b8 71
+mg_b8 48
+mg_b8 1
+mg_b8 k
+end
+
+note TypePayload{tag u32 = 3 UNSIGNED_INT, width u16, pad 2, length u32 0, elem_type 32 zero}: 44 bytes
+fn mg_tyid w ulong s ulong to void
+mg_bhdr 2
+mg_b16 0
+mg_b16 0
+mg_b16 0
+mg_b32 44
+mg_b8 3
+mg_bz 3
+mg_b8 and w 255
+mg_b8 shr w 8
+mg_bz 38
+mg_hash s
+end
+
+note parameter 0: attribute "omega.param" = 00 00, ValuePayload{type_id, byte_len 0, bytes 0}: 98
+fn mg_parid t ulong s ulong to void
+mg_bhdr 1
+mg_b16 1
+mg_b8 len mgtpa
+for i ulong len mgtpa
+mg_b8 ulong get mgtpa i
+end
+mg_b16 2
+mg_b16 0
+mg_b16 0
+mg_b16 0
+mg_b32 98
+mg_bid t
+mg_bz 66
+end
+
+fn mg_parfin s ulong to void
+mg_hash s
+end
+
+note literal: ValuePayload{type_id, byte_len LE = (w+7)/8, value big-endian in byte_len bytes}: 98
+fn mg_valid t ulong w ulong v ulong s ulong to void
+mg_bhdr 1
+mg_b16 0
+mg_b16 0
+mg_b16 0
+mg_b32 98
+mg_bid t
+nb = shr add w 7 3
+mg_b8 nb
+mg_b8 0
+for i ulong nb
+mg_b8 shr v mul sub sub nb 1 i 8
+end
+mg_bz sub 64 nb
+mg_hash s
+end
+
+note OperationPayload{opcode u32, overflow u32 = 1 WRAP, type_id, arity 2, input_types T T 0 0,
+note output_type T, pad 3}: 204 bytes
+fn mg_opid t ulong o ulong s ulong to void
+mg_bhdr 3
+mg_b16 0
+mg_b16 0
+mg_b16 0
+mg_b32 204
+mg_b8 o
+mg_bz 3
+mg_b8 1
+mg_bz 3
+mg_bid t
+mg_b8 2
+mg_bid t
+mg_bid t
+mg_bz 64
+mg_bid t
+mg_bz 3
+mg_hash s
+end
+
+note ApplyPayload{op_id, operand_count 2, operands a b 0 0}: 161 bytes
+fn mg_apid o ulong a ulong b ulong s ulong to void
+mg_bhdr 3
+mg_b16 0
+mg_b16 0
+mg_b16 0
+mg_b32 161
+mg_bid o
+mg_b8 2
+mg_bid a
+mg_bid b
+mg_bz 64
+mg_hash s
+end
+
+note the body's SEMANTIC_ID: the root apply object built bottom-up; for a V0 chain this is exactly
+note omega_program_body_root_id (src/omega_program.c), checked against the program_id goldens
+fn mg_body p ulong s ulong to void
+b = get mgpr mul p 4
+n = get mgpr add mul p 4 1
+w = mg_pw p
+mg_tyid w 0
+mg_parid 0 1
+mg_parfin 1
+sp = ulong 16
+for i ulong n
+o = mg_top add b i
+if eq o 1
+mg_idcp 1 sp
+sp = add sp 1
+continue
+end
+if eq o 2
+mg_valid 0 w mg_tv add b i sp
+sp = add sp 1
+continue
+end
+mg_opid 0 o 2
+mg_apid 2 sub sp 2 sub sp 1 sub sp 2
+sp = sub sp 1
+end
+mg_idcp 16 s
+end
+
+note constraint object: no attributes or relations, one constraint {kind, text}, empty payload
+fn mg_cid k ulong o ulong n ulong s ulong to void
+if gt n 128
+trap 10
+end
+mg_bhdr 5
+mg_b16 0
+mg_b16 0
+mg_b16 1
+mg_b16 k
+mg_b16 n
+mg_bh o n
+mg_b32 0
+mg_hash s
+end
+
+note program_id v2 = SHA256("omega.program.v2" 0x00 || body || T(w) || T(w) || pre || post) -> slot 102
+fn mg_pid bs ulong w ulong po ulong pl ulong qo ulong ql ulong to void
+mg_tyid w 0
+mg_cid 7 po pl 3
+mg_cid 8 qo ql 4
+mg_bdom 2
+mg_bid bs
+mg_bid 0
+mg_bid 0
+mg_bid 3
+mg_bid 4
+mg_hash 102
+end
+
+note ---- FUNCTION_ID (spec/program-identity.md 9) ----
+note class 1: SHA256("omega.function.v1" 0x00 || 01 || w u16 || K u16 || a_0..a_{K-1} u64 BE)
+note class 2: SHA256("omega.function.v1" 0x00 || 02 || w u16 || body SEMANTIC_ID)
+note The preimage stays in mgb after the call.
+fn mg_fid p ulong s ulong to ulong
+w = mg_pw p
+if eq mg_frag p 1
+kk = mg_canon p
+mg_bdom 1
+mg_b8 1
+mg_b16 w
+mg_b16 kk
+for i ulong kk
+mg_b64 get mgc i
+end
+mg_hash s
+ret 1
+end
+mg_body p 5
+mg_bdom 1
+mg_b8 2
+mg_b16 w
+mg_bid 5
+mg_hash s
+ret 2
+end
+
+note ---- heap ----
+
+fn mg_hpush v ulong to void
+h = get mgs 6
+if ge h len mgh
+trap 12
+end
+put mgh h uchar and v 255
+put mgs 6 add h 1
+end
+
+fn mg_hpos to ulong
+ret get mgs 6
+end
+
+note copy mgb[from..cursor) to the heap; returns its offset
+fn mg_hput f ulong to ulong
+h = get mgs 6
+c = get mgs 2
+for i ulong sub c f
+mg_hpush ulong get mgb add f i
+end
+ret h
+end
+
+fn mg_h8 o ulong to ulong
+ret ulong get mgh o
+end
+
+fn mg_h16 o ulong to ulong
+ret or shl mg_h8 o 8 mg_h8 add o 1
+end
+
+fn mg_h64 o ulong to ulong
+v = ulong 0
+for i ulong 8
+v = or shl v 8 mg_h8 add o i
+end
+ret v
+end
+
+note ---- graph store (spec/program-identity.md 10) ----
+note node kinds: 1 PROGRAM (program_id v2), 2 BODY (body SEMANTIC_ID), 3 FUNCTION (FUNCTION_ID)
+note node cells: kind, heap offset, content length, aux (BODY: program index; FUNCTION: class;
+note PROGRAM: body node). Edge cells: src node, rel, dst node, receipt index + 1 (0 = none).
+note rel codes are RelationKind (src/omega_types.h): 2 NOT_EQUAL, 4 CONTAINS, 7 DERIVED_FROM,
+note 9 EQUIVALENT_TO.
+
+fn mg_ns n ulong to ulong
+ret add 1024 n
+end
+
+fn mg_nk n ulong to ulong
+ret get mgnd mul n 4
+end
+
+fn mg_no n ulong to ulong
+ret get mgnd add mul n 4 1
+end
+
+fn mg_nl n ulong to ulong
+ret get mgnd add mul n 4 2
+end
+
+fn mg_na n ulong to ulong
+ret get mgnd add mul n 4 3
+end
+
+fn mg_nfind s ulong to ulong
+for i ulong get mgs 3
+if eq mg_idcmp s mg_ns i 0
+ret i
+end
+end
+ret MGNONE
+end
+
+fn mg_nadd k ulong s ulong o ulong l ulong a ulong to ulong
+f = mg_nfind s
+if ne f MGNONE
+if ne mg_nk f k
+trap 11
+end
+ret f
+end
+n = get mgs 3
+if ge n MGNMAX
+trap 12
+end
+mg_idcp s mg_ns n
+put mgnd mul n 4 k
+put mgnd add mul n 4 1 o
+put mgnd add mul n 4 2 l
+put mgnd add mul n 4 3 a
+put mgs 3 add n 1
+ret n
+end
+
+fn mg_rfind s ulong to ulong
+for i ulong get mgs 4
+if eq mg_idcmp s add 8192 i 0
+ret i
+end
+end
+ret MGNONE
+end
+
+note receipt content is mgb[25..cursor) after mg_bdom 3; id = SHA256(whole mgb) -> slot 103
+fn mg_radd to ulong
+mg_hash 103
+f = mg_rfind 103
+if ne f MGNONE
+ret f
+end
+r = get mgs 4
+if ge r MGRMAX
+trap 12
+end
+h = mg_hput 25
+put mgrc mul r 2 h
+put mgrc add mul r 2 1 sub get mgs 2 25
+mg_idcp 103 add 8192 r
+put mgs 4 add r 1
+ret r
+end
+
+fn mg_eadd s ulong rl ulong d ulong r ulong to void
+ne0 = get mgs 5
+for e ulong ne0
+if eq get mged mul e 4 s
+if eq get mged add mul e 4 1 rl
+if eq get mged add mul e 4 2 d
+if eq get mged add mul e 4 3 r
+ret
+end
+end
+end
+end
+end
+if ge ne0 MGEMAX
+trap 12
+end
+put mged mul ne0 4 s
+put mged add mul ne0 4 1 rl
+put mged add mul ne0 4 2 d
+put mged add mul ne0 4 3 r
+put mgs 5 add ne0 1
+end
+
+fn mg_lo a ulong b ulong to ulong
+if eq mg_idcmp mg_ns a mg_ns b 2
+ret b
+end
+ret a
+end
+
+note receipt kind 1 CANON: 01 || lo id || hi id || w u16 || FUNCTION_ID
+fn mg_rcanon a ulong b ulong f ulong to void
+lo = mg_lo a b
+hi = sub add a b lo
+mg_bdom 3
+mg_b8 1
+mg_bid mg_ns lo
+mg_bid mg_ns hi
+mg_b16 mg_pw mg_na lo
+mg_bid mg_ns f
+r = mg_radd
+mg_eadd lo 9 hi add r 1
+end
+
+fn mg_fnode bn ulong to void
+cl = mg_fid mg_na bn 101
+h = mg_hput 0
+fnn = mg_nadd 3 101 h get mgs 2 cl
+mg_eadd fnn 7 bn 0
+if ne cl 1
+ret
+end
+for e ulong get mgs 5
+if eq get mged mul e 4 fnn
+if eq get mged add mul e 4 1 7
+o = get mged add mul e 4 2
+if ne o bn
+mg_rcanon o bn fnn
+end
+end
+end
+end
+end
+
+note body content: w u16 || token count u16 || tokens (op u8, and for op 2 the constant u64 BE)
+fn mg_bcont p ulong to void
+b = get mgpr mul p 4
+n = get mgpr add mul p 4 1
+mg_b0
+mg_b16 mg_pw p
+mg_b16 n
+for i ulong n
+o = mg_top add b i
+mg_b8 o
+if eq o 2
+mg_b64 mg_tv add b i
+end
+end
+end
+
+note program content: body id || w u16 || pre length u16 || pre || post length u16 || post
+fn mg_addprog p ulong po ulong pl ulong qo ulong ql ulong to ulong
+w = mg_pw p
+mg_body p 100
+mg_bcont p
+h = mg_hput 0
+n0 = get mgs 3
+bn = mg_nadd 2 100 h get mgs 2 p
+if gt get mgs 3 n0
+mg_fnode bn
+end
+mg_pid 100 w po pl qo ql
+mg_b0
+mg_bid 100
+mg_b16 w
+mg_b16 pl
+mg_bh po pl
+mg_b16 ql
+mg_bh qo ql
+h = mg_hput 0
+pn = mg_nadd 1 102 h get mgs 2 bn
+mg_eadd pn 4 bn 0
+ret pn
+end
+
+note 0 when the programs agree on all 2^w inputs (w <= 32), else first differing x + 1
+fn mg_exeq pa ulong pb ulong w ulong to ulong
+inner = ulong 65536
+outer = ulong 1
+if lt w 16
+inner = shl ulong 1 w
+else
+outer = shl ulong 1 sub w 16
+end
+for oi ulong outer
+for ii ulong inner
+x = add mul oi inner ii
+if ne mg_eval pa x mg_eval pb x
+ret add x 1
+end
+end
+end
+ret 0
+end
+
+note receipt kind 3 WITNESS: 03 || lo || hi || w u16 || x u64 || f_lo(x) u64 || f_hi(x) u64
+fn mg_rwit a ulong b ulong x ulong to void
+lo = mg_lo a b
+hi = sub add a b lo
+mg_bdom 3
+mg_b8 3
+mg_bid mg_ns lo
+mg_bid mg_ns hi
+mg_b16 mg_pw mg_na lo
+mg_b64 x
+mg_b64 mg_eval mg_na lo x
+mg_b64 mg_eval mg_na hi x
+r = mg_radd
+mg_eadd lo 2 hi add r 1
+end
+
+note 0 equal (EQUIVALENT_TO edge with an EXHAUSTIVE receipt), 1 differ (NOT_EQUAL edge with a
+note WITNESS receipt), 3 widths differ, 4 w over 32. a and b are BODY nodes.
+fn mg_exh a ulong b ulong to ulong
+pa = mg_na a
+pb = mg_na b
+w = mg_pw pa
+if ne w mg_pw pb
+ret 3
+end
+if gt w 32
+ret 4
+end
+x = mg_exeq pa pb w
+if ne x 0
+mg_rwit a b sub x 1
+ret 1
+end
+lo = mg_lo a b
+hi = sub add a b lo
+mg_bdom 3
+mg_b8 2
+mg_bid mg_ns lo
+mg_bid mg_ns hi
+mg_b16 w
+mg_b64 shl ulong 1 w
+r = mg_radd
+mg_eadd lo 9 hi add r 1
+ret 0
+end
+
+note candidate inputs: 0..127, the edges (all-ones, all-ones - 1, 2^(w-1), 2^(w-1) - 1), then splitmix64
+fn mg_cand i ulong w ulong to ulong
+m = mg_mask w
+if lt i 128
+ret and i m
+end
+if eq i 128
+ret m
+end
+if eq i 129
+ret and sub m 1 m
+end
+if eq i 130
+ret shl ulong 1 sub w 1
+end
+if eq i 131
+ret and sub shl ulong 1 sub w 1 1 m
+end
+z = mul i 0x9e3779b97f4a7c15
+z = mul xor z shr z 30 0xbf58476d1ce4e5b9
+z = mul xor z shr z 27 0x94d049bb133111eb
+ret and xor z shr z 31 m
+end
+
+note search 4096 candidates for a witness; 1 found (NOT_EQUAL edge added), 0 none (nothing added:
+note no witness is not a proof of equality)
+fn mg_wit a ulong b ulong to ulong
+pa = mg_na a
+pb = mg_na b
+w = mg_pw pa
+if ne w mg_pw pb
+ret 0
+end
+for i ulong 4096
+x = mg_cand i w
+if ne mg_eval pa x mg_eval pb x
+mg_rwit a b x
+ret 1
+end
+end
+ret 0
+end
+
+note ---- queries (results in mgq) ----
+
+fn mg_qhas v ulong n ulong to ulong
+for i ulong n
+if eq get mgq i v
+ret 1
+end
+end
+ret 0
+end
+
+note every node joined to n by an edge (either direction); rel 0 = any relation
+fn mg_nbr n ulong rl ulong to ulong
+c = ulong 0
+for e ulong get mgs 5
+r = get mged add mul e 4 1
+if eq rl 0
+r = rl
+end
+if eq r rl
+s = get mged mul e 4
+d = get mged add mul e 4 2
+if eq s n
+put mgq c d
+c = add c 1
+else
+if eq d n
+put mgq c s
+c = add c 1
+end
+end
+end
+end
+ret c
+end
+
+note the equivalence class of n: closure over EQUIVALENT_TO edges, n first
+fn mg_class n ulong to ulong
+put mgq 0 n
+c = ulong 1
+h = ulong 0
+while lt h c bound 16384
+v = get mgq h
+for e ulong get mgs 5
+if eq get mged add mul e 4 1 9
+s = get mged mul e 4
+d = get mged add mul e 4 2
+o = MGNONE
+if eq s v
+o = d
+end
+if eq d v
+o = s
+end
+if ne o MGNONE
+if eq mg_qhas o c 0
+put mgq c o
+c = add c 1
+end
+end
+end
+end
+h = add h 1
+end
+ret c
+end
+
+note provenance of n: every edge index touching n (its receipts explain each relation)
+fn mg_prov n ulong to ulong
+c = ulong 0
+for e ulong get mgs 5
+if eq get mged mul e 4 n
+put mgq c e
+c = add c 1
+else
+if eq get mged add mul e 4 2 n
+put mgq c e
+c = add c 1
+end
+end
+end
+ret c
+end
+
+note ---- verification ----
+
+note rebuild a program from body content at heap o, length l; MGNONE if malformed
+fn mg_bparse o ulong l ulong to ulong
+if lt l 4
+ret MGNONE
+end
+w = mg_h16 o
+n = mg_h16 add o 2
+if eq n 0
+ret MGNONE
+end
+if gt n 4096
+ret MGNONE
+end
+p = mg_pnew w
+q = add o 4
+e = add o l
+for i ulong n
+if ge q e
+ret MGNONE
+end
+t = mg_h8 q
+q = add q 1
+v = ulong 0
+if eq t 2
+if gt add q 8 e
+ret MGNONE
+end
+v = mg_h64 q
+q = add q 8
+end
+mg_ptok p t v
+end
+if ne q e
+ret MGNONE
+end
+if ne mg_pchk p 0
+ret MGNONE
+end
+ret p
+end
+
+fn mg_hideq o ulong s ulong to ulong
+for i ulong 32
+if ne get mgh add o i get mgi add mul s 32 i
+ret 0
+end
+end
+ret 1
+end
+
+fn mg_hid o ulong s ulong to void
+for i ulong 32
+put mgi add mul s 32 i get mgh add o i
+end
+end
+
+note 1 when node n (kind 1) has well-formed content whose program_id v2 recomputes to its id
+fn mg_vprog n ulong to ulong
+o = mg_no n
+l = mg_nl n
+if lt l 38
+ret 0
+end
+w = mg_h16 add o 32
+pl = mg_h16 add o 34
+if gt add 38 pl l
+ret 0
+end
+ql = mg_h16 add add o 36 pl
+if ne l add add 38 pl ql
+ret 0
+end
+mg_hid o 106
+mg_pid 106 w add o 36 pl add add o 38 pl ql
+if eq mg_idcmp 102 mg_ns n 0
+ret 1
+end
+ret 0
+end
+
+fn mg_vnodes to ulong
+bad = ulong 0
+for n ulong get mgs 3
+k = mg_nk n
+put mgvp n MGNONE
+if eq k 2
+p = mg_bparse mg_no n mg_nl n
+if eq p MGNONE
+bad = add bad 1
+continue
+end
+put mgvp n p
+mg_body p 104
+if ne mg_idcmp 104 mg_ns n 0
+bad = add bad 1
+end
+continue
+end
+if eq k 3
+mg_b0
+mg_bh mg_no n mg_nl n
+mg_hash 105
+if ne mg_idcmp 105 mg_ns n 0
+bad = add bad 1
+end
+continue
+end
+if eq k 1
+if eq mg_vprog n 0
+bad = add bad 1
+end
+continue
+end
+bad = add bad 1
+end
+ret bad
+end
+
+fn mg_vrecs to ulong
+bad = ulong 0
+for r ulong get mgs 4
+mg_bdom 3
+mg_bh get mgrc mul r 2 get mgrc add mul r 2 1
+mg_hash 105
+if ne mg_idcmp 105 add 8192 r 0
+bad = add bad 1
+end
+end
+ret bad
+end
+
+note 1 when the receipt of edge e (src s, rel rl, dst d) proves the relation
+fn mg_vrec s ulong rl ulong d ulong ri ulong to ulong
+if eq ri 0
+ret 0
+end
+o = get mgrc mul sub ri 1 2
+l = get mgrc add mul sub ri 1 2 1
+if lt l 67
+ret 0
+end
+k = mg_h8 o
+if eq mg_hideq add o 1 mg_ns s 0
+ret 0
+end
+if eq mg_hideq add o 33 mg_ns d 0
+ret 0
+end
+if ne mg_idcmp mg_ns s mg_ns d 1
+ret 0
+end
+pa = get mgvp s
+pb = get mgvp d
+if eq pa MGNONE
+ret 0
+end
+if eq pb MGNONE
+ret 0
+end
+w = mg_h16 add o 65
+if ne w mg_pw pa
+ret 0
+end
+if ne w mg_pw pb
+ret 0
+end
+if eq k 1
+if ne rl 9
+ret 0
+end
+if ne l 99
+ret 0
+end
+if ne mg_fid pa 107 1
+ret 0
+end
+if ne mg_fid pb 108 1
+ret 0
+end
+if eq mg_hideq add o 67 107 0
+ret 0
+end
+if eq mg_hideq add o 67 108 0
+ret 0
+end
+ret 1
+end
+if eq k 2
+if ne rl 9
+ret 0
+end
+if ne l 75
+ret 0
+end
+if gt w 32
+ret 0
+end
+if ne mg_h64 add o 67 shl ulong 1 w
+ret 0
+end
+if ne mg_exeq pa pb w 0
+ret 0
+end
+ret 1
+end
+if eq k 3
+if ne rl 2
+ret 0
+end
+if ne l 91
+ret 0
+end
+x = mg_h64 add o 67
+ya = mg_h64 add o 75
+if ne mg_eval pa x ya
+ret 0
+end
+if ne mg_eval pb x mg_h64 add o 83
+ret 0
+end
+if eq ya mg_h64 add o 83
+ret 0
+end
+ret 1
+end
+ret 0
+end
+
+fn mg_vedges to ulong
+bad = ulong 0
+for e ulong get mgs 5
+s = get mged mul e 4
+rl = get mged add mul e 4 1
+d = get mged add mul e 4 2
+ri = get mged add mul e 4 3
+if eq rl 4
+if ne mg_nk s 1
+bad = add bad 1
+continue
+end
+if ne mg_nk d 2
+bad = add bad 1
+continue
+end
+if eq mg_hideq mg_no s mg_ns d 0
+bad = add bad 1
+end
+continue
+end
+if eq rl 7
+if ne mg_nk s 3
+bad = add bad 1
+continue
+end
+if ne mg_nk d 2
+bad = add bad 1
+continue
+end
+p = get mgvp d
+if eq p MGNONE
+bad = add bad 1
+continue
+end
+c = mg_fid p 107
+if ne mg_idcmp 107 mg_ns s 0
+bad = add bad 1
+end
+continue
+end
+if ne mg_nk s 2
+bad = add bad 1
+continue
+end
+if ne mg_nk d 2
+bad = add bad 1
+continue
+end
+if eq mg_vrec s rl d ri 0
+bad = add bad 1
+end
+end
+ret bad
+end
+
+note number of failures over every node id, receipt id and edge receipt (0 = the graph checks)
+fn mg_verify to ulong
+a = mg_vnodes
+b = mg_vrecs
+c = mg_vedges
+ret add add a b c
+end
+
+note ---- canonical storage (spec/program-identity.md 10.3) ----
+
+fn mg_o8 v ulong to void
+c = get mgs 8
+put mgo c uchar and v 255
+put mgs 8 add c 1
+end
+
+fn mg_o32 v ulong to void
+mg_o8 shr v 24
+mg_o8 shr v 16
+mg_o8 shr v 8
+mg_o8 v
+end
+
+fn mg_oid s ulong to void
+for i ulong 32
+mg_o8 ulong get mgi add mul s 32 i
+end
+end
+
+fn mg_oh o ulong n ulong to void
+for i ulong n
+mg_o8 ulong get mgh add o i
+end
+end
+
+note edge order: src id, rel, dst id, receipt id (none = 32 zero bytes, slot 109)
+fn mg_ers e ulong to ulong
+r = get mged add mul e 4 3
+if eq r 0
+mg_idz 109
+ret 109
+end
+ret add 8192 sub r 1
+end
+
+fn mg_ecmp a ulong b ulong to ulong
+c = mg_idcmp mg_ns get mged mul a 4 mg_ns get mged mul b 4
+if ne c 0
+ret c
+end
+ra = get mged add mul a 4 1
+rb = get mged add mul b 4 1
+if lt ra rb
+ret 1
+end
+if gt ra rb
+ret 2
+end
+c = mg_idcmp mg_ns get mged add mul a 4 2 mg_ns get mged add mul b 4 2
+if ne c 0
+ret c
+end
+sa = mg_ers a
+mg_idcp sa 108
+ret mg_idcmp 108 mg_ers b
+end
+
+note insertion sorts of index lists: 1 nodes (mgsn), 2 receipts (mgsr), 3 edges (mgse)
+fn mg_gt k ulong a ulong b ulong to ulong
+c = ulong 0
+if eq k 1
+c = mg_idcmp mg_ns a mg_ns b
+else
+if eq k 2
+c = mg_idcmp add 8192 a add 8192 b
+else
+c = mg_ecmp a b
+end
+end
+if eq c 2
+ret 1
+end
+ret 0
+end
+
+fn mg_sget k ulong i ulong to ulong
+if eq k 1
+ret get mgsn i
+end
+if eq k 2
+ret get mgsr i
+end
+ret get mgse i
+end
+
+fn mg_sput k ulong i ulong v ulong to void
+if eq k 1
+put mgsn i v
+ret
+end
+if eq k 2
+put mgsr i v
+ret
+end
+put mgse i v
+end
+
+fn mg_sort k ulong n ulong to void
+for i ulong n
+mg_sput k i i
+end
+i = ulong 1
+while lt i n bound 999999
+cur = mg_sget k i
+j = i
+while gt j 0 bound 999999
+pv = mg_sget k sub j 1
+if eq mg_gt k pv cur 0
+break
+end
+mg_sput k j pv
+j = sub j 1
+end
+mg_sput k j cur
+i = add i 1
+end
+end
+
+note "omega.meaning.graph.v1" 0x00 || u32 N || N x (id, kind u8, u32 len, content)
+note || u32 R || R x (id, u32 len, content) || u32 E || E x (src id, rel u16, dst id, receipt id)
+fn mg_sern nn ulong to void
+mg_o32 nn
+for i ulong nn
+n = get mgsn i
+mg_oid mg_ns n
+mg_o8 mg_nk n
+mg_o32 mg_nl n
+mg_oh mg_no n mg_nl n
+end
+end
+
+fn mg_serr nr ulong to void
+mg_o32 nr
+for i ulong nr
+r = get mgsr i
+l = get mgrc add mul r 2 1
+mg_oid add 8192 r
+mg_o32 l
+mg_oh get mgrc mul r 2 l
+end
+end
+
+fn mg_sere ne0 ulong to void
+mg_o32 ne0
+for i ulong ne0
+e = get mgse i
+q = mul e 4
+rl = get mged add q 1
+mg_oid mg_ns get mged q
+mg_o8 shr rl 8
+mg_o8 rl
+mg_oid mg_ns get mged add q 2
+mg_oid mg_ers e
+end
+end
+
+fn mg_ser to ulong
+put mgs 8 0
+for i ulong len mgtgd
+mg_o8 ulong get mgtgd i
+end
+mg_o8 0
+mg_sort 1 get mgs 3
+mg_sort 2 get mgs 4
+mg_sort 3 get mgs 5
+mg_sern get mgs 3
+mg_serr get mgs 4
+mg_sere get mgs 5
+ret get mgs 8
+end
+
+note SHA-256 of mgo[0..n) -> slot s, streamed in 4096-byte runs
+fn mg_odig n ulong s ulong to void
+c = new ulong 40 0
+a = new uchar 4096 0
+o = new uchar 32 0
+sha256_init c
+q = ulong 0
+while lt q n bound 999999
+k = sub n q
+if gt k 4096
+k = 4096
+end
+for i ulong k
+put a i get mgo add q i
+end
+sha256_update c part a 0 k
+q = add q k
+end
+sha256_final c o
+for j ulong 32
+put mgi add mul s 32 j get o j
+end
+end
+
+fn mg_gdig s ulong to ulong
+n = mg_ser
+mg_odig n s
+ret n
+end
+
+note ---- reading the storage back ----
+
+fn mg_i8 to ulong
+c = get mgs 9
+if ge c get mgs 11
+put mgs 10 1
+ret 0
+end
+put mgs 9 add c 1
+ret ulong get mgo c
+end
+
+fn mg_i32 to ulong
+v = ulong 0
+for i ulong 4
+v = or shl v 8 mg_i8
+end
+ret v
+end
+
+fn mg_iid s ulong to void
+for i ulong 32
+put mgi add mul s 32 i uchar mg_i8
+end
+end
+
+fn mg_ih n ulong to ulong
+h = get mgs 6
+for i ulong n
+mg_hpush mg_i8
+end
+ret h
+end
+
+note replace the whole state by the graph in mgo[0..n). 0 ok; 1 truncated or trailing bytes; 2 bad
+note domain tag; 3 order not strictly increasing (non-canonical or duplicate); 4 malformed body;
+note 5 edge names an unknown node or receipt; 6 bad node kind. Run mg_verify afterwards.
+fn mg_load n ulong to ulong
+mg_reset
+put mgs 9 0
+put mgs 10 0
+put mgs 11 n
+for i ulong len mgtgd
+if ne mg_i8 ulong get mgtgd i
+ret 2
+end
+end
+if ne mg_i8 0
+ret 2
+end
+nn = mg_i32
+if gt nn MGNMAX
+ret 1
+end
+for i ulong nn
+mg_iid 104
+if gt i 0
+if ne mg_idcmp mg_ns sub i 1 104 1
+ret 3
+end
+end
+k = mg_i8
+l = mg_i32
+if gt l 65536
+ret 1
+end
+h = mg_ih l
+if ne get mgs 10 0
+ret 1
+end
+a = ulong 0
+if eq k 2
+a = mg_bparse h l
+if eq a MGNONE
+ret 4
+end
+end
+if eq k 3
+if lt l 19
+ret 4
+end
+a = mg_h8 add h 18
+end
+if eq k 0
+ret 6
+end
+if gt k 3
+ret 6
+end
+f = mg_nadd k 104 h l a
+end
+nr = mg_i32
+if gt nr MGRMAX
+ret 1
+end
+for i ulong nr
+mg_iid add 8192 i
+if gt i 0
+if ne mg_idcmp add 8191 i add 8192 i 1
+ret 3
+end
+end
+l = mg_i32
+if gt l 65536
+ret 1
+end
+h = mg_ih l
+put mgrc mul i 2 h
+put mgrc add mul i 2 1 l
+put mgs 4 add i 1
+end
+ne0 = mg_i32
+if gt ne0 MGEMAX
+ret 1
+end
+for i ulong ne0
+mg_iid 104
+rl = mg_i8
+rl = or shl rl 8 mg_i8
+mg_iid 105
+mg_iid 106
+if ne get mgs 10 0
+ret 1
+end
+s = mg_nfind 104
+d = mg_nfind 105
+if eq s MGNONE
+ret 5
+end
+if eq d MGNONE
+ret 5
+end
+r = ulong 0
+mg_idz 109
+if ne mg_idcmp 106 109 0
+r = mg_rfind 106
+if eq r MGNONE
+ret 5
+end
+r = add r 1
+end
+e = get mgs 5
+put mged mul e 4 s
+put mged add mul e 4 1 rl
+put mged add mul e 4 2 d
+put mged add mul e 4 3 r
+put mgs 5 add e 1
+if gt e 0
+if ne mg_ecmp sub e 1 e 1
+ret 3
+end
+end
+end
+if ne get mgs 10 0
+ret 1
+end
+if ne get mgs 9 n
+ret 1
+end
+for i ulong get mgs 3
+if eq mg_nk i 1
+if lt mg_nl i 32
+ret 4
+end
+mg_hid mg_no i 107
+b = mg_nfind 107
+if eq b MGNONE
+ret 5
+end
+put mgnd add mul i 4 3 b
+end
+end
+ret 0
+end
diff --git a/om/meaning/test/driver.om b/om/meaning/test/driver.om
new file mode 100644
index 000000000..ad32db63f
--- /dev/null
+++ b/om/meaning/test/driver.om
@@ -0,0 +1,971 @@
+note SPDX-License-Identifier: Apache-2.0
+note om/meaning/test/driver.om: reads om/meaning/test/vectors on stdin and checks om/meaning/meaning.om.
+note Linked after om/tls/sha2.om and om/meaning/meaning.om (run.sh). One record per line, # comments:
+note   D w tok... [; pre ; post]  define program #n (n = 0, 1, ...; tokens x, a number, add sub mul and
+note                              or) and add it to the graph; contract texts default to true / true
+note   C a b      FUNCTION_ID(a) = FUNCTION_ID(b)        N a b   FUNCTION_ID(a) differs from (b)
+note   F a k      FUNCTION_ID class of a is k (1 canonical, 2 intensional fallback)
+note   K a c...   canonical coefficients of a are exactly c_0..c_{K-1} (decimal or 0x hex)
+note   I a hex    program_id v2 of a equals the golden
+note   H a hex    FUNCTION_ID of a equals the golden (goldens: sha256sum of the spec 9.3 preimage, run.sh)
+note   W w k      K(w) = k
+note   V code w tok...  mg_pchk refuses the token list with that code (negative control)
+note   E a b r    exhaustive proof on the body nodes gives r (0 equal, 1 differ); recorded for G
+note   X a b r    witness search gives r (1 witness found, 0 none); recorded for G
+note   Q a c      the equivalence class of a's body node has c members
+note   P a c      a's body node has c provenance edges
+note   R w n s    randomized differential: n random programs at width w, seed s
+note   G          graph checks: verify, store/load/store byte identity, reverse-order rebuild digest,
+note              tamper detection. Rebuilds the graph, so it comes last.
+note Output: FAIL line L code C per failed check, then "meaning driver: N checks, F failed".
+note Exit 0 all pass, 1 a failure, 2 unreadable input.
+
+global inp uchar 1048576
+global st ulong 16
+global ob uchar 32
+global one uchar 1
+global mdw uchar 512
+global mdtk ulong 65536
+global mddf ulong 6144
+global mdtx uchar 65536
+global mdpn ulong 1024
+global mdpr ulong 1024
+global mdpf ulong 3072
+global mdsv uchar 4194304
+text tfail "FAIL line "
+text tcode " code "
+text tsum "meaning driver: "
+text tchk " checks, "
+text tfld " failed\n"
+text tnl "\n"
+text tsp " "
+text trnd "R w="
+text trn " programs="
+text trp " pairs="
+text tre " equal_id_pairs="
+text trc " canonical="
+text tgr "G nodes="
+text tge " edges="
+text tgc " receipts="
+text tgb " bytes="
+text tgt " tampered="
+text tio "meaning driver: cannot read input or input over 1 MiB\n"
+
+note st: 0 input length, 1 position, 2 line, 3 bad, 5 checks, 6 failed, 7 defs, 8 tokens used,
+note 9 text bytes used, 10 proofs recorded, 11 random state
+
+fn mdslurp to int
+t = ulong 0
+while true bound 999999
+room = sub len inp t
+if eq room 0
+r = read 0 one 0 1
+if ne r 0
+ret 2
+end
+break
+end
+r = read 0 inp t room
+if lt r 0
+ret 2
+end
+if eq r 0
+break
+end
+t = add t ulong r
+end
+put st 0 t
+ret 0
+end
+
+fn mdpeek to ulong
+c = get st 1
+if ge c get st 0
+ret 256
+end
+ret ulong get inp c
+end
+
+fn mdadv to void
+put st 1 add get st 1 1
+end
+
+fn mdprn v ulong to void
+x = v
+k = ulong 0
+while true bound 21
+put ob sub 31 k uchar add 48 rem x 10
+k = add k 1
+x = div x 10
+if eq x 0
+break
+end
+end
+r = write 1 ob sub 32 k k
+end
+
+fn mdout k ulong to void
+if eq k 0
+r = write 1 tsp 0 len tsp
+end
+if eq k 1
+r = write 1 tnl 0 len tnl
+end
+end
+
+fn mdchk ok bool code ulong to void
+put st 5 add get st 5 1
+if not ok
+put st 6 add get st 6 1
+r = write 1 tfail 0 len tfail
+mdprn get st 2
+r = write 1 tcode 0 len tcode
+mdprn code
+mdout 1
+end
+end
+
+note next word of the line into mdw; 0 at the end of the line (the newline is not consumed)
+fn mdword to ulong
+while true bound 999999
+c = mdpeek
+if ne c 32
+if ne c 9
+break
+end
+end
+mdadv
+end
+n = ulong 0
+while true bound 999999
+c = mdpeek
+if eq c 32
+break
+end
+if eq c 9
+break
+end
+if eq c 10
+break
+end
+if eq c 13
+break
+end
+if eq c 256
+break
+end
+if ge n len mdw
+put st 3 1
+ret n
+end
+put mdw n uchar c
+n = add n 1
+mdadv
+end
+ret n
+end
+
+fn mdeol to void
+while true bound 999999
+c = mdpeek
+if eq c 256
+ret
+end
+mdadv
+if eq c 10
+ret
+end
+end
+end
+
+fn mdhexv c ulong to ulong
+if ge c 48
+if le c 57
+ret sub c 48
+end
+end
+if ge c 97
+if le c 102
+ret sub c 87
+end
+end
+ret 16
+end
+
+note the number in mdw[0..n): decimal (at most 20 digits, below 2^64) or 0x hex (at most 16 digits)
+fn mdval n ulong to ulong
+if eq n 0
+put st 3 1
+ret 0
+end
+v = ulong 0
+if gt n 2
+if eq get mdw 1 120
+if gt n 18
+put st 3 1
+ret 0
+end
+for i ulong sub n 2
+d = mdhexv ulong get mdw add i 2
+if gt d 15
+put st 3 1
+ret 0
+end
+v = or shl v 4 d
+end
+ret v
+end
+end
+if gt n 20
+put st 3 1
+ret 0
+end
+for i ulong n
+d = ulong get mdw i
+if lt d 48
+put st 3 1
+ret 0
+end
+if gt d 57
+put st 3 1
+ret 0
+end
+nv = add mul v 10 sub d 48
+if lt nv v
+put st 3 1
+ret 0
+end
+if gt v 1844674407370955161
+put st 3 1
+ret 0
+end
+v = nv
+end
+ret v
+end
+
+fn mdnum to ulong
+ret mdval mdword
+end
+
+note token word in mdw[0..n) -> code (1 x, 2 constant with value in st 12, 3 add 4 sub 5 mul 9 and
+note 10 or), 0 = the ';' separator, 99 = unknown
+fn mdtokc n ulong to ulong
+c = ulong get mdw 0
+if eq n 1
+if eq c 120
+ret 1
+end
+if eq c 59
+ret 0
+end
+end
+if ge c 48
+if le c 57
+put st 12 mdval n
+ret 2
+end
+end
+if eq n 3
+d = ulong get mdw 1
+if eq c 97
+if eq d 100
+ret 3
+end
+if eq d 110
+ret 9
+end
+end
+if eq c 115
+ret 4
+end
+if eq c 109
+ret 5
+end
+end
+if eq n 2
+if eq c 111
+ret 10
+end
+end
+put st 3 1
+ret 99
+end
+
+note read tokens until ';' or the end of the line into mdtk; returns the count. Sets st 13 = 1 when a
+note ';' was read.
+fn mdtoks to ulong
+put st 13 0
+k = ulong 0
+b = get st 8
+while true bound 99999
+n = mdword
+if eq n 0
+break
+end
+c = mdtokc n
+if eq c 0
+put st 13 1
+break
+end
+v = ulong 0
+if eq c 2
+v = get st 12
+end
+if ge add b k 32768
+put st 3 1
+ret k
+end
+put mdtk mul add b k 2 c
+put mdtk add mul add b k 2 1 v
+k = add k 1
+end
+ret k
+end
+
+note the rest of the line, "pre ; post", into mdtx; st 14 pre length, st 15 post length
+fn mdtexts to void
+t = get st 9
+s = t
+while true bound 999999
+c = mdpeek
+if eq c 32
+mdadv
+continue
+end
+break
+end
+while true bound 999999
+c = mdpeek
+if eq c 10
+break
+end
+if eq c 13
+break
+end
+if eq c 256
+break
+end
+if ge t len mdtx
+put st 3 1
+ret
+end
+put mdtx t uchar c
+t = add t 1
+mdadv
+end
+note split at the first " ; "
+cut = MGNONE
+for i ulong sub t s
+j = add s i
+if eq cut MGNONE
+if lt add j 2 t
+if eq get mdtx j 32
+if eq get mdtx add j 1 59
+if eq get mdtx add j 2 32
+cut = j
+end
+end
+end
+end
+end
+end
+if eq cut MGNONE
+put st 3 1
+ret
+end
+put st 14 sub cut s
+put st 15 sub t add cut 3
+note move the post text down over the separator
+for i ulong get st 15
+put mdtx add cut i get mdtx add add cut 3 i
+end
+put st 9 add cut get st 15
+end
+
+fn mdlit to void
+h = get st 9
+put mdtx h 116
+put mdtx add h 1 114
+put mdtx add h 2 117
+put mdtx add h 3 101
+put st 9 add h 4
+end
+
+note build the program of definition d into the pool
+fn mdmkp d ulong to ulong
+b = get mddf mul d 6
+n = get mddf add mul d 6 1
+p = mg_pnew get mddf add mul d 6 2
+for i ulong n
+t = mul add b i 2
+mg_ptok p get mdtk t get mdtk add t 1
+end
+ret p
+end
+
+note build definition d into the pool and the graph; returns the program
+fn mdmk d ulong to ulong
+p = mdmkp d
+q = mul d 6
+tb = get mddf add q 3
+pl = get mddf add q 4
+ql = get mddf add q 5
+po = mg_hpos
+for i ulong add pl ql
+mg_hpush ulong get mdtx add tb i
+end
+put mdpn d mg_addprog p po pl add po pl ql
+put mdpr d p
+ret p
+end
+
+fn mdrecd to void
+d = get st 7
+if ge d 1024
+put st 3 1
+ret
+end
+w = mdnum
+b = get st 8
+n = mdtoks
+put st 8 add b n
+put mddf mul d 6 b
+put mddf add mul d 6 1 n
+put mddf add mul d 6 2 w
+put mddf add mul d 6 3 get st 9
+if eq get st 13 1
+mdtexts
+else
+mdlit
+mdlit
+put st 14 4
+put st 15 4
+end
+put mddf add mul d 6 4 get st 14
+put mddf add mul d 6 5 get st 15
+if ne get st 3 0
+ret
+end
+put st 7 add d 1
+p = mdmk d
+mdchk eq mg_pchk p 0 1
+end
+
+fn mdprog a ulong to ulong
+if ge a get st 7
+put st 3 1
+ret 0
+end
+ret get mdpr a
+end
+
+fn mdbody a ulong to ulong
+ret mg_na get mdpn a
+end
+
+note 1 when FUNCTION_ID(a) = FUNCTION_ID(b)
+fn mdfeq a ulong b ulong to ulong
+k = mg_fid mdprog a 16000
+k = mg_fid mdprog b 16001
+if eq mg_idcmp 16000 16001 0
+ret 1
+end
+ret 0
+end
+
+fn mdreck to void
+a = mdnum
+p = mdprog a
+if ne get st 3 0
+ret
+end
+if eq mg_frag p 0
+mdchk false 2
+ret
+end
+kk = mg_canon p
+for i ulong kk
+c = mdnum
+if ne c get mgc i
+mdchk false 3
+ret
+end
+end
+if ne mdword 0
+mdchk false 4
+ret
+end
+mdchk true 0
+end
+
+fn mdrecv to void
+x = mdnum
+w = mdnum
+b = get st 8
+n = mdtoks
+p = mg_pnew w
+for i ulong n
+t = mul add b i 2
+mg_ptok p get mdtk t get mdtk add t 1
+end
+mdchk eq mg_pchk p x 5
+end
+
+note compare the 32 bytes of mgi slot s with the next word (64 hex digits); failure code c
+fn mdhexs s ulong c ulong to void
+n = mdword
+if ne n 64
+put st 3 1
+ret
+end
+b = mul s 32
+for i ulong 32
+hi = mdhexv ulong get mdw mul i 2
+lo = mdhexv ulong get mdw add mul i 2 1
+if gt or hi lo 15
+put st 3 1
+ret
+end
+if ne ulong get mgi add b i or shl hi 4 lo
+mdchk false c
+ret
+end
+end
+mdchk true 0
+end
+
+fn mdreci to void
+mdhexs mg_ns get mdpn mdnum 6
+end
+
+fn mdrech to void
+k = mg_fid mdprog mdnum 16000
+mdhexs 16000 27
+end
+
+fn mdproof k ulong a ulong b ulong to ulong
+if eq k 0
+ret mg_exh mdbody a mdbody b
+end
+ret mg_wit mdbody a mdbody b
+end
+
+fn mdrecp k ulong to void
+a = mdnum
+b = mdnum
+r = mdnum
+if ne get st 3 0
+ret
+end
+q = get st 10
+if ge q 1024
+put st 3 1
+ret
+end
+put mdpf mul q 3 k
+put mdpf add mul q 3 1 a
+put mdpf add mul q 3 2 b
+put st 10 add q 1
+mdchk eq mdproof k a b r 7
+end
+
+note ---- randomized differential ----
+
+fn mdrnd to ulong
+x = get st 11
+x = xor x shl x 13
+x = xor x shr x 7
+x = xor x shl x 17
+put st 11 x
+ret x
+end
+
+fn mdleaf p ulong w ulong to void
+m = mg_mask w
+r = rem mdrnd 16
+if lt r 8
+mg_ptok p 1 0
+ret
+end
+v = ulong 0
+if eq r 8
+v = 1
+end
+if eq r 9
+v = 2
+end
+if eq r 10
+v = 3
+end
+if eq r 11
+v = m
+end
+if eq r 12
+v = shl ulong 1 sub w 1
+end
+if eq r 13
+v = and sub m 1 m
+end
+if eq r 14
+v = and mdrnd m
+end
+mg_ptok p 2 and v m
+end
+
+fn mdgen w ulong to ulong
+p = mg_pnew w
+nl = add 1 rem mdrnd 6
+l = ulong 0
+d = ulong 0
+while true bound 999
+if ge l nl
+if le d 1
+break
+end
+end
+op = ulong 0
+if ge d 2
+if ge l nl
+op = 1
+else
+op = rem mdrnd 2
+end
+end
+if eq op 0
+mdleaf p w
+l = add l 1
+d = add d 1
+continue
+end
+r = rem mdrnd 16
+o = ulong 3
+if ge r 5
+o = 4
+end
+if ge r 9
+o = 5
+end
+if eq r 14
+o = 9
+end
+if eq r 15
+o = 10
+end
+mg_ptok p o 0
+d = sub d 1
+end
+ret p
+end
+
+note value signature of p: SHA-256 of f at every input (w <= 16) or at the 4096 mg_cand inputs
+note (they include 0..127, which determine every polynomial function for w <= 64)
+fn mdsx p ulong i ulong to ulong
+w = mg_pw p
+if gt w 16
+ret mg_eval p mg_cand i w
+end
+ret mg_eval p i
+end
+
+fn mdp8 a edit uchar * k ulong v ulong to void
+for j ulong 8
+put a add k j uchar and shr v mul sub 7 j 8 255
+end
+end
+
+fn mdsig p ulong s ulong to void
+c = new ulong 40 0
+a = new uchar 4096 0
+o = new uchar 32 0
+sha256_init c
+n = ulong 4096
+if le mg_pw p 16
+n = shl ulong 1 mg_pw p
+end
+k = ulong 0
+for i ulong n
+mdp8 a k mdsx p i
+k = add k 8
+if eq k 4096
+sha256_update c part a 0 k
+k = 0
+end
+end
+if gt k 0
+sha256_update c part a 0 k
+end
+sha256_final c o
+for j ulong 32
+put mgi add mul s 32 j get o j
+end
+end
+
+note reconstruction: sum a_k x(x-1)...(x-k+1) mod 2^w equals f at the 4096 mg_cand inputs
+fn mdrecon p ulong to ulong
+w = mg_pw p
+m = mg_mask w
+kk = mg_canon p
+for i ulong 4096
+x = mg_cand i w
+s = ulong 0
+t = ulong 1
+for k ulong kk
+s = add s mul get mgc k t
+t = mul t sub x k
+end
+if ne and s m mg_eval p x
+ret 0
+end
+end
+ret 1
+end
+
+fn mdrecr to void
+w = mdnum
+n = mdnum
+put st 11 or mdnum 1
+if ne get st 3 0
+ret
+end
+if gt n 2048
+put st 3 1
+ret
+end
+canon = ulong 0
+for i ulong n
+p = mdgen w
+mdchk eq mg_pchk p 0 8
+put mdpf add 1024 i p
+cl = mg_fid p add 16384 i
+if eq cl 1
+canon = add canon 1
+mdchk eq mdrecon p 1 9
+end
+mdsig p add 20480 i
+end
+pairs = ulong 0
+eqid = ulong 0
+for i ulong n
+for j ulong i
+pairs = add pairs 1
+fe = ulong 0
+if eq mg_idcmp add 16384 i add 16384 j 0
+fe = 1
+eqid = add eqid 1
+end
+se = ulong 0
+if eq mg_idcmp add 20480 i add 20480 j 0
+se = 1
+end
+pi = get mdpf add 1024 i
+pj = get mdpf add 1024 j
+both = and mg_frag pi mg_frag pj
+if eq both 1
+mdchk eq fe se 10
+else
+if eq fe 1
+mdchk eq se 1 11
+end
+end
+end
+end
+r = write 1 trnd 0 len trnd
+mdprn w
+r = write 1 trn 0 len trn
+mdprn n
+r = write 1 trp 0 len trp
+mdprn pairs
+r = write 1 tre 0 len tre
+mdprn eqid
+r = write 1 trc 0 len trc
+mdprn canon
+mdout 1
+end
+
+note ---- graph checks ----
+
+fn mdbuild rev ulong to void
+mg_reset
+nd = get st 7
+for i ulong nd
+d = i
+if eq rev 1
+d = sub sub nd 1 i
+end
+p = mdmk d
+end
+nq = get st 10
+for i ulong nq
+q = i
+if eq rev 1
+q = sub sub nq 1 i
+end
+q = mul q 3
+k = get mdpf q
+a = get mdpf add q 1
+r = mdproof k a get mdpf add q 2
+end
+end
+
+fn mdrecg to void
+mdchk eq mg_verify 0 12
+nn = get mgs 3
+ne0 = get mgs 5
+nr = get mgs 4
+n1 = mg_gdig 30000
+for i ulong n1
+put mdsv i get mgo i
+end
+mdchk eq mg_load n1 0 13
+mdchk eq mg_verify 0 14
+n2 = mg_gdig 30001
+mdchk eq n2 n1 15
+mdchk eq mg_idcmp 30000 30001 0 16
+mdbuild 1
+mdchk eq mg_verify 0 17
+n3 = mg_gdig 30002
+mdchk eq n3 n1 18
+mdchk eq mg_idcmp 30000 30002 0 19
+note tamper: flip one bit at every 37th byte and at the last; load or verify must refuse each
+tam = ulong 0
+pos = ulong 0
+while lt pos n1 bound 999999
+for i ulong n1
+put mgo i get mdsv i
+end
+put mgo pos xor get mgo pos 1
+rc = mg_load n1
+bad = ulong 0
+if ne rc 0
+bad = 1
+else
+if ne mg_verify 0
+bad = 1
+end
+end
+mdchk eq bad 1 20
+tam = add tam 1
+if eq pos sub n1 1
+break
+end
+pos = add pos 37
+if ge pos n1
+pos = sub n1 1
+end
+end
+r = write 1 tgr 0 len tgr
+mdprn nn
+r = write 1 tge 0 len tge
+mdprn ne0
+r = write 1 tgc 0 len tgc
+mdprn nr
+r = write 1 tgb 0 len tgb
+mdprn n1
+r = write 1 tgt 0 len tgt
+mdprn tam
+mdout 1
+end
+
+fn mdrec to void
+n = mdword
+if eq n 0
+ret
+end
+c = ulong get mdw 0
+if eq c 35
+ret
+end
+if eq c 68
+mdrecd
+ret
+end
+if eq c 67
+mdchk eq mdfeq mdnum mdnum 1 21
+ret
+end
+if eq c 78
+mdchk eq mdfeq mdnum mdnum 0 22
+ret
+end
+if eq c 70
+a = mdnum
+k = mg_fid mdprog a 16000
+mdchk eq k mdnum 23
+ret
+end
+if eq c 75
+mdreck
+ret
+end
+if eq c 73
+mdreci
+ret
+end
+if eq c 72
+mdrech
+ret
+end
+if eq c 87
+w = mdnum
+mdchk eq mg_kof w mdnum 24
+ret
+end
+if eq c 86
+mdrecv
+ret
+end
+if eq c 69
+mdrecp 0
+ret
+end
+if eq c 88
+mdrecp 1
+ret
+end
+if eq c 81
+a = mdnum
+mdchk eq mg_class mdbody a mdnum 25
+ret
+end
+if eq c 80
+a = mdnum
+mdchk eq mg_prov mdbody a mdnum 26
+ret
+end
+if eq c 82
+mdrecr
+ret
+end
+if eq c 71
+mdrecg
+ret
+end
+put st 3 1
+end
+
+fn main to int
+mg_reset
+if ne mdslurp 0
+r = write 1 tio 0 len tio
+ret 2
+end
+while lt get st 1 get st 0 bound 999999
+put st 2 add get st 2 1
+put st 3 0
+mdrec
+if ne get st 3 0
+mdchk false 99
+end
+mdeol
+end
+r = write 1 tsum 0 len tsum
+mdprn get st 5
+r = write 1 tchk 0 len tchk
+mdprn get st 6
+r = write 1 tfld 0 len tfld
+if ne get st 6 0
+ret 1
+end
+ret 0
+end
diff --git a/om/meaning/test/run.sh b/om/meaning/test/run.sh
new file mode 100755
index 000000000..eb547a471
--- /dev/null
+++ b/om/meaning/test/run.sh
@@ -0,0 +1,165 @@
+#!/bin/sh
+# SPDX-License-Identifier: Apache-2.0
+# Test suite for om/meaning/meaning.om (FUNCTION_ID and the graph of meaning). Usage (from the
+# omega-mv root):
+#   sh om/meaning/test/run.sh seed/out/omc
+# Builds into build/meaning/. Exits 0 only when every vector passes, the FUNCTION_ID goldens match an
+# independent sha256sum of the spec section 9.3 preimage, and every mutant and negative control is
+# detected. Final line: MEANING PASS checks=N mutants=M/M, or MEANING FAIL.
+set -eu
+omc=${1:?usage: run.sh OMC}
+here=$(cd "$(dirname "$0")" && pwd)
+lib=$(cd "$here/.." && pwd)
+root=$(cd "$lib/../.." && pwd)
+out="$root/build/meaning"
+vec="$here/vectors"
+sha2="$root/om/tls/sha2.om"
+mkdir -p "$out"
+nice="nice -n 19 ionice -c3"
+checks=0
+mut=0
+mutok=0
+bad=0
+
+say() { printf '%s\n' "$*"; }
+fail() { say "FAIL $*"; bad=1; }
+
+# build LIB BIN: om2 line, sha2.om, LIB, the driver; compile with omc
+build() {
+	{ printf 'om2\n'; cat "$sha2" "$1" "$here/driver.om"; } > "$2.om"
+	if ! $nice "$omc" < "$2.om" > "$2" 2> "$2.err" || [ -s "$2.err" ]; then
+		say "omc refused $2.om: $(cat "$2.err")"
+		return 1
+	fi
+	chmod +x "$2"
+}
+
+# summary LINE -> "N F" when LINE is a complete driver summary
+summary() {
+	printf '%s\n' "$1" | awk '$1 == "meaning" && $2 == "driver:" && $4 == "checks," && $6 == "failed" { print $3, $5 }'
+}
+
+# detected NAME FILE BIN: BIN reported a difference (exit 1 with F > 0 failures) or refused the
+# input with a trap (exit 100..199); a signal (128+N within that range is not produced by omc
+# binaries, which trap through exit) or exit 0 is not detection
+detected() {
+	set +e
+	$nice "$3" < "$2" > "$out/$1.out" 2>&1
+	rc=$?
+	set -e
+	last=$(tail -n 1 "$out/$1.out")
+	s=$(summary "$last")
+	f=${s#* }
+	if [ "$rc" -eq 1 ] && [ -n "$s" ] && [ "$f" -gt 0 ]; then
+		say "PASS $1: detected ($(grep -c '^FAIL' "$out/$1.out") FAIL lines, first: $(grep -m 1 '^FAIL' "$out/$1.out"))"
+		return 0
+	fi
+	if [ "$rc" -ge 100 ] && [ "$rc" -le 127 ]; then
+		say "PASS $1: detected (trap, exit $rc)"
+		return 0
+	fi
+	fail "$1: not detected: exit $rc: $last"
+	return 1
+}
+
+# mutant NAME SED_EXPR: apply SED_EXPR to meaning.om, rebuild, require detection on the vectors
+mutant() {
+	mut=$((mut + 1))
+	sed "$2" "$lib/meaning.om" > "$out/mut-$1.om.lib"
+	if cmp -s "$lib/meaning.om" "$out/mut-$1.om.lib"; then
+		fail "$1: sed changed nothing"
+		return
+	fi
+	build "$out/mut-$1.om.lib" "$out/mut-$1" || { fail "$1: mutant did not compile"; return; }
+	if detected "mutant-$1" "$vec" "$out/mut-$1"; then
+		mutok=$((mutok + 1))
+	fi
+}
+
+# fid W K C... -> SHA-256 of "omega.function.v1" 0x00 || 01 || W u16 || K u16 || C u64 BE each
+fid() {
+	w=$1
+	k=$2
+	shift 2
+	{
+		printf 'omega.function.v1\000\001'
+		printf '%04x%04x' "$w" "$k" | xxd -r -p
+		for c in "$@"; do printf '%016x' "$c" | xxd -r -p; done
+	} | sha256sum | cut -d' ' -f1
+}
+zeros() { i=0; while [ "$i" -lt "$1" ]; do printf ' 0'; i=$((i + 1)); done; }
+
+build "$lib/meaning.om" "$out/driver" || { say "MEANING FAIL build"; exit 1; }
+say "omc        sha256 $(sha256sum "$omc" | cut -d' ' -f1)"
+say "sha2.om    sha256 $(sha256sum "$sha2" | cut -d' ' -f1)"
+say "meaning.om sha256 $(sha256sum "$lib/meaning.om" | cut -d' ' -f1)"
+say "driver.om  sha256 $(sha256sum "$here/driver.om" | cut -d' ' -f1)"
+say "vectors    sha256 $(sha256sum "$vec" | cut -d' ' -f1)"
+
+# FUNCTION_ID goldens in the vectors must equal the independently built preimage hashes
+# (x + 2 at w 64: a = 2 1 0...; zero at w 64: 66 zeros; 3x^3 + 5x + 7 at w 8: a = 7 8 9 3 0 0 0 0 0 0,
+# the coefficient vector computed by Wolfram, spec section 9.2)
+g1=$(fid 64 66 2 1 $(zeros 64))
+g2=$(fid 64 66 $(zeros 66))
+g3=$(fid 8 10 7 8 9 3 0 0 0 0 0 0)
+for want in "H 0 $g1" "H 2 $g1" "H 8 $g2" "H 9 $g2" "H 19 $g3"; do
+	if grep -qx "$want" "$vec"; then
+		say "PASS golden: $want"
+	else
+		fail "golden: vectors lack \"$want\""
+	fi
+done
+
+# the vectors
+set +e
+$nice "$out/driver" < "$vec" > "$out/vectors.out" 2>&1
+rc=$?
+set -e
+last=$(tail -n 1 "$out/vectors.out")
+s=$(summary "$last")
+if [ "$rc" -eq 0 ] && [ -n "$s" ] && [ "${s#* }" = 0 ] && [ "${s% *}" -gt 0 ]; then
+	checks=${s% *}
+	grep '^[RG] ' "$out/vectors.out" | while IFS= read -r l; do say "  $l"; done
+	say "PASS vectors: $last"
+else
+	fail "vectors: exit $rc: $(tail -n 5 "$out/vectors.out" | tr '\n' ' ')"
+fi
+
+# source mutants: each must be detected by the vectors
+# K one too small: x(x-1)...(x-8) and 0 at w 8 collapse, the iff check sees equal ids for different functions
+mutant kof-minus-1 's/^kk = mg_kof w$/kk = sub mg_kof w 1/'
+# Newton inverse with 4 steps (48 bits): wrong coefficients at w 64, reconstruction fails
+mutant inverse-4-steps 's/^for i ulong 5$/for i ulong 4/'
+# Newton inverse started from 1 instead of u (1 correct bit, 32 after 5 steps)
+mutant inverse-start-1 's/^y = u$/y = ulong 1/'
+# and with the all-ones constant no longer recognised: x and 255 at w 8 falls back, C 15 16 fails
+mutant and-ones-dropped '/^if eq o 9$/,/^end$/s/^if eq c m$/if lt c 0/'
+# and with 1 accepted as the identity: x and 1 treated as x, the iff check or the canon trap fires
+mutant and-one-accepted '/^if eq o 9$/,/^end$/s/^if eq c m$/if eq c 1/'
+# ApplyPayload size 161 -> 160: program_id goldens fail
+mutant apply-payload-160 's/^mg_b32 161$/mg_b32 160/'
+# storage sort comparator always "not greater": reverse rebuild bytes differ or load refuses order
+mutant sort-cmp-never '/^fn mg_gt /,/^fn mg_sget /s/^ret 1$/ret 0/'
+# FUNCTION_ID domain tag changed: the independent goldens fail
+mutant fid-domain 's/^text mgtfd "omega.function.v1"$/text mgtfd "omega.function.v2"/'
+
+# expectation mutants: a must-not-collapse pair asserted equal, a must-collapse pair asserted
+# different, each must fail exactly the changed record
+mut=$((mut + 1))
+sed 's/^N 1 3$/C 1 3/' "$vec" > "$out/mut-expect-c.txt"
+if cmp -s "$vec" "$out/mut-expect-c.txt"; then fail "expect-c changed nothing"
+elif detected mutant-expect-c "$out/mut-expect-c.txt" "$out/driver"; then mutok=$((mutok + 1)); fi
+mut=$((mut + 1))
+sed 's/^C 0 1$/N 0 1/' "$vec" > "$out/mut-expect-n.txt"
+if cmp -s "$vec" "$out/mut-expect-n.txt"; then fail "expect-n changed nothing"
+elif detected mutant-expect-n "$out/mut-expect-n.txt" "$out/driver"; then mutok=$((mutok + 1)); fi
+
+# negative control: a refused program defined with D is reported (pchk code 4: constant 256 at w 8)
+printf 'D 8 x 256 add\n' > "$out/neg-define.txt"
+detected neg-define "$out/neg-define.txt" "$out/driver" || true
+
+if [ "$bad" -ne 0 ]; then
+	say "MEANING FAIL checks=$checks mutants=$mutok/$mut"
+	exit 1
+fi
+say "MEANING PASS checks=$checks mutants=$mutok/$mut"
diff --git a/om/meaning/test/vectors b/om/meaning/test/vectors
new file mode 100644
index 000000000..f9d846ff9
--- /dev/null
+++ b/om/meaning/test/vectors
@@ -0,0 +1,230 @@
+# om/meaning/test/vectors: input of om/meaning/test/driver.om (record formats in the driver header).
+# Expected values: K table, coefficient lines (K) and the counting argument come from Wolfram Language
+# evaluations quoted in spec/program-identity.md section 9; program_id goldens (I) are the C goldens of
+# tests/language/golden/v0.txt lines 24 and 27. Programs are numbered in order of their D lines.
+#
+# 0..3 x+1+1, x+2, 2+x, x+3 (w 64)
+D 64 x 1 add 1 add
+D 64 x 2 add
+D 64 2 x add
+D 64 x 3 add
+# 4..7 x(x+1), x*x+x, x(x+1) + 2^63 x(x-1) (2^63 x(x-1) is a null polynomial mod 2^64), x^2
+D 64 x x 1 add mul
+D 64 x x mul x add
+D 64 x x 1 add mul 0x8000000000000000 x mul x 1 sub mul add
+D 64 x x mul
+# 8 x(x-1)...(x-65) (66 factors: divisible by 66!, v2(66!) = 64), 9 the constant 0,
+# 10 x(x-1)...(x-64) (65 factors: v2(65!) = 63, nonzero at x = 65)
+D 64 x x 1 sub mul x 2 sub mul x 3 sub mul x 4 sub mul x 5 sub mul x 6 sub mul x 7 sub mul x 8 sub mul x 9 sub mul x 10 sub mul x 11 sub mul x 12 sub mul x 13 sub mul x 14 sub mul x 15 sub mul x 16 sub mul x 17 sub mul x 18 sub mul x 19 sub mul x 20 sub mul x 21 sub mul x 22 sub mul x 23 sub mul x 24 sub mul x 25 sub mul x 26 sub mul x 27 sub mul x 28 sub mul x 29 sub mul x 30 sub mul x 31 sub mul x 32 sub mul x 33 sub mul x 34 sub mul x 35 sub mul x 36 sub mul x 37 sub mul x 38 sub mul x 39 sub mul x 40 sub mul x 41 sub mul x 42 sub mul x 43 sub mul x 44 sub mul x 45 sub mul x 46 sub mul x 47 sub mul x 48 sub mul x 49 sub mul x 50 sub mul x 51 sub mul x 52 sub mul x 53 sub mul x 54 sub mul x 55 sub mul x 56 sub mul x 57 sub mul x 58 sub mul x 59 sub mul x 60 sub mul x 61 sub mul x 62 sub mul x 63 sub mul x 64 sub mul x 65 sub mul
+D 64 0
+D 64 x x 1 sub mul x 2 sub mul x 3 sub mul x 4 sub mul x 5 sub mul x 6 sub mul x 7 sub mul x 8 sub mul x 9 sub mul x 10 sub mul x 11 sub mul x 12 sub mul x 13 sub mul x 14 sub mul x 15 sub mul x 16 sub mul x 17 sub mul x 18 sub mul x 19 sub mul x 20 sub mul x 21 sub mul x 22 sub mul x 23 sub mul x 24 sub mul x 25 sub mul x 26 sub mul x 27 sub mul x 28 sub mul x 29 sub mul x 30 sub mul x 31 sub mul x 32 sub mul x 33 sub mul x 34 sub mul x 35 sub mul x 36 sub mul x 37 sub mul x 38 sub mul x 39 sub mul x 40 sub mul x 41 sub mul x 42 sub mul x 43 sub mul x 44 sub mul x 45 sub mul x 46 sub mul x 47 sub mul x 48 sub mul x 49 sub mul x 50 sub mul x 51 sub mul x 52 sub mul x 53 sub mul x 54 sub mul x 55 sub mul x 56 sub mul x 57 sub mul x 58 sub mul x 59 sub mul x 60 sub mul x 61 sub mul x 62 sub mul x 63 sub mul x 64 sub mul
+# 11 fn mask(x: u64) -> u64 { x & 0xff }; 12 fn transform requires true ensures result >= 1 { x * 2 + 1 }
+D 64 x 255 and
+D 64 x 2 mul 1 add ; true ; result >= 1
+# 13 the same body without the contract, 14 2(x+1) - 1
+D 64 x 2 mul 1 add
+D 64 x 1 add 2 mul 1 sub
+# 15..18 w 8: x and 255, x, x(x-1)...(x-8) (9 factors, v2(9!) = 7 < 8: zero on 0..8, 8! at 9... nonzero), 0
+D 8 x 255 and
+D 8 x
+D 8 x x 1 sub mul x 2 sub mul x 3 sub mul x 4 sub mul x 5 sub mul x 6 sub mul x 7 sub mul x 8 sub mul
+D 8 0
+# 19..21 coefficient vectors computed by Wolfram
+D 8 x x mul x mul 3 mul x 5 mul add 7 add
+D 16 x x mul x mul x mul x mul 7 mul x x mul 200 mul add 13 add
+D 8 x x mul 255 mul 254 add
+# 22..24 w 8: x+2, x+1+1, x+3 (exhaustive proofs)
+D 8 x 2 add
+D 8 x 1 add 1 add
+D 8 x 3 add
+# 25..28 w 64: x and (2^63-1) (outside the fragment), x and all-ones, x, x-1+1
+D 64 x 0x7fffffffffffffff and
+D 64 x 0xffffffffffffffff and
+D 64 x
+D 64 x 1 sub 1 add
+# 29, 30 w 16: x^2, x(x-1)+x
+D 16 x x mul
+D 16 x x 1 sub mul x add
+# 31..33 one-bit constant differences: x + 2^63 vs x; 2^62 x vs 3 2^62 x
+D 64 x 0x8000000000000000 add
+D 64 x 0x4000000000000000 mul
+D 64 x 0xc000000000000000 mul
+# 34..37 reassociation and commutation of add: (x+3)+5, x+(5+3), 3+(x+5), x+8
+D 64 x 3 add 5 add
+D 64 x 5 3 add add
+D 64 3 x 5 add add
+D 64 x 8 add
+# 38, 39 (x x) x vs x (x x); 40, 41 (x+3) 5 vs 5x + 15
+D 64 x x mul x mul
+D 64 x x x mul mul
+D 64 x 3 add 5 mul
+D 64 x 5 mul 15 add
+# 42, 43 w 64 or: x or 0 = x; and 0 = 0
+D 64 x 0 or
+D 64 x 0 and
+# 44 the outside program 25 with its operands swapped (another body: the fallback id differs),
+# 45, 46 x and 1 (not a polynomial function for w >= 2: outside the fragment)
+D 64 0x7fffffffffffffff x and
+D 64 x 1 and
+D 8 x 1 and
+#
+# must collapse
+C 0 1
+C 0 2
+C 1 2
+C 4 5
+C 4 6
+C 5 6
+C 8 9
+C 12 14
+C 15 16
+C 26 27
+C 27 28
+C 29 30
+C 34 35
+C 34 36
+C 34 37
+C 38 39
+C 40 41
+C 42 27
+C 43 9
+C 22 23
+# must not collapse (one-bit constant differences and near misses)
+N 1 3
+N 31 27
+N 32 33
+N 10 9
+N 17 18
+N 4 7
+N 25 27
+N 11 27
+N 22 24
+N 15 22
+N 16 27
+N 25 44
+N 45 27
+# the same body twice: same FUNCTION_ID (12 and 13 differ only in the contract)
+C 12 13
+# classes
+F 0 1
+F 8 1
+F 11 2
+F 25 2
+F 15 1
+F 26 1
+F 42 1
+F 43 1
+F 44 2
+F 45 2
+F 46 2
+# canonical coefficients (Wolfram)
+K 4 0 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+K 7 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+K 6 0 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+K 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+K 19 7 8 9 3 0 0 0 0 0 0
+K 20 13 207 305 175 70 7 0 0 0 0 0 0 0 0 0 0 0 0
+K 21 254 255 127 0 0 0 0 0 0 0
+# program_id v2 goldens (tests/language/golden/v0.txt)
+I 11 e180baf4807d890dc1ba22472e847da76e877ee04d59b0762f6dfc26b2af62ff
+I 12 83bd39597742d3bb83e5140c662532c0a2ecb59e5f868e38be16276981644543
+# FUNCTION_ID goldens: sha256sum of the section 9.3 preimage built byte by byte in run.sh
+H 0 11b8858ec5c305c0160d84eb2f30786c9429731bc6a88516d530ecefc819bef2
+H 2 11b8858ec5c305c0160d84eb2f30786c9429731bc6a88516d530ecefc819bef2
+H 8 96cb6ace92436b94aa6f49967d967b900f069c6c34b9cf73f7ce2d7d773cc1fa
+H 9 96cb6ace92436b94aa6f49967d967b900f069c6c34b9cf73f7ce2d7d773cc1fa
+H 19 89877bca66e566c52e7dbc92df7fc3bacb25542066df417a3641f504e1d216eb
+# K(w) for w = 1..64 (Wolfram: least k with IntegerExponent[k!, 2] >= w)
+W 1 2
+W 2 4
+W 3 4
+W 4 6
+W 5 8
+W 6 8
+W 7 8
+W 8 10
+W 9 12
+W 10 12
+W 11 14
+W 12 16
+W 13 16
+W 14 16
+W 15 16
+W 16 18
+W 17 20
+W 18 20
+W 19 22
+W 20 24
+W 21 24
+W 22 24
+W 23 26
+W 24 28
+W 25 28
+W 26 30
+W 27 32
+W 28 32
+W 29 32
+W 30 32
+W 31 32
+W 32 34
+W 33 36
+W 34 36
+W 35 38
+W 36 40
+W 37 40
+W 38 40
+W 39 42
+W 40 44
+W 41 44
+W 42 46
+W 43 48
+W 44 48
+W 45 48
+W 46 48
+W 47 50
+W 48 52
+W 49 52
+W 50 54
+W 51 56
+W 52 56
+W 53 56
+W 54 58
+W 55 60
+W 56 60
+W 57 62
+W 58 64
+W 59 64
+W 60 64
+W 61 64
+W 62 64
+W 63 64
+W 64 66
+# refused programs (negative controls): constant not below 2^w, missing operand, two results, widths
+V 4 8 x 256 add
+V 5 8 x add
+V 7 8 x x
+V 1 0 x
+V 1 65 x
+V 4 1 x 2 add
+# graph proofs: exhaustive equal (w 8 and 16), exhaustive differ, witness found, no witness
+E 22 23 0
+E 29 30 0
+E 22 24 1
+X 1 3 1
+X 25 27 1
+X 26 27 0
+X 4 7 1
+# queries: class of x+1+1 is {x+1+1, x+2, 2+x}; class of w 8 x+2 is {x+2, x+1+1}
+Q 0 3
+Q 22 2
+Q 9 3
+Q 11 1
+P 0 4
+P 3 3
+# randomized differential: FUNCTION_ID equal iff value signatures equal (both in the fragment)
+R 1 64 3
+R 3 300 5
+R 8 300 12345
+R 16 120 777
+R 64 300 99
+G
diff --git a/spec/.crumb b/spec/.crumb
index a226ce192..fe7008dca 100644
--- a/spec/.crumb
+++ b/spec/.crumb
@@ -20,14 +20,14 @@
         }
       ],
       "children_root": "sha256:6834a3241647d3a098283d4eafedbdb1428dfa4d834f9ed5f22025b6d2303093",
-      "compiled_at": "2026-10-30T11:28:28Z",
+      "compiled_at": "2026-10-30T16:31:35Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:f765ad87fdddd9b47f690b07298c951a0f7e7675dc5de4ffe44e33a0c14b1986",
+      "digest": "sha256:de6bbe151f93066995ce70103d3477870f39b1b6a0872a16270915f56a0b1f44",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 63,
-      "generated_at_commit": "a8a6a3d3c47ce797430f045edc5eae11594ba36d",
-      "source_tree": "sha256:4cb3bb1977c84caacc34366f814d6fe403a2eda7b89b916948d29541675c59bb"
+      "generated_at_commit": "9c563f6c364ccb0416cc029dcffacd8d9c7e3d84",
+      "source_tree": "sha256:be9f974d75eb09068cba46bbd3034697b4e54b0149fa343f2714196934f37d61"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/spec/program-identity.md b/spec/program-identity.md
index 30c6d6ba7..02827d441 100644
--- a/spec/program-identity.md
+++ b/spec/program-identity.md
@@ -213,9 +213,11 @@ The discovered abstraction (lifted, not composed) keeps `52b6059b...`.
 
 ## 8. Non-claims and deferred defects
 
-- Identity is **intensional**: it names the canonical body, not the mathematical function.
-  `x + 1 + 1` and `x + 2` compute the same function and have different ids. Proving
-  extensional equality is out of scope.
+- `SEMANTIC_ID` / `program_id` is **intensional**: it names the canonical body, not the
+  mathematical function. `x + 1 + 1` and `x + 2` compute the same function and have different
+  program ids, and that stays so. The extensional identity is a separate, versioned id,
+  `FUNCTION_ID` (section 9): canonical inside the polynomial fragment only. Equality of
+  arbitrary programs is undecidable, so no id is extensional for every program.
 - Contract clauses are identified by their canonical **text** (`omega_build_constraint_id`);
   two logically equivalent clauses with different text differ.
 - Historical receipts under `evidence/` carry v1 ids and are append-only; they are not
@@ -226,7 +228,150 @@ The discovered abstraction (lifted, not composed) keeps `52b6059b...`.
 - Payload bytes are the existing host-struct canonical payloads (spec/omega-language-v0.md),
   so ids are pinned to the LP64 / 4-byte-enum ABI, as before.
 
-## 9. Qualification
+## 9. FUNCTION_ID (`omega.function.v1`)
+
+```text
+Status:      IMPLEMENTED and EXERCISED on the host (om/meaning/meaning.om, om/meaning/test/run.sh);
+             not wired into the C library, Visor or any receipt; program ids are unchanged
+Domain tag:  "omega.function.v1"
+```
+
+`FUNCTION_ID` names the function a program computes, where that can be decided cheaply. It
+lives beside `omega.program.v2`; it never replaces a program id, never enters a program id
+preimage and never rewrites a receipt.
+
+### 9.1 Programs and the polynomial fragment
+
+A program is a width `w` (1..64) and a postfix list over `x`, constants below `2^w`, `add`,
+`sub`, `mul`, `and`, `or`, with arithmetic modulo `2^w`. The V0 body chain of section 2
+(`x c1 op1 c2 op2 ...`) is one such list. The **polynomial fragment** is decided by an abstract
+evaluation that gives each stack entry the class constant, polynomial or outside:
+
+- `add`, `sub`, `mul` of constants and polynomials are polynomials; `mul` by the constant 0 is the
+  constant 0 (even if the other side is outside).
+- `and`/`or` with a constant side use only exact identities modulo `2^w`: `and` all-ones = the
+  other side, `and 0` = 0, `or 0` = the other side, `or` all-ones = all-ones.
+- Everything else is outside. (So `x and 0xff` at w 64 is outside; `x and 0xff` at w 8 is `x`.)
+
+A program in the fragment computes a polynomial function `Z/2^w -> Z/2^w`.
+
+### 9.2 Canonical form
+
+Every polynomial function `f` modulo `2^w` has exactly one representation
+
+`f(x) = sum_{k<K} a_k x(x-1)...(x-k+1)  (mod 2^w)`, with `0 <= a_k < 2^(w - v2(k!))`,
+
+where `v2` is the 2-adic valuation and `K = K(w)` is the least `k` with `v2(k!) >= w` (the
+falling factorial of degree `>= K` is divisible by `K!`, hence zero modulo `2^w`). This is the
+falling-factorial normal form of Keller and Olson (Counting polynomial functions (mod p^n),
+Duke Math. J. 35, 1968) and Singmaster (On polynomial functions (mod m), J. Number Theory 6,
+1974, 345-352). The coefficients come from the values `f(0..K-1)` alone: the forward
+differences are `d_k = Delta^k f(0) = k! a_k (mod 2^w)`; with `k! = 2^v u`, `u` odd,
+`a_k = (d_k / 2^v) u^-1 mod 2^(w-v)` (Newton inverse modulo `2^64`, five steps from `u`).
+`meaning.om` traps (code 9) if a `d_k` is not divisible by `2^v`, which the fragment check makes
+unreachable.
+
+Wolfram evaluations behind the constants (WolframLanguageEvaluator):
+
+- `K(w)` for `w = 1..64` = `{2,4,4,6,8,8,8,10,12,12,14,16,16,16,16,18,20,20,22,24,24,24,26,28,28,30,32,32,32,32,32,34,36,36,38,40,40,40,42,44,44,46,48,48,48,48,50,52,52,54,56,56,56,58,60,60,62,64,64,64,64,64,64,66}`
+  (least `k` with `IntegerExponent[k!, 2] >= w`; `K(8) = 10`, `K(64) = 66`). The suite checks
+  all 64 values against `mg_kof` (`W` records).
+- The number of polynomial functions is `prod_{k<K} 2^(w - v2(k!))`: `log2` = 50 (w 8), 170
+  (w 16), 2274 (w 64). At w 3, a brute force over all coefficient tuples gives 1024 distinct
+  functions, equal to the product of the bounds, and every canonical tuple round-trips.
+- `canon[x(x+1), 64] = {0, 2, 1, 0, ...}`, `canon[x^2, 64] = {0, 1, 1, 0, ...}`,
+  `canon[3x^3 + 5x + 7, 8] = {7, 8, 9, 3, 0, 0, 0, 0, 0, 0}`,
+  `canon[7x^5 + 200x^2 + 13, 16] = {13, 207, 305, 175, 70, 7, 0, ...}`,
+  `canon[255x^2 + 254, 8] = {254, 255, 127, 0, ...}`; `2^63 x(x-1) = 0 (mod 2^64)` for
+  `x = 0..999`. These are the `K` records of `om/meaning/test/vectors`.
+
+The falling-factorial form is not the only canonical choice: any injective function of
+`f(0..K-1)` would serve. It is used because it is readable and because it gives an independent
+check: the suite rebuilds `sum a_k x^(k)` and compares it with `f` on 4096 inputs.
+
+### 9.3 Preimage
+
+- Inside the fragment (class 1): `SHA256("omega.function.v1" 0x00 || 0x01 || w u16 || K u16 ||
+  a_0 .. a_{K-1} u64)`, all big-endian.
+- Outside (class 2, intensional fallback): `SHA256("omega.function.v1" 0x00 || 0x02 || w u16 ||
+  body SEMANTIC_ID)`.
+
+The class byte is in the preimage, so a fallback id never equals a canonical id except by a
+SHA-256 collision, and the id records which kind it is.
+
+### 9.4 What is claimed
+
+- Two programs of the same width in the fragment get the same `FUNCTION_ID` **if and only if**
+  they compute the same function (up to SHA-256 collisions). Programs of different widths
+  always differ.
+- Outside the fragment, equal ids imply equal functions (same body), **not** conversely:
+  `x and 0x7fffffffffffffff` written two ways gets two ids.
+- Not claimed: anything about contracts (a program's contract does not enter its
+  `FUNCTION_ID`), division, shifts, comparisons, multi-parameter or effectful programs.
+
+## 10. The graph of meaning (`omega.meaning.graph.v1`)
+
+```text
+Status:      IMPLEMENTED and EXERCISED on the host (om/meaning/meaning.om); in-memory library
+             plus a canonical byte format; no service, no persistence path, no consumer yet
+Domain tags: "omega.meaning.graph.v1", "omega.meaning.receipt.v1"
+```
+
+A graph whose nodes are content-addressed meanings and whose edges are typed relations, each
+equivalence backed by a receipt that a reader can recheck without trusting the writer.
+
+### 10.1 Nodes and edges
+
+| node kind | id | content |
+|---|---|---|
+| 1 PROGRAM | program_id v2 (section 2) | body id, w u16, pre length u16, pre, post length u16, post |
+| 2 BODY | body `SEMANTIC_ID` | w u16, token count u16, tokens (op u8; for a constant also u64) |
+| 3 FUNCTION | `FUNCTION_ID` | the section 9.3 preimage |
+
+Edges use the `RelationKind` codes of `src/omega_types.h`:
+
+| rel | edge | receipt |
+|---|---|---|
+| 4 CONTAINS | PROGRAM -> BODY | none (recomputed) |
+| 7 DERIVED_FROM | FUNCTION -> BODY | none (recomputed) |
+| 9 EQUIVALENT_TO | BODY lo -> BODY hi | kind 1 CANON or kind 2 EXHAUSTIVE |
+| 2 NOT_EQUAL | BODY lo -> BODY hi | kind 3 WITNESS |
+
+`lo`/`hi` order the endpoints by id. Adding a program adds its PROGRAM, BODY and FUNCTION nodes
+(deduplicated by id) and, for a canonical FUNCTION, a CANON equivalence to every other body of
+that FUNCTION.
+
+### 10.2 Receipts
+
+Receipt id = `SHA256("omega.meaning.receipt.v1" 0x00 || content)`.
+
+- kind 1 CANON (99 bytes): `01 || lo || hi || w u16 || FUNCTION_ID`. Checked by recomputing both
+  bodies' `FUNCTION_ID`s from the stored body content: both class 1 and both equal to the one
+  recorded.
+- kind 2 EXHAUSTIVE (75 bytes, w <= 32): `02 || lo || hi || w u16 || 2^w u64`. Checked by
+  evaluating both bodies on all `2^w` inputs.
+- kind 3 WITNESS (91 bytes): `03 || lo || hi || w u16 || x u64 || f_lo(x) u64 || f_hi(x) u64`.
+  Checked by evaluating both bodies at `x`.
+
+`mg_verify` recomputes every node id from its content, every receipt id, and every edge's
+receipt; a witness search that finds nothing adds nothing (no witness is not a proof).
+
+### 10.3 Storage
+
+`"omega.meaning.graph.v1" 0x00 || u32 N || N x (id, kind u8, u32 len, content) || u32 R ||
+R x (id, u32 len, content) || u32 E || E x (src id, rel u16, dst id, receipt id or 32 zero
+bytes)`, big-endian, each list strictly increasing (nodes and receipts by id, edges by
+src, rel, dst, receipt). The bytes depend only on the set of nodes, receipts and edges, not on
+insertion order; the graph digest is SHA-256 of these bytes. `mg_load` refuses truncated or
+trailing bytes, a wrong tag, non-increasing order (so duplicates), malformed bodies, dangling
+edges and unknown node kinds.
+
+### 10.4 Queries (OM-2 words)
+
+`mg_nbr n rel` (neighbours over one relation, or any with rel 0), `mg_class n` (closure over
+EQUIVALENT_TO, n first), `mg_prov n` (every edge touching n; its receipts are the provenance).
+
+## 11. Qualification
 
 `make test-program-id` (tests/program/test_program_id.c, physics-free, runs in the CI AArch64
 job) prints five gates:
@@ -243,3 +388,17 @@ job) prints five gates:
 qualification campaign, the omegatool M8-M14 and Crumbline consumers and the non-energy host
 regression suites on the committed clean tree, and writes a content-addressed receipt under
 `evidence/PROGRAM_ID/`.
+
+`sh om/meaning/test/run.sh seed/out/omc` (host only, no C) builds `om/meaning/meaning.om` with
+the pinned compiler and checks sections 9 and 10: must-collapse pairs (`x + 1 + 1` / `x + 2` /
+`2 + x`, `x(x+1)` / `x*x + x` / `x(x+1) + 2^63 x(x-1)`, the 66-factor falling factorial / 0,
+reassociation, commutation, distribution, `x and 255` / `x` at w 8), must-not-collapse pairs
+(constants one bit apart, the 65-factor product / 0 at w 64, the 9-factor product / 0 at w 8),
+Wolfram coefficient vectors, `FUNCTION_ID` goldens that `run.sh` recomputes with `sha256sum`
+from the 9.3 preimage, the two program_id goldens of `tests/language/golden/v0.txt`, the `K(w)`
+table, refused programs, exhaustive and witness proofs, queries, a randomized differential at
+w 1, 3, 8, 16, 64 (ids equal iff value signatures equal for fragment pairs; equal ids imply
+equal signatures otherwise; reconstruction of every canonical form), graph verification,
+store/load/store byte identity, reverse-insertion digest equality and tamper detection, then
+source and expectation mutants that must each go red. Final line: `MEANING PASS checks=N
+mutants=M/M`.