
    g.a                        d 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 h d	Zd
dd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&d'd(d)d*d+d,Zd-d.d-d/d0d0d1Zd2 Zd3 Z G d4 d5e          Z G d6 d7          Z G d8 d9e          Zej        D ]Z eed:ez  e           eD ]Z eed:ez  e           d; Zd<                                Zd= e                                D             Z eefi d>d?d@dAdBdCdDdEdFdGdHdIdJZd-d.dKdLdMd0d/dNdOZdP Z  G dQ dRe          Z!e!j        D ]Z ee!d:ez  e           eD ]Z ee!d:ez  e            G dS dTe          Z"dUS )Vzy
Python code printers

This module contains Python code printers for plain Python as well as NumPy & SciPy enabled code.
    )defaultdict)chain)S)Mod   )
precedence)CodePrinter>!   asifinisoranddefdelfornottryNoneTrueelifelsefrompasswithFalsebreakclassraisewhileyieldassertexceptglobalimportlambdareturnfinallycontinuenonlocalabsminmax)AbsMinMaxacosacoshasinasinhatanatan2atanhceilingceilcoscosherferfcexpexpm1	factorialfloorgammahypotisnanlgammaloglog10log1plog2sinsinhsqrttantanh)rC   rD   loggammarF   lnrG   rH   rI   rJ   rK   SqrtrM   rN   epiinfnan)Exp1PiEInfinityNaNComplexInfinityc                       j         |j        j                 }d                                         |          d                     fd|j        D                                 S )Nz{name}({args}), c              3   B   K   | ]}                     |          V  d S N_print.0argselfs     Q/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/printing/pycode.py	<genexpr>z$_print_known_func.<locals>.<genexpr>F   s/      2Y2Y4;;s3C3C2Y2Y2Y2Y2Y2Y    )nameargs)known_functions	__class____name__format_module_formatjoinrj   re   exprknowns   `  rf   _print_known_funcrt   C   sk     !89E""(;(;E(B(B(,		2Y2Y2Y2Yty2Y2Y2Y(Z(Z # \ \ \rh   c                 Z    | j         |j        j                 }|                     |          S r_   )known_constantsrl   rm   ro   rq   s      rf   _print_known_constrw   I   s(     !89Eu%%%rh   c            	           e Zd ZdZdZeZdZdZ e	 e
e                                d e                                D                                 Zd e                                D             Zddd	d
Z e	ej        i ddddd          Zd2 fd	Zd Zd3dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z! fdZ"d Z#d  Z$d! Z%d" Z&d# Z'd$ xZ(xZ)xZ*xZ+xZ,xZ-xZ.Z/d% Z0d& Z1d' Z2d( Z3d) Z4d* Z5d+ Z6d, Z7d- Z8d. Z9d/ Z:d4d1Z; xZ<S )5AbstractPythonCodePrinter_pythoncodePythonNz    c                 "    g | ]\  }}|d |z   fS zmath. rc   kvs      rf   
<listcomp>z$AbstractPythonCodePrinter.<listcomp>V   s%    DDDda!Wq[	DDDrh   c                      i | ]\  }}|d |z   S r}   r~   r   s      rf   
<dictcomp>z$AbstractPythonCodePrinter.<dictcomp>X   s"    
B
B
BDAq1gai
B
B
Brh   r   r   r   )r   r   r      TFpython3)user_functions	precisioninlinefully_qualified_modulescontractstandardc                    t                                          |           | j        d         }|#dd l}d                    |j        j                  }|dk    rt          d          || _        t          t                    | _        t          | j        fi |pi                     di           | _        t          | j        fi |pi                     di           | _        d S )Nr   r   zpython{}r   zOnly Python 3 is supported.r   user_constants)super__init__	_settingssysrn   version_infomajor
ValueErrorr   r   setmodule_importsdict_kfgetrk   _kcrv   )re   settingsstdr   rl   s       rf   r   z"AbstractPythonCodePrinter.__init__d   s    """ nZ(;JJJ##C$4$:;;C):;;;)#..  $DH  #  #R0D0Db1" 1"  #  ##DH  #  #R0D0Db1" 1"  #  #rh   c                     |d|S Nz = r~   )re   ri   values      rf   _declare_number_constz/AbstractPythonCodePrinter._declare_number_constx   s     DD%%((rh   c                    |                     d          }|rTt          |          dk    rA| j        d                    |d d                                                |d                    | j        d         r|S |                     d          d                              d          d                              d          d         S )N.r   r   (r   [)splitlenr   rp   addr   )re   fqnregisterpartss       rf   ro   z(AbstractPythonCodePrinter._module_format{   s    		# 	EE

Qss 4 4599%)DDD>34 	BJ99S>>!$**3//288==bAArh   c                     |S r_   r~   )re   liness     rf   _format_codez&AbstractPythonCodePrinter._format_code   s    rh   c                 ,    d                     |          S )Nz{}rn   re   
codestrings     rf   _get_statementz(AbstractPythonCodePrinter._get_statement   s    {{:&&&rh   c                 ,    d                     |          S )Nz  # {}r   )re   texts     rf   _get_commentz&AbstractPythonCodePrinter._get_comment   s    t$$$rh   c                    t          |          dk    r|                     |d                   S |                     |          d|                     ||dd                   d|                     |d                   dS )z
        This method expands a fold on binary operations.

        ``functools.reduce`` is an example of a folded operation.

        For example, the expression

        `A + B + C + D`

        is folded into

        `((A + B) + C) + D`
        r   r   r   Nr   r]   ))r   ra   ro   _expand_fold_binary_op)re   oprj   s      rf   r   z0AbstractPythonCodePrinter._expand_fold_binary_op   s     t99>>;;tAw''' ##B''''++BSbS	::::DH%%%% rh   c           	      .   t          |          dk    r|                     |d                   S t          |          }|dz  }|                     |          d|                     |d|                   d|                     ||d                   dS )z
        This method expands a reductin on binary operations.

        Notice: this is NOT the same as ``functools.reduce``.

        For example, the expression

        `A + B + C + D`

        is reduced into:

        `(A + B) + (C + D)`
        r   r      r   Nr]   r   )r   ra   ro   _expand_reduce_binary_op)re   r   rj   NNhalfs        rf   r   z2AbstractPythonCodePrinter._expand_reduce_binary_op   s     t99>>;;tAw'''D		AFE##B''''--d6E6l;;;;--d566l;;;; rh   c                     dS )Nzfloat('nan')r~   re   rr   s     rf   
_print_NaNz$AbstractPythonCodePrinter._print_NaN       ~rh   c                     dS )Nzfloat('inf')r~   r   s     rf   _print_Infinityz)AbstractPythonCodePrinter._print_Infinity   r   rh   c                     dS )Nzfloat('-inf')r~   r   s     rf   _print_NegativeInfinityz1AbstractPythonCodePrinter._print_NegativeInfinity   s    rh   c                 ,    |                      |          S r_   )r   r   s     rf   _print_ComplexInfinityz0AbstractPythonCodePrinter._print_ComplexInfinity   s    t$$$rh   c                 \     t          |           dj         fd|j        D              S )Nz{} % {}c              3   D   K   | ]}                     |          V  d S r_   )parenthesize)rc   xPRECre   s     rf   rg   z7AbstractPythonCodePrinter._print_Mod.<locals>.<genexpr>   s3      "Q"Q!4#4#4Q#=#="Q"Q"Q"Q"Q"Qrh   )r   rn   rj   re   rr   r   s   ` @rf   
_print_Modz$AbstractPythonCodePrinter._print_Mod   s;    $ 	 "Q"Q"Q"Q"Qty"Q"Q"QRSrh   c                    g }d}|j         D ]}|j        }|j        }|dk    r|                    d           |                    d           |                    |                     |                     |                    d           |                    d           |                    |                     |                     |                    d           |dz  }|d d         }|d         dk    r |d d	         }|                    d           n|                    d
           d                    |          S )Nr   r   r   z if z else r   r   r   z else None) )rj   rr   condappendra   rp   )re   rr   resultird   rR   cs          rf   _print_Piecewisez*AbstractPythonCodePrinter._print_Piecewise   s1   9 	 	CAAAvvc"""MM#MM$++a..)))MM#MM&!!!MM$++a..)))MM(###FAA":CRC[FMM#MM-(((wwvrh   c                    ddddddd}|j         |v rQ|                     |j                  }|                     |j                  }d                    |j         ||	          S t                                          |          S )
z.Relational printer for Equality and Unequalityequal	not_equalless
less_equalgreatergreater_equal)z==z!=<z<=>z>=z({lhs} {op} {rhs}))r   lhsrhs)rel_opra   r   r   rn   r   _print_Relational)re   rr   r   r   r   rl   s        rf   r   z+AbstractPythonCodePrinter._print_Relational   s     !
 
 ;"++dh''C++dh''C'..$+3C.PPPww((...rh   c                 ^    ddl m} |                     |                    |                    S )Nr   )	Piecewise)$sympy.functions.elementary.piecewiser   ra   rewrite)re   rr   r   s      rf   
_print_ITEz$AbstractPythonCodePrinter._print_ITE   s2    BBBBBB{{4<<	22333rh   c                       fd|j         D             }d                                         |j                  d                    |                    S )Nc              3      K   | ]Y\  }}}d                                          |                              |                              |                    V  ZdS )zfor {i} in range({a}, {b}+1))r   abN)rn   ra   )rc   r   r   r   re   s       rf   rg   z7AbstractPythonCodePrinter._print_Sum.<locals>.<genexpr>   s{       ( (
 1a	 +11++a..++a..++a.. 2 " "( ( ( ( ( (rh   z"(builtins.sum({function} {loops})) )functionloops)limitsrn   ra   r   rp   )re   rr   r   s   `  rf   
_print_Sumz$AbstractPythonCodePrinter._print_Sum   sl    ( ( ( (
  ;( ( ( 4::[[//((5// ; # # 	#rh   c                     dS )N1jr~   r   s     rf   _print_ImaginaryUnitz.AbstractPythonCodePrinter._print_ImaginaryUnit  s    trh   c                     |j         \  }}d                    |                     |          |                     |                    S )Nz(1 if {a} == {b} else 0))r   r   )rj   rn   ra   )re   rr   r   r   s       rf   _print_KroneckerDeltaz/AbstractPythonCodePrinter._print_KroneckerDelta  sD    y1)00AA 1 
 
 	
rh   c                     |j         j        }| j                            ||          }|d|                     |                                          dS )Nr   r   )rl   rm   rk   r   ra   tolist)re   rr   ri   funcs       rf   _print_MatrixBasez+AbstractPythonCodePrinter._print_MatrixBase  sM    ~&#''d3344T[[]]!;!;!;!;<<rh   c                 ,    |                      |          S r_   )r   r   s     rf   <lambda>z"AbstractPythonCodePrinter.<lambda>  s    411$77 rh   c                 l     d                      fd|                    d          D                       S )N
c                 $    g | ]}j         |z   S r~   )tab)rc   linere   s     rf   r   z@AbstractPythonCodePrinter._indent_codestring.<locals>.<listcomp>  s    MMMd$(T/MMMrh   )rp   r   r   s   ` rf   _indent_codestringz,AbstractPythonCodePrinter._indent_codestring  s8    yyMMMMj6F6Ft6L6LMMMNNNrh   c                     d                      fd|j        D                       }d                                         |j                  d                      fd|j        D                                            |                    S )Nr  c              3   B   K   | ]}                     |          V  d S r_   r`   rb   s     rf   rg   zFAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<genexpr>"  s/      >>s$++c**>>>>>>rh   z def {name}({parameters}):
{body}r]   c                 D    g | ]}                     |j                  S r~   )ra   symbol)rc   varre   s     rf   r   zGAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<listcomp>%  s'    !S!S!Sc$++cj"9"9!S!S!Srh   )ri   
parametersbody)rp   r  rn   ra   ri   r  r  )re   fdr  s   `  rf   _print_FunctionDefinitionz3AbstractPythonCodePrinter._print_FunctionDefinition!  s    yy>>>>bg>>>??299RW%%yy!S!S!S!SR]!S!S!STT((.. : 
 
 	
rh   c                      d                      fd|j        D                       }d                                         |j                                       |                    S )Nr  c              3   B   K   | ]}                     |          V  d S r_   r`   rb   s     rf   rg   z9AbstractPythonCodePrinter._print_While.<locals>.<genexpr>*  s/      ??s$++c**??????rh   zwhile {cond}:
{body})r   r  )rp   r  rn   ra   	conditionr  )re   whlr  s   `  rf   _print_Whilez&AbstractPythonCodePrinter._print_While)  sj    yy????ch???@@&--S]++((.. . 
 
 	
rh   c                     |                      |j        j                  d|                      |j        j                  S r   )ra   variabler
  r   )re   decls     rf   _print_Declarationz,AbstractPythonCodePrinter._print_Declaration0  s=    KK,----KK+,,,
 	
rh   c                     dS )Nr   r~   )re   bts     rf   _print_BreakTokenz+AbstractPythonCodePrinter._print_BreakToken6  s    wrh   c                 D    |j         \  }d|                     |          z  S )Nz	return %srj   ra   )re   retrd   s      rf   _print_Returnz'AbstractPythonCodePrinter._print_Return9  s"    xT[[----rh   c                 D    |j         \  }d|                     |          z  S )Nzraise %sr  )re   rsrd   s      rf   _print_Raisez&AbstractPythonCodePrinter._print_Raise=  s"    wDKK,,,,rh   c                 D    |j         \  }d|                     |          z  S )NzRuntimeError(%s)r  )re   remessages      rf   _print_RuntimeError_z.AbstractPythonCodePrinter._print_RuntimeError_A  s"    7!DKK$8$888rh   c                 .    d                      fd|j        D                       }ddlm} |j        |k    r.d                                         |j                  |          }|j        d k    r |d                     |j                  z  z  }d|z  S )Nr]   c              3   B   K   | ]}                     |          V  d S r_   r`   rb   s     rf   rg   z9AbstractPythonCodePrinter._print_Print.<locals>.<genexpr>F  s/      LLSC 0 0LLLLLLrh   r   )nonez{} % ({}), end=""z	, file=%sz	print(%s))rp   
print_argssympy.codegen.astr)  format_stringrn   ra   file)re   prntr*  r)  s   `   rf   _print_Printz&AbstractPythonCodePrinter._print_PrintE  s    YYLLLLDOLLLMM
******%%,33D.// J 9+DI(>(>>>JZ''rh   c                     t          |j                  dk    r|                     d          S t          |j                  dk    r|                     d          S |                     |j                  S )Nstdoutz
sys.stdoutstderrz
sys.stderr)strri   ro   ra   )re   strms     rf   _print_Streamz'AbstractPythonCodePrinter._print_StreamQ  sd    ty>>X%%&&|444^^x''&&|444;;ty)))rh   c                     dS )Nr   r~   )re   rd   s     rf   _print_NoneTokenz*AbstractPythonCodePrinter._print_NoneTokenY  s    vrh   	math.sqrtc                    t          |          }|j        t          j        k    rH|sF|                     |          }|                     |j                  }d                    ||          S |j        r|s|j         t          j        u rY|                     |          }|                     t          j	                  }|                     |j                  }| d| d| dS |j        t          j
        u rC|                     t          j	                  }|                     |j        |d          }| d| S |                     |j        |d          }|                     |j        |d          }	d                    ||	          S )	a  Printing helper function for ``Pow``

        Notes
        =====

        This preprocesses the ``sqrt`` as math formatter and prints division

        Examples
        ========

        >>> from sympy import sqrt
        >>> from sympy.printing.pycode import PythonCodePrinter
        >>> from sympy.abc import x

        Python code printer automatically looks up ``math.sqrt``.

        >>> printer = PythonCodePrinter()
        >>> printer._hprint_Pow(sqrt(x), rational=True)
        'x**(1/2)'
        >>> printer._hprint_Pow(sqrt(x), rational=False)
        'math.sqrt(x)'
        >>> printer._hprint_Pow(1/sqrt(x), rational=True)
        'x**(-1/2)'
        >>> printer._hprint_Pow(1/sqrt(x), rational=False)
        '1/math.sqrt(x)'
        >>> printer._hprint_Pow(1/x, rational=False)
        '1/x'
        >>> printer._hprint_Pow(1/x, rational=True)
        'x**(-1)'

        Using sqrt from numpy or mpmath

        >>> printer._hprint_Pow(sqrt(x), sqrt='numpy.sqrt')
        'numpy.sqrt(x)'
        >>> printer._hprint_Pow(sqrt(x), sqrt='mpmath.sqrt')
        'mpmath.sqrt(x)'

        See Also
        ========

        sympy.printing.str.StrPrinter._print_Pow
        z{func}({arg}))r   rd   /r   r   Fstrictz{}**{})r   r>   r   Halfro   ra   basern   is_commutativeOneNegativeOner   )
re   rr   rationalrL   r   r   rd   numbase_strexp_strs
             rf   _hprint_Powz%AbstractPythonCodePrinter._hprint_Pow\  s|   V $8qvh&&t,,D++di((C"))t)=== 		&x 		&yAF""**400kk!%((kk$),,----s----x1=((kk!%((''	4'FF~~~~% $$TYU$CC##DHd5#AAx111rh   r_   )T)Fr8  )=rm   
__module____qualname__printmethodlanguage_kwreserved_wordsmodulesr  r   r   _known_functionsitems_known_functions_mathr   _known_constants_mathr   
_operatorsr	   _default_settingsr   r   ro   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _print_SparseRepMatrix_print_MutableSparseMatrix_print_ImmutableSparseMatrix_print_Matrix_print_DenseMatrix_print_MutableDenseMatrix_print_ImmutableMatrix_print_ImmutableDenseMatrixr  r  r  r  r  r  r"  r&  r/  r5  r7  rF  __classcell__rl   s   @rf   ry   ry   N   sE       KHNG
C
$uu  DD&;&A&A&C&CDDD   C C
B$9$?$?$A$A
B
B
BCd599J% $  # # # # # #() ) )B B B B  ' ' '% % %  .  2      % % %T T T  ./ / / / / 4 4 4	# 	# 	#  
 
 
= = = 	878 8"8$8 	8 		8
 	"8 	#O O O
 
 

 
 

 
 
  . . .- - -9 9 9
( 
( 
(* * *  @2 @2 @2 @2 @2 @2 @2 @2rh   ry   c                   V    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZdS )ArrayPrinterc                 J    ddl m} 	  ||          S # t          $ r |cY S w xY w)Nr   )convert_indexed_to_array)4sympy.tensor.array.expressions.from_indexed_to_arrayra  	Exception)re   indexedra  s      rf   	_arrayifyzArrayPrinter._arrayify  sN    aaaaaa	++G444 	 	 	NNN	s   
 ""c                    |                                  }d}d}d |D             }g }|D ]e}g }	t          |          D ]<}
||v r|	                    ||                    n|	                    |           |dz  }=|                    |	           fi }g }g }|D ]e}
|
D ][}||vrt          |          }|||<   n||         }||z  }||v r||vr|                    |           F|                    |           \|dz  }f|d d         }|||fS )Nr   r   c                 8    i | ]}|D ]}|t          |          S r~   )r,   )rc   r   js      rf   r   z3ArrayPrinter._get_einsum_string.<locals>.<dictcomp>  s-    ???1Q??QA????rh   r   ,r   ) _get_letter_generator_for_einsumranger   next)re   subrankscontraction_indicesletterscontraction_stringcounterdindicesrank_arglindicesr   mappingletters_freeletters_dumrh  ls                   rf   _get_einsum_stringzArrayPrinter._get_einsum_string  s   7799?? 3???  	% 	%HH8__  a<<OOAgJ////OOG,,,1NN8$$$$ 	& 	&A + +G##WA!"GAJJ
A"a'"66++#**1--- ''****#%/4!<<<rh   c              #      K   t          dd          D ]}t          |          V  t          dd          D ]}t          |          V  t          d          )Na   {   A   [   zout of letters)rk  chrr   )re   r   s     rf   rj  z-ArrayPrinter._get_letter_generator_for_einsum  se      r3 	 	Aa&&LLLLr2 	 	Aa&&LLLL)***rh   c                                                       d                    fd|j        D                       }                      j        dz    j        z             d|dd                     fd|j        D                       dS )	Nri  c                 l    g | ]0}d                      fdt          |          D                       1S )r   c                 .    g | ]}t                    S r~   )rl  )rc   rh  ro  s     rf   r   zEArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>.<listcomp>  s    /P/P/P!W/P/P/Prh   )rp   rk  )rc   r   ro  s     rf   r   z:ArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>  sA    &i&i&iVWrww/P/P/P/PuQxx/P/P/P'Q'Q&i&i&irh   r   ("", r]   c                 :    g | ]}                     |          S r~   r`   rb   s     rf   r   z:ArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>  s%    AAA4;;s++AAArh   r   )rj  rp   rm  ro   _module_einsumrj   )re   rr   rp  ro  s   `  @rf   _print_ArrayTensorProductz&ArrayPrinter._print_ArrayTensorProduct  s    7799 XX&i&i&i&i[_[h&i&i&ijj##DL3$6$EFFFF"""		AAAAtyAAABBBB
 	
rh   c           
          ddl m} |j        }|j        }t	          ||          r.d                     fd|j        D                       }|j        }n*                     |          }t          |j
                  g}                     ||          \  }}}	|s                     |          S t	          ||          r'd                     fd|j        D                       }n                     |          }                      j        dz    j        z             dd                    |d	                    t!          |                              d
|dS )Nr   ArrayTensorProductri  c                 @    g | ]}d                      |          z  S z%sr`   rb   s     rf   r   z8ArrayPrinter._print_ArrayContraction.<locals>.<listcomp>  *    MMMCddkk#&6&67MMMrh   c                 @    g | ]}d                      |          z  S r  r`   rb   s     rf   r   z8ArrayPrinter._print_ArrayContraction.<locals>.<listcomp>  r  rh   r   r  {}->{}r   r  r   )0sympy.tensor.array.expressions.array_expressionsr  rr   rn  
isinstancerp   rj   rm  ra   r   shaperz  ro   r  r  rn   sorted)
re   rr   r  r>  rn  elemsranksrp  rw  rx  s
   `         rf   _print_ArrayContractionz$ArrayPrinter._print_ArrayContraction  ss   WWWWWWy"6d.// 	&HHMMMM49MMMNNEMEEKK%%E__%E8<8O8OPUWj8k8k5L+" 	%;;t$$$d.// 	&HHMMMM49MMMNNEEKK%%Es 2T\ ABBBBOO.|8L8L0M0MNNNNEE
 	
rh   c           	          ddl m} t          |j                  }t	          |j        |          r|j        j        }|j        j        }n|j        }|j        g}                     ||          \  }}} fd|D             } 	                     j
        dz    j        z             dd                    |d                    ||z                       dd	                    |          d
S )Nr   r  c                 :    g | ]}                     |          S r~   r`   )rc   r   re   s     rf   r   z5ArrayPrinter._print_ArrayDiagonal.<locals>.<listcomp>  s#    ///AQ///rh   r   r  r  r   r  r]   r   )r  r  listdiagonal_indicesr  rr   rm  rj   rz  ro   r  r  rn   rp   )	re   rr   r  r  rm  r  diagonal_stringrw  rx  s	   `        rf   _print_ArrayDiagonalz!ArrayPrinter._print_ArrayDiagonal  s   WWWWWW 566di!344 	 y)HINEE}HYKE595L5LXWg5h5h2{///////s 2T\ ABBBBOOORWW\+5M-N-NOOOOIIe
 	
rh   c                     |                      | j        dz   | j        z             d|                     |j                  d|                     |j        j                  dS )Nr   r   r]   r   )ro   r  
_transposera   rr   permutation
array_formr   s     rf   _print_PermuteDimszArrayPrinter._print_PermuteDims  sc    s 2T_ DEEEEKK	""""KK(34444
 	
rh   c                 X    |                      | j        dz   | j        z   |j                  S )Nr   )r   r  _addrj   r   s     rf   _print_ArrayAddzArrayPrinter._print_ArrayAdd  s(    **4<#+=	+I49UUUrh   c                     |                      | j        dz   | j        z             dd                    t	          | j        |j                            dS Nr   z((ri  z,)))ro   r  _onesrp   mapra   rj   r   s     rf   _print_OneArrayzArrayPrinter._print_OneArray  sT    c 1DJ >????HHSTY//0000
 	
rh   c                     |                      | j        dz   | j        z             dd                    t	          | j        |j                            dS r  )ro   r  _zerosrp   r  ra   rj   r   s     rf   _print_ZeroArrayzArrayPrinter._print_ZeroArray  sT    c 1DK ?@@@@HHSTY//0000
 	
rh   c                     |                      |                     |j                            }|                      |                     |j                            }|d|S r   )ra   re  r   r   )re   rr   r   r   s       rf   _print_AssignmentzArrayPrinter._print_Assignment  sS     kk$..2233kk$..2233 SS##''rh   c                 ,    |                      |          S r_   )_print_ArraySymbolr   s     rf   _print_IndexedBasezArrayPrinter._print_IndexedBase#  s    &&t,,,rh   N)rm   rG  rH  re  rz  rj  r  r  r  r  r  r  r  r  r  r~   rh   rf   r_  r_    s          != != !=F+ + +
 
 

 
 
4
 
 
"
 
 
V V V
 
 

 
 
( ( (- - - - -rh   r_  c                        e Zd Zd Zd Zd Zd ZddZd Zd Z	d	 Z
 fd
Zej        Zej        Zej        Zej        Z xZS )PythonCodePrinterc                     d                     |                     d          |                     |j        d                             S )Nz"(0.0 if {e} == 0 else {f}(1, {e}))zmath.copysignr   )frR   rn   ro   ra   rj   re   rR   s     rf   _print_signzPythonCodePrinter._print_sign)  sG    3::!!/22dkk!&)6L6L ; N N 	Nrh   c                 ~    t          |          }| j        d         |                     |j        d         |          z   S )Nr   r   )r   rR  r   rj   r   s      rf   
_print_NotzPythonCodePrinter._print_Not-  s7    $u%(9(9$)A,(M(MMMrh   c                     |j         S r_   )ri   r   s     rf   r  z$PythonCodePrinter._print_IndexedBase1  s
    yrh   c                      |j         d         }|j         dd          }d                    t          |          d                     fd|D                                 S )Nr   r   z{}[{}]r]   c                 :    g | ]}                     |          S r~   r`   )rc   indre   s     rf   r   z4PythonCodePrinter._print_Indexed.<locals>.<listcomp>7  s%    4W4W4W#T[[5E5E4W4W4Wrh   )rj   rn   r3  rp   )re   rr   r>  indexs   `   rf   _print_Indexedz PythonCodePrinter._print_Indexed4  sY    y|	!""s4yy$))4W4W4W4WQV4W4W4W*X*XYYYrh   Fc                 0    |                      ||          S )N)rB  rF  re   rr   rB  s      rf   
_print_PowzPythonCodePrinter._print_Pow9  s    x888rh   c                 B    d                     |j        |j                  S )Nz{}/{})rn   pqr   s     rf   _print_Rationalz!PythonCodePrinter._print_Rational<  s    ~~dfdf---rh   c                 ,    |                      |          S r_   r  r   s     rf   _print_HalfzPythonCodePrinter._print_Half?  s    ##D)))rh   c                 ^    |                      t          |j        d         d                    S )Nr   r   )r   r   rj   r   s     rf   _print_fraczPythonCodePrinter._print_fracB  s$    s49Q<33444rh   c                 :   t                                          |          }|| j        v rA| j        d         r$d}t	          |                    |                    || j        d         z   S d|v r*|                    dd                              dd          S |S )Nerror_on_reservedzVThis expression includes the symbol "{}" which is a reserved keyword in this language.reserved_word_suffix{r   })r   _print_SymbolrL  r   r   rn   replace)re   rr   ri   msgrl   s       rf   r  zPythonCodePrinter._print_SymbolE  s    ww$$T**4&&&~12 3< D!1!1222$.)?@@@D[[<<R((00b999Krh   F)rm   rG  rH  r  r  r  r  r  r  r  r  r  r	   _print_not_supported_print_lowergamma_print_uppergamma_print_fresnelc_print_fresnelsr\  r]  s   @rf   r  r  '  s        N N NN N N  Z Z Z
9 9 9 9. . .* * *5 5 5     $8#8!6O!6OOOOOrh   r  z	_print_%sc                 F    t          |                              |           S )a)   Converts an expr to a string of Python code

    Parameters
    ==========

    expr : Expr
        A SymPy expression.
    fully_qualified_modules : bool
        Whether or not to write out full module names of functions
        (``math.sin`` vs. ``sin``). default: ``True``.
    standard : str or None, optional
        Only 'python3' (default) is supported.
        This parameter may be removed in the future.

    Examples
    ========

    >>> from sympy import pycode, tan, Symbol
    >>> pycode(tan(Symbol('x')) + 1)
    'math.tan(x) + 1'

    )r  doprint)rr   r   s     rf   pycoder  a  s     . X&&..t444rh   z
log1p log2c                 .    g | ]\  }}|t           v||fS r~   )_not_in_mpmathr   s      rf   r   r   |  s*    ZZZA!>BYBYq!fBYBYBYrh   betafracfresnelcfresnelssignrO   hypermeijergbesseljbesselybesselibesselk)r  r  r  r  r  rO   r  r  r  r  r  r  phieulercatalanninf)rV   rW   GoldenRatio
EulerGammaCatalanrZ   rY   NegativeInfinityc                     g }g }| j         D ]W}t          |          dk    r|\  }}}nt          d          |                    |           |                    ||f           X||fS )z helper function for _print_Integral that
        - accepts an Integral expression
        - returns a tuple of
           - a list variables of integration
           - a list of tuples of the upper and lower limits of integration
       z%Only definite integrals are supported)r   r   NotImplementedErrorr   )integral_exprintegration_varsr   integration_rangeintegration_varlower_limitupper_limits          rf   _unpack_integral_limitsr    s     F*1 2 2 !!Q&&8I5O[++%&MNNN000{K01111V##rh   c                      e Zd ZdZdZdZ e ee	                                d e
	                                D                                 Zd e	                                D             Zd Zd Zd Zd	 Zd
 Zd Zd ZddZd ZdS )MpmathPrinterzH
    Lambda printer for mpmath which maintains precision for floats
    _mpmathcodezPython with mpmathc                 "    g | ]\  }}|d |z   fS zmpmath.r~   r   s      rf   r   zMpmathPrinter.<listcomp>  s%    HHH1!Y]	HHHrh   c                      i | ]\  }}|d |z   S r  r~   r   s      rf   r   zMpmathPrinter.<dictcomp>  s"    
F
F
Fda1ik
F
F
Frh   c                     t          t          t          t          |j                                      }d                    |                     d          |          S )Nz{func}({args})
mpmath.mpf)r   rj   )r3  tupler  int_mpf_rn   ro   )re   rR   rj   s      rf   _print_FloatzMpmathPrinter._print_Float  sM     5S!'**++,,&&D,?,?,M,MTX&YYYrh   c                     d                     |                     d          |                     |j                  |                     |j                            S )Nz{func}({p})/{func}({q})r  )r   r  r  )rn   ro   ra   r  r  r  s     rf   r  zMpmathPrinter._print_Rational  sR    (//$$\22kk!#kk!# 0 
 
 	
rh   c                 ,    |                      |          S r_   r  r  s     rf   r  zMpmathPrinter._print_Half  s    ##A&&&rh   c                     d                     |                     d          |                     |j        d                   |                     |j        d                   |                     d                    S )Nz{}({}, {}, {})mpmath.gammaincr   r   z
mpmath.infr  r  s     rf   r  zMpmathPrinter._print_uppergamma  sg    && 122KKq	""KKq	""--	/ / 	/rh   c                     d                     |                     d          |                     |j        d                   |                     |j        d                             S )Nz{}({}, 0, {})r  r   r   r  r  s     rf   r  zMpmathPrinter._print_lowergamma  sV    %% 122KKq	""KKq	""$ $ 	$rh   c                     d                     |                     d          |                     |j        d                             S )Nz{0}({1})/{0}(2)z
mpmath.logr   r  r  s     rf   _print_log2zMpmathPrinter._print_log2  sB     ''--t{{16!9/E/EG G 	Grh   c                     d                     |                     d          |                     |j        d                             S )Nz{}({})zmpmath.log1pr   r  r  s     rf   _print_log1pzMpmathPrinter._print_log1p  s@    //QVAY1G1GI I 	Irh   Fc                 2    |                      ||d          S )Nzmpmath.sqrtrB  rL   r  r  s      rf   r  zMpmathPrinter._print_Pow  s    xmLLLrh   c           	      D    t          |          \  }}d                                         d          d                    t	           j        |                                         |j        d                   d                     fd|D                                 S )Nz{}(lambda {}: {}, {})zmpmath.quadr]   r   c              3   b   K   | ])}d t          t          j        |                    z  V  *dS )z(%s, %s)N)r  r  ra   )rc   ry  re   s     rf   rg   z0MpmathPrinter._print_Integral.<locals>.<genexpr>  s<      RRa*uSa-@-@'A'AARRRRRRrh   )r  rn   ro   rp   r  ra   rj   )re   rR   r  r   s   `   rf   _print_IntegralzMpmathPrinter._print_Integral  s    #:1#=#= &&--##M22		#dk+;<<==AF1I&&		RRRR6RRRRR	T T 	Trh   Nr  )rm   rG  rH  __doc__rI  rJ  r   r   rN  rO  _known_functions_mpmathr   _known_constants_mpmathr   r  r  r  r  r  r  r  r  r  r~   rh   rf   r  r    s7          K#H
$uu  HH(?(E(E(G(GHHH   C G
F&=&C&C&E&E
F
F
FCZ Z Z
 
 
' ' '/ / /$ $ $G G GI I IM M M MT T T T Trh   r  c                   D    e Zd ZdZ eej        d          Zd ZddZdS )SymPyPrinterzPython with SymPyFr;  c                      |j         j        pd}                     ||rdndz   |j         j        z             dd                     fd|j        D                       dS )Nr   r   r   r]   c              3   B   K   | ]}                     |          V  d S r_   r`   rb   s     rf   rg   z/SymPyPrinter._print_Function.<locals>.<genexpr>  s/      %L%L3dkk#&6&6%L%L%L%L%L%Lrh   r   )r   rG  ro   rm   rp   rj   )re   rr   mods   `  rf   _print_FunctionzSymPyPrinter._print_Function  sy    i"(b..sS6Hccb/IDIL^/^____99%L%L%L%L$)%L%L%LMMMMO 	Orh   c                 2    |                      ||d          S )Nz
sympy.sqrtr  r  r  s      rf   r  zSymPyPrinter._print_Pow  s    xlKKKrh   Nr  )	rm   rG  rH  rJ  r   ry   rS  r"  r  r~   rh   rf   r  r    se        "H!3  
O O O
L L L L L Lrh   r  N)#r  collectionsr   	itertoolsr   
sympy.corer   sympy.core.modr   r   codeprinterr	   rK  rN  rP  rQ  rt   rw   ry   r_  r  r   r   setattrr  r   r  rO  
_in_mpmathr   r  r  r  r  r  r~   rh   rf   <module>r+     s~   
 $ # # # # #                   " " " " " " $ $ $ $ $ $     

FW F W	
 F W W v 
5 F 
5 F 
5 W   W!" W#$ 
=   D 
	  \ \ \& & &
N2 N2 N2 N2 N2 N2 N2 N2b
E- E- E- E- E- E- E- E-P07 07 07 07 071 07 07 07f 
	 C CAG{Q0ABBBB	 D DAG{Q0BCCCC5 5 54 ##%%ZZ!6!<!<!>!>ZZZ
$z  . .    
	 	 $ $ $&AT AT AT AT AT% AT AT ATH 
	 ? ?AGM;?,=>>>>	  @ @AGM;?,>????L L L L L, L L L L Lrh   