.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/09_statistics.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_09_statistics.py: 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. .. GENERATED FROM PYTHON SOURCE LINES 10-17 .. code-block:: Python from tididi import Vtree, literal vtree = Vtree.balanced(4) x1 = literal(vtree, 1) x2 = literal(vtree, 2) exclusive = x1.copy() ^ x2 .. GENERATED FROM PYTHON SOURCE LINES 18-21 ``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. .. GENERATED FROM PYTHON SOURCE LINES 21-31 .. code-block:: Python 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}") print("Widest literal node:", widest_node(x1)[2], "pair") print("Total XOR pairs:", exclusive.pair_count()) print("Satisfying assignments:", exclusive.model_count()) .. rst-class:: sphx-glr-script-out .. code-block:: none Widest XOR node: 2 pairs at vtree node 4 Widest literal node: 1 pair Total XOR pairs: 4 Satisfying assignments: 8 .. GENERATED FROM PYTHON SOURCE LINES 32-35 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. .. _sphx_glr_download_tutorials_09_statistics.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 09_statistics.ipynb <09_statistics.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 09_statistics.py <09_statistics.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 09_statistics.zip <09_statistics.zip>`