boofun.core.representations.sparse_truth_table
Sparse truth table representation for Boolean functions.
This module implements memory-efficient sparse representations for Boolean functions where most outputs are 0 or 1, significantly reducing memory usage for large functions.
Classes
Adaptive truth table that automatically chooses between dense and sparse formats. |
|
Sparse truth table representation for memory efficiency. |
- class boofun.core.representations.sparse_truth_table.SparseTruthTableRepresentation(compression_threshold: float = 0.1)[source]
Sparse truth table representation for memory efficiency.
Stores only non-default values to save memory for large functions. Data format: {
‘default_value’: bool, # Value for unspecified indices ‘exceptions’: Dict[int, bool], # Indices with non-default values ‘n_vars’: int, # Number of variables ‘size’: int # Total size (2^n_vars)
}
- __init__(compression_threshold: float = 0.1)[source]
Initialize sparse representation.
- Parameters:
compression_threshold – Use sparse format if non-default ratio < threshold
- evaluate(inputs: ndarray, data: Dict[str, Any], space: Space, n_vars: int) bool | ndarray[source]
Evaluate the sparse truth table at given inputs.
- Parameters:
inputs – Input values (integer indices or binary vectors)
data – Sparse truth table data
space – Evaluation space
n_vars – Number of variables
- Returns:
Boolean result(s)
- dump(data: Dict[str, Any], space=None, **kwargs) Dict[str, Any][source]
Export sparse 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 sparse truth table.
- convert_to(target_repr: BooleanFunctionRepresentation, source_data: Any, space: Space, n_vars: int, **kwargs) ndarray[source]
Convert sparse truth table to another representation.
- create_empty(n_vars: int, **kwargs) Dict[str, Any][source]
Create empty sparse truth table (all False).
- time_complexity_rank(n_vars: int) Dict[str, int][source]
Return time complexity for sparse operations.
- class boofun.core.representations.sparse_truth_table.AdaptiveTruthTableRepresentation(sparse_threshold: float = 0.3)[source]
Adaptive truth table that automatically chooses between dense and sparse formats.
Dynamically selects the most memory-efficient representation based on the data.
- __init__(sparse_threshold: float = 0.3)[source]
Initialize adaptive representation.
- Parameters:
sparse_threshold – Use sparse format if non-default ratio < threshold
- evaluate(inputs: ndarray, data: Dict[str, Any], space: Space, n_vars: int) bool | ndarray[source]
Evaluate using the appropriate internal representation.
- convert_from(source_repr: BooleanFunctionRepresentation, source_data: Any, space: Space, n_vars: int, **kwargs) Dict[str, Any][source]
Convert and choose optimal format.
- convert_to(target_repr: BooleanFunctionRepresentation, source_data: Any, space: Space, n_vars: int, **kwargs) ndarray[source]
Convert to another representation.
- dump(data: Dict[str, Any], space=None, **kwargs) Dict[str, Any][source]
Export adaptive representation.