Ë
    7^(h|  ã                   óÈ   — 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„ Zd	„ Zd
„ Zd„ Zd„ Zdd„Zd„ Z d„ Z!dd„Z"y)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                 ól   ‡ — t         t        t        t        t        t
        f}t        ˆ fd„|D «       «      S )Nc              3   ó6   •K  — | ]  }t        ‰|«      –— Œ y ­w©N©Ú
issubclass)Ú.0ÚaopÚops     €úP/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/unify/usympy.pyú	<genexpr>z$sympy_associative.<locals>.<genexpr>   s   øè ø€ Ò8 sŒz˜"˜c×"Ñ8ùó   ƒ)r   r	   r
   r   r   r   Úany)r   Ú	assoc_opss   ` r   Úsympy_associativer       s&   ø€ Üœ&¤&¬%´¼yÐI€IÜÓ8¨iÔ8Ó8Ð8ó    c                 ób   ‡ — t         t        t        t        t        f}t        ˆ fd„|D «       «      S )Nc              3   ó6   •K  — | ]  }t        ‰|«      –— Œ y ­wr   r   )r   Úcopr   s     €r   r   z$sympy_commutative.<locals>.<genexpr>   s   øè ø€ Ò7 sŒz˜"˜c×"Ñ7ùr   )r   r	   r   r   r   r   )r   Úcomm_opss   ` r   Úsympy_commutativer&      s$   ø€ Ü”VœU¤L´)Ð<€HÜÓ7¨hÔ7Ó7Ð7r!   c                 óP   — t        | t        «      xr t        | j                  «      S r   )Ú
isinstancer   r    r   ©Úxs    r   Úis_associativer+      s   € Ü�aœÓ"Ò>Ô'8¸¿¹Ó'>Ð>r!   c                 ó¾   — t        | t        «      syt        | j                  «      ryt	        | j                  t
        «      rt        d„ | j                  D «       «      S y )NFTc              3   óF   K  — | ]  }t        |«      j                  –— Œ y ­wr   )Ú	constructÚis_commutative)r   Úargs     r   r   z!is_commutative.<locals>.<genexpr>"   s   è ø€ ÒC°S”9˜S“>×0Õ0ÑCùs   ‚!)r(   r   r&   r   r   r   ÚallÚargsr)   s    r   r/   r/      sF   € Ü�aœÔ"ØÜ˜Ÿ™ÔØÜ�!—$‘$œÔÜÑC¸A¿F¹FÔCÓCÐCð r!   c                 ó   ‡ — ˆ fd„}|S )Nc                 óp   •— t        | ‰«      xs( t        | t        «      xr t        | j                  ‰«      S r   )r(   r   r   r   )r*   Útyps    €r   Ú	matchtypezmk_matchtype.<locals>.matchtype%   s3   ø€ Ü˜1˜cÓ"ò BÜ˜1œhÓ'ÒA¬J°q·t±t¸SÓ,Að	Cr!   © )r5   r6   s   ` r   Úmk_matchtyper8   $   s   ø€ ôCð Ðr!   c                 óò   ‡— | ‰v rt        | «      S t        | t         t        f«      r| S t        | t        «      r| j                  r| S t        | j                  t        ˆfd„| j                  D «       «      «      S )z% Turn a SymPy object into a Compound c              3   ó6   •K  — | ]  }t        |‰«      –— Œ y ­wr   ©Údeconstruct)r   r0   Ú	variabless     €r   r   zdeconstruct.<locals>.<genexpr>3   s   øè ø€ ÒH¸#œ+ c¨9×5ÑHùr   )	r   r(   r   r   Úis_Atomr   Ú	__class__Útupler2   )Úsr=   s    `r   r<   r<   *   sd   ø€ àˆI�~Ü˜‹{ÐÜ�!”h¤Ð-Ô.ØˆÜ�aœÔ 1§9¢9ØˆÜ�A—K‘KÜÓHÀÇÁÔHÓHóJð Jr!   c                 óÞ  ‡ — t        ‰ t        t        f«      r‰ j                  S t        ‰ t        «      s‰ S t        ˆ fd„t        D «       «      r* ‰ j                  t        t        ‰ j                  «      ddiŽS t        ˆ fd„t        D «       «      r8t        j                  ‰ j                  gt        t        ‰ j                  «      ¢­Ž S  ‰ j                  t        t        ‰ j                  «      Ž S )z% Turn a Compound into a SymPy object c              3   óJ   •K  — | ]  }t        ‰j                  |«      –— Œ y ­wr   ©r   r   ©r   ÚclsÚts     €r   r   zconstruct.<locals>.<genexpr>;   s   øè ø€ Ò
= SŒ:�a—d‘d˜C× Ñ
=ùó   ƒ #ÚevaluateFc              3   óJ   •K  — | ]  }t        ‰j                  |«      –— Œ y ­wr   rD   rE   s     €r   r   zconstruct.<locals>.<genexpr>=   s   øè ø€ Ò> sŒZ˜Ÿ™˜c×"Ñ>ùrH   )r(   r   r   r0   r   r   Úeval_false_legalr   Úmapr.   r2   Úbasic_new_legalr   Ú__new__)rG   s   `r   r.   r.   5   s§   ø€ ä�!”h¤Ð-Ô.Ø�u‰uˆÜ�aœÔ"ØˆÜ
Ó
=Ô,<Ô
=Ô=Øˆq�t‰t”Sœ A§F¡FÓ+Ð<°eÑ<Ð<Ü	Ó>¬oÔ>Ô	>Ü�}‰}˜QŸT™TÐ;¤C¬	°1·6±6Ó$:Ò;Ð;àˆq�t‰t”Sœ A§F¡FÓ+Ð,Ð,r!   c                 ó*   — t        t        | «      «      S )z[ Rebuild a SymPy expression.

    This removes harm caused by Expr-Rules interactions.
    )r.   r<   )rA   s    r   ÚrebuildrP   B   s   € ô
 ”[ “^Ó$Ð$r!   Nc           	   +   óv  ‡K  — ˆfd„}|xs i }|j                  «       D ��ci c]  \  }} ||«       ||«      “Œ }}}t        j                   || «       ||«      |ft        t        dœ|¤Ž}|D ]:  }	|	j                  «       D ��ci c]  \  }}t        |«      t        |«      “Œ c}}–— Œ< yc c}}w c c}}w ­w)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                 ó   •— t        | ‰«      S r   r;   )r*   r=   s    €r   ú<lambda>zunify.<locals>.<lambda>s   s   ø€ ”{ 1 iÓ0€ r!   )r+   r/   N)Úitemsr   Úunifyr+   r/   r.   )
r*   ÚyrA   r=   ÚkwargsÚdeconsÚkÚvÚdsÚds
      `      r   rU   rU   I   s¹   øè ø€ óT 1€FØ	ŠˆR€AØ*+¯'©'«)×4¡$ ! Q‰�‹‘F˜1“IÑ	Ð4€AÑ4ä	�‰‘F˜1“I™v a›y¨!ð 
/Ü4BÜ4Bñ
/ð (.ñ
/€Bð ò AˆØ67·g±g³i×@©d¨a°Œy˜‹|œY q›\Ñ)Ó@Ó@ñAùó 	5ùó Aùs   ƒB9¢B-»A
B9ÂB3Â$B9)r7   )Nr7   )#Ú__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   rM   rK   Úillegalr    r&   r+   r/   r8   r<   r.   rP   rU   r7   r!   r   ú<module>re      su   ðñ3÷
 ,Ó +ß 4ß 5Ñ 5ß :Ñ :ß =Ñ =Ý à�,€Ø˜S )Ð,Ð Øˆ+€ò9ò8ò?òDòó	Jò-ò%ô3Ar!   