U
    9%e                     @   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	   /var/www/html/Darija-Ai-API/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   $
