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 / program-identity.md

404 lines · 26074 bytes Raw Blame History Source

Specification: Omega Program Identity v2 (OMEGA_PROGRAM_ID_*)

Document ID:     SPEC-OMEGA-PROGRAM-ID-V2
Amends:          SPEC-OMEGA-M8 (spec/program.md), spec/omega-language-v0.md identity law 6,
                 spec/visor.md section 6a (program id finding)
Status:          IMPLEMENTED (branch fix/program-id-body)
Domain tag:      "omega.program.v2"

1. The defect this fixes

omega_program_compute_id (v1) hashed "PROG", the program name, the contract type tags and the low byte of each width, the two contract constraint ids, and the low byte of cost.insn_count and cost.latency_cycles. It did not hash the body. Two programs with different meaning therefore shared an id whenever they shared a name, a contract and (by accident) a cost low byte. Reproduced in Visor: after clear, fn t(x: u64) -> u64 { x + 1 } and fn t(x: u64) -> u64 { x + 2 } got the same program_id (reproduced on origin/main 8e7a445: both 87a9e0e1...). Discovery gives every machine-code slice candidate the same name and contract, so equal-length slices would also have shared one id. That breaks content addressing: one id named two meanings.

2. Identity law (v2)

program_id = SHA256( "omega.program.v2" || 0x00
                     || body_root_id                     (32 bytes)
                     || input_type_id                    (32 bytes)
                     || output_type_id                   (32 bytes)
                     || contract.precondition_id         (32 bytes)
                     || contract.postcondition_id )      (32 bytes)

Every 32-byte component is an existing canonical SemanticId computed by omega_compute_semantic_id (spec/canonical-encoding.md). No second canonical encoder exists: the body is lowered into a scratch OmegaGraph with the existing builders and only the root object's id is taken. The 17-byte domain tag is the version boundary: a v1 preimage began with "PROG" and a name, so a v1 id and a v2 id can never come from the same preimage, and a reader that sees the tag knows which law produced the id.

2.1 The canonical semantic body

A program body is the ordered step list OmegaProgramBody (innermost step first): f(x) = op_n( ... op_2( op_1(x, c_1), c_2) ..., c_n), each step one of OP_ADD OP_SUB OP_MUL OP_AND OP_OR with one constant. It is lowered as:

objectbuildernotes
Tomega_build_type_uint(w) (or _signed_int / _bitvector for those tags)w = contract input width; the operation type
Pomega_build_param(T, 0)the program's parameter (section 2.2)
C_iomega_build_val_uint(T, w, c_i)step constant, big-endian ceil(w/8) bytes
O_iomega_build_op_binary(op_i, OVERFLOW_WRAP, T)the step's operation; wrap is what the AArch64 realization does
A_iomega_build_apply(O_i, A_{i-1}, C_i) with A_0 = Prunning value is operand 0, constant operand 1

body_root_id = id(A_n) (and id(P) for an empty body, the identity function). These are the same object shapes the Visor language already builds for expressions (x + y lowers to omega_build_apply(omega_build_op_binary(OP_ADD, OVERFLOW_WRAP, u64), x, y)).

input_type_id / output_type_id are the ids of the contract's TYPE objects built the same way from (tag, width), so a width change changes the id through a canonical type object, not through a raw byte.

2.2 The parameter object (new canonical shape)

The object model had no free variable. omega_build_param(type_id, index) builds:

A literal value always has byte_len >= 1 and no attributes, so a parameter can never equal a literal. The parameter carries its position, never its source name, so fn f(x) and fn f(n) with the same body are the same program (alpha-equivalence).

2.3 Programs without a body

has_body = false means the program's meaning is unknown to Omega (for example a raw machine-code slice nothing could lift). Such a program has no identity: omega_program_compute_id returns -1 and sets program_id to all zero bytes, and omega_library_insert refuses an all-zero id. Two unknown programs never share an id.

2.4 The composed postcondition (semantic rule: composition is associative)

Composition is sequencing, and sequencing is associative, so the contract of a composition must not depend on how the chain was bracketed. omega_program_compose(a, b) therefore does not derive a postcondition text (the old "(B)o(A)" text was non-associative: (a;b);c and a;(b;c) got different postcondition ids and so different program ids). Instead:

Hence (a;b);c, a;(b;c) and every other bracketing of one chain have one program id, while a;b and b;a differ whenever the bodies differ (different body, different leaf order).

3. Field classification

fieldclassin the id?reason
body (step list)semanticyes, as body_root_idwhat the program computes
contract.input_type, input_widthsemanticyes, as input_type_idthe domain
contract.output_type, output_widthsemanticyes, as output_type_idthe codomain
contract.precondition_id, postcondition_idsemanticyesthe promise the program makes; the text strings are the source of these ids and enter only through them
namemetadatano (removed in v2)a human label; renaming does not change meaning. Two names for one body now share one id (dedupe), exactly as let a = 7 / let b = 7 share one VALUE id
cost.insn_count, reg_pressure, memory_bytesmetadatano (removed in v2)properties of one realization (the same body realized differently has a different count)
cost.latency_cyclesmetadatano (removed in v2)a model or measurement of one realization on one machine
contract.post_leaves (compositions)semanticyes, through postcondition_id (section 2.4)the ordered component postconditions
contract.postcondition text of a compositionmetadatanodisplay only; the id comes from the leaf list
realization (code bytes, realization id, target)metadatanoa realization of the meaning, identified separately by realization_id and the (program, machine, realization) triple id
graph pointermetadatanonot used for identity; pointer values never enter an id
is_realized, is_verifiedstatenolifecycle, not meaning
source whitespace, comments, literal spelling, parameter name, commutative operand sidenot storednonormalized away by the parser/lowering before the body exists
parser node allocation order, builder call ordernot storednothe body is an ordered step list; the scratch graph is rebuilt from it in one fixed order

4. Where bodies come from

5. Consequences for consumers

6. Visor behaviour change

Before: fn t(x: u64) -> u64 { x + 1 } then fn t(x: u64) -> u64 { x + 2 } failed with "identity collision ... the program id does not cover the body". Now: both succeed, the ids differ, the second definition is added to the program table and t is rebound to it. fn other with transform's exact body and contract returns transform's id and reuses its table entry (the entry keeps its first name).

7. Changed golden ids (old v1 -> new v2)

Every program id changes (new preimage). The ids pinned in tests, and why:

whereprogramold (v1)new (v2)
tests/language/golden/v0.txt P rows 1-3, tests/visor/sessions/e2e.expected (2 lines)fn transform(x: u64) -> u64 requires true ensures result >= 1 { x * 2 + 1 } (and its two respellings)beedf7f6fc3853c0aed82e0b35e165b14878a82b0ebac64aa5bd9430800a8c4f83bd39597742d3bb83e5140c662532c0a2ecb59e5f868e38be16276981644543
tests/language/golden/v0.txt P row 4fn mask(x: u64) -> u64 { x & 0xff }7f6104b6cbf7b1e87055458fa9de9794067893186a84991b35b2a435c06ee244e180baf4807d890dc1ba22472e847da76e877ee04d59b0762f6dfc26b2af62ff

Reason for all: v2 hashes the domain tag, the canonical body root and the contract type object ids, and no longer hashes the name or cost. The realization code bytes in the same rows (and every E row) are unchanged. Behaviour changes in tests:

The omegatool M4-M14 gate suites needed no change.

Composition postcondition rule (section 2.4) changes every composed program's id again (its postcondition id is now the sequence constraint over the flattened leaf list, not the hash of the "(B)o(A)" text). No pinned golden changes: Visor fn programs carry their own ensures leaf, so the language golden P rows and e2e.expected keep the v2 ids above. Examples (M11 benchmark corpus, make test-m11 demo, first 16 hex; text-derived -> leaf-list):

programbefore 2.4after 2.4
mul2;add1;add5bdca70b9e99a31cbabdda5bc4c0d1300
mul2;add1;mul3e678c0ba6f3e1236db28207b80a5f6ed
mul2;add1;sub4451f56e9b4c8564df9d39c98a66da1ec
mul2;add1;add10c1a07f6c9dfa754cb1ccbc58e3eb04c3

The discovered abstraction (lifted, not composed) keeps 52b6059b....

8. Non-claims and deferred defects

9. FUNCTION_ID (omega.function.v1)

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:

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):

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

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

10. The graph of meaning (omega.meaning.graph.v1)

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 kindidcontent
1 PROGRAMprogram_id v2 (section 2)body id, w u16, pre length u16, pre, post length u16, post
2 BODYbody SEMANTIC_IDw u16, token count u16, tokens (op u8; for a constant also u64)
3 FUNCTIONFUNCTION_IDthe section 9.3 preimage

Edges use the RelationKind codes of src/omega_types.h:

reledgereceipt
4 CONTAINSPROGRAM -> BODYnone (recomputed)
7 DERIVED_FROMFUNCTION -> BODYnone (recomputed)
9 EQUIVALENT_TOBODY lo -> BODY hikind 1 CANON or kind 2 EXHAUSTIVE
2 NOT_EQUALBODY lo -> BODY hikind 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).

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:

gatewhat it proves
OMEGA_PROGRAM_ID_BODY_BOUND_PASSx + 1 vs x + 2 differ through omega_program_build_unary_op, through Visor lowering, and under an identical name + contract + cost (the v1 collision); composition order separates; a body-less program gets no id; a 33-bit constant is refused; the v2 id differs from the v1 recipe
OMEGA_PROGRAM_ID_REPRESENTATION_INVARIANT_PASSname, cost, realization bytes and pointer values do not move the id; six Visor spellings (whitespace, comments, parameter name, operand side, literal spelling, fn name) share one id; library composition equals Visor lowering when both state the same contract; 400 seeded chains (3-8 parts, some with user-stated leaf postconditions) x 4 random bracketings all equal the left fold, with the leaf list flattened; a;b != b;a for 400 pairs with different bodies; a stale leaf list is ignored; a hand-built body graph in 8 scrambled allocation orders has the same root; lift(realization) == body
OMEGA_PROGRAM_ID_MUTATION_SEPARATION_PASSseeded differential over 3000 random programs (every pair, ~4.5M comparisons): id equal iff a hash-free structural oracle says body + contract equal; 2000 programs x 8 single mutations (op, constant, width, output width, pre, post, step added, step removed) always separate
OMEGA_PROGRAM_ID_LIBRARY_REGRESSION_PASSlibrary duplicate / admission / no-body refusal / DAG, discovery lift to mul2;add1 and admission, refactor keeps identity, realization triple id follows the program id, 64-step capacity
OMEGA_PROGRAM_ID_VISOR_REGRESSION_PASSVisor session: distinct ids after clear, redefinition rebinds, aliases and respellings reuse the entry, stored realization == emit(body)

tools/program_id_receipt.sh (shell only) runs these plus the Visor suites, the Visor V1 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`.