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/tests/brownian/test_brw_tps.om # 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 / tests / brownian / test_brw_tps.om` 610 lines ยท 14812 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 note 4 note tests/brownian/test_brw_tps.om -- Pure seeded OM-2 test suite for the 5 note TPS1 binariser (lane T, phases 1-2). Mirrors tests/brownian/test_brw_tps.c 6 note 100%, including streams A..I, phase 2 range+rANS coders, hostile #27 7 note tamper gates, frequency rows, and hostile input refusals. 8 9 global g_rs ulong 4 10 global g_fails ulong 1 11 global g_worst_ex f64 1 12 global g_env_lo f64 1 13 global g_env_hi f64 1 14 global g_quant_lo f64 1 15 global g_quant_hi f64 1 16 global g_files_dn ulong 1 17 global g_recs_dn ulong 1 18 global g_ext_low ulong 1 19 global g_out_buf uchar 1024 20 global g_out_len ulong 1 21 22 text t_pass "test_brw_tps: PASS\n" 23 text t_fail "test_brw_tps: FAIL\n" 24 text t_chkf "FAIL check #" 25 text t_nl "\n" 26 text t_sp " " 27 text t_rc " rc=" 28 text t_rec " records=" 29 text t_byt " bytes=" 30 text t_h27 "hostile #27 mode=" 31 text t_bad " bad_index=" 32 text t_p2 "phase 2: files=" 33 text t_ext " heavy-tails low=" 34 text t_sA "A mixed scales" 35 text t_sB "B centre and small offsets" 36 text t_sC "C far tails" 37 text t_sD "D sd at sd_min" 38 text t_sE "E huge sd" 39 text t_sF "F fractional bin position" 40 text t_sG "G sd_min offsets in bins" 41 text t_sH "H sd_min, z_c in sd units" 42 text t_sI "I y_prev predictor, N(0,1) steps" 43 text t_c1 "small" 44 text t_c2 "mixed scales" 45 text t_c3 "sharp near sd_min" 46 text t_c4 "heavy tails" 47 text t_c5 "large" 48 text t_rng " range" 49 text t_rns " rANS" 50 51 fn out_flush to void 52 n = get g_out_len 0 53 if gt n 0 54 k = write 1 g_out_buf 0 n 55 put g_out_len 0 0 56 end 57 end 58 59 fn out_ch c uchar to void 60 n = get g_out_len 0 61 if ge n 1020 62 out_flush 63 n = 0 64 end 65 put g_out_buf n c 66 put g_out_len 0 add n 1 67 end 68 69 fn out_txt s view uchar * to void 70 for i ulong len s bound 1024 71 out_ch get s i 72 end 73 end 74 75 fn out_u64 v ulong to void 76 tmp = new uchar 24 0 77 if eq v 0 78 out_ch 48 79 ret 80 end 81 k = ulong 0 82 x = v 83 while gt x 0 bound 24 84 put tmp k uchar add 48 rem x 10 85 x = div x 10 86 k = add k 1 87 end 88 while gt k 0 bound 24 89 k = sub k 1 90 out_ch get tmp k 91 end 92 end 93 94 fn out_i64 v long to void 95 if lt v 0 96 out_ch 45 97 out_u64 ulong sub 0 v 98 ret 99 end 100 out_u64 ulong v 101 end 102 103 fn chk cond bool id ulong to void 104 if not cond 105 put g_fails 0 add get g_fails 0 1 106 out_txt t_chkf 107 out_u64 id 108 out_txt t_nl 109 out_flush 110 end 111 end 112 113 note ---- xoshiro256** seeded via splitmix64 (bit-identical to C) ---- 114 fn sm_next x ulong to ulong 115 z = add x 0x9e3779b97f4a7c15 116 z = mul xor z shr z 30 0xbf58476d1ce4e5b9 117 z = mul xor z shr z 27 0x94d049bb133111eb 118 ret xor z shr z 31 119 end 120 121 fn rseed s ulong to void 122 x = s 123 for i ulong 4 124 x = add x 0x9e3779b97f4a7c15 125 z = mul xor x shr x 30 0xbf58476d1ce4e5b9 126 z = mul xor z shr z 27 0x94d049bb133111eb 127 put g_rs i xor z shr z 31 128 end 129 end 130 131 fn rnext to ulong 132 s0 = get g_rs 0 133 s1 = get g_rs 1 134 s2 = get g_rs 2 135 s3 = get g_rs 3 136 r = mul rotl mul s1 5 7 9 137 t = shl s1 17 138 s2 = xor s2 s0 139 s3 = xor s3 s1 140 s1 = xor s1 s2 141 s0 = xor s0 s3 142 s2 = xor s2 t 143 s3 = rotl s3 45 144 put g_rs 0 s0 145 put g_rs 1 s1 146 put g_rs 2 s2 147 put g_rs 3 s3 148 ret r 149 end 150 151 fn runif to f64 152 p53 = bitcast f64 shl ulong 0x3ca00000 32 153 ret mul f64 shr rnext 11 p53 154 end 155 156 fn rnorm to f64 157 u = runif 158 v = runif 159 minu = bitcast f64 or shl ulong 0x01c81f62 32 ulong 0x06410c2a 160 if lt u minu 161 u = minu 162 end 163 tp = bitcast f64 or shl ulong 0x401921fb 32 ulong 0x54442d18 164 ret mul fsqrt mul f64 -2.0 q_ln u q_cos mul tp v 165 end 166 167 fn fill_obs i ulong m f64 s f64 z f64 to void 168 put g_in_mu i m 169 put g_in_sd i s 170 put g_in_b i long q_floor mul add m mul z s f64 `1048576`.0 171 end 172 173 fn run_stream label view uchar * n ulong id ulong to void 174 rc = brw_tps_check_stream n 175 me = get g_tps_res 2 176 if gt me get g_worst_ex 0 177 put g_worst_ex 0 me 178 end 179 out_txt label 180 out_txt t_rc 181 out_i64 rc 182 out_txt t_nl 183 out_flush 184 chk eq rc 0 id 185 end 186 187 fn chk_decoded_eq to bool 188 pn = get g_ps_n 0 189 for t ulong pn bound `4194304` 190 if ne get g_ps_dec t get g_ps_sym t 191 ret false 192 end 193 end 194 ret true 195 end 196 197 fn code_check_env extreme ulong c ulong id_base ulong ideal f64 to void 198 pn = get g_ps_n 0 199 clen = get g_coded_len 0 200 dev = sub sub mul f64 8.0 f64 clen ideal f64 448.0 201 lim = add f64 64.0 mul f64 0.001 f64 pn 202 if ne extreme 0 203 chk le dev lim add id_base add 13 mul c 4 204 if lt dev sub f64 0.0 lim 205 put g_ext_low 0 add get g_ext_low 0 1 206 end 207 else 208 chk le q_fabs dev lim add id_base add 13 mul c 4 209 if lt dev get g_env_lo 0 210 put g_env_lo 0 dev 211 end 212 if gt dev get g_env_hi 0 213 put g_env_hi 0 dev 214 end 215 end 216 end 217 218 fn code_one_coder label view uchar * extreme ulong c ulong id_base ulong ideal f64 to void 219 rc = long 0 220 if eq c 0 221 rc = tc_range_encode 222 else 223 rc = tc_rans_encode 224 end 225 chk eq rc TC_OK add id_base add 10 mul c 4 226 if ne rc TC_OK 227 ret 228 end 229 if eq c 0 230 rc = tc_range_decode 231 else 232 rc = tc_rans_decode 233 end 234 chk eq rc TC_OK add id_base add 11 mul c 4 235 if eq rc TC_OK 236 chk chk_decoded_eq add id_base add 12 mul c 4 237 end 238 code_check_env extreme c id_base ideal 239 out_txt label 240 if eq c 0 241 out_txt t_rng 242 else 243 out_txt t_rns 244 end 245 out_txt t_rec 246 out_u64 get g_ps_n 0 247 out_txt t_byt 248 out_u64 get g_coded_len 0 249 out_txt t_nl 250 out_flush 251 end 252 253 fn code_file label view uchar * nobs ulong extreme ulong id_base ulong to void 254 rc = brw_tps_build nobs -1 0 f64 0.0 255 chk eq rc 0 id_base 256 if ne rc 0 257 ret 258 end 259 chk eq tc_ps_check_rows TC_OK add id_base 1 260 chk eq tc_ps_serialize_hash TC_OK add id_base 2 261 chk eq tc_sy_serialize_hash TC_OK add id_base 3 262 chk eq tc_pair_check TC_OK add id_base 4 263 chk eq tc_ideal_ub TC_OK add id_base 5 264 pn = get g_ps_n 0 265 ideal = div f64 get g_ub_out 0 f64 `1000000`.0 266 exact = f64 0.0 267 for i ulong nobs bound 100000 268 r2 = tps_bin_idx i 269 chk eq r2 0 add id_base 6 270 exact = add exact get g_tps_be 0 271 end 272 qd = div sub ideal exact f64 pn 273 if ne extreme 0 274 chk lt qd f64 0.0 add id_base 7 275 else 276 chk lt q_fabs qd f64 0.0001 add id_base 7 277 end 278 if lt qd get g_quant_lo 0 279 put g_quant_lo 0 qd 280 end 281 if gt qd get g_quant_hi 0 282 put g_quant_hi 0 qd 283 end 284 code_one_coder label extreme 0 id_base ideal 285 code_one_coder label extreme 1 id_base ideal 286 put g_files_dn 0 add get g_files_dn 0 1 287 put g_recs_dn 0 add get g_recs_dn 0 pn 288 end 289 290 fn hostile_gate to void 291 nobs = ulong 200 292 for i ulong nobs 293 fill_obs i mul f64 5.0 sub runif f64 0.5 add f64 0.05 mul f64 2.0 runif rnorm 294 end 295 chk eq brw_tps_build nobs -1 0 f64 0.0 0 800 296 chk le get g_tps_res 0 tps_exact_tol 801 297 rels = new f64 3 0.0 298 put rels 0 f64 0.001 299 put rels 1 f64 0.00001 300 put rels 2 f64 0.`0000001` 301 for mode ulong 2 302 for r ulong 3 303 rv = get rels r 304 rc = brw_tps_build nobs long mode 37 rv 305 out_txt t_h27 306 out_u64 mode 307 out_txt t_rc 308 out_i64 rc 309 out_txt t_bad 310 out_u64 get g_tps_bad 0 311 out_txt t_nl 312 out_flush 313 base = add 810 add mul mode 12 mul r 3 314 chk eq rc BRW_TPS_E_PROOF base 315 chk eq get g_tps_bad 0 37 add base 1 316 chk eq get g_ps_alloc 0 0 add base 2 317 end 318 end 319 chk eq brw_tps_check_stream nobs 0 850 320 end 321 322 fn coder_tests to void 323 rseed 0xfeedfacecafebeef 324 for i ulong 40 325 fill_obs i mul f64 3.0 sub runif f64 0.5 add f64 0.1 runif rnorm 326 end 327 code_file t_c1 40 0 500 328 for i ulong 3000 329 fill_obs i mul f64 200.0 sub runif f64 0.5 mul f64 0.05 q_exp mul f64 6.0 runif rnorm 330 end 331 code_file t_c2 3000 0 520 332 for i ulong 3000 333 fill_obs i mul f64 2.0 sub runif f64 0.5 mul q_sd_min add f64 1.0 mul f64 3.0 runif rnorm 334 end 335 code_file t_c3 3000 0 540 336 for i ulong 3000 337 sgn = f64 -1.0 338 if ne and i 1 0 339 sgn = f64 1.0 340 end 341 fill_obs i mul f64 10.0 sub runif f64 0.5 add f64 0.1 runif mul add f64 5.0 mul f64 25.0 runif sgn 342 end 343 code_file t_c4 3000 1 560 344 for i ulong 60000 345 fill_obs i mul f64 200.0 sub runif f64 0.5 mul f64 0.05 q_exp mul f64 6.0 runif rnorm 346 end 347 code_file t_c5 60000 0 580 348 out_txt t_p2 349 out_u64 get g_files_dn 0 350 out_txt t_rec 351 out_u64 get g_recs_dn 0 352 out_txt t_ext 353 out_u64 get g_ext_low 0 354 out_txt t_nl 355 out_flush 356 chk eq get g_files_dn 0 5 600 357 hostile_gate 358 end 359 360 fn test_streams_a_to_d to void 361 for i ulong 40000 362 s = mul f64 0.05 q_exp mul f64 6.0 runif 363 fill_obs i mul f64 200.0 sub runif f64 0.5 s rnorm 364 end 365 run_stream t_sA 40000 10 366 367 d20 = q_delta 368 for i ulong 20000 369 s = add f64 0.02 runif 370 m = mul f64 long mul sub runif f64 0.5 f64 200000.0 d20 371 if ne and i 1 0 372 m = add m mul f64 0.5 d20 373 end 374 put g_in_mu i m 375 put g_in_sd i s 376 c = long q_floor mul m f64 `1048576`.0 377 put g_in_b i sub add c long rem rnext 9 4 378 end 379 run_stream t_sB 20000 20 380 381 for i ulong 10000 382 sgn = f64 -1.0 383 if ne and i 1 0 384 sgn = f64 1.0 385 end 386 z = mul add f64 20.0 mul f64 20.0 runif sgn 387 fill_obs i mul f64 10.0 sub runif f64 0.5 add f64 0.1 mul f64 3.0 runif z 388 end 389 put g_in_mu 0 f64 0.0 390 put g_in_sd 0 f64 1.0 391 put g_in_b 0 long mul f64 40.0 f64 `1048576`.0 392 run_stream t_sC 10000 30 393 394 for i ulong 10000 395 r3 = rem i 3 396 s = q_sd_min 397 if eq r3 1 398 s = mul q_sd_min f64 0.25 399 else 400 if eq r3 2 401 s = mul q_sd_min add f64 1.0 runif 402 end 403 end 404 fill_obs i mul f64 4.0 sub runif f64 0.5 s mul f64 2.0 rnorm 405 end 406 run_stream t_sD 10000 40 407 chk eq brw_tps_check_stream 10000 0 41 408 chk gt get g_tps_res 1 tps_exact_tol 42 409 end 410 411 fn fill_g_row n0 ulong sg long off long frv f64 to ulong 412 n = n0 413 for m ulong 4 414 rv = sub long rem rnext `2000001` `1000000` 415 mm = add mul add f64 rv frv q_delta mul f64 m f64 0.37 416 put g_in_mu n mm 417 put g_in_sd n q_sd_min 418 put g_in_b n add long q_floor mul mm f64 `1048576`.0 mul sg off 419 n = add n 1 420 end 421 ret n 422 end 423 424 fn test_stream_g to void 425 offs = new long 7 0 426 put offs 0 0 427 put offs 1 1 428 put offs 2 5 429 put offs 3 30 430 put offs 4 1448 431 put offs 5 2048 432 put offs 6 4096 433 fr = new f64 5 0.0 434 put fr 0 f64 0.0 435 put fr 1 f64 0.25 436 put fr 2 f64 0.5 437 put fr 3 f64 0.75 438 put fr 4 f64 0.999 439 n = ulong 0 440 for o ulong 7 441 ov = get offs o 442 for fi ulong 5 443 fv = get fr fi 444 n = fill_g_row n -1 ov fv 445 n = fill_g_row n 1 ov fv 446 end 447 end 448 run_stream t_sG n 50 449 end 450 451 fn fill_h_row n0 ulong sg long zv f64 frv f64 to ulong 452 n = n0 453 off = mul sg long mul zv f64 1024.0 454 for m ulong 5 455 rv = sub long rem rnext 200001 100000 456 mm = add mul f64 rv q_sd_min mul frv q_delta 457 put g_in_mu n mm 458 put g_in_sd n q_sd_min 459 b0 = long q_floor mul mm f64 `1048576`.0 460 put g_in_b n add add b0 off long m 461 n = add n 1 462 end 463 ret n 464 end 465 466 fn test_stream_h to void 467 zs = new f64 7 0.0 468 put zs 0 f64 0.0 469 put zs 1 f64 1.0 470 put zs 2 f64 5.0 471 put zs 3 f64 30.0 472 put zs 4 f64 1448.0 473 put zs 5 f64 2048.0 474 put zs 6 f64 4096.0 475 frh = new f64 4 0.0 476 put frh 0 f64 0.0 477 put frh 1 f64 0.3 478 put frh 2 f64 0.5 479 put frh 3 f64 0.9 480 n = ulong 0 481 for o ulong 7 482 zv = get zs o 483 for fi ulong 4 484 fv = get frh fi 485 n = fill_h_row n -1 zv fv 486 n = fill_h_row n 1 zv fv 487 end 488 end 489 run_stream t_sH n 60 490 end 491 492 fn test_stream_i to void 493 y = f64 0.0 494 for i ulong 3000 495 y2 = add y rnorm 496 put g_in_mu i y 497 put g_in_sd i q_sd_min 498 put g_in_b i long q_floor mul y2 f64 `1048576`.0 499 y = y2 500 end 501 run_stream t_sI 3000 70 502 end 503 504 fn test_streams_g_h_i to void 505 test_stream_g 506 test_stream_h 507 test_stream_i 508 end 509 510 fn test_limits_e_f_hostile to void 511 lim = sub shl long 1 51 1 512 chk eq brw_tps_binarise f64 0.0 q_sd_min lim BRW_TPS_MAX_STEPS 0 100 513 chk eq brw_tps_binarise f64 0.0 q_sd_min sub 0 lim BRW_TPS_MAX_STEPS 0 101 514 chk lt brw_tps_binarise f64 0.0 q_sd_min add lim 1 BRW_TPS_MAX_STEPS 0 102 515 chk eq brw_tps_binarise f64 `2147483647`.0 q_sd_min sub 0 lim BRW_TPS_MAX_STEPS 0 103 516 chk eq brw_tps_binarise f64 -`2147483647`.0 q_sd_min lim BRW_TPS_MAX_STEPS 0 104 517 518 for i ulong 10000 519 s = mul f64 `1000000000`.0 add f64 1.0 runif 520 if ne and i 1 0 521 s = f64 `1000000`.0 522 end 523 fill_obs i mul f64 10000.0 sub runif f64 0.5 s rnorm 524 if ge q_fabs add get g_in_mu i mul f64 5.0 s f64 `1073741824`.0 525 fill_obs i get g_in_mu i s mul f64 0.2 rnorm 526 end 527 if gt get g_in_b i lim 528 put g_in_b i lim 529 end 530 if lt get g_in_b i sub 0 lim 531 put g_in_b i sub 0 lim 532 end 533 end 534 run_stream t_sE 10000 110 535 536 for i ulong 10000 537 s = add f64 0.01 mul f64 5.0 runif 538 frac = div f64 rem rnext 1000 f64 1000.0 539 m = mul add f64 long mul sub runif f64 0.5 f64 `1000000`.0 frac q_delta 540 put g_in_mu i m 541 put g_in_sd i s 542 put g_in_b i add long q_floor mul m f64 `1048576`.0 long mul mul rnorm s f64 `1048576`.0 543 end 544 run_stream t_sF 10000 120 545 546 ps = new f64 6 0.0 547 put ps 0 f64 0.0 548 put ps 1 bitcast f64 or shl ulong 0x01c81f62 32 ulong 0x06410c2a 549 put ps 2 f64 0.000005 550 put ps 3 f64 0.5 551 put ps 4 sub f64 1.0 f64 0.`000000001` 552 put ps 5 f64 1.0 553 for i ulong 6 554 chk eq brw_tps_p1_to_freq get ps i 0 add 130 mul i 2 555 f0 = ulong get g_tps_fq 0 556 f1 = ulong get g_tps_fq 1 557 chk and ge f0 1 and ge f1 1 eq add f0 f1 65536 add 131 mul i 2 558 end 559 chk lt brw_tps_p1_to_freq q_nan 0 150 560 561 bigv = shl long 1 51 562 i64_max = bitcast long or shl ulong 0x7fffffff 32 ulong 0xffffffff 563 i64_min = bitcast long shl ulong 0x80000000 32 564 e300 = bitcast f64 or shl ulong 0x7e37e43c 32 ulong 0x8800759c 565 chk lt brw_tps_binarise q_nan f64 1.0 0 BRW_TPS_MAX_STEPS 0 200 566 chk lt brw_tps_binarise f64 0.0 q_nan 0 BRW_TPS_MAX_STEPS 0 201 567 chk lt brw_tps_binarise f64 0.0 f64 0.0 0 BRW_TPS_MAX_STEPS 0 202 568 chk lt brw_tps_binarise f64 0.0 f64 -1.0 0 BRW_TPS_MAX_STEPS 0 203 569 chk lt brw_tps_binarise f64 0.0 q_inf 0 BRW_TPS_MAX_STEPS 0 204 570 chk lt brw_tps_binarise q_inf f64 1.0 0 BRW_TPS_MAX_STEPS 0 205 571 chk lt brw_tps_binarise e300 f64 1.0 0 BRW_TPS_MAX_STEPS 0 206 572 chk lt brw_tps_binarise f64 0.0 f64 1.0 bigv BRW_TPS_MAX_STEPS 0 207 573 chk lt brw_tps_binarise f64 0.0 f64 1.0 sub 0 bigv BRW_TPS_MAX_STEPS 0 208 574 chk lt brw_tps_binarise f64 0.0 f64 1.0 i64_min BRW_TPS_MAX_STEPS 0 209 575 chk lt brw_tps_binarise f64 0.0 f64 1.0 i64_max BRW_TPS_MAX_STEPS 0 210 576 chk lt brw_tps_binarise f64 0.0 f64 1.0 5000 2 0 211 577 put g_in_mu 0 q_nan 578 put g_in_sd 0 f64 1.0 579 put g_in_b 0 0 580 chk lt brw_tps_check_stream 1 0 212 581 end 582 583 fn main to int 584 put g_fails 0 0 585 put g_worst_ex 0 tps_big_neg 586 put g_env_lo 0 sub f64 0.0 tps_big_neg 587 put g_env_hi 0 tps_big_neg 588 put g_quant_lo 0 sub f64 0.0 tps_big_neg 589 put g_quant_hi 0 tps_big_neg 590 put g_files_dn 0 0 591 put g_recs_dn 0 0 592 put g_ext_low 0 0 593 rseed 0x0123456789abcdef 594 595 test_streams_a_to_d 596 test_streams_g_h_i 597 test_limits_e_f_hostile 598 coder_tests 599 600 chk le get g_worst_ex 0 tps_exact_tol 900 601 602 if ne get g_fails 0 0 603 out_txt t_fail 604 out_flush 605 ret 1 606 end 607 out_txt t_pass 608 out_flush 609 ret 0 610 end