boofun.core.legacy_adapter
Legacy adapter for converting old BooleanFunc objects to new BooleanFunction.
This module provides adapters to use the legacy BooleanFunc class from BooleanFunc.py with the modern boofun library, enabling:
Import old BooleanFunc objects as new BooleanFunction
Export new BooleanFunction to legacy format
Wrap legacy objects for analysis with new tools
Migrate codebases incrementally
- Example usage:
>>> from boofun.core.legacy_adapter import from_legacy, to_legacy >>> >>> # Convert legacy object to new >>> legacy_func = BooleanFunc([0, 1, 1, 0]) >>> new_func = from_legacy(legacy_func) >>> >>> # Use new analysis tools >>> from boofun.analysis import SpectralAnalyzer >>> analyzer = SpectralAnalyzer(new_func)
Functions
|
Generic conversion function for custom legacy classes. |
|
Convert a legacy BooleanFunc object to a modern BooleanFunction. |
|
Check if an object is a legacy BooleanFunc instance. |
|
Convert a modern BooleanFunction to legacy format (list-based). |
Classes
|
Wrapper that provides legacy BooleanFunc-like interface for modern functions. |
- boofun.core.legacy_adapter.from_legacy(legacy_func: Any, import_fourier: bool = False) BooleanFunction[source]
Convert a legacy BooleanFunc object to a modern BooleanFunction.
- Parameters:
legacy_func – Legacy BooleanFunc object with .f (truth table) and .k (n_vars)
import_fourier – If True and legacy has Fourier data, import it
- Returns:
New BooleanFunction with truth table representation
- Raises:
ValueError – If the legacy object doesn’t have required attributes
Example
>>> # Assuming BooleanFunc is the legacy class >>> legacy = BooleanFunc([0, 1, 1, 0]) >>> modern = from_legacy(legacy) >>> modern.evaluate(0) # Works with new API
- boofun.core.legacy_adapter.to_legacy(func: BooleanFunction) Any[source]
Convert a modern BooleanFunction to legacy format (list-based).
Note: This returns the truth table as a list, which can be passed to the legacy BooleanFunc constructor. It does NOT create a BooleanFunc object directly (to avoid importing the legacy module).
- Parameters:
func – Modern BooleanFunction
- Returns:
Tuple of (truth_table_list, n_vars) for legacy BooleanFunc constructor
Example
>>> modern = bf.create([0, 1, 1, 0]) >>> tt, k = to_legacy(modern) >>> legacy = BooleanFunc(tt) # In code that has legacy import
- class boofun.core.legacy_adapter.LegacyWrapper(func: BooleanFunction)[source]
Wrapper that provides legacy BooleanFunc-like interface for modern functions.
This allows using modern BooleanFunction objects with code that expects the legacy API, without modifying the modern object.
Example
>>> modern = bf.create([0, 1, 1, 0]) >>> wrapped = LegacyWrapper(modern) >>> wrapped.k # Legacy attribute access 2 >>> wrapped.f # Truth table as list [0, 1, 1, 0] >>> wrapped.fix(0, 1) # Legacy method, returns wrapped result
- __init__(func: BooleanFunction)[source]
Wrap a modern BooleanFunction with legacy-compatible interface.
- Parameters:
func – Modern BooleanFunction to wrap
- fix(var: int, val: int) LegacyWrapper[source]
Fix a variable (legacy method).
Returns a new LegacyWrapper around the restricted function.
- fix_single(var: int, val: int) LegacyWrapper[source]
Alias for fix() - legacy naming.
- property modern: BooleanFunction
Get the underlying modern BooleanFunction.