boofun.core.conversion_graph
Lazy conversion graph system for Boolean function representations.
This module implements the conversion graph mentioned in the design document, enabling intelligent conversion between representations with optimal paths and caching for efficiency.
Functions
|
Estimate the cost of converting between representations. |
|
Find optimal conversion path between representations. |
Get the global conversion graph instance. |
|
|
Get all conversion options from a source representation. |
|
Register a custom conversion between representations. |
Classes
|
Represents the cost of converting between two representations. |
|
Represents an edge in the conversion graph. |
Manages the graph of possible conversions between representations. |
|
|
Represents a complete conversion path between representations. |
- class boofun.core.conversion_graph.ConversionCost(time_complexity: float, space_complexity: float, accuracy_loss: float = 0.0, is_exact: bool = True)[source]
Represents the cost of converting between two representations.
Includes time complexity, space complexity, and accuracy considerations.
- __init__(time_complexity: float, space_complexity: float, accuracy_loss: float = 0.0, is_exact: bool = True)[source]
Initialize conversion cost.
- Parameters:
time_complexity – Time cost (higher = more expensive)
space_complexity – Space cost (higher = more expensive)
accuracy_loss – Information loss (0 = lossless, 1 = complete loss)
is_exact – Whether conversion is mathematically exact
- class boofun.core.conversion_graph.ConversionEdge(source: str, target: str, cost: ConversionCost, converter: Callable | None = None)[source]
Represents an edge in the conversion graph.
- class boofun.core.conversion_graph.ConversionPath(edges: List[ConversionEdge])[source]
Represents a complete conversion path between representations.
- __init__(edges: List[ConversionEdge])[source]
Initialize conversion path.
- Parameters:
edges – List of conversion edges forming the path
- class boofun.core.conversion_graph.ConversionGraph[source]
Manages the graph of possible conversions between representations.
Implements Dijkstra’s algorithm to find optimal conversion paths and caches results for efficiency.
- add_edge(source: str, target: str, cost: ConversionCost, converter: Callable | None = None)[source]
Add a conversion edge to the graph.
- Parameters:
source – Source representation name
target – Target representation name
cost – Conversion cost
converter – Optional custom conversion function
- find_optimal_path(source: str, target: str, n_vars: int | None = None) ConversionPath | None[source]
Find the optimal conversion path using Dijkstra’s algorithm.
- Parameters:
source – Source representation name
target – Target representation name
n_vars – Number of variables (affects cost calculations)
- Returns:
Optimal conversion path or None if no path exists
- get_conversion_options(source: str, max_cost: float | None = None) Dict[str, ConversionPath][source]
Get all possible conversion targets from a source representation.
- Parameters:
source – Source representation name
max_cost – Maximum acceptable cost (optional)
- Returns:
Dictionary mapping target representations to optimal paths
- estimate_conversion_cost(source: str, target: str, n_vars: int | None = None) ConversionCost | None[source]
Estimate conversion cost without finding the full path.
- Parameters:
source – Source representation name
target – Target representation name
n_vars – Number of variables
- Returns:
Estimated conversion cost or None if no path exists
- boofun.core.conversion_graph.get_conversion_graph() ConversionGraph[source]
Get the global conversion graph instance.
- boofun.core.conversion_graph.find_conversion_path(source: str, target: str, n_vars: int | None = None) ConversionPath | None[source]
Find optimal conversion path between representations.
- Parameters:
source – Source representation name
target – Target representation name
n_vars – Number of variables
- Returns:
Optimal conversion path or None
- boofun.core.conversion_graph.register_custom_conversion(source: str, target: str, cost: ConversionCost, converter: Callable)[source]
Register a custom conversion between representations.
- Parameters:
source – Source representation name
target – Target representation name
cost – Conversion cost
converter – Conversion function
- boofun.core.conversion_graph.get_conversion_options(source: str, max_cost: float | None = None) Dict[str, ConversionPath][source]
Get all conversion options from a source representation.
- Parameters:
source – Source representation name
max_cost – Maximum acceptable cost
- Returns:
Dictionary of conversion options
- boofun.core.conversion_graph.estimate_conversion_cost(source: str, target: str, n_vars: int | None = None) ConversionCost | None[source]
Estimate the cost of converting between representations.
- Parameters:
source – Source representation name
target – Target representation name
n_vars – Number of variables
- Returns:
Estimated conversion cost