U
    9%e#                     @   s&  d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZmZmZ ed\ZZZed\ZZZ ed\Z!Z"Z#dd Z$dd Z%dd Z&dd Z'dd Z(dd Z)dd Z*dd Z+d d! Z,G d"d# d#eZ-d$d% Z.d&S )'    )Sum)Expr)symbols)sqrt)	Piecewise)sin)MutableDenseMatrix)Interval)lambdify)raises)TensorflowPrinter)
lambdareprLambdaPrinterNumExprPrinterzx,y,zzi,a,bzj,c,dc                   C   s@   t tt dkstt tt dks(tt tt dks<td S )Nzx*y)zy + xzx + yzx**y)r   xyAssertionError r   r   c/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sympy/printing/tests/test_lambdarepr.py
test_basic   s    r   c                  C   s6   t d } t| t| ksttt| gdks2td S )N   zImmutableDenseMatrix([[x % 2]]))r   r   strr   Matrix)er   r   r   test_matrix   s    r   c                  C   sR  d} t ttdk f}t|}t| |  |dks4tt dtdk fdtdk fd}t|}t| |  |dksptt dtdk fdtdk f}t|}t| |  |dkstt ttdk ftd td	d
ddtfd}t|}t| |  |dkstt td tdk fttdk fdt tdkfddd}t|}t| |  |dksJtt td tdk fttdk fdt tdkfdd}t|}t| |  |dkstt dtdkfdtdkfd	td	kfd
td
kfdtdkfd}t|}t| |  |dkstt dtdkfdtdkfd	td	kfd
td
kfdtdkfd}t|}t| |  |dksTtt dtdkfdtdkfd	td	kfd
td
kfdtdkfd}t|}t| |  |dkstt dtdk fdtdk fd	td	k fd
td
k fdtdk fd}t|}t| |  |dkstt t dtdkfdtdkfd}t|}t| |  |dksNtd S )Nz
lambda x: r   z((x) if (x < 0) else None)   r   )r   Tz-((1) if (x < 1) else (2) if (x < 2) else (0))z.((1) if (x < 1) else (2) if (x < 2) else None)      TFzC((x) if (x < 1) else (x**2) if (((x <= 4)) and ((x > 3))) else (0))evaluatezI((x**2) if (x < 0) else (x) if (x < 1) else (2 - x) if (x >= 1) else (0))zJ((x**2) if (x < 0) else (x) if (x < 1) else (2 - x) if (x >= 1) else None)   )   Tzn((1) if (x >= 1) else (2) if (x >= 2) else (3) if (x >= 3) else (4) if (x >= 4) else (5) if (x >= 5) else (6))zn((1) if (x <= 1) else (2) if (x <= 2) else (3) if (x <= 3) else (4) if (x <= 4) else (5) if (x <= 5) else (6))zi((1) if (x > 1) else (2) if (x > 2) else (3) if (x > 3) else (4) if (x > 4) else (5) if (x > 5) else (6))zi((1) if (x < 1) else (2) if (x < 2) else (3) if (x < 3) else (4) if (x < 4) else (5) if (x < 5) else (6)))r   T)r   Tz1((((1) if (x > 0) else (2))) if (y > 0) else (3)))r   r   r   evalr   r	   containsr   )hplr   r   r   test_piecewise#   s    





 
 




















r'   c                  C   sd   t tt tttf} t| }|dks(ttttf}t|| }d}|| | t	||
 ks`td S )Nz+(builtins.sum(x**i for i in range(a, b+1)))r   r      )r   r   iabr   r   r
   subszipdoitsr&   argsfvr   r   r   test_sum__1   s    

r5   c                  C   sd   t tt tttf} t| }|dks(ttttf}t|| }d}|| | t	||
 ks`td S )Nz*(builtins.sum(i*x for i in range(a, b+1)))r(   )r   r*   r   r+   r,   r   r   r
   r-   r.   r/   r0   r   r   r   test_sum__2   s    

r6   c                  C   s|   t tt t tttftttf} t| }|dks4t	tttttf}t
|| }d}| t|| }|| }||ksxt	d S )NzE(builtins.sum(i*x + j for i in range(a, b+1) for j in range(c, d+1))))r   r   r   r    r!   )r   r*   r   jr+   r,   cdr   r   r
   r-   r.   r/   )r1   r&   r2   r3   valsZf_refZf_resr   r   r   test_multiple_sums   s     
r;   c                  C   sD   t ddi} | jttdddks&t| jttdddks@td S )Nstandardpython3F)Zrationalzsqrt(x)Tzx**(1/2))r   Z
_print_Powr   r   r   )Zprntrr   r   r   	test_sqrt   s    r>   c                   C   s   t tdd  d S )Nc                   S   s   t ttddS )Ngarbage)method)r   r   r   r   r   r   r   <lambda>       ztest_settings.<locals>.<lambda>)r   	TypeErrorr   r   r   r   test_settings   s    rD   c                  C   s   ddl m}  | tdkdddd}t |dks4tddlm}m}m	}m
} |d d|tg|tt|td	 g}d
}t ||kstd S )Nr   )ITETFr   z=numexpr.evaluate('where((x > 0), True, False)', truediv=True))ReturnFunctionDefinitionVariable
AssignmentZfoor   zidef foo(x):
    y = numexpr.evaluate('x', truediv=True)
    return numexpr.evaluate('y**2', truediv=True))Zsympy.logic.boolalgrE   r   r   doprintr   Zsympy.codegen.astrF   rG   rH   rI   r   )rE   exprrF   rG   rH   rI   Zfunc_defexpectedr   r   r   test_numexpr   s    
&rM   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )CustomPrintedObjectc                 C   s   dS )Nlambdar   selfprinterr   r   r   _lambdacode   s    zCustomPrintedObject._lambdacodec                 C   s   dS )N
tensorflowr   rP   r   r   r   _tensorflowcode   s    z#CustomPrintedObject._tensorflowcodec                 C   s   dS )Nnumpyr   rP   r   r   r   
_numpycode   s    zCustomPrintedObject._numpycodec                 C   s   dS )NZnumexprr   rP   r   r   r   _numexprcode   s    z CustomPrintedObject._numexprcodec                 C   s   dS )NZmpmathr   rP   r   r   r   _mpmathcode   s    zCustomPrintedObject._mpmathcodeN)__name__
__module____qualname__rS   rU   rW   rX   rY   r   r   r   r   rN      s
   rN   c                  C   sp   t  } t | dkstt | dks.tt | dksBtt tttdkft	tdk fdksltd S )NrO   rT   z)numexpr.evaluate('numexpr', truediv=True)r   z7numexpr.evaluate('where((x >= 0), y, z)', truediv=True))
rN   r   rJ   r   r   r   r   r   r   z)objr   r   r   test_printmethod   s     r_   N)/Zsympy.concrete.summationsr   Zsympy.core.exprr   Zsympy.core.symbolr   Z(sympy.functions.elementary.miscellaneousr   Z$sympy.functions.elementary.piecewiser   Z(sympy.functions.elementary.trigonometricr   Zsympy.matrices.denser   r   Zsympy.sets.setsr	   Zsympy.utilities.lambdifyr
   Zsympy.testing.pytestr   Zsympy.printing.tensorflowr   Zsympy.printing.lambdareprr   r   r   r   r   r]   r*   r+   r,   r7   r8   r9   r   r   r'   r5   r6   r;   r>   rD   rM   rN   r_   r   r   r   r   <module>   s2   z