boofun.core.adapters
Adapters for integrating legacy Boolean function implementations and external libraries.
This module provides adapters to make external Boolean function implementations compatible with the BooFun library’s representation system.
Functions
|
Adapt simple callable to BooleanFunction. |
|
Adapt legacy Boolean function. |
|
Adapt NumPy-based Boolean function. |
|
Adapt SymPy Boolean expression. |
|
Factory function for creating adapters. |
Classes
Abstract base class for Boolean function adapters. |
|
|
Adapter for simple callable functions. |
|
Protocol for external library Boolean functions. |
|
Adapter for legacy Boolean function implementations. |
|
Protocol for legacy Boolean function implementations. |
|
Adapter for NumPy-based Boolean function implementations. |
Adapter for SymPy Boolean expressions. |
- class boofun.core.adapters.LegacyBooleanFunction(*args, **kwargs)[source]
Protocol for legacy Boolean function implementations.
- __init__(*args, **kwargs)
- class boofun.core.adapters.ExternalLibraryFunction(*args, **kwargs)[source]
Protocol for external library Boolean functions.
- __init__(*args, **kwargs)
- class boofun.core.adapters.BooleanFunctionAdapter[source]
Abstract base class for Boolean function adapters.
- abstractmethod adapt(external_function: Any) BooleanFunction[source]
Adapt external function to BooFun interface.
- Parameters:
external_function – External Boolean function implementation
- Returns:
BooleanFunction compatible with BooFun system
- class boofun.core.adapters.LegacyAdapter(evaluation_method: str = 'evaluate', input_format: str = 'auto', output_format: str = 'auto', n_vars: int | None = None)[source]
Adapter for legacy Boolean function implementations.
Wraps legacy functions that may have different interfaces to work with the modern BooFun system.
- __init__(evaluation_method: str = 'evaluate', input_format: str = 'auto', output_format: str = 'auto', n_vars: int | None = None)[source]
Initialize legacy adapter.
- Parameters:
evaluation_method – Name of evaluation method in legacy function
input_format – Expected input format (“binary”, “integer”, “auto”)
output_format – Expected output format (“boolean”, “integer”, “auto”)
n_vars – Number of variables if known
- adapt(legacy_function: Any) BooleanFunction[source]
Adapt legacy function to BooFun interface.
- class boofun.core.adapters.CallableAdapter(n_vars: int | None = None, input_type: str = 'binary_vector')[source]
Adapter for simple callable functions.
Wraps Python functions or lambdas to work with BooFun system.
- __init__(n_vars: int | None = None, input_type: str = 'binary_vector')[source]
Initialize callable adapter.
- Parameters:
n_vars – Number of variables
input_type – How to pass inputs (“binary_vector”, “individual_args”, “integer”)
- adapt(callable_function: Callable) BooleanFunction[source]
Adapt callable to BooleanFunction.
- class boofun.core.adapters.SymPyAdapter[source]
Adapter for SymPy Boolean expressions.
Integrates SymPy symbolic Boolean functions with BooFun.
- adapt(sympy_expr, variables: list | None = None) BooleanFunction[source]
Adapt SymPy Boolean expression to BooleanFunction.
- Parameters:
sympy_expr – SymPy Boolean expression
variables – List of variable symbols (auto-detected if None)
- Returns:
BooleanFunction representing the SymPy expression
- class boofun.core.adapters.NumPyAdapter(vectorized: bool = True)[source]
Adapter for NumPy-based Boolean function implementations.
Handles vectorized NumPy functions and makes them compatible with BooFun.
- __init__(vectorized: bool = True)[source]
Initialize NumPy adapter.
- Parameters:
vectorized – Whether the function supports batch evaluation
- adapt(numpy_function: Callable, n_vars: int) BooleanFunction[source]
Adapt NumPy function to BooleanFunction.
- Parameters:
numpy_function – NumPy-based Boolean function
n_vars – Number of variables
- Returns:
BooleanFunction wrapper
- boofun.core.adapters.create_adapter(adapter_type: str, **kwargs) BooleanFunctionAdapter[source]
Factory function for creating adapters.
- Parameters:
adapter_type – Type of adapter (“legacy”, “callable”, “sympy”, “numpy”)
**kwargs – Adapter-specific parameters
- Returns:
Appropriate adapter instance
- boofun.core.adapters.adapt_legacy_function(legacy_func, **kwargs) BooleanFunction[source]
Adapt legacy Boolean function.
- boofun.core.adapters.adapt_callable(func: Callable, n_vars: int, **kwargs) BooleanFunction[source]
Adapt simple callable to BooleanFunction.
- boofun.core.adapters.adapt_sympy_expr(expr, variables: list | None = None) BooleanFunction[source]
Adapt SymPy Boolean expression.