U
    9%eO3                     @   s  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mZmZmZ d dl mZmZmZmZmZmZ d dl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) d dl*m+Z+ d dl,m-Z- ed	\Z.Z/Z0d
d Z1dd Z2dd Z3dd Z4dd Z5dd Z6dd Z7dd Z8dd Z9dd Z:dd Z;d d! Z<d"d# Z=d$d% Z>d&d' Z?d(d) Z@d*d+ ZAd,d- ZBd.d/ ZCd0d1 ZDd2d3 ZEd4d5 ZFd6d7 ZGd8d9 ZHd:d; ZId<d= ZJd>d? ZKd@dA ZLdBdC ZMdDdE ZNdFdG ZOdHdI ZPdJdK ZQdLdM ZRdNdO ZSdPS )Q    )SpioosymbolsFunctionRationalIntegerTupleSymbolEqNeLeLtGtGe)
EulerGammaGoldenRatioCatalanLambdaMulPow)	Piecewisesqrtceilingexpsincossinclucas)raises)implemented_function)eyeMatrixMatrixSymbolIdentityHadamardProductSparseMatrix)besseli
maple_codezx,y,zc                   C   s,   t tddkstt tddks(td S )NC   Z67z-1)r)   r   AssertionError r-   r-   ^/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sympy/printing/tests/test_maple.pytest_Integer   s    r/   c                   C   s   t tdddkstt tdddks,tt tdddksBtt td	ddksXtt ttdd d
ksrtt tddt dkstd S )N      z3/7   	   2iz-3/7zx + 3/7z(3/7)*x)r)   r   r,   xr-   r-   r-   r.   test_Rational   s    r7   c                   C   s   t tttdkstt tttdks,tt tttdksBtt tttdksXtt tttdksntt t	ttdkstd S )Nzx = yzx <> yzx <= yzx < yzx > yzx >= y)
r)   r   r6   yr,   r   r   r   r   r   r-   r-   r-   r.   test_Relational   s    r9   c                   C   sH   t tttt dkstt ttdks0tt ttdksDtd S )Nzsin(x)^cos(x)zabs(x)zceil(x))r)   r   r6   r   r,   absr   r-   r-   r-   r.   test_Function'   s    r;   c               
   C   s   t td dkstt ttd  dks,tt td t dksDtt ttdd dks^ttdttdt } t d| td	 ttt    td t  d
kstt tdtttttddddddddkstd S )Nr0   zx^3zx^(y^3)z(x^3)^y   zx^(2/3)g   g      @z(3.5*2*x)^(-x + y^x)/(x^2 + y)F)evaluater+   z
-2*x/(y*y))	r)   r6   r,   r8   r   r    r   r   r   )r=   r-   r-   r.   test_Pow-   s    *rA   c                   C   sR   t tt dkstt tt dks(tt tt dks<tt t dksNtd S )Nx*yzx + yzx - yz-x)r)   r6   r8   r,   r-   r-   r-   r.   test_basic_ops<   s    rC   c                   C   s  t dt dkstt td t td   kr8dks>n tt dtt dksVtt ttj  t td   kr~dksn tt ttdkstt ttj t td   krdksn tt dt d	kstt td t td   krd	ksn tt td d
kstd S )Nr>   z1/xr+   g      z	1/sqrt(x)g      zsqrt(x)g      ?z1/Piz
1/sqrt(Pi))r)   r6   r,   r   r   Halfr   r-   r-   r-   r.   test_1_over_x_and_sqrtC   s    *.,,rE   c                   C   s^  t dt dkstt tt dks(tt dt dks<tt tt dksPtt td dksdtt tt dksxtt tt dkstt dt t d	kstt dt t t d
kstt tt dkstt dt t dkstt tt t dkstt tt t dks tt dt t dks:tt dt t t t dks\tt dt t dksvtt tdd dkstt tdd t dkstt tt t dkstt tt t dkstt tt tt  dks tt tt t dkstt td t dks4tt tdd t t t dksZtd S )Nr0   z3*xzPi*xz3/xzPi/xz(1/3)*xzx/PirB   z3*x*yz3*Pi*x*yzx/yz3*x/yzx*y/zzx*z/yr>   z1/(x*y)r<   z2*Pi*x/(y*z)z3*Pi/x   z3/5z(3/5)*xzx/(y*z)z	(x + y)/zz(x + y)/(x + z)z(x + y)/gammaz
(1/3)*x/Piz(3/5)*x*y/Pi)r)   r6   r,   r   r8   zr   r   r-   r-   r-   r.   test_mix_number_mult_symbolsQ   s0    "rH   c                   C   s   t td dkstt td dks(tt ttd  dks@tt tt dksTtt ttt  dksltt tt t dkstd S )	Nr0   zPi^3r<   zx^2zx^(Pi^3)zx^yzx^(y^z)z(x^y)^z)r)   r   r,   r6   r8   rG   r-   r-   r-   r.   test_mix_number_pow_symbolsl   s    rI   c                  C   sd   t d} t| dksttd|  dks,ttt dd |  dksHttdd|   dks`td S )	NIrF   z5*Ir0   r<   z(3/2)*I   z3 + 4*I)r   r)   r,   )rJ   r-   r-   r.   	test_imagw   s
    rL   c                   C   s   t tdkstt tdks tt t dks2tt tjdksDtt tjdksVtt tjdkshtt tddks|td S )NPiinfinityz	-infinity	undefinedzexp(1)r>   )	r)   r   r,   r   r   NegativeInfinityNaNZExp1r   r-   r-   r-   r.   test_constants   s    rR   c                   C   s@   t dt dkstt dt dks(tt dt dks<td S )Nr<   z2*(1/2 + (1/2)*sqrt(5))z	2*Catalanz2*gamma)r)   r   r,   r   r   r-   r-   r-   r.   test_constants_other   s    rS   c                   C   s   t tt@ dkstt ttB dks(tt t dks:tt tt@ t@ dksRtt ttB tB dksjtt tt@ tB dkstt ttB t@ dkstd S )Nzx && yzx || yz!xzx && y && zzx || y || zzz || x && yzz && (x || y))r)   r6   r8   r,   rG   r-   r-   r-   r.   test_boolean   s    rT   c                  C   s   t tdddgdksttdttd ttgddtgdtdttgg} d}t | |ksbtt | d d df dks~tt | dd d f dkstt tttt	 t	 ggd	kstt tddg d
kstt tddg d
kstd S )Nr>   
   z%Matrix([[10]], storage = rectangular)r<   r   z\Matrix([[1, sin((1/2)*x), abs(x)], [0, 1, Pi], [0, exp(1), ceil(x)]], storage = rectangular)z.Matrix([[1], [0], [0]], storage = rectangular)z:Matrix([[1, sin((1/2)*x), abs(x)]], storage = rectangular)z/Matrix([[x, x - y, -y]], storage = rectangular)z!Matrix([], storage = rectangular)r0   )
r)   r"   r,   r   r6   r:   r   r   r   r8   Aexpectedr-   r-   r.   test_Matrices   s2    rY   c                   C   s   t ttddkstd S )Nr<   z*Matrix([[1, 0], [0, 1]], storage = sparse))r)   r&   r$   r,   r-   r-   r-   r.   test_SparseMatrices   s    rZ   c                  C   sJ   t dtdt dt t d gg} t| dks4tt| jdksFtd S )Nr>   r<   r0   rF   z:Matrix([[1, sin(2/x), (3/5)*Pi/x]], storage = rectangular)z>Matrix([[1], [sin(2/x)], [(3/5)*Pi/x]], storage = rectangular))r"   r   r6   r   r)   r,   TrW   r-   r-   r.   test_vector_entries_hadamard   s    $r]   c                  C   sH   t dtdt dt t d gddtt gg} d}t| |ksDtd S )Nr>   r<   r0   rF   zGMatrix([[1, sin(2/x), (3/5)*Pi/x], [1, 2, x*y]], storage = rectangular))r"   r   r6   r   r8   r)   r,   rV   r-   r-   r.   "test_Matrices_entries_not_hadamard   s    0r^   c                  C   s   t ddd} td| | }td| | }t|| dks8tt|| dksLttd| | d	ksdtt|d | d
ks|tt||dt|    dkstt|td  dkstt|d dkstt|tj dkstd S )NnT)integerrW   BzA.BzB.Ar<   z2*A.Bz2*B.Ar0   z%A.(3*Matrix(n, shape = identity) + B)zMatrixPower(A, x^2)zMatrixPower(A, 3)zMatrixPower(A, 1/2))r
   r#   r)   r,   r$   r6   r   rD   )r_   rW   ra   r-   r-   r.   test_MatrixSymbol   s    rb   c                   C   s0   t dtd dkstt ttdks,td S )N   r0   z=6*Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]], storage = sparse)zMatrix(x, shape = identity))r)   r$   r,   r6   r-   r-   r-   r.   test_special_matrices   s    rd   c                   C   s   t dddddddggdd	d
gdgdks,tt ddks<tt dgdksNtt ddks^tt tdddg dksxtt dtt dtd ffdkstt dtdtddg g fdkstd S )Nr>   r<   r0   rK   rF   rc   r1      r3   rU      z)[1, 2, 3, [4, 5, [6, 7]], 8, [9, 10], 11])r>   r<   )r0   rK   z[1, 2, [3, 4]]z[1])r>   z	[1, 2, 3]z[1, x*y, [3, x^2]]r   zl[1, Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]], storage = rectangular), Matrix([], storage = rectangular), []])r)   r,   r	   r6   r8   r!   r"   r-   r-   r-   r.   test_containers   s    ""rg   c                  C   s*   t tt t ddd} d}| |ks&td S )NmeF)	assign_toinlinezme := (x + y)/Catalan)r)   r6   r8   r   r,   )sourcerX   r-   r-   r.   test_maple_noninline   s    rl   c                  C   sP   t dddgg} t| dddks$tt ddgddgg} t| ddd	ksLtd S )
Nr>   r<   r0   ari   z/a := Matrix([[1, 2, 3]], storage = rectangular)rK   rW   z4A := Matrix([[1, 2], [3, 4]], storage = rectangular)r"   r)   r,   r\   r-   r-   r.   test_maple_matrix_assign_to   s    rp   c                     sf   t dddgg tddd} tdddt | ddks<ttt fdd	 tt fd
d	 d S )Nr>   r<   r0   ra   Crn   z/B := Matrix([[1, 2, 3]], storage = rectangular)c                      s   t  tdS Nrn   )r)   r6   r-   r\   r-   r.   <lambda>      z2test_maple_matrix_assign_to_more.<locals>.<lambda>c                      s   t  dS rr   r(   r-   rW   rq   r-   r.   rs     rt   )r"   r#   r)   r,   r   
ValueError)ra   r-   ru   r.    test_maple_matrix_assign_to_more   s    rw   c                  C   s$   t dgg} t| dddks td S )Nr0   ra   rn   z)B := Matrix([[3]], storage = rectangular)ro   r\   r-   r-   r.   test_maple_matrix_1x1	  s    rx   c                  C   s   t tdtt gg} t| d d | d  | d  dks<ttddd}t|dksXtt|d d t|d  |d  d	ksttt|d
kstd S )Nr<   r   r   )r   r>   )r   r<   zx^2 + x*y + 2AAr>   r0   z%sin(AA[1, 2]) + AA[1, 1]^2 + AA[1, 3]zAA[1, 1] + AA[1, 2] + AA[1, 3])r"   r6   r8   r)   r,   r#   r   sum)rW   rz   r-   r-   r.   test_maple_matrix_elements  s    ("r|   c                   C   sH   t ddkstt tjdks"tt ddks2tt tjdksDtd S )NTtrueFfalse)r)   r,   r   r}   r~   r-   r-   r-   r.   test_maple_boolean  s    r   c                  C   sL   t ddi } d| d< d| d< d| d< d	| d
< tt | d< t| dksHtd S )NrF   rc   rU   )r<   r<      )r>   r<      )r>   r0      )r   r0   )r0   r   zMatrix([[0, 0, 0, 30, 0, 0], [0, 0, 20, 22, 0, 0], [0, 0, 10, 0, 0, 0], [x*y, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]], storage = sparse))r&   r6   r8   r)   r,   )Mr-   r-   r.   test_sparse!  s    r   c                   C   s   t tjdkstd S )Nz/# Not supported in maple:
# ComplexInfinity
zoo)r)   r   ZComplexInfinityr,   r-   r-   r-   r.   test_maple_not_supported1  s    r   c                  C   sd   t ddd} t ddd}t| d dks,ttd| d  dksDt| | }t|d dks`td S )	NrW   r>   r0   ra   ry   zA[1, 1]z	3*A[1, 1]zA[1, 1] - B[1, 1])r#   r)   r,   )rW   ra   Fr-   r-   r.   test_MatrixElement_printing9  s    r   c                  C   s   t ddd} t ddd}t ddd}t ddd}t| |}t|dksJtt|| dks^tt|| | d	ksvtt||  d
kstt|t t dkstd S )NrW   r0   ra   vr>   hzA*Bz(A*B).vz	h.(A*B).vz(A*B).Az	x*y*(A*B))r#   r%   r)   r,   r6   r8   )rW   ra   r   r   rq   r-   r-   r.   test_hadamardF  s    
r   c                     s   t ttdk ftd df t dks*tt dddks>tt td tdk ftd tdk ftd	 tdk ftd
 df d} t | kstt ddd|  kstt ttdk ftd tdkftttdkf tt fdd d S )Nr>   r<   Tzpiecewise(x < 1, x, x^2)rrn   zr := piecewise(x < 1, x, x^2)r0   rK   rF   z2piecewise(x < 1, x^2, x < 2, x^3, x < 3, x^4, x^5)zr := r   c                      s   t  S )Nr(   r-   exprr-   r.   rs   g  rt   z&test_maple_piecewise.<locals>.<lambda>)r   r6   r)   r,   r   r   rv   )rX   r-   r   r.   test_maple_piecewiseY  s    
:,r   c                  C   sr   t ttdk ftd df} td|  dks.tt| t dksBtt| tt  dksZtt| d dksntd S )	Nr>   r<   Tz2*piecewise(x < 1, x, x^2)zpiecewise(x < 1, x, x^2)/xzpiecewise(x < 1, x, x^2)/(x*y)r0   z(1/3)*piecewise(x < 1, x, x^2))r   r6   r)   r,   r8   )pwr-   r-   r.    test_maple_piecewise_times_constj  s
    r   c                  C   sB   t d} t| ttdks"tt| ttddks>td S )Nfzdiff(f(x), x)r<   zdiff(f(x), x$2))r   r)   r6   diffr,   )r   r-   r-   r.   test_maple_derivativess  s    r   c                   C   s,   t ttdkstt ttdks(td S )Nz*2^(-x)*((1 - sqrt(5))^x + (1 + sqrt(5))^x)zpiecewise(x <> 0, sin(x)/x, 1))r)   r   r6   r,   r   r-   r-   r-   r.   test_automatic_rewritesy  s    r   c                   C   s*   t ddkstt tttdks&td S )Nzasin(x)z	arcsin(x)zBesselI(x, y))r)   r,   r'   r6   r8   r-   r-   r-   r.   test_specfun~  s    r   N)TZ
sympy.corer   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   Zsympy.functionsr   r   r   r   r   r   r   r   Zsympy.testing.pytestr   Zsympy.utilities.lambdifyr    Zsympy.matricesr!   r"   r#   r$   r%   r&   Zsympy.functions.special.besselr'   Zsympy.printing.mapler)   r6   r8   rG   r/   r7   r9   r;   rA   rC   rE   rH   rI   rL   rR   rS   rT   rY   rZ   r]   r^   rb   rd   rg   rl   rp   rw   rx   r|   r   r   r   r   r   r   r   r   r   r   r-   r-   r-   r.   <module>   sV   D ( 			

	
	