boofun.core.builtins

Classes

BooleanFunctionBuiltins()

Collection of standard Boolean functions used in research and testing.

class boofun.core.builtins.BooleanFunctionBuiltins[source]

Collection of standard Boolean functions used in research and testing.

classmethod majority(n: int) BooleanFunction[source]

Create majority function on n variables.

Returns 1 if more than half of the inputs are 1, 0 otherwise. For even n, ties are broken by returning 0.

Parameters:

n – Number of input variables (must be positive)

Returns:

BooleanFunction implementing the majority function

classmethod dictator(n: int, i: int = 0) BooleanFunction[source]

Create dictator function (output equals i-th input).

The function returns the value of the i-th input variable, ignoring all other inputs: f(x) = x_i.

Parameters:
  • n – Total number of input variables

  • i – Index of the dictating variable (0-indexed, default 0)

Returns:

BooleanFunction that outputs x_i

Examples

>>> bf.dictator(5)     # 5-var dictator on x₀
>>> bf.dictator(5, 2)  # 5-var dictator on x₂
classmethod tribes(k: int, n: int) BooleanFunction[source]

Generate tribes function (k-wise AND of n/k ORs).

The tribes function divides n variables into groups of k, computes OR within each group, then AND across groups.

Parameters:
  • k – Size of each tribe (group)

  • n – Total number of variables (should be divisible by k)

Returns:

BooleanFunction implementing the tribes function

Note

If n is not divisible by k, the last group will have fewer variables.

classmethod parity(n: int) BooleanFunction[source]

Create parity function on n variables.

Returns 1 if an odd number of inputs are 1, 0 otherwise.

Parameters:

n – Number of input variables

Returns:

BooleanFunction implementing the parity function

classmethod constant(value: bool, n: int) BooleanFunction[source]

Create constant function.

Parameters:
  • value – Constant value to return (True or False)

  • n – Number of input variables (for compatibility)

Returns:

BooleanFunction that always returns the constant value