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 / research / atemporal / at1 / evaluator / src / synth.rs

276 lines · 10498 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//! Synthetic writers built on the shadow: an honest engine, an honest oracle
17//! record, the runner's splice, and every mutant of the receipt. These are the
18//! evaluator's own controls; they are never presented as a candidate.
19
20use crate::big::Int;
21use crate::case::{case_bytes_from_body, BoundKind, Case};
22use crate::judge::{label_from, placeholder_verdict, rederive};
23use crate::model::{shadow, status_rule, Mods, Shadow, Status, Val};
24use crate::rat::{Scaled, Q};
25use crate::result::{zero_scaled, Prov, RVal, ResultFile, Six};
26use crate::sha256::sha256_hex;
27
28pub const SYNTH_TIME: &str = "2026-10-09T00:00:00Z";
29pub const SYNTH_COMMIT: &str = "0000000000000000000000000000000000000000";
30
31/// Engine-side defects (all false = the honest synthetic engine).
32#[derive(Clone, Copy, Debug, Default)]
33pub struct EngineMut {
34 pub physics: Mods,
35 /// M5: P(Y+) and P(Y-) exchanged
36 pub y_sign: bool,
37 /// M6: X and Y axes exchanged
38 pub axis_swap: bool,
39 /// clock marginal written as the ideal w/N instead of the interacting p(k)
40 pub ideal_marginal: bool,
41 /// label k reuses the status and Pauli values computed for label k-1 (stale cache)
42 pub stale_label: bool,
43 pub bound_kind_none_nonzero: bool,
44}
45
46/// Oracle-side defects (all false = the honest synthetic oracle).
47#[derive(Clone, Copy, Debug, Default)]
48pub struct OracleMut {
49 pub physics: Mods,
50 /// reference_ideal computed without H_S (no rotation)
51 pub ideal_drop_h: bool,
52}
53
54pub fn bound_1e15() -> Scaled {
55 Scaled { n: Int::from_u64(1), k: 15 }
56}
57
58fn rv(v: &Val, b: &Scaled) -> RVal {
59 RVal::of(v.f64(), b)
60}
61fn undef6() -> Six {
62 let u = RVal::undefined();
63 [[u.clone(), u.clone()], [u.clone(), u.clone()], [u.clone(), u]]
64}
65fn six_of(s: &[[Val; 2]; 3], b: &Scaled) -> Six {
66 [[rv(&s[0][0], b), rv(&s[0][1], b)], [rv(&s[1][0], b), rv(&s[1][1], b)], [rv(&s[2][0], b), rv(&s[2][1], b)]]
67}
68
69pub fn synth_prov(engine_tag: &str, oracle_tag: Option<&str>) -> Prov {
70 let e = sha256_hex(engine_tag.as_bytes());
71 let o = match oracle_tag {
72 Some(t) => sha256_hex(t.as_bytes()),
73 None => e.clone(),
74 };
75 Prov {
76 source_repo: "aien-dev/omega".into(),
77 source_commit: SYNTH_COMMIT.into(),
78 source_tree_clean: "YES".into(),
79 contract_commit: crate::verify::CONTRACT_COMMITS[0].into(),
80 engine_sha256: e,
81 oracle_repo: "aien-dev/omega".into(),
82 oracle_commit: SYNTH_COMMIT.into(),
83 oracle_sha256: o,
84 build_cc: if oracle_tag.is_none() { format!("oracle {}", engine_tag) } else { engine_tag.to_string() },
85 build_flags: "synthetic writer of the AT-1 Agent 4 evaluator (shadow model)".into(),
86 host: "synthetic: values from the at1-eval shadow model, not a candidate".into(),
87 run_started: SYNTH_TIME.into(),
88 run_finished: SYNTH_TIME.into(),
89 artifacts: Vec::new(),
90 }
91}
92
93fn blank(c: &Case, prov: Prov) -> ResultFile {
94 let m = c.m;
95 ResultFile {
96 case: c.clone(),
97 case_file_sha256: sha256_hex(&case_bytes_from_body(&c.body_lines)),
98 arithmetic: "BINARY64".into(),
99 bound_kind: BoundKind::Estimated,
100 kernel_dim: 0,
101 constraint: RVal::undefined(),
102 povm: RVal::undefined(),
103 label: vec![Status::Undefined; m],
104 clock: vec![RVal::undefined(); m],
105 pauli: vec![undef6(); m],
106 ref_label: vec![Status::Undefined; m],
107 ref_clock: vec![RVal::undefined(); m],
108 ref_ideal: vec![undef6(); m],
109 ref_inter: vec![undef6(); m],
110 verdict: placeholder_verdict("NOT_RUN", "none"),
111 verdict_id: String::new(),
112 prov,
113 evidence_digest: String::new(),
114 }
115}
116
117/// The interacting family written from a shadow: (kernel_dim, trivial, labels, clock, pauli).
118fn interacting_lines(c: &Case, sh: &Shadow, b: &Scaled) -> (Vec<Status>, Vec<RVal>, Vec<Six>) {
119 let tolz = Q::from_scaled(&c.tol_zero);
120 let mut lab = vec![Status::Undefined; c.m];
121 let mut clk = vec![RVal::undefined(); c.m];
122 let mut pa = vec![undef6(); c.m];
123 if sh.trivial {
124 return (lab, clk, pa);
125 }
126 for k in 0..c.m {
127 clk[k] = rv(&sh.p[k], b);
128 lab[k] = label_from(&clk[k], &tolz);
129 if lab[k] == Status::Defined {
130 if let Some(s) = &sh.pauli[k] {
131 pa[k] = six_of(s, b);
132 }
133 }
134 }
135 (lab, clk, pa)
136}
137
138/// Engine result before the splice: engine families written, reference families
139/// undefined (the runner replaces them), verdict judged on the engine's own claim.
140pub fn engine_result(c: &Case, em: &EngineMut, tag: &str) -> ResultFile {
141 let b = bound_1e15();
142 let sh = shadow(c, &em.physics, false);
143 let mut r = blank(c, synth_prov(tag, Some("pending-splice")));
144 r.kernel_dim = sh.kernel_dim as i64;
145 r.povm = rv(&sh.povm_residual, &b);
146 if !sh.trivial {
147 r.constraint = RVal::of(0.0, &b);
148 let (mut lab, mut clk, mut pa) = interacting_lines(c, &sh, &b);
149 let tolz = Q::from_scaled(&c.tol_zero);
150 if em.ideal_marginal {
151 let wn = Val::exact(c.w.div(&Q::int(c.n as i64)));
152 for k in 0..c.m {
153 clk[k] = rv(&wn, &b);
154 let st = status_rule(&clk[k].q().unwrap(), &clk[k].bq(), &tolz);
155 if st != lab[k] {
156 // the label now claims what the ideal marginal implies
157 lab[k] = st;
158 if st == Status::Defined {
159 pa[k] = match &sh.pauli[k] { Some(s) => six_of(s, &b), None => six_of(&sh.ideal[k], &b) };
160 } else {
161 pa[k] = undef6();
162 }
163 }
164 }
165 }
166 for k in 0..c.m {
167 if lab[k] != Status::Defined {
168 continue;
169 }
170 if em.y_sign {
171 pa[k][1].swap(0, 1);
172 }
173 if em.axis_swap {
174 pa[k].swap(0, 1);
175 }
176 }
177 if em.stale_label {
178 for k in (1..c.m).rev() {
179 lab[k] = lab[k - 1];
180 pa[k] = pa[k - 1].clone();
181 }
182 }
183 r.label = lab;
184 r.clock = clk;
185 r.pauli = pa;
186 }
187 if em.bound_kind_none_nonzero {
188 r.bound_kind = BoundKind::None;
189 }
190 let nontrivial = !crate::verify::claims_trivial(&r);
191 r.verdict = rederive(&r, nontrivial);
192 r.seal();
193 r
194}
195
196/// Oracle-written record: build_cc `oracle ...`, engine_sha256 == oracle_sha256.
197/// Its engine families repeat its own interacting values.
198pub fn oracle_record(c: &Case, om: &OracleMut, tag: &str) -> ResultFile {
199 let b = bound_1e15();
200 let sh = shadow(c, &om.physics, false);
201 let mut r = blank(c, synth_prov(tag, None));
202 r.kernel_dim = sh.kernel_dim as i64;
203 r.povm = rv(&sh.povm_residual, &b);
204 let ideal = if om.ideal_drop_h { crate::model::ideal_values(c, true) } else { sh.ideal.clone() };
205 for k in 0..c.m {
206 r.ref_ideal[k] = six_of(&ideal[k], &b);
207 }
208 if !sh.trivial {
209 r.constraint = RVal::of(0.0, &b);
210 let (lab, clk, pa) = interacting_lines(c, &sh, &b);
211 r.label = lab.clone();
212 r.clock = clk.clone();
213 r.pauli = pa.clone();
214 r.ref_label = lab;
215 r.ref_clock = clk;
216 r.ref_inter = pa;
217 }
218 let nontrivial = !crate::verify::claims_trivial(&r);
219 r.verdict = rederive(&r, nontrivial);
220 r.seal();
221 r
222}
223
224/// The runner's splice (charter reading c): every reference_* family of the
225/// oracle record replaces the candidate's, oracle provenance is filled from the
226/// record, the verdict is judged again on the engine's own trivial claim, and
227/// both identities are recomputed. An oracle record that did not complete
228/// turns the candidate into ERROR ORACLE_UNAVAILABLE.
229pub fn splice(engine: &ResultFile, oracle: &ResultFile) -> Result<ResultFile, String> {
230 if engine.case.body_lines != oracle.case.body_lines || engine.case_file_sha256 != oracle.case_file_sha256 {
231 return Err("engine result and oracle record are not for the same case".into());
232 }
233 if !(oracle.prov.build_cc.starts_with("oracle ") && oracle.prov.engine_sha256 == oracle.prov.oracle_sha256) {
234 return Err("second input is not an oracle-marked record (build_cc `oracle ...`, engine_sha256 == oracle_sha256)".into());
235 }
236 if engine.prov.build_cc.starts_with("oracle ") {
237 return Err("first input is an oracle record, never a candidate".into());
238 }
239 let mut r = engine.clone();
240 let eo = engine.verdict.outcome.as_str();
241 if eo == "ERROR" || eo == "NOT_RUN" {
242 return Ok(r);
243 }
244 r.prov.oracle_repo = oracle.prov.source_repo.clone();
245 r.prov.oracle_commit = oracle.prov.source_commit.clone();
246 r.prov.oracle_sha256 = oracle.prov.engine_sha256.clone();
247 let oo = oracle.verdict.outcome.as_str();
248 if oo == "ERROR" || oo == "NOT_RUN" {
249 let m = r.case.m;
250 r.kernel_dim = 0;
251 r.constraint = RVal::undefined();
252 r.povm = RVal::undefined();
253 r.label = vec![Status::Undefined; m];
254 r.clock = vec![RVal::undefined(); m];
255 r.pauli = vec![undef6(); m];
256 r.ref_label = vec![Status::Undefined; m];
257 r.ref_clock = vec![RVal::undefined(); m];
258 r.ref_ideal = vec![undef6(); m];
259 r.ref_inter = vec![undef6(); m];
260 r.verdict = placeholder_verdict("ERROR", "ORACLE_UNAVAILABLE");
261 r.seal();
262 return Ok(r);
263 }
264 r.ref_label = oracle.ref_label.clone();
265 r.ref_clock = oracle.ref_clock.clone();
266 r.ref_ideal = oracle.ref_ideal.clone();
267 r.ref_inter = oracle.ref_inter.clone();
268 let nontrivial = !crate::verify::claims_trivial(&r);
269 r.verdict = rederive(&r, nontrivial);
270 r.seal();
271 Ok(r)
272}
273
274pub fn none_bound() -> Scaled {
275 zero_scaled()
276}