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
omega-mv / tests / dual / test_dual_bind.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | note |
| 4 | note tests/dual/test_dual_bind.om -- DUAL-0b binding and classification tests in pure seeded OM-2. |
| 5 | note Replaces tests/dual/test_dual_bind.c. |
| 6 | note Built by concatenating src/dual/rx_dual.om + tests/dual/test_dual_bind.om. |
| 7 | |
| 8 | text t_str_0 "FAIL test_dual_bind check=" |
| 9 | text t_str_1 "\n" |
| 10 | text t_str_2 "test_dual_bind: " |
| 11 | text t_str_3 " checks, " |
| 12 | text t_str_4 " failures: PASS\n" |
| 13 | text t_str_5 " failures: FAIL\n" |
| 14 | global g_chk ulong 1 |
| 15 | global g_fl ulong 1 |
| 16 | global g_out uchar 256 |
| 17 | |
| 18 | fn t_pr_txt s view uchar * to void |
| 19 | n = len s |
| 20 | for i ulong n |
| 21 | put g_out i get s i |
| 22 | end |
| 23 | _w = write 1 g_out 0 n |
| 24 | end |
| 25 | |
| 26 | fn t_pr_u64 v ulong to void |
| 27 | if eq v 0 |
| 28 | put g_out 0 uchar 48 |
| 29 | _w = write 1 g_out 0 1 |
| 30 | ret |
| 31 | end |
| 32 | n = ulong 0 |
| 33 | x = v |
| 34 | while gt x 0 |
| 35 | put g_out n uchar add 48 rem x 10 |
| 36 | x = div x 10 |
| 37 | n = add n 1 |
| 38 | end |
| 39 | i = ulong 0 |
| 40 | while lt i div n 2 |
| 41 | j = sub sub n 1 i |
| 42 | tmp = get g_out i |
| 43 | put g_out i get g_out j |
| 44 | put g_out j tmp |
| 45 | i = add i 1 |
| 46 | end |
| 47 | _w = write 1 g_out 0 n |
| 48 | end |
| 49 | |
| 50 | fn chk ok bool id ulong to void |
| 51 | put g_chk 0 add get g_chk 0 1 |
| 52 | if not ok |
| 53 | put g_fl 0 add get g_fl 0 1 |
| 54 | t_pr_txt t_str_0 |
| 55 | t_pr_u64 id |
| 56 | t_pr_txt t_str_1 |
| 57 | end |
| 58 | end |
| 59 | |
| 60 | fn chk_st got long want long id ulong to void |
| 61 | put g_chk 0 add get g_chk 0 1 |
| 62 | if ne got want |
| 63 | put g_fl 0 add get g_fl 0 1 |
| 64 | t_pr_txt t_str_0 |
| 65 | t_pr_u64 id |
| 66 | t_pr_txt t_str_1 |
| 67 | end |
| 68 | end |
| 69 | |
| 70 | fn fx_model s ulong u ulong to void |
| 71 | put g_dm_n s 1 |
| 72 | put g_dm_m s 1 |
| 73 | put g_dm_ek s 1 |
| 74 | put g_dm_mn s 1 |
| 75 | put g_dm_su mul s 8 u |
| 76 | put g_dm_ou mul s 8 u |
| 77 | bo = mul s 64 |
| 78 | put g_dm_F bo 1.0 |
| 79 | put g_dm_Q bo 0.01 |
| 80 | put g_dm_H bo 1.0 |
| 81 | put g_dm_R bo 0.04 |
| 82 | put g_dm_st s 1000 |
| 83 | end |
| 84 | |
| 85 | fn fx_obs s ulong u ulong z f64 vr f64 sq ulong to void |
| 86 | put g_do_m s 1 |
| 87 | put g_do_u mul s 8 u |
| 88 | put g_do_z mul s 8 z |
| 89 | put g_do_R mul s 64 vr |
| 90 | put g_do_tn s mul long sq 1000 |
| 91 | put g_do_sq s sq |
| 92 | dl_dg_fill add 13504 mul s 32 uchar 0x5a |
| 93 | dl_dg_fill add 13568 mul s 32 uchar add 0xe1 and sq 255 |
| 94 | end |
| 95 | |
| 96 | fn fx_belief bs ulong ms ulong os ulong u ulong x f64 vr f64 to void |
| 97 | put g_db_n bs 1 |
| 98 | put g_db_u mul bs 8 u |
| 99 | put g_db_x mul bs 8 x |
| 100 | put g_db_P mul bs 64 vr |
| 101 | off = mul bs 32 |
| 102 | _dm = de_digest_model ms add 13632 off |
| 103 | dl_dg_fill add 13696 off uchar 0x77 |
| 104 | _do = de_digest_obs os ulong 480 |
| 105 | _de = de_evroot_extend ulong 0 ulong 480 |
| 106 | dl_dg_cp add 13760 off ulong 896 |
| 107 | end |
| 108 | |
| 109 | fn fx_ctl s ulong id ulong eta f64 rho f64 ks f64 lmax f64 to void |
| 110 | put g_ct_eta s eta |
| 111 | put g_ct_rho s rho |
| 112 | put g_ct_ks s ks |
| 113 | put g_ct_age s 4 |
| 114 | put g_ct_cad s 1 |
| 115 | put g_ct_n s 1 |
| 116 | bo = mul s 32 |
| 117 | put g_ct_rid bo id |
| 118 | put g_ct_lm bo lmax |
| 119 | end |
| 120 | |
| 121 | fn fx_input ins ulong x f64 sd f64 gen ulong cal ulong to void |
| 122 | dl_in_clr ins |
| 123 | off = mul ins 32 |
| 124 | dl_dg_fill add 12992 off uchar add 0x30 and gen 0x3f |
| 125 | put g_in_ek ins DL_EK_EST |
| 126 | put g_in_u ins DL_U_BYTES |
| 127 | put g_in_est ins x |
| 128 | put g_in_unc ins sd |
| 129 | put g_in_gen ins gen |
| 130 | dl_dg_fill add 13248 off uchar 0x66 |
| 131 | put g_in_evv ins 1 |
| 132 | if ne cal 0 |
| 133 | dl_dg_fill add 13376 off uchar 0x44 |
| 134 | end |
| 135 | end |
| 136 | |
| 137 | fn test_units to void |
| 138 | chk eq dl_unit_from_est 6 DL_U_BYTES 100 |
| 139 | chk eq dl_unit_from_est 5 DL_U_NS 101 |
| 140 | chk eq dl_unit_from_est 3 DL_U_WATT 102 |
| 141 | chk eq dl_unit_from_est 8 DL_U_LOG2PS 103 |
| 142 | chk eq dl_unit_from_est 0 DL_U_NONE 104 |
| 143 | chk eq dl_unit_from_est 9 DL_U_NONE 105 |
| 144 | chk eq dl_unit_from_est 77 DL_U_NONE 106 |
| 145 | end |
| 146 | |
| 147 | fn test_bind_belief to void |
| 148 | fx_model 0 6 |
| 149 | fx_obs 0 6 5200.0 100.0 1 |
| 150 | dl_dg_clr ulong 0 |
| 151 | dl_dg_fill ulong 32 uchar 0x44 |
| 152 | fx_belief 0 0 0 6 5150.0 64.0 |
| 153 | put g_db_gn 0 7 |
| 154 | put g_db_tn 0 7000 |
| 155 | chk_st de_check_belief 0 0 200 |
| 156 | chk_st dl_bind_belief 0 0 1 1 0 DL_OK 201 |
| 157 | chk and eq get g_in_est 0 5150.0 and eq get g_in_unc 0 8.0 and eq get g_in_u 0 DL_U_BYTES eq get g_in_gen 0 7 202 |
| 158 | chk and eq get g_in_ek 0 DL_EK_EST and eq get g_in_evv 0 0 eq dl_dg_is_zero ulong 13120 1 203 |
| 159 | _db = de_digest_belief 0 ulong 64 |
| 160 | chk eq dl_dg_eq ulong 64 ulong 12992 1 204 |
| 161 | chk eq dl_dg_eq ulong 13248 ulong 13760 1 205 |
| 162 | chk_st dl_verify_belief_ev 0 0 0 0 DL_OK 206 |
| 163 | chk eq get g_in_evv 0 1 207 |
| 164 | note broken evidence root |
| 165 | b0 = get g_dig ulong 13763 |
| 166 | put g_dig ulong 13763 uchar xor ulong b0 1 |
| 167 | chk_st dl_bind_belief 0 0 1 1 1 DL_OK 208 |
| 168 | chk_st dl_verify_belief_ev 0 0 0 1 DL_E_EVID 209 |
| 169 | chk eq get g_in_evv 1 0 210 |
| 170 | put g_dig ulong 13763 b0 |
| 171 | note wrong obs |
| 172 | fx_obs 1 6 5200.0 100.0 2 |
| 173 | chk_st dl_bind_belief 0 0 1 1 1 DL_OK 211 |
| 174 | chk_st dl_verify_belief_ev 0 0 1 1 DL_E_EVID 212 |
| 175 | note wrong parent root |
| 176 | dl_dg_fill ulong 96 uchar 0x99 |
| 177 | chk_st dl_bind_belief 0 0 1 1 1 DL_OK 213 |
| 178 | chk_st dl_verify_belief_ev 0 3 0 1 DL_E_EVID 214 |
| 179 | note input not bound from belief |
| 180 | fx_input 1 1.0 1.0 7 1 |
| 181 | chk_st dl_verify_belief_ev 0 0 0 1 DL_E_DIG 215 |
| 182 | note refusals |
| 183 | chk_st dl_bind_belief 0 1 1 1 0 DL_E_RANGE 216 |
| 184 | put g_db_gn 0 0 |
| 185 | dl_dg_clr ulong 13696 |
| 186 | dl_dg_clr ulong 13760 |
| 187 | chk_st de_check_belief 0 0 217 |
| 188 | chk_st dl_bind_belief 0 0 1 1 0 DL_E_EVID 218 |
| 189 | fx_belief 0 0 0 6 5150.0 64.0 |
| 190 | put g_db_gn 0 7 |
| 191 | put g_db_x 0 bitcast f64 ulong 0x7ff8000000000000 |
| 192 | chk_st dl_bind_belief 0 0 1 1 0 DL_E_KIND 219 |
| 193 | put g_db_x 0 5150.0 |
| 194 | put g_db_u 0 0 |
| 195 | chk ne dl_bind_belief 0 0 1 1 0 DL_OK 220 |
| 196 | put g_db_u 0 6 |
| 197 | chk_st dl_bind_belief 0 0 0 0 0 DL_OK 221 |
| 198 | chk eq dl_dg_is_zero ulong 13376 1 222 |
| 199 | end |
| 200 | |
| 201 | fn test_bind_pred_obs to void |
| 202 | fx_model 0 5 |
| 203 | fx_obs 0 5 10.0 1.0 1 |
| 204 | dl_dg_clr ulong 0 |
| 205 | fx_belief 0 0 0 5 10.0 1.0 |
| 206 | put g_db_gn 0 3 |
| 207 | put g_db_tn 0 3000 |
| 208 | _d1 = de_digest_belief 0 ulong 13824 |
| 209 | _d2 = de_digest_model 0 ulong 13888 |
| 210 | put g_dp_hz 0 2 |
| 211 | put g_dp_gn 0 5 |
| 212 | put g_dp_tn 0 5000 |
| 213 | put g_dp_n 0 1 |
| 214 | put g_dp_m 0 1 |
| 215 | put g_dp_hc 0 0 |
| 216 | put g_dp_x 0 12.0 |
| 217 | put g_dp_P 0 2.25 |
| 218 | put g_dp_ym 0 12.0 |
| 219 | put g_dp_S 0 2.29 |
| 220 | chk_st de_check_pred 0 0 300 |
| 221 | chk_st dl_bind_prediction 0 0 0 0 99 0 DL_OK 301 |
| 222 | chk and eq get g_in_est 0 12.0 eq get g_in_unc 0 1.5 302 |
| 223 | chk and eq get g_in_u 0 DL_U_NS and eq get g_in_gen 0 5 eq get g_in_ek 0 DL_EK_PRED 302 |
| 224 | _d3 = de_digest_pred 0 ulong 64 |
| 225 | chk eq dl_dg_eq ulong 64 ulong 12992 1 303 |
| 226 | chk eq dl_dg_eq ulong 13248 ulong 13760 1 304 |
| 227 | fx_model 1 5 |
| 228 | put g_dm_Q 64 0.02 |
| 229 | chk_st dl_bind_prediction 0 1 0 0 99 0 DL_E_DIG 305 |
| 230 | fx_belief 1 0 0 5 11.0 1.0 |
| 231 | put g_db_gn 1 3 |
| 232 | put g_db_tn 1 3000 |
| 233 | chk_st dl_bind_prediction 0 0 1 0 99 0 DL_E_DIG 306 |
| 234 | chk_st dl_bind_prediction 0 0 0 1 99 0 DL_E_RANGE 307 |
| 235 | chk_st dl_bind_obs 0 0 9 0 0 0 DL_OK 308 |
| 236 | chk and eq get g_in_ek 0 DL_EK_MEAS eq get g_in_est 0 10.0 309 |
| 237 | chk and eq get g_in_unc 0 1.0 eq get g_in_gen 0 9 309 |
| 238 | chk and eq dl_dg_eq ulong 12992 ulong 13120 1 eq get g_in_evv 0 1 310 |
| 239 | chk eq dl_dg_eq ulong 13248 ulong 13568 1 311 |
| 240 | dl_dg_clr ulong 13568 |
| 241 | chk_st dl_bind_obs 0 0 9 0 0 0 DL_E_KIND 312 |
| 242 | fx_obs 0 5 10.0 1.0 1 |
| 243 | chk_st dl_bind_obs 0 3 9 0 0 0 DL_E_RANGE 313 |
| 244 | end |
| 245 | |
| 246 | fn test_classify to void |
| 247 | fx_ctl 0 1 0.1 0.01 2.0 10.0 |
| 248 | fx_input 0 5200.0 100.0 10 1 |
| 249 | put g_cs_id 0 1 |
| 250 | put g_cs_u 0 DL_U_BYTES |
| 251 | put g_cs_cls 0 DL_CLS_SOFT |
| 252 | put g_cs_bgt 0 5000.0 |
| 253 | dl_dg_fill ulong 2304 uchar 0x22 |
| 254 | dl_dg_clr ulong 2560 |
| 255 | dl_dg_fill ulong 2816 uchar 0x33 |
| 256 | put g_cs_ek 0 DL_EK_EST |
| 257 | put g_cs_est 0 5000.0 |
| 258 | put g_cs_unc 0 100.0 |
| 259 | dl_dg_fill ulong 3072 uchar 0x44 |
| 260 | put g_cs_lam 0 0.0 |
| 261 | put g_cs_ls 0 DL_LS_FRESH |
| 262 | dl_dg_fill ulong 3328 uchar 0x55 |
| 263 | put g_cs_gen 0 9 |
| 264 | put g_cs_tk 0 0 |
| 265 | dl_dg_fill ulong 3584 uchar 0x66 |
| 266 | dl_dg_clr ulong 3840 |
| 267 | chk_st dl_classify_input 0 1 0 0 10 DL_OK 400 |
| 268 | chk eq get g_dws 3 DL_LS_FRESH 401 |
| 269 | chk_st dl_classify_input 0 0 0 0 10 DL_OK 402 |
| 270 | chk eq get g_dws 3 DL_LS_FRESH 403 |
| 271 | dl_dg_clr ulong 13376 |
| 272 | chk_st dl_classify_input 0 1 0 0 10 DL_OK 404 |
| 273 | chk eq get g_dws 3 DL_LS_UNCAL 405 |
| 274 | fx_input 0 5200.0 100.0 10 1 |
| 275 | put g_in_reg 0 1 |
| 276 | chk_st dl_classify_input 0 1 0 0 10 DL_OK 406 |
| 277 | chk eq get g_dws 3 DL_LS_FROZEN 407 |
| 278 | put g_in_reg 0 0 |
| 279 | put g_in_evv 0 0 |
| 280 | chk_st dl_classify_input 0 1 0 0 10 DL_OK 408 |
| 281 | chk eq get g_dws 3 DL_LS_STALE 409 |
| 282 | put g_in_evv 0 1 |
| 283 | chk_st dl_classify_input 0 1 0 0 14 DL_OK 410 |
| 284 | chk eq get g_dws 3 DL_LS_FRESH 411 |
| 285 | chk_st dl_classify_input 0 1 0 0 15 DL_OK 412 |
| 286 | chk eq get g_dws 3 DL_LS_STALE 413 |
| 287 | put g_in_gen 0 8 |
| 288 | chk_st dl_classify_input 0 1 0 0 10 DL_OK 414 |
| 289 | chk eq get g_dws 3 DL_LS_STALE 415 |
| 290 | put g_in_gen 0 11 |
| 291 | chk_st dl_classify_input 0 1 0 0 10 DL_OK 416 |
| 292 | chk eq get g_dws 3 DL_LS_REFUSED 417 |
| 293 | put g_in_gen 0 10 |
| 294 | put g_in_est 0 bitcast f64 ulong 0x7ff8000000000000 |
| 295 | chk_st dl_classify_input 0 1 0 0 10 DL_OK 418 |
| 296 | chk eq get g_dws 3 DL_LS_REFUSED 419 |
| 297 | put g_in_est 0 bitcast f64 ulong 0x7ff0000000000000 |
| 298 | chk_st dl_classify_input 0 1 0 0 10 DL_OK 420 |
| 299 | chk eq get g_dws 3 DL_LS_REFUSED 421 |
| 300 | put g_in_est 0 5200.0 |
| 301 | put g_in_unc 0 -1.0 |
| 302 | chk_st dl_classify_input 0 1 0 0 10 DL_OK 422 |
| 303 | chk eq get g_dws 3 DL_LS_REFUSED 423 |
| 304 | put g_in_unc 0 100.0 |
| 305 | dl_dg_clr ulong 13248 |
| 306 | chk_st dl_classify_input 0 1 0 0 10 DL_OK 424 |
| 307 | chk eq get g_dws 3 DL_LS_REFUSED 425 |
| 308 | fx_input 0 5200.0 100.0 10 1 |
| 309 | put g_in_u 0 DL_U_NS |
| 310 | chk_st dl_classify_input 0 1 0 0 10 DL_E_UNIT 426 |
| 311 | put g_in_u 0 DL_U_BYTES |
| 312 | put g_cs_cls 0 DL_CLS_INV |
| 313 | chk_st dl_classify_input 0 1 0 0 10 DL_E_CLASS 427 |
| 314 | put g_cs_cls 0 DL_CLS_SOFT |
| 315 | put g_ct_age 0 0 |
| 316 | chk_st dl_classify_input 0 1 0 0 10 DL_E_RANGE 428 |
| 317 | dl_dg_clr ulong 0 |
| 318 | dl_dg_fill ulong 32 uchar 0x33 |
| 319 | chk_st dl_ev_extend ulong 0 ulong 32 DL_OK 429 |
| 320 | dl_dg_cp ulong 64 ulong 896 |
| 321 | chk_st dl_ev_extend ulong 64 ulong 32 DL_OK 430 |
| 322 | dl_dg_cp ulong 96 ulong 896 |
| 323 | chk_st dl_ev_extend ulong 0 ulong 32 DL_OK 431 |
| 324 | dl_dg_cp ulong 128 ulong 896 |
| 325 | chk and eq dl_dg_is_zero ulong 64 0 and eq dl_dg_eq ulong 64 ulong 96 0 eq dl_dg_eq ulong 64 ulong 128 1 432 |
| 326 | chk_st dl_ev_extend ulong 0 ulong 0 DL_E_DIG 433 |
| 327 | end |
| 328 | |
| 329 | fn main to long |
| 330 | test_units |
| 331 | test_bind_belief |
| 332 | test_bind_pred_obs |
| 333 | test_classify |
| 334 | t_pr_txt t_str_2 |
| 335 | t_pr_u64 get g_chk 0 |
| 336 | t_pr_txt t_str_3 |
| 337 | t_pr_u64 get g_fl 0 |
| 338 | if eq get g_fl 0 0 |
| 339 | t_pr_txt t_str_4 |
| 340 | ret 0 |
| 341 | end |
| 342 | t_pr_txt t_str_5 |
| 343 | ret 1 |
| 344 | end |