o
    *ήc _                     @   s4  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+Zd,d-d,d.d/d/d0Zd1d2 Zd3d4 ZG d5d6 d6eZG d7d8 d8ZG d9d: d:eZejD ]
Zeed;e e qeD ]
Zeed;e e qd<d= Zd> Zd?d@ e D Zeefi dAdBdCdDdEdFdGdHdIdJdKdLdMZd,d-dNdOdPd/d.dQdRZdSdT Z G dUdV dVeZ!e!jD ]
Zee!d;e e qeD ]Zee!d;e e qG dWdX dXeZ"dYS )Zzy
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lgammaloglog10log1plog2sinsinhsqrttantanh)rB   loggammarD   lnrE   rF   rG   rH   rI   SqrtrK   rL   epiinfnan)Exp1PiEInfinityNaNComplexInfinityc                    s8    j |jj }dj |dt fdd|jdS )Nz{name}({args}), c                    
     | S N_printargself </tmp/pip-target-vg8gfxp4/lib/python/sympy/printing/pycode.py<lambda>E      
 z#_print_known_func.<locals>.<lambda>)nameargs)known_functions	__class____name__format_module_formatjoinmaprh   rb   exprknownrc   ra   rd   _print_known_funcB   s   rs   c                 C   s   | j |jj }| |S r\   )known_constantsrj   rk   rm   rp   rc   rc   rd   _print_known_constH   s   
ru   c                	       s  e Zd ZdZdZeZdZdZe	e
e dd e D Zdd e D Zd	d
ddZe	eji ddddddZdO fdd	Zdd ZdPddZdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Z d,d- Z! fd.d/Z"d0d1 Z#d2d3 Z$d4d5 Z%d6d7 Z&d8d9 Z'd:d;  Z( Z) Z* Z+ Z, Z- Z.Z/d<d= Z0d>d? Z1d@dA Z2dBdC Z3dDdE Z4dFdG Z5dHdI Z6dJdK Z7dQdMdNZ8  Z9S )RAbstractPythonCodePrinter_pythoncodePythonNz    c                 C      g | ]
\}}|d | fqS zmath.rc   .0kvrc   rc   rd   
<listcomp>U       z$AbstractPythonCodePrinter.<listcomp>c                 C      i | ]	\}}|d | qS rz   rc   r{   rc   rc   rd   
<dictcomp>W       z$AbstractPythonCodePrinter.<dictcomp>r   r   r   )r   r   r      TFpython3)user_functions	precisioninlinefully_qualified_modulescontractstandardc                    s   t  | | jd }|d u rdd l}d|jj}|dkr"td|| _t	t
| _t| jfi |p2i di | _t| jfi |pBi di | _d S )Nr   r   zpython{}r   zOnly Python 3 is supported.r   user_constants)super__init__	_settingssysrl   version_infomajor
ValueErrorr   r   setmodule_importsdict_kfgetri   _kcrt   )rb   settingsstdr   rj   rc   rd   r   c   s   


z"AbstractPythonCodePrinter.__init__c                 C   s   d||f S Nz%s = %src   )rb   rg   valuerc   rc   rd   _declare_number_constw   s   z/AbstractPythonCodePrinter._declare_number_constc                 C   sl   | d}|rt|dkr| jd|d d  |d  | jd r%|S | dd  dd  dd S )N.r   r   (r   [)splitlenr   rn   addr   )rb   fqnregisterpartsrc   rc   rd   rm   z   s   
"
"z(AbstractPythonCodePrinter._module_formatc                 C   s   |S r\   rc   )rb   linesrc   rc   rd   _format_code      z&AbstractPythonCodePrinter._format_codec                 C   
   d |S )Nz{}rl   rb   
codestringrc   rc   rd   _get_statement      
z(AbstractPythonCodePrinter._get_statementc                 C   r   )Nz  # {}r   )rb   textrc   rc   rd   _get_comment   r   z&AbstractPythonCodePrinter._get_commentc                 C   sH   t |dkr| |d S d| || ||dd | |d f 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   
%s(%s, %s)Nr   )r   r^   rm   _expand_fold_binary_op)rb   oprh   rc   rc   rd   r      s   z0AbstractPythonCodePrinter._expand_fold_binary_opc                 C   sZ   t |dkr| |d S t |}|d }d| || |d| | ||d f 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   N)r   r^   rm   _expand_reduce_binary_op)rb   r   rh   NNhalfrc   rc   rd   r      s   z2AbstractPythonCodePrinter._expand_reduce_binary_opc                 C      dS )Nzfloat('nan')rc   rb   rq   rc   rc   rd   
_print_NaN   r   z$AbstractPythonCodePrinter._print_NaNc                 C   r   )Nzfloat('inf')rc   r   rc   rc   rd   _print_Infinity   r   z)AbstractPythonCodePrinter._print_Infinityc                 C   r   )Nzfloat('-inf')rc   r   rc   rc   rd   _print_NegativeInfinity   r   z1AbstractPythonCodePrinter._print_NegativeInfinityc                 C   
   |  |S r\   )r   r   rc   rc   rd   _print_ComplexInfinity   r   z0AbstractPythonCodePrinter._print_ComplexInfinityc                    s$   t | djt fdd|j S )Nz{} % {}c                    s    |  S r\   )parenthesize)xPRECrb   rc   rd   re      s    z6AbstractPythonCodePrinter._print_Mod.<locals>.<lambda>)r   rl   ro   rh   r   rc   r   rd   
_print_Mod      z$AbstractPythonCodePrinter._print_Modc                 C   s   g }d}|j D ]9}|j}|j}|dkr|d |d || | |d |d || | |d |d7 }q|d d }|d dkrY|d d	 }|d n|d
 d|S )Nr   r   )z if z else r   r   r   z else None) )rh   rq   condappendr^   rn   )rb   rq   resultir`   rP   crc   rc   rd   _print_Piecewise   s(   








z*AbstractPythonCodePrinter._print_Piecewisec                    sR   ddddddd}|j |v r#| |j}| |j}dj|j ||d	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_opr^   r   r   rl   r   _print_Relational)rb   rq   r   r   r   r   rc   rd   r      s   
z+AbstractPythonCodePrinter._print_Relationalc                 C   s   ddl m} | ||S )Nr   )	Piecewise)$sympy.functions.elementary.piecewiser   r^   rewrite)rb   rq   r   rc   rc   rd   
_print_ITE   s   z$AbstractPythonCodePrinter._print_ITEc                    s0    fdd|j D }dj |jd|dS )Nc                 3   s8    | ]\}}}d j  | | |dV  qdS )zfor {i} in range({a}, {b}+1))r   abN)rl   r^   )r|   r   r   r   ra   rc   rd   	<genexpr>   s    
z7AbstractPythonCodePrinter._print_Sum.<locals>.<genexpr>z"(builtins.sum({function} {loops})) )functionloops)limitsrl   r^   r   rn   )rb   rq   r   rc   ra   rd   
_print_Sum   s   

z$AbstractPythonCodePrinter._print_Sumc                 C   r   )N1jrc   r   rc   rc   rd   _print_ImaginaryUnit  r   z.AbstractPythonCodePrinter._print_ImaginaryUnitc                 C   s$   |j \}}dj| || |dS )Nz(1 if {a} == {b} else 0))r   r   )rh   rl   r^   )rb   rq   r   r   rc   rc   rd   _print_KroneckerDelta  s
   
z/AbstractPythonCodePrinter._print_KroneckerDeltac                 C   s,   |j j}| j||}d|| | f S )N%s(%s))rj   rk   ri   r   r^   tolist)rb   rq   rg   funcrc   rc   rd   _print_MatrixBase  s   z+AbstractPythonCodePrinter._print_MatrixBasec                 C   r   r\   )r   r   rc   rc   rd   re     rf   z"AbstractPythonCodePrinter.<lambda>c                    s   d  fdd|dD S )N
c                    s   g | ]} j | qS rc   )tab)r|   linera   rc   rd   r         z@AbstractPythonCodePrinter._indent_codestring.<locals>.<listcomp>)rn   r   r   rc   ra   rd   _indent_codestring  s   z,AbstractPythonCodePrinter._indent_codestringc                    sN   d t fdd|j}dj |jd  fdd|jD  |dS )	Nr   c                    r[   r\   r]   r_   ra   rc   rd   re   !  rf   zEAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<lambda>z def {name}({parameters}):
{body}rZ   c                    s   g | ]}  |jqS rc   )r^   symbol)r|   varra   rc   rd   r   $  s    zGAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<listcomp>)rg   
parametersbody)rn   ro   r   rl   r^   rg   r   r   )rb   fdr   rc   ra   rd   _print_FunctionDefinition   s   
z3AbstractPythonCodePrinter._print_FunctionDefinitionc                    s6   d t fdd|j}dj |j |dS )Nr   c                    r[   r\   r]   r_   ra   rc   rd   re   )  rf   z8AbstractPythonCodePrinter._print_While.<locals>.<lambda>zwhile {cond}:
{body})r   r   )rn   ro   r   rl   r^   	conditionr   )rb   whlr   rc   ra   rd   _print_While(  s
   
z&AbstractPythonCodePrinter._print_Whilec                 C   s    d|  |jj|  |jjf S r   )r^   variabler   r   )rb   declrc   rc   rd   _print_Declaration/  s   z,AbstractPythonCodePrinter._print_Declarationc                 C   s   |j \}d| | S )Nz	return %s)rh   r^   )rb   retr`   rc   rc   rd   _print_Return5  s   z'AbstractPythonCodePrinter._print_Returnc                    s^   d t fdd|j}|jd krd |j|}|jd kr+|d |j 7 }d| S )NrZ   c                    r[   r\   r]   r_   ra   rc   rd   re   :  rf   z8AbstractPythonCodePrinter._print_Print.<locals>.<lambda>z	{} % ({})z	, file=%sz	print(%s))rn   ro   
print_argsformat_stringrl   r^   file)rb   prntr  rc   ra   rd   _print_Print9  s   

z&AbstractPythonCodePrinter._print_Printc                 C   s<   t |jdkr| dS t |jdkr| dS | |jS )Nstdoutz
sys.stdoutstderrz
sys.stderr)strrg   rm   r^   )rb   strmrc   rc   rd   _print_StreamC  s
   

z'AbstractPythonCodePrinter._print_Streamc                 C   r   )Nr   rc   )rb   r`   rc   rc   rd   _print_NoneTokenK  r   z*AbstractPythonCodePrinter._print_NoneToken	math.sqrtc           
      C   s   t |}|jtjkr|s| |}| |j}dj||dS |jrb|sb|j tju rF| |}| tj	}| |j}| d| d| dS |jtj
u rb| tj	}| j|j|dd}| d| S | j|j|dd}| j|j|d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   r`   /r   r   F)strictz{}**{})r   r=   r   Halfrm   r^   baserl   is_commutativeOneNegativeOner   )
rb   rq   rationalrJ   r   r   r`   numbase_strexp_strrc   rc   rd   _hprint_PowN  s$   +


z%AbstractPythonCodePrinter._hprint_Powr\   )T)Fr  ):rk   
__module____qualname__printmethodlanguage_kwreserved_wordsmodulesr   r   r   _known_functionsitems_known_functions_mathr   _known_constants_mathr   
_operatorsr   _default_settingsr   r   rm   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  __classcell__rc   rc   r   rd   rv   M   s    



rv   c                   @   sl   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )ArrayPrinterc                 C   s.   ddl m} z||W S  ty   | Y S w )Nr   )convert_indexed_to_array)4sympy.tensor.array.expressions.conv_indexed_to_arrayr3  	Exception)rb   indexedr3  rc   rc   rd   	_arrayify  s   
zArrayPrinter._arrayifyc                 C   s   |   }d}d}dd |D }g }|D ]%}g }	t|D ]}
||v r)|	||  n|	| |d7 }q||	 qi }g }g }|D ]3}
|
D ]*}||vrTt|}|||< n|| }||7 }||v rj||vri|| qE|| qE|d7 }qA|d d }|||fS )Nr   r   c                 S   s    i | ]}|D ]}|t |qqS rc   )r+   )r|   r   jrc   rc   rd   r          z3ArrayPrinter._get_einsum_string.<locals>.<dictcomp>r   ,r   ) _get_letter_generator_for_einsumranger   next)rb   subrankscontraction_indicesletterscontraction_stringcounterdindicesrank_arglindicesr   mappingletters_freeletters_dumr8  lrc   rc   rd   _get_einsum_string  s>   





zArrayPrinter._get_einsum_stringc                 c   s>    t ddD ]}t|V  qt ddD ]}t|V  qtd)Na   {   A   [   zout of letters)r<  chrr   )rb   r   rc   rc   rd   r;    s   z-ArrayPrinter._get_letter_generator_for_einsumc                    sX      d fdd|jD }djd j |dfdd|jD f S )Nr:  c                    s(   g | ]}d   fddt|D qS )r   c                    s   g | ]}t  qS rc   )r=  )r|   r8  r@  rc   rd   r     s    zEArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>.<listcomp>)rn   r<  r|   r   rQ  rc   rd   r     s   ( z:ArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>%s("%s", %s)r   rZ   c                       g | ]}  |qS rc   r]   r|   r`   ra   rc   rd   r     r   )r;  rn   r>  rm   _module_einsumrh   )rb   rq   rA  rc   )r@  rb   rd   _print_ArrayTensorProduct  s   z&ArrayPrinter._print_ArrayTensorProductc           
   	      s   ddl m} |j}|j}t||r"d fdd|jD }|j}n |}t	|j
g} ||\}}}	|s= |S t||rPd fdd|jD }n |}d  jd  j d	|d
t||f S )Nr   ArrayTensorProductr:  c                       g | ]	}d   | qS z%sr]   rU  ra   rc   rd   r     r   z8ArrayPrinter._print_ArrayContraction.<locals>.<listcomp>c                    r[  r\  r]   rU  ra   rc   rd   r     r   rS  r   {}->{}r   )0sympy.tensor.array.expressions.array_expressionsrZ  rq   r?  
isinstancern   rh   r>  r^   r   shaperK  rm   rV  rW  rl   sorted)
rb   rq   rZ  r  r?  elemsranksrA  rH  rI  rc   ra   rd   _print_ArrayContraction  s&   




z$ArrayPrinter._print_ArrayContractionc           	   	      s   ddl m} t|j}t|j|r|jj}|jj}n|j}|jg} ||\}}} fdd|D }d 	 j
d  j d|d|| d	|f S )
Nr   rY  c                    rT  rc   r]   rR  ra   rc   rd   r     r   z5ArrayPrinter._print_ArrayDiagonal.<locals>.<listcomp>rS  r   r]  r   rZ   )r^  rZ  listdiagonal_indicesr_  rq   r>  rh   rK  rm   rV  rW  rl   rn   )	rb   rq   rZ  rf  r>  rb  diagonal_stringrH  rI  rc   ra   rd   _print_ArrayDiagonal  s   

z!ArrayPrinter._print_ArrayDiagonalc                 C   s2   d|  | jd | j | |j| |jjf S )Nr   r   )rm   rV  
_transposer^   rq   permutation
array_formr   rc   rc   rd   _print_PermuteDims  s
   
zArrayPrinter._print_PermuteDimsc                 C   s   |  | jd | j |jS )Nr   )r   rV  _addrh   r   rc   rc   rd   _print_ArrayAdd  s   zArrayPrinter._print_ArrayAddc                 C   .   d|  | jd | j dt| j|jf S Nz	%s((%s,))r   r:  )rm   rV  _onesrn   ro   r^   rh   r   rc   rc   rd   _print_OneArray     zArrayPrinter._print_OneArrayc                 C   ro  rp  )rm   rV  _zerosrn   ro   r^   rh   r   rc   rc   rd   _print_ZeroArray  rs  zArrayPrinter._print_ZeroArrayc                 C   s0   |  | |j}|  | |j}d||f S r   )r^   r7  r   r   )rb   rq   r   r   rc   rc   rd   _print_Assignment  s   zArrayPrinter._print_Assignmentc                 C   r   r\   )_print_ArraySymbolr   rc   rc   rd   _print_IndexedBase  r   zArrayPrinter._print_IndexedBaseN)rk   r  r  r7  rK  r;  rX  rd  rh  rl  rn  rr  ru  rv  rx  rc   rc   rc   rd   r2    s    #	r2  c                       sn   e Zd Zdd Zdd Zdd Zddd	Zd
d Zdd Zdd Z	 fddZ
ejZejZejZejZ  ZS )PythonCodePrinterc                 C   s    dj | d| |jd dS )Nz"(0.0 if {e} == 0 else {f}(1, {e}))zmath.copysignr   )frP   rl   rm   r^   rh   rb   rP   rc   rc   rd   _print_sign  s   zPythonCodePrinter._print_signc                 C   s$   t |}| jd | |jd | S )Nr   r   )r   r'  r   rh   )rb   rq   r   rc   rc   rd   
_print_Not  r   zPythonCodePrinter._print_Notc                    s<   |j d }|j dd  }dt|d fdd|D S )Nr   r   z{}[{}]rZ   c                    rT  rc   r]   )r|   indra   rc   rd   r   &  r   z4PythonCodePrinter._print_Indexed.<locals>.<listcomp>)rh   rl   r  rn   )rb   rq   r  indexrc   ra   rd   _print_Indexed#  s   
$z PythonCodePrinter._print_IndexedFc                 C   s   | j ||dS )N)r  r  rb   rq   r  rc   rc   rd   
_print_Pow(  s   zPythonCodePrinter._print_Powc                 C   s   d |j|jS )Nz{}/{})rl   pqr   rc   rc   rd   _print_Rational+     z!PythonCodePrinter._print_Rationalc                 C   r   r\   r  r   rc   rc   rd   _print_Half.  r   zPythonCodePrinter._print_Halfc                 C   s   |  t|jd dS )Nr   r   )r   r   rh   r   rc   rc   rd   _print_frac1  s   zPythonCodePrinter._print_fracc                    s`   t  |}|| jv r | jd rd}t|||| jd  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_Symbolr!  r   r   rl   replace)rb   rq   rg   msgr   rc   rd   r  4  s   

zPythonCodePrinter._print_SymbolF)rk   r  r  r}  r~  r  r  r  r  r  r  r   _print_not_supported_print_lowergamma_print_uppergamma_print_fresnelc_print_fresnelsr1  rc   rc   r   rd   ry    s    
ry  z	_print_%sc                 K   s   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'

    )ry  doprint)rq   r   rc   rc   rd   pycodeP  s   r  z
log1p log2c                 C   s    g | ]\}}|t vr||fqS rc   )_not_in_mpmathr{   rc   rc   rd   r   k  r9  r   betafracfresnelcfresnelssignrM   hypermeijergbesseljbesselybesselibesselk)r  r  r  r  r  rM   r  r  r  r  r  r  phieulercatalanninf)rT   rU   GoldenRatio
EulerGammaCatalanrX   rW   NegativeInfinityc                 C   sT   g }g }| j D ]}t|dkr|\}}}ntd|| |||f q||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_limitrc   rc   rd   _unpack_integral_limits  s   

r  c                   @   s   e Zd ZdZdZdZeee	 dd e
	 D Zdd e	 D Zdd	 Zd
d Zdd Zdd Zdd Zdd Zdd ZdddZdd ZdS )MpmathPrinterzH
    Lambda printer for mpmath which maintains precision for floats
    _mpmathcodezPython with mpmathc                 C   ry   zmpmath.rc   r{   rc   rc   rd   r     r   zMpmathPrinter.<listcomp>c                 C   r   r  rc   r{   rc   rc   rd   r     r   zMpmathPrinter.<dictcomp>c                 C   s(   t ttt|j}dj| d|dS )Nz{func}({args})
mpmath.mpf)r   rh   )r  tuplero   int_mpf_rl   rm   )rb   rP   rh   rc   rc   rd   _print_Float  s   zMpmathPrinter._print_Floatc                 C   s&   dj | d| |j| |jdS )Nz{func}({p})/{func}({q})r  )r   r  r  )rl   rm   r^   r  r  r|  rc   rc   rd   r    s
   

zMpmathPrinter._print_Rationalc                 C   r   r\   r  r|  rc   rc   rd   r    r   zMpmathPrinter._print_Halfc                 C   s4   d | d| |jd | |jd | dS )Nz{}({}, {}, {})mpmath.gammaincr   r   z
mpmath.infr{  r|  rc   rc   rd   r    s   zMpmathPrinter._print_uppergammac                 C   s,   d | d| |jd | |jd S )Nz{}({}, 0, {})r  r   r   r{  r|  rc   rc   rd   r    s
   zMpmathPrinter._print_lowergammac                 C      d | d| |jd S )Nz{0}({1})/{0}(2)
mpmath.logr   r{  r|  rc   rc   rd   _print_log2     zMpmathPrinter._print_log2c                 C   r  )Nz{}({}+1)r  r   r{  r|  rc   rc   rd   _print_log1p  r  zMpmathPrinter._print_log1pFc                 C      | j ||ddS )Nzmpmath.sqrtr  rJ   r  r  rc   rc   rd   r    r  zMpmathPrinter._print_Powc              
      sP   t |\}}d ddt j| |jd d fdd|D S )Nz{}(lambda {}: {}, {})zmpmath.quadrZ   r   c                 3   s$    | ]}d t t j| V  qdS )z(%s, %s)N)r  ro   r^   )r|   rJ  ra   rc   rd   r     s   " z0MpmathPrinter._print_Integral.<locals>.<genexpr>)r  rl   rm   rn   ro   r^   rh   )rb   rP   r  r   rc   ra   rd   _print_Integral  s   zMpmathPrinter._print_IntegralNr  )rk   r  r  __doc__r  r  r   r   r#  r$  _known_functions_mpmathr   _known_constants_mpmathr   r  r  r  r  r  r  r  r  r  rc   rc   rc   rd   r    s$    

r  c                   @   s"   e Zd ZdZdd ZdddZdS )	SymPyPrinterzPython with SymPyc                    sH   |j jpd}d ||rdnd |j j dt fdd|jf S )Nr   r   r   rZ   c                    r[   r\   r]   r_   ra   rc   rd   re     rf   z.SymPyPrinter._print_Function.<locals>.<lambda>)r   r  rm   rk   rn   ro   rh   )rb   rq   modrc   ra   rd   _print_Function  s   zSymPyPrinter._print_FunctionFc                 C   r  )Nz
sympy.sqrtr  r  r  rc   rc   rd   r    r  zSymPyPrinter._print_PowNr  )rk   r  r  r  r  r  rc   rc   rc   rd   r    s    r  N)#r  collectionsr   	itertoolsr   
sympy.corer   sympy.core.modr   r   codeprinterr   r   r#  r%  r&  rs   ru   rv   r2  ry  r   r}   setattrr  r   r  r$  
_in_mpmathr   r  r  r  r  r  rc   rc   rc   rd   <module>   s    	
!	  F 	
0

D