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 / physics0 / test_pd0_osc.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note tests/physics0/test_pd0_osc.om: Pure OM-2 differential verification of pd0_helpers.osc arithmetic. |
| 3 | note Prints PHYSICS0_OSC_DIFF: PASS|FAIL. |
| 4 | |
| 5 | text OSC_TAG "osc-diff" |
| 6 | text OSC_P1 "osc differential: runs=" |
| 7 | text OSC_P2 " mismatches=" |
| 8 | text OSC_P3 " native=om2\n" |
| 9 | text OSC_PASS "PHYSICS0_OSC_DIFF: PASS\n" |
| 10 | text OSC_FAIL "PHYSICS0_OSC_DIFF: FAIL\n" |
| 11 | |
| 12 | fn osc_const_draw lo long hi long uu long to long |
| 13 | ret add lo pd0_mul sub hi lo uu |
| 14 | end |
| 15 | |
| 16 | fn osc_noise_map u1 long u2 long u3 long u4 long sigma long to long |
| 17 | s = sub add add u1 u2 add u3 u4 long 2000000 |
| 18 | ret div mul s sigma PD0_IH_SD |
| 19 | end |
| 20 | |
| 21 | fn osc_l0_s0 s0 long s1 long to long |
| 22 | ret add s0 s1 |
| 23 | end |
| 24 | |
| 25 | fn osc_l0_s1 s1 long u long to long |
| 26 | ret add s1 u |
| 27 | end |
| 28 | |
| 29 | fn osc_l1_s0 s0 long s1 long dt long to long |
| 30 | ret add s0 pd0_mul s1 dt |
| 31 | end |
| 32 | |
| 33 | fn osc_l1_s1 s0 long s1 long u long k long dt long to long |
| 34 | ret add s1 pd0_mul add neg pd0_mul k s0 u dt |
| 35 | end |
| 36 | |
| 37 | fn osc_l2_s1 s0 long s1 long u long k long c long dt long to long |
| 38 | ret add s1 pd0_mul add sub neg pd0_mul k s0 pd0_mul c s1 u dt |
| 39 | end |
| 40 | |
| 41 | fn osc_cube s0 long to long |
| 42 | ret pd0_mul pd0_mul s0 s0 s0 |
| 43 | end |
| 44 | |
| 45 | fn osc_desc_bits nv ulong nc ulong nt ulong nl ulong to uint |
| 46 | ret add mul uint 8 uint nl mul add mul uint 8 uint add nv nc uint 24 uint nt |
| 47 | end |
| 48 | |
| 49 | fn osc_iter_dyn rng edit ulong 1 to ulong |
| 50 | mism = ulong 0 |
| 51 | dt = long 50000 |
| 52 | s0 = pd0_const rng neg PD0_BOUND PD0_BOUND |
| 53 | s1 = pd0_const rng neg PD0_BOUND PD0_BOUND |
| 54 | u = pd0_const rng long -2000000 long 2000000 |
| 55 | k = pd0_const rng long 0 long 9000000 |
| 56 | c = pd0_const rng long 0 long 2000000 |
| 57 | if ne osc_l0_s0 s0 s1 add s0 s1 |
| 58 | mism = add mism 1 |
| 59 | end |
| 60 | if ne osc_l0_s1 s1 u add s1 u |
| 61 | mism = add mism 1 |
| 62 | end |
| 63 | if ne osc_l1_s0 s0 s1 dt add s0 pd0_mul s1 dt |
| 64 | mism = add mism 1 |
| 65 | end |
| 66 | if ne osc_l1_s1 s0 s1 u k dt add s1 pd0_mul add neg pd0_mul k s0 u dt |
| 67 | mism = add mism 1 |
| 68 | end |
| 69 | if ne osc_l2_s1 s0 s1 u k c dt add s1 pd0_mul add sub neg pd0_mul k s0 pd0_mul c s1 u dt |
| 70 | mism = add mism 1 |
| 71 | end |
| 72 | if ne osc_cube s0 pd0_mul pd0_mul s0 s0 s0 |
| 73 | mism = add mism 1 |
| 74 | end |
| 75 | ret mism |
| 76 | end |
| 77 | |
| 78 | fn osc_iter_bits rng edit ulong 1 to ulong |
| 79 | nv = add ulong 1 rem pd0_splitmix64 rng ulong 4 |
| 80 | nl = rem pd0_splitmix64 rng ulong 2 |
| 81 | if ge nl nv |
| 82 | nl = ulong 0 |
| 83 | end |
| 84 | nc = add ulong 1 rem pd0_splitmix64 rng ulong 2 |
| 85 | nt = rem pd0_splitmix64 rng ulong 6 |
| 86 | p0r_clear ulong 0 |
| 87 | put p0r_nvars 0 uchar nv |
| 88 | put p0r_nlat 0 uchar nl |
| 89 | put p0r_nch 0 uchar nc |
| 90 | put p0r_neq 0 uchar 1 |
| 91 | put p0r_eq_nt p0r_eq_idx 0 0 uchar nt |
| 92 | if ne osc_desc_bits nv nc nt nl pd0_relation_description_bits ulong 0 |
| 93 | ret ulong 1 |
| 94 | end |
| 95 | ret ulong 0 |
| 96 | end |
| 97 | |
| 98 | fn osc_iter_rng rng edit ulong 1 to ulong |
| 99 | mism = ulong 0 |
| 100 | r1 = new ulong 1 0 |
| 101 | lo = pd0_const rng long -5000000 long 5000000 |
| 102 | hi = add lo pd0_const rng long 0 long 9000000 |
| 103 | uu = pd0_uniform rng |
| 104 | if ne osc_const_draw lo hi uu add lo pd0_mul sub hi lo uu |
| 105 | mism = add mism 1 |
| 106 | end |
| 107 | sigma = pd0_const rng long 0 long 500000 |
| 108 | put r1 0 get rng 0 |
| 109 | want = pd0_noise edit r1 sigma |
| 110 | u1 = pd0_uniform rng |
| 111 | u2 = pd0_uniform rng |
| 112 | u3 = pd0_uniform rng |
| 113 | u4 = pd0_uniform rng |
| 114 | if ne osc_noise_map u1 u2 u3 u4 sigma want |
| 115 | mism = add mism 1 |
| 116 | end |
| 117 | ret add mism osc_iter_bits rng |
| 118 | end |
| 119 | |
| 120 | fn main to int |
| 121 | iters = ulong 20000 |
| 122 | rng = new ulong 1 0 |
| 123 | pd0_stream edit rng ulong 0x9d0 OSC_TAG |
| 124 | mism = ulong 0 |
| 125 | runs = ulong 0 |
| 126 | for it ulong iters bound 25000 |
| 127 | mism = add mism osc_iter_dyn edit rng |
| 128 | mism = add mism osc_iter_rng edit rng |
| 129 | runs = add runs ulong 10 |
| 130 | end |
| 131 | obuf = new uchar 128 0 |
| 132 | p = pd0_buf_str edit obuf ulong 0 ulong 128 OSC_P1 |
| 133 | p = pd0_buf_u64 edit obuf p ulong 128 runs |
| 134 | p = pd0_buf_str edit obuf p ulong 128 OSC_P2 |
| 135 | p = pd0_buf_u64 edit obuf p ulong 128 mism |
| 136 | p = pd0_buf_str edit obuf p ulong 128 OSC_P3 |
| 137 | pd0_put_bytes 1 view obuf p |
| 138 | if eq mism ulong 0 |
| 139 | pd0_puts 1 OSC_PASS |
| 140 | ret 0 |
| 141 | end |
| 142 | pd0_puts 1 OSC_FAIL |
| 143 | ret 1 |
| 144 | end |