
    Xhi                        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,d-Zd.d/d.d0d1d1d2Zd3 Zd4 Z G d5 d6e          Z G d7 d8          Z G d9 d:e          Zej        D ]Z eed;ez  e           eD ]Z eed;ez  e           d< ZddlmZ dd=lmZ dd*d$dd(d+ddddd)d,dddd>Zd/d.d0d?d@Z G dA dBe          Zej        D ]Z eed;ez  ej                   eD ]Z eed;ez  ej                   dC                                ZdD e                                D             Z  e!e fi dEdFdGdHdIdJdKdLdMdNdOdPdQZ"d.d/dRdSdTd1d0dUdVZ#dW Z$ G dX dYe          Z%e%j        D ]Z ee%d;ez  e           e#D ]Z ee%d;ez  e            G dZ d[e          Z&d\S )]zy
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isinfisnanlgammaloglog10log1plog2sinsinhsqrttantanh)rC   rD   rE   loggammarG   lnrH   rI   rJ   rK   rL   SqrtrN   rO   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     g/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/sympy/printing/pycode.py	<genexpr>z$_print_known_func.<locals>.<genexpr>G   s/      2Y2Y4;;s3C3C2Y2Y2Y2Y2Y2Y    )nameargs)known_functions	__class____name__format_module_formatjoinrk   rf   exprknowns   `  rg   _print_known_funcru   D   sk     !89E""(;(;E(B(B(,		2Y2Y2Y2Yty2Y2Y2Y(Z(Z # \ \ \ri   c                 Z    | j         |j        j                 }|                     |          S r`   )known_constantsrm   rn   rp   rr   s      rg   _print_known_constrx   J   s(     !89Eu%%%ri   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. rd   kvs      rg   
<listcomp>z$AbstractPythonCodePrinter.<listcomp>W   s%    DDDda!Wq[	DDDri   c                      i | ]\  }}|d |z   S r~   r   r   s      rg   
<dictcomp>z$AbstractPythonCodePrinter.<dictcomp>Y   s"    
B
B
BDAq1gai
B
B
Bri   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sysro   version_infomajor
ValueErrorr   r   setmodule_importsdict_kfgetrl   _kcrw   )rf   settingsstdr   rm   s       rg   r   z"AbstractPythonCodePrinter.__init__e   s    """ nZ(;JJJ##C$4$:;;C):;;;)#..  $DH  #  #R0D0Db1" 1"  #  ##DH  #  #R0D0Db1" 1"  #  #ri   c                     |d|S Nz = r   )rf   rj   values      rg   _declare_number_constz/AbstractPythonCodePrinter._declare_number_consty   s     DD%%((ri   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   rq   addr   )rf   fqnregisterpartss       rg   rp   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Ari   c                     |S r`   r   )rf   liness     rg   _format_codez&AbstractPythonCodePrinter._format_code   s    ri   c                 ,    d                     |          S )Nz{}ro   rf   
codestrings     rg   _get_statementz(AbstractPythonCodePrinter._get_statement   s    {{:&&&ri   c                 ,    d                     |          S )Nz  # {}r   )rf   texts     rg   _get_commentz&AbstractPythonCodePrinter._get_comment   s    t$$$ri   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   rb   rp   _expand_fold_binary_op)rf   oprk   s      rg   r   z0AbstractPythonCodePrinter._expand_fold_binary_op   s     t99>>;;tAw''' ##B''''++BSbS	::::DH%%%% ri   c           	      .   t          |          dk    r|                     |d                   S t          |          }|dz  }|                     |          d|                     |d|                   d|                     ||d                   dS )z
        This method expands a reduction 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   rb   rp   _expand_reduce_binary_op)rf   r   rk   NNhalfs        rg   r   z2AbstractPythonCodePrinter._expand_reduce_binary_op   s     t99>>;;tAw'''D		AFE##B''''--d6E6l;;;;--d566l;;;; ri   c                     dS )Nzfloat('nan')r   rf   rs   s     rg   
_print_NaNz$AbstractPythonCodePrinter._print_NaN       ~ri   c                     dS )Nzfloat('inf')r   r   s     rg   _print_Infinityz)AbstractPythonCodePrinter._print_Infinity   r   ri   c                     dS )Nzfloat('-inf')r   r   s     rg   _print_NegativeInfinityz1AbstractPythonCodePrinter._print_NegativeInfinity   s    ri   c                 ,    |                      |          S r`   )r   r   s     rg   _print_ComplexInfinityz0AbstractPythonCodePrinter._print_ComplexInfinity   s    t$$$ri   c                 \     t          |           dj         fd|j        D              S )Nz{} % {}c              3   D   K   | ]}                     |          V  d S r`   )parenthesize)rd   xPRECrf   s     rg   rh   z7AbstractPythonCodePrinter._print_Mod.<locals>.<genexpr>   s3      "Q"Q!4#4#4Q#=#="Q"Q"Q"Q"Q"Qri   )r   ro   rk   rf   rs   r   s   ` @rg   
_print_Modz$AbstractPythonCodePrinter._print_Mod   s;    $ 	 "Q"Q"Q"Q"Qty"Q"Q"QRSri   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) )rk   rs   condappendrb   rq   )rf   rs   resultire   rS   cs          rg   _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ri   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_oprb   r   r   ro   r   _print_Relational)rf   rs   r   r   r   rm   s        rg   r   z+AbstractPythonCodePrinter._print_Relational   s     !
 
 ;"++dh''C++dh''C'..$+3C.PPPww((...ri   c                 ^    ddl m} |                     |                    |                    S )Nr   )	Piecewise)$sympy.functions.elementary.piecewiser   rb   rewrite)rf   rs   r   s      rg   
_print_ITEz$AbstractPythonCodePrinter._print_ITE   s2    BBBBBB{{4<<	22333ri   c                       fd|j         d d d         D             }d                                         |j                  d                    |                    S )Nc              3      K   | ]Y\  }}}d                                          |                              |                              |                    V  ZdS )zfor {i} in range({a}, {b}+1))r   abN)ro   rb   )rd   r   r   r   rf   s       rg   rh   z7AbstractPythonCodePrinter._print_Sum.<locals>.<genexpr>   s{       . .
 1a	 +11++a..++a..++a.. 2 " ". . . . . .ri   r   z"(builtins.sum({function} {loops})) )functionloops)limitsro   rb   r   rq   )rf   rs   r   s   `  rg   
_print_Sumz$AbstractPythonCodePrinter._print_Sum   sw    . . . .
  ;ttt,. . . 4::[[//((5// ; # # 	#ri   c                     dS )N1jr   r   s     rg   _print_ImaginaryUnitz.AbstractPythonCodePrinter._print_ImaginaryUnit  s    tri   c                     |j         \  }}d                    |                     |          |                     |                    S )Nz(1 if {a} == {b} else 0))r   r   )rk   ro   rb   )rf   rs   r   r   s       rg   _print_KroneckerDeltaz/AbstractPythonCodePrinter._print_KroneckerDelta  sD    y1)00AA 1 
 
 	
ri   c                     |j         j        }| j                            ||          }|d|                     |                                          dS )Nr   r   )rm   rn   rl   r   rb   tolist)rf   rs   rj   funcs       rg   _print_MatrixBasez+AbstractPythonCodePrinter._print_MatrixBase  sM    ~&#''d3344T[[]]!;!;!;!;<<ri   c                 ,    |                      |          S r`   )r   r   s     rg   <lambda>z"AbstractPythonCodePrinter.<lambda>  s    411$77 ri   c                 l     d                      fd|                    d          D                       S )N
c                 $    g | ]}j         |z   S r   )tab)rd   linerf   s     rg   r   z@AbstractPythonCodePrinter._indent_codestring.<locals>.<listcomp>   s    MMMd$(T/MMMri   )rq   r   r   s   ` rg   _indent_codestringz,AbstractPythonCodePrinter._indent_codestring  s8    yyMMMMj6F6Ft6L6LMMMNNNri   c                     d                      fd|j        D                       }d                                         |j                  d                      fd|j        D                                            |                    S )Nr  c              3   B   K   | ]}                     |          V  d S r`   ra   rc   s     rg   rh   zFAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<genexpr>#  s/      >>s$++c**>>>>>>ri   z def {name}({parameters}):
{body}r^   c                 D    g | ]}                     |j                  S r   )rb   symbol)rd   varrf   s     rg   r   zGAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<listcomp>&  s'    !S!S!Sc$++cj"9"9!S!S!Sri   )rj   
parametersbody)rq   r  ro   rb   rj   r  r  )rf   fdr  s   `  rg   _print_FunctionDefinitionz3AbstractPythonCodePrinter._print_FunctionDefinition"  s    yy>>>>bg>>>??299RW%%yy!S!S!S!SR]!S!S!STT((.. : 
 
 	
ri   c                      d                      fd|j        D                       }d                                         |j                                       |                    S )Nr  c              3   B   K   | ]}                     |          V  d S r`   ra   rc   s     rg   rh   z9AbstractPythonCodePrinter._print_While.<locals>.<genexpr>+  s/      ??s$++c**??????ri   zwhile {cond}:
{body})r   r  )rq   r  ro   rb   	conditionr  )rf   whlr  s   `  rg   _print_Whilez&AbstractPythonCodePrinter._print_While*  sj    yy????ch???@@&--S]++((.. . 
 
 	
ri   c                     |                      |j        j                  d|                      |j        j                  S r   )rb   variabler  r   )rf   decls     rg   _print_Declarationz,AbstractPythonCodePrinter._print_Declaration1  s=    KK,----KK+,,,
 	
ri   c                     dS )Nr   r   )rf   bts     rg   _print_BreakTokenz+AbstractPythonCodePrinter._print_BreakToken7  s    wri   c                 D    |j         \  }d|                     |          z  S )Nz	return %srk   rb   )rf   retre   s      rg   _print_Returnz'AbstractPythonCodePrinter._print_Return:  s"    xT[[----ri   c                 D    |j         \  }d|                     |          z  S )Nzraise %sr  )rf   rsre   s      rg   _print_Raisez&AbstractPythonCodePrinter._print_Raise>  s"    wDKK,,,,ri   c                 D    |j         \  }d|                     |          z  S )NzRuntimeError(%s)r  )rf   remessages      rg   _print_RuntimeError_z.AbstractPythonCodePrinter._print_RuntimeError_B  s"    7!DKK$8$888ri   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`   ra   rc   s     rg   rh   z9AbstractPythonCodePrinter._print_Print.<locals>.<genexpr>G  s/      LLSC 0 0LLLLLLri   r   )nonez{} % ({}), end=""z	, file=%sz	print(%s))rq   
print_argssympy.codegen.astr*  format_stringro   rb   file)rf   prntr+  r*  s   `   rg   _print_Printz&AbstractPythonCodePrinter._print_PrintF  s    YYLLLLDOLLLMM
******%%,33D.// J 9+DI(>(>>>JZ''ri   c                     t          |j                  dk    r|                     d          S t          |j                  dk    r|                     d          S |                     |j                  S )Nstdoutz
sys.stdoutstderrz
sys.stderr)strrj   rp   rb   )rf   strms     rg   _print_Streamz'AbstractPythonCodePrinter._print_StreamR  sd    ty>>X%%&&|444^^x''&&|444;;ty)))ri   c                     dS )Nr   r   )rf   re   s     rg   _print_NoneTokenz*AbstractPythonCodePrinter._print_NoneTokenZ  s    vri   	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   re   /r   r   Fstrictz{}**{})r   r>   r   Halfrp   rb   basero   is_commutativeOneNegativeOner   )
rf   rs   rationalrM   r   r   re   numbase_strexp_strs
             rg   _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1ri   r`   )T)Fr9  )=rn   
__module____qualname__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  r  r   r#  r'  r0  r6  r8  rG  __classcell__rm   s   @rg   rz   rz   O   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 @2ri   rz   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_arrayrb  	Exception)rf   indexedrb  s      rg   	_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,   )rd   r   js      rg   r   z3ArrayPrinter._get_einsum_string.<locals>.<dictcomp>  s-    ???1Q??QA????ri   r   ,r   ) _get_letter_generator_for_einsumranger   next)rf   subrankscontraction_indicesletterscontraction_stringcounterdindicesrank_arglindicesr   mappingletters_freeletters_dumri  ls                   rg   _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!<<<ri   c              #      K   t          dd          D ]}t          |          V  t          dd          D ]}t          |          V  t          d          )Na   {   A   [   zout of letters)rl  chrr   )rf   r   s     rg   rk  z-ArrayPrinter._get_letter_generator_for_einsum  se      r3 	 	Aa&&LLLLr2 	 	Aa&&LLLL)***ri   c                                                       d                    fd|j        D                       }                      j        dz    j        z             d|dd                     fd|j        D                       dS )	Nrj  c                 l    g | ]0}d                      fdt          |          D                       1S )r   c                 .    g | ]}t                    S r   )rm  )rd   ri  rp  s     rg   r   zEArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>.<listcomp>  s    /P/P/P!W/P/P/Pri   )rq   rl  )rd   r   rp  s     rg   r   z:ArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>  sA    &i&i&iVWrww/P/P/P/PuQxx/P/P/P'Q'Q&i&i&iri   r   ("", r^   c                 :    g | ]}                     |          S r   ra   rc   s     rg   r   z:ArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>  s%    AAA4;;s++AAAri   r   )rk  rq   rn  rp   _module_einsumrk   )rf   rs   rq  rp  s   `  @rg   _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
 	
ri   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   ArrayTensorProductrj  c                 @    g | ]}d                      |          z  S z%sra   rc   s     rg   r   z8ArrayPrinter._print_ArrayContraction.<locals>.<listcomp>  *    MMMCddkk#&6&67MMMri   c                 @    g | ]}d                      |          z  S r  ra   rc   s     rg   r   z8ArrayPrinter._print_ArrayContraction.<locals>.<listcomp>  r  ri   r   r  {}->{}r   r  r   )0sympy.tensor.array.expressions.array_expressionsr  rs   ro  
isinstancerq   rk   rn  rb   r   shaper{  rp   r  r  ro   sorted)
rf   rs   r  r?  ro  elemsranksrq  rx  ry  s
   `         rg   _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
 	
ri   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   ra   )rd   r   rf   s     rg   r   z5ArrayPrinter._print_ArrayDiagonal.<locals>.<listcomp>   s#    ///AQ///ri   r   r  r  r   r  r^   r   )r  r  listdiagonal_indicesr  rs   rn  rk   r{  rp   r  r  ro   rq   )	rf   rs   r  r  rn  r  diagonal_stringrx  ry  s	   `        rg   _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
 	
ri   c                     |                      | j        dz   | j        z             d|                     |j                  d|                     |j        j                  dS )Nr   r   r^   r   )rp   r  
_transposerb   rs   permutation
array_formr   s     rg   _print_PermuteDimszArrayPrinter._print_PermuteDims  sc    s 2T_ DEEEEKK	""""KK(34444
 	
ri   c                 X    |                      | j        dz   | j        z   |j                  S )Nr   )r   r  _addrk   r   s     rg   _print_ArrayAddzArrayPrinter._print_ArrayAdd  s(    **4<#+=	+I49UUUri   c                     |                      | j        dz   | j        z             dd                    t	          | j        |j                            dS Nr   z((rj  z,)))rp   r  _onesrq   maprb   rk   r   s     rg   _print_OneArrayzArrayPrinter._print_OneArray  sT    c 1DJ >????HHSTY//0000
 	
ri   c                     |                      | j        dz   | j        z             dd                    t	          | j        |j                            dS r  )rp   r  _zerosrq   r  rb   rk   r   s     rg   _print_ZeroArrayzArrayPrinter._print_ZeroArray  sT    c 1DK ?@@@@HHSTY//0000
 	
ri   c                     |                      |                     |j                            }|                      |                     |j                            }|d|S r   )rb   rf  r   r   )rf   rs   r   r   s       rg   _print_AssignmentzArrayPrinter._print_Assignment  sS     kk$..2233kk$..2233 SS##''ri   c                 ,    |                      |          S r`   )_print_ArraySymbolr   s     rg   _print_IndexedBasezArrayPrinter._print_IndexedBase$  s    &&t,,,ri   N)rn   rH  rI  rf  r{  rk  r  r  r  r  r  r  r  r  r  r   ri   rg   r`  r`    s          != != !=F+ + +
 
 

 
 
4
 
 
"
 
 
V V V
 
 

 
 
( ( (- - - - -ri   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   )frS   ro   rp   rb   rk   rf   rS   s     rg   _print_signzPythonCodePrinter._print_sign*  sG    3::!!/22dkk!&)6L6L ; N N 	Nri   c                     t          |          }| j        d         dz   |                     |j        d         |          z   S )Nr   r   r   )r   rS  r   rk   r   s      rg   
_print_NotzPythonCodePrinter._print_Not.  s<    $u%+d.?.?	!d.S.SSSri   c                     |j         S r`   )rj   r   s     rg   r  z$PythonCodePrinter._print_IndexedBase2  s
    yri   c                      |j         d         }|j         dd          }d                    t          |          d                     fd|D                                 S )Nr   r   z{}[{}]r^   c                 :    g | ]}                     |          S r   ra   )rd   indrf   s     rg   r   z4PythonCodePrinter._print_Indexed.<locals>.<listcomp>8  s%    4W4W4W#T[[5E5E4W4W4Wri   )rk   ro   r4  rq   )rf   rs   r?  indexs   `   rg   _print_Indexedz PythonCodePrinter._print_Indexed5  sY    y|	!""s4yy$))4W4W4W4WQV4W4W4W*X*XYYYri   Fc                 0    |                      ||          S )N)rC  rG  rf   rs   rC  s      rg   
_print_PowzPythonCodePrinter._print_Pow:  s    x888ri   c                 B    d                     |j        |j                  S )Nz{}/{})ro   pqr   s     rg   _print_Rationalz!PythonCodePrinter._print_Rational=  s    ~~dfdf---ri   c                 ,    |                      |          S r`   r  r   s     rg   _print_HalfzPythonCodePrinter._print_Half@  s    ##D)))ri   c                 ^    |                      t          |j        d         d                    S )Nr   r   )r   r   rk   r   s     rg   _print_fraczPythonCodePrinter._print_fracC  s$    s49Q<33444ri   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_SymbolrM  r   r   ro   replace)rf   rs   rj   msgrm   s       rg   r  zPythonCodePrinter._print_SymbolF  s    ww$$T**4&&&~12 3< D!1!1222$.)?@@@D[[<<R((00b999Kri   F)rn   rH  rI  r  r  r  r  r  r  r  r  r  r	   _print_not_supported_print_lowergamma_print_uppergamma_print_fresnelc_print_fresnelsr]  r^  s   @rg   r  r  (  s        N N NT T T  Z Z Z
9 9 9 9. . .* * *5 5 5     $8#8!6O!6OOOOOri   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)rs   r   s     rg   pycoder  b  s     . X&&..t444ri   )r  )r>   rM   rG   r:   rK   rN   r1   r3   r5   r;   rL   rO   r2   r4   r7   z-inf)rX   rY   rZ   NegativeInfinityc                        e Zd ZdZdZdZ e ee	                                                    Z
d e	                                D             ZddZd Z fdZd	 Zd
 Zd Z xZS )CmathPrinterz# Printer for Python's cmath module 
_cmathcodezPython with cmathc                      i | ]\  }}|d |z   S )cmath.r   r   s      rg   r   zCmathPrinter.<dictcomp>  s"    
F
F
Ftq!1hl
F
F
Fri   Fc                 2    |                      ||d          S )Nz
cmath.sqrtrC  rM   r  r  s      rg   r  zCmathPrinter._print_Pow      xlKKKri   c                 |    d                     |                     d          |                     |                    S )Nz{func}({val})z	cmath.mpf)r   valro   rp   rb   r  s     rg   _print_FloatzCmathPrinter._print_Float  s9    %%4+>+>{+K+KQUQ\Q\]^Q_Q_%```ri   c           	          |j         j        }|| j        v r?d| j        |          dd                    t	          | j        |j                             dS t                                          |          S )Nr  r   r^   r   )	r   rn   r   rq   r  rb   rk   r   _print_Function)rf   rs   	func_namerm   s      rg   ru   zCmathPrinter._print_known_func  sl    I&	  [DHY/[[$))CTY<W<W2X2X[[[[ww&&t,,,ri   c                 0    | j         |j        j                 S r`   )r   rm   rn   r   s     rg   rx   zCmathPrinter._print_known_const  s    x/00ri   c                 J    d|                      |j        d                    dS )zPrints `re(z)` as `z.real`r   r   z).realrb   rk   r   s     rg   	_print_rezCmathPrinter._print_re  %    44;;ty|,,4444ri   c                 J    d|                      |j        d                    dS )zPrints `im(z)` as `z.imag`r   r   z).imagr  r   s     rg   	_print_imzCmathPrinter._print_im  r  ri   r  )rn   rH  rI  __doc__rJ  rK  r   r   _known_functions_cmathrP  r   _known_constants_cmathr   r  r  ru   rx   r  r  r]  r^  s   @rg   r  r    s        --K"H
$uu$$&&   C G
F'='C'C'E'E
F
F
FCL L L La a a- - - - -1 1 15 5 55 5 5 5 5 5 5ri   r  z
log1p log2c                 .    g | ]\  }}|t           v||fS r   )_not_in_mpmathr   s      rg   r   r     s*    ZZZA!>BYBYq!fBYBYBYri   betafracfresnelcfresnelssignrP   hypermeijergbesseljbesselybesselibesselk)r  r  r   r  r  rP   r  r  r  r  r  r  phieulercatalanninf)rW   rX   GoldenRatio
EulerGammaCatalanr[   rZ   r  c                     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          rg   _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##ri   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 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      rg   r   zMpmathPrinter.<listcomp>  s%    HHH1!Y]	HHHri   c                      i | ]\  }}|d |z   S r  r   r   s      rg   r   zMpmathPrinter.<dictcomp>  s"    
F
F
Fda1ik
F
F
Fri   c                     t          t          t          t          |j                                      }d                    |                     d          |          S )Nz{func}({args})
mpmath.mpf)r   rk   )r4  tupler  int_mpf_ro   rp   )rf   rS   rk   s      rg   r  zMpmathPrinter._print_Float  sM     5S!'**++,,&&D,?,?,M,MTX&YYYri   c                     d                     |                     d          |                     |j                  |                     |j                            S )Nz{func}({p})/{func}({q})r!  )r   r  r  )ro   rp   rb   r  r  r  s     rg   r  zMpmathPrinter._print_Rational	  sR    (//$$\22kk!#kk!# 0 
 
 	
ri   c                 ,    |                      |          S r`   r  r  s     rg   r  zMpmathPrinter._print_Half  s    ##A&&&ri   c                     d                     |                     d          |                     |j        d                   |                     |j        d                   |                     d                    S )Nz{}({}, {}, {})mpmath.gammaincr   r   z
mpmath.infr  r  s     rg   r  zMpmathPrinter._print_uppergamma  sg    && 122KKq	""KKq	""--	/ / 	/ri   c                     d                     |                     d          |                     |j        d                   |                     |j        d                             S )Nz{}({}, 0, {})r(  r   r   r  r  s     rg   r  zMpmathPrinter._print_lowergamma  sV    %% 122KKq	""KKq	""$ $ 	$ri   c                     d                     |                     d          |                     |j        d                             S )Nz{0}({1})/{0}(2)z
mpmath.logr   r  r  s     rg   _print_log2zMpmathPrinter._print_log2   sB     ''--t{{16!9/E/EG G 	Gri   c                     d                     |                     d          |                     |j        d                             S )Nz{}({})zmpmath.log1pr   r  r  s     rg   _print_log1pzMpmathPrinter._print_log1p$  s@    //QVAY1G1GI I 	Iri   Fc                 2    |                      ||d          S )Nzmpmath.sqrtr  r  r  s      rg   r  zMpmathPrinter._print_Pow(  s    xmLLLri   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  rb   )rd   rz  rf   s     rg   rh   z0MpmathPrinter._print_Integral.<locals>.<genexpr>2  s<      RRa*uSa-@-@'A'AARRRRRRri   )r  ro   rp   rq   r  rb   rk   )rf   rS   r  r   s   `   rg   _print_IntegralzMpmathPrinter._print_Integral+  s    #:1#=#= &&--##M22		#dk+;<<==AF1I&&		RRRR6RRRRR	T T 	Tri   c                     |\  }|\  }d                     |                     d          |                     |          |          S )Nz{}({}, derivative={})zmpmath.zetar  )rf   rk   
seq_ordersre   deriv_orders        rg   _print_Derivative_zetaz$MpmathPrinter._print_Derivative_zeta5  sJ    !&--..KKk
 
 	
ri   Nr  )rn   rH  rI  r  rJ  rK  r   r   rO  rP  _known_functions_mpmathr   _known_constants_mpmathr   r  r  r  r  r  r+  r-  r  r1  r5  r   ri   rg   r  r    sD          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
 
 
 
 
ri   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`   ra   rc   s     rg   rh   z/SymPyPrinter._print_Function.<locals>.<genexpr>Q  s/      %L%L3dkk#&6&6%L%L%L%L%L%Lri   r   )r   rH  rp   rn   rq   rk   )rf   rs   mods   `  rg   r  zSymPyPrinter._print_FunctionN  sy    i"(b..sS6Hccb/IDIL^/^____99%L%L%L%L$)%L%L%LMMMMO 	Ori   c                 2    |                      ||d          S )Nz
sympy.sqrtr  r  r  s      rg   r  zSymPyPrinter._print_PowS  r  ri   Nr  )	rn   rH  rI  rK  r   rz   rT  r  r  r   ri   rg   r9  r9  E  se        "H!3  
O O O
L L L L L Lri   r9  N)'r  collectionsr   	itertoolsr   
sympy.corer   sympy.core.modr   r   codeprinterr	   rL  rO  rQ  rR  ru   rx   rz   r`  r  r   r   setattrr  sympy.printing.pycoder  r  r  r   r  rP  
_in_mpmathr   r6  r7  r  r  r9  r   ri   rg   <module>rF     s   
 $ # # # # #                   " " " " " " $ $ $ $ $ $     
 
F W  F  W	 
 F  W  W  v  
5  F  
5  F  
5  W     W! " W# $ 
?      F 
	  \ \ \& & &
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       3 3 3 3 3 3   & 		   5  5  5  5  5$  5  5  5F 
	 K KAGL+/<+IJJJJ	 L LAGL+/<+JKKKK ##%%ZZ!6!<!<!>!>ZZZ
$z  . .    
	 	 $ $ $&J
 J
 J
 J
 J
% J
 J
 J
Z 
	 ? ?AGM;?,=>>>>	  @ @AGM;?,>????L L L L L, L L L L Lri   