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 / turing / qcont_kat_gen.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | note |
| 4 | note tests/turing/qcont_kat_gen.om -- Composite Simpson known-answer generator |
| 5 | note for qint.v1 in pure seeded OM-2. Composed after src/turing/ty_qcont_lib.om. |
| 6 | |
| 7 | const QKAT_PANELS ulong 4096 |
| 8 | |
| 9 | text t_qk_s "s=" |
| 10 | text t_qk_zc " zc=" |
| 11 | text t_qk_bt " bits=" |
| 12 | text t_qk_ok " ok\n" |
| 13 | text t_qk_rf " REFUSED\n" |
| 14 | text t_qk_dot "." |
| 15 | |
| 16 | global g_qko uchar 512 |
| 17 | global g_qkl ulong 1 |
| 18 | global g_qks f64 3 |
| 19 | global g_qkz f64 6 |
| 20 | |
| 21 | fn qk_flush to void |
| 22 | n = get g_qkl 0 |
| 23 | if gt n 0 |
| 24 | _w = write 1 g_qko 0 n |
| 25 | put g_qkl 0 0 |
| 26 | end |
| 27 | end |
| 28 | |
| 29 | fn qk_putc b uchar to void |
| 30 | n = get g_qkl 0 |
| 31 | if ge n 512 |
| 32 | qk_flush |
| 33 | n = 0 |
| 34 | end |
| 35 | put g_qko n b |
| 36 | put g_qkl 0 add n 1 |
| 37 | end |
| 38 | |
| 39 | fn qk_puts s view uchar * to void |
| 40 | n = len s |
| 41 | for i ulong n |
| 42 | qk_putc get s i |
| 43 | end |
| 44 | end |
| 45 | |
| 46 | fn qk_put_u64 v ulong to void |
| 47 | if eq v 0 |
| 48 | qk_putc uchar 48 |
| 49 | ret |
| 50 | end |
| 51 | x = v |
| 52 | d = ulong 1 |
| 53 | while ge div x d 10 |
| 54 | d = mul d 10 |
| 55 | end |
| 56 | while gt d 0 |
| 57 | qk_putc uchar add 48 rem div x d 10 |
| 58 | d = div d 10 |
| 59 | end |
| 60 | end |
| 61 | |
| 62 | fn qk_put_f x f64 dp ulong to void |
| 63 | ax = x |
| 64 | if lt ax f64 0.0 |
| 65 | qk_putc uchar 45 |
| 66 | ax = sub f64 0.0 ax |
| 67 | end |
| 68 | ip = ulong ax |
| 69 | qk_put_u64 ip |
| 70 | qk_putc uchar 46 |
| 71 | fr = sub ax f64 ip |
| 72 | for i ulong dp |
| 73 | fr = mul fr f64 10.0 |
| 74 | dig = ulong fr |
| 75 | if gt dig 9 |
| 76 | dig = 9 |
| 77 | end |
| 78 | qk_putc uchar add 48 dig |
| 79 | fr = sub fr f64 dig |
| 80 | end |
| 81 | end |
| 82 | |
| 83 | fn qkat_pt zc f64 u f64 to f64 |
| 84 | t = mul add mul f64 2.0 zc u f64 0.5 |
| 85 | ret q_exp mul sub f64 0.0 u t |
| 86 | end |
| 87 | |
| 88 | fn qkat_simpson zc f64 w f64 to f64 |
| 89 | h = div w f64 QKAT_PANELS |
| 90 | hw = mul w f64 0.5 |
| 91 | sum = f64 0.0 |
| 92 | for i ulong add QKAT_PANELS 1 |
| 93 | fv = qkat_pt zc sub mul h f64 i hw |
| 94 | wt = f64 2.0 |
| 95 | if or eq i 0 eq i QKAT_PANELS |
| 96 | wt = f64 1.0 |
| 97 | else |
| 98 | if ne and i 1 0 |
| 99 | wt = f64 4.0 |
| 100 | end |
| 101 | end |
| 102 | sum = add sum mul fv wt |
| 103 | end |
| 104 | ret div mul sum h f64 3.0 |
| 105 | end |
| 106 | |
| 107 | fn qkat_bound zc f64 w f64 to f64 |
| 108 | az = q_fabs zc |
| 109 | t = add az mul w f64 0.5 |
| 110 | t2 = mul t t |
| 111 | he = add add mul t2 t2 mul f64 6.0 t2 f64 3.0 |
| 112 | h = div w f64 QKAT_PANELS |
| 113 | h2 = mul h h |
| 114 | e1 = q_exp add mul az w div mul w w f64 8.0 |
| 115 | ret mul mul div mul h2 h2 f64 180.0 e1 he |
| 116 | end |
| 117 | |
| 118 | note Composite Simpson over [zlo, zhi] with 4096 panels. |
| 119 | note Writes bits -> g_qret_f[4], rel_bound -> g_qret_f[5]. Returns 0 or -1 if bound > 1e-12. |
| 120 | fn qkat_ref scale f64 loc f64 k long to long |
| 121 | delta = q_delta |
| 122 | s = scale |
| 123 | if lt s q_sd_min |
| 124 | s = q_sd_min |
| 125 | end |
| 126 | zc = div sub mul add f64 k f64 0.5 delta loc s |
| 127 | w = div delta s |
| 128 | iv = qkat_simpson zc w |
| 129 | bd = qkat_bound zc w |
| 130 | t1 = add mul mul zc zc f64 0.5 q_hln2pi |
| 131 | bits = div sub t1 q_ln iv q_ln2 |
| 132 | put g_qret_f 4 bits |
| 133 | put g_qret_f 5 bd |
| 134 | if gt bd f64 0.000000000001 |
| 135 | ret -1 |
| 136 | end |
| 137 | ret 0 |
| 138 | end |
| 139 | |
| 140 | fn main to int |
| 141 | put g_qks 0 q_sd_min |
| 142 | put g_qks 1 f64 1.0 |
| 143 | put g_qks 2 f64 1000.0 |
| 144 | put g_qkz 0 f64 0.0 |
| 145 | put g_qkz 1 f64 1.0 |
| 146 | put g_qkz 2 f64 5.0 |
| 147 | put g_qkz 3 f64 30.0 |
| 148 | put g_qkz 4 f64 2048.0 |
| 149 | put g_qkz 5 f64 4096.0 |
| 150 | for i ulong 3 |
| 151 | si = get g_qks i |
| 152 | for j ulong 6 |
| 153 | zj = get g_qkz j |
| 154 | k = long -12345 |
| 155 | m = sub mul add f64 k f64 0.5 q_delta mul zj si |
| 156 | rc = qkat_ref si m k |
| 157 | qk_puts t_qk_s |
| 158 | qk_put_f si 6 |
| 159 | qk_puts t_qk_zc |
| 160 | qk_put_f zj 1 |
| 161 | qk_puts t_qk_bt |
| 162 | qk_put_f get g_qret_f 4 6 |
| 163 | if ne rc 0 |
| 164 | qk_puts t_qk_rf |
| 165 | else |
| 166 | qk_puts t_qk_ok |
| 167 | end |
| 168 | end |
| 169 | end |
| 170 | qk_flush |
| 171 | ret 0 |
| 172 | end |