boofun.core.representations.packed_truth_table

Packed truth table representation using bitarray for memory efficiency.

This module provides memory-optimized truth table storage using the bitarray library, reducing memory usage from 8 bytes per entry (numpy bool) to 1 bit.

For n=20: standard numpy = 8MB, bitarray = 128KB (64x smaller) For n=24: standard numpy = 128MB, bitarray = 2MB (64x smaller)

Functions

create_packed_truth_table(truth_table)

Create a packed truth table from a numpy array.

is_bitarray_available()

Check if bitarray is available.

memory_comparison(n_vars)

Compare memory usage for different truth table representations.

Classes

PackedTruthTableRepresentation()

Memory-efficient truth table using bitarray (1 bit per entry).

boofun.core.representations.packed_truth_table.is_bitarray_available() bool[source]

Check if bitarray is available.

class boofun.core.representations.packed_truth_table.PackedTruthTableRepresentation[source]

Memory-efficient truth table using bitarray (1 bit per entry).

This is ideal for large Boolean functions (n > 14) where memory becomes a concern. Provides 8x memory savings compared to numpy bool arrays.

Falls back to numpy if bitarray is not installed.

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

Evaluate the packed truth table at given inputs.

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

  • data – Packed truth table (bitarray or numpy fallback)

  • space – Evaluation space

  • n_vars – Number of variables

Returns:

Boolean result(s)

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

Export packed truth table in serializable format.

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

Convert from any representation to packed truth table.

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

Convert packed truth table to another representation.

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

Create empty packed truth table.

is_complete(data: Any) bool[source]

Check if representation is complete.

to_numpy(data: Any) ndarray[source]

Convert to numpy boolean array.

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

Return time complexity for packed operations.

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

Return storage requirements for packed representation.

boofun.core.representations.packed_truth_table.create_packed_truth_table(truth_table: ndarray) Dict[str, Any][source]

Create a packed truth table from a numpy array.

Parameters:

truth_table – Boolean numpy array

Returns:

Packed truth table data structure

boofun.core.representations.packed_truth_table.memory_comparison(n_vars: int) Dict[str, str][source]

Compare memory usage for different truth table representations.

Parameters:

n_vars – Number of variables

Returns:

Dictionary with memory comparisons