
    \h|                         S r SSKJrJrJrJr  SSKJrJr  SSK	J
r
JrJr  SSKJrJrJr  SSKJrJrJr  SSKJr  \/r\\\/r\/rS rS	 rS
 rS rS rSS jrS r S r!SS jr"g)zSymPy 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                 n   ^  [         [        [        [        [        [
        4n[        U 4S jU 5       5      $ )Nc              3   <   >#    U  H  n[        TU5      v   M     g 7fN
issubclass).0aopops     J/var/www/auris/envauris/lib/python3.13/site-packages/sympy/unify/usympy.py	<genexpr>$sympy_associative.<locals>.<genexpr>   s     8isz"c""i   )r   r	   r
   r   r   r   any)r   	assoc_opss   ` r   sympy_associativer!      s&    &&%yII8i888    c                 d   ^  [         [        [        [        [        4n[        U 4S jU 5       5      $ )Nc              3   <   >#    U  H  n[        TU5      v   M     g 7fr   r   )r   copr   s     r   r   $sympy_commutative.<locals>.<genexpr>   s     7hsz"c""hr   )r   r	   r   r   r   r   )r   comm_opss   ` r   sympy_commutativer(      s$    VUL)<H7h777r"   c                 Z    [        U [        5      =(       a    [        U R                  5      $ r   )
isinstancer   r!   r   xs    r   is_associativer-      s    a">'8'>>r"   c                     [        U [        5      (       d  g[        U R                  5      (       a  g[	        U R                  [
        5      (       a  [        S U R                   5       5      $ g )NFTc              3   L   #    U  H  n[        U5      R                  v   M     g 7fr   )	constructis_commutative)r   args     r   r   !is_commutative.<locals>.<genexpr>"   s     CFS9S>00Fs   "$)r*   r   r(   r   r   r   allargsr+   s    r   r1   r1      sO    a""!$$CAFFCCC r"   c                    ^  U 4S jnU$ )Nc                    > [        U T5      =(       d-    [        U [        5      =(       a    [        U R                  T5      $ r   )r*   r   r   r   )r,   typs    r   	matchtypemk_matchtype.<locals>.matchtype%   s3    1c" B1h'AJqttS,A	Cr"    )r8   r9   s   ` r   mk_matchtyper<   $   s    C r"   c                   ^ U T;   a  [        U 5      $ [        U [         [        45      (       a  U $ [        U [        5      (       a  U R                  (       a  U $ [        U R                  [        U4S jU R                   5       5      5      $ )z$Turn a SymPy object into a Compound c              3   <   >#    U  H  n[        UT5      v   M     g 7fr   deconstruct)r   r2   	variabless     r   r   deconstruct.<locals>.<genexpr>3   s     H#+c955r   )	r   r*   r   r   is_Atomr   	__class__tupler5   )srA   s    `r   r@   r@   *   sj    I~{!h-..a199AKKHHHJ Jr"   c                   ^  [        T [        [        45      (       a  T R                  $ [        T [        5      (       d  T $ [        U 4S j[         5       5      (       a*  T R                  " [        [        T R                  5      SS06$ [        U 4S j[         5       5      (       a9  [        R                  " T R                  /[        [        T R                  5      Q76 $ T R                  " [        [        T R                  5      6 $ )z$Turn a Compound into a SymPy object c              3   P   >#    U  H  n[        TR                  U5      v   M     g 7fr   r   r   r   clsts     r   r   construct.<locals>.<genexpr>;   s!     
=,<S:addC  ,<   #&evaluateFc              3   P   >#    U  H  n[        TR                  U5      v   M     g 7fr   rI   rJ   s     r   r   rM   =   s     >osZc""orN   )r*   r   r   r2   r   r   eval_false_legalr   mapr0   r5   basic_new_legalr   __new__)rL   s   `r   r0   r0   5   s    !h-..uua""

=,<
===ttSAFF+<e<<	>o>	>	>}}QTT;C	166$:;;ttSAFF+,,r"   c                 *    [        [        U 5      5      $ )zRRebuild a SymPy expression.

This removes harm caused by Expr-Rules interactions.
)r0   r@   )rF   s    r   rebuildrV   B   s    
 [^$$r"   Nc           	   +     ^#    U4S jnU=(       d    0 nUR                  5        VVs0 s H  u  pgU" U5      U" U5      _M     nnn[        R                  " U" U 5      U" U5      U4[        [        S.UD6nU H=  n	U	R                  5        VVs0 s H  u  pg[        U5      [        U5      _M     snnv   M?     gs  snnf s  snnf 7f)a  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                    > [        U T5      $ r   r?   )r,   rA   s    r   <lambda>unify.<locals>.<lambda>s   s    {1i0r"   )r-   r1   N)itemsr   unifyr-   r1   r0   )
r,   yrF   rA   kwargsdeconskvdsds
      `      r   r\   r\   I   s     T 1F	RA*+'')4)$!F1I	)A4	F1Ivay! 
/4B4B
/ (.
/B 67ggi@iday|Yq\)i@@  	5 As   %CB:AC!C /C)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   rS   rQ   illegalr!   r(   r-   r1   r<   r@   r0   rV   r\   r;   r"   r   <module>rl      su   3
 , + 4 5 5 : : = = ,S), +98?D	J-%3Ar"   