boofun.utils.math
Lightweight math helpers shared across BooFun modules.
Functions
|
Convert binary tuple (LSB first) to integer. |
|
Return n bits of i as a list (MSB first). |
|
Yield cartesian product rows from sequences. |
Generate all permutations of [0, 1, ..., n-1]. |
|
|
Compute Hamming distance between two integers (number of differing bits). |
Alias for popcnt - number of 1 bits in x. |
|
|
Convert integer x to an n-bit binary tuple (LSB first). |
|
Classical binary Krawchouk polynomial K_k(x; n). |
|
Legacy variant with (-2)^j weights (kept for completeness). |
|
Convert num to an n-digit binary list (MSB first). |
|
Safe binomial coefficient with bounds guarding. |
|
Return the population count of an integer. |
|
Return the parity of the population count. |
|
Yield subsets of sequence a (optionally fixed size). |
|
Compute the Kronecker product of A and B. |
- boofun.utils.math.subsets(a: Sequence[int] | int, k: int | None = None) Iterator[Tuple[int, ...]][source]
Yield subsets of sequence a (optionally fixed size).
- boofun.utils.math.cartesian(seqs: Sequence[Sequence]) Iterator[Tuple][source]
Yield cartesian product rows from sequences.
- boofun.utils.math.num2bin_list(num: int, n_digits: int) List[int][source]
Convert num to an n-digit binary list (MSB first).
- boofun.utils.math.tensor_product(A: ndarray | Sequence, B: ndarray | Sequence) ndarray[source]
Compute the Kronecker product of A and B.
- boofun.utils.math.krawchouk(n: int, k: int, x: int) int[source]
Classical binary Krawchouk polynomial K_k(x; n).
- boofun.utils.math.krawchouk2(n: int, k: int, x: int) int[source]
Legacy variant with (-2)^j weights (kept for completeness).
- boofun.utils.math.hamming_distance(x: int, y: int) int[source]
Compute Hamming distance between two integers (number of differing bits).
- boofun.utils.math.generate_permutations(n: int) Iterator[Tuple[int, ...]][source]
Generate all permutations of [0, 1, …, n-1].