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 / test_dual_update.om

513 lines · 13557 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3note
4note tests/dual/test_dual_update.om -- DUAL-1a reference update tests in pure seeded OM-2.
5note Replaces tests/dual/test_dual_update.c and tests/dual/dual_ref.{c,h}.
6note Built by concatenating src/dual/rx_dual.om + tests/dual/test_dual_update.om.
7
8const T_BUDGET f64 5000.0
9const T_SCALE f64 1000.0
10
11text t_str_0 "FAIL test_dual_update check="
12text t_str_1 "\n"
13text t_str_2 "test_dual_update: "
14text t_str_3 " checks, "
15text t_str_4 " failures: PASS\n"
16text t_str_5 " failures: FAIL\n"
17global g_chk ulong 1
18global g_fl ulong 1
19global g_rng ulong 1
20global g_out uchar 256
21global g_est f64 64
22global g_sd f64 64
23global g_tr f64 64
24global g_ea uchar 4096
25
26fn t_pr_txt s view uchar * to void
27 n = len s
28 for i ulong n
29 put g_out i get s i
30 end
31 _w = write 1 g_out 0 n
32end
33
34fn t_pr_u64 v ulong to void
35 if eq v 0
36 put g_out 0 uchar 48
37 _w = write 1 g_out 0 1
38 ret
39 end
40 n = ulong 0
41 x = v
42 while gt x 0
43 put g_out n uchar add 48 rem x 10
44 x = div x 10
45 n = add n 1
46 end
47 i = ulong 0
48 while lt i div n 2
49 j = sub sub n 1 i
50 tmp = get g_out i
51 put g_out i get g_out j
52 put g_out j tmp
53 i = add i 1
54 end
55 _w = write 1 g_out 0 n
56end
57
58fn chk ok bool id ulong to void
59 put g_chk 0 add get g_chk 0 1
60 if not ok
61 put g_fl 0 add get g_fl 0 1
62 t_pr_txt t_str_0
63 t_pr_u64 id
64 t_pr_txt t_str_1
65 end
66end
67
68fn chk_st got long want long id ulong to void
69 put g_chk 0 add get g_chk 0 1
70 if ne got want
71 put g_fl 0 add get g_fl 0 1
72 t_pr_txt t_str_0
73 t_pr_u64 id
74 t_pr_txt t_str_1
75 end
76end
77
78fn trnd to ulong
79 x = get g_rng 0
80 x = xor x shr x 12
81 x = xor x shl x 25
82 x = xor x shr x 27
83 put g_rng 0 x
84 m = or shl ulong 0x2545f491 32 ulong 0x4f6cdd1d
85 ret mul x m
86end
87
88fn trdbl lo f64 hi f64 to f64
89 u = div f64 shr trnd 11 9007199254740992.0
90 ret add lo mul sub hi lo u
91end
92
93fn fx_ctl s ulong id ulong eta f64 rho f64 ks f64 lmax f64 to void
94 put g_ct_eta s eta
95 put g_ct_rho s rho
96 put g_ct_ks s ks
97 put g_ct_age s 4
98 put g_ct_cad s 1
99 put g_ct_n s 1
100 bo = mul s 32
101 put g_ct_rid bo id
102 put g_ct_lm bo lmax
103end
104
105fn fx_res s ulong id ulong u ulong sc f64 to void
106 put g_rs_id s id
107 put g_rs_u s u
108 put g_rs_sc s sc
109 dl_dg_fill add 1024 mul s 32 uchar 0x11
110end
111
112fn fx_input ins ulong x f64 sd f64 gen ulong cal ulong to void
113 dl_in_clr ins
114 off = mul ins 32
115 dl_dg_fill add 12992 off uchar add 0x30 and gen 0x3f
116 put g_in_ek ins DL_EK_EST
117 put g_in_u ins DL_U_BYTES
118 put g_in_est ins x
119 put g_in_unc ins sd
120 put g_in_gen ins gen
121 dl_dg_fill add 13248 off uchar 0x66
122 put g_in_evv ins 1
123 if ne cal 0
124 dl_dg_fill add 13376 off uchar 0x44
125 end
126end
127
128fn ref_grad est f64 bgt f64 sc f64 unc f64 ks f64 to f64
129 p = div sub est bgt sc
130 band = div mul ks unc sc
131 if gt p band
132 ret sub p band
133 end
134 if lt p sub 0.0 band
135 ret add p band
136 end
137 ret 0.0
138end
139
140fn pow_int base f64 n ulong to f64
141 r = f64 1.0
142 for i ulong n
143 r = mul r base
144 end
145 ret r
146end
147
148fn ref_closed l0 f64 g f64 eta f64 rho f64 t ulong to f64
149 if eq rho 0.0
150 ret add l0 mul mul eta g f64 t
151 end
152 a = pow_int sub 1.0 rho t
153 ret add mul a l0 div mul mul eta g sub 1.0 a rho
154end
155
156fn ref_fp g f64 eta f64 rho f64 to f64
157 ret div mul eta g rho
158end
159
160fn run_seq ctl ulong rs ulong n ulong dst ulong rec_tr ulong to long
161 fx_input 0 get g_est 0 get g_sd 0 1 1
162 put g_dla 3 T_BUDGET
163 put g_dws 0 0
164 st = dl_init_state rs DL_CLS_SOFT 0 0 ctl 1
165 if ne st DL_OK
166 ret st
167 end
168 if ne rec_tr 0
169 put g_tr 0 get g_cs_lam 0
170 end
171 t = ulong 1
172 while lt t n
173 fx_input 0 get g_est t get g_sd t add t 1 1
174 st = dl_update 0 rs 0 ctl add t 1 1
175 if ne st DL_OK
176 ret st
177 end
178 if ne rec_tr 0
179 put g_tr t get g_cs_lam 1
180 end
181 dl_cs_copy 0 1
182 t = add t 1
183 end
184 dl_cs_copy dst 0
185 ret DL_OK
186end
187
188fn test_analytic_2 to void
189 note 5. clip
190 fx_ctl 0 1 1.0 0.0 0.0 3.0
191 for i ulong 60
192 put g_est i 7000.0
193 put g_sd i 0.0
194 end
195 chk_st run_seq 0 0 60 2 1 DL_OK 140
196 chk and eq get g_tr 0 2.0 and eq get g_tr 1 3.0 eq get g_tr 59 3.0 141
197 note 6. zero eta
198 fx_ctl 0 1 0.0 0.1 2.0 10.0
199 for i ulong 60
200 put g_est i 9000.0
201 put g_sd i 0.0
202 end
203 chk_st run_seq 0 0 60 2 1 DL_OK 142
204 for i ulong 60
205 chk eq get g_tr i 0.0 143
206 end
207 note 7. rho > 0 forgets scarcity
208 fx_ctl 0 1 0.5 0.1 2.0 10.0
209 for i ulong 60
210 if lt i 10
211 put g_est i 7000.0
212 else
213 put g_est i 5000.0
214 end
215 put g_sd i 100.0
216 end
217 chk_st run_seq 0 0 60 2 1 DL_OK 144
218 chk gt get g_tr 9 1.0 145
219 i = ulong 10
220 while lt i 60
221 want = mul get g_tr 9 pow_int 0.9 sub i 9
222 chk lt dl_fabs sub get g_tr i want 1e-9 146
223 i = add i 1
224 end
225 chk lt get g_cs_lam 2 mul 0.01 get g_tr 9 147
226 note 8. determinism
227 fx_ctl 0 1 0.1 0.05 2.0 10.0
228 for k ulong 60
229 put g_est k add 5300.0 mul 200.0 sub f64 rem k 7 3.0
230 put g_sd k 80.0
231 end
232 chk_st run_seq 0 0 60 2 0 DL_OK 148
233 chk_st run_seq 0 0 60 3 0 DL_OK 149
234 chk_st dl_enc_constraint 2 DL_ENC_MAX DL_OK 150
235 la = get g_dws 1
236 for m1 ulong la
237 put g_ea m1 get g_dw m1
238 end
239 chk_st dl_enc_constraint 3 DL_ENC_MAX DL_OK 151
240 lb = get g_dws 1
241 eq_all = eq la lb
242 if eq_all
243 for m2 ulong la
244 if ne get g_ea m2 get g_dw m2
245 eq_all = false
246 end
247 end
248 end
249 chk and eq_all eq get g_cs_tk 2 59 152
250end
251
252fn test_analytic to void
253 fx_res 0 1 DL_U_BYTES T_SCALE
254 note 1. single binding
255 fx_ctl 0 1 0.1 0.05 2.0 10.0
256 g = ref_grad 5500.0 T_BUDGET T_SCALE 100.0 2.0
257 for i ulong 60
258 put g_est i 5500.0
259 put g_sd i 100.0
260 end
261 chk lt dl_fabs sub g 0.3 1e-12 100
262 chk_st run_seq 0 0 60 2 1 DL_OK 101
263 for t ulong 60
264 w = ref_closed 0.0 g 0.1 0.05 add t 1
265 chk lt dl_fabs sub get g_tr t w 1e-9 102
266 end
267 chk and gt get g_tr 59 get g_tr 0 and le get g_tr 59 add ref_fp g 0.1 0.05 1e-9 eq get g_cs_ls 2 DL_LS_FRESH 103
268 note 2. slack constraint
269 for i ulong 60
270 if lt i 20
271 put g_est i 5500.0
272 else
273 put g_est i 4000.0
274 end
275 put g_sd i 100.0
276 end
277 chk_st run_seq 0 0 60 2 1 DL_OK 104
278 chk and gt get g_tr 19 0.3 eq get g_cs_lam 2 0.0 105
279 i = ulong 20
280 while lt i 60
281 chk and le get g_tr i get g_tr sub i 1 ge get g_tr i 0.0 106
282 i = add i 1
283 end
284 note 3. two competing constraints
285 fx_res 1 1 DL_U_BYTES T_SCALE
286 fx_res 2 2 DL_U_BYTES T_SCALE
287 put g_ct_eta 1 0.2
288 put g_ct_rho 1 0.1
289 put g_ct_ks 1 1.0
290 put g_ct_age 1 4
291 put g_ct_cad 1 1
292 put g_ct_n 1 2
293 put g_ct_rid 32 1
294 put g_ct_rid 33 2
295 put g_ct_lm 32 5.0
296 put g_ct_lm 33 5.0
297 for k1 ulong 60
298 put g_est k1 6000.0
299 put g_sd k1 50.0
300 end
301 chk_st run_seq 1 1 60 2 1 DL_OK 107
302 gm = ref_grad 6000.0 T_BUDGET T_SCALE 50.0 1.0
303 chk lt dl_fabs sub get g_tr 59 ref_closed 0.0 gm 0.2 0.1 60 1e-9 108
304 for k2 ulong 60
305 put g_est k2 4900.0
306 put g_sd k2 50.0
307 end
308 chk_st run_seq 1 2 60 3 1 DL_OK 109
309 gl = ref_grad 4900.0 T_BUDGET T_SCALE 50.0 1.0
310 chk and lt gl 0.0 and eq get g_cs_lam 3 0.0 gt get g_cs_lam 2 1.0 110
311 note 4. inside deadband
312 fx_ctl 0 1 0.5 0.0 2.0 10.0
313 for k3 ulong 60
314 put g_est k3 5100.0
315 put g_sd k3 100.0
316 end
317 chk_st run_seq 0 0 60 2 1 DL_OK 111
318 for k4 ulong 60
319 chk eq get g_tr k4 0.0 112
320 end
321 test_analytic_2
322end
323
324fn test_states_refusals_2 to void
325 note structural refusals
326 fx_ctl 0 1 0.1 0.05 2.0 10.0
327 fx_res 0 1 DL_U_BYTES T_SCALE
328 fx_input 0 9000.0 100.0 2 1
329 fx_ctl 1 1 0.2 0.05 2.0 10.0
330 chk_st dl_update 0 0 0 1 2 1 DL_E_CTL 220
331 fx_ctl 1 2 0.1 0.05 2.0 10.0
332 chk_st dl_update 0 0 0 1 2 1 DL_E_RES 221
333 fx_res 1 1 DL_U_NS T_SCALE
334 chk_st dl_update 0 1 0 0 2 1 DL_E_UNIT 222
335 fx_res 1 3 DL_U_BYTES T_SCALE
336 chk_st dl_update 0 1 0 0 2 1 DL_E_RES 223
337 fx_res 1 1 DL_U_BYTES 0.0
338 chk_st dl_update 0 1 0 0 2 1 DL_E_SCALE 224
339 fx_res 1 1 DL_U_BYTES -1.0
340 chk_st dl_update 0 1 0 0 2 1 DL_E_SCALE 225
341 fx_input 1 9000.0 100.0 2 1
342 put g_in_u 1 DL_U_NS
343 chk_st dl_update 0 0 1 0 2 1 DL_E_UNIT 226
344 dl_cs_copy 3 0
345 put g_cs_cls 3 DL_CLS_INV
346 chk_st dl_update 3 0 0 0 2 1 DL_E_CLASS 227
347 dl_cs_copy 3 0
348 put g_cs_lam 3 11.0
349 chk_st dl_update 3 0 0 0 2 1 DL_E_RANGE 228
350 dl_cs_copy 3 0
351 put g_cs_lam 3 -1.0
352 chk_st dl_update 3 0 0 0 2 1 DL_E_RANGE 229
353 dl_cs_copy 3 0
354 dl_dg_fill ulong 3936 uchar 0x01
355 chk_st dl_update 3 0 0 0 2 1 DL_E_DIG 230
356 dl_cs_copy 3 0
357 dl_dg_clr ulong 3424
358 chk_st dl_update 3 0 0 0 2 1 DL_E_DIG 231
359 put g_dla 3 T_BUDGET
360 put g_dws 0 1
361 chk_st dl_init_state 0 DL_CLS_INV 0 0 0 1 DL_E_CLASS 232
362 put g_dws 0 1
363 chk_st dl_init_state 0 DL_CLS_UNDECL 0 0 0 1 DL_E_CLASS 233
364 put g_dla 3 bitcast f64 ulong 0x7ff0000000000000
365 put g_dws 0 1
366 chk_st dl_init_state 0 DL_CLS_SOFT 0 0 0 1 DL_E_NONFIN 234
367 put g_dla 3 T_BUDGET
368 dl_dg_clr ulong 32
369 put g_dws 0 1
370 chk_st dl_init_state 0 DL_CLS_SOFT 1 0 0 1 DL_E_DIG 235
371 fx_input 1 bitcast f64 ulong 0x7ff8000000000000 100.0 2 1
372 put g_dws 0 1
373 chk_st dl_init_state 0 DL_CLS_SOFT 0 1 0 1 DL_E_NONFIN 236
374 put g_dws 0 1
375 chk_st dl_init_state 0 DL_CLS_CAP 0 0 0 2 DL_OK 237
376 chk and eq get g_cs_cls 1 DL_CLS_CAP gt get g_cs_lam 1 0.0 238
377 put g_dla 0 10.0
378 chk_st dl_step_lambda 0.5 bitcast f64 ulong 0x7ff0000000000000 1.0 T_BUDGET T_SCALE 0 DL_E_NONFIN 239
379 put g_dla 0 10.0
380 chk_st dl_step_lambda 0.5 bitcast f64 or shl ulong 0xfff00000 32 ulong 0 1.0 T_BUDGET T_SCALE 0 DL_E_NONFIN 240
381 put g_dla 0 10.0
382 chk_st dl_step_lambda 0.5 1.0 1.0 T_BUDGET 0.0 0 DL_E_SCALE 241
383 put g_dla 0 10.0
384 chk_st dl_step_lambda 0.5 1.0 1.0 T_BUDGET -1.0 0 DL_E_SCALE 242
385 put g_dla 0 10.0
386 chk_st dl_step_lambda -0.5 1.0 1.0 T_BUDGET T_SCALE 0 DL_E_RANGE 243
387 put g_dla 0 10.0
388 chk_st dl_step_lambda 0.5 1.0 -1.0 T_BUDGET T_SCALE 0 DL_E_RANGE 244
389 put g_dla 0 10.0
390 chk_st dl_step_lambda 11.0 1.0 1.0 T_BUDGET T_SCALE 0 DL_E_RANGE 245
391 put g_dla 0 10.0
392 chk_st dl_step_lambda 0.5 1e308 1.0 -1e308 T_SCALE 0 DL_E_NONFIN 246
393end
394
395fn test_states_and_refusals to void
396 fx_ctl 0 1 0.1 0.05 2.0 10.0
397 fx_res 0 1 DL_U_BYTES T_SCALE
398 fx_input 0 5500.0 100.0 1 1
399 put g_dla 3 T_BUDGET
400 put g_dws 0 0
401 chk_st dl_init_state 0 DL_CLS_SOFT 0 0 0 1 DL_OK 200
402 chk and eq get g_cs_tk 0 0 and eq dl_dg_is_zero ulong 3840 1 and gt get g_cs_lam 0 0.0 eq get g_cs_ls 0 DL_LS_FRESH 201
403 chk_st dl_dig_constraint 0 ulong 64 DL_OK 202
404 fx_input 0 9000.0 100.0 2 1
405 put g_in_evv 0 0
406 chk_st dl_update 0 0 0 0 2 1 DL_OK 203
407 chk eq get g_cs_ls 1 DL_LS_STALE 204
408 chk eq get g_cs_lam 1 get g_cs_lam 0 204
409 chk eq get g_cs_est 1 get g_cs_est 0 204
410 chk eq get g_cs_gen 1 get g_cs_gen 0 204
411 chk and eq dl_dg_eq ulong 3872 ulong 64 1 and eq get g_cs_tk 1 1 eq dl_dg_eq ulong 3616 ulong 3584 1 205
412 fx_input 0 9000.0 100.0 2 1
413 chk_st dl_update 0 0 0 0 7 1 DL_OK 206
414 chk and eq get g_cs_ls 1 DL_LS_STALE eq get g_cs_lam 1 get g_cs_lam 0 207
415 fx_input 0 bitcast f64 ulong 0x7ff8000000000000 100.0 2 1
416 chk_st dl_update 0 0 0 0 2 1 DL_OK 208
417 chk and eq get g_cs_ls 1 DL_LS_REFUSED eq get g_cs_lam 1 get g_cs_lam 0 209
418 fx_input 0 9000.0 -1.0 2 1
419 chk_st dl_update 0 0 0 0 2 1 DL_OK 210
420 chk eq get g_cs_ls 1 DL_LS_REFUSED 211
421 fx_input 0 9000.0 100.0 5 1
422 chk_st dl_update 0 0 0 0 2 1 DL_OK 212
423 chk eq get g_cs_ls 1 DL_LS_REFUSED 213
424 fx_input 0 9000.0 100.0 2 1
425 put g_in_reg 0 1
426 chk_st dl_update 0 0 0 0 2 1 DL_OK 214
427 chk and eq get g_cs_ls 1 DL_LS_FROZEN eq get g_cs_lam 1 get g_cs_lam 0 215
428 fx_input 0 9000.0 100.0 2 0
429 chk_st dl_update 0 0 0 0 2 1 DL_OK 216
430 chk and eq get g_cs_ls 1 DL_LS_UNCAL gt get g_cs_lam 1 get g_cs_lam 0 217
431 fx_input 0 9000.0 100.0 3 1
432 chk_st dl_update 1 0 0 0 3 2 DL_OK 218
433 chk and eq get g_cs_ls 2 DL_LS_FRESH eq get g_cs_tk 2 2 219
434 test_states_refusals_2
435end
436
437fn test_prop_check_ns prev f64 nl f64 bgt f64 lmax f64 to void
438 g = ref_grad get g_in_est 0 bgt get g_rs_sc 0 get g_in_unc 0 get g_ct_ks 0
439 t1 = mul sub 1.0 get g_ct_rho 0 prev
440 t2 = mul get g_ct_eta 0 g
441 want = add t1 t2
442 if lt want 0.0
443 want = f64 0.0
444 end
445 if gt want lmax
446 want = lmax
447 end
448 chk le dl_fabs sub nl want mul 1e-9 add 1.0 dl_fabs want 304
449 if eq g 0.0
450 chk le nl prev 305
451 end
452 if eq get g_ct_eta 0 0.0
453 chk le nl prev 306
454 end
455end
456
457fn test_prop_step t ulong bgt f64 lmax f64 to void
458 prev = get g_cs_lam 0
459 cal = ulong 1
460 if eq rem trnd 5 0
461 cal = 0
462 end
463 fx_input 0 trdbl -1000000.0 1000000.0 trdbl 0.0 10000.0 t cal
464 if eq rem trnd 7 0
465 put g_in_evv 0 0
466 end
467 chk_st dl_update 0 0 0 0 t 1 DL_OK 301
468 nl = get g_cs_lam 1
469 chk and dl_fin nl and ge nl 0.0 and le nl lmax eq get g_cs_tk 1 sub t 1 302
470 if eq get g_cs_ls 1 DL_LS_STALE
471 chk eq nl prev 303
472 else
473 test_prop_check_ns prev nl bgt lmax
474 end
475 dl_cs_copy 0 1
476end
477
478fn test_properties to void
479 for r ulong 3000
480 fx_ctl 0 1 trdbl 0.0 2.0 trdbl 0.0 1.0 trdbl 0.0 4.0 trdbl 0.01 50.0
481 put g_ct_age 0 add 1 rem trnd 8
482 fx_res 0 1 DL_U_BYTES trdbl 0.001 1000000.0
483 fx_input 0 trdbl -1000000.0 1000000.0 trdbl 0.0 10000.0 1 1
484 bgt = trdbl -1000000.0 1000000.0
485 lmax = get g_ct_lm 0
486 put g_dla 3 bgt
487 put g_dws 0 0
488 chk_st dl_init_state 0 DL_CLS_SOFT 0 0 0 1 DL_OK 300
489 t = ulong 2
490 while le t 40
491 test_prop_step t bgt lmax
492 t = add t 1
493 end
494 end
495end
496
497fn main to long
498 put g_rng 0 or shl ulong 0xd1b54a32 32 ulong 0xd192ed03
499 dl_dg_fill ulong 0 uchar 0x22
500 test_analytic
501 test_states_and_refusals
502 test_properties
503 t_pr_txt t_str_2
504 t_pr_u64 get g_chk 0
505 t_pr_txt t_str_3
506 t_pr_u64 get g_fl 0
507 if eq get g_fl 0 0
508 t_pr_txt t_str_4
509 ret 0
510 end
511 t_pr_txt t_str_5
512 ret 1
513end