boofun.core.representations.truth_table
Classes
Truth table representation using NumPy arrays. |
- class boofun.core.representations.truth_table.TruthTableRepresentation[source]
Truth table representation using NumPy arrays.
- evaluate(inputs: ndarray, data: ndarray, space: Space, n_vars: int) ndarray[source]
Evaluate the Boolean function using its truth table.
- Parameters:
inputs – Input values - can be: - Integer indices (0 to 2^n-1) - Binary vectors (shape: (n,) or (batch, n)) - Batch of integer indices (shape: (batch,))
data – Truth table as boolean array of length 2^n
space – Evaluation space (affects input interpretation)
n_vars – Number of Boolean variables
- Returns:
Boolean result(s) - scalar for single input, array for batch
- dump(data: ndarray, space=None, **kwargs) Dict[str, Any][source]
Export the truth table.
Returns a serializable dictionary containing: - ‘table’: list of booleans - ‘n_vars’: number of variables
- convert_from(source_repr: BooleanFunctionRepresentation, source_data: Any, space: Space, n_vars: int, **kwargs) ndarray[source]
Convert from any representation by evaluating all possible inputs.
This is the universal converter - any representation can be converted to truth table by exhaustive evaluation.
- Parameters:
source_repr – Source representation strategy
source_data – Data in source format
space – Mathematical space
n_vars – Number of variables
**kwargs –
Additional options: - lenient (bool): If True, substitute False for failed evaluations
and emit a warning. Default is False (strict mode).
- Returns:
Truth table as boolean array
- Raises:
EvaluationError – If evaluation fails at any index (unless lenient=True)
- convert_to(target_repr: BooleanFunctionRepresentation, source_data: Any, space: Space, n_vars: int, **kwargs) ndarray[source]
Convert truth table to another representation.
- create_empty(n_vars: int, **kwargs) ndarray[source]
Create an empty (all-False) truth table for n variables.
- get_storage_requirements(n_vars: int) Dict[str, int][source]
Storage grows exponentially: 1 byte per entry (packed to bits).