U
    ¹mœd¨  ã                   @   sr  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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)ÚnxZdag_to_branchingÚnodes)ÚcircuitÚformulaÚvr   © r	   úz/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/../../../share/doc/networkx-3.1/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rPtj |¡}|› dˆ | |ƒ› d�S | | \}}ˆ | |ƒ}ˆ | |ƒ}d|› d|› d|› d�S )Nr   é   ú(ú)ú )r   Úlenr   ÚutilsZarbitrary_element)	r   Úrootr   ÚchildrenÚchildÚleftÚrightZleft_subformulaZ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>)ÚnextZ	in_degree)r   r   r	   r   r
   Úformula_to_string   s    r   u   âˆ§)r   Úlayerr   u   âˆ¨é   é   Úxé   Úyé   õ   Â¬é   Úzr   iX  g      à?Úblueé   )Z	node_sizeÚalphaZ
node_colorÚlabelsZ	font_size)é   r,   )Zfigsizer   )Z
subset_keyÚequal)Ú__doc__Zmatplotlib.pyplotZpyplotZpltZnetworkxr   r   r   ZDiGraphr   Úadd_nodeZadd_edger   ÚprintZget_node_attributesr+   ÚoptionsZfigureZmultipartite_layoutÚposZdraw_networkxÚtitleZaxisÚshowr	   r	   r	   r
   Ú<module>   sD   $û
