
    sg.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<j3                         Zej7                         D  cg c]  \  } }| evs| |f c}} Z eefi d=d>d?d@dAdBdCdDdEdFdGdHdIZd-d.dJdKdLd0d/dMdNZdO Z  G dP dQe      Z!e!j*                  D ]  Z ee!d:ez  e        eD ]  Z ee!d:ez  e         G dR dSe      Z"yTc c}} w )Uzy
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j                   j	                  |      dj                   fd|j                  D                    S )Nz{name}({args}), c              3   @   K   | ]  }j                  |        y wN_print.0argselfs     H/var/www/html/venv/lib/python3.12/site-packages/sympy/printing/pycode.py	<genexpr>z$_print_known_func.<locals>.<genexpr>F   s     2Y4;;s3C2Y   )nameargs)known_functions	__class____name__format_module_formatjoinrj   re   exprknowns   `  rf   _print_known_funcrt   C   sZ      !8!89E""(;(;E(B(,		2Ytyy2Y(Z # \ \    c                 j    | j                   |j                  j                     }| j                  |      S r_   )known_constantsrl   rm   ro   rq   s      rf   _print_known_constrx   I   s-      !8!89Eu%%ru   c                   N   e Zd ZdZdZeZdZdZ e	 e
ej                         ej                         D  cg c]  \  }}|d|z   f c}}}             Zej                         D  ci c]  \  }}|d|z    c}}} Zdddd	Z e	ej&                  i d
dddd      Zd0fd	Zd Zd1d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:d2d/Z;xZ<S c c}}} w c c}}} w )3AbstractPythonCodePrinter_pythoncodePythonNz    zmath.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
                  j                        }|dk7  rt        d      || _        t        t              | _        t        | j                  fi |xs i j                  di       | _        t        | j                   fi |xs i j                  di       | _        y )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   _kcrw   )re   settingsstdr   rl   s       rf   r   z"AbstractPythonCodePrinter.__init__d   s    " nnZ(;##C$4$4$:$:;C):;;)#.  $DHH  #R0D0Db1"  ##DHH  #R0D0Db1"  #ru   c                     |d|S Nz =  )re   ri   values      rf   _declare_number_constz/AbstractPythonCodePrinter._declare_number_constx   s     %((ru   c                 <   |j                  d      }|rAt        |      dkD  r3| j                  dj                  |d d          j	                  |d          | j
                  d   r|S |j                  d      d   j                  d      d   j                  d      d   S )N.r   r   (r   [)splitlenr   rp   addr   )re   fqnregisterpartss       rf   ro   z(AbstractPythonCodePrinter._module_format{   s    		#E
Qs 4599%)D>>34J99S>!$**3/288=bAAru   c                     |S r_   r   )re   liness     rf   _format_codez&AbstractPythonCodePrinter._format_code   s    ru   c                 $    dj                  |      S )Nz{}rn   )re   
codestrings     rf   _get_statementz(AbstractPythonCodePrinter._get_statement   s    {{:&&ru   c                 $    dj                  |      S )Nz  # {}r   )re   texts     rf   _get_commentz&AbstractPythonCodePrinter._get_comment   s    t$$ru   c                     t        |      dk(  r| j                  |d         S | j                  |      d| j                  ||dd       d| j                  |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   sb     t9>;;tAw'' ##B'++BSb	:DH% ru   c           	          t        |      dk(  r| j                  |d         S t        |      }|dz  }| j                  |      d| j                  |d|       d| j                  ||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   st     t9>;;tAw''D	AFE##B'--d6El;--d56l; ru   c                      y)Nzfloat('nan')r   re   rr   s     rf   
_print_NaNz$AbstractPythonCodePrinter._print_NaN       ru   c                      y)Nzfloat('inf')r   r   s     rf   _print_Infinityz)AbstractPythonCodePrinter._print_Infinity   r   ru   c                      y)Nzfloat('-inf')r   r   s     rf   _print_NegativeInfinityz1AbstractPythonCodePrinter._print_NegativeInfinity   s    ru   c                 $    | j                  |      S r_   )r   r   s     rf   _print_ComplexInfinityz0AbstractPythonCodePrinter._print_ComplexInfinity   s    t$$ru   c                 b     t        |       dj                   fd|j                  D         S )Nz{} % {}c              3   B   K   | ]  }j                  |        y wr_   )parenthesize)rc   xPRECre   s     rf   rg   z7AbstractPythonCodePrinter._print_Mod.<locals>.<genexpr>   s     "Q!4#4#4Q#="Qs   )r   rn   rj   re   rr   r   s   ` @rf   
_print_Modz$AbstractPythonCodePrinter._print_Mod   s*    $ 	  "Qtyy"QRSru   c                 &   g }d}|j                   D ]  }|j                  }|j                  }|dk(  r|j                  d       |j                  d       |j                  | j	                  |             |j                  d       |j                  d       |j                  | j	                  |             |j                  d       |dz  } |d d }|d   dk(  r|d d	 }|j                  d       n|j                  d
       dj                  |      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   s    99 	CAAAvc"MM#MM$++a.)MM#MM&!MM$++a.)MM(#FA	 ":CR[FMM#MM-(wwvru   c                     ddddddd}|j                   |v rT| j                  |j                        }| j                  |j                        }dj	                  |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|     !
 ;;"++dhh'C++dhh'C'..$++3C.PPw(..ru   c                 N    ddl m} | j                  |j                  |            S )Nr   )	Piecewise)$sympy.functions.elementary.piecewiser   ra   rewrite)re   rr   r   s      rf   
_print_ITEz$AbstractPythonCodePrinter._print_ITE   s    B{{4<<	233ru   c                       fd|j                   D        }dj                   j                  |j                        dj	                  |            S )Nc              3      K   | ]I  \  }}}d j                  j                  |      j                  |      j                  |             K yw)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>   sR      (
 1a	 +11++a.++a.++a. 2 "(s   AAz"(builtins.sum({function} {loops})) )functionloops)limitsrn   ra   r   rp   )re   rr   r   s   `  rf   
_print_Sumz$AbstractPythonCodePrinter._print_Sum   sM    (
  ;;( 4::[[/((5/ ; # 	#ru   c                      y)N1jr   r   s     rf   _print_ImaginaryUnitz.AbstractPythonCodePrinter._print_ImaginaryUnit  s    ru   c                     |j                   \  }}dj                  | j                  |      | j                  |            S )Nz(1 if {a} == {b} else 0))r   r   )rj   rn   ra   )re   rr   r   r   s       rf   _print_KroneckerDeltaz/AbstractPythonCodePrinter._print_KroneckerDelta  s=    yy1)00AA 1 
 	
ru   c                     |j                   j                  }| j                  j                  ||      }|d| j	                  |j                               dS )Nr   r   )rl   rm   rk   r   ra   tolist)re   rr   ri   funcs       rf   _print_MatrixBasez+AbstractPythonCodePrinter._print_MatrixBase  sC    ~~&&##''d3T[[]!;<<ru   c                 $    | j                  |      S r_   )r   r   s     rf   <lambda>z"AbstractPythonCodePrinter.<lambda>  s    411$7 ru   c                     dj                  |j                  d      D cg c]  }| j                  |z    c}      S c c}w )N
)rp   r   tab)re   r   lines      rf   _indent_codestringz,AbstractPythonCodePrinter._indent_codestring  s2    yyj6F6Ft6LMd$((T/MNNMs   <c                 N    dj                   fd|j                  D              }dj                   j                  |j                        dj                  |j
                  D cg c]  } j                  |j                         c}       j                  |            S c c}w )Nr   c              3   @   K   | ]  }j                  |        y wr_   r`   rb   s     rf   rg   zFAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<genexpr>"  s     >s$++c*>rh   z def {name}({parameters}):
{body}r]   )ri   
parametersbody)rp   r  rn   ra   ri   r   symbolr   )re   fdr  vars   `   rf   _print_FunctionDefinitionz3AbstractPythonCodePrinter._print_FunctionDefinition!  s|    yy>bgg>?299RWW%yyR]]!Sc$++cjj"9!ST((. : 
 	
!Ss   $"B"c                      dj                   fd|j                  D              }dj                   j                  |j                         j                  |            S )Nr   c              3   @   K   | ]  }j                  |        y w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)  sQ    yy?chh?@&--S]]+((. . 
 	
ru   c                     | j                  |j                  j                        d| j                  |j                  j                        S r   )ra   variabler  r   )re   decls     rf   _print_Declarationz,AbstractPythonCodePrinter._print_Declaration0  s8    KK,,-KK++,
 	
ru   c                      y)Nr   r   )re   bts     rf   _print_BreakTokenz+AbstractPythonCodePrinter._print_BreakToken6  s    ru   c                 F    |j                   \  }d| j                  |      z  S )Nz	return %srj   ra   )re   retrd   s      rf   _print_Returnz'AbstractPythonCodePrinter._print_Return9  s!    xxT[[---ru   c                 F    |j                   \  }d| j                  |      z  S )Nzraise %sr  )re   rsrd   s      rf   _print_Raisez&AbstractPythonCodePrinter._print_Raise=  s!    wwDKK,,,ru   c                 F    |j                   \  }d| j                  |      z  S )NzRuntimeError(%s)r  )re   remessages      rf   _print_RuntimeError_z.AbstractPythonCodePrinter._print_RuntimeError_A  s!    77!DKK$888ru   c                 6    dj                   fd|j                  D              }ddlm} |j                  |k7  r+dj                   j                  |j                        |      }|j                  d k7  r!|d j                  |j                        z  z  }d|z  S )Nr]   c              3   @   K   | ]  }j                  |        y wr_   r`   rb   s     rf   rg   z9AbstractPythonCodePrinter._print_Print.<locals>.<genexpr>F  s     LSC 0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LDOOLM
*%,33D../J 99+DII(>>>JZ''ru   c                     t        |j                        dk(  r| j                  d      S t        |j                        dk(  r| j                  d      S | j                  |j                        S )Nstdoutz
sys.stdoutstderrz
sys.stderr)strri   ro   ra   )re   strms     rf   _print_Streamz'AbstractPythonCodePrinter._print_StreamQ  sW    tyy>X%&&|44^x'&&|44;;tyy))ru   c                      y)Nr   r   )re   rd   s     rf   _print_NoneTokenz*AbstractPythonCodePrinter._print_NoneTokenY  s    ru   c                 2   t        |      }|j                  t        j                  k(  rA|s?| j	                  |      }| j                  |j                        }dj                  ||      S |j                  r|s|j                   t        j                  u rV| j	                  |      }| j                  t        j                        }| j                  |j                        }| d| d| dS |j                  t        j                  u rD| j                  t        j                        }| j                  |j                  |d      }| d| S | j                  |j                  |d      }| j                  |j                  |d      }	dj                  ||	      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\  sY   V $88qvvh&&t,D++dii(C"))t)==xyAFF"**40kk!%%(kk$)),avQse1--xx1==(kk!%%(''		4'Fau~% $$TYYU$C##DHHd5#Ax11ru   r_   )T)Fz	math.sqrt)=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%  r+  r-  r;  __classcell__)rc   kvrl   s   000@rf   rz   rz   N   s   KHNG
C
u &;&A&A&CDDda!Wq[	D C %:$?$?$A
B
BDAq1gai<
BCd59J%% $#()B'%.2%T./ 4	#
= 	88 8"8$8 	8 		8
 	"8 	#O


.-9
(*@2M 	E
Bs   D)D rz   c                   T    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y)ArrayPrinterc                 B    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_arrayrW  	Exception)re   indexedrW  s      rf   	_arrayifyzArrayPrinter._arrayify  s)    a	+G44 	N	s    c           	         | j                         }d}d}|D ci c]  }|D ]  }|t        |        }}}g }	|D ]T  }
g }t        |
      D ]1  }||v r|j                  ||          n|j                  |       |dz  }3 |	j                  |       V i }g }g }|	D ]Y  }|D ]M  }||vrt	        |      }|||<   n||   }||z  }||v r||vs+|j                  |       =|j                  |       O |dz  }[ |d d }|||fS c c}}w )Nr   r   r   ,r   ) _get_letter_generator_for_einsumr,   ranger   next)re   subrankscontraction_indicesletterscontraction_stringcounterr   jdindicesrank_arglindicesmappingletters_freeletters_dumls                   rf   _get_einsum_stringzArrayPrinter._get_einsum_string  s_   779 3?1Q?QAY?Q??  	%HH8_ a<OOAgJ/OOG,1 NN8$	%  	&A +G#WA!"GAJ
A"a'"6+#**1- ''*+ #%	& 04!<<<; @s   D c              #      K   t        dd      D ]  }t        |        t        dd      D ]  }t        |        t        d      w)Na   {   A   [   zout of letters)r_  chrr   )re   r   s     rf   r^  z-ArrayPrinter._get_letter_generator_for_einsum  sN     r3 	Aa&L	r2 	Aa&L	)**s   AA
c                    | j                         }dj                  |j                  D cg c]3  }dj                  t        |      D cg c]  }t	        |       c}      5 c}}      }| j                  | j                  dz   | j                  z         d|ddj                  |j                  D cg c]  }| j                  |       c}      dS c c}w c c}}w c c}w )Nr]  r   r   ("", r]   r   )
r^  rp   ra  r_  r`  ro   _module_einsumrj   ra   )re   rr   rc  r   rf  rd  rd   s          rf   _print_ArrayTensorProductz&ArrayPrinter._print_ArrayTensorProduct  s    779 XX[_[h[h&iVWrwwuQx/P!W/P'Q&ij##DLL3$6$EF"		tyyA4;;s+AB
 	
 0Q&i Bs   C
C	C
3C C
c           
         ddl m} |j                  }|j                  }t	        ||      rHdj                  |j                  D cg c]  }d| j                  |      z   c}      }|j                  }n'| j                  |      }t        |j                        g}| j                  ||      \  }}	}
|s| j                  |      S t	        ||      r<dj                  |j                  D cg c]  }d| j                  |      z   c}      }n| j                  |      }| j                  | j                  dz   | j                  z         ddj                  |dj                  t!        |	                  d	|d
S c c}w c c}w )Nr   ArrayTensorProductr]  z%sr   rw  {}->{}r   rx  r   )0sympy.tensor.array.expressions.array_expressionsr~  rr   rb  
isinstancerp   rj   ra   ra  r   shapero  ro   ry  rz  rn   sorted)re   rr   r~  r3  rb  rd   elemsranksrd  rl  rm  s              rf   _print_ArrayContractionz$ArrayPrinter._print_ArrayContraction  s?   Wyy"66d./HH499MCddkk#&67MNEMMEKK%E_%E8<8O8OPUWj8k5L+";;t$$d./HH499MCddkk#&67MNEKK%Es 2T\\ ABOO.|8L0MN
 	
 N Ns   E8(E=c           	      ,   ddl m} t        |j                        }t	        |j
                  |      r-|j
                  j                  }|j
                  j                  }n|j                  }|j
                  g}| j                  ||      \  }}}|D 	cg c]  }	| j                  |	       }}	| j                  | j                  dz   | j                  z         ddj                  |dj                  ||z               ddj                  |      d	S c c}	w )
Nr   r}  r   rw  r  r   rx  r]   r   )r  r~  listdiagonal_indicesr  rr   ra  rj   ro  ra   ro   ry  rz  rn   rp   )
re   rr   r~  r  ra  r  diagonal_stringrl  rm  r   s
             rf   _print_ArrayDiagonalz!ArrayPrinter._print_ArrayDiagonal  s    W 5 56dii!34yy))HIINNE}}HYYKE595L5LXWg5h2{)./AQ//s 2T\\ ABOOORWW\+5M-NOIIe
 	
 0s   Dc                     | j                  | j                  dz   | j                  z         d| j                  |j                        d| j                  |j
                  j                        dS )Nr   r   r]   r   )ro   ry  
_transposera   rr   permutation
array_formr   s     rf   _print_PermuteDimszArrayPrinter._print_PermuteDims  sT    s 2T__ DEKK		"KK((334
 	
ru   c                 n    | j                  | j                  dz   | j                  z   |j                        S )Nr   )r   ry  _addrj   r   s     rf   _print_ArrayAddzArrayPrinter._print_ArrayAdd  s+    **4<<#+=		+I499UUru   c                     | j                  | j                  dz   | j                  z         ddj                  t	        | j
                  |j                              dS Nr   z((r]  z,)))ro   ry  _onesrp   mapra   rj   r   s     rf   _print_OneArrayzArrayPrinter._print_OneArray  sG    c 1DJJ >?HHSTYY/0
 	
ru   c                     | j                  | j                  dz   | j                  z         ddj                  t	        | j
                  |j                              dS r  )ro   ry  _zerosrp   r  ra   rj   r   s     rf   _print_ZeroArrayzArrayPrinter._print_ZeroArray  sG    c 1DKK ?@HHSTYY/0
 	
ru   c                     | j                  | j                  |j                              }| j                  | j                  |j                              }|d|S r   )ra   r[  r   r   )re   rr   r   r   s       rf   _print_AssignmentzArrayPrinter._print_Assignment  sE     kk$..23kk$..23 #''ru   c                 $    | j                  |      S r_   )_print_ArraySymbolr   s     rf   _print_IndexedBasezArrayPrinter._print_IndexedBase#  s    &&t,,ru   N)rm   r<  r=  r[  ro  r^  r{  r  r  r  r  r  r  r  r  r   ru   rf   rU  rU    s@    !=F+

4
"
V

(-ru   rU  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j                  | j                  d      | j                  |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)  s=    3::!!/2dkk!&&)6L ; N 	Nru   c                 v    t        |      }| j                  d   | j                  |j                  d   |      z   S )Nr   r   )r   rG  r   rj   r   s      rf   
_print_NotzPythonCodePrinter._print_Not-  s5    $u%(9(9$))A,(MMMru   c                     |j                   S r_   )ri   r   s     rf   r  z$PythonCodePrinter._print_IndexedBase1  s    yyru   c                     |j                   d   }|j                   dd  }dj                  t        |      dj                  |D cg c]  }| j	                  |       c}            S c c}w )Nr   r   z{}[{}]r]   )rj   rn   r)  rp   ra   )re   rr   r3  indexinds        rf   _print_Indexedz PythonCodePrinter._print_Indexed4  sT    yy|		!"s4y$))QV4W#T[[5E4W*XYY4Ws   A&c                 (    | j                  ||      S )N)r7  r;  re   rr   r7  s      rf   
_print_PowzPythonCodePrinter._print_Pow9  s    x88ru   c                 N    dj                  |j                  |j                        S )Nz{}/{})rn   pqr   s     rf   _print_Rationalz!PythonCodePrinter._print_Rational<  s    ~~dffdff--ru   c                 $    | j                  |      S r_   r  r   s     rf   _print_HalfzPythonCodePrinter._print_Half?  s    ##D))ru   c                 R    | j                  t        |j                  d   d            S )Nr   r   )r   r   rj   r   s     rf   _print_fraczPythonCodePrinter._print_fracB  s     s499Q<344ru   c                    t         |   |      }|| j                  v r=| j                  d   rd}t	        |j                  |            || j                  d   z   S d|v r"|j                  dd      j                  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_SymbolrA  r   r   rn   replace)re   rr   ri   msgrl   s       rf   r  zPythonCodePrinter._print_SymbolE  s    w$T*4&&&~~12< D!122$..)?@@@D[<<R(00b99Kru   F)rm   r<  r=  r  r  r  r  r  r  r  r  r  r	   _print_not_supported_print_lowergamma_print_uppergamma_print_fresnelc_print_fresnelsrQ  )rl   s   @rf   r  r  '  sc    NNZ
9.*5 $88#88!66O!66Oru   r  z	_print_%sc                 6    t        |      j                  |       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4ru   z
log1p log2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 ]F  }t        |      dk(  r|\  }}}nt        d      |j                  |       |j                  ||f       H ||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    sw     F*11 2 !Q&8I5O[+%&MNN0{K012 V##ru   c                   H   e Zd ZdZdZdZ e eej                         e
j                         D  cg c]  \  }}|d|z   f c}}}             Zej                         D  ci c]  \  }}|d|z    c}}} Zd Zd Zd Zd Zd	 Zd
 Zd ZddZd Zyc c}}} w c c}}} w )MpmathPrinterzH
    Lambda printer for mpmath which maintains precision for floats
    _mpmathcodezPython with mpmathzmpmath.c                     t        t        t        t        |j                                    }dj                  | j                  d      |      S )Nz{func}({args})
mpmath.mpf)r   rj   )r)  tupler  int_mpf_rn   ro   )re   rR   rj   s      rf   _print_FloatzMpmathPrinter._print_Float  s@     5S!''*+,&&D,?,?,MTX&YYru   c                     dj                  | j                  d      | j                  |j                        | 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  sH    (//$$\2kk!##kk!## 0 
 	
ru   c                 $    | j                  |      S r_   r  r  s     rf   r  zMpmathPrinter._print_Half  s    ##A&&ru   c                     dj                  | j                  d      | j                  |j                  d         | j                  |j                  d         | j                  d            S )Nz{}({}, {}, {})mpmath.gammaincr   r   z
mpmath.infr  r  s     rf   r  zMpmathPrinter._print_uppergamma  sZ    && 12KKq	"KKq	"-	/ 	/ru   c                     dj                  | j                  d      | j                  |j                  d         | j                  |j                  d               S )Nz{}({}, 0, {})r  r   r   r  r  s     rf   r  zMpmathPrinter._print_lowergamma  sL    %% 12KKq	"KKq	"$ 	$ru   c                 |    dj                  | j                  d      | j                  |j                  d               S )Nz{0}({1})/{0}(2)z
mpmath.logr   r  r  s     rf   _print_log2zMpmathPrinter._print_log2  s8     ''-t{{166!9/EG 	Gru   c                 |    dj                  | j                  d      | j                  |j                  d               S )Nz{}({})zmpmath.log1pr   r  r  s     rf   _print_log1pzMpmathPrinter._print_log1p  s6    /QVVAY1GI 	Iru   c                 *    | j                  ||d      S )Nzmpmath.sqrtr7  rL   r  r  s      rf   r  zMpmathPrinter._print_Pow  s    xmLLru   c           	          t        |      \  }}dj                   j                  d      dj                  t	         j
                  |             j                  |j                  d         dj                   fd|D                    S )Nz{}(lambda {}: {}, {})zmpmath.quadr]   r   c              3   b   K   | ]&  }d t        t        j                  |            z   ( yw)z(%s, %s)N)r  r  ra   )rc   rn  re   s     rf   rg   z0MpmathPrinter._print_Integral.<locals>.<genexpr>  s&     Ra*uSa-@'AARs   ,/)r  rn   ro   rp   r  ra   rj   )re   rR   r  r   s   `   rf   _print_IntegralzMpmathPrinter._print_Integral  st    #:1#= &&--##M2		#dkk+;<=AFF1I&		R6RR	T 	Tru   Nr  )rm   r<  r=  __doc__r>  r?  r   r   rC  rD  _known_functions_mpmathr   _known_constants_mpmathr   r  r  r  r  r  r  r  r  r   )rc   rR  rS  s   000rf   r  r    s      K#H
u (?(E(E(GHH1!Y]	H C '>&C&C&E
F
Fda1ik>
FCZ
'/$GIMTa 	I
Fs   B$Br  c                   F    e Zd ZdZ eej                  d      Zd ZddZy)SymPyPrinterzPython with SymPyFr0  c                      |j                   j                  xs d} j                  ||rdndz   |j                   j                  z         ddj	                   fd|j
                  D              dS )Nr   r   r   r]   c              3   @   K   | ]  }j                  |        y wr_   r`   rb   s     rf   rg   z/SymPyPrinter._print_Function.<locals>.<genexpr>  s     %L3dkk#&6%Lrh   r   )r   r<  ro   rm   rp   rj   )re   rr   mods   `  rf   _print_FunctionzSymPyPrinter._print_Function  s_    ii""(b..sScb/IDIIL^L^/^_99%L$))%LMO 	Oru   c                 *    | j                  ||d      S )Nz
sympy.sqrtr  r  r  s      rf   r  zSymPyPrinter._print_Pow  s    xlKKru   Nr  )	rm   r<  r=  r?  r   rz   rH  r	  r  r   ru   rf   r  r    s*    "H!33
O
Lru   r  N)#r  collectionsr   	itertoolsr   
sympy.corer   sympy.core.modr   r   codeprinterr	   r@  rC  rE  rF  rt   rx   rz   rU  r  r   rR  setattrr  r   _not_in_mpmathrD  
_in_mpmathr   r  r  r  r  r  )rR  rS  s   00rf   <module>r     s  
 $    " $  

FW F W	
 F W W v 
5 F 
5 F 
5 W   W!" W#$ 
= D 
	 \&
N2 N2b
E- E-P071 07f 
		 CA{Q0ABC 
 DA{Q0BCD54 ##%!6!<!<!>ZA!>BYq!fZ
z .   
	 $&AT% ATH 
		 ?AM;?,=>? 
! @AM;?,>?@L, Ls [s   =F
F