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 / om / runtime / rx_route_core.om

46 lines · 1093 bytes Raw Blame History
1om2
2note rx_route_core.om -- Cognitive compute routing confidence binning and
3note 95% Wilson score interval in pure OM-2.
4note Replaces conf_bin, wilson_lower, wilson_upper in src/runtime/rx_route.c.
5
6const WILSON_Z f64 1.959964
7
8fn wilson_lo k ulong n ulong to f64
9 if eq n 0
10 ret 0.0f64
11 end
12 nn = f64 n
13 p = div f64 k nn
14 z2 = mul WILSON_Z WILSON_Z
15 c = add p div z2 mul 2.0f64 nn
16 t1 = div mul p sub 1.0f64 p nn
17 t2 = div z2 mul 4.0f64 mul nn nn
18 r = mul WILSON_Z fsqrt add t1 t2
19 ret div sub c r add 1.0f64 div z2 nn
20end
21
22export fn rx_rt_conf_bin conf ulong conf_one ulong bins ulong to ulong
23 if eq bins 0
24 ret 0
25 end
26 if eq conf_one 0
27 ret 0
28 end
29 if ge conf conf_one
30 ret sub bins 1
31 end
32 ret div mul conf bins conf_one
33end
34
35note Compute 95% Wilson lower (dst[0]) and upper (dst[1]) bounds as bitcast ulong.
36export fn rx_rt_wilson k ulong n ulong dst edit ulong 2 to void
37 lo = wilson_lo k n
38 hi = f64 1.0f64
39 if ne n 0
40 if le k n
41 hi = sub 1.0f64 wilson_lo sub n k n
42 end
43 end
44 put dst 0 bitcast ulong lo
45 put dst 1 bitcast ulong hi
46end