
    Цi.a                     &   S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J	r	  SSK
Jr  1 S	krS
SSS.r0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S!S"S#S#S$S%S&S'S(S)S*S+S,.ErS-S.S-S/S0S0S1.rS2 rS3 r " S4 S5\5      r " S6 S75      r " S8 S9\5      r\R*                   H  r\" \S:\-  \5        M     \ H  r\" \S:\-  \5        M     S; rS<R3                  5       r\R7                  5        V Vs/ s H  u  pU \;  d  M  X4PM     snn r\" \40 S=S>S?S@SASBSCSDSESFSGSHSI.D6rS-S.SJSKSLS0S/SMSN.rSO r  " SP SQ\5      r!\!R*                   H  r\" \!S:\-  \5        M     \ H  r\" \!S:\-  \5        M      " SR SS\5      r"gTs  snn f )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                    ^  T R                   UR                  R                     nSR                  T R	                  U5      SR                  U 4S jUR                   5       5      S9$ )Nz{name}({args}), c              3   F   >#    U  H  nTR                  U5      v   M     g 7fN_print.0argselfs     T/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/sympy/printing/pycode.py	<genexpr>$_print_known_func.<locals>.<genexpr>F   s     2Yy4;;s3C3Cy   !)nameargs)known_functions	__class____name__format_module_formatjoinrk   re   exprknowns   `  rf   _print_known_funcru   C   sZ      !8!89E""(;(;E(B(,		2Ytyy2Y(Z # \ \    c                 j    U R                   UR                  R                     nU R                  U5      $ r_   )known_constantsrm   rn   rp   rr   s      rf   _print_known_constry   I   s-      !8!89Eu%%rv   c                   b  ^ \ rS rSrSrSr\rSrSr	\
" \" \R                  5       \R                  5        V VVs/ s H  u  pUSU-   4PM     snnn 5      5      r\R                  5        V VVs0 s H  u  pUSU-   _M     snnn rSSS	S
.r\
" \R(                  0 SSSSSS9rS2U4S jjrS rS3S jrS rS rS rS rS rS rS rS rS r S r!S r"U4S jr#S r$S  r%S! r&S" r'S# r(S$ =r)=r*=r+=r,=r-=r.=r/r0S% r1S& r2S' r3S( r4S) r5S* r6S+ r7S, r8S- r9S. r:S/ r;S4S0 jr<S1r=U=r>$ s  snnn f s  snnn f )5AbstractPythonCodePrinterN   _pythoncodePythonNz    zmath.r   r   r   )r   r   r      TFpython3)user_functions	precisioninlinefully_qualified_modulescontractstandardc                   > [         TU ]  U5        U R                  S   nUc)  SS KnSR	                  UR
                  R                  5      nUS:w  a  [        S5      eX l        [        [        5      U l        [        U R                  40 U=(       d    0 R                  S0 5      D6U l        [        U R                   40 U=(       d    0 R                  S0 5      D6U l        g )Nr   r   zpython{}r   zOnly Python 3 is supported.r   user_constants)super__init__	_settingssysro   version_infomajor
ValueErrorr   r   setmodule_importsdict_kfgetrl   _kcrx   )re   settingsstdr   rm   s       rf   r   "AbstractPythonCodePrinter.__init__d   s    " nnZ(;##C$4$4$:$:;C):;;)#.  $DHH  #R0D0Db1"  ##DHH  #R0D0Db1"  #rv   c                     U< SU< 3$ Nz =  )re   rj   values      rf   _declare_number_const/AbstractPythonCodePrinter._declare_number_constx   s     %((rv   c                 R   UR                  S5      nU(       aB  [        U5      S:  a3  U R                  SR                  US S 5         R	                  US   5        U R
                  S   (       a  U$ UR                  S5      S   R                  S5      S   R                  S5      S   $ )N.r   r   (r   [)splitlenr   rq   addr   )re   fqnregisterpartss       rf   rp   (AbstractPythonCodePrinter._module_format{   s    		#E
Qs 4599%)D>>34J99S>!$**3/288=bAArv   c                     U$ r_   r   )re   liness     rf   _format_code&AbstractPythonCodePrinter._format_code   s    rv   c                 $    SR                  U5      $ )Nz{}ro   )re   
codestrings     rf   _get_statement(AbstractPythonCodePrinter._get_statement   s    {{:&&rv   c                 $    SR                  U5      $ )Nz  # {}r   )re   texts     rf   _get_comment&AbstractPythonCodePrinter._get_comment   s    t$$rv   c                     [        U5      S:X  a  U R                  US   5      $ U R                  U5      < SU R                  XSS 5      < SU R                  US   5      < S3$ )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   rp   _expand_fold_binary_op)re   oprk   s      rf   r   0AbstractPythonCodePrinter._expand_fold_binary_op   s`     t9>;;tAw'' ##B'++BSb	:DH% rv   c           	          [        U5      S:X  a  U R                  US   5      $ [        U5      nUS-  nU R                  U5      < SU R                  USU 5      < SU R                  X$S 5      < S3$ )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   rp   _expand_reduce_binary_op)re   r   rk   NNhalfs        rf   r   2AbstractPythonCodePrinter._expand_reduce_binary_op   sr     t9>;;tAw''D	AFE##B'--d6El;--d6l; rv   c                     g)Nzfloat('nan')r   re   rs   s     rf   
_print_NaN$AbstractPythonCodePrinter._print_NaN       rv   c                     g)Nzfloat('inf')r   r   s     rf   _print_Infinity)AbstractPythonCodePrinter._print_Infinity   r   rv   c                     g)Nzfloat('-inf')r   r   s     rf   _print_NegativeInfinity1AbstractPythonCodePrinter._print_NegativeInfinity   s    rv   c                 $    U R                  U5      $ r_   )r   r   s     rf   _print_ComplexInfinity0AbstractPythonCodePrinter._print_ComplexInfinity   s    t$$rv   c                 d   ^ ^ [        U5      mSR                  " UU 4S jUR                   5       6 $ )Nz{} % {}c              3   H   >#    U  H  nTR                  UT5      v   M     g 7fr_   )parenthesize)rc   xPRECre   s     rf   rg   7AbstractPythonCodePrinter._print_Mod.<locals>.<genexpr>   s!     "Qy!4#4#4Q#=#=ys   ")r   ro   rk   re   rs   r   s   ` @rf   
_print_Mod$AbstractPythonCodePrinter._print_Mod   s(    $  "Qtyy"QRSrv   c                 .   / nSnUR                    H  nUR                  nUR                  nUS:X  a  UR                  S5        UR                  S5        UR                  U R	                  U5      5        UR                  S5        UR                  S5        UR                  U R	                  U5      5        UR                  S5        US-  nM     US S nUS   S:X  a  US S	 nUR                  S5        OUR                  S
5        SR                  U5      $ )Nr   r   r   z if z else r   r   r   z else None) )rk   rs   condappendra   rq   )re   rs   resultird   rR   cs          rf   _print_Piecewise*AbstractPythonCodePrinter._print_Piecewise   s    99CAAAvc"MM#MM$++a.)MM#MM&!MM$++a.)MM(#FA  ":CR[FMM#MM-(wwvrv   c                    > SSSSSSS.nUR                   U;   aP  U R                  UR                  5      nU R                  UR                  5      nSR	                  UR                   X4S	9$ [
        TU ]  U5      $ )
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   ro   r   _print_Relational)re   rs   r   r   r   rm   s        rf   r   +AbstractPythonCodePrinter._print_Relational   sz     !
 ;;"++dhh'C++dhh'C'..$++3.PPw(..rv   c                 N    SSK Jn  U R                  UR                  U5      5      $ )Nr   )	Piecewise)$sympy.functions.elementary.piecewiser   ra   rewrite)re   rs   r   s      rf   
_print_ITE$AbstractPythonCodePrinter._print_ITE   s    B{{4<<	233rv   c                    ^  U 4S jUR                    5       nSR                  T R                  UR                  5      SR	                  U5      S9$ )Nc              3      >#    U  HF  u  pnS R                  TR                  U5      TR                  U5      TR                  U5      S9v   MH     g7f)zfor {i} in range({a}, {b}+1))r   abN)ro   ra   )rc   r   r   r   re   s       rf   rg   7AbstractPythonCodePrinter._print_Sum.<locals>.<genexpr>   sQ      (
 'a	 +11++a.++a.++a. 2 " 's   AAz"(builtins.sum({function} {loops})) )functionloops)limitsro   ra   r   rq   )re   rs   r   s   `  rf   
_print_Sum$AbstractPythonCodePrinter._print_Sum   sM    (
  ;;( 4::[[/((5/ ; # 	#rv   c                     g)N1jr   r   s     rf   _print_ImaginaryUnit.AbstractPythonCodePrinter._print_ImaginaryUnit  s    rv   c                 z    UR                   u  p#SR                  U R                  U5      U R                  U5      S9$ )Nz(1 if {a} == {b} else 0))r   r   )rk   ro   ra   )re   rs   r   r   s       rf   _print_KroneckerDelta/AbstractPythonCodePrinter._print_KroneckerDelta  s;    yy)00AA 1 
 	
rv   c                     UR                   R                  nU R                  R                  X"5      nU< SU R	                  UR                  5       5      < S3$ )Nr   r   )rm   rn   rl   r   ra   tolist)re   rs   rj   funcs       rf   _print_MatrixBase+AbstractPythonCodePrinter._print_MatrixBase  sA    ~~&&##''3T[[]!;<<rv   c                 $    U R                  U5      $ r_   )r  r   s     rf   <lambda>"AbstractPythonCodePrinter.<lambda>  s    411$7rv   c                     SR                  UR                  S5       Vs/ s H  o R                  U-   PM     sn5      $ s  snf )N
)rq   r   tab)re   r   lines      rf   _indent_codestring,AbstractPythonCodePrinter._indent_codestring  s6    yyj6F6Ft6LM6Ld((T/6LMNNMs   >c                 P  ^  SR                  U 4S jUR                   5       5      nSR                  T R                  UR                  5      SR                  UR
                   Vs/ s H  nT R                  UR                  5      PM      sn5      T R                  U5      S9$ s  snf )Nr  c              3   F   >#    U  H  nTR                  U5      v   M     g 7fr_   r`   rb   s     rf   rg   FAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<genexpr>"  s     >gs$++c**gri   z def {name}({parameters}):
{body}r]   )rj   
parametersbody)rq   r  ro   ra   rj   r  symbolr  )re   fdr  vars   `   rf   _print_FunctionDefinition3AbstractPythonCodePrinter._print_FunctionDefinition!  s    yy>bgg>?299RWW%yyR]]!S]c$++cjj"9]!ST((. : 
 	
!Ss   %%B#c                    ^  SR                  U 4S jUR                   5       5      nSR                  T R                  UR                  5      T R                  U5      S9$ )Nr  c              3   F   >#    U  H  nTR                  U5      v   M     g 7fr_   r`   rb   s     rf   rg   9AbstractPythonCodePrinter._print_While.<locals>.<genexpr>*  s     ?hs$++c**hri   zwhile {cond}:
{body})r   r  )rq   r  ro   ra   	conditionr  )re   whlr  s   `  rf   _print_While&AbstractPythonCodePrinter._print_While)  sQ    yy?chh?@&--S]]+((. . 
 	
rv   c                     U R                  UR                  R                  5      < SU R                  UR                  R                  5      < 3$ r   )ra   variabler  r   )re   decls     rf   _print_Declaration,AbstractPythonCodePrinter._print_Declaration0  s8    KK,,-KK++,
 	
rv   c                     g)Nr   r   )re   bts     rf   _print_BreakToken+AbstractPythonCodePrinter._print_BreakToken6  s    rv   c                 F    UR                   u  nSU R                  U5      -  $ )Nz	return %srk   ra   )re   retrd   s      rf   _print_Return'AbstractPythonCodePrinter._print_Return9  s!    xxT[[---rv   c                 F    UR                   u  nSU R                  U5      -  $ )Nzraise %sr3  )re   rsrd   s      rf   _print_Raise&AbstractPythonCodePrinter._print_Raise=  s!    wwDKK,,,rv   c                 F    UR                   u  nSU R                  U5      -  $ )NzRuntimeError(%s)r3  )re   remessages      rf   _print_RuntimeError_.AbstractPythonCodePrinter._print_RuntimeError_A  s!    77!DKK$888rv   c                 <  ^  SR                  U 4S jUR                   5       5      nSSKJn  UR                  U:w  a+  SR                  T R                  UR                  5      U5      nUR                  S :w  a!  UST R                  UR                  5      -  -  nSU-  $ )Nr]   c              3   F   >#    U  H  nTR                  U5      v   M     g 7fr_   r`   rb   s     rf   rg   9AbstractPythonCodePrinter._print_Print.<locals>.<genexpr>F  s     LOSC 0 0Ori   r   )nonez{} % ({}), end=""z	, file=%sz	print(%s))rq   
print_argssympy.codegen.astrC  format_stringro   ra   file)re   prntrD  rC  s   `   rf   _print_Print&AbstractPythonCodePrinter._print_PrintE  s    YYLDOOLM
*%,33D../J 99+DII(>>>JZ''rv   c                     [        UR                  5      S:X  a  U R                  S5      $ [        UR                  5      S:X  a  U R                  S5      $ U R                  UR                  5      $ )Nstdoutz
sys.stdoutstderrz
sys.stderr)strrj   rp   ra   )re   strms     rf   _print_Stream'AbstractPythonCodePrinter._print_StreamQ  sW    tyy>X%&&|44^x'&&|44;;tyy))rv   c                     g)Nr   r   )re   rd   s     rf   _print_NoneToken*AbstractPythonCodePrinter._print_NoneTokenY  s    rv   c                 :   [        U5      nUR                  [        R                  :X  aB  U(       d;  U R	                  U5      nU R                  UR                  5      nSR                  XVS9$ UR                  (       a  U(       d  UR                  * [        R                  L aV  U R	                  U5      nU R                  [        R                  5      nU R                  UR                  5      nU SU SU S3$ UR                  [        R                  L aA  U R                  [        R                  5      nU R                  UR                  USS9nU SU 3$ U R                  UR                  USS9nU R                  UR                  USS9n	SR                  X5      $ )	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   Halfrp   ra   basero   is_commutativeOneNegativeOner   )
re   rs   rationalrL   r   r  rd   numbase_strexp_strs
             rf   _hprint_Pow%AbstractPythonCodePrinter._hprint_Pow\  sU   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1rv   )rx   rl   r   r   r_   )T)Fz	math.sqrt)?rn   
__module____qualname____firstlineno__printmethodlanguage_kwreserved_wordsmodulesr  r   r   _known_functionsitems_known_functions_mathr   _known_constants_mathr   
_operatorsr	   _default_settingsr   r   rp   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,  r0  r5  r9  r>  rI  rP  rS  rb  __static_attributes____classcell__)rc   kvrm   s   000@rf   r{   r{   N   s   KHNG
C
u &;&A&A&CD&Cda!Wq[	&CD C %:$?$?$A
B$ADA1gai<$A
BCd59J%% $#()B'%.2%T./ 4	#
= 	88 8"8$8 	8 		8
 	"8 	#O


.-9
(*@2 @2M 	E
Bs   D#-D*r{   c                   \    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rSrg)ArrayPrinteri  c                 D    SSK Jn   U" U5      $ ! [         a    Us $ f = f)Nr   )convert_indexed_to_array)4sympy.tensor.array.expressions.from_indexed_to_arrayr  	Exception)re   indexedr  s      rf   	_arrayifyArrayPrinter._arrayify  s)    a	+G44 	N	s    c           	      &   U R                  5       nSnSnU VVs0 s H  of  H  ow[        U5      _M     M     nnn/ n	U HW  n
/ n[        U
5       H2  nXX;   a  UR                  X   5        OUR                  U5        US-  nM4     U	R                  U5        MY     0 n/ n/ nU	 H^  nU HP  nX|;  a  [	        U5      nXU'   OX   nXO-  nXx;   a  X;  a  UR                  U5        M=  M?  UR                  U5        MR     US-  nM`     US S nXMU4$ s  snnf )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_stringArrayPrinter._get_einsum_string  s=   779 3? 31QAYQQ 3? HH8_<OOAJ/OOG,1 % NN8$ ! A#WA!"AJ
A"'"6+#**1- , !''*  #%  04!<<; @s   Dc              #      #    [        SS5       H  n[        U5      v   M     [        SS5       H  n[        U5      v   M     [        S5      e7f)Na   {   A   [   zout of letters)r  chrr   )re   r   s     rf   r  -ArrayPrinter._get_letter_generator_for_einsum  sC     r3Aa&L  r2Aa&L )**s   AAc                    U R                  5       nSR                  UR                   VVs/ s H7  nSR                  [        U5       Vs/ s H  n[	        U5      PM     sn5      PM9     snn5      nU R                  U R                  S-   U R                  -   5      < SU< SSR                  UR                   Vs/ s H  o`R                  U5      PM     sn5      < S3$ s  snf s  snnf s  snf )Nr  r   r   ("", r]   r   )
r  rq   r  r  r  rp   _module_einsumrk   ra   )re   rs   r  r   r  r  rd   s          rf   _print_ArrayTensorProduct&ArrayPrinter._print_ArrayTensorProduct  s    779 XX[_[h[h&i[hVWrwwuQx/Px!Wx/P'Q[h&ij##DLL3$6$EF"		tyyAy;;s+yAB
 	
 0Q&i Bs   C%
	C C%
;C+ C%
c           
      ,   SSK Jn  UR                  nUR                  n[	        X25      (       aK  SR                  UR                   Vs/ s H  nSU R                  U5      -  PM     sn5      nUR                  nO'U R                  U5      n[        UR                  5      /nU R                  Xt5      u  pn
U(       d  U R                  U5      $ [	        X25      (       a?  SR                  UR                   Vs/ s H  nSU R                  U5      -  PM     sn5      nOU R                  U5      nU R                  U R                  S-   U R                  -   5      < SSR                  USR                  [!        U	5      5      5      < S	U< S
3$ s  snf s  snf )Nr   ArrayTensorProductr  z%sr   r  {}->{}r   r  r   )0sympy.tensor.array.expressions.array_expressionsr  rs   r  
isinstancerq   rk   ra   r  r   shaper  rp   r  r  ro   sorted)re   rs   r  rZ  r  rd   elemsranksr  r  r  s              rf   _print_ArrayContraction$ArrayPrinter._print_ArrayContraction  sB   Wyy"66d//HH499M9Cddkk#&679MNEMMEKK%E_%E8<8O8OPU8k5+";;t$$d//HH499M9Cddkk#&679MNEKK%Es 2T\\ ABOO.|8L0MN
 	
 N Ns   F6Fc           	      :   SSK Jn  [        UR                  5      n[	        UR
                  U5      (       a-  UR
                  R                  nUR
                  R                  nOUR                  nUR
                  /nU R                  XC5      u  pgnU V	s/ s H  oR                  U	5      PM     nn	U R                  U R                  S-   U R                  -   5      < SSR                  USR                  Xx-   5      5      < SSR                  U5      < S	3$ s  sn	f )
Nr   r  r   r  r  r   r  r]   r   )r  r  listdiagonal_indicesr  rs   r  rk   r  ra   rp   r  r  ro   rq   )
re   rs   r  r  r  r  diagonal_stringr  r  r   s
             rf   _print_ArrayDiagonal!ArrayPrinter._print_ArrayDiagonal  s    W 5 56dii!344yy))HIINNE}}HYYKE595L5LX5h2{)./AQ/s 2T\\ ABOOORWW\5M-NOIIe
 	
 0s   Dc                     U R                  U R                  S-   U R                  -   5      < SU R                  UR                  5      < SU R                  UR
                  R                  5      < S3$ )Nr   r   r]   r   )rp   r  
_transposera   rs   permutation
array_formr   s     rf   _print_PermuteDimsArrayPrinter._print_PermuteDims  sT    s 2T__ DEKK		"KK((334
 	
rv   c                 n    U R                  U R                  S-   U R                  -   UR                  5      $ )Nr   )r   r  _addrk   r   s     rf   _print_ArrayAddArrayPrinter._print_ArrayAdd  s+    **4<<#+=		+I499UUrv   c                     U R                  U R                  S-   U R                  -   5      < SSR                  [	        U R
                  UR                  5      5      < S3$ Nr   z((r  z,)))rp   r  _onesrq   mapra   rk   r   s     rf   _print_OneArrayArrayPrinter._print_OneArray  sG    c 1DJJ >?HHSTYY/0
 	
rv   c                     U R                  U R                  S-   U R                  -   5      < SSR                  [	        U R
                  UR                  5      5      < S3$ r  )rp   r  _zerosrq   r  ra   rk   r   s     rf   _print_ZeroArrayArrayPrinter._print_ZeroArray  sG    c 1DKK ?@HHSTYY/0
 	
rv   c                     U R                  U R                  UR                  5      5      nU R                  U R                  UR                  5      5      nU< SU< 3$ r   )ra   r  r   r   )re   rs   r   r   s       rf   _print_AssignmentArrayPrinter._print_Assignment  sE     kk$..23kk$..23 #''rv   c                 $    U R                  U5      $ r_   )_print_ArraySymbolr   s     rf   _print_IndexedBaseArrayPrinter._print_IndexedBase#  s    &&t,,rv   r   N)rn   rd  re  rf  r  r  r  r  r  r  r  r  r  r  r  r  rz  r   rv   rf   r  r    s@    !=F+

4
"
V

(-rv   r  c                      ^  \ rS rSrS rS rS rS rSS jrS r	S r
S	 rU 4S
 jr\R                  r\R                  r\R                  r\R                  rSrU =r$ )PythonCodePrinteri'  c                 x    SR                  U R                  S5      U R                  UR                  S   5      S9$ )Nz"(0.0 if {e} == 0 else {f}(1, {e}))zmath.copysignr   )frR   ro   rp   ra   rk   re   rR   s     rf   _print_signPythonCodePrinter._print_sign)  s=    3::!!/2dkk!&&)6L ; N 	Nrv   c                 v    [        U5      nU R                  S   U R                  UR                  S   U5      -   $ )Nr   r   )r   rp  r   rk   r   s      rf   
_print_NotPythonCodePrinter._print_Not-  s5    $u%(9(9$))A,(MMMrv   c                     UR                   $ r_   )rj   r   s     rf   r  $PythonCodePrinter._print_IndexedBase1  s    yyrv   c                     UR                   S   nUR                   SS  nSR                  [        U5      SR                  U Vs/ s H  o@R	                  U5      PM     sn5      5      $ s  snf )Nr   r   z{}[{}]r]   )rk   ro   rN  rq   ra   )re   rs   rZ  indexinds        rf   _print_Indexed PythonCodePrinter._print_Indexed4  sX    yy|		!"s4y$))QV4WQV#[[5EQV4W*XYY4Ws   A(c                      U R                  XS9$ )N)r^  rb  re   rs   r^  s      rf   
_print_PowPythonCodePrinter._print_Pow9  s    88rv   c                 N    SR                  UR                  UR                  5      $ )Nz{}/{})ro   pqr   s     rf   _print_Rational!PythonCodePrinter._print_Rational<  s    ~~dffdff--rv   c                 $    U R                  U5      $ r_   r  r   s     rf   _print_HalfPythonCodePrinter._print_Half?  s    ##D))rv   c                 R    U R                  [        UR                  S   S5      5      $ )Nr   r   )r   r   rk   r   s     rf   _print_fracPythonCodePrinter._print_fracB  s     s499Q<344rv   c                   > [         TU ]  U5      nX R                  ;   aA  U R                  S   (       a  Sn[	        UR                  U5      5      eX R                  S   -   $ SU;   a"  UR                  SS5      R                  SS5      $ U$ )Nerror_on_reservedzVThis expression includes the symbol "{}" which is a reserved keyword in this language.reserved_word_suffix{r   })r   _print_Symbolrj  r   r   ro   replace)re   rs   rj   msgrm   s       rf   r  PythonCodePrinter._print_SymbolE  s    w$T*&&&~~12< D!122..)?@@@D[<<R(00b99Krv   r   F)rn   rd  re  rf  r  r  r  r  r  r  r  r  r  r	   _print_not_supported_print_lowergamma_print_uppergamma_print_fresnelc_print_fresnelsrz  r{  )rm   s   @rf   r  r  '  sc    NNZ
9.*5 $88#88!66O!66Orv   r  z	_print_%sc                 6    [        U5      R                  U 5      $ )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)rs   r   s     rf   pycoder  a  s    . X&..t44rv   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                     / n/ nU R                    HF  n[        U5      S:X  a  Uu  pEnO[        S5      eUR                  U5        UR                  XV45        MH     X4$ )zhelper 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(    sl     F*11 !Q&8I5O+%&MNN0{01 2 ##rv   c                   Z   \ rS rSrSrSrSr\" \" \	R                  5       \R                  5        V VVs/ s H  u  pUSU-   4PM     snnn 5      5      r\R                  5        V VVs0 s H  u  pUSU-   _M     snnn rS rS rS rS	 rS
 rS rS rSS jrS rSrgs  snnn f s  snnn f )MpmathPrinteri  z@
Lambda printer for mpmath which maintains precision for floats
_mpmathcodezPython with mpmathzmpmath.c                     [        [        [        [        UR                  5      5      5      nSR                  U R                  S5      US9$ )Nz{func}({args})
mpmath.mpf)r  rk   )rN  tupler  int_mpf_ro   rp   )re   rR   rk   s      rf   _print_FloatMpmathPrinter._print_Float  s@     5S!''*+,&&D,?,?,MTX&YYrv   c                     SR                  U R                  S5      U R                  UR                  5      U R                  UR                  5      S9$ )Nz{func}({p})/{func}({q})r-  )r  r  r  )ro   rp   ra   r  r  r  s     rf   r  MpmathPrinter._print_Rational  sH    (//$$\2kk!##kk!## 0 
 	
rv   c                 $    U R                  U5      $ r_   r  r  s     rf   r  MpmathPrinter._print_Half  s    ##A&&rv   c                     SR                  U R                  S5      U R                  UR                  S   5      U R                  UR                  S   5      U R                  S5      5      $ )Nz{}({}, {}, {})mpmath.gammaincr   r   z
mpmath.infr  r  s     rf   r  MpmathPrinter._print_uppergamma  sZ    && 12KKq	"KKq	"-	/ 	/rv   c                     SR                  U R                  S5      U R                  UR                  S   5      U R                  UR                  S   5      5      $ )Nz{}({}, 0, {})r8  r   r   r  r  s     rf   r  MpmathPrinter._print_lowergamma  sL    %% 12KKq	"KKq	"$ 	$rv   c                 |    SR                  U R                  S5      U R                  UR                  S   5      5      $ )Nz{0}({1})/{0}(2)z
mpmath.logr   r  r  s     rf   _print_log2MpmathPrinter._print_log2  s8     ''-t{{166!9/EG 	Grv   c                 |    SR                  U R                  S5      U R                  UR                  S   5      5      $ )Nz{}({})zmpmath.log1pr   r  r  s     rf   _print_log1pMpmathPrinter._print_log1p  s6    /QVVAY1GI 	Irv   c                 "    U R                  XSS9$ )Nzmpmath.sqrtr^  rL   r  r  s      rf   r  MpmathPrinter._print_Pow  s    mLLrv   c           	        ^  [        U5      u  p#SR                  T R                  S5      SR                  [	        T R
                  U5      5      T R                  UR                  S   5      SR                  U 4S jU 5       5      5      $ )Nz{}(lambda {}: {}, {})zmpmath.quadr]   r   c              3   h   >#    U  H'  nS [        [        TR                  U5      5      -  v   M)     g7f)z(%s, %s)N)r.  r  ra   )rc   r  re   s     rf   rg   0MpmathPrinter._print_Integral.<locals>.<genexpr>  s&     R6a*uSa-@'AA6s   /2)r(  ro   rp   rq   r  ra   rk   )re   rR   r#  r   s   `   rf   _print_IntegralMpmathPrinter._print_Integral  sr    #:1#= &--##M2		#dkk+;<=AFF1I&		R6RR	T 	Trv   r   Nr  )rn   rd  re  rf  __doc__rg  rh  r   r   rl  rm  _known_functions_mpmathr   _known_constants_mpmathr   r1  r  r  r  r  r=  r@  r  rH  rz  )rc   r|  r}  s   000rf   r*  r*    s      K#H
u (?(E(E(GH(G!Y]	(GH C '>&C&C&E
F&Eda1ik>&E
FCZ
'/$GIMTa 	I
Fs   B(B&r*  c                   J    \ rS rSrSr\" \R                  SS9rS rS	S jr	Sr
g)
SymPyPrinteri  zPython with SymPyFrW  c                    ^  UR                   R                  =(       d    SnT R                  X"(       a  SOS-   UR                   R                  -   5      < SSR	                  U 4S jUR
                   5       5      < S3$ )Nr   r   r   r]   c              3   F   >#    U  H  nTR                  U5      v   M     g 7fr_   r`   rb   s     rf   rg   /SymPyPrinter._print_Function.<locals>.<genexpr>  s     %L)3dkk#&6&6)ri   r   )r  rd  rp   rn   rq   rk   )re   rs   mods   `  rf   _print_FunctionSymPyPrinter._print_Function  s_    ii""(b..sScb/IDIIL^L^/^_99%L$))%LMO 	Orv   c                 "    U R                  XSS9$ )Nz
sympy.sqrtrC  r  r  s      rf   r  SymPyPrinter._print_Pow  s    lKKrv   r   Nr  )rn   rd  re  rf  rh  r   r{   rq  rS  r  rz  r   rv   rf   rN  rN    s*    "H!33
O
Lrv   rN  N)#rJ  collectionsr   	itertoolsr   
sympy.corer   sympy.core.modr   r   codeprinterr	   ri  rl  rn  ro  ru   ry   r{   r  r  r   r|  setattrr  r   _not_in_mpmathrm  
_in_mpmathr   rK  rL  r(  r*  rN  )r|  r}  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 
		A{Q0AB 
 
A{Q0BC 
54 ##%!6!<!<!>Z!>!>BYfqf!>Z
z .   
	 $&AT% ATH 
		AM;?,=> 
 
!AM;?,>? 
!L, Ls [s   FF