U
    ˜9%eR  ã                   @   sP   d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
 dd„ Zdd	„ Zd
S )zS Optimizations of the expression tree representation for better CSE
opportunities.
é    )ÚAddÚBasicÚMul)ÚS)Údefault_sort_key)Úpreorder_traversalc                 C   sÔ   dd„ |   t¡D ƒ}i }tƒ }|D ]0}| }|jr>| |¡ q"t tj|g¡||< q"|  	|¡} t
| tƒrÐi }t|   t¡tdD ]F}||krŒq~||kr¢|| ||< q~| ¡ r~t tjtj| g¡||< q~|  	|¡} | S )zD Replace y - x with -(x - y) if -1 can be extracted from y - x.
    c                 S   s   g | ]}|  ¡ r|‘qS © )Úcould_extract_minus_sign)Ú.0Úar   r   úV/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sympy/simplify/cse_opts.pyÚ
<listcomp>   s      zsub_pre.<locals>.<listcomp>)Úkey)Zatomsr   ÚsetZis_MulÚaddr   Ú
_from_argsr   ÚNegativeOneÚxreplaceÚ
isinstancer   Úsortedr   r	   ÚOne)ÚeZaddsZrepsÚignorer   ÚnaZnegsr   r   r   Úsub_pre
   s*    



r   c              	   C   s|   g }t | ƒD ]N}t|tƒr|jd tjkr|jd tjkr| |t |jdd… ¡ f¡ q|D ]\}}|  	||i¡} q`| S )z Replace 1*-1*x with -x.
    r   é   é   N)
r   r   r   Úargsr   r   r   Úappendr   r   )r   ZreplacementsÚnodeÚreplacementr   r   r   Úsub_post)   s    
ÿÿ"r!   N)Ú__doc__Z
sympy.corer   r   r   Zsympy.core.singletonr   Zsympy.core.sortingr   Zsympy.core.traversalr   r   r!   r   r   r   r   Ú<module>   s   