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 / tests / dual_experiment / test_applic.om

355 lines · 8999 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3note
4note DUAL applicability experiment tests (pure seeded OM-2, composed after
5note src/dual_experiment/applic.om). Exact port of test_applic.c: 13,020 checks
6note covering ledger conservation at every step, determinism, pinned parameter
7note digest, predictor finiteness/bounds, and negative controls.
8
9global ta_stats ulong 2
10global ta_out uchar 256
11
12text ta_t_pin "e489d25f5f0d23cfe8624a5cc82a5f770f04cb03fd3b441aac627e1a0087ecea"
13text ta_t_fail "FAIL test_applic check "
14text ta_t_nl "\n"
15text ta_t_rdig "results digest: "
16text ta_t_pdig "params digest: "
17text ta_t_shuf1 "shuffled worse than real in "
18text ta_t_shuf2 " / 192 runs\n"
19text ta_t_sum1 "test_applic: "
20text ta_t_sum2 " checks, "
21text ta_t_sum3 " failures\n"
22
23fn ta_write_all fd int n ulong to void
24 off = ulong 0
25 while lt off n bound 64
26 k = write fd ta_out off sub n off
27 if le k 0
28 ret
29 end
30 off = add off ulong k
31 end
32end
33
34fn ta_check cond bool id ulong to void
35 buf = new uchar 128 0
36 put ta_stats 0 add get ta_stats 0 1
37 if not cond
38 put ta_stats 1 add get ta_stats 1 1
39 p = ulong 0
40 p = ap_buf_copy buf p ta_t_fail
41 p = ap_buf_u64 buf p id
42 p = ap_buf_byte buf p uchar 10
43 for i ulong p bound 128
44 put ta_out i get buf i
45 end
46 ta_write_all int 2 p
47 end
48end
49
50fn ta_eq_bytes a view uchar 64 b view uchar * to bool
51 if ne len b 64
52 ret false
53 end
54 for i ulong 64
55 if ne get a i get b i
56 ret false
57 end
58 end
59 ret true
60end
61
62fn ta_eq_bytes64 a view uchar 64 b view uchar 64 to bool
63 for i ulong 64
64 if ne get a i get b i
65 ret false
66 end
67 end
68 ret true
69end
70
71fn ta_windows_eq to bool
72 for i ulong 800
73 if ne get ap_win_u i get ap_win_u add 800 i
74 ret false
75 end
76 end
77 for i ulong 600
78 a = bitcast ulong get ap_win_f i
79 b = bitcast ulong get ap_win_f add 600 i
80 if ne a b
81 ret false
82 end
83 end
84 ret true
85end
86
87fn ta_items_eq n ulong to bool
88 for i ulong n bound 65536
89 j = add AP_MAX_ITEMS i
90 if ne get ap_it_arr i get ap_it_arr j
91 ret false
92 end
93 if ne get ap_it_dem i get ap_it_dem j
94 ret false
95 end
96 if ne get ap_it_rem i get ap_it_rem j
97 ret false
98 end
99 if ne get ap_it_mem i get ap_it_mem j
100 ret false
101 end
102 if ne get ap_it_slt i get ap_it_slt j
103 ret false
104 end
105 if ne get ap_it_cls i get ap_it_cls j
106 ret false
107 end
108 end
109 ret true
110end
111
112fn ta_test_ledger_one wl ulong si ulong to void
113 ap_sim_init_indexed 0 wl ap_seed wl si si
114 for t ulong AP_STEPS bound 2048
115 r = ap_sim_step 0
116 if or ne r 0 not ap_sim_ledger_ok 0
117 ta_check false 100
118 break
119 end
120 end
121 ta_check eq get ap_sim_u 14 AP_STEPS 101
122 ta_check eq get ap_sim_u 11 AP_WINDOWS 102
123 ta_check eq get ap_sim_u 9 0 103
124 ta_check and gt get ap_sim_u 6 0 gt get ap_sim_u 7 0 104
125 a = ulong 0
126 c = ulong 0
127 rj = ulong 0
128 nw = get ap_sim_u 11
129 for w ulong nw bound 128
130 wub = mul w 8
131 a = add a get ap_win_u wub
132 c = add c get ap_win_u add wub 1
133 rj = add rj get ap_win_u add wub 3
134 end
135 ta_check eq a get ap_sim_u 6 105
136 ta_check eq c get ap_sim_u 7 106
137 ta_check eq rj get ap_sim_u 8 107
138 lim = add 1.0f64 1.0e-12f64
139 for w ulong nw bound 128
140 wfb = mul w 6
141 wub = mul w 8
142 ta_check le get ap_win_f wfb lim 108
143 ta_check le get ap_win_f add wfb 1 lim 109
144 ta_check le get ap_win_f add wfb 2 lim 110
145 ta_check le get ap_win_u add wub 2 AP_WINDOW 111
146 end
147end
148
149fn ta_test_ledger_every_step to void
150 for wl ulong AP_WL_COUNT
151 for si ulong 3
152 ta_test_ledger_one wl si
153 end
154 end
155 ap_sim_init 0 5 ap_seed 5 0
156 r1 = ap_sim_run 0
157 ta_check eq get ap_win_u 7 AP_SLOTS 120
158 ta_check eq get ap_win_u 799 AP_CAP_DROP_SLOTS 121
159 ap_sim_init 0 2 ap_seed 2 0
160 r2 = ap_sim_run 0
161 ta_check gt get ap_sim_u 8 0 122
162 for si ulong AP_SEEDS
163 ap_sim_init_indexed 0 7 ap_seed 7 si si
164 ta_check and gt get ap_sim_f 4 0.0f64 eq get ap_sim_f 3 ap_sweep_sigma si 123
165 rc = ap_sim_run 0
166 ta_check and eq rc 0 eq get ap_sim_u 9 0 124
167 end
168 ta_check and eq ap_sweep_sigma 0 0.0f64 eq ap_sweep_sigma 23 1.5f64 125
169 put ap_sim_u 7 add get ap_sim_u 7 1
170 ta_check not ap_sim_ledger_ok 0 126
171 put ap_sim_u 7 sub get ap_sim_u 7 1
172 ta_check ap_sim_ledger_ok 0 127
173end
174
175fn ta_print_digest label view uchar * hx view uchar 64 to void
176 buf = new uchar 128 0
177 p = ulong 0
178 p = ap_buf_copy buf p label
179 for i ulong 64
180 put buf add p i get hx i
181 end
182 p = add p 64
183 p = ap_buf_byte buf p uchar 10
184 for i ulong p bound 128
185 put ta_out i get buf i
186 end
187 ta_write_all int 1 p
188end
189
190fn ta_test_determinism to void
191 ap_sim_init 0 1 12345
192 r1 = ap_sim_run 0
193 ap_sim_init 1 1 12345
194 r2 = ap_sim_run 1
195 ta_check ta_windows_eq 201
196 ni0 = get ap_sim_u 0
197 ni1 = get ap_sim_u 20
198 ta_check and eq ni0 ni1 ta_items_eq ni0 202
199 ap_sim_init 1 1 12346
200 r3 = ap_sim_run 1
201 ta_check not ta_windows_eq 203
202 ta_check eq ap_campaign 0 0 0 204
203 ta_check eq ap_campaign 1 1 0 205
204 ta_check eq AP_NROWS 192 206
205 da = new uchar 32 0
206 db = new uchar 32 0
207 ha = new uchar 64 0
208 hb = new uchar 64 0
209 ap_rows_digest 0 AP_NROWS da
210 ap_rows_digest 1 AP_NROWS db
211 p1 = ap_buf_hex32 ha 0 da
212 p2 = ap_buf_hex32 hb 0 db
213 ta_check ta_eq_bytes64 ha hb 207
214 ta_print_digest ta_t_rdig ha
215 pd = new uchar 32 0
216 ph = new uchar 64 0
217 ap_params_digest pd
218 p3 = ap_buf_hex32 ph 0 pd
219 ta_print_digest ta_t_pdig ph
220 ta_check ta_eq_bytes ph ta_t_pin 208
221end
222
223fn ta_test_predictor_finite to void
224 for wl ulong AP_WL_COUNT
225 ap_sim_init 0 wl ap_seed wl 7
226 r = ap_sim_run 0
227 nw = get ap_sim_u 11
228 for w ulong nw bound 128
229 ap_predict_win_default 0 w
230 pc = get ap_pred_f 0
231 pq = get ap_pred_f 1
232 pb = get ap_pred_f 2
233 ta_check and ap_isfinite pc ge pc 0.0f64 301
234 ta_check and ap_isfinite pq and ge pq 0.0f64 le pq 1.0f64 302
235 ta_check and ap_isfinite pb and ge pb 0.0f64 le pb 1.0f64 303
236 end
237 ap_error_real 0
238 ec = get ap_err_f 3
239 ew = get ap_err_w 0
240 ap_error_shuffled 0 3
241 sc = get ap_err_f 3
242 ap_error_known_arrivals 0
243 kc = get ap_err_f 3
244 ok_e = and and ap_isfinite ec ge ec 0.0f64 and ap_isfinite sc and ap_isfinite kc ge kc 0.0f64
245 ta_check ok_e 304
246 ta_check eq ew 94 305
247 end
248 for i ulong 8
249 put ap_win_u i 0
250 end
251 for i ulong 6
252 put ap_win_f i 0.0f64
253 end
254 put ap_win_u 7 AP_SLOTS
255 ap_predict_win_default 0 0
256 ta_check and eq get ap_pred_f 0 0.0f64 and eq get ap_pred_f 1 0.0f64 eq get ap_pred_f 2 0.0f64 306
257end
258
259fn ta_test_neg_extra to void
260 eps = 1.0e-12f64
261 cv_a = 0.0f64
262 cv_b = 0.0f64
263 top_a = 0.0f64
264 top_b = 0.0f64
265 for i ulong AP_NROWS
266 wl = get ap_row_u mul i 7
267 rfb = mul i 19
268 if eq wl 0
269 cv_a = add cv_a get ap_row_f add rfb 12
270 top_a = add top_a get ap_row_f add rfb 13
271 end
272 if eq wl 1
273 cv_b = add cv_b get ap_row_f add rfb 12
274 top_b = add top_b get ap_row_f add rfb 13
275 end
276 end
277 ta_check and gt cv_b cv_a gt top_b top_a 407
278 va = new f64 4 0.0f64
279 vb = new f64 4 0.0f64
280 vc = new f64 4 0.0f64
281 put va 0 1.0f64
282 put va 1 2.0f64
283 put va 2 3.0f64
284 put va 3 4.0f64
285 put vb 0 2.0f64
286 put vb 1 4.0f64
287 put vb 2 6.0f64
288 put vb 3 8.0f64
289 put vc 0 4.0f64
290 put vc 1 3.0f64
291 put vc 2 2.0f64
292 put vc 3 1.0f64
293 ta_check lt fabs sub ap_pearson va vb 4 1.0f64 eps 408
294 ta_check lt fabs add ap_pearson va vc 4 1.0f64 eps 409
295end
296
297fn ta_test_negative_controls to void
298 x = new f64 192 0.0f64
299 y = new f64 192 0.0f64
300 worse = ulong 0
301 eps = 1.0e-12f64
302 for i ulong AP_NROWS
303 rfb = mul i 19
304 rc = get ap_row_f add rfb 3
305 if gt get ap_row_f add rfb 11 rc
306 worse = add worse 1
307 end
308 put x i get ap_row_f add rfb 17
309 put y i rc
310 cv = get ap_row_f add rfb 12
311 top = get ap_row_f add rfb 13
312 mx = get ap_row_f add rfb 14
313 ent = get ap_row_f add rfb 15
314 ta_check and ap_isfinite cv ge cv 0.0f64 401
315 ta_check and ge top 0.0f64 le top 1.0f64 402
316 ta_check and ge mx 0.0f64 le mx add top eps 403
317 ta_check and ge ent 0.0f64 le ent add 1.0f64 eps 404
318 end
319 buf = new uchar 128 0
320 p = ulong 0
321 p = ap_buf_copy buf p ta_t_shuf1
322 p = ap_buf_u64 buf p worse
323 p = ap_buf_copy buf p ta_t_shuf2
324 for i ulong p bound 128
325 put ta_out i get buf i
326 end
327 ta_write_all int 1 p
328 ta_check gt mul worse 2 AP_NROWS 405
329 pr = ap_pearson x y AP_NROWS
330 cov = get ap_pearson_f 1
331 ta_check and eq cov 0.0f64 eq pr 0.0f64 406
332 ta_test_neg_extra
333end
334
335fn main to int
336 ta_test_ledger_every_step
337 ta_test_determinism
338 ta_test_predictor_finite
339 ta_test_negative_controls
340 buf = new uchar 128 0
341 p = ulong 0
342 p = ap_buf_copy buf p ta_t_sum1
343 p = ap_buf_u64 buf p get ta_stats 0
344 p = ap_buf_copy buf p ta_t_sum2
345 p = ap_buf_u64 buf p get ta_stats 1
346 p = ap_buf_copy buf p ta_t_sum3
347 for i ulong p bound 128
348 put ta_out i get buf i
349 end
350 ta_write_all int 1 p
351 if ne get ta_stats 1 0
352 ret int 1
353 end
354 ret int 0
355end