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 a packed truth table from a numpy array. |
Check if bitarray is available. |
|
|
Compare memory usage for different truth table representations. |
Classes
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.