def unbiased
import bend-collections-laws-crypto@1.0.0.0/proofs/math/random/lemire.bend as Lemireimport Base
import bend-collections-laws-crypto@1.0.0.0/spec/lib/common.bend as C
import bend-collections-laws-crypto@1.0.0.0/spec/math/random/rand.bend as SR
import bend-collections-laws-crypto@1.0.0.0/proofs/lib/logic.bend as L
598# THEOREM (Lemire.unbiased): for every width w, bound 0 < n < 2^w and
599# k < n, exactly floor(2^w / n) of the 2^w outputs draw k
600def unbiased(+w: Nat, +n: Nat, +k: Nat, +hn: {Nat.is_lt(0n, n) == True{} : Bool}, +hw: {C.fits(w, n) == True{} : Bool}, +hk: {Nat.is_lt(k, n) == True{} : Bool}) -> {SR.count(w, n, k, C.shift(w, 1n)) == Nat.div(C.shift(w, 1n), n) : Nat}:
601 match n:
602 case 0n:
603 Empty.absurd({SR.count(w, 0n, k, C.shift(w, 1n)) == Nat.div(C.shift(w, 1n), 0n) : Nat}, L.false_true(hn))
604 case 1n+m:
605 unbiased_c(w, m, k, hw, hk, Nat.is_eq(SR.and_bits(w, 1n+m, m), 0n), {==})
Uses (12)
Used by (0)
No other definition uses this definition.