
    Gd                        d Z ddlmZ ddlZd Zd Z ej                    Z	e	
                    ddd           e	
                    ddd           e	
                    d	dd           e	                    dd           e	                    dd	           e	
                    d
dd	           e	
                    ddd	           e	
                    ddd	           e	                    dd
           e	                    dd           e	                    d	d           e	                    d	d           e	
                    ddd
           e	                    dd            ee	          Z e ee                      ej        e	d          ZdddeddZ ej        d            ej        e	d          Z ej        e	efi e  ej         ee                      ej        d            ej                     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                     t          j        |           }|D ]6}|j        |         d         }| j        |         d         |j        |         d<   7|S )Nsourcelabel)nxdag_to_branchingnodes)circuitformulavr   s       ;share/doc/networkx-3.1/examples/algorithms/plot_circuits.pycircuit_to_formular      s[    !'**G  C Cq!(+$+M&$9'$Ba!!N    c                 |    fdt          d |                                 D                       } | |          S )Nc                 4   | j         |         d         }| |         s|S | |         }t          |          dk    r1t          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_strings
            r   r   z%formula_to_string.<locals>._to_string   s    d#G,t} 	L4=x==AH..x88E;;jj%88;;;; dme$*Wd33%:gu55@?@@U@@-=@@@@r   c              3   ,   K   | ]\  }}|d k    |V  dS )r   N ).0r   ds      r   	<genexpr>z$formula_to_string.<locals>.<genexpr>5   s*      <<daQ!VVVVVV<<r   )next	in_degree)r
   r   r   s     @r   formula_to_stringr'      s]    A A A A A, <<g//11<<<<<D:gt$$$r   u   ∧)r   layerr   u   ∨      x   y      ¬   zr   iX  g      ?blue   )	node_sizealpha
node_colorlabels	font_size)   r9   )figsizer(   )
subset_keyequal)__doc__matplotlib.pyplotpyplotpltnetworkxr   r   r'   DiGraphr	   add_nodeadd_edger
   printget_node_attributesr7   optionsfiguremultipartite_layoutposdraw_networkxtitleaxisshowr!   r   r   <module>rO      s                % % %H "*,,   %q  ) ) )   %q  ) ) )   %q  ) ) )   A      A      #Q  ' ' '   #Q  ' ' '   $a  ( ( (   A      A      A      A      #Q  ' ' '   A   

W
%
%    ! ! ! 
 		1	1  
6    bW999  # ) ) ) ) ) 		

G
$
$ % % %     




r   