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_conversion_cost(source, target[, ...])

Estimate the cost of converting between representations.

find_conversion_path(source, target[, n_vars])

Find optimal conversion path between representations.

get_conversion_graph()

Get the global conversion graph instance.

get_conversion_options(source[, max_cost])

Get all conversion options from a source representation.

register_custom_conversion(source, target, ...)

Register a custom conversion between representations.

set_large_n_policy([policy, threshold])

Configure what happens when a conversion would create a huge truth table.

Classes

ConversionCost(time_complexity, space_complexity)

Represents the cost of converting between two representations.

ConversionEdge(source, target, cost[, converter])

Represents an edge in the conversion graph.

ConversionGraph()

Manages conversions between Boolean function representations.

ConversionPath(edges)

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.

__init__(time_complexity: float, space_complexity: float, accuracy_loss: float = 0.0, is_exact: bool = True)[source]
class boofun.core.conversion_graph.ConversionEdge(source: str, target: str, cost: ConversionCost, converter: Callable | None = None)[source]

Represents an edge in the conversion graph.

__init__(source: str, target: str, cost: ConversionCost, converter: Callable | None = None)[source]
class boofun.core.conversion_graph.ConversionPath(edges: List[ConversionEdge])[source]

Represents a complete conversion path between representations.

__init__(edges: List[ConversionEdge])[source]
execute(data: Any, space: Space, n_vars: int) Any[source]

Execute the conversion path step by step.

If the path goes through truth_table and n_vars exceeds the configured threshold, behaviour depends on the policy set via set_large_n_policy() (default: warn).

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.

__init__() None[source]
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:
  1. If source == target, return None (no conversion needed).

  2. If a direct edge exists, use it.

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

estimate_conversion_cost(source: str, target: str, n_vars: int | None = None) ConversionCost | None[source]

Estimate conversion cost without executing the path.

clear_cache() None[source]
get_graph_stats() Dict[str, Any][source]
visualize_graph(output_format: str = 'text') str[source]
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.

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.

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.