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:

  1. Import old BooleanFunc objects as new BooleanFunction

  2. Export new BooleanFunction to legacy format

  3. Wrap legacy objects for analysis with new tools

  4. 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

convert_legacy_function(legacy_class, ...)

Generic conversion function for custom legacy classes.

from_legacy(legacy_func[, import_fourier])

Convert a legacy BooleanFunc object to a modern BooleanFunction.

is_legacy_object(obj)

Check if an object is a legacy BooleanFunc instance.

to_legacy(func)

Convert a modern BooleanFunction to legacy format (list-based).

Classes

LegacyWrapper(func)

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

property f: List[int]

Truth table as list (legacy format).

property k: int

Number of variables (legacy naming).

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.

sensitivity(x: int) int[source]

Compute sensitivity at input x.

influence(i: int) float[source]

Compute influence of variable i.

total_influence() float[source]

Compute total influence.

bias() float[source]

Compute bias of the function.

property modern: BooleanFunction

Get the underlying modern BooleanFunction.

boofun.core.legacy_adapter.is_legacy_object(obj: Any) bool[source]

Check if an object is a legacy BooleanFunc instance.

Parameters:

obj – Object to check

Returns:

True if obj appears to be a legacy BooleanFunc