o
    ˷e                     @   sv  d Z ddlmZ ddlZdd Zdd Ze Z	e	j
dddd e	j
d	d
d	d e	j
dd
d	d e	dd	 e	dd e	j
dddd e	j
dddd e	j
dddd e	d	d e	d	d e	dd e	dd e	j
dddd e	dd ee	Zeee ee	dZdddeddZejdd eje	ddZeje	efi e eee ed e  dS )a  
========
Circuits
========

Convert a Boolean circuit to an equivalent Boolean formula.

A Boolean circuit can be exponentially more expressive than an
equivalent formula in the worst case, since the circuit can reuse
subcircuits multiple times, whereas a formula cannot reuse subformulas
more than once. Thus creating a Boolean formula from a Boolean circuit
in this way may be infeasible if the circuit is large.

    Nc                 C   s>   t | }|D ]}|j| d }| j| d |j| d< q|S )Nsourcelabel)nxdag_to_branchingnodes)circuitformulavr    r
   z/var/www/ideatree/venv/lib/python3.10/site-packages/../../../share/doc/networkx-2.8.6/examples/algorithms/plot_circuits.pycircuit_to_formula   s
   
r   c                    s,    fdd t dd |  D } | |S )Nc           	         s   | j | d }| | s|S | | }t|dkr(tj|}| d | | dS | | \}} | |} | |}d| d| d| dS )Nr      () )r   lenr   utilsarbitrary_element)	r   rootr   childrenchildleftrightleft_subformularight_subformula
_to_stringr
   r   r      s   

z%formula_to_string.<locals>._to_stringc                 s   s     | ]\}}|d kr|V  qdS )r   Nr
   ).0r	   dr
   r
   r   	<genexpr>5   s    z$formula_to_string.<locals>.<genexpr>)next	in_degree)r   r   r
   r   r   formula_to_string   s   
r"   u   ∧)r   layerr   u   ∨      x   y      ¬   zr   iX  g      ?blue   )	node_sizealpha
node_colorlabels	font_size)   r4   )figsizer#   )
subset_keyequal)__doc__matplotlib.pyplotpyplotpltnetworkxr   r   r"   DiGraphr   add_nodeadd_edger   printget_node_attributesr2   optionsfiguremultipartite_layoutposdraw_networkxtitleaxisshowr
   r
   r
   r   <module>   sF    $
