o
    oh|                     @   s   d Z ddlmZmZmZmZ ddlmZmZ ddl	m
Z
mZmZ ddlmZmZmZ ddlmZmZmZ ddlmZ egZeeegZegZdd	 Zd
d Zdd Zdd Zdd ZdddZdd Z dd Z!dddZ"dS )z SymPy interface to Unification engine

See sympy.unify for module level docstring
See sympy.unify.core for algorithmic docstring     )BasicAddMulPow)AssocOp	LatticeOp)MatAddMatMul
MatrixExpr)UnionIntersection	FiniteSet)CompoundVariableCondVariable)corec                    s&   t tttttf}t fdd|D S )Nc                 3       | ]}t  |V  qd S N
issubclass).0aopop f/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/unify/usympy.py	<genexpr>       z$sympy_associative.<locals>.<genexpr>)r   r   r	   r   r   r   any)r   	assoc_opsr   r   r   sympy_associative   s   r    c                    s$   t ttttf}t fdd|D S )Nc                 3   r   r   r   )r   copr   r   r   r      r   z$sympy_commutative.<locals>.<genexpr>)r   r   r   r   r   r   )r   comm_opsr   r   r   sympy_commutative   s   r#   c                 C   s   t | to	t| jS r   )
isinstancer   r    r   xr   r   r   is_associative   s   r'   c                 C   s@   t | tsdS t| jrdS t| jtrtdd | jD S d S )NFTc                 s   s    | ]}t |jV  qd S r   )	constructis_commutativer   argr   r   r   r   "   r   z!is_commutative.<locals>.<genexpr>)r$   r   r#   r   r   r   allargsr%   r   r   r   r)      s   

r)   c                    s    fdd}|S )Nc                    s    t |  pt | tot| j S r   )r$   r   r   r   r%   typr   r   	matchtype%   s   
zmk_matchtype.<locals>.matchtyper   )r/   r0   r   r.   r   mk_matchtype$   s   r1   r   c                    sV   |  v rt | S t| t tfr| S t| tr| jr| S t| jt fdd| jD S )z% Turn a SymPy object into a Compound c                 3   s    | ]}t | V  qd S r   deconstructr*   	variablesr   r   r   3   r   zdeconstruct.<locals>.<genexpr>)	r   r$   r   r   is_Atomr   	__class__tupler-   )sr5   r   r4   r   r3   *   s   r3   c                    s   t  ttfr
 jS t  ts S t fddtD r( jtt	 j
ddiS t fddtD rAtj jgtt	 j
R  S  jtt	 j
 S )z% Turn a Compound into a SymPy object c                 3       | ]	}t  j|V  qd S r   r   r   r   clstr   r   r   ;       zconstruct.<locals>.<genexpr>evaluateFc                 3   r:   r   r;   r<   r>   r   r   r   =   r@   )r$   r   r   r+   r   r   eval_false_legalr   mapr(   r-   basic_new_legalr   __new__r>   r   r>   r   r(   5   s   
r(   c                 C   s   t t| S )z[ Rebuild a SymPy expression.

    This removes harm caused by Expr-Rules interactions.
    )r(   r3   )r9   r   r   r   rebuildB   s   rF   Nc                 +   sr    fdd |p
i } fdd|  D }tj |  ||fttd|}|D ]}dd |  D V  q*dS )af   Structural unification of two expressions/patterns.

    Examples
    ========

    >>> from sympy.unify.usympy import unify
    >>> from sympy import Basic, S
    >>> from sympy.abc import x, y, z, p, q

    >>> next(unify(Basic(S(1), S(2)), Basic(S(1), x), variables=[x]))
    {x: 2}

    >>> expr = 2*x + y + z
    >>> pattern = 2*p + q
    >>> next(unify(expr, pattern, {}, variables=(p, q)))
    {p: x, q: y + z}

    Unification supports commutative and associative matching

    >>> expr = x + y + z
    >>> pattern = p + q
    >>> len(list(unify(expr, pattern, {}, variables=(p, q))))
    12

    Symbols not indicated to be variables are treated as literal,
    else they are wild-like and match anything in a sub-expression.

    >>> expr = x*y*z + 3
    >>> pattern = x*y + 3
    >>> next(unify(expr, pattern, {}, variables=[x, y]))
    {x: y, y: x*z}

    The x and y of the pattern above were in a Mul and matched factors
    in the Mul of expr. Here, a single symbol matches an entire term:

    >>> expr = x*y + 3
    >>> pattern = p + 3
    >>> next(unify(expr, pattern, {}, variables=[p]))
    {p: x*y}

    c                    s
   t |  S r   r2   r%   r4   r   r   <lambda>s   s   
 zunify.<locals>.<lambda>c                    s   i | ]\}} | |qS r   r   r   kv)deconsr   r   
<dictcomp>u       zunify.<locals>.<dictcomp>)r'   r)   c                 S   s   i | ]\}}t |t |qS r   )r(   rH   r   r   r   rL   |   rM   N)itemsr   unifyr'   r)   )r&   yr9   r5   kwargsdsdr   )rK   r5   r   rO   I   s   *rO   )r   )Nr   )#__doc__
sympy.corer   r   r   r   sympy.core.operationsr   r   sympy.matricesr   r	   r
   sympy.sets.setsr   r   r   sympy.unify.corer   r   r   sympy.unifyr   rD   rB   illegalr    r#   r'   r)   r1   r3   r(   rF   rO   r   r   r   r   <module>   s&    

