o
    oh                     @   sF   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 d
dd	Z
dS )z5 Functions to support rewriting of SymPy expressions     )Expr)ask)subs)rebuildunify Nc                    s   d fdd	}|S )a   Rewrite rule.

    Transform expressions that match source into expressions that match target
    treating all ``variables`` as wilds.

    Examples
    ========

    >>> from sympy.abc import w, x, y, z
    >>> from sympy.unify.rewrite import rewriterule
    >>> from sympy import default_sort_key
    >>> rl = rewriterule(x + y, x**y, [x, y])
    >>> sorted(rl(z + 3), key=default_sort_key)
    [3**z, z**3]

    Use ``condition`` to specify additional requirements.  Inputs are taken in
    the same order as is found in variables.

    >>> rl = rewriterule(x + y, x**y, [x, y], lambda x, y: x.is_integer)
    >>> list(rl(z + 3))
    [3**z]

    Use ``assume`` to specify additional requirements using new assumptions.

    >>> from sympy.assumptions import Q
    >>> rl = rewriterule(x + y, x**y, [x, y], assume=Q.integer(x))
    >>> list(rl(z + 3))
    [3**z]

    Assumptions for the local context are provided at rule runtime

    >>> list(rl(w + z, Q.integer(z)))
    [z**w]
    Tc                 3   sr    t | i dD ]- r fddD  sq	r$t |s$q	t }t|tr3t|}|V  q	d S )N)	variablesc                    s   g | ]}  ||qS r   )get).0varmatchr   g/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/unify/rewrite.py
<listcomp>/   s    z3rewriterule.<locals>.rewrite_rl.<locals>.<listcomp>)r   r   xreplacer   
isinstancer   r   )exprassumptionsexpr2assume	conditionsourcetargetr   r   r   
rewrite_rl,   s   
zrewriterule.<locals>.rewrite_rlN)Tr   )r   r   r   r   r   r   r   r   r   rewriterule   s   $r   )r   NN)__doc__sympy.core.exprr   sympy.assumptionsr   sympy.strategies.toolsr   sympy.unify.usympyr   r   r   r   r   r   r   <module>   s    