boofun.core.factory

Classes

BooleanFunctionFactory()

Factory for creating BooleanFunction instances from various representations.

class boofun.core.factory.BooleanFunctionFactory[source]

Factory for creating BooleanFunction instances from various representations.

classmethod create(boolean_function_cls: Type, data: Any = None, **kwargs)[source]

Main factory method that dispatches to specialized creators based on input data type.

Parameters:
  • boolean_function_cls – The BooleanFunction class to instantiate

  • data – Input data in one of the supported formats

  • **kwargs – Additional arguments (n_vars, space, rep_type, etc.)

Returns:

BooleanFunction instance

Raises:

Example

>>> bf.create([0, 1, 1, 0])  # From truth table
>>> bf.create(lambda x: x[0] ^ x[1], n=2)  # From function
classmethod from_truth_table(boolean_function_cls, truth_table, rep_type='truth_table', **kwargs)[source]

Create from truth table data.

Parameters:
  • boolean_function_cls – The BooleanFunction class to instantiate

  • truth_table – List or array of boolean values (length must be power of 2)

  • rep_type – Representation type name (default “truth_table”)

  • **kwargs – Additional arguments

Returns:

BooleanFunction instance

Raises:

InvalidTruthTableError – If truth table size is not a power of 2

classmethod from_function(boolean_function_cls, func, rep_type='function', domain_size=None, **kwargs)[source]

Create from callable function

classmethod from_scipy_distribution(boolean_function_cls, distribution, rep_type='distribution', **kwargs)[source]

Create from scipy.stats distribution

classmethod from_polynomial(boolean_function_cls, coeffs, rep_type='polynomial', **kwargs)[source]

Create from polynomial coefficients

classmethod from_multilinear(boolean_function_cls, coeffs, rep_type='fourier_expansion', **kwargs)[source]

Create from multilinear polynomial coefficients

classmethod from_iterable(boolean_function_cls, data, rep_type='iterable_rep', **kwargs)[source]

Create from streaming truth table

classmethod from_symbolic(boolean_function_cls, expression, rep_type='symbolic', **kwargs)[source]

Create from symbolic expression string

classmethod from_input_invariant_truth_table(boolean_function_cls, true_inputs, rep_type='truth_table', **kwargs)[source]

Create from set of true input vectors

classmethod create_composite(boolean_function_cls, operator, left_func, right_func, rep_type='symbolic', **kwargs)[source]

Create composite function from BooleanFunctions or scalars.

Prefers truth-table composition when both operands are BooleanFunction instances on the same domain/space, while still recording the symbolic expression for readability. Falls back to symbolic-only composition when truth tables are unavailable (e.g., mixing scalars or mismatched domains).

classmethod compose_truth_tables(boolean_function_cls, outer_func, inner_func, rep_type: str = 'truth_table', **kwargs)[source]

Compose two BooleanFunction instances via truth tables.

Mirrors the legacy BooleanFunc.compose semantics: if outer has n variables and inner has m variables, the result is a function on n * m variables obtained by feeding disjoint copies of inner into each input of outer.

classmethod from_dnf(boolean_function_cls, dnf_formula, rep_type='dnf', **kwargs)[source]

Create from DNF (Disjunctive Normal Form) formula.

Parameters:
  • boolean_function_cls – The BooleanFunction class to instantiate

  • dnf_formula – A DNFFormula object

  • rep_type – Representation type (default “dnf”)

  • **kwargs – Additional arguments (n_vars, space, etc.)

Returns:

BooleanFunction instance

classmethod from_cnf(boolean_function_cls, cnf_formula, rep_type='cnf', **kwargs)[source]

Create from CNF (Conjunctive Normal Form) formula.

Parameters:
  • boolean_function_cls – The BooleanFunction class to instantiate

  • cnf_formula – A CNFFormula object

  • rep_type – Representation type (default “cnf”)

  • **kwargs – Additional arguments (n_vars, space, etc.)

Returns:

BooleanFunction instance

classmethod from_file(boolean_function_cls, path, **kwargs)[source]

Create from file (JSON, .bf, or DIMACS CNF).

Parameters:
  • boolean_function_cls – The BooleanFunction class to instantiate

  • path – Path to file (str or Path object)

  • **kwargs – Additional arguments passed to the loader

Returns:

BooleanFunction instance

Example

>>> bf.create("function.json")
>>> bf.create("function.bf")
>>> bf.create("function.cnf")