Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/src/turing/field.h # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / src / turing / field.h` 219 lines ยท 9087 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* TURING Field V0: records that link one contract to its realization specs, 18 * the evidence measured for them, and the selection decisions that cite that 19 * evidence. docs/turing/TURING_W0_PROPOSAL.md sections F and K. 20 * 21 * Data only, not a subsystem. Built post hoc from existing receipts 22 * (evidence/MIXED_ALGEBRA) and the oma_rz_impl registry, read-only. Nothing 23 * here touches src/runtime, src/algebra or src/polyglot. 24 * 25 * Canonical bytes: every record is laid out as an OMG0 object 26 * (omega_canonical_encode: attributes sorted by key, relations sorted by kind 27 * then target) and digested as SHA-256(domain || 0x00 || OMG0 bytes). The 28 * domain prefix keeps every Field digest distinct from an Omega semantic id 29 * (which is SHA-256(OMG0 bytes) with no prefix); Field digests are NOT Omega 30 * semantic ids and must never be used as one (OSC-0B, omega PR #76). 31 * 32 * contract_digest is PROVISIONAL (V0): no existing digest names the Omega-X 33 * contract, so V0 digests the canonical contract bytes defined in field.c. 34 */ 35 #ifndef TURING_FIELD_H 36 #define TURING_FIELD_H 37 38 #include 39 #include 40 41 #define TURING_DIGEST_BYTES 32 42 #define TURING_TEXT 96 43 #define TURING_MAX_SPECS 32 44 #define TURING_MAX_EVIDENCE 1024 45 #define TURING_MAX_RECEIPTS 8 46 #define TURING_MAX_CAND 16 47 #define TURING_MAX_CITE 128 /* v1 cites a whole footprint: specs x sparsities x receipts */ 48 49 #define TURING_DOMAIN_CONTRACT "turing.contract.v0.provisional" 50 #define TURING_DOMAIN_SPEC "turing.spec.v0" 51 #define TURING_DOMAIN_EVIDENCE "turing.evidence.v0" 52 #define TURING_DOMAIN_DECISION "turing.decision.v1" /* v1: cites committed as one cite-set digest */ 53 #define TURING_DOMAIN_CITESET "turing.citeset.v0" 54 55 /* ADR 0019 tiers are PROPOSED: tier is stored as text with the revision it 56 * came from, never as an enum bound to the schema. */ 57 #define TURING_TIER_SOURCE "ADR 0019 PROPOSED, aien-architecture PR #58 head `ed4474a`" 58 59 typedef struct { 60 uint8_t b[TURING_DIGEST_BYTES]; 61 } turing_digest; 62 63 /* The operation's contract (canonical bytes -> PROVISIONAL contract_digest). */ 64 typedef struct { 65 char name[TURING_TEXT]; 66 char statement[256]; 67 char exactness[TURING_TEXT]; 68 char overflow[TURING_TEXT]; 69 char oracle[TURING_TEXT]; 70 char source[TURING_TEXT]; 71 uint64_t max_n; 72 } turing_contract; 73 74 /* A realization choice. No build fields: spec_id must be stable across 75 * rebuilds (Fable item 2). */ 76 typedef struct { 77 turing_digest contract_digest; 78 char rz_id[32]; /* oma_rz_impl.id, e.g. "R2c_crumb" */ 79 char algorithm[TURING_TEXT]; 80 char algebra[TURING_TEXT]; 81 char representation[TURING_TEXT]; 82 char precision[TURING_TEXT]; 83 char language[TURING_TEXT]; 84 char backend[TURING_TEXT]; 85 char machine_class[TURING_TEXT]; 86 uint64_t max_n; 87 int exact; 88 int weak_baseline; 89 } turing_rz_spec; 90 91 enum { TURING_PACK_ONCE = 0, TURING_PACK_PER_CALL = 1 }; 92 93 /* One measured cell of one receipt for one spec. Build identity lives here. */ 94 typedef struct { 95 turing_digest spec_id; 96 uint64_t n, m; 97 uint32_t sparsity_milli; /* sparsity x 1000 */ 98 turing_digest receipt_digest; /* SHA-256 of the receipt file bytes */ 99 char receipt_path[256]; /* where to find it; NOT part of the digest */ 100 char run_id[TURING_TEXT]; 101 char tier[8]; /* text, e.g. "E2" */ 102 char tier_source[TURING_TEXT]; 103 int verified; /* receipt "verified" (oracle-checked) */ 104 uint32_t forced, retries, samples; 105 uint64_t median_ps, q25_ps, q75_ps, min_ps, pack_ps; 106 uint32_t noise_ppm, pack_noise_ppm; 107 uint64_t weight_bytes, working_set_bytes; 108 char build_digest[72]; /* bench binary SHA-256 (hex) */ 109 char git_commit[48]; 110 int tree_dirty; 111 char toolchain[TURING_TEXT]; 112 char cpu_freq_state[TURING_TEXT]; 113 char quiet_flag[TURING_TEXT]; 114 char thermal[TURING_TEXT]; 115 } turing_evidence; 116 117 /* Filter / outcome reason codes carried per candidate in a decision. */ 118 typedef enum { 119 TURING_R_CHOSEN = 0, 120 TURING_R_RANKED, /* eligible, measured, not chosen */ 121 TURING_R_TIED, /* eligible, inside the tied set, not chosen */ 122 TURING_R_CONTRACT_MISMATCH, 123 TURING_R_NOT_EXACT, 124 TURING_R_MAX_N, 125 TURING_R_NO_EVIDENCE, 126 TURING_R_RECEIPT_UNVERIFIED, 127 TURING_R_UNVERIFIED_RUN, 128 TURING_R_CONTENTION_FORCED, 129 TURING_R_TIER, 130 TURING_R_EXPLORE, /* control arm: cold-start pick */ 131 TURING_R__COUNT 132 } turing_reason; 133 134 const char *turing_reason_name(turing_reason r); 135 136 typedef struct { 137 turing_digest contract_digest; 138 char selector[32]; /* "turing.field.v1", "turing.history.v0", or retired "turing.field.v0" */ 139 char constraints[TURING_TEXT]; 140 uint64_t n, m; 141 uint32_t sparsity_milli; 142 int pack; /* TURING_PACK_* */ 143 uint64_t cell_n, cell_m; /* the measured cell (v0) or footprint (v1) the costs came from */ 144 uint32_t cell_sparsity_milli; /* TURING_SPARSITY_ANY when the footprint spans every sparsity */ 145 int exact_cell; 146 size_t ncand; 147 turing_digest cand[TURING_MAX_CAND]; 148 char cand_rz[TURING_MAX_CAND][32]; 149 turing_reason reason[TURING_MAX_CAND]; 150 uint64_t cost_ps[TURING_MAX_CAND]; /* 0 when unmeasured */ 151 int chosen; /* index into cand, -1 none */ 152 char verdict[16]; /* CHOSEN, TIE, NONE, EXPLORE */ 153 char tie_resolution[16]; /* none, incumbent, reference, cheapest */ 154 uint32_t margin_ppm, band_ppm; 155 size_t ncite; 156 turing_digest cite[TURING_MAX_CITE]; /* evidence digests */ 157 int has_supersedes; 158 turing_digest supersedes; 159 } turing_decision; 160 161 typedef struct { 162 turing_digest digest; 163 char path[256]; 164 char run_id[TURING_TEXT]; 165 } turing_receipt_ref; 166 167 typedef struct { 168 turing_contract contract; 169 turing_digest contract_digest; 170 size_t nspec; 171 turing_rz_spec spec[TURING_MAX_SPECS]; 172 turing_digest spec_id[TURING_MAX_SPECS]; 173 size_t nev; 174 turing_evidence ev[TURING_MAX_EVIDENCE]; 175 turing_digest ev_id[TURING_MAX_EVIDENCE]; 176 size_t nreceipt; 177 turing_receipt_ref receipt[TURING_MAX_RECEIPTS]; 178 } turing_store; 179 180 /* Digests. Every function returns 0 on success, -1 on error. */ 181 int turing_contract_digest(const turing_contract *c, turing_digest *out); 182 int turing_spec_digest(const turing_rz_spec *s, turing_digest *out); 183 int turing_evidence_digest(const turing_evidence *e, turing_digest *out); 184 int turing_decision_digest(const turing_decision *d, turing_digest *out); 185 /* Canonical bytes (OMG0 layout) of a record; *len set. For tests. */ 186 int turing_spec_bytes(const turing_rz_spec *s, uint8_t *buf, size_t cap, size_t *len); 187 188 void turing_hex(const turing_digest *d, char out[65]); 189 void turing_hex_short(const turing_digest *d, char out[13]); 190 int turing_digest_eq(const turing_digest *a, const turing_digest *b); 191 int turing_file_digest(const char *path, turing_digest *out); 192 193 /* The Omega-X contract (spec/mixed-algebra-ma2.md, realize_common.h). */ 194 void turing_contract_omega_x(turing_contract *c); 195 196 /* Store. The store is large: allocate with turing_store_new. */ 197 turing_store *turing_store_new(void); 198 void turing_store_free(turing_store *st); 199 /* Adapter 1: oma_rz_impl registry (read-only) -> spec records. */ 200 int turing_ingest_registry(turing_store *st); 201 /* Adapter 2: MA-3 bench receipt (post hoc, read-only) -> spec (must already 202 * exist or be identical) + evidence records. Returns number of evidence 203 * records added, or -1. */ 204 int turing_ingest_receipt(turing_store *st, const char *path); 205 /* Spec derived from a receipt's realizations row (for the rebuild cross-check). */ 206 int turing_spec_from_fields(const turing_digest *contract, const char *rz_id, const char *family, 207 int exact, int weak_baseline, uint64_t max_n, turing_rz_spec *out); 208 int turing_find_spec(const turing_store *st, const char *rz_id); 209 int turing_find_evidence(const turing_store *st, const turing_digest *ev_id); 210 211 /* Decision verification: recompute the decision's cited evidence digests from 212 * the store and re-hash each cited receipt file. Returns 0 when every cited 213 * receipt verifies; otherwise a negative code and a reason in why. */ 214 int turing_decision_verify(const turing_store *st, const turing_decision *d, char *why, size_t whylen); 215 216 /* Per-call cost of one evidence record for a pack mode. */ 217 uint64_t turing_ev_cost(const turing_evidence *e, int pack); 218 219 #endif /* TURING_FIELD_H */