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.binary_tuple_to_int(bits: Sequence[int]) int[source]
Convert binary tuple (LSB first) to integer.
- Parameters:
bits – Sequence of bits (0 or 1)
- Returns:
Integer value
- boofun.utils.math.cartesian(seqs: Sequence[Sequence[Any]]) Iterator[tuple[Any, ...]][source]
Yield cartesian product rows from sequences.
- boofun.utils.math.generate_permutations(n: int) Iterator[tuple[int, ...]][source]
Generate all permutations of [0, 1, …, n-1].
- boofun.utils.math.hamming_distance(x: int, y: int) int[source]
Compute Hamming distance between two integers (number of differing bits).
- boofun.utils.math.int_to_binary_tuple(x: int, n: int) tuple[int, ...][source]
Convert integer x to an n-bit binary tuple (LSB first).
- Parameters:
x – Integer to convert
n – Number of bits
- Returns:
Tuple of n bits, e.g., (0, 1, 1) for x=6 with n=3
- 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.num2bin_list(num: int, n_digits: int) list[int][source]
Convert num to an n-digit binary list (MSB first).