boofun.core.representations.polynomial

Polynomial (ANF) representation for Boolean functions.

This module implements the Algebraic Normal Form (ANF) representation, where Boolean functions are represented as multivariate polynomials over GF(2).

Functions

create_constant(value)

Create constant polynomial.

create_monomial(variables)

Create a single monomial from list of variable indices.

create_variable(var_index)

Create polynomial for single variable.

Classes

PolynomialRepresentation()

Polynomial (ANF) representation using coefficient dictionaries.

class boofun.core.representations.polynomial.PolynomialRepresentation[source]

Polynomial (ANF) representation using coefficient dictionaries.

Represents Boolean functions as polynomials over GF(2): f(x₁,…,xₙ) = ⊕ᵢ aᵢ ∏ⱼ∈Sᵢ xⱼ

Data format: Dict[frozenset, int] mapping subsets to coefficients

evaluate(inputs: ndarray, data: Dict[frozenset, int], space: Space, n_vars: int) bool | ndarray[source]

Evaluate the polynomial at given inputs.

Parameters:
  • inputs – Input values (integer indices or binary vectors)

  • data – Polynomial coefficients as {subset: coefficient}

  • space – Evaluation space

  • n_vars – Number of variables

Returns:

Boolean result(s)

dump(data: Dict[frozenset, int], space=None, **kwargs) Dict[str, Any][source]

Export polynomial in serializable format.

Returns:

Dictionary with monomials and coefficients

convert_from(source_repr: BooleanFunctionRepresentation, source_data: Any, space: Space, n_vars: int, **kwargs) Dict[frozenset, int][source]

Convert from any representation to polynomial using truth table method.

Uses the Möbius transform to compute ANF coefficients.

convert_to(target_repr: BooleanFunctionRepresentation, source_data: Any, space: Space, n_vars: int, **kwargs) ndarray[source]

Convert from polynomial to another representation.

create_empty(n_vars: int, **kwargs) Dict[frozenset, int][source]

Create empty polynomial (constant 0).

is_complete(data: Dict[frozenset, int]) bool[source]

Check if polynomial has any non-zero coefficients.

time_complexity_rank(n_vars: int) Dict[str, int][source]

Return time complexity for polynomial operations.

get_storage_requirements(n_vars: int) Dict[str, int][source]

Return storage requirements for polynomial representation.

get_degree(data: Dict[frozenset, int]) int[source]

Get the degree of the polynomial (size of largest monomial).

get_monomials(data: Dict[frozenset, int]) List[frozenset][source]

Get all monomials with non-zero coefficients.

add_polynomials(poly1: Dict[frozenset, int], poly2: Dict[frozenset, int]) Dict[frozenset, int][source]

Add two polynomials in GF(2) (XOR operation).

multiply_polynomials(poly1: Dict[frozenset, int], poly2: Dict[frozenset, int]) Dict[frozenset, int][source]

Multiply two polynomials in GF(2).

boofun.core.representations.polynomial.create_monomial(variables: List[int]) Dict[frozenset, int][source]

Create a single monomial from list of variable indices.

boofun.core.representations.polynomial.create_constant(value: bool) Dict[frozenset, int][source]

Create constant polynomial.

boofun.core.representations.polynomial.create_variable(var_index: int) Dict[frozenset, int][source]

Create polynomial for single variable.