U
    ;qLe^                  !   @   s,  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 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)h!Zd*d+d,d-Zd.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdAdBdCdDdEdFdGdHdIdJZdKdLdKdMdNdNdOZdPdQ ZdRdS ZG dTdU dUeZG dVdW dWZG dXdY dYeZejD ]ZeedZe e q4eD ]ZeedZe e qPd[d\ Zd] Zd^d_ e D Zeefd`dadbdcdddedfdgdhdidjdkdlZdKdLdmdndodNdMdpdqZdrds Z G dtdu dueZ!e!jD ]Zee!dZe e qeD ]Zee!dZe e q G dvdw dweZ"dxS )yzy
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andasassertbreakclasscontinuedefdelelifelseexceptfinallyforfromglobalifimportinislambdanotorpassraisereturntrywhilewithyieldNoneFalsenonlocalTrueabsminmax)AbsMinMaxacosacoshasinasinhatanatan2atanhceilcoscosherferfcexpexpm1	factorialfloorgammahypotlgammaloglog10log1plog2sinsinhsqrttantanh)r0   r1   r2   r3   r4   r5   r6   ceilingr8   r9   r:   r;   r<   r=   r>   r?   r@   rA   loggammarC   lnrD   rE   rF   rG   rH   SqrtrJ   rK   epiinfnan)Exp1PiEInfinityNaNComplexInfinityc                    s8    j |jj }dj |d fdd|jD dS )Nz{name}({args}), c                 3   s   | ]}  |V  qd S N_print.0argself l/home/p21-0144/sympy/latex2sympy2solve-back-end/sympyEq/lib/python3.8/site-packages/sympy/printing/pycode.py	<genexpr>E   s     z$_print_known_func.<locals>.<genexpr>)nameargs)known_functions	__class____name__format_module_formatjoinrg   rb   exprknownrc   ra   rd   _print_known_funcB   s    rq   c                 C   s   | j |jj }| |S r[   )known_constantsri   rj   rl   rn   rc   rc   rd   _print_known_constH   s    rs   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AbstractPythonCodePrinterZ_pythoncodePythonNz    c                 C   s   g | ]\}}|d | fqS zmath.rc   r_   kvrc   rc   rd   
<listcomp>U   s     z$AbstractPythonCodePrinter.<listcomp>c                 C   s   i | ]\}}|d | qS rv   rc   rw   rc   rc   rd   
<dictcomp>W   s      z$AbstractPythonCodePrinter.<dictcomp>r	   r   r   )r	   r   r      TFpython3)user_functions	precisioninlinefully_qualified_modulesZcontractstandardc                    s   t  | | jd }|d kr4dd l}d|jj}|dkrDtd|| _t	t
| _t| jf|pbi di | _t| jf|p~i di | _d S )Nr   r   zpython{}r}   zOnly Python 3 is supported.r~   Zuser_constants)super__init__	_settingssysrk   version_infomajor
ValueErrorr   r   setmodule_importsdict_kfgetrh   _kcrr   )rb   settingsZstdr   ri   rc   rd   r   c   s"    

  z"AbstractPythonCodePrinter.__init__c                 C   s   d||f S Nz%s = %src   )rb   rf   valuerc   rc   rd   _declare_number_constw   s    z/AbstractPythonCodePrinter._declare_number_constc                 C   sp   | d}|r<t|dkr<| jd|d d  |d  | jd rJ|S | dd  dd  dd S d S )N.r   r   (r   [)splitlenr   rm   addr   )rb   Zfqnregisterpartsrc   rc   rd   rl   z   s    
"
z(AbstractPythonCodePrinter._module_formatc                 C   s   |S r[   rc   )rb   linesrc   rc   rd   _format_code   s    z&AbstractPythonCodePrinter._format_codec                 C   s
   d |S )Nz{}rk   rb   Z
codestringrc   rc   rd   _get_statement   s    z(AbstractPythonCodePrinter._get_statementc                 C   s
   d |S )Nz  # {}r   )rb   textrc   rc   rd   _get_comment   s    z&AbstractPythonCodePrinter._get_commentc                 C   sL   t |dkr| |d S d| || ||dd | |d f S 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   
%s(%s, %s)Nr   )r   r]   rl   _expand_fold_binary_op)rb   oprg   rc   rc   rd   r      s    z0AbstractPythonCodePrinter._expand_fold_binary_opc                 C   s^   t |dkr| |d S t |}|d }d| || |d| | ||d f S dS )z
        This method expands a reductin on binary operations.

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

        For example, the expression

        `A + B + C + D`

        is reduced into:

        `(A + B) + (C + D)`
        r   r      r   N)r   r]   rl   _expand_reduce_binary_op)rb   r   rg   NZNhalfrc   rc   rd   r      s    z2AbstractPythonCodePrinter._expand_reduce_binary_opc                 C   s   dS )Nzfloat('nan')rc   rb   ro   rc   rc   rd   
_print_NaN   s    z$AbstractPythonCodePrinter._print_NaNc                 C   s   dS )Nzfloat('inf')rc   r   rc   rc   rd   _print_Infinity   s    z)AbstractPythonCodePrinter._print_Infinityc                 C   s   dS )Nzfloat('-inf')rc   r   rc   rc   rd   _print_NegativeInfinity   s    z1AbstractPythonCodePrinter._print_NegativeInfinityc                 C   s
   |  |S r[   )r   r   rc   rc   rd   _print_ComplexInfinity   s    z0AbstractPythonCodePrinter._print_ComplexInfinityc                    s$   t | dj fdd|jD  S )Nz{} % {}c                 3   s   | ]} | V  qd S r[   )parenthesize)r_   xPRECrb   rc   rd   re      s     z7AbstractPythonCodePrinter._print_Mod.<locals>.<genexpr>)r   rk   rg   r   rc   r   rd   
_print_Mod   s    z$AbstractPythonCodePrinter._print_Modc                 C   s   g }d}|j D ]r}|j}|j}|dkr0|d |d || | |d |d || | |d |d7 }q|d d }|d dkr|d d	 }|d n
|d
 d|S )Nr   r   )z if z else r   r   r)   z else None) )rg   ro   condappendr]   rm   )rb   ro   resultir`   rP   crc   rc   rd   _print_Piecewise   s(    







z*AbstractPythonCodePrinter._print_Piecewisec                    sR   ddddddd}|j |krF| |j}| |j}dj|j ||d	S t |S )
z.Relational printer for Equality and UnequalityequalZ	not_equallessZ
less_equalZgreaterZgreater_equal)z==z!=<z<=>z>=z({lhs} {op} {rhs}))r   lhsrhs)rel_opr]   r   r   rk   r   _print_Relational)rb   ro   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   ro   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   s6   | ].\}}}d j  | | |dV  qdS )zfor {i} in range({a}, {b}+1))r   abN)rk   r]   )r_   r   r   r   ra   rc   rd   re      s   z7AbstractPythonCodePrinter._print_Sum.<locals>.<genexpr>z"(builtins.sum({function} {loops})) )functionloops)limitsrk   r]   r   rm   )rb   ro   r   rc   ra   rd   
_print_Sum   s    

z$AbstractPythonCodePrinter._print_Sumc                 C   s   dS )NZ1jrc   r   rc   rc   rd   _print_ImaginaryUnit  s    z.AbstractPythonCodePrinter._print_ImaginaryUnitc                 C   s$   |j \}}dj| || |dS )Nz(1 if {a} == {b} else 0))r   r   )rg   rk   r]   )rb   ro   r   r   rc   rc   rd   _print_KroneckerDelta  s
    
z/AbstractPythonCodePrinter._print_KroneckerDeltac                 C   s,   |j j}| j||}d|| | f S )N%s(%s))ri   rj   rh   r   r]   tolist)rb   ro   rf   funcrc   rc   rd   _print_MatrixBase  s    z+AbstractPythonCodePrinter._print_MatrixBasec                 C   s
   |  |S r[   )r   r   rc   rc   rd   <lambda>      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   rz     s     z@AbstractPythonCodePrinter._indent_codestring.<locals>.<listcomp>)rm   r   r   rc   ra   rd   _indent_codestring  s    z,AbstractPythonCodePrinter._indent_codestringc                    sN   d  fdd|jD }dj |jd  fdd|jD  |dS )	Nr   c                 3   s   | ]}  |V  qd S r[   r\   r^   ra   rc   rd   re   !  s     zFAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<genexpr>z def {name}({parameters}):
{body}rZ   c                    s   g | ]}  |jqS rc   )r]   symbol)r_   varra   rc   rd   rz   $  s     zGAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<listcomp>)rf   
parametersbody)rm   r   rk   r]   rf   r   r   )rb   fdr   rc   ra   rd   _print_FunctionDefinition   s    
z3AbstractPythonCodePrinter._print_FunctionDefinitionc                    s6   d  fdd|jD }dj |j |dS )Nr   c                 3   s   | ]}  |V  qd S r[   r\   r^   ra   rc   rd   re   )  s     z9AbstractPythonCodePrinter._print_While.<locals>.<genexpr>zwhile {cond}:
{body})r   r   )rm   r   rk   r]   	conditionr   )rb   Z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   Zdeclrc   rc   rd   _print_Declaration/  s    z,AbstractPythonCodePrinter._print_Declarationc                 C   s   |j \}d| | S )Nz	return %s)rg   r]   )rb   retr`   rc   rc   rd   _print_Return5  s    z'AbstractPythonCodePrinter._print_Returnc                    s^   d  fdd|jD }|jd kr8d |j|}|jd krV|d |j 7 }d| S )NrZ   c                 3   s   | ]}  |V  qd S r[   r\   r^   ra   rc   rd   re   :  s     z9AbstractPythonCodePrinter._print_Print.<locals>.<genexpr>z	{} % ({})z	, file=%sz	print(%s))rm   
print_argsformat_stringrk   r]   file)rb   Zprntr   rc   ra   rd   _print_Print9  s    

 
z&AbstractPythonCodePrinter._print_Printc                 C   s@   t |jdkr| dS t |jdkr0| dS | |jS d S )Nstdoutz
sys.stdoutstderrz
sys.stderr)strrf   rl   r]   )rb   Zstrmrc   rc   rd   _print_StreamC  s
    

z'AbstractPythonCodePrinter._print_Streamc                 C   s   dS )Nr&   rc   )rb   r`   rc   rc   rd   _print_NoneTokenK  s    z*AbstractPythonCodePrinter._print_NoneToken	math.sqrtc           
      C   s   t |}|jtjkr<|s<| |}| |j}dj||dS |jr|s|j tjkr| |}| tj	}| |j}| d| d| dS |jtj
kr| 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   Halfrl   r]   baserk   is_commutativeOneNegativeOner   )
rb   ro   rationalrI   r   r   r`   numbase_strZexp_strrc   rc   rd   _hprint_PowN  s$    +


z%AbstractPythonCodePrinter._hprint_Pow)N)T)Fr   ):rj   
__module____qualname__printmethodlanguage_kwreserved_wordsmodulesr   r   r   _known_functionsitems_known_functions_mathr   _known_constants_mathr   
_operatorsr   _default_settingsr   r   rl   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Z_print_SparseRepMatrixZ_print_MutableSparseMatrixZ_print_ImmutableSparseMatrixZ_print_MatrixZ_print_DenseMatrixZ_print_MutableDenseMatrixZ_print_ImmutableMatrixZ_print_ImmutableDenseMatrixr   r   r   r   r   r   r   r   r   __classcell__rc   rc   r   rd   rt   M   s~   



rt   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   s4   ddl m} z
||W S  tk
r.   | Y S X d S )Nr   )convert_indexed_to_array)Z4sympy.tensor.array.expressions.from_indexed_to_arrayr  	Exception)rb   indexedr  rc   rc   rd   	_arrayify  s
    
zArrayPrinter._arrayifyc                 C   s   |   }d}d}dd |D }g }|D ]J}g }	t|D ].}
||krR|	||  n
|	| |d7 }q6||	 q&i }g }g }|D ]f}
|
D ]T}||krt|}|||< n|| }||7 }||kr||kr|| q|| q|d7 }q|d d }|||fS )Nr   r   c                 S   s    i | ]}|D ]}|t |qqS rc   )r+   )r_   r   jrc   rc   rd   r{     s
        z3ArrayPrinter._get_einsum_string.<locals>.<dictcomp>r   ,r   ) _get_letter_generator_for_einsumranger   next)rb   subrankscontraction_indicesletterscontraction_stringcounterdindicesZrank_argZlindicesr   mappingletters_freeletters_dumr  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d S )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_   r  r  rc   rd   rz     s     zEArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>.<listcomp>)rm   r  r_   r   r'  rc   rd   rz     s     z:ArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>%s("%s", %s)r   rZ   c                    s   g | ]}  |qS rc   r\   r^   ra   rc   rd   rz     s     )r  rm   r  rl   _module_einsumrg   )rb   ro   r  rc   )r  rb   rd   _print_ArrayTensorProduct  s    z&ArrayPrinter._print_ArrayTensorProductc           
   	      s   ddl m} |j}|j}t||rDd fdd|jD }|j}n |}t	|j
g} ||\}}}	|sz |S t||rd fdd|jD }n
 |}d  jd  j d	|d
t||f S )Nr   ArrayTensorProductr  c                    s   g | ]}d   | qS z%sr\   r^   ra   rc   rd   rz     s     z8ArrayPrinter._print_ArrayContraction.<locals>.<listcomp>c                    s   g | ]}d   | qS r/  r\   r^   ra   rc   rd   rz     s     r)  r   {}->{}r   )0sympy.tensor.array.expressions.array_expressionsr.  ro   r  
isinstancerm   rg   r  r]   r   shaper!  rl   r*  r+  rk   sorted)
rb   ro   r.  r   r  elemsZranksr  r  r  rc   ra   rd   _print_ArrayContraction  s&    




z$ArrayPrinter._print_ArrayContractionc           	   	      s   ddl m} t|j}t|j|r4|jj}|jj}n|j}|jg} ||\}}} fdd|D }d 	 j
d  j d|d|| d	|f S )
Nr   r-  c                    s   g | ]}  |qS rc   r\   r(  ra   rc   rd   rz     s     z5ArrayPrinter._print_ArrayDiagonal.<locals>.<listcomp>r)  r   r0  r   rZ   )r1  r.  listdiagonal_indicesr2  ro   r  rg   r!  rl   r*  r+  rk   rm   )	rb   ro   r.  r8  r  r5  Zdiagonal_stringr  r  rc   ra   rd   _print_ArrayDiagonal  s    

z!ArrayPrinter._print_ArrayDiagonalc                 C   s2   d|  | jd | j | |j| |jjf S )Nr   r   )rl   r*  Z
_transposer]   ro   Zpermutation
array_formr   rc   rc   rd   _print_PermuteDims  s
    
zArrayPrinter._print_PermuteDimsc                 C   s   |  | jd | j |jS )Nr   )r   r*  _addrg   r   rc   rc   rd   _print_ArrayAdd  s    zArrayPrinter._print_ArrayAddc                 C   s.   d|  | jd | j dt| j|jf S Nz	%s((%s,))r   r  )rl   r*  Z_onesrm   mapr]   rg   r   rc   rc   rd   _print_OneArray  s    zArrayPrinter._print_OneArrayc                 C   s.   d|  | jd | j dt| j|jf S r>  )rl   r*  Z_zerosrm   r?  r]   rg   r   rc   rc   rd   _print_ZeroArray  s    zArrayPrinter._print_ZeroArrayc                 C   s0   |  | |j}|  | |j}d||f S r   )r]   r  r   r   )rb   ro   r   r   rc   rc   rd   _print_Assignment  s    zArrayPrinter._print_Assignmentc                 C   s
   |  |S r[   )_print_ArraySymbolr   rc   rc   rd   _print_IndexedBase  s    zArrayPrinter._print_IndexedBaseN)rj   r   r   r  r!  r  r,  r6  r9  r;  r=  r@  rA  rB  rD  rc   rc   rc   rd   r    s   #	r  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   rk   rl   r]   rg   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   rg   )rb   ro   r   rc   rc   rd   
_print_Not  s    zPythonCodePrinter._print_Notc                    s<   |j d }|j dd  }dt|d fdd|D S )Nr   r   z{}[{}]rZ   c                    s   g | ]}  |qS rc   r\   )r_   indra   rc   rd   rz   &  s     z4PythonCodePrinter._print_Indexed.<locals>.<listcomp>)rg   rk   r   rm   )rb   ro   r   indexrc   ra   rd   _print_Indexed#  s    
z PythonCodePrinter._print_IndexedFc                 C   s   | j ||dS )N)r   r   rb   ro   r   rc   rc   rd   
_print_Pow(  s    zPythonCodePrinter._print_Powc                 C   s   d |j|jS )Nz{}/{})rk   pqr   rc   rc   rd   _print_Rational+  s    z!PythonCodePrinter._print_Rationalc                 C   s
   |  |S r[   rS  r   rc   rc   rd   _print_Half.  s    zPythonCodePrinter._print_Halfc                 C   s   |  t|jd dS )Nr   r   )r   r   rg   r   rc   rc   rd   _print_frac1  s    zPythonCodePrinter._print_fracc                    sd   t  |}|| jkr@| jd r2d}t|||| jd  S d|kr\|ddddS |S d S )NZerror_on_reservedzVThis expression includes the symbol "{}" which is a reserved keyword in this language.Zreserved_word_suffix{r   })r   _print_Symbolr  r   r   rk   replace)rb   ro   rf   msgr   rc   rd   rY  4  s    

zPythonCodePrinter._print_Symbol)F)rj   r   r   rI  rJ  rM  rP  rS  rU  rV  rY  r   Z_print_not_supported_print_lowergamma_print_uppergamma_print_fresnelc_print_fresnelsr  rc   rc   r   rd   rE    s   
rE  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'

    )rE  doprint)ro   r   rc   rc   rd   pycodeP  s    ra  z
log1p log2c                 C   s    g | ]\}}|t kr||fqS rc   )_not_in_mpmathrw   rc   rc   rd   rz   k  s      rz   betafracfresnelcfresnelssignrM   hypermeijergbesseljbesselybesselibesselk)rc  rd  re  rf  rg  rM   rh  ri  rj  rk  rl  rm  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   )Zintegral_exprintegration_varsr   Zintegration_rangeZintegration_varZlower_limitZupper_limitrc   rc   rd   _unpack_integral_limits  s    

ry  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
    Z_mpmathcodezPython with mpmathc                 C   s   g | ]\}}|d | fqS zmpmath.rc   rw   rc   rc   rd   rz     s     zMpmathPrinter.<listcomp>c                 C   s   i | ]\}}|d | qS r{  rc   rw   rc   rc   rd   r{     s      zMpmathPrinter.<dictcomp>c                 C   s(   t ttt|j}dj| d|dS )Nz{func}({args})
mpmath.mpf)r   rg   )r   tupler?  int_mpf_rk   rl   )rb   rP   rg   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   rR  rQ  )rk   rl   r]   rR  rQ  rH  rc   rc   rd   rS    s
    

zMpmathPrinter._print_Rationalc                 C   s
   |  |S r[   rT  rH  rc   rc   rd   rU    s    zMpmathPrinter._print_Halfc                 C   s4   d | d| |jd | |jd | dS )Nz{}({}, {}, {})mpmath.gammaincr   r   z
mpmath.infrG  rH  rc   rc   rd   r]    s    zMpmathPrinter._print_uppergammac                 C   s,   d | d| |jd | |jd S )Nz{}({}, 0, {})r  r   r   rG  rH  rc   rc   rd   r\    s
    zMpmathPrinter._print_lowergammac                 C   s   d | d| |jd S )Nz{0}({1})/{0}(2)z
mpmath.logr   rG  rH  rc   rc   rd   _print_log2  s     zMpmathPrinter._print_log2c                 C   s   d | d| |jd S )Nz{}({})zmpmath.log1pr   rG  rH  rc   rc   rd   _print_log1p  s     zMpmathPrinter._print_log1pFc                 C   s   | j ||ddS )Nzmpmath.sqrtr   rI   rN  rO  rc   rc   rd   rP    s    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}  r?  r]   )r_   r   ra   rc   rd   re     s     z0MpmathPrinter._print_Integral.<locals>.<genexpr>)ry  rk   rl   rm   r?  r]   rg   )rb   rP   rx  r   rc   ra   rd   _print_Integral  s    zMpmathPrinter._print_IntegralN)F)rj   r   r   __doc__r   r  r   r   r  r  _known_functions_mpmathr   _known_constants_mpmathr   r  rS  rU  r]  r\  r  r  rP  r  rc   rc   rc   rd   rz    s"   

rz  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 fdd|jD f S )Nr   r   r   rZ   c                 3   s   | ]}  |V  qd S r[   r\   r^   ra   rc   rd   re     s     z/SymPyPrinter._print_Function.<locals>.<genexpr>)r   r   rl   rj   rm   rg   )rb   ro   modrc   ra   rd   _print_Function  s    zSymPyPrinter._print_FunctionFc                 C   s   | j ||ddS )Nz
sympy.sqrtr  rN  rO  rc   rc   rd   rP    s    zSymPyPrinter._print_PowN)F)rj   r   r   r  r  rP  rc   rc   rc   rd   r    s   r  N)#r  collectionsr   	itertoolsr   
sympy.corer   Zsympy.core.modr   r   codeprinterr   r  r  r  r  rq   rs   rt   r  rE  r   rx   setattrra  r   rb  r  Z
_in_mpmathr   r  r  ry  rz  r  rc   rc   rc   rd   <module>   s                                !	  F 	0
D
