def xor_bits

bend-collections-laws-math@1.0.0.0 · spec/math/random/pcg.bend:29

import bend-collections-laws-math@1.0.0.0/spec/math/random/pcg.bend as Pcg
import Base
import bend-collections-laws-math@1.0.0.0/spec/lib/common.bend as C

29# the exclusive or of the low w bits of a and b
30def xor_bits(w: Nat, +a: Nat, +b: Nat) -> Nat:
31  match w:
32    case 0n:
33      0n
34    case 1n+k:
35      Nat.add(b2n(Bool.not(Nat.is_eq(C.bit(a), C.bit(b)))), Nat.double(xor_bits(k, C.half(a), C.half(b))))

Uses (8)

Used by (13)