boofun.core.representations.symbolic
Classes
Symbolic representation storing an expression and variable order. |
- class boofun.core.representations.symbolic.SymbolicRepresentation[source]
Symbolic representation storing an expression and variable order.
Data format: (expression: str, variables: List[str])
- evaluate(inputs: ndarray, data: Tuple[str, List[Any]], space: Space, n_vars: int) ndarray[source]
Evaluate the symbolic Boolean expression composed of sub-BooleanFunctions using bit slicing.
Inputs are integers representing bitstrings. Only the last n_vars bits are used.
Each sub-function is evaluated on a slice of those bits, passed as an integer or array of integers.
- Parameters:
inputs – np.ndarray of shape () or (batch,) — each integer encodes a bitstring.
data – Tuple (expr: str, funcs: List[BooleanFunction]) — symbolic expression and sub-functions.
space – evaluation space.
kwargs – must include ‘n_vars’: total number of bits in each bitstring.
- Returns:
Single bool or np.ndarray of bools (same shape as inputs).
- issues:
is recomputing repeated variables
- dump(data: Tuple[str, List[str]], space=None, **kwargs) Dict[str, Any][source]
Export the symbolic representation as a dictionary.
- Returns:
- {
“expression”: expr, “variables”: vars
}
- convert_from(source_repr: BooleanFunctionRepresentation, source_data: Any, space: Space, n_vars: int, **kwargs) Tuple[str, List[Any]][source]
Convert from another representation to symbolic form.
Creates a symbolic expression that calls x0(…) etc. on the original function using wrapped variables.
- Parameters:
source_repr – The original representation class.
source_data – The original representation data.
space – The evaluation space (e.g. Boolean cube).
n_vars – Number of variables in the original function.
kwargs – Must include ‘functions’ — the BooleanFunction constructor/class.
- Returns:
Tuple[str, List[BooleanFunction]] — symbolic expression and subfunctions list.
- convert_to(target_repr: BooleanFunctionRepresentation, souce_data: Any, space: Space, n_vars: int, **kwargs) ndarray[source]
Convert to another representation from Fourier expansion
- create_empty(n_vars: int, **kwargs) Tuple[str, List[str]][source]
Create an empty symbolic representation: - Empty expression string - Default variable symbols [“x0”, “x1”, …, “x{n_vars-1}”]
- is_complete(data: Tuple[str, List[str]]) bool[source]
A symbolic representation is complete if the expression is non-empty.