10. Inspecting circuit size

Model counts describe a function’s solutions. Nodes and pairs describe the stored circuit. We can inspect that storage to locate the node with the largest number of alternatives.

from tididi import Vtree, literal

vtree = Vtree.balanced(4)
x1 = literal(vtree, 1)
x2 = literal(vtree, 2)
exclusive = x1.copy() ^ x2

node_sizes() returns a snapshot of the stored internal nodes as (vtree_node, local_node, pair_count) tuples. The snapshot does not borrow native storage, so it stays readable after the circuit is consumed.

def widest_node(circuit):
    return max(circuit.node_sizes(), key=lambda node: node[2], default=None)


level, node, pairs = widest_node(exclusive)
print(f"Widest XOR node: {pairs} pairs at vtree node {level}")
Widest XOR node: 2 pairs at vtree node 4

A Python vtree is a home: each circuit stores levels only for the variables it uses. A literal is decided by its variable’s leaf alone, so it stores no internal node and widest_node returns None.

print("Widest literal node:", widest_node(x1))
print("Total XOR pairs:", exclusive.pair_count())
print("Satisfying assignments:", exclusive.model_count())
Widest literal node: None
Total XOR pairs: 2
Satisfying assignments: 8

Storage identifiers belong to this particular diagram and can change after a transformation. Use semantic queries such as equivalent() to compare functions. For a visual inspection, to_dot() exports a Graphviz graph.