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 / seed / qualification / om2 / fixtures / oracle / kiv.py

28 lines · 1168 bytes Raw Blame History
1# Independent cross-check of kiv.out (bc): exact integers (Newton) and decimal at 120 digits.
2import sys
3from decimal import Decimal, getcontext, ROUND_FLOOR
4getcontext().prec = 120
5def primes(n):
6 out, p = [], 2
7 while len(out) < n:
8 if all(p % d for d in range(2, int(p**0.5) + 1)): out.append(p)
9 p += 1
10 return out
11def iroot(n, k):
12 x = 1 << ((n.bit_length() + k - 1) // k)
13 while True:
14 y = ((k - 1) * x + n // x ** (k - 1)) // k
15 if y >= x: return x
16 x = y
17P = primes(64)
18K = [iroot(p << 96, 3) % 2**32 for p in P]
19H = [iroot(p << 64, 2) % 2**32 for p in P[:8]]
20def dfrac(p, k):
21 r = Decimal(p) ** (Decimal(1) / Decimal(k))
22 f = r - r.to_integral_value(rounding=ROUND_FLOOR)
23 return int((f * (Decimal(2) ** 32)).to_integral_value(rounding=ROUND_FLOOR))
24assert K == [dfrac(p, 3) for p in P] and H == [dfrac(p, 2) for p in P[:8]]
25got = [l.split() for l in open(sys.argv[1])]
26assert [int(g[3]) for g in got if g[0] == 'K'] == K and [int(g[3]) for g in got if g[0] == 'H'] == H
27assert [int(g[2]) for g in got if g[0] == 'K'] == P
28print("PASS bc K/H equal python exact-integer and decimal(120) derivations")