boofun.core.representations.base

Classes

BooleanFunctionRepresentation()

Abstract base class for all Boolean function representations

PartialRepresentation(strategy, data[, ...])

Wrapper for handling partial/incomplete Boolean function data.

partial_representation

class boofun.core.representations.base.BooleanFunctionRepresentation[source]

Abstract base class for all Boolean function representations

abstractmethod evaluate(inputs: ndarray, data: Any, space: Space, n_vars: int) ndarray[source]

Evaluate the function on given inputs using the provided data.

Parameters:
  • inputs – Input values (binary array or boolean values)

  • data – Representation-specific data (coefficients, truth table, etc.)

Returns:

Boolean result or array of results

abstractmethod dump(data: DataType, space: Space = None, **kwargs) Dict[str, Any][source]

Export the representation data in a serializable format.

Parameters:
  • data – The representation data to export

  • space – Optional space specification (some representations need this)

  • **kwargs – Representation-specific options

Returns:

Dictionary containing the exported representation

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

Convert from another representation to this representation.

Parameters:
  • source_repr – Source representation strategy

  • source_data – Data in source format

  • **kwargs – Conversion options

Returns:

Data in this representation’s format

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

Convert from this representation to target representation.

Parameters:
  • target_repr – Target representation strategy

  • data – Data in this representation’s format

  • **kwargs – Conversion options

Returns:

Data in target representation’s format

abstractmethod create_empty(n_vars: int, **kwargs) DataType[source]

Create empty representation data structure for n variables.

abstractmethod is_complete(data: DataType) bool[source]

Check if the representation contains complete information.

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

Return time_complexity for computing/evaluating n variables.

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

Return memory/storage requirements for n variables.

class boofun.core.representations.base.PartialRepresentation(strategy: BooleanFunctionRepresentation[DataType], data: DataType, known_mask: ndarray | None = None, n_vars: int | None = None)[source]

Wrapper for handling partial/incomplete Boolean function data.

A partial representation is useful when: - Only some outputs are known (e.g., from sampling) - Data is streaming in incrementally - Function is too large to store completely

Provides: - Confidence tracking for known vs unknown inputs - Interpolation/estimation for unknown values - Completion status and statistics

Example

>>> # Create partial truth table (only some values known)
>>> known_values = {0: True, 1: False, 3: True}
>>> partial = PartialRepresentation.from_sparse(
...     n_vars=2, known_values=known_values
... )
>>> partial.completeness  # 0.75 (3 of 4 values known)
>>> partial.evaluate_with_confidence(2)  # (estimated_value, confidence)
__init__(strategy: BooleanFunctionRepresentation[DataType], data: DataType, known_mask: ndarray | None = None, n_vars: int | None = None)[source]

Initialize partial representation.

Parameters:
  • strategy – The representation strategy to use

  • data – The partial data (may have unknown values)

  • known_mask – Boolean mask indicating which values are known

  • n_vars – Number of variables (inferred from data if not provided)

classmethod from_sparse(n_vars: int, known_values: Dict[int, bool], strategy_name: str = 'truth_table') PartialRepresentation[source]

Create partial representation from sparse known values.

Parameters:
  • n_vars – Number of variables

  • known_values – Dict mapping input indices to output values

  • strategy_name – Name of representation strategy

Returns:

PartialRepresentation with known values filled in

property completeness: float

Fraction of values that are known (0.0 to 1.0).

property is_complete: bool

Check if all values are known.

property num_known: int

Number of known values.

property num_unknown: int

Number of unknown values.

is_known(idx: int) bool[source]

Check if a specific input’s output is known.

get_known_indices() ndarray[source]

Get indices of all known values.

get_unknown_indices() ndarray[source]

Get indices of all unknown values.

evaluate(inputs: ndarray, space: Space) Any[source]

Evaluate at inputs (returns None for unknown values).

Parameters:
  • inputs – Input index or array

  • space – Mathematical space

Returns:

Boolean result or None if unknown

evaluate_with_confidence(inputs: ndarray, space: Space) tuple[Any, float][source]

Evaluate with confidence measure.

For known values, confidence is 1.0. For unknown values, estimates based on known neighbors.

Parameters:
  • inputs – Input index or array

  • space – Mathematical space

Returns:

Tuple of (estimated_value, confidence)

add_value(idx: int, value: bool) None[source]

Add a known value to the partial representation.

Parameters:
  • idx – Input index

  • value – Output value

to_complete(default: bool = False) ndarray[source]

Convert to complete representation, filling unknowns with default.

Parameters:

default – Value to use for unknown entries

Returns:

Complete truth table as numpy array

to_complete_estimated() tuple[ndarray, ndarray][source]

Convert to complete representation using estimation for unknowns.

Returns:

Tuple of (values, confidence) arrays

boofun.core.representations.base.partial_representation

alias of PartialRepresentation