o
    ohR                     @   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 ]}| }|jr|| qttj|g||< q| 	|} t
| trhi }t|  ttdD ]#}||v rFq?||v rQ|| ||< q?| rbt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   k/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/simplify/cse_opts.py
<listcomp>   s    zsub_pre.<locals>.<listcomp>)key)atomsr   setis_Muladdr   
_from_argsr   NegativeOnexreplace
isinstancer   sortedr   r	   One)eaddsrepsignorer   nanegsr   r   r   sub_pre
   s,   



r   c              	   C   s|   g }t | D ]'}t|tr-|jd tju r-|jd tju r-||t|jdd  f q|D ]\}}| 	||i} q0| S )z Replace 1*-1*x with -x.
    r         N)
r   r   r   argsr   r   r   appendr   r   )r   replacementsnodereplacementr   r   r   sub_post)   s   
  r'   N)__doc__
sympy.corer   r   r   sympy.core.singletonr   sympy.core.sortingr   sympy.core.traversalr   r   r'   r   r   r   r   <module>   s    