
    sg>                     2   d dl mZ d dlmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d d	lmZmZmZmZmZm Z m!Z!m"Z"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/m0Z0m1Z1m2Z2 d dl3m4Z4 d dl5m6Z6m7Z7 d dl8m9Z9m:Z: d dl;m<Z<m=Z= d dl>m?Z?m@Z@mAZAmBZBmCZC d dlDmEZE d dlFmGZG  ed      \  ZHZIZJ e<d      ZKd ZLd ZMd ZNd ZOd ZPd ZQd ZRd ZSd ZTd ZU G d  d!e      ZVd" ZWd# ZXd$ ZYd% ZZd& Z[d' Z\d( Z]d) Z^d* Z_d+ Z`d, Zad- Zby.)/    )
Assignment)none)expm1log1p)cosm1)MatrixSolve)
ExprModsymbolsEqLeGtzooooRationalPow)pi)S)acosKroneckerDelta	PiecewisesignsqrtMinMaxcotacschaseccothsec)AndOr)SparseMatrixMatrixSymbolIdentity)MpmathPrinterPythonCodePrinterpycodeSymPyPrinter)TensorflowPrinter)NumPyPrinterSciPyPrinter)raisesskip)IndexedBaseIdx)ArraySymbolArrayDiagonalArrayContraction	ZeroArrayOneArray)import_module)loggammazx y zpc            
         t               } | j                  rJ | j                  t        t        z        dk(  sJ | j                  t        t        d            dk(  sJ | j                  t        t        t                     dk(  sJ | j                  t        t         t                    dk(  sJ | j                  t        t        t                    dk(  sJ | j                  t        t        t                    dk(  sJ | j                  dt        t        z   z        d	k(  sJ | j                  rJ | j                  t              d
k(  sJ | j                  ddhik(  sJ | j                  t        t        dd      z        dk(  sJ | j                  t        t                    dk(  sJ | j                  dddhik(  sJ | j                  t        t                    dk(  sJ | j                  t        t                    dk(  sJ | j                  t        t                    dk(  sJ | j                  t        t                    dk(  sJ | j                  t        t                    dk(  sJ | j                  t!        t        d            dk(  sJ | j                  t#        dt%        t        d      fdt        dkD  f            dk(  sJ | j                  t#        dt'        t        d      fdt)        t        d      fd            dk(  sJ | j                  t+        t                    dk(  sJ | j                  t,        d         dk(  sJ | j                  t/        t        t                    dk(  sJ | j                  d       d!k(  sJ | j                  ddg      d"k(  sJ | j                  t1        t        t                    d#k(  sJ | j                  t3        t        t                    d$k(  sJ y )%Nzx**y   zx % 2z-(x % y)z(-x) % yzx and yzx or y   z	1/(x + y)zmath.pimathr   math.sqrt(x)r   zmath.acos(x)z(1/math.tan(x))z;((math.exp(x) + math.exp(-x))/(math.exp(x) - math.exp(-x)))z(math.acos(1/x))z((math.log(math.sqrt(1 + x**(-2)) + 1/x))zx = 2r      z/((1) if (x == 0) else (2) if (x > 6) else None)   Fevaluatez/((2) if (x <= 0) else (3) if (x > 0) else None)z((0.0 if x == 0 else math.copysign(1, x))r   r;   zp[0, 1]z(1 if x == y else 0)r:   r?   z(2, 3)z[2, 3]z	min(x, y)z	max(x, y))r'   module_importsdoprintxyr
   r!   r"   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r8   r   r   r   prntrs    S/var/www/html/venv/lib/python3.12/site-packages/sympy/printing/tests/test_pycode.pytest_PythonCodePrinterrK      su   E####==A&(((==Q#w...==#a)$
222==aR$
222==Q#y000==Aq"h...==AaC![000####==	)))FTF#3333==HQN*+~=====a!^333FT6N#;;;;==a!^333==Q $5555==a!%bbbb==a!%7777==q"&PPPP==Aq)*g555==Ar!Qx=AaC" #&WX X X==Ar!Qx=Bq!H7 8<UU U U ==a!%OOOO==4!Y...==!,-1GGGG==8+++==!A8+++==Q#{222==Q#{222    c                  \    t               } | j                  dk(  sJ t        t        d        y )Npython3c                      t        ddi      S )Nstandardpython4)r'    rL   rJ   <lambda>z1test_PythonCodePrinter_standard.<locals>.<lambda>M   s    0*Y1GH rL   )r'   rP   r-   
ValueErrorrH   s    rJ   test_PythonCodePrinter_standardrU   H   s'    E>>Y&&&
:HIrL   c                     t               } | j                  t        t                    dk(  sJ | j                  t	        dd            dk(  sJ | j                  t
        j                        dk(  sJ | j                  t
        j                        dk(  sJ | j                  t
        j                        dk(  sJ | j                  t
        j                        dk(  sJ | j                  t
        j                        d	k(  sJ | j                  t
        j                        d
k(  sJ | j                  t
        j                        dk(  sJ | j                  t        t                    dk(  sJ y )Nzmpmath.sign(x)r;   r:   zmpmath.mpf(1)/mpmath.mpf(2)zmpmath.ez	mpmath.piz
mpmath.phizmpmath.eulerz
mpmath.nanz
mpmath.infzmpmath.ninfzmpmath.loggamma(x))r&   rE   r   rF   r   r   Exp1PiGoldenRatio
EulerGammaNaNInfinityNegativeInfinityr7   )r8   s    rJ   test_MpmathPrinterr^   P   s   A99T!W!111199Xa^$(EEEE99QVV
***99QTT?k)))99Q]]#|33399Q\\"n44499QUU|+++99QZZ L00099Q''(M99999Xa[!%9999rL   c                  f   ddl m}  ddlm} ddlm}m}m} ddlm	} ddl
m} ddlm} ddlm}m}	 dd	lm}
m} t)               }|j+                  t-        t.                    d
k(  sJ t1        ddd      }t1        ddd      }t1        ddd      }t1        ddd      }|j+                  |dz        dk(  sJ |j+                  |dz        dk(  sJ |j+                  t3        d            dk(  sJ t1        ddd      }t1        ddd      }|j+                  t5        ||            dk(  sJ |j+                  t5        ||      |z         dk(  sJ |j+                   |	dd            dk(  sJ |j+                   |dd            dk(  sJ |j+                   |dd | |
|f|
|z                     dk(  sJ |j+                   |||            dk(  sJ |j+                   |||            d k(  sJ |j+                   ||            d!k(  sJ |j+                   ||            d"k(  sJ |j+                   ||            d#k(  sJ |j+                   ||            d$k(  sJ |j+                  t.        dz        d%k(  sJ |j+                  t.        d&z        d'k(  sJ t7        ddd()      }|j+                  |      d*k(  sJ |j+                  t8        j:                        d+k(  sJ |j+                  t8        j<                        d,k(  sJ |j+                  t8        j>                        d-k(  sJ |j+                  t8        j@                        d.k(  sJ |j+                  t8        jB                        d/k(  sJ |j+                  t8        jD                        d0k(  sJ |j+                  tG        t.              dz        d1k(  sJ y )2Nr   )Lambda)Adjoint)
DiagMatrixDiagonalMatrix
DiagonalOf)FunctionMatrix)HadamardProduct)KroneckerProduct)	OneMatrix
ZeroMatrix)abznumpy.sign(x)Ar:   BCr;      Dr?      znumpy.linalg.inv(A)znumpy.linalg.matrix_power(A, 5)znumpy.eye(3)rF   rG   znumpy.linalg.solve(A, x)znumpy.linalg.solve(A, x) + yznumpy.zeros((2, 3))znumpy.ones((2, 3))z.numpy.fromfunction(lambda a, b: a + b, (4, 5))znumpy.multiply(A, B)znumpy.kron(A, B)z#numpy.conjugate(numpy.transpose(A))z%numpy.reshape(numpy.diag(A), (-1, 1))znumpy.diagflat(C)z"numpy.multiply(D, numpy.eye(3, 4))z	x**(-1.0)z	x**(-2.0)Fr@   z	2**(-1.0)numpy.eznumpy.piznumpy.euler_gammaz	numpy.nanz	numpy.infz
-numpy.infz(numpy.cos(x)**(-1.0))**2)$sympy.core.functionr`   "sympy.matrices.expressions.adjointra   #sympy.matrices.expressions.diagonalrb   rc   rd   %sympy.matrices.expressions.funcmatrixre   #sympy.matrices.expressions.hadamardrf   $sympy.matrices.expressions.kroneckerrg   "sympy.matrices.expressions.specialrh   ri   	sympy.abcrj   rk   r+   rE   r   rF   r$   r%   r   r   r   rW   rX   rZ   r[   r\   r]   r    )r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   r8   rl   rm   rn   rp   uvexprs                       rJ   test_NumPyPrinterr   _   sm   *:\\DCEJA99T!W000S!QAS!QAS!QAS!QA99QW!666699QT?????99Xa[!^333S!QAS!QA99[A&'+EEEE99[A&*+/MMMM99Z1%&*????99Yq!_%)====99^Aq&!QQ*?@A89 9 999_Q*+/EEEE99%a+,0BBBB99WQZ $IIII99Z]#'NNNN99Z]#'::::99^A&'+OOOO 99QU{***99QU{***q"u%D99T?k)))99QVV	)))99QTT?j(((99Q\\"&999999QUU{***99QZZ K///99Q''(L888 99SVQY#>>>>rL   c                     t        d      } | st        d       ddlm}m} ddlm}  |dt        z  dz   t        dz   d	t        z  dz         } |t        |d      } || j                  ddd            g d
k(  j                         sJ  |d      dk(  sJ  |t        dz  t        dz        } |t        |d      } || j                  ddd            g dk(  j                         sJ  |d      dk(  sJ y )Nnumpyznumpy not installed.r   )r   r   )lambdifyg?r?   r;   g      ?)g      ?g      ?g      @rq   r:   rr   )r;   r   r;      @   )
r6   r.   (sympy.functions.elementary.miscellaneousr   r   sympy.utilities.lambdifyr   rF   linspaceall)r   r   r   r   expr1funcs         rJ   test_issue_18770r      s    '"E#$C1A	1q5#a%!),EAug&D1a()->>CCEEEGqLL1adOEAeW%DAq)*l:@@BBB7b==rL   c                      t               } t        t              }d| j                  vsJ | j	                  |      dk(  sJ d| j                  v sJ t        d | j                  D              rJ t        ddddi      }| j	                  |      dk(  sJ d	| j                  v sJ | j	                  t        j                        d
k(  sJ | j	                  t        j                        dk(  sJ | j	                  t        j                        dk(  sJ y )Nr   znumpy.arccos(x)c              3   >   K   | ]  }|j                  d         yw)scipyN)
startswith).0ms     rJ   	<genexpr>z$test_SciPyPrinter.<locals>.<genexpr>   s     CQ1<<(Cs   r:   ro   rB   r?   z8scipy.sparse.coo_matrix(([3], ([0], [1])), shape=(2, 5))zscipy.sparsezscipy.constants.golden_ratiozscipy.constants.pirt   )r,   r   rF   rD   rE   anyr#   r   rY   rX   rW   )r8   r   smats      rJ   test_SciPyPrinterr      s   A7D!*****99T?////a&&&&&C!2B2BCCCC1vqk*D99T?BC C CQ-----99Q]]#'EEEE99QTT?222299QVV	)))rL   c                  t    t        d      \  t        t        fd       t        z         } | dv sJ y )Nzif elsec                  $    t         z   d      S )NT)error_on_reserved)r(   )s1s2s   rJ   rS   z,test_pycode_reserved_words.<locals>.<lambda>   s    vb2gF rL   )zelse_ + if_zif_ + else_)r   r-   rT   r(   )py_strr   r   s    @@rJ   test_pycode_reserved_wordsr      s8    YFB
:FGBG_F3333rL   c                  v    t        d      \  } }}| |z  }t        |      dk(  sJ ||z  }t        |      dk(  sJ y )Nza_{b} b a_{11}za_b*bza_11*b)r   r(   )a_brk   a_11r   s       rJ   test_issue_20762r      sI    +,LCDq5D$<7"""6D$<8###rL   c                     t               } | j                  t        t              d      dk(  sJ | j                  dt        t              z  d      dk(  sJ t        ddi      } | j                  t        t              d      d	k(  sJ | j                  dt        t              z  d      d
k(  sJ t	               } | j                  t        t              d      dk(  sJ | j                  t        t              d      dk(  sJ t               } | j                  t        t              d      dk(  sJ | j                  t        t              d      d	k(  sJ t               } | j                  t        t              d      dk(  sJ | j                  t        t              d      d	k(  sJ t               } | j                  t        t              d      dk(  sJ | j                  t        t              d      d	k(  sJ y )NF)rationalr=   r;   z1/math.sqrt(x)rP   rN   Tzx**(1/2)z	x**(-1/2)zmpmath.sqrt(x)z x**(mpmath.mpf(1)/mpmath.mpf(2))znumpy.sqrt(x)zsympy.sqrt(x))r'   
_print_Powr   rF   r&   r+   r,   r)   rH   s    rJ   	test_sqrtr      s   EDGe4FFFAd1gI6:JJJJzI67EDGd3zAAAAd1gI5DDDOEDGe48HHHHDGd3*+ + + NEDGe4GGGDGd3zAAANEDGe4GGGDGd3zAAANEDGe4GGGDGd3zAAArL   c                  h   ddl m}   | t              }t               }|j	                  |      dk(  sJ t               }|j	                  |      dk(  sJ t               }|j	                  |      dk(  sJ t               }|j	                  |      dk(  sJ t               }|j	                  |      dk(  sJ y )Nr   )fracznumpy.mod(x, 1)zx % 1zmpmath.frac(x)z+sympy.functions.elementary.integers.frac(x))	#sympy.functions.elementary.integersr   rF   r+   rE   r,   r'   r&   r)   )r   r   rI   s      rJ   	test_fracr      s    87DNE=="3333NE=="3333E==')))OE=="2222NE=="OOOOrL   c                       e Zd Zd Zd Zy)CustomPrintedObjectc                      y)Nr   rR   selfprinters     rJ   
_numpycodezCustomPrintedObject._numpycode   s    rL   c                      y)NmpmathrR   r   s     rJ   _mpmathcodezCustomPrintedObject._mpmathcode   s    rL   N)__name__
__module____qualname__r   r   rR   rL   rJ   r   r      s    rL   r   c                      t               } t               j                  |       dk(  sJ t               j                  |       dk(  sJ y )Nr   r   )r   r+   rE   r&   )objs    rJ   test_printmethodr      s@    

C>!!#&'111?""3'8333rL   c                  ,    t        t              dk(  sJ y )NNone)r(   r   rR   rL   rJ   test_codegen_ast_nodesr     s    $<6!!!rL   c                      t               } | j                  t              dk(  sJ | j                  t               dk(  sJ y )Nzmath.nanzfloat('-inf'))r'   rE   r   r   rH   s    rJ   test_issue_14283r   	  s:    E==+++=="000rL   c                  V    t               } | j                  t        d            dk(  sJ y )Nr:   z(0, 1,))r+   
_print_seqrange)ns    rJ   test_NumPyPrinter_print_seqr     s$    A<<a!Y...rL   c                     ddl m} m} t        d      } | |t              } ||t              }t               }|j                  |      dk(  sJ |j                  |      dk(  sJ t               }t        ddi      }||fD ]@  }t        t              5  |j                  |       d d d        d|j                  |      v r@J  y # 1 sw Y   !xY w)	Nr   )
lowergamma
uppergammarj   z3scipy.special.gamma(a)*scipy.special.gammainc(a, x)z4scipy.special.gamma(a)*scipy.special.gammaincc(a, x)strictFNot supported)'sympy.functions.special.gamma_functionsr   r   r   rF   r,   rE   r+   r'   r-   NotImplementedError)	r   r   rj   r   expr2rI   p_numpyp_pycoder   s	            rJ   test_issue_16535_16536r     s    PAq!Eq!ENE==#XXXX==#YYYYnG (E!23H 9'( 	#OOE"	#("2"24"88889	# 	#s   CC	c                     ddl m}  ddlm}  | | t               t        dt
        f      } |t        dz   | t        t        z        z  t        t         t        ft        dt        f      } |t        dz  t               |t        dz  t        df      t               j                  |      dk(  sJ j                  |      dk(  sJ t        t        fd       t        t        fd	       t               j                  |      d
k(  sJ j                  |      dk(  sJ t        t        fd       t        t        fd       y )Nr   )exp)Integralr:   r;   z>scipy.integrate.quad(lambda x: numpy.exp(-x), 0, numpy.inf)[0]zMscipy.integrate.nquad(lambda x, y: x**2*numpy.exp(x*y), ((-z, z), (0, z)))[0]c                  &    j                         S NrE   
indefiniterI   s   rJ   rS   ztest_Integral.<locals>.<lambda>6      j(A rL   c                  &    j                         S r   r   
evaluateatrI   s   rJ   rS   ztest_Integral.<locals>.<lambda>7  r   rL   z6mpmath.quad(lambda x: mpmath.exp(-x), (0, mpmath.inf))z?mpmath.quad(lambda x, y: x**2*mpmath.exp(x*y), (-z, z), (0, z))c                  &    j                         S r   r   r   s   rJ   rS   ztest_Integral.<locals>.<lambda><  r   rL   c                  &    j                         S r   r   r   s   rJ   rS   ztest_Integral.<locals>.<lambda>=  r   rL   )&sympy.functions.elementary.exponentialr   sympy.integrals.integralsr   rF   r   rG   zr,   rE   r-   r   r&   )r   r   singledoubler   r   rI   s       @@@rJ   test_Integralr   *  s   :2c1"g1bz*Fad3qs8ma!QZ!Q;F!Q$"J!Q$A'JNE== $dddd== $ssss
 AB
 ABOE== $\\\\== $eeee
 AB
 ABrL   c                  *   ddl m} m}  | t              } |t              }t	               }|j                  |      dk(  sJ |j                  |      dk(  sJ t               }t               }t               }||fD ]T  }t        t              5  |j                  |       d d d        t        t              5  |j                  |       d d d        V |j                  |      dk(  sJ |j                  |      dk(  sJ y # 1 sw Y   axY w# 1 sw Y   xY w)Nr   )fresnelcfresnelszscipy.special.fresnel(x)[1]zscipy.special.fresnel(x)[0]zmpmath.fresnelc(x)zmpmath.fresnels(x))'sympy.functions.special.error_functionsr   r   rF   r,   rE   r+   r'   r&   r-   r   )	r   r   r   r   rI   r   r   p_mpmathr   s	            rJ   test_fresnel_integralsr   @  s   LQKEQKENE==#@@@@==#@@@@nG "HH #'( 	"OOD!	"'( 	#T"	# 	## E"&::::E"&::::	" 	"	# 	#s   C=4D	=D		D	c                  x   ddl m}   | t        t              }t	               }|j                  |      dk(  sJ t               }|j                  |      dk(  sJ t               }|j                  |      dk(  sJ t        ddi      }|j                  |      dk(  sJ t               }|j                  |      dk(  sJ y )Nr   )betazscipy.special.beta(x, y)z/(math.gamma(x)*math.gamma(y)/math.gamma(x + y))allow_unknown_functionsTzmpmath.beta(x, y))	&sympy.functions.special.beta_functionsr   rF   rG   r,   rE   r+   r'   r&   )r   r   rI   s      rJ   	test_betar   W  s    ;1:DNE=="<<<<NE=="SSSSE=="SSSS8$?@E=="SSSSOE==#6666rL   c                     ddl m} m}  | t              } |t              }t	               }|j                  |      dk(  sJ |j                  |      dk(  sJ t        ddi      }d|j                  |      v sJ d|j                  |      v sJ t        ddi      }d|j                  |      v sJ d|j                  |      v sJ y )Nr   )airyaiairybizscipy.special.airy(x)[0]zscipy.special.airy(x)[2]r   Fr   )sympy.functions.special.besselr   r   rF   r,   rE   r+   r'   )r   r   r   r   rI   s        rJ   	test_airyr   k  s    ?1IE1IENE==#======#====(E*+EemmE2222emmE2222x/0EemmE2222emmE2222rL   c                     ddl m} m}  | t              } |t              }t	               }|j                  |      dk(  sJ |j                  |      dk(  sJ t        ddi      }d|j                  |      v sJ d|j                  |      v sJ t        ddi      }d|j                  |      v sJ d|j                  |      v sJ y )Nr   )airyaiprimeairybiprimezscipy.special.airy(x)[1]zscipy.special.airy(x)[3]r   Fr   )r   r   r   rF   r,   rE   r+   r'   )r   r   r   r   rI   s        rJ   test_airy_primer   }  s    INENENE==#======#====(E*+EemmE2222emmE2222x/0EemmE2222emmE2222rL   c                      t               } | j                  t        t                    dk(  sJ | j                  t	        t                    dk(  sJ | j                  t        t                    dk(  sJ y )Nznumpy.expm1(x)znumpy.log1p(x)zscipy.special.cosm1(x))r,   rE   r   rF   r   r   rH   s    rJ   !test_numerical_accuracy_functionsr     s]    NE==q"&6666==q"&6666==q"&>>>>rL   c            	         t        dd      } t        d      }t        dd      t        dd      t        dd	      }}}t               }|j	                  t        d
            dk(  sJ |j	                  t        d
            dk(  sJ |j	                  t        | ddg            dk(  sJ |j	                  |      dk(  sJ |j	                  t        | g d            dk(  sJ |j	                  t        | ddgddg            dk(  sJ |j	                  t        | dgdg            dk(  sJ |j	                  t        ||||f   ||||f               dk(  sJ t               }|j	                  t        d
            dk(  sJ |j	                  t        d
            dk(  sJ |j	                  t        | ddg            dk(  sJ |j	                  |      dk(  sJ |j	                  t        | g d            dk(  sJ |j	                  t        | ddgddg            dk(  sJ |j	                  t        | dgdg            dk(  sJ |j	                  t        ||||f   ||||f               dk(  sJ y )Nrl   )rq   rq   r>   r>   r>   IirB   jrC   k)rq   ro   ro   znumpy.zeros((5,))znumpy.ones((5,))r:   r?   znumpy.einsum("abccd->abd", A))r:   r?   rq   znumpy.einsum("abccc->abc", A)r   r;   znumpy.einsum("aabbc->cab", A)znumpy.einsum("abcde->abe", A)zI = Iztensorflow.zeros((5,))ztensorflow.ones((5,))z)tensorflow.linalg.einsum("abccd->abd", A)z)tensorflow.linalg.einsum("abccc->abc", A)z)tensorflow.linalg.einsum("aabbc->cab", A)z)tensorflow.linalg.einsum("abcde->abe", A))r1   r/   r0   r+   rE   r4   r5   r3   r2   r   r*   )rl   r   r   r   r   rI   s         rJ   test_array_printerr     sl   C%ACAUOSe_c#uoaANE==1&*======!%);;;;==)!aU348WWWW==s"""==q'237VVVV==q1Q%!A78<[[[[==)!aS1#67;ZZZZ==Aa!eHa!Ah78GCCCE==1&*BBBB==!%)@@@@==)!aU348cccc==s"""==q'237bbbb==q1Q%!A78<gggg==)!aS1#67;ffff==Aa!eHa!Ah78GCCCrL   N)csympy.codegenr   sympy.codegen.astr   sympy.codegen.cfunctionsr   r   sympy.codegen.scipy_nodesr   sympy.codegen.matrix_nodesr   
sympy.corer	   r
   r   r   r   r   r   r   r   r   sympy.core.numbersr   sympy.core.singletonr   sympy.functionsr   r   r   r   r   r   r   r   r   r   r   r    sympy.logicr!   r"   sympy.matricesr#   r$   r%   sympy.printing.pycoder&   r'   r(   r)   sympy.printing.tensorflowr*   sympy.printing.numpyr+   r,   sympy.testing.pytestr-   r.   sympy.tensorr/   r0   0sympy.tensor.array.expressions.array_expressionsr1   r2   r3   r4   r5   sympy.externalr6   r   r7   rF   rG   r   r8   rK   rU   r^   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rR   rL   rJ   <module>r     s    $ " 1 + 2 M M M ! " n n n n  ? ?  8 ; - ) ~ ~ ( < '
1a)3XJ:2?j&*"4$B6P($ 4"1/9(C,;.7(3$3&?DrL   