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/reservoir/test_reservoir.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 / reservoir / test_reservoir.om` 2043 lines · 55324 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 Pure seeded OM-2 Gate 1 test suite for src/reservoir/reservoir.om. 5 note Replaces tests/reservoir/test_reservoir.c, res_oracle64.{c,h}, res_fixtures.h. 6 note Concatenated after src/reservoir/reservoir.om (which supplies the om2 header). 7 8 text tr_hdr "test_reservoir: " 9 text tr_chks " checks, " 10 text tr_fld " failed\n" 11 text tr_pass "test_reservoir: PASS\n" 12 text tr_fail "test_reservoir: FAIL\n" 13 text tr_fail_pfx "FAIL test_reservoir check #" 14 text tr_nl "\n" 15 text tr_orc_ok "oracle scenario OK\n" 16 17 global tr_checks ulong 1 18 global tr_fail_cnt ulong 1 19 global tr_rng ulong 1 20 21 global tr_ws uint 3564 22 global tr_cfg uint 5363 23 global tr_cfg2 uint 5363 24 global tr_s uint 932 25 global tr_s2 uint 932 26 global tr_tab f32 262144 27 global tr_vref f64 262144 28 global tr_vtight f64 262144 29 global tr_rws ulong 67334 30 31 note Binary64 oracle globals (res_oracle64) 32 global o64_n ulong 1 33 global o64_ne ulong 1 34 global o64_m ulong 1 35 global o64_a ulong 192 36 global o64_b ulong 192 37 global o64_unk long 64 38 global o64_unk_node ulong 64 39 global o64_lu f64 4096 40 global o64_piv ulong 64 41 global o64_par f64 5 42 global o64_c f64 64 43 global o64_tau0 f64 64 44 global o64_vtau f64 64 45 global o64_ve f64 64 46 global o64_y f64 448 47 global o64_yn f64 448 48 global o64_yt f64 448 49 global o64_k f64 3136 50 global o64_cur f64 64 51 global o64_B f64 64 52 global o64_x f64 64 53 global o64_ninit f64 384 54 55 note ================================================================ 56 note Printing & Check helpers 57 note ================================================================ 58 59 fn tr_wstr s view uchar * to void 60 _w = write 1 s 0 len s 61 end 62 63 fn tr_wu64 fd int v ulong to void 64 buf = new uchar 24 0 65 if eq v 0 66 put buf 0 uchar 48 67 _w = write fd buf 0 1 68 ret 69 end 70 x = v 71 n = ulong 0 72 while gt x 0 bound 24 73 put buf n uchar add 48 rem x 10 74 x = div x 10 75 n = add n 1 76 end 77 rev = new uchar 24 0 78 for i ulong n bound 24 79 put rev i get buf sub sub n 1 i 80 end 81 _w = write fd rev 0 n 82 end 83 84 fn tr_check ok bool to void 85 c = add get tr_checks 0 1 86 put tr_checks 0 c 87 if not ok 88 put tr_fail_cnt 0 add get tr_fail_cnt 0 1 89 _w1 = write 2 tr_fail_pfx 0 len tr_fail_pfx 90 tr_wu64 2 c 91 _w2 = write 2 tr_nl 0 1 92 end 93 end 94 95 fn tr_abs64 x f64 to f64 96 if lt x 0.0f64 97 ret neg x 98 end 99 ret x 100 end 101 102 fn tr_max64 a f64 b f64 to f64 103 if gt a b 104 ret a 105 end 106 ret b 107 end 108 109 fn tr_min64 a f64 b f64 to f64 110 if lt a b 111 ret a 112 end 113 ret b 114 end 115 116 fn tr_near a f64 b f64 rel f64 to void 117 d = tr_abs64 sub a b 118 s = tr_max64 tr_abs64 b 1.0e-300f64 119 tr_check le d mul rel s 120 end 121 122 fn tr_nearabs a f64 b f64 ab f64 to void 123 tr_check le tr_abs64 sub a b ab 124 end 125 126 note ================================================================ 127 note Pure OM-2 binary64 math: exp64, log64, pow64, sin64, nextafterf32 128 note ================================================================ 129 130 fn tr_exp64 x f64 to f64 131 if not res_fin64 bitcast ulong x 132 if gt x 0.0f64 133 ret x 134 end 135 ret 0.0f64 136 end 137 if lt x -745.0f64 138 ret 0.0f64 139 end 140 if gt x 709.78f64 141 ret bitcast f64 ulong 0x7ff0000000000000 142 end 143 inv_ln2 = 1.`4426950408889634f64` 144 ln2_hi = 0.`6931471803691238f64` 145 ln2_lo = 1.`9082149292705877e`-10f64 146 prod = mul x inv_ln2 147 k = long 0 148 if ge prod 0.0f64 149 k = long add prod 0.5f64 150 else 151 k = long sub prod 0.5f64 152 end 153 fk = f64 k 154 r = sub sub x mul fk ln2_hi mul fk ln2_lo 155 p = div 1.0f64 `39916800`.0f64 156 p = add div 1.0f64 `3628800`.0f64 mul r p 157 p = add div 1.0f64 362880.0f64 mul r p 158 p = add div 1.0f64 40320.0f64 mul r p 159 p = add div 1.0f64 5040.0f64 mul r p 160 p = add div 1.0f64 720.0f64 mul r p 161 p = add div 1.0f64 120.0f64 mul r p 162 p = add div 1.0f64 24.0f64 mul r p 163 p = add div 1.0f64 6.0f64 mul r p 164 p = add 0.5f64 mul r p 165 p = add 1.0f64 mul r p 166 poly = add 1.0f64 mul r p 167 if gt k 1023 168 s1 = bitcast f64 shl ulong 2046 52 169 s2 = bitcast f64 shl ulong add sub k 1023 1023 52 170 ret mul mul poly s1 s2 171 end 172 if lt k -1022 173 s1 = bitcast f64 shl ulong add add k 512 1023 52 174 s2 = bitcast f64 shl ulong 511 52 175 ret mul mul poly s1 s2 176 end 177 ret mul poly bitcast f64 shl ulong add k 1023 52 178 end 179 180 fn tr_log64 x f64 to f64 181 if or not res_fin64 bitcast ulong x le x 0.0f64 182 ret bitcast f64 ulong 0x7ff8000000000000 183 end 184 u = bitcast ulong x 185 e = sub long and shr u 52 0x7ff 1023 186 m = bitcast f64 or and u 0x000fffffffffffff 0x3ff0000000000000 187 if gt m 1.`4142135623730951f64` 188 m = mul m 0.5f64 189 e = add e 1 190 end 191 z = div sub m 1.0f64 add m 1.0f64 192 z2 = mul z z 193 p = div 1.0f64 15.0f64 194 p = add div 1.0f64 13.0f64 mul z2 p 195 p = add div 1.0f64 11.0f64 mul z2 p 196 p = add div 1.0f64 9.0f64 mul z2 p 197 p = add div 1.0f64 7.0f64 mul z2 p 198 p = add div 1.0f64 5.0f64 mul z2 p 199 p = add div 1.0f64 3.0f64 mul z2 p 200 p = add 1.0f64 mul z2 p 201 lnm = mul mul 2.0f64 z p 202 ret add mul f64 e 0.`6931471805599453f64` lnm 203 end 204 205 fn tr_pow64 a f64 b f64 to f64 206 if le a 0.0f64 207 ret 0.0f64 208 end 209 ret tr_exp64 mul b tr_log64 a 210 end 211 212 fn tr_sin64_exact x f64 to f64 213 twopi = 6.`283185307179586f64` 214 pi = 3.`141592653589793f64` 215 q = div x twopi 216 k = long 0 217 if ge q 0.0f64 218 k = long add q 0.5f64 219 else 220 k = long sub q 0.5f64 221 end 222 r = sub x mul f64 k twopi 223 if gt r 1.`5707963267948966f64` 224 r = sub pi r 225 else 226 if lt r -1.`5707963267948966f64` 227 r = sub neg pi r 228 end 229 end 230 r2 = mul r r 231 p = div 1.0f64 `6227020800`.0f64 232 p = add div -1.0f64 `39916800`.0f64 mul r2 p 233 p = add div 1.0f64 362880.0f64 mul r2 p 234 p = add div -1.0f64 5040.0f64 mul r2 p 235 p = add div 1.0f64 120.0f64 mul r2 p 236 p = add div -1.0f64 6.0f64 mul r2 p 237 p = add 1.0f64 mul r2 p 238 ret mul r p 239 end 240 241 fn tr_nextafter_up f f32 to f32 242 u = bitcast uint f 243 if eq and u 0x7fffffff 0 244 ret bitcast f32 uint 1 245 end 246 if lt f 0.0f32 247 ret bitcast f32 sub u 1 248 end 249 ret bitcast f32 add u 1 250 end 251 252 fn tr_rnd to ulong 253 s = get tr_rng 0 254 s = xor s shr s 12 255 s = xor s shl s 25 256 s = xor s shr s 27 257 put tr_rng 0 s 258 c = or shl ulong 0x2545f491 32 ulong 0x4f6cdd1d 259 ret mul s c 260 end 261 262 fn tr_runit to f64 263 ret div f64 shr tr_rnd 11 `9007199254740992`.0f64 264 end 265 266 note ================================================================ 267 note Reference fixtures (res_fixtures.h) 268 note ================================================================ 269 270 global fx_nb uint 301 271 global fx_e uint 384 272 273 fn fx_add_row row ulong cnt ulong n1 uint n2 uint n3 uint n4 uint to void 274 b = mul row 7 275 put fx_nb b uint cnt 276 put fx_nb add b 1 n1 277 put fx_nb add b 2 n2 278 put fx_nb add b 3 n3 279 put fx_nb add b 4 n4 280 end 281 282 fn fx_add_row6 row ulong n5 uint n6 uint to void 283 b = mul row 7 284 put fx_nb add b 5 n5 285 put fx_nb add b 6 n6 286 end 287 288 fn fx_add_edge_unique m ulong a uint b uint to ulong 289 lo = a 290 hi = b 291 if gt a b 292 lo = b 293 hi = a 294 end 295 for q ulong m bound 192 296 if eq get fx_e mul q 2 lo 297 if eq get fx_e add mul q 2 1 hi 298 ret m 299 end 300 end 301 end 302 put fx_e mul m 2 lo 303 put fx_e add mul m 2 1 hi 304 ret add m 1 305 end 306 307 fn fx_collect_row i ulong m ulong to ulong 308 cnt = ulong get fx_nb mul i 7 309 mm = m 310 for k ulong cnt bound 6 311 nb1 = get fx_nb add mul i 7 add k 1 312 mm = fx_add_edge_unique mm uint i sub nb1 1 313 end 314 ret mm 315 end 316 317 fn fx_build_from_nb n ulong ground1 uint out_t edit uint 514 to int 318 m = ulong 0 319 for i ulong n bound 64 320 m = fx_collect_row i m 321 end 322 eloc = new uint 384 0 323 for i ulong mul m 2 bound 384 324 put eloc i get fx_e i 325 end 326 g = new uint 1 0 327 put g 0 sub ground1 1 328 tm = new uint 3 0 329 put tm 0 uint n 330 put tm 1 uint m 331 put tm 2 1 332 ret res_topology_build view tm view eloc view g out_t 333 end 334 335 fn fx_hex13 out_t edit uint 514 to int 336 for i ulong 91 bound 91 337 put fx_nb i 0 338 end 339 fx_add_row 0 1 3 0 0 0 340 fx_add_row 1 1 6 0 0 0 341 fx_add_row 2 3 1 4 7 0 342 fx_add_row 3 4 3 5 7 8 343 fx_add_row 4 4 4 8 9 6 344 fx_add_row 5 3 2 5 9 0 345 fx_add_row 6 4 3 4 8 10 346 fx_add_row 7 6 4 5 7 9 347 fx_add_row6 7 10 11 348 fx_add_row 8 4 5 6 8 11 349 fx_add_row 9 4 7 8 11 12 350 fx_add_row 10 4 8 9 10 12 351 fx_add_row 11 3 10 11 13 0 352 fx_add_row 12 1 12 0 0 0 353 ret fx_build_from_nb 13 8 out_t 354 end 355 356 fn fx_hex25 out_t edit uint 514 to int 357 for i ulong 175 bound 175 358 put fx_nb i 0 359 end 360 fx_add_row 0 1 3 0 0 0 361 fx_add_row 1 1 7 0 0 0 362 fx_add_row 2 3 1 4 8 0 363 fx_add_row 3 4 3 5 8 9 364 fx_add_row 4 4 4 6 9 10 365 fx_add_row 5 4 5 7 10 11 366 fx_add_row 6 3 2 6 11 0 367 fx_add_row 7 5 3 4 9 12 368 fx_add_row6 7 13 0 369 fx_add_row 8 6 4 5 8 10 370 fx_add_row6 8 13 14 371 fx_add_row 9 6 5 6 9 11 372 fx_add_row6 9 14 15 373 fx_add_row 10 5 6 7 10 15 374 fx_add_row6 10 16 0 375 fx_add_row 11 3 8 13 17 0 376 fx_add_row 12 6 8 9 12 14 377 fx_add_row6 12 17 18 378 fx_add_row 13 6 9 10 13 15 379 fx_add_row6 13 18 19 380 fx_add_row 14 6 10 11 14 16 381 fx_add_row6 14 19 20 382 fx_add_row 15 2 15 20 0 0 383 fx_add_row 16 4 12 13 18 21 384 fx_add_row 17 6 13 14 17 19 385 fx_add_row6 17 21 22 386 fx_add_row 18 6 14 15 18 20 387 fx_add_row6 18 22 23 388 fx_add_row 19 4 15 16 19 23 389 fx_add_row 20 3 17 18 22 0 390 fx_add_row 21 5 18 19 21 23 391 fx_add_row6 21 24 0 392 fx_add_row 22 4 19 20 22 24 393 fx_add_row 23 3 22 23 25 0 394 fx_add_row 24 1 24 0 0 0 395 ret fx_build_from_nb 25 14 out_t 396 end 397 398 fn fx_hex43_part1 to void 399 fx_add_row 0 1 3 0 0 0 400 fx_add_row 1 3 4 5 7 0 401 fx_add_row 2 3 1 6 9 0 402 fx_add_row 3 4 2 6 7 10 403 fx_add_row 4 4 2 7 8 11 404 fx_add_row 5 5 3 4 9 10 405 fx_add_row6 5 13 0 406 fx_add_row 6 6 2 4 5 10 407 fx_add_row6 6 11 14 408 fx_add_row 7 4 5 11 12 15 409 fx_add_row 8 4 3 6 13 16 410 fx_add_row 9 6 4 6 7 13 411 fx_add_row6 9 14 17 412 fx_add_row 10 6 5 7 8 14 413 fx_add_row6 10 15 18 414 fx_add_row 11 3 8 15 19 0 415 fx_add_row 12 6 6 9 10 16 416 fx_add_row6 12 17 20 417 fx_add_row 13 6 7 10 11 17 418 fx_add_row6 13 18 21 419 fx_add_row 14 6 8 11 12 18 420 fx_add_row6 14 19 22 421 fx_add_row 15 4 9 13 20 24 422 fx_add_row 16 6 10 13 14 20 423 fx_add_row6 16 21 25 424 fx_add_row 17 6 11 14 15 21 425 fx_add_row6 17 22 26 426 fx_add_row 18 5 12 15 22 23 427 fx_add_row6 18 27 0 428 fx_add_row 19 6 13 16 17 24 429 fx_add_row6 19 25 29 430 fx_add_row 20 6 14 17 18 25 431 fx_add_row6 20 26 30 432 fx_add_row 21 6 15 18 19 26 433 fx_add_row6 21 27 31 434 end 435 436 fn fx_hex43_part2 to void 437 fx_add_row 22 3 19 27 28 0 438 fx_add_row 23 4 16 20 29 32 439 fx_add_row 24 6 17 20 21 29 440 fx_add_row6 24 30 33 441 fx_add_row 25 6 18 21 22 30 442 fx_add_row6 25 31 34 443 fx_add_row 26 5 19 22 23 31 444 fx_add_row6 26 35 0 445 fx_add_row 27 1 23 0 0 0 446 fx_add_row 28 6 20 24 25 32 447 fx_add_row6 28 33 36 448 fx_add_row 29 6 21 25 26 33 449 fx_add_row6 29 34 37 450 fx_add_row 30 6 22 26 27 34 451 fx_add_row6 30 35 38 452 fx_add_row 31 4 24 29 36 39 453 fx_add_row 32 6 25 29 30 36 454 fx_add_row6 32 37 40 455 fx_add_row 33 6 26 30 31 37 456 fx_add_row6 33 38 41 457 fx_add_row 34 3 27 31 38 0 458 fx_add_row 35 5 29 32 33 39 459 fx_add_row6 35 40 0 460 fx_add_row 36 6 30 33 34 40 461 fx_add_row6 36 41 43 462 fx_add_row 37 4 31 34 35 41 463 fx_add_row 38 3 32 36 42 0 464 fx_add_row 39 4 33 36 37 43 465 fx_add_row 40 4 34 37 38 43 466 fx_add_row 41 1 39 0 0 0 467 fx_add_row 42 3 37 40 41 0 468 end 469 470 fn fx_hex43 out_t edit uint 514 to int 471 for i ulong 301 bound 301 472 put fx_nb i 0 473 end 474 fx_hex43_part1 475 fx_hex43_part2 476 ret fx_build_from_nb 43 21 out_t 477 end 478 479 fn fx_set_c50 e edit uint 98 idx ulong a uint b uint to void 480 put e mul idx 2 sub a 1 481 put e add mul idx 2 1 sub b 1 482 end 483 484 fn fx_chain50 out_t edit uint 514 to int 485 e = new uint 98 0 486 fx_set_c50 e 0 1 4 487 fx_set_c50 e 1 2 5 488 fx_set_c50 e 2 3 6 489 fx_set_c50 e 3 3 7 490 fx_set_c50 e 4 5 8 491 fx_set_c50 e 5 6 9 492 fx_set_c50 e 6 7 10 493 fx_set_c50 e 7 4 11 494 fx_set_c50 e 8 8 12 495 fx_set_c50 e 9 9 12 496 fx_set_c50 e 10 10 13 497 fx_set_c50 e 11 13 14 498 fx_set_c50 e 12 11 15 499 fx_set_c50 e 13 14 16 500 fx_set_c50 e 14 15 17 501 fx_set_c50 e 15 16 18 502 fx_set_c50 e 16 17 19 503 fx_set_c50 e 17 18 20 504 fx_set_c50 e 18 20 25 505 fx_set_c50 e 19 19 26 506 fx_set_c50 e 20 21 27 507 fx_set_c50 e 21 21 28 508 fx_set_c50 e 22 22 28 509 fx_set_c50 e 23 22 29 510 fx_set_c50 e 24 23 29 511 fx_set_c50 e 25 23 30 512 fx_set_c50 e 26 24 30 513 fx_set_c50 e 27 24 31 514 fx_set_c50 e 28 25 31 515 fx_set_c50 e 29 27 32 516 fx_set_c50 e 30 26 33 517 fx_set_c50 e 31 32 34 518 fx_set_c50 e 32 33 35 519 fx_set_c50 e 33 35 36 520 fx_set_c50 e 34 34 37 521 fx_set_c50 e 35 36 38 522 fx_set_c50 e 36 37 39 523 fx_set_c50 e 37 39 40 524 fx_set_c50 e 38 38 41 525 fx_set_c50 e 39 40 42 526 fx_set_c50 e 40 41 43 527 fx_set_c50 e 41 42 44 528 fx_set_c50 e 42 43 47 529 fx_set_c50 e 43 44 48 530 fx_set_c50 e 44 45 48 531 fx_set_c50 e 45 45 49 532 fx_set_c50 e 46 46 49 533 fx_set_c50 e 47 46 50 534 fx_set_c50 e 48 47 50 535 g = new uint 1 0 536 put g 0 49 537 tm = new uint 3 0 538 put tm 0 50 539 put tm 1 49 540 put tm 2 1 541 ret res_topology_build view tm view e view g out_t 542 end 543 544 note ================================================================ 545 note Global state / tab helpers (since globals cannot be passed as args) 546 note ================================================================ 547 548 fn tr_cfg_eq_id to bool 549 for i ulong 32 bound 32 550 if ne get tr_cfg add RES_CFG_ID i get tr_cfg2 add RES_CFG_ID i 551 ret false 552 end 553 end 554 ret true 555 end 556 557 fn tr_build_cfg t view uint 514 p view uint 265 h f32 k uint which uint to int 558 c = new uint 5363 0 559 st = res_config_build t p h k c 560 if eq st RES_OK 561 for i ulong RES_CFG_WORDS bound 5363 562 if eq which 0 563 put tr_cfg i get c i 564 else 565 put tr_cfg2 i get c i 566 end 567 end 568 end 569 ret st 570 end 571 572 fn tr_init_s kind uint val f32 to int 573 c = new uint 5363 0 574 for i ulong RES_CFG_WORDS bound 5363 575 put c i get tr_cfg i 576 end 577 s = new uint 932 0 578 st = res_state_init view c kind val s 579 if eq st RES_OK 580 for i ulong RES_STATE_WORDS bound 932 581 put tr_s i get s i 582 end 583 end 584 ret st 585 end 586 587 fn tr_advance_global in_nc uint in_kn uint steps ulong obs uint to int 588 c = new uint 5363 0 589 for i ulong RES_CFG_WORDS bound 5363 590 put c i get tr_cfg i 591 end 592 s = new uint 932 0 593 for i ulong RES_STATE_WORDS bound 932 594 put s i get tr_s i 595 end 596 ws = new uint 3564 0 597 for i ulong RES_WS_WORDS bound 3564 598 put ws i get tr_ws i 599 end 600 total = mul ulong in_nc ulong in_kn 601 note Copy needed slice of tr_tab into local? Up to 262144 f32 = 1 MiB (fits 4 MiB local limit!) 602 note Actually we can just copy needed knots! Wait: local array must have const size. 603 note Let's use a 131072-element local f32 array (512 KiB) — max knots*n in test_reservoir is 2001*5=10005 or 1001*13=13013! 604 ltab = new f32 32768 0.0f32 605 for i ulong total bound 32768 606 put ltab i get tr_tab i 607 end 608 am = new uint 5 0 609 put am 0 in_nc 610 put am 1 in_kn 611 put am 2 uint and steps 0xffffffff 612 put am 3 uint shr steps 32 613 put am 4 obs 614 st = res_advance_meta view c part ltab 0 total view am ws s 615 for i ulong RES_STATE_WORDS bound 932 616 put tr_s i get s i 617 end 618 for i ulong RES_WS_WORDS bound 3564 619 put tr_ws i get ws i 620 end 621 ret st 622 end 623 624 fn tr_step_global in_nc uint in_kn uint to int 625 c = new uint 5363 0 626 for i ulong RES_CFG_WORDS bound 5363 627 put c i get tr_cfg i 628 end 629 s = new uint 932 0 630 for i ulong RES_STATE_WORDS bound 932 631 put s i get tr_s i 632 end 633 ws = new uint 3564 0 634 for i ulong RES_WS_WORDS bound 3564 635 put ws i get tr_ws i 636 end 637 total = mul ulong in_nc ulong in_kn 638 ltab = new f32 32768 0.0f32 639 for i ulong total bound 32768 640 put ltab i get tr_tab i 641 end 642 im = new uint 2 0 643 put im 0 in_nc 644 put im 1 in_kn 645 st = res_step_spare view c part ltab 0 total view im ws view s 646 for i ulong RES_WS_WORDS bound 3564 647 put tr_ws i get ws i 648 end 649 ret st 650 end 651 652 fn tr_fill_const knots ulong n ulong vals view f32 * to void 653 for k ulong knots bound 4096 654 for i ulong n bound 64 655 put tr_tab add mul k n i get vals i 656 end 657 end 658 end 659 660 fn tr_fill_masked_row mask view uint 512 n ulong k ulong mi ulong seq f64 hi f32 to void 661 for i ulong n bound 64 662 if ne get mask add mul i 8 mi 0 663 put tr_tab add mul k n i f32 seq 664 else 665 put tr_tab add mul k n i f32 sub f64 hi seq 666 end 667 end 668 end 669 670 fn tr_fill_masked n ulong samples ulong mask_len ulong hi f32 to ulong 671 mask = new uint 512 0 672 for i ulong n bound 64 673 for j ulong mask_len bound 8 674 put mask add mul i 8 j uint and tr_rnd 1 675 end 676 end 677 knots = add mul mul samples mask_len 10 1 678 seq = 0.0f64 679 for k ulong knots bound 4096 680 sub_i = div k 10 681 smp = div sub_i mask_len 682 mi = rem sub_i mask_len 683 if eq rem k mul 10 mask_len 0 684 if lt smp samples 685 seq = mul tr_runit f64 hi 686 end 687 end 688 tr_fill_masked_row view mask n k mi seq hi 689 end 690 ret knots 691 end 692 693 note ================================================================ 694 note Independent binary64 Dormand-Prince 5(4) oracle (res_oracle64.c) 695 note ================================================================ 696 697 fn o64_lu_swap m ulong k ulong p ulong to void 698 for j ulong m bound 64 699 ik = add mul k 64 j 700 ip = add mul p 64 j 701 tk = get o64_lu ik 702 tp = get o64_lu ip 703 put o64_lu ik tp 704 put o64_lu ip tk 705 end 706 end 707 708 fn o64_lu_elim_row m ulong k ulong i ulong lik f64 to void 709 j = add k 1 710 while lt j m bound 64 711 ukj = get o64_lu add mul k 64 j 712 idx = add mul i 64 j 713 put o64_lu idx sub get o64_lu idx mul lik ukj 714 j = add j 1 715 end 716 end 717 718 fn o64_lu_elim m ulong k ulong to void 719 piv = get o64_lu add mul k 64 k 720 i = add k 1 721 while lt i m bound 64 722 lik = div get o64_lu add mul i 64 k piv 723 put o64_lu add mul i 64 k lik 724 o64_lu_elim_row m k i lik 725 i = add i 1 726 end 727 end 728 729 fn o64_find_pivot m ulong k ulong to ulong 730 p = k 731 best = tr_abs64 get o64_lu add mul k 64 k 732 i = add k 1 733 while lt i m bound 64 734 cand = tr_abs64 get o64_lu add mul i 64 k 735 if gt cand best 736 best = cand 737 p = i 738 end 739 i = add i 1 740 end 741 ret p 742 end 743 744 fn o64_lu_factor to int 745 m = get o64_m 0 746 for k ulong m bound 64 747 p = o64_find_pivot m k 748 if eq get o64_lu add mul p 64 k 0.0f64 749 ret -1 750 end 751 put o64_piv k p 752 if ne p k 753 o64_lu_swap m k p 754 end 755 o64_lu_elim m k 756 end 757 ret 0 758 end 759 760 fn o64_lu_fwd m ulong k ulong to void 761 p = get o64_piv k 762 if ne p k 763 t = get o64_x k 764 put o64_x k get o64_x p 765 put o64_x p t 766 end 767 xk = get o64_x k 768 i = add k 1 769 while lt i m bound 64 770 lik = get o64_lu add mul i 64 k 771 put o64_x i sub get o64_x i mul lik xk 772 i = add i 1 773 end 774 end 775 776 fn o64_lu_bwd m ulong i ulong to void 777 s = get o64_x i 778 j = add i 1 779 while lt j m bound 64 780 uij = get o64_lu add mul i 64 j 781 s = sub s mul uij get o64_x j 782 j = add j 1 783 end 784 put o64_x i div s get o64_lu add mul i 64 i 785 end 786 787 fn o64_lu_solve to void 788 m = get o64_m 0 789 for k ulong m bound 64 790 o64_lu_fwd m k 791 end 792 for step ulong m bound 64 793 o64_lu_bwd m sub sub m 1 step 794 end 795 end 796 797 fn o64_rhs_side o ulong dv f64 nk f64 to f64 798 alpha = div get o64_par 2 mul get o64_tau0 o tr_exp64 div dv get o64_vtau o 799 nss = mul mul get o64_par 3 tr_exp64 mul get o64_par 4 get o64_c o tr_exp64 div dv get o64_ve o 800 ret mul mul alpha nk sub 1.0f64 tr_pow64 div nk nss get o64_par 1 801 end 802 803 fn o64_rhs_edge e ulong n ulong kbase ulong to void 804 a = get o64_a e 805 b = get o64_b e 806 s0 = add n mul e 2 807 dv = sub get o64_yt a get o64_yt b 808 q = add get o64_yt s0 get o64_yt add s0 1 809 q = mul mul get o64_par 0 q dv 810 put o64_B a sub get o64_B a q 811 put o64_B b add get o64_B b q 812 q = o64_rhs_side a dv get o64_yt s0 813 put o64_k add kbase s0 q 814 q = o64_rhs_side b neg dv get o64_yt add s0 1 815 put o64_k add kbase add s0 1 q 816 end 817 818 fn o64_rhs stage ulong to void 819 n = get o64_n 0 820 ne_c = get o64_ne 0 821 kbase = mul stage 448 822 for i ulong n bound 64 823 put o64_B i get o64_cur i 824 end 825 for e ulong ne_c bound 192 826 o64_rhs_edge e n kbase 827 end 828 m = get o64_m 0 829 for u ulong m bound 64 830 put o64_x u get o64_B get o64_unk_node u 831 end 832 o64_lu_solve 833 for i ulong n bound 64 834 ui = get o64_unk i 835 if lt ui 0 836 put o64_k add kbase i 0.0f64 837 else 838 put o64_k add kbase i get o64_x ulong ui 839 end 840 end 841 end 842 843 fn o64_stage_s st ulong j ulong to f64 844 if eq st 1 845 ret mul 0.2f64 get o64_k j 846 end 847 if eq st 2 848 s = mul div 3.0f64 40.0f64 get o64_k j 849 s = add s mul div 9.0f64 40.0f64 get o64_k add 448 j 850 ret s 851 end 852 if eq st 3 853 s = mul div 44.0f64 45.0f64 get o64_k j 854 s = add s mul div -56.0f64 15.0f64 get o64_k add 448 j 855 s = add s mul div 32.0f64 9.0f64 get o64_k add 896 j 856 ret s 857 end 858 if eq st 4 859 s = mul div 19372.0f64 6561.0f64 get o64_k j 860 s = add s mul div -25360.0f64 2187.0f64 get o64_k add 448 j 861 s = add s mul div 64448.0f64 6561.0f64 get o64_k add 896 j 862 s = add s mul div -212.0f64 729.0f64 get o64_k add 1344 j 863 ret s 864 end 865 if eq st 5 866 s = mul div 9017.0f64 3168.0f64 get o64_k j 867 s = add s mul div -355.0f64 33.0f64 get o64_k add 448 j 868 s = add s mul div 46732.0f64 5247.0f64 get o64_k add 896 j 869 s = add s mul div 49.0f64 176.0f64 get o64_k add 1344 j 870 s = add s mul div -5103.0f64 18656.0f64 get o64_k add 1792 j 871 ret s 872 end 873 if eq st 6 874 s = mul div 35.0f64 384.0f64 get o64_k j 875 s = add s mul div 500.0f64 1113.0f64 get o64_k add 896 j 876 s = add s mul div 125.0f64 192.0f64 get o64_k add 1344 j 877 s = add s mul div -2187.0f64 6784.0f64 get o64_k add 1792 j 878 s = add s mul div 11.0f64 84.0f64 get o64_k add 2240 j 879 ret s 880 end 881 ret 0.0f64 882 end 883 884 fn o64_stage_yt st ulong h f64 ny ulong to void 885 for j ulong ny bound 448 886 acc = add get o64_y j mul h o64_stage_s st j 887 if eq st 6 888 put o64_yn j acc 889 end 890 put o64_yt j acc 891 end 892 end 893 894 fn o64_stage_c st ulong to f64 895 if eq st 0 896 ret 0.0f64 897 end 898 if eq st 1 899 ret 0.2f64 900 end 901 if eq st 2 902 ret 0.3f64 903 end 904 if eq st 3 905 ret 0.8f64 906 end 907 if eq st 4 908 ret div 8.0f64 9.0f64 909 end 910 ret 1.0f64 911 end 912 913 fn o64_err_one h f64 j ulong rtol f64 atol f64 to f64 914 ej = mul sub div 35.0f64 384.0f64 div 5179.0f64 57600.0f64 get o64_k j 915 ej = add ej mul sub div 500.0f64 1113.0f64 div 7571.0f64 16695.0f64 get o64_k add 896 j 916 ej = add ej mul sub div 125.0f64 192.0f64 div 393.0f64 640.0f64 get o64_k add 1344 j 917 ej = add ej mul add div -2187.0f64 6784.0f64 div 92097.0f64 339200.0f64 get o64_k add 1792 j 918 ej = add ej mul sub div 11.0f64 84.0f64 div 187.0f64 2100.0f64 get o64_k add 2240 j 919 ej = add ej mul -0.025f64 get o64_k add 2688 j 920 ej = mul h ej 921 ynj = get o64_yn j 922 if not res_fin64 bitcast ulong ynj 923 ret bitcast f64 ulong 0x7ff0000000000000 924 end 925 if ge j get o64_n 0 926 if le ynj 0.0f64 927 ret bitcast f64 ulong 0x7ff0000000000000 928 end 929 end 930 sc = add atol mul rtol tr_max64 tr_abs64 get o64_y j tr_abs64 ynj 931 ret div tr_abs64 ej sc 932 end 933 934 fn o64_err_norm h f64 ny ulong rtol f64 atol f64 to f64 935 err = 0.0f64 936 for j ulong ny bound 448 937 r = o64_err_one h j rtol atol 938 if not res_fin64 bitcast ulong r 939 ret bitcast f64 ulong 0x7ff0000000000000 940 end 941 if gt r err 942 err = r 943 end 944 end 945 ret err 946 end 947 948 fn o64_fill_lu ne_c ulong cap f64 to void 949 for e ulong ne_c bound 192 950 ua = get o64_unk get o64_a e 951 ub = get o64_unk get o64_b e 952 if ge ua 0 953 idx = add mul ulong ua 64 ulong ua 954 put o64_lu idx add get o64_lu idx cap 955 end 956 if ge ub 0 957 idx = add mul ulong ub 64 ulong ub 958 put o64_lu idx add get o64_lu idx cap 959 end 960 if and ge ua 0 ge ub 0 961 i1 = add mul ulong ua 64 ulong ub 962 i2 = add mul ulong ub 64 ulong ua 963 put o64_lu i1 sub get o64_lu i1 cap 964 put o64_lu i2 sub get o64_lu i2 cap 965 end 966 end 967 end 968 969 fn o64_setup t view uint 514 p view uint 265 to int 970 n = ulong get t 0 971 ne_c = ulong get t 1 972 put o64_n 0 n 973 put o64_ne 0 ne_c 974 for e ulong ne_c bound 192 975 put o64_a e ulong get t add RES_TOPO_EDGES mul e 2 976 put o64_b e ulong get t add RES_TOPO_EDGES add mul e 2 1 977 end 978 put o64_par 0 mul f64 bitcast f32 get p 4 f64 bitcast f32 get p 3 979 put o64_par 1 f64 bitcast f32 get p 5 980 put o64_par 2 f64 bitcast f32 get p 6 981 put o64_par 3 f64 bitcast f32 get p 7 982 put o64_par 4 f64 bitcast f32 get p 8 983 m = ulong 0 984 for i ulong n bound 64 985 put o64_c i f64 bitcast f32 get p add RES_PAR_CONC i 986 put o64_tau0 i f64 bitcast f32 get p add RES_PAR_TAU0 i 987 put o64_vtau i f64 bitcast f32 get p add RES_PAR_VTAU i 988 put o64_ve i f64 bitcast f32 get p add RES_PAR_VE i 989 put o64_unk i -1 990 if eq get t add RES_TOPO_GND i 0 991 put o64_unk i long m 992 put o64_unk_node m i 993 m = add m 1 994 end 995 end 996 put o64_m 0 m 997 for i ulong 4096 bound 4096 998 put o64_lu i 0.0f64 999 end 1000 cap = div mul f64 bitcast f32 get p 1 f64 bitcast f32 get p 3 f64 bitcast f32 get p 2 1001 o64_fill_lu ne_c cap 1002 ret o64_lu_factor 1003 end 1004 1005 fn o64_interp_cur b0 ulong n ulong f f64 to void 1006 for i ulong n bound 64 1007 v0 = f64 get tr_tab add b0 i 1008 v1 = f64 get tr_tab add add b0 n i 1009 put o64_cur i add v0 mul f sub v1 v0 1010 end 1011 end 1012 1013 fn o64_run_stages b0 ulong t f64 h f64 dt_s f64 to void 1014 n = get o64_n 0 1015 ny = add n mul get o64_ne 0 2 1016 for st ulong 7 bound 7 1017 o64_stage_yt st h ny 1018 f = div add t mul o64_stage_c st h dt_s 1019 o64_interp_cur b0 n f 1020 o64_rhs st 1021 end 1022 end 1023 1024 fn o64_accept_y ny ulong to void 1025 for j ulong ny bound 448 1026 put o64_y j get o64_yn j 1027 end 1028 end 1029 1030 fn o64_next_h h f64 err f64 accepted bool to f64 1031 if accepted 1032 ec = tr_max64 err 1.0e-30f64 1033 fac = tr_min64 5.0f64 tr_max64 0.2f64 mul 0.9f64 tr_pow64 ec -0.2f64 1034 ret mul h fac 1035 end 1036 if res_fin64 bitcast ulong err 1037 fac = tr_max64 0.1f64 mul 0.9f64 tr_pow64 err -0.2f64 1038 ret mul h fac 1039 end 1040 ret mul h 0.1f64 1041 end 1042 1043 fn o64_run_knot kn ulong dt_s f64 rtol f64 atol f64 h_io edit f64 1 to int 1044 n = get o64_n 0 1045 ny = add n mul get o64_ne 0 2 1046 t = 0.0f64 1047 h = get h_io 0 1048 b0 = mul kn n 1049 while lt t dt_s bound 100000 1050 if gt h sub dt_s t 1051 h = sub dt_s t 1052 end 1053 if lt h 1.0e-18f64 1054 ret -1 1055 end 1056 o64_run_stages b0 t h dt_s 1057 err = o64_err_norm h ny rtol atol 1058 if le err 1.0f64 1059 o64_accept_y ny 1060 t = add t h 1061 h = o64_next_h h err true 1062 else 1063 h = o64_next_h h err false 1064 end 1065 end 1066 put h_io 0 h 1067 ret 0 1068 end 1069 1070 fn o64_store_v base ulong n ulong which_out uint to void 1071 for i ulong n bound 64 1072 if eq which_out 0 1073 put tr_vtight add base i get o64_y i 1074 else 1075 put tr_vref add base i get o64_y i 1076 end 1077 end 1078 end 1079 1080 fn o64_init_y which_out uint to void 1081 n = get o64_n 0 1082 ne_c = get o64_ne 0 1083 for i ulong n bound 64 1084 put o64_y i 0.0f64 1085 end 1086 o64_store_v 0 n which_out 1087 for s ulong mul ne_c 2 bound 384 1088 put o64_y add n s get o64_ninit s 1089 end 1090 end 1091 1092 fn o64_check_fin to int 1093 ny = add get o64_n 0 mul get o64_ne 0 2 1094 for j ulong ny bound 448 1095 if not res_fin64 bitcast ulong get o64_y j 1096 ret -1 1097 end 1098 end 1099 ret 0 1100 end 1101 1102 note which_out: 0 -> tr_vtight, 1 -> tr_vref 1103 fn o64_run t view uint 514 p view uint 265 knots ulong rtol f64 atol f64 which_out uint to int 1104 if ne o64_setup t p 0 1105 ret -1 1106 end 1107 o64_init_y which_out 1108 h_io = new f64 1 1.0e-4f64 1109 for kn ulong sub knots 1 bound 4096 1110 if ne o64_run_knot kn 1.0e-4f64 rtol atol h_io 0 1111 ret -1 1112 end 1113 o64_store_v mul add kn 1 get o64_n 0 get o64_n 0 which_out 1114 end 1115 ret o64_check_fin 1116 end 1117 1118 note ================================================================ 1119 note Test 1 & 2: Topology and Reference Lattices 1120 note ================================================================ 1121 1122 fn test_topology_bad2 to void 1123 t2 = new uint 514 0 1124 g0 = new uint 1 0 1125 g9 = new uint 1 9 1126 tm = new uint 3 0 1127 dupl_e = new uint 4 0 1128 put dupl_e 1 1 1129 put dupl_e 2 1 1130 put tm 0 2 1131 put tm 1 1 1132 put tm 2 0 1133 tr_check eq res_topology_build view tm view dupl_e view g0 t2 RES_ERR_TOPOLOGY 1134 put tm 1 0 1135 put tm 2 1 1136 tr_check eq res_topology_build view tm view dupl_e view g0 t2 RES_ERR_TOPOLOGY 1137 put tm 0 1 1138 put tm 1 1 1139 tr_check eq res_topology_build view tm view dupl_e view g0 t2 RES_ERR_TOPOLOGY 1140 put tm 0 65 1141 tr_check eq res_topology_build view tm view dupl_e view g0 t2 RES_ERR_TOPOLOGY 1142 put tm 0 3 1143 tr_check eq res_topology_build view tm view dupl_e view g9 t2 RES_ERR_TOPOLOGY 1144 tr_check eq res_topology_build view tm view dupl_e view g0 t2 RES_ERR_TOPOLOGY 1145 tr_check eq res_topology_chain 1 0 t2 RES_ERR_TOPOLOGY 1146 tr_check eq res_topology_chain 4 4 t2 RES_ERR_TOPOLOGY 1147 end 1148 1149 fn test_topology_bad to void 1150 t2 = new uint 514 0 1151 g0 = new uint 1 0 1152 gg = new uint 2 0 1153 gall = new uint 2 0 1154 put gall 1 1 1155 tm = new uint 3 0 1156 e = new uint 4 1 1157 put tm 0 2 1158 put tm 1 1 1159 put tm 2 1 1160 tr_check eq res_topology_build view tm view e view g0 t2 RES_ERR_TOPOLOGY 1161 put e 0 0 1162 put e 1 1 1163 put e 2 1 1164 put e 3 0 1165 put tm 1 2 1166 tr_check eq res_topology_build view tm view e view g0 t2 RES_ERR_TOPOLOGY 1167 put e 1 5 1168 put tm 0 5 1169 put tm 1 1 1170 tr_check eq res_topology_build view tm view e view g0 t2 RES_ERR_TOPOLOGY 1171 put e 1 1 1172 put tm 0 2 1173 put tm 1 1 1174 put tm 2 2 1175 tr_check eq res_topology_build view tm view e view gg t2 RES_ERR_TOPOLOGY 1176 tr_check eq res_topology_build view tm view e view gall t2 RES_ERR_TOPOLOGY 1177 test_topology_bad2 1178 end 1179 1180 fn test_topology to void 1181 t = new uint 514 0 1182 t2 = new uint 514 0 1183 tr_check eq res_topology_chain 5 4 t RES_OK 1184 tr_check and eq get t 0 5 eq get t 1 4 1185 tr_check and eq get t RES_TOPO_DEG 1 eq get t add RES_TOPO_DEG 1 2 1186 tr_check and eq get t add RES_TOPO_GND 4 1 eq get t RES_TOPO_GND 0 1187 sh = new uint 8 0 1188 put sh 0 4 1189 put sh 1 3 1190 put sh 2 1 1191 put sh 3 0 1192 put sh 4 2 1193 put sh 5 3 1194 put sh 6 2 1195 put sh 7 1 1196 g4 = new uint 1 4 1197 tm = new uint 3 0 1198 put tm 0 5 1199 put tm 1 4 1200 put tm 2 1 1201 tr_check eq res_topology_build view tm view sh view g4 t2 RES_OK 1202 same = true 1203 for i ulong RES_TOPO_WORDS bound 514 1204 if ne get t i get t2 i 1205 same = false 1206 end 1207 end 1208 tr_check same 1209 test_topology_bad 1210 star = new uint 14 0 1211 for i ulong 7 bound 7 1212 put star mul i 2 0 1213 put star add mul i 2 1 uint add i 1 1214 end 1215 g0 = new uint 1 0 1216 put tm 0 8 1217 put tm 1 7 1218 put tm 2 1 1219 tr_check eq res_topology_build view tm view star view g0 t2 RES_ERR_TOPOLOGY 1220 put tm 0 7 1221 put tm 1 6 1222 tr_check eq res_topology_build view tm view star view g0 t2 RES_OK 1223 tr_check eq get t2 RES_TOPO_DEG 6 1224 two = new uint 6 0 1225 put two 0 0 1226 put two 1 1 1227 put two 2 1 1228 put two 3 2 1229 put two 4 3 1230 put two 5 4 1231 g2 = new uint 1 2 1232 g24 = new uint 2 2 1233 put g24 1 4 1234 put tm 0 5 1235 put tm 1 3 1236 put tm 2 1 1237 tr_check eq res_topology_build view tm view two view g2 t2 RES_ERR_TOPOLOGY 1238 put tm 2 2 1239 tr_check eq res_topology_build view tm view two view g24 t2 RES_OK 1240 end 1241 1242 fn tr_deg_hist t view uint 514 h edit uint 8 to void 1243 for i ulong 8 bound 8 1244 put h i 0 1245 end 1246 for i ulong ulong get t 0 bound 64 1247 d = ulong get t add RES_TOPO_DEG i 1248 put h d add get h d 1 1249 end 1250 end 1251 1252 fn test_reference_lattices to void 1253 t = new uint 514 0 1254 h = new uint 8 0 1255 tr_check eq fx_hex13 t RES_OK 1256 tr_check eq get t 1 21 1257 tr_deg_hist view t h 1258 tr_check and eq get h 1 3 and eq get h 3 3 and eq get h 4 6 eq get h 6 1 1259 tr_check and eq get t add RES_TOPO_DEG 7 6 eq get t add RES_TOPO_GND 7 1 1260 1261 tr_check eq fx_hex25 t RES_OK 1262 tr_check eq get t 1 51 1263 tr_deg_hist view t h 1264 tr_check and eq get h 1 3 and eq get h 3 6 and eq get h 5 3 eq get h 6 7 1265 tr_check eq get t add RES_TOPO_DEG 13 6 1266 1267 tr_check eq fx_hex43 t RES_OK 1268 tr_check eq get t 1 99 1269 tr_deg_hist view t h 1270 tr_check and eq get h 1 3 and eq get h 3 7 and eq get h 4 10 eq get h 6 19 1271 tr_check eq get t add RES_TOPO_DEG 20 6 1272 bnd = ulong 0 1273 for i ulong 43 bound 43 1274 if lt get t add RES_TOPO_DEG i 6 1275 bnd = add bnd 1 1276 end 1277 end 1278 tr_check eq bnd 24 1279 1280 tr_check eq fx_chain50 t RES_OK 1281 tr_deg_hist view t h 1282 tr_check and eq get h 1 2 eq get h 2 48 1283 tr_check and eq get t RES_TOPO_DEG 1 and eq get t add RES_TOPO_DEG 1 1 eq get t add RES_TOPO_DEG 49 2 1284 end 1285 1286 note ================================================================ 1287 note Test 3 & 4: Params and Identity (with frozen C SHA-256 config_id!) 1288 note ================================================================ 1289 1290 fn test_params to void 1291 p = new uint 265 0 1292 tr_check eq res_params_reference RES_REF_NARMA 5 p RES_OK 1293 tr_check eq bitcast f32 get p 1 8.85e-12f32 1294 tr_check eq bitcast f32 get p 5 0.`00015f32` 1295 tr_check and eq bitcast f32 get p RES_PAR_CONC 1.0f32 eq bitcast f32 get p add RES_PAR_CONC 2 3.0f32 1296 tr_check eq res_params_reference RES_REF_LORENZ 43 p RES_OK 1297 tr_check eq bitcast f32 get p 1 f32 mul 2.1f64 8.85e-12f64 1298 tr_check eq bitcast f32 get p add RES_PAR_VTAU 42 0.`0454f32` 1299 tr_check eq res_params_reference 7 5 p RES_ERR_PARAM 1300 tr_check eq res_params_reference RES_REF_NARMA 0 p RES_ERR_PARAM 1301 1302 t = new uint 514 0 1303 _rt = res_topology_chain 5 4 t 1304 _rp = res_params_reference RES_REF_NARMA 5 p 1305 put p 1 0x7fc00000 1306 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_ERR_PARAM 1307 _rp = res_params_reference RES_REF_NARMA 5 p 1308 put p 5 bitcast uint 1.5f32 1309 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_ERR_PARAM 1310 _rp = res_params_reference RES_REF_NARMA 5 p 1311 put p 8 bitcast uint 40.0f32 1312 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_ERR_PARAM 1313 _rp = res_params_reference RES_REF_NARMA 4 p 1314 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_ERR_PARAM 1315 _rp = res_params_reference RES_REF_NARMA 5 p 1316 tr_check eq tr_build_cfg view t view p 0.0f32 10 0 RES_ERR_PARAM 1317 tr_check eq tr_build_cfg view t view p 2.0e-3f32 1 0 RES_ERR_PARAM 1318 tr_check eq tr_build_cfg view t view p 1.0e-5f32 0 0 RES_ERR_PARAM 1319 t2 = new uint 514 0 1320 for i ulong RES_TOPO_WORDS bound 514 1321 put t2 i get t i 1322 end 1323 put t2 RES_TOPO_DEG 3 1324 tr_check eq tr_build_cfg view t2 view p 1.0e-5f32 10 0 RES_ERR_TOPOLOGY 1325 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_OK 1326 end 1327 1328 note Frozen C SHA-256 config_id for 5-node NARMA chain, h=1e-5, K=10: 1329 note `cb778325f867428cd815041fe262c19c734db220a95e32a2506fc6af673e6224` 1330 fn tr_check_frozen_chain5_cid to void 1331 w = new uchar 32 0 1332 put w 0 0xcb 1333 put w 1 0x77 1334 put w 2 0x83 1335 put w 3 0x25 1336 put w 4 0xf8 1337 put w 5 0x67 1338 put w 6 0x42 1339 put w 7 0x8c 1340 put w 8 0xd8 1341 put w 9 0x15 1342 put w 10 0x04 1343 put w 11 0x1f 1344 put w 12 0xe2 1345 put w 13 0x62 1346 put w 14 0xc1 1347 put w 15 0x9c 1348 put w 16 0x73 1349 put w 17 0x4d 1350 put w 18 0xb2 1351 put w 19 0x20 1352 put w 20 0xa9 1353 put w 21 0x5e 1354 put w 22 0x32 1355 put w 23 0xa2 1356 put w 24 0x50 1357 put w 25 0x6f 1358 put w 26 0xc6 1359 put w 27 0xaf 1360 put w 28 0x67 1361 put w 29 0x3e 1362 put w 30 0x62 1363 put w 31 0x24 1364 ok = true 1365 for i ulong 32 bound 32 1366 if ne get tr_cfg add RES_CFG_ID i uint get w i 1367 ok = false 1368 end 1369 end 1370 tr_check ok 1371 end 1372 1373 fn test_identity to void 1374 t = new uint 514 0 1375 t2 = new uint 514 0 1376 p = new uint 265 0 1377 _r1 = res_topology_chain 5 4 t 1378 _r2 = res_params_reference RES_REF_NARMA 5 p 1379 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_OK 1380 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 1 RES_OK 1381 tr_check tr_cfg_eq_id 1382 tr_check_frozen_chain5_cid 1383 sh = new uint 8 0 1384 put sh 0 3 1385 put sh 1 4 1386 put sh 2 2 1387 put sh 3 1 1388 put sh 4 0 1389 put sh 5 1 1390 put sh 6 3 1391 put sh 7 2 1392 g4 = new uint 1 4 1393 tm = new uint 3 0 1394 put tm 0 5 1395 put tm 1 4 1396 put tm 2 1 1397 _r3 = res_topology_build view tm view sh view g4 t2 1398 tr_check eq tr_build_cfg view t2 view p 1.0e-5f32 10 1 RES_OK 1399 tr_check tr_cfg_eq_id 1400 put p RES_PAR_CONC 0 1401 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_OK 1402 put p RES_PAR_CONC 0x80000000 1403 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 1 RES_OK 1404 tr_check tr_cfg_eq_id 1405 _r2 = res_params_reference RES_REF_NARMA 5 p 1406 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_OK 1407 tr_check eq tr_build_cfg view t view p tr_nextafter_up 1.0e-5f32 10 1 RES_OK 1408 tr_check not tr_cfg_eq_id 1409 tr_check eq tr_build_cfg view t view p 1.0e-5f32 11 1 RES_OK 1410 tr_check not tr_cfg_eq_id 1411 _r4 = res_topology_chain 5 0 t2 1412 tr_check eq tr_build_cfg view t2 view p 1.0e-5f32 10 1 RES_OK 1413 tr_check not tr_cfg_eq_id 1414 end 1415 1416 note ================================================================ 1417 note Test 5..9: Closed-form dynamics & connected/disconnected 1418 note ================================================================ 1419 1420 fn test_zero_input_fixed_point to void 1421 t = new uint 514 0 1422 p = new uint 265 0 1423 _r1 = res_topology_chain 5 4 t 1424 _r2 = res_params_reference RES_REF_NARMA 5 p 1425 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_OK 1426 tr_check eq tr_init_s RES_INIT_N0 0.0f32 RES_OK 1427 s = new uint 932 0 1428 for i ulong RES_STATE_WORDS bound 932 1429 put s i get tr_s i 1430 put tr_s2 i get tr_s i 1431 end 1432 tr_near f64 res_state_pore view s 0 mul 0.002f64 tr_exp64 3.`7919f64` 1.0e-5f64 1433 tr_near f64 res_state_pore view s 1 mul 0.002f64 tr_exp64 mul 3.`7919f64` 2.0f64 1.0e-5f64 1434 tr_check res_f32_isnan res_state_pore view s 8 1435 z5 = new f32 5 0.0f32 1436 tr_fill_const 401 5 view z5 1437 tr_check eq tr_advance_global 5 401 4000 0 RES_OK 1438 tr_check eq or shl ulong get tr_s RES_ST_STEP_HI 32 ulong get tr_s RES_ST_STEP_LO 4000 1439 same = true 1440 for i ulong 64 bound 64 1441 a = get tr_s add RES_ST_V i 1442 b = get tr_s2 add RES_ST_V i 1443 if ne a b 1444 same = false 1445 end 1446 end 1447 for i ulong 384 bound 384 1448 a = get tr_s add RES_ST_Y i 1449 b = get tr_s2 add RES_ST_Y i 1450 if ne a b 1451 same = false 1452 end 1453 end 1454 tr_check same 1455 end 1456 1457 fn tr_decay_check_side ms ulong side ulong prev edit f64 2 to void 1458 cval = 1.0f64 1459 if ne side 0 1460 cval = 2.0f64 1461 end 1462 ln0 = add tr_log64 0.002f64 mul 3.`7919f64` cval 1463 s0 = tr_exp64 mul -0.`00015f64` sub tr_log64 1000.0f64 ln0 1464 sv = tr_exp64 mul -1500.0f64 mul f64 add ms 1 1.0e-3f64 1465 sv = sub 1.0f64 mul sub 1.0f64 s0 sv 1466 sv = sub ln0 div tr_log64 sv 0.`00015f64` 1467 ygot = f64 bitcast f32 get tr_s add RES_ST_Y side 1468 tr_nearabs ygot sv 2.0e-4f64 1469 tr_check and lt ygot get prev side gt ygot ln0 1470 put prev side ygot 1471 end 1472 1473 fn test_decay to void 1474 t = new uint 514 0 1475 p = new uint 265 0 1476 _r1 = res_topology_chain 2 1 t 1477 _r2 = res_params_reference RES_REF_NARMA 2 p 1478 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_OK 1479 tr_check eq tr_init_s RES_INIT_CONST 1000.0f32 RES_OK 1480 z2 = new f32 2 0.0f32 1481 tr_fill_const 101 2 view z2 1482 prev = new f64 2 1.0e9f64 1483 for ms ulong 8 bound 8 1484 tr_check eq tr_advance_global 2 101 100 0 RES_OK 1485 tr_check eq bitcast f32 get tr_s RES_ST_V 0.0f32 1486 tr_check eq bitcast f32 get tr_s add RES_ST_V 1 0.0f32 1487 tr_decay_check_side ms 0 prev 1488 tr_decay_check_side ms 1 prev 1489 end 1490 end 1491 1492 fn test_charging_a to void 1493 t = new uint 514 0 1494 p = new uint 265 0 1495 _r = res_topology_chain 2 1 t 1496 _r = res_params_reference RES_REF_NARMA 2 p 1497 put p 6 bitcast uint 1.0e-12f32 1498 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_OK 1499 tr_check eq tr_init_s RES_INIT_CONST 1.0e-30f32 RES_OK 1500 c2 = new f32 2 0.0f32 1501 put c2 0 1.0e-10f32 1502 put c2 1 5.0e-10f32 1503 tr_fill_const 11 2 view c2 1504 tr_check eq tr_advance_global 2 11 100 0 RES_OK 1505 cap = div mul 8.85e-12f64 5.0e-8f64 4.0e-9f64 1506 tr_near f64 bitcast f32 get tr_s RES_ST_V div mul 1.0e-10f64 1.0e-3f64 cap 1.0e-5f64 1507 tr_check eq bitcast f32 get tr_s add RES_ST_V 1 0.0f32 1508 end 1509 1510 fn test_charging to void 1511 test_charging_a 1512 t = new uint 514 0 1513 p = new uint 265 0 1514 e = new uint 4 0 1515 put e 1 1 1516 put e 2 1 1517 put e 3 2 1518 gr = new uint 2 0 1519 put gr 1 2 1520 tm = new uint 3 0 1521 put tm 0 3 1522 put tm 1 2 1523 put tm 2 2 1524 tr_check eq res_topology_build view tm view e view gr t RES_OK 1525 _r = res_params_reference RES_REF_NARMA 3 p 1526 put p 6 bitcast uint 1.0e-12f32 1527 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_OK 1528 tr_check eq tr_init_s RES_INIT_CONST 1.0e-30f32 RES_OK 1529 c3 = new f32 3 0.0f32 1530 put c3 1 1.0e-10f32 1531 tr_fill_const 11 3 view c3 1532 tr_check eq tr_advance_global 3 11 100 0 RES_OK 1533 cap = div mul 8.85e-12f64 5.0e-8f64 4.0e-9f64 1534 tr_near f64 bitcast f32 get tr_s add RES_ST_V 1 div mul 1.0e-10f64 1.0e-3f64 mul 2.0f64 cap 1.0e-5f64 1535 tr_check eq bitcast f32 get tr_s RES_ST_V 0.0f32 1536 tr_check eq bitcast f32 get tr_s add RES_ST_V 2 0.0f32 1537 end 1538 1539 fn tr_sat_vstar to f64 1540 iv = f64 1.0e-10f32 1541 gua = mul 5.0e-8f64 5.0e-8f64 1542 n01 = mul 0.002f64 tr_exp64 3.`7919f64` 1543 n10 = mul 0.002f64 tr_exp64 mul 3.`7919f64` 2.0f64 1544 lo = 0.0f64 1545 hi = 0.5f64 1546 for it ulong 200 bound 200 1547 mid = mul 0.5f64 add lo hi 1548 t1 = mul n01 tr_exp64 div mid 0.`0055f64` 1549 t2 = mul n10 tr_exp64 div neg mid 0.`0055f64` 1550 f = sub mul mul gua add t1 t2 mid iv 1551 if gt f 0.0f64 1552 hi = mid 1553 else 1554 lo = mid 1555 end 1556 end 1557 ret mul 0.5f64 add lo hi 1558 end 1559 1560 fn test_saturation to void 1561 t = new uint 514 0 1562 p = new uint 265 0 1563 _r1 = res_topology_chain 2 1 t 1564 _r2 = res_params_reference RES_REF_NARMA 2 p 1565 tr_check eq tr_build_cfg view t view p 1.0e-5f32 1000 0 RES_OK 1566 tr_check eq tr_init_s RES_INIT_N0 0.0f32 RES_OK 1567 c2 = new f32 2 0.0f32 1568 put c2 0 1.0e-10f32 1569 tr_fill_const 301 2 view c2 1570 vstar = tr_sat_vstar 1571 tr_check and gt vstar 0.08f64 lt vstar 0.09f64 1572 worst = 0.0f64 1573 for k ulong 300 bound 300 1574 tr_check eq tr_advance_global 2 301 1000 0 RES_OK 1575 if ge k 150 1576 d = tr_abs64 sub f64 bitcast f32 get tr_s RES_ST_V vstar 1577 if gt d worst 1578 worst = d 1579 end 1580 end 1581 end 1582 tr_check le worst mul 2.0e-4f64 vstar 1583 tr_near f64 bitcast f32 get tr_s RES_ST_V vstar 2.0e-5f64 1584 end 1585 1586 fn test_connected_chain3 to void 1587 t = new uint 514 0 1588 p = new uint 265 0 1589 _r = res_topology_chain 3 2 t 1590 _r = res_params_reference RES_REF_NARMA 3 p 1591 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_OK 1592 tr_check eq tr_init_s RES_INIT_N0 0.0f32 RES_OK 1593 c3 = new f32 3 0.0f32 1594 put c3 0 1.0e-10f32 1595 tr_fill_const 101 3 view c3 1596 tr_check eq tr_advance_global 3 101 1000 0 RES_OK 1597 v0 = bitcast f32 get tr_s RES_ST_V 1598 v1 = bitcast f32 get tr_s add RES_ST_V 1 1599 v2 = bitcast f32 get tr_s add RES_ST_V 2 1600 tr_check gt v0 v1 1601 tr_check gt v1 0.0f32 1602 tr_check eq v2 0.0f32 1603 end 1604 1605 fn test_connected_and_disconnected to void 1606 test_connected_chain3 1607 t = new uint 514 0 1608 p = new uint 265 0 1609 tr_check eq fx_hex43 t RES_OK 1610 _r = res_params_reference RES_REF_LORENZ 43 p 1611 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_OK 1612 tr_check eq tr_init_s RES_INIT_CONST 1.0f32 RES_OK 1613 c43 = new f32 43 0.0f32 1614 put c43 0 1.1e-10f32 1615 put c43 27 1.1e-10f32 1616 put c43 41 1.1e-10f32 1617 tr_fill_const 201 43 view c43 1618 tr_check eq tr_advance_global 43 201 2000 0 RES_OK 1619 tr_check eq bitcast f32 get tr_s add RES_ST_V 20 0.0f32 1620 tr_check gt bitcast f32 get tr_s RES_ST_V bitcast f32 get tr_s add RES_ST_V 2 1621 tr_check gt bitcast f32 get tr_s add RES_ST_V 27 bitcast f32 get tr_s add RES_ST_V 22 1622 tr_check gt bitcast f32 get tr_s add RES_ST_V 41 bitcast f32 get tr_s add RES_ST_V 38 1623 end 1624 1625 note ================================================================ 1626 note Test 10, 11, 12: Reproducibility, Refusals, Membrane Guard 1627 note ================================================================ 1628 1629 fn test_reproducibility to void 1630 t = new uint 514 0 1631 p = new uint 265 0 1632 _r1 = res_topology_chain 5 4 t 1633 _r2 = res_params_reference RES_REF_NARMA 5 p 1634 put tr_rng 0 42 1635 knots = tr_fill_masked 5 30 2 1.0e-10f32 1636 steps = mul sub knots 1 10 1637 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_OK 1638 tr_check eq tr_init_s RES_INIT_N0 0.0f32 RES_OK 1639 tr_check eq tr_advance_global 5 uint knots steps 0 RES_OK 1640 for i ulong RES_STATE_WORDS bound 932 1641 put tr_s2 i get tr_s i 1642 end 1643 for i ulong RES_WS_WORDS bound 3564 1644 put tr_ws i 0xffffffff 1645 end 1646 tr_check eq tr_init_s RES_INIT_N0 0.0f32 RES_OK 1647 tr_check eq tr_advance_global 5 uint knots steps 0 RES_OK 1648 same = true 1649 for i ulong RES_STATE_WORDS bound 932 1650 if ne get tr_s i get tr_s2 i 1651 same = false 1652 end 1653 end 1654 tr_check same 1655 tr_check ne bitcast f32 get tr_s RES_ST_V 0.0f32 1656 end 1657 1658 fn test_refusals_overflow to void 1659 t = new uint 514 0 1660 p = new uint 265 0 1661 _r = res_topology_chain 2 1 t 1662 _r = res_params_reference RES_REF_NARMA 2 p 1663 put p 6 bitcast uint 1.0e-12f32 1664 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_OK 1665 tr_check eq tr_init_s RES_INIT_CONST 1.0e-30f32 RES_OK 1666 bg = new f32 2 0.0f32 1667 put bg 0 1.0e-6f32 1668 tr_fill_const 101 2 view bg 1669 tr_check eq tr_advance_global 2 101 1000 0 RES_ERR_RANGE 1670 v0 = bitcast f32 get tr_s RES_ST_V 1671 tr_check le v0 1.0f32 1672 tr_check gt v0 0.99f32 1673 tr_check eq get tr_s RES_ST_STEP_LO 11 1674 end 1675 1676 fn test_refusals to void 1677 t = new uint 514 0 1678 p = new uint 265 0 1679 _r = res_topology_chain 3 2 t 1680 _r = res_params_reference RES_REF_NARMA 3 p 1681 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_OK 1682 tr_check eq tr_init_s RES_INIT_N0 0.0f32 RES_OK 1683 c3 = new f32 3 0.0f32 1684 put c3 0 1.0e-10f32 1685 tr_fill_const 2 3 view c3 1686 for i ulong RES_STATE_WORDS bound 932 1687 put tr_s2 i get tr_s i 1688 end 1689 tr_check eq tr_advance_global 3 2 25 0 RES_ERR_INPUT 1690 tr_check eq or shl ulong get tr_s RES_ST_STEP_HI 32 ulong get tr_s RES_ST_STEP_LO 10 1691 for i ulong RES_STATE_WORDS bound 932 1692 put tr_s i get tr_s2 i 1693 end 1694 put tr_tab 1 bitcast f32 uint 0x7fc00000 1695 tr_check eq tr_advance_global 3 2 1 0 RES_ERR_NONFINITE 1696 put tr_tab 1 2.0e-6f32 1697 tr_check eq tr_step_global 3 2 RES_ERR_INPUT 1698 put tr_tab 1 0.0f32 1699 tr_check eq tr_step_global 2 2 RES_ERR_INPUT 1700 tr_check eq tr_step_global 3 1 RES_ERR_INPUT 1701 put tr_s RES_ST_V 0x7fc00000 1702 tr_check eq tr_step_global 3 2 RES_ERR_NONFINITE 1703 put tr_s RES_ST_V get tr_s2 RES_ST_V 1704 put tr_s add RES_ST_V 2 bitcast uint 1.0e-3f32 1705 tr_check eq tr_step_global 3 2 RES_ERR_RANGE 1706 put tr_s add RES_ST_V 2 0 1707 put tr_s RES_ST_V bitcast uint 1.5f32 1708 tr_check eq tr_step_global 3 2 RES_ERR_RANGE 1709 put tr_s RES_ST_V 0 1710 put tr_s add RES_ST_Y 1 bitcast uint 100.0f32 1711 tr_check eq tr_step_global 3 2 RES_ERR_RANGE 1712 put tr_s add RES_ST_Y 1 get tr_s2 add RES_ST_Y 1 1713 put tr_s 5 xor get tr_s 5 1 1714 tr_check eq tr_step_global 3 2 RES_ERR_MISMATCH 1715 put tr_s 5 get tr_s2 5 1716 1717 note Stiffness refusal 1718 tr_check eq tr_init_s RES_INIT_CONST f32 tr_exp64 70.0f64 RES_OK 1719 tr_check eq tr_advance_global 3 2 1 0 RES_ERR_STIFF 1720 test_refusals_overflow 1721 end 1722 1723 fn test_membrane_guard to void 1724 t = new uint 514 0 1725 p = new uint 265 0 1726 tr_check eq res_topology_chain 30 29 t RES_OK 1727 tr_check eq res_params_reference RES_REF_NARMA 30 p RES_OK 1728 put p 6 bitcast uint 1.0e-12f32 1729 tr_check eq tr_build_cfg view t view p 1.0e-5f32 10 0 RES_OK 1730 tr_check eq tr_init_s RES_INIT_CONST 1.0e-30f32 RES_OK 1731 c30 = new f32 30 0.0f32 1732 put c30 0 1.0e-8f32 1733 tr_fill_const 201 30 view c30 1734 for i ulong RES_MSTATS_WORDS bound 200 1735 put tr_ws add RES_WS_MSTATS i 0 1736 end 1737 tr_check eq tr_advance_global 30 201 300 1 RES_OK 1738 tr_check eq get tr_s RES_ST_STEP_LO 300 1739 v0 = bitcast f32 get tr_s RES_ST_V 1740 tr_check gt v0 7.5f32 1741 tr_check lt v0 8.2f32 1742 tr_check eq get tr_ws add RES_WS_MSTATS RES_MS_OBS_LO 300 1743 tr_check eq get tr_ws add RES_WS_MSTATS RES_MS_MEM_IMP 0 1744 1745 tr_check eq tr_advance_global 30 201 1900 1 RES_ERR_RANGE 1746 st_lo = get tr_s RES_ST_STEP_LO 1747 tr_check gt st_lo 1090 1748 tr_check lt st_lo 1120 1749 tr_check eq get tr_ws add RES_WS_MSTATS RES_MS_OBS_LO st_lo 1750 tr_check eq get tr_ws add RES_WS_MSTATS RES_MS_MEM_IMP 29 1751 max_mv = bitcast f32 get tr_ws add RES_WS_MSTATS RES_MS_MAX_MV 1752 tr_check le max_mv 1.0f32 1753 tr_check gt max_mv 0.99f32 1754 tr_check gt bitcast f32 get tr_s RES_ST_V 28.0f32 1755 end 1756 1757 note ================================================================ 1758 note Test 13: Agreement with independent binary64 Dormand-Prince oracle 1759 note ================================================================ 1760 1761 fn tr_knot_max_err base ulong n ulong cur_max f64 to f64 1762 me = cur_max 1763 for i ulong n bound 64 1764 a = f64 bitcast f32 get tr_s add RES_ST_V i 1765 b = get tr_vtight add base i 1766 e = tr_abs64 sub a b 1767 if gt e me 1768 me = e 1769 end 1770 end 1771 ret me 1772 end 1773 1774 fn tr_compare_oracle t view uint 514 p view uint 265 om view uint 5 to f64 1775 if ne tr_build_cfg t p bitcast f32 get om 0 get om 1 0 RES_OK 1776 ret 1.0e9f64 1777 end 1778 if ne tr_init_s get om 2 bitcast f32 get om 3 RES_OK 1779 ret 1.0e9f64 1780 end 1781 n = ulong get t 0 1782 knots = ulong get om 4 1783 ks = ulong get om 1 1784 max_err = 0.0f64 1785 for kn ulong sub knots 1 bound 4096 1786 if ne tr_advance_global uint n uint knots ks 0 RES_OK 1787 ret 1.0e9f64 1788 end 1789 max_err = tr_knot_max_err mul add kn 1 n n max_err 1790 end 1791 ret max_err 1792 end 1793 1794 fn tr_init_ninit_one t view uint 514 p view uint 265 e ulong kind uint init_v f32 to void 1795 if eq kind RES_INIT_N0 1796 n0s = f64 bitcast f32 get p 7 1797 n0r = f64 bitcast f32 get p 8 1798 nd = ulong get t add RES_TOPO_EDGES mul e 2 1799 cc = f64 bitcast f32 get p add RES_PAR_CONC nd 1800 put o64_ninit mul e 2 mul n0s tr_exp64 mul n0r cc 1801 nd = ulong get t add RES_TOPO_EDGES add mul e 2 1 1802 cc = f64 bitcast f32 get p add RES_PAR_CONC nd 1803 put o64_ninit add mul e 2 1 mul n0s tr_exp64 mul n0r cc 1804 else 1805 put o64_ninit mul e 2 f64 init_v 1806 put o64_ninit add mul e 2 1 f64 init_v 1807 end 1808 end 1809 1810 fn tr_init_ninit t view uint 514 p view uint 265 kind uint init_v f32 to void 1811 ec = ulong get t 1 1812 for e ulong ec bound 192 1813 tr_init_ninit_one t p e kind init_v 1814 end 1815 end 1816 1817 fn tr_oracle_vmax_ref total ulong out_pair edit f64 2 to void 1818 vmax = 0.0f64 1819 ref_err = 0.0f64 1820 for q ulong total bound 262144 1821 vt = get tr_vtight q 1822 av = tr_abs64 vt 1823 if gt av vmax 1824 vmax = av 1825 end 1826 e = tr_abs64 sub get tr_vref q vt 1827 if gt e ref_err 1828 ref_err = e 1829 end 1830 end 1831 put out_pair 0 vmax 1832 put out_pair 1 ref_err 1833 end 1834 1835 fn tr_oracle_sweep t view uint 514 p view uint 265 om edit uint 5 vmax f64 to void 1836 hs = new f32 5 0.0f32 1837 put hs 0 1.0e-4f32 1838 put hs 1 5.0e-5f32 1839 put hs 2 2.0e-5f32 1840 put hs 3 1.0e-5f32 1841 put hs 4 5.0e-6f32 1842 ks = new uint 5 0 1843 put ks 0 1 1844 put ks 1 2 1845 put ks 2 5 1846 put ks 3 10 1847 put ks 4 20 1848 for c ulong 5 bound 5 1849 put om 0 bitcast uint get hs c 1850 put om 1 get ks c 1851 me = tr_compare_oracle t p view om 1852 tr_check le me mul 1.0e-6f64 vmax 1853 end 1854 end 1855 1856 fn tr_oracle_case t view uint 514 p view uint 265 kind uint init_v f32 knots ulong to void 1857 tr_init_ninit t p kind init_v 1858 tr_check eq o64_run t p knots 1.0e-10f64 1.0e-14f64 0 0 1859 tr_check eq o64_run t p knots 1.0e-6f64 1.0e-8f64 1 0 1860 pr = new f64 2 0.0f64 1861 tr_oracle_vmax_ref mul knots ulong get t 0 pr 1862 vmax = get pr 0 1863 tr_check gt vmax 0.0f64 1864 tr_check le get pr 1 mul 1.0e-9f64 vmax 1865 om = new uint 5 0 1866 put om 2 kind 1867 put om 3 bitcast uint init_v 1868 put om 4 uint knots 1869 tr_oracle_sweep t p om vmax 1870 tr_wstr tr_orc_ok 1871 end 1872 1873 fn tr_fill_lorenz13 kn ulong to void 1874 for i ulong mul 13 kn bound 32768 1875 put tr_tab i 0.0f32 1876 end 1877 twopi = 6.`283185307179586f64` 1878 for k ulong kn bound 2048 1879 t_s = mul mul twopi 20.0f64 mul f64 k 1.0e-4f64 1880 put tr_tab mul k 13 f32 div add mul mul 15.0f64 tr_sin64_exact t_s 1.05e-10f64 1.0e-9f64 10.0f64 1881 put tr_tab add mul k 13 1 f32 div add mul mul 15.0f64 tr_sin64_exact add t_s 1.0f64 1.05e-10f64 1.0e-9f64 10.0f64 1882 put tr_tab add mul k 13 12 f32 div add mul mul 15.0f64 tr_sin64_exact add t_s 2.0f64 1.05e-10f64 1.0e-9f64 10.0f64 1883 end 1884 end 1885 1886 fn test_oracle_agreement to void 1887 t = new uint 514 0 1888 p = new uint 265 0 1889 _r = res_topology_chain 2 1 t 1890 _r = res_params_reference RES_REF_NARMA 2 p 1891 c2 = new f32 2 0.0f32 1892 put c2 0 1.0e-10f32 1893 tr_fill_const 2001 2 view c2 1894 tr_oracle_case view t view p RES_INIT_N0 0.0f32 2001 1895 1896 _r = res_topology_chain 5 4 t 1897 _r = res_params_reference RES_REF_NARMA 5 p 1898 put tr_rng 0 7 1899 kn = tr_fill_masked 5 100 2 1.0e-10f32 1900 tr_oracle_case view t view p RES_INIT_N0 0.0f32 kn 1901 1902 tr_check eq fx_hex13 t RES_OK 1903 _r = res_params_reference RES_REF_LORENZ 13 p 1904 tr_fill_lorenz13 1001 1905 tr_oracle_case view t view p RES_INIT_CONST 1.0f32 1001 1906 end 1907 1908 note ================================================================ 1909 note Test 14: Readout & NRMSE 1910 note ================================================================ 1911 1912 fn test_readout_nrmse to void 1913 ref = new f64 4 0.0f64 1914 put ref 0 1.0f64 1915 put ref 1 2.0f64 1916 put ref 2 3.0f64 1917 put ref 3 4.0f64 1918 pred = new f64 4 0.0f64 1919 put pred 0 1.0f64 1920 put pred 1 2.0f64 1921 put pred 2 3.0f64 1922 put pred 3 5.0f64 1923 flat = new f64 4 2.5f64 1924 c4 = new f64 4 7.0f64 1925 v = new f64 1 0.0f64 1926 tr_check eq res_nrmse_f64 view ref view pred v RES_OK 1927 tr_near get v 0 0.`4472135954999579f64` 1.0e-15f64 1928 ref2 = new f64 4 0.0f64 1929 put ref2 0 1.0f64 1930 put ref2 1 2.0f64 1931 put ref2 2 3.0f64 1932 put ref2 3 4.0f64 1933 tr_check eq res_nrmse_f64 view ref view ref2 v RES_OK 1934 tr_check eq get v 0 0.0f64 1935 tr_check eq res_nrmse_f64 view ref view flat v RES_OK 1936 tr_check eq get v 0 1.0f64 1937 tr_check eq res_nrmse_f64 view c4 view ref v RES_ERR_SINGULAR 1938 tr_check eq res_nrmse_f64 part ref 0 1 part pred 0 1 v RES_ERR_PARAM 1939 wn = new f64 4 1.0f64 1940 put wn 1 bitcast f64 ulong 0x7ff8000000000000 1941 tr_check eq res_nrmse_f64 view wn view pred v RES_ERR_NONFINITE 1942 end 1943 1944 fn tr_fill_ro_data x edit f64 180 y edit f64 120 to void 1945 put tr_rng 0 99 1946 for s ulong 60 bound 60 1947 x0 = sub mul tr_runit 2.0f64 1.0f64 1948 x1 = sub mul tr_runit 2.0f64 1.0f64 1949 x2 = sub mul tr_runit 2.0f64 1.0f64 1950 put x mul s 3 x0 1951 put x add mul s 3 1 x1 1952 put x add mul s 3 2 x2 1953 put y mul s 2 add add add 0.5f64 mul 2.0f64 x0 mul -1.0f64 x1 mul 0.25f64 x2 1954 put y add mul s 2 1 add -3.0f64 mul 0.125f64 x1 1955 end 1956 end 1957 1958 fn tr_test_ro_degen x view f64 180 y view f64 120 rws edit ulong 67334 to void 1959 meta = new ulong 4 0 1960 put meta 0 60 1961 put meta 1 2 1962 put meta 2 2 1963 xd = new f64 120 0.0f64 1964 for s ulong 60 bound 60 1965 put xd mul s 2 get x mul s 3 1966 put xd add mul s 2 1 get x mul s 3 1967 end 1968 put meta 3 bitcast ulong 0.0f64 1969 tr_check eq res_readout_fit_ws view xd y view meta rws RES_ERR_SINGULAR 1970 put meta 3 bitcast ulong 1.0e-3f64 1971 tr_check eq res_readout_fit_ws view xd y view meta rws RES_OK 1972 put meta 1 3 1973 put meta 3 bitcast ulong -1.0f64 1974 tr_check eq res_readout_fit_ws x y view meta rws RES_ERR_PARAM 1975 end 1976 1977 fn test_readout to void 1978 x = new f64 180 0.0f64 1979 y = new f64 120 0.0f64 1980 tr_fill_ro_data x y 1981 rws = new ulong 67334 0 1982 ro = new ulong 1031 0 1983 meta = new ulong 4 0 1984 put meta 0 60 1985 put meta 1 3 1986 put meta 2 2 1987 put meta 3 bitcast ulong 0.0f64 1988 tr_check eq res_readout_fit_ws view x view y view meta rws RES_OK 1989 res_readout_extract view rws view meta ro 1990 tr_nearabs bitcast f64 get ro 3 0.5f64 1.0e-12f64 1991 tr_nearabs bitcast f64 get ro 7 2.0f64 1.0e-12f64 1992 tr_nearabs bitcast f64 get ro 11 -1.0f64 1.0e-12f64 1993 tr_nearabs bitcast f64 get ro 15 0.25f64 1.0e-12f64 1994 tr_nearabs bitcast f64 get ro 4 -3.0f64 1.0e-12f64 1995 tr_nearabs bitcast f64 get ro 12 0.125f64 1.0e-12f64 1996 yout = new f64 2 0.0f64 1997 tr_check eq res_readout_apply view ro part x 15 3 yout RES_OK 1998 tr_nearabs get yout 0 get y 10 1.0e-12f64 1999 put meta 3 bitcast ulong 1.`0e12f64` 2000 tr_check eq res_readout_fit_ws view x view y view meta rws RES_OK 2001 res_readout_extract view rws view meta ro 2002 mean = 0.0f64 2003 for s ulong 60 bound 60 2004 mean = add mean get y mul s 2 2005 end 2006 mean = div mean 60.0f64 2007 tr_nearabs bitcast f64 get ro 3 mean 1.0e-6f64 2008 tr_nearabs bitcast f64 get ro 7 0.0f64 1.0e-9f64 2009 tr_test_ro_degen view x view y rws 2010 put meta 3 bitcast ulong 0.0f64 2011 put x 7 bitcast f64 ulong 0x7ff8000000000000 2012 tr_check eq res_readout_fit_ws view x view y view meta rws RES_ERR_NONFINITE 2013 test_readout_nrmse 2014 end 2015 2016 fn main to int 2017 put tr_rng 0 or shl ulong 0x9e3779b9 32 ulong 0x7f4a7c15 2018 test_topology 2019 test_reference_lattices 2020 test_params 2021 test_identity 2022 test_zero_input_fixed_point 2023 test_decay 2024 test_charging 2025 test_saturation 2026 test_connected_and_disconnected 2027 test_reproducibility 2028 test_refusals 2029 test_membrane_guard 2030 test_oracle_agreement 2031 test_readout 2032 tr_wstr tr_hdr 2033 tr_wu64 1 get tr_checks 0 2034 tr_wstr tr_chks 2035 tr_wu64 1 get tr_fail_cnt 0 2036 tr_wstr tr_fld 2037 if ne get tr_fail_cnt 0 0 2038 tr_wstr tr_fail 2039 ret 1 2040 end 2041 tr_wstr tr_pass 2042 ret 0 2043 end