o
    GZh#                     @   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
J t tt dv sJ t tt dksJ d S )Nzx*y)zy + xzx + yzx**y)r   xy r   r   S/var/www/auris/lib/python3.10/site-packages/sympy/printing/tests/test_lambdarepr.py
test_basic   s   r   c                  C   s6   t d } t| t| ksJ tt| gdksJ d S )N   zImmutableDenseMatrix([[x % 2]]))r   r   strMatrix)er   r   r   test_matrix   s   r   c                  C   sL  d} t ttdk f}t|}t| |  |dksJ t dtdk fdtdk fd}t|}t| |  |dks8J t dtdk fdtdk f}t|}t| |  |dksUJ t ttdk ftd td	d
ddtfd}t|}t| |  |dks{J 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sJ t td tdk fttdk fdt tdkfdd}t|}t| |  |dksJ 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sJ 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'J 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sUJ 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sJ t t dtdkfdtdkfd}t|}t| |  |dksJ 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	   containsr   )hplr   r   r   test_piecewise#   s   



























r&   c                  C   sd   t tt tttf} t| }|dksJ tttf}t|| }d}|| | t||	 ks0J d S )Nz+(builtins.sum(x**i for i in range(a, b+1)))r   r      )
r   r   iabr   r
   subszipdoitsr%   argsfvr   r   r   test_sum__1   s   

$r4   c                  C   sd   t tt tttf} t| }|dksJ tttf}t|| }d}|| | t||	 ks0J 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/   r   r   r   test_sum__2   s   

$r5   c                  C   s|   t tt t tttftttf} t| }|dksJ tttttf}t	|| }d}| 
t|| }|| }||ks<J d S )NzE(builtins.sum(i*x + j for j in range(c, d+1) for i in range(a, b+1))))r   r   r   r   r    )r   r)   r   jr*   r+   cdr   r
   r,   r-   r.   )r0   r%   r1   r2   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J | jttdddks J d S )Nstandardpython3F)Zrationalzsqrt(x)Tzx**(1/2))r   Z
_print_Powr   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>   s    ztest_settings.<locals>.<lambda>)r   	TypeErrorr   r   r   r   test_settings   s   rB   c                  C   s   ddl m}  | tdkdddd}t |dksJ ddlm}m}m}m	} |d d|tg|t
t|t
d	 g}d
}t ||ksEJ 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.boolalgrC   r   r   doprintZsympy.codegen.astrD   rE   rF   rG   r   )rC   exprrD   rE   rF   rG   Zfunc_defexpectedr   r   r   test_numexpr   s   
&rK   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      dS )Nlambdar   selfprinterr   r   r   _lambdacode      zCustomPrintedObject._lambdacodec                 C   rM   )N
tensorflowr   rO   r   r   r   _tensorflowcode   rS   z#CustomPrintedObject._tensorflowcodec                 C   rM   )Nnumpyr   rO   r   r   r   
_numpycode   rS   zCustomPrintedObject._numpycodec                 C   rM   )NZnumexprr   rO   r   r   r   _numexprcode   rS   z CustomPrintedObject._numexprcodec                 C   rM   )NZmpmathr   rO   r   r   r   _mpmathcode   rS   zCustomPrintedObject._mpmathcodeN)__name__
__module____qualname__rR   rU   rW   rX   rY   r   r   r   r   rL      s    rL   c                  C   sp   t  } t | dksJ t | dksJ t | dks!J t tttdkfttdk fdks6J d S )NrN   rT   z)numexpr.evaluate('numexpr', truediv=True)r   z7numexpr.evaluate('where((x >= 0), y, z)', truediv=True))	rL   r   rH   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+   r6   r7   r8   r   r   r&   r4   r5   r:   r=   rB   rK   rL   r_   r   r   r   r   <module>   s4    z