boofun.core.conversion_graph
Conversion graph system for Boolean function representations.
Implements two-level dispatch for converting between representations: every representation converts through truth_table as the universal hub.
source -> truth_table -> target
This is simpler and more predictable than the previous Dijkstra-based pathfinding (removed in v1.3.0), with no loss of functionality since truth_table is the one representation every other type can convert to/from.
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. |
|
Configure what happens when a conversion would create a huge truth table. |
Classes
|
Represents the cost of converting between two representations. |
|
Represents an edge in the conversion graph. |
Manages conversions between Boolean function representations. |
|
|
Represents a complete conversion path between representations. |
- boofun.core.conversion_graph.set_large_n_policy(policy: str = 'warn', threshold: int = 25) None[source]
Configure what happens when a conversion would create a huge truth table.
- Parameters:
policy – One of
"warn"(default),"raise", or"off".threshold – Number of variables above which the policy applies (default 25, meaning 2^25 = 33 million entries).
Example:
import boofun from boofun.core.conversion_graph import set_large_n_policy # I know what I'm doing -- let me materialise up to n=28 set_large_n_policy("warn", threshold=28) # Hard error for safety in automated pipelines set_large_n_policy("raise", threshold=22) # Disable the check entirely set_large_n_policy("off")
- 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.
- 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]
- class boofun.core.conversion_graph.ConversionGraph[source]
Manages conversions between Boolean function representations.
- Uses two-level dispatch through truth_table as the universal hub:
source -> truth_table -> target
Direct edges (source -> target) are used when available; otherwise the path goes through truth_table.
- add_edge(source: str, target: str, cost: ConversionCost, converter: Callable | None = None) None[source]
Add a conversion edge to the graph.
- find_optimal_path(source: str, target: str, n_vars: int | None = None) ConversionPath | None[source]
Find a conversion path from source to target.
- Strategy:
If source == target, return None (no conversion needed).
If a direct edge exists, use it.
Otherwise route through truth_table: source -> truth_table -> target.
- get_conversion_options(source: str, max_cost: float | None = None) Dict[str, ConversionPath][source]
Get all possible conversion targets from a source representation.
- 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.
- boofun.core.conversion_graph.register_custom_conversion(source: str, target: str, cost: ConversionCost, converter: Callable) None[source]
Register a custom conversion between representations.