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/turing/test_ty_qcont.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 / turing / test_ty_qcont.om` 448 lines ยท 13005 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/turing/test_ty_qcont.om -- qint.v1 scorer + PRD1 reader unit tests 5 note in pure seeded OM-2. Composed after src/turing/ty_qcont_lib.om. 6 7 const QKAT_PANELS ulong 4096 8 9 text t_tq_fail "FAIL test_ty_qcont check=" 10 text t_tq_nl "\n" 11 text t_tq_sum1 "test_ty_qcont: " 12 text t_tq_sum2 " checks, " 13 text t_tq_sum3 " failed\n" 14 text t_tq_tmp "/tmp/tyqcont_prd_om_test.bin" 15 text t_tq_badp "/nonexistent/prd" 16 17 global g_tq_chk ulong 1 18 global g_tq_fl ulong 1 19 global g_tqo uchar 256 20 global g_tq_ss f64 3 21 global g_tq_zs f64 6 22 global g_tq_ks long 4 23 24 fn tq_puts s view uchar * to void 25 n = len s 26 for i ulong n 27 put g_tqo i get s i 28 end 29 _w = write 1 g_tqo 0 n 30 end 31 32 fn tq_put_u64 v ulong to void 33 if eq v 0 34 put g_tqo 0 uchar 48 35 _w = write 1 g_tqo 0 1 36 ret 37 end 38 n = ulong 0 39 x = v 40 while gt x 0 41 put g_tqo n uchar add 48 rem x 10 42 x = div x 10 43 n = add n 1 44 end 45 i = ulong 0 46 while lt i div n 2 47 j = sub sub n 1 i 48 tmp = get g_tqo i 49 put g_tqo i get g_tqo j 50 put g_tqo j tmp 51 i = add i 1 52 end 53 _w = write 1 g_tqo 0 n 54 end 55 56 fn chk ok bool id ulong to void 57 put g_tq_chk 0 add get g_tq_chk 0 1 58 if not ok 59 put g_tq_fl 0 add get g_tq_fl 0 1 60 tq_puts t_tq_fail 61 tq_put_u64 id 62 tq_puts t_tq_nl 63 end 64 end 65 66 fn set_g p ulong idx ulong lc f64 sc f64 to void 67 put g_qp_idx p idx 68 put g_qp_fam p TYQ_FAM_GAUSS 69 put g_qp_k p 0 70 put g_qp_loc p lc 71 put g_qp_sc p sc 72 end 73 74 fn qkat_pt zc f64 u f64 to f64 75 t = mul add mul f64 2.0 zc u f64 0.5 76 ret q_exp mul sub f64 0.0 u t 77 end 78 79 fn qkat_simpson zc f64 w f64 to f64 80 h = div w f64 QKAT_PANELS 81 hw = mul w f64 0.5 82 sum = f64 0.0 83 for i ulong add QKAT_PANELS 1 84 fv = qkat_pt zc sub mul h f64 i hw 85 wt = f64 2.0 86 if or eq i 0 eq i QKAT_PANELS 87 wt = f64 1.0 88 else 89 if ne and i 1 0 90 wt = f64 4.0 91 end 92 end 93 sum = add sum mul fv wt 94 end 95 ret div mul sum h f64 3.0 96 end 97 98 fn qkat_bound zc f64 w f64 to f64 99 az = q_fabs zc 100 t = add az mul w f64 0.5 101 t2 = mul t t 102 he = add add mul t2 t2 mul f64 6.0 t2 f64 3.0 103 h = div w f64 QKAT_PANELS 104 h2 = mul h h 105 e1 = q_exp add mul az w div mul w w f64 8.0 106 ret mul mul div mul h2 h2 f64 180.0 e1 he 107 end 108 109 fn qkat_ref scale f64 loc f64 k long to long 110 delta = q_delta 111 s = scale 112 if lt s q_sd_min 113 s = q_sd_min 114 end 115 zc = div sub mul add f64 k f64 0.5 delta loc s 116 w = div delta s 117 iv = qkat_simpson zc w 118 bd = qkat_bound zc w 119 t1 = add mul mul zc zc f64 0.5 q_hln2pi 120 bits = div sub t1 q_ln iv q_ln2 121 put g_qret_f 4 bits 122 put g_qret_f 5 bd 123 if gt bd f64 0.`000000000001` 124 ret -1 125 end 126 ret 0 127 end 128 129 fn test_lnsinhc to void 130 hi = f64 0.0001 131 lo = bitcast f64 sub bitcast ulong hi 1 132 chk lt q_fabs sub tyq_lnsinhc hi tyq_lnsinhc lo f64 0.`000000000000001` 1 133 chk lt q_fabs sub q_ln div q_sinh hi hi div f64 0.`00000001` f64 6.0 f64 0.`000000000000001` 2 134 hi2 = f64 1.0 135 lo2 = bitcast f64 sub bitcast ulong hi2 1 136 chk lt q_fabs sub tyq_lnsinhc hi2 tyq_lnsinhc lo2 f64 0.`00000000000001` 3 137 r2 = add sub f64 1.0 q_ln f64 2.0 q_log1p sub f64 0.0 q_exp f64 -2.0 138 chk lt q_fabs sub q_ln q_sinh f64 1.0 r2 f64 0.`00000000000001` 4 139 worst = f64 0.0 140 a = f64 0.`000000001` 141 while lt a f64 200.0 142 rf = f64 0.0 143 if lt a f64 0.001 144 a2 = mul a a 145 rf = sub div a2 f64 6.0 div mul a2 a2 f64 180.0 146 else 147 if gt a f64 40.0 148 rf = add sub a q_ln mul f64 2.0 a q_log1p sub f64 0.0 q_exp mul f64 -2.0 a 149 else 150 rf = q_ln div q_sinh a a 151 end 152 end 153 er = q_fabs sub rf tyq_lnsinhc a 154 if gt er worst 155 worst = er 156 end 157 a = mul a f64 1.37 158 end 159 chk lt worst f64 0.`00000000000001` 5 160 chk eq tyq_lnsinhc f64 0.0 f64 0.0 6 161 end 162 163 fn test_simpson_one si f64 zt f64 k long to void 164 m = sub mul add f64 k f64 0.5 q_delta mul zt si 165 chk eq qkat_ref si m k 0 10 166 rb = get g_qret_f 4 167 set_g 0 0 m si 168 chk eq ty_qcont_bits 0 k TYQ_OK 11 169 chk eq get g_qret_u 0 0 12 170 tol = add f64 0.`0000002` mul f64 0.`000000000001` rb 171 err = q_fabs sub get g_qret_f 0 rb 172 chk le err tol 13 173 end 174 175 fn test_simpson_kats to void 176 put g_tq_ss 0 q_sd_min 177 put g_tq_ss 1 f64 1.0 178 put g_tq_ss 2 f64 1000.0 179 put g_tq_zs 0 f64 0.0 180 put g_tq_zs 1 f64 1.0 181 put g_tq_zs 2 f64 5.0 182 put g_tq_zs 3 f64 30.0 183 put g_tq_zs 4 f64 2048.0 184 put g_tq_zs 5 f64 4096.0 185 put g_tq_ks 0 -12345 186 put g_tq_ks 1 777777 187 put g_tq_ks 2 0 188 put g_tq_ks 3 -1 189 for i ulong 3 190 si = get g_tq_ss i 191 for j ulong 6 192 zj = get g_tq_zs j 193 for q ulong 4 194 kv = get g_tq_ks q 195 test_simpson_one si zj kv 196 test_simpson_one si sub f64 0.0 zj kv 197 end 198 end 199 end 200 chk eq qkat_ref f64 0.00001 f64 0.25 5 0 14 201 rb = get g_qret_f 4 202 set_g 0 0 f64 0.25 f64 0.00001 203 chk eq ty_qcont_bits 0 5 TYQ_OK 15 204 chk eq get g_qret_u 0 1 16 205 chk le q_fabs sub get g_qret_f 0 rb add f64 0.`0000002` mul f64 0.`000000000001` rb 17 206 end 207 208 fn test_refusals to void 209 nan = q_nan 210 inf = q_inf 211 ninf = sub f64 0.0 inf 212 set_g 0 0 nan f64 1.0 213 chk eq ty_qcont_bits 0 0 TYQ_FAIL_PROTOCOL 20 214 set_g 0 0 inf f64 1.0 215 chk eq ty_qcont_bits 0 0 TYQ_FAIL_PROTOCOL 21 216 set_g 0 0 ninf f64 1.0 217 chk eq ty_qcont_bits 0 0 TYQ_FAIL_PROTOCOL 22 218 set_g 0 0 f64 0.0 nan 219 chk eq ty_qcont_bits 0 0 TYQ_FAIL_PROTOCOL 23 220 set_g 0 0 f64 0.0 inf 221 chk eq ty_qcont_bits 0 0 TYQ_FAIL_PROTOCOL 24 222 set_g 0 0 f64 0.0 f64 0.0 223 chk eq ty_qcont_bits 0 0 TYQ_FAIL_PROTOCOL 25 224 set_g 0 0 f64 0.0 f64 -1.0 225 chk eq ty_qcont_bits 0 0 TYQ_FAIL_PROTOCOL 26 226 set_g 0 0 f64 0.0 bitcast f64 shl ulong 0x80000000 32 227 chk eq ty_qcont_bits 0 0 TYQ_FAIL_PROTOCOL 27 228 set_g 0 0 f64 0.0 f64 1.0 229 chk eq ty_qcont_bits 0 TYQ_K_LIMIT TYQ_FAIL_PROTOCOL 28 230 chk eq ty_qcont_bits 0 sub 0 TYQ_K_LIMIT TYQ_FAIL_PROTOCOL 29 231 chk eq ty_qcont_bits 0 sub TYQ_K_LIMIT 1 TYQ_OK 30 232 put g_qp_fam 0 TYQ_FAM_STUDENT 233 chk eq ty_qcont_bits 0 0 TYQ_FAIL_PROTOCOL 31 234 put g_qp_fam 0 TYQ_FAM_MIX 235 chk eq ty_qcont_bits 0 0 TYQ_FAIL_PROTOCOL 32 236 put g_qp_fam 0 77 237 chk eq ty_qcont_bits 0 0 TYQ_FAIL_PROTOCOL 33 238 set_g 0 0 sub mul f64 0.5 q_delta f64 `1000000`.0 f64 1.0 239 chk eq ty_qcont_bits 0 0 TYQ_OK 34 240 chk and q_isfinite get g_qret_f 0 gt get g_qret_f 0 f64 `700000000000`.0 35 241 chk eq ty_qcont_point_ub 0 0 TYQ_OK 36 242 chk gt get g_qret_i 0 0 37 243 big150 = mul f64 `1000000000000000`.0 mul f64 `1000000000000000`.0 q_pow2i 400 244 put g_qp_loc 0 sub mul f64 0.5 q_delta big150 245 chk eq ty_qcont_bits 0 0 TYQ_OK 38 246 chk eq ty_qcont_point_ub 0 0 TYQ_FAIL_PROTOCOL 39 247 put g_qp_loc 0 sub mul f64 0.5 q_delta mul big150 q_pow2i 40 248 chk eq ty_qcont_bits 0 0 TYQ_FAIL_PROTOCOL 40 249 put g_qp_loc 0 sub mul f64 0.5 q_delta f64 `10000000`.0 250 chk eq ty_qcont_bits 0 0 TYQ_OK 41 251 chk eq ty_qcont_point_ub 0 0 TYQ_FAIL_PROTOCOL 42 252 end 253 254 fn test_symbol_and_ub to void 255 chk eq long q_floor div mul f64 -0.5 q_delta q_delta -1 50 256 set_g 0 0 f64 0.0 f64 1.0 257 chk eq ty_qcont_bits 0 0 TYQ_OK 51 258 exp_b = add f64 20.0 div q_hln2pi q_ln2 259 chk lt q_fabs sub get g_qret_f 0 exp_b f64 0.000001 52 260 b0 = get g_qret_f 0 261 chk eq ty_qcont_point_ub 0 0 TYQ_OK 53 262 chk eq get g_qret_i 0 q_llrint mul f64 `1000000`.0 b0 54 263 set_g 0 0 f64 0.0 f64 1.0 264 set_g 1 1 f64 0.5 f64 0.000001 265 set_g 2 2 f64 -2.0 f64 3.0 266 put g_qk_arr 0 0 267 put g_qk_arr 1 524288 268 put g_qk_arr 2 -100 269 chk eq ty_qcont_sum_ub 0 0 3 TYQ_OK 55 270 s_all = get g_qret_i 1 271 h_all = get g_qret_u 1 272 chk eq ty_qcont_point_ub 0 0 TYQ_OK 56 273 e0 = get g_qret_i 0 274 chk eq ty_qcont_point_ub 1 524288 TYQ_OK 57 275 e1 = get g_qret_i 0 276 chk eq get g_qret_u 0 1 58 277 chk eq ty_qcont_point_ub 2 -100 TYQ_OK 59 278 e2 = get g_qret_i 0 279 chk and eq s_all add add e0 e1 e2 eq h_all 1 60 280 put g_qp_sc 1 f64 -1.0 281 chk eq ty_qcont_sum_ub 0 0 3 TYQ_FAIL_PROTOCOL 61 282 chk eq ty_qcont_sum_ub 0 0 0 TYQ_OK 62 283 chk and eq get g_qret_i 1 0 eq get g_qret_u 1 0 63 284 for i ulong 4 285 set_g i i sub mul f64 0.5 q_delta f64 `2000000`.0 f64 1.0 286 put g_qk_arr i 0 287 end 288 chk eq ty_qcont_point_ub 0 0 TYQ_OK 64 289 chk gt get g_qret_i 0 `2000000000000000000` 65 290 chk eq ty_qcont_sum_ub 0 0 4 TYQ_FAIL_PROTOCOL 66 291 chk eq ty_qcont_bytes_ub 0 TYQ_OK 67 292 chk eq get g_qret_i 0 0 68 293 chk eq ty_qcont_bytes_ub 1000 TYQ_OK 69 294 chk eq get g_qret_i 0 `8000000000` 70 295 chk eq ty_qcont_bytes_ub `4294967295` TYQ_OK 71 296 chk eq get g_qret_i 0 mul long `8000000` long `4294967295` 72 297 chk eq ty_qcont_rider_ub 0 128 TYQ_OK 73 298 chk eq get g_qret_i 0 0 74 299 chk eq ty_qcont_rider_ub 0 0 TYQ_OK 75 300 chk eq ty_qcont_rider_ub 2 128 TYQ_OK 76 301 chk eq get g_qret_i 0 `7000000` 77 302 chk eq ty_qcont_rider_ub 3 1 TYQ_OK 78 303 chk eq get g_qret_i 0 0 79 304 chk eq ty_qcont_rider_ub 1 0 TYQ_FAIL_PROTOCOL 80 305 chk eq ty_qcont_rider_ub 1 3 TYQ_OK 81 306 chk eq get g_qret_i 0 q_llrint mul f64 `1000000`.0 mul f64 0.5 q_log2 f64 3.0 82 307 chk eq ty_qcont_floor_check 25 25600 TYQ_OK 83 308 chk eq ty_qcont_floor_check 26 25600 TYQ_FAIL_FLOOR 84 309 chk eq ty_qcont_floor_check 0 800 TYQ_OK 85 310 chk eq ty_qcont_floor_check 1 800 TYQ_FAIL_FLOOR 86 311 chk eq ty_qcont_floor_check or shl ulong 0xffffffff 32 ulong 0xffffffff 1 TYQ_FAIL_FLOOR 87 312 end 313 314 fn build_prd1 first ulong n ulong to ulong 315 for i ulong 4 316 put g_qwire i get t_p1_mag i 317 end 318 qw_wr32 0 4 1 319 for i ulong n 320 off = add PRD_HDR mul i PRD_REC 321 qw_wr32 0 off add first i 322 qw_wr32 0 add off 4 0 323 qw_wrf 0 add off 8 mul f64 0.25 f64 i 324 qw_wrf 0 add off 16 add f64 1.0 f64 i 325 end 326 ret add PRD_HDR mul n PRD_REC 327 end 328 329 fn mal_cp blen ulong to void 330 for i ulong blen 331 put g_qwire2 i get g_qwire i 332 end 333 end 334 335 fn test_prd_mal blen ulong to void 336 mal_cp blen 337 put g_qwire2 0 uchar 88 338 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 100 339 mal_cp blen 340 qw_wr32 1 4 2 341 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 101 342 mal_cp blen 343 qw_wr32 1 4 0 344 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 102 345 mal_cp blen 346 chk eq ty_prd_parse 1 5 128 4 100 TYQ_FAIL_PROTOCOL 103 347 chk eq ty_prd_parse 1 0 128 4 100 TYQ_FAIL_PROTOCOL 104 348 chk eq ty_prd_parse 1 sub blen 1 128 4 100 TYQ_FAIL_PROTOCOL 105 349 chk eq ty_prd_parse 1 sub blen 24 128 4 100 TYQ_FAIL_PROTOCOL 106 350 put g_qwire2 blen uchar 0 351 chk eq ty_prd_parse 1 add blen 1 128 4 100 TYQ_FAIL_PROTOCOL 107 352 for i ulong 24 353 put g_qwire2 add blen i uchar 0 354 end 355 chk eq ty_prd_parse 1 add blen 24 128 4 100 TYQ_FAIL_PROTOCOL 108 356 mal_cp blen 357 qw_wr32 1 32 134 358 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 109 359 mal_cp blen 360 qw_wr32 1 8 127 361 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 110 362 mal_cp blen 363 qw_wr32 1 32 128 364 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 111 365 mal_cp blen 366 qw_wr32 1 80 200 367 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 112 368 mal_cp blen 369 qw_wr32 1 12 1 370 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 113 371 mal_cp blen 372 qw_wr32 1 12 2 373 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 114 374 mal_cp blen 375 qw_wr32 1 12 3 376 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 115 377 mal_cp blen 378 qw_wr32 1 12 `4294967295` 379 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 116 380 mal_cp blen 381 qw_wrf 1 16 q_nan 382 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 117 383 mal_cp blen 384 qw_wrf 1 16 q_inf 385 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 118 386 mal_cp blen 387 qw_wrf 1 24 q_nan 388 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 119 389 mal_cp blen 390 qw_wrf 1 24 q_inf 391 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 120 392 mal_cp blen 393 qw_wrf 1 24 f64 0.0 394 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 121 395 mal_cp blen 396 qw_wrf 1 24 bitcast f64 shl ulong 0x80000000 32 397 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 122 398 mal_cp blen 399 qw_wrf 1 24 f64 -2.0 400 chk eq ty_prd_parse 1 blen 128 4 100 TYQ_FAIL_PROTOCOL 123 401 end 402 403 fn test_prd to void 404 blen = build_prd1 128 4 405 chk eq ty_prd_parse 0 blen 128 4 0 TYQ_OK 90 406 chk and eq get g_qp_idx 3 131 and eq get g_qp_loc 2 f64 0.5 and eq get g_qp_sc 2 f64 3.0 eq get g_qp_fam 2 0 91 407 chk eq ty_prd_encode 0 128 4 TYQ_OK 92 408 chk eq get g_qret_u 0 blen 93 409 same = true 410 for i ulong blen 411 if ne get g_qwire i get g_qwire2 i 412 same = false 413 end 414 end 415 chk same 94 416 chk eq ty_prd_parse 0 blen 128 0 0 TYQ_E_ARG 95 417 test_prd_mal blen 418 blen1 = build_prd1 0 1 419 qw_wrf 0 24 f64 0.`000000001` 420 chk eq ty_prd_parse 0 blen1 0 1 0 TYQ_OK 124 421 set_g 0 0 f64 0.0 f64 1.0 422 chk eq ty_prd_validate 0 TYQ_OK 125 423 put g_qp_fam 0 TYQ_FAM_MIX 424 chk eq ty_prd_validate 0 TYQ_FAIL_PROTOCOL 126 425 set_g 0 0 f64 0.0 f64 0.0 426 chk eq ty_prd_validate 0 TYQ_FAIL_PROTOCOL 127 427 set_g 0 7 q_nan f64 1.0 428 chk eq ty_prd_encode 0 7 1 TYQ_FAIL_PROTOCOL 128 429 set_g 0 8 f64 0.0 f64 1.0 430 chk eq ty_prd_encode 0 7 1 TYQ_FAIL_PROTOCOL 129 431 end 432 433 fn main to int 434 test_lnsinhc 435 test_simpson_kats 436 test_refusals 437 test_symbol_and_ub 438 test_prd 439 tq_puts t_tq_sum1 440 tq_put_u64 get g_tq_chk 0 441 tq_puts t_tq_sum2 442 tq_put_u64 get g_tq_fl 0 443 tq_puts t_tq_sum3 444 if ne get g_tq_fl 0 0 445 ret 1 446 end 447 ret 0 448 end