~/bend-docscommunity

src/math/w64.bend checks

raw source on the hub · import bend-collections-laws-math@1.0.0.0/src/math/w64.bend as W64

2 imports
import Base
import ./u64.bend as W

Definitions

def lo source · line 20 · raw

@a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> U32

def hi source · line 25 · raw

@a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> U32

def b32 source · line 30 · raw

@b:Bool -> U32

def mk source · line 37 · raw

@+l:U32 -> @+h:U32 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def of32 source · line 40 · raw

@+x:U32 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def is_zero source · line 43 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Bool

def lt source · line 46 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Bool

def le source · line 49 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Bool

def eq source · line 52 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Bool

def add_fin source · line 57 · raw

@+l:U32 -> @+al:U32 -> @+ah:U32 -> @+bh:U32 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def add source · line 60 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def add_over_fin source · line 63 · raw

@+s:U32 -> @+ah:U32 -> @c:Bool -> Bool

def add_over source · line 67 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Bool

a + b >= 2^64

def sub source · line 71 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

a - b mod 2^64

def half source · line 74 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def odd source · line 77 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Bool

def mul32_fin source · line 82 · raw

@+ll:U32 -> @+mid:U32 -> @+hh:U32 -> @mc:Bool -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def mul32_mid source · line 85 · raw

@+ll:U32 -> @+lh:U32 -> @+hl:U32 -> @+hh:U32 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def mul32_h source · line 88 · raw

@+al:U32 -> @+ah:U32 -> @+bl:U32 -> @+bh:U32 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def mul32 source · line 92 · raw

@+a:U32 -> @+b:U32 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

the full product of two U32

def mul source · line 96 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

a * b mod 2^64

def mul_over_one source · line 99 · raw

@+p:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+c:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Bool

def mul_over source · line 103 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Bool

a * b >= 2^64

def dig_t source · line 113 · raw

@+r:Nat -> @+base:Nat -> @+g:Nat -> Nat

One digit of the long division by d: (r * base + g) / d and mod d, for a remainder r < d < 2^32 and a digit g < base = 2^16, so every partial dividend r * 2^16 + g is below 2^48 (the runtime's Nat bound). The low word is taken as two 16-bit digits; the base is written 256 * 256 so the proof checker never expands a 17-bit literal.

def dig1 source · line 116 · raw

@+lo:U32 -> Nat

def dig2 source · line 119 · raw

@+lo:U32 -> Nat

def div32_fin source · line 122 · raw

@+qh:U32 -> @+q1:Nat -> @+t2:Nat -> @+d:Nat -> Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, U32)

def div32_t1 source · line 125 · raw

@+qh:U32 -> @+lo:U32 -> @+t1:Nat -> @+d:Nat -> Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, U32)

def div32 source · line 129 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+d:U32 -> Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, U32)

(a / d, a mod d) for d > 0: the high word natively, the low word by digits

def mod_step source · line 132 · raw

@+r:Nat -> @+base:Nat -> @+g:Nat -> @+d:Nat -> Nat

def mod32 source · line 136 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+d:U32 -> U32

a mod d for d > 0

def pow2 source · line 142 · raw

@k:Nat -> U32

2^k for k < 32

def bl_pick source · line 209 · raw

@+x:U32 -> @+t:U32 -> @+k:Nat -> @+base:Nat -> @big:Bool -> Pair(Nat, U32)

def bl_step source · line 216 · raw

@+k:Nat -> @st:Pair(Nat, U32) -> Pair(Nat, U32)

def bl_fin source · line 220 · raw

@st:Pair(Nat, U32) -> Nat

def bitlen source · line 225 · raw

@+x:U32 -> Nat

the number of bits of x (0 for 0), by a binary search on the top bit

def shl_lt source · line 228 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+k:Nat -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def shl_ge source · line 235 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+k:Nat -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def shl_pick source · line 238 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+k:Nat -> @small:Bool -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def shl source · line 246 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+k:Nat -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

a << k mod 2^64 for k < 64

def shr_lt source · line 249 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+k:Nat -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def shr_ge source · line 256 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+k:Nat -> @huge:Bool -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def shr_pick source · line 263 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+k:Nat -> @small:Bool -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def shr source · line 271 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+k:Nat -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

a >> k (0 for k >= 64)

def fst_q source · line 274 · raw

@p:Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, U32) -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def snd_r source · line 278 · raw

@p:Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, U32) -> U32

def q_clamp_z source · line 282 · raw

@+l:U32 -> @z:Bool -> U32

def q_clamp source · line 290 · raw

@+q:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> U32

min(q, 2^32 - 1)

def mul_32_64_fin source · line 294 · raw

@+p0:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+p1:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, U32)

the product of a U32 and a U64 as (low 64 bits, top 32 bits)

def mul_32_64 source · line 297 · raw

@+q:U32 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, U32)

def over96 source · line 301 · raw

@+xl:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+xh:U32 -> @p:Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, U32) -> Bool

the 96-bit product p exceeds x = xh * 2^64 + xl

def q_fix source · line 306 · raw

@fuel:Nat -> @+xl:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+xh:U32 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+q:U32 -> @over:Bool -> U32

q - 1 while q * b > x: at most q steps (fuel q + 1)

def q_start source · line 317 · raw

@+xl:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+xh:U32 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+q:U32 -> U32

floor(x / b) from an estimate q >= floor(x / b): down while q * b > x (at most q steps, fuel q + 1)

def est_lo source · line 324 · raw

@+q1:Nat -> @+t2:Nat -> @+d:Nat -> U32

Knuth's estimate for x = xh * 2^64 + xl < b * 2^32 and b >= 2^32, t = bits(hi(b)): with Y = x >> t (below 2^64) and B = b >> t in [2^31, 2^32), min(floor(Y / B), 2^32 - 1) is at least floor(x / b) (as B 2^t <= b) and at most 2 over it (Theorem B), so q_start takes a step or two

def est_mid source · line 327 · raw

@+lo:U32 -> @+t1:Nat -> @+d:Nat -> U32

def est_pick source · line 334 · raw

@+y:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+d:U32 -> @big:Bool -> U32

min(floor(y / d), 2^32 - 1) for d > 0: when hi(y) >= d the quotient needs more than 32 bits; otherwise the high word is its own remainder, and div32's two 16-bit Nat digit steps finish the division without dividing the high word.

def est32 source · line 341 · raw

@+y:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+d:U32 -> U32

def q_est source · line 344 · raw

@+xl:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+xh:U32 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+t:Nat -> U32

def q96 source · line 348 · raw

@+xl:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+xh:U32 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+t:Nat -> U32

floor(x / b) for x = xh * 2^64 + xl < b * 2^32 and b >= 2^32, t = bits(hi(b))

def dm_small source · line 353 · raw

@p:Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, U32) -> Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64)

def dm_big source · line 357 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+q:U32 -> Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64)

def dm_pick source · line 360 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @small:Bool -> Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64)

def divmod source · line 368 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64)

(a / b, a mod b) for b > 0

def pfst source · line 371 · raw

@p:Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64) -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def psnd source · line 375 · raw

@p:Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64) -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def quot source · line 379 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def rem source · line 382 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def red96_z source · line 388 · raw

@+xh:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+x0:U32 -> @+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @small:Bool -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

x mod m for x = xh * 2^32 + x0 with xh < m and m >= 2^32

def red96 source · line 398 · raw

@+xh:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+x0:U32 -> @+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

(the zero test of hi(m) only guards the digit: red96 is called with hi(m) != 0; it also stops the proof checker from expanding the digit in every statement that names red96)

def mul128_fin source · line 401 · raw

@+p00:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+mid:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @c1:Bool -> @+p11:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64)

def mul128_mid source · line 404 · raw

@+p00:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+p01:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+p10:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+p11:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64)

def mul128 source · line 408 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64)

the full product as (low 64 bits, high 64 bits)

def mm_big source · line 411 · raw

@+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @p:Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64) -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def mm_pick source · line 415 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @small:Bool -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def mulmod source · line 423 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

a * b mod m for a, b < m

def down32 source · line 430 · raw

@fuel:Nat -> @+x:U32 -> @+r:U32 -> @over:Bool -> U32

r - 1 while r * r > x: from r <= 65535 at most r steps (fuel r + 1), and r * r never wraps

def up_ok source · line 439 · raw

@+x:U32 -> @+r:U32 -> Bool

def up32 source · line 443 · raw

@fuel:Nat -> @+x:U32 -> @+r:U32 -> @up:Bool -> U32

r + 1 while r < 65535 and (r + 1)^2 <= x: at most 65535 - r steps

def isqrt32_fix source · line 452 · raw

@+x:U32 -> @+r:U32 -> U32

def isqrt32_est source · line 459 · raw

@+x:U32 -> @+r:U32 -> U32

floor(sqrt(x)) from any estimate r <= 65535: down while r^2 > x, then up while (r + 1)^2 <= x. The F32 square root lands within 1, so both loops take at most a step or two; the fuel covers any estimate, so the result never depends on F32's accuracy.

def isqrt32 source · line 462 · raw

@+x:U32 -> U32

def sq_over source · line 465 · raw

@+n:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+r:U32 -> Bool

def down64 source · line 468 · raw

@fuel:Nat -> @+n:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+r:U32 -> @over:Bool -> U32

def up64_ok source · line 477 · raw

@+n:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+r:U32 -> Bool

def up64 source · line 480 · raw

@fuel:Nat -> @+n:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+r:U32 -> @up:Bool -> U32

def isqrt64_fix source · line 489 · raw

@+n:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+r:U32 -> U32

def isqrt_newton source · line 494 · raw

@+n:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+r1:U32 -> U32

floor(sqrt(n)) from any estimate r1: down while r^2 > n, then up while (r + 1)^2 <= n; the fuel covers any estimate

def isqrt_big source · line 499 · raw

@+n:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+r0:U32 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

one Newton step from the F32 estimate r0 > 0 lands within a few units of floor(sqrt(n)); the correction makes the result exact for any r0

def f32_clamp32 source · line 502 · raw

@+f:F32 -> @big:Bool -> U32

def isqrt_est source · line 509 · raw

@+f:F32 -> U32

def isqrt_pick source · line 512 · raw

@+n:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @small:Bool -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def isqrt source · line 519 · raw

@+n:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def w_pow2 source · line 522 · raw

@+k:Nat -> @small:Bool -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def or_bit source · line 531 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @b:Bool -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def jam_pick source · line 534 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+k:Nat -> @huge:Bool -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def shr_jam source · line 543 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+k:Nat -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

a >> k with the bits shifted out OR-ed into bit 0 (SoftFloat's shiftRightJam64)

def clz_pick source · line 546 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @high:Bool -> Nat

def clz source · line 554 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Nat

the number of leading zero bits of a (64 for 0)

def clear0 source · line 558 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @b:Bool -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

a with bit 0 cleared when b

def cmp_pick source · line 561 · raw

@less:Bool -> @same:Bool -> Cmp

def cmp source · line 570 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Cmp

def inv_step source · line 580 · raw

@+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+x:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

x (2 - m x): doubles the correct low bits of an inverse of m mod 2^64

def minv source · line 585 · raw

@+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

-1 / m mod 2^64 for odd m (m is its own inverse mod 8; five Newton steps reach 96 >= 64 bits)

def sub_if source · line 588 · raw

@+r:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @big:Bool -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def redc_r source · line 595 · raw

@+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+r:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def redc_p source · line 598 · raw

@+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+tl:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+th:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @p:Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64) -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def redc source · line 603 · raw

@+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+mp:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @t:Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64) -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

t / 2^64 mod m for t = (tl, th) < m^2

def mont source · line 608 · raw

@+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+mp:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

a b / 2^64 mod m for a, b < m

def mbit source · line 611 · raw

@odd:Bool -> @+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+mp:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+acc:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def mpow_go source · line 619 · raw

@fuel:Nat -> @+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+mp:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+acc:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @st:Pair(0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64, Bool) -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

pow_mod_go of generic.bend on Montgomery forms x 2^64 mod m

def to_mont source · line 629 · raw

@+x:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

x 2^64 mod m for x < m, m >= 2^32

def mont_ok source · line 634 · raw

@+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Bool

m odd with 2^32 <= m < 2^63 and m minv(m) = -1 mod 2^64 (always so for odd m; checked, so the proof needs no Hensel lemma)

def mpow_m source · line 637 · raw

@+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+e:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+mp:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

def mpow source · line 641 · raw

@+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+e:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+m:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

b^e mod m for b < m and mont_ok(m)

def inv32_step source · line 646 · raw

@+m:U32 -> @+x:U32 -> U32

def minv32 source · line 650 · raw

@+m:U32 -> U32

-1 / m mod 2^32 for odd m

def sub_if32 source · line 653 · raw

@+r:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+m:U32 -> @big:Bool -> U32

def redc32_r source · line 660 · raw

@+m:U32 -> @+r:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> U32

def redc32_s source · line 663 · raw

@+m:U32 -> @+s1:U32 -> @+s2:U32 -> @+c1:Bool -> U32

def redc32_p source · line 666 · raw

@+m:U32 -> @+t:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+p:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> U32

def redc32 source · line 669 · raw

@+m:U32 -> @+mp:U32 -> @+t:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> U32

def mont32 source · line 672 · raw

@+m:U32 -> @+mp:U32 -> @+a:U32 -> @+b:U32 -> U32

def mbit32 source · line 675 · raw

@odd:Bool -> @+m:U32 -> @+mp:U32 -> @+b:U32 -> @+acc:U32 -> U32

def mpow32_go source · line 682 · raw

@fuel:Nat -> @+m:U32 -> @+mp:U32 -> @+b:U32 -> @+acc:U32 -> @st:Pair(U32, Bool) -> U32

def mont32_ok source · line 691 · raw

@+m:U32 -> Bool

def mpow32_m source · line 694 · raw

@+b:U32 -> @+e:U32 -> @+m:U32 -> @+mp:U32 -> U32

def mpow32 source · line 697 · raw

@+b:U32 -> @+e:U32 -> @+m:U32 -> U32

def small2 source · line 703 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> @+b:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Bool

a and b fit 48 bits (runtime Nats) and a has more than 16: the binary gcd then hands them to Euclid on Nat (native division); below 2^16 its few steps are cheaper

def n48 source · line 706 · raw

@+a:0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64 -> Nat

def of48_h source · line 711 · raw

@+g:Nat -> @+h:Nat -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64

the words of g < 2^64 from h = g div 2^32 (two divisions by 2^16, so no closed 2^32 appears: the proof checker would expand it in unary)

def of48 source · line 714 · raw

@+g:Nat -> 0xf86f5f1d9a594d5a5cff999100e01d03/src/math/u64.U64