
    wgq                          d dl mZmZ d dlmZ ddlmZ g dZ G d de      Z G d d	e      Z	 G d
 dee      Z
e	j                  D ]  Z ee	dez  e	j                          d Zy)   )PythonCodePrinterMpmathPrinter)NumPyPrinter    )default_sort_key)r   r   r   LambdaPrinterr   IntervalPrinter
lambdareprc                   P     e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Z fd
Z xZS )r   zZ
    This printer converts expressions into strings that can be used by
    lambdify.
    _lambdacodec                     dg}t        |j                  t              D ]6  }|j                  d| j	                  |      dg       |j                  d       8 |d d }|j                  d       dj                  |      S )N(key)z and  sortedargsr   extend_printappendjoinselfexprresultargs       ^/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/printing/lambdarepr.py
_print_AndzLambdaPrinter._print_And   ss    $)))9: 	#CMM3C 0#67MM'"	# cwwv    c                     dg}t        |j                  t              D ]6  }|j                  d| j	                  |      dg       |j                  d       8 |d d }|j                  d       dj                  |      S )Nr   r   r   z or r   r   r   r   s       r    	_print_OrzLambdaPrinter._print_Or%   ss    $)))9: 	"CMM3C 0#67MM&!	" cwwvr"   c                 h    dd| j                  |j                  d         dg}dj                  |      S )Nr   znot (r   ))r   r   r   r   r   r   r   s      r    
_print_NotzLambdaPrinter._print_Not.   s/    wDIIaL 94@wwvr"   c                      y)NTrue r   r   s     r    _print_BooleanTruez LambdaPrinter._print_BooleanTrue2   s    r"   c                      y)NFalser,   r-   s     r    _print_BooleanFalsez!LambdaPrinter._print_BooleanFalse5   s    r"   c           	          d| j                  |j                  d         d| j                  |j                  d         d| j                  |j                  d         dg}dj                  |      S )	Nz((r   z) if (r   z) else (   r&   r   r'   r(   s      r    
_print_ITEzLambdaPrinter._print_ITE8   s]    $++diil+dkk$))A,/DIIaL14

 wwvr"   c                     t        |      S N)strr-   s     r    _print_NumberSymbolz!LambdaPrinter._print_NumberSymbol@   s    4yr"   c                 ,    t        t        | 
  |fi |S r6   )superr   
_print_Pow)r   r   kwargs	__class__s      r    r;   zLambdaPrinter._print_PowC   s     &8HHHr"   )__name__
__module____qualname____doc__printmethodr!   r$   r)   r.   r1   r4   r8   r;   __classcell__r=   s   @r    r   r      s>      KI Ir"   r   c            	       "    e Zd ZdZi ddddddddddd	d
ddddddddddddddddddddddddddddd d!Zd"Zd# Zd.d$Zd% Zd& Z	d' Z
d( ZexZxZxZxZxZxZxZZexZxZxZxZZd) Z fd*Z fd+Z fd,Z fd-Z xZS )/NumExprPrinter_numexprcodesincostanasinarcsinacosarccosatanarctanatan2arctan2sinhcoshtanhasinharcsinhacosharccoshatanharctanhlnlogexpsqrtabsconjimagrealwherecomplexcontains)Abs	conjugateimrerd   re   rf   numexprc                      y)N1jr,   r-   s     r    _print_ImaginaryUnitz#NumExprPrinter._print_ImaginaryUnitm   s    r"   c                 p    |D cg c]  }| j                  |       }}|r|j                  |      S yc c}w )Nr   )r   r   )r   seq	delimiteritemss        r    
_print_seqzNumExprPrinter._print_seqp   s8    +./4T[[//>>!$$	 0s   3c                 6   |j                   j                  }| j                  j                  |d       }|Et	        |d      r+d| j                   |j                  |j                         z  S t        d|z        |d| j                  |j                        dS )N_imp_z(%s)z&numexpr does not support function '%s'r   r   )
funcr>   _numexpr_functionsgethasattrr   rv   r   	TypeErrorrt   )r   e	func_namenstrs       r    _print_FunctionzNumExprPrinter._print_Functionx   s    FFOO	&&**9d;<q'"GAGGQVV,< === H )!* + +!899r"   c                    |j                   D cg c]  }| j                  |j                         }}|j                   D cg c]  }| j                  |j                         }}g }d}d}t	        ||      D ]<  \  }}|dk(  r|j                  |       d} n|j                  d|d|d       |dz  }> |s|j                  d       d	j                  |      d
|z  z   S c c}w c c}w )zPiecewise function printerr   Fr+   Tzwhere(, r   zlog(-1)r   r   )r   r   r   condzipr   r   )	r   r   r   exprscondsansparenthesis_countis_last_cond_Truer   s	            r    _print_PiecewisezNumExprPrinter._print_Piecewise   s    26))<3SXX&<<26))<3SXX&<<
 !eU+ 	'JD$v~

4 $(!

tT:;!Q&!	' ! JJy!wws|c$5555C =<s   "C "C%c                 N    ddl m} | j                  |j                  |            S )Nr   )	Piecewise)$sympy.functions.elementary.piecewiser   r   rewrite)r   r   r   s      r    r4   zNumExprPrinter._print_ITE   s    B{{4<<	233r"   c                 F    t        d|j                  j                  z        )Nznumexpr cannot be used with %s)r{   r=   r>   r-   s     r    blacklistedzNumExprPrinter.blacklisted   s$    8//0 1 	1r"   c                     | j                  | j                  dz         }|d| j                  |j                        dS )Nz	.evaluatez('z', truediv=True))_module_formatmoduler   r   )r   r   evaluates      r    _print_NumExprEvaluatez%NumExprPrinter._print_NumExprEvaluate   s3    &&t{{K'?@+3T[[5KLLr"   c                 b    ddl m} ddlm} t	        ||      s ||      }t
        |   |      S Nr   )
CodegenASTNumExprEvaluate)sympy.codegen.astr   sympy.codegen.pynodesr   
isinstancer:   doprint)r   r   r   r   r=   s       r    r   zNumExprPrinter.doprint   s,    09$
+"4(Dwt$$r"   c                     ddl m} |j                  \  }t        ||      s|j	                   ||            }t
        |   |      S Nr   r   )r   r   r   r   rw   r:   _print_Return)r   r   r   rr=   s       r    r   zNumExprPrinter._print_Return   s>    9YY!_-99_Q/0Dw$T**r"   c                     ddl m} |j                  ^}}}t        ||      s |j                  | ||      g| }t
        |   |      S r   )r   r   r   r   rw   r:   _print_Assignment)r   r   r   lhsrhsr   r=   s         r    r   z NumExprPrinter._print_Assignment   sK    9))S4#/499S/#"6>>Dw(..r"   c                     ddl m} ddlm} |j                  D cg c]  }t        ||      r|n ||       }}t        |   |  |j                  |       S c c}w r   )	r   r   r   r   r   r   r:   _print_CodeBlockrw   )r   r   r   r   r   r   r=   s         r    r   zNumExprPrinter._print_CodeBlock   sY    09Y]YbYbdRU
3
39MMddw'idii.>?? es   A)r   )r>   r?   r@   rB   rx   r   rn   rt   r   r   r4   r   _print_SparseRepMatrix_print_MutableSparseMatrix_print_ImmutableSparseMatrix_print_Matrix_print_DenseMatrix_print_MutableDenseMatrix_print_ImmutableMatrix_print_ImmutableDenseMatrix_print_list_print_tuple_print_Tuple_print_dict_print_Dictr   r   r   r   r   rC   rD   s   @r    rF   rF   K   s    !K 	 		
 	 	 	) 	 	 	 	 	 	 	u 	u  	u!" 	#$ 16 F:#6J41     	
   K  M%+/@ @r"   rF   c                   @     e Zd ZdZ fdZ fdZ fdZ fdZ xZS )r	   z?Use ``lambda`` printer but print numbers as ``mpi`` intervals. c                 0    dt         t        |   |      z  S Nz	mpi('%s'))r:   r   _print_Integerr   r   r=   s     r    r   zIntervalPrinter._print_Integer   s    U#4dJ4PPPr"   c                 0    dt         t        |   |      z  S r   r:   r   _print_Rationalr   s     r    r   zIntervalPrinter._print_Rational       U#4dKDQQQr"   c                 0    dt         t        |   |      z  S r   r   r   s     r    _print_HalfzIntervalPrinter._print_Half   r   r"   c                 .    t         t        |   |d      S )NT)rational)r:   r   r;   r   s     r    r;   zIntervalPrinter._print_Pow   s    ]D4TD4IIr"   )	r>   r?   r@   rA   r   r   r   r;   rC   rD   s   @r    r	   r	      s$    IQRRJ Jr"   r	   z	_print_%sc                 6    t        |      j                  |       S )z2
    Returns a string usable for lambdifying.
    )r   r   )r   settingss     r    r
   r
      s     "**400r"   N)pycoder   r   numpyr   sympy.core.sortingr   __all__r   rF   r	   rx   ksetattrr   r
   r,   r"   r    <module>r      s~      /2I% 2InV@] V@rJm] J  
	*	* MANK!O^-K-KLM1r"   