interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / tests / physics0 / test_pd0_osc.om

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