a
    RG5d _                     @   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 h d	Zd
ddd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*Zd+d,d+d-d.d.d/Zd0d1 Zd2d3 ZG d4d5 d5eZG d6d7 d7ZG d8d9 d9eZejD ]Zeed:e e qeD ]Zeed:e e qd;d< Zd= Zd>d? e D Zeefi d@dAdBdCdDdEdFdGdHdIdJdKdLZd+d,dMdNdOd.d-dPdQZdRdS Z G dTdU dUeZ!e!jD ]Zee!d:e e qeD ]Zee!d:e e qG 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>!   tryorFalsewithdelcontinueclasswhileTruebreakelseelifinreturnifraiseforglobalexceptandimportnotfinallyfromnonlocalassertaspasslambdaisNoneyielddef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t fdd|jdS )Nz{name}({args}), c                    s
     | S N_printargself Q/var/www/html/django/DPS/env/lib/python3.9/site-packages/sympy/printing/pycode.py<lambda>E       z#_print_known_func.<locals>.<lambda>)nameargs)known_functions	__class____name__format_module_formatjoinmaprg   ra   exprknownrb   r`   rc   _print_known_funcB   s    rr   c                 C   s   | j |jj }| |S r[   )known_constantsri   rj   rl   ro   rb   rb   rc   _print_known_constH   s    rt   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.rb   .0kvrb   rb   rc   
<listcomp>U   re   z$AbstractPythonCodePrinter.<listcomp>c                 C   s   i | ]\}}|d | qS rw   rb   rx   rb   rb   rc   
<dictcomp>W   re   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 r4dd l}d|jj}|dkrDtd|| _t	t
| _t| jfi |pdi di | _t| jfi |pi 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   _kcrs   )ra   settingsstdr   ri   rb   rc   r   c   s    


z"AbstractPythonCodePrinter.__init__c                 C   s   d||f S Nz%s = %srb   )ra   rf   valuerb   rb   rc   _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   )ra   Zfqnregisterpartsrb   rb   rc   rl   z   s    
"
z(AbstractPythonCodePrinter._module_formatc                 C   s   |S r[   rb   )ra   linesrb   rb   rc   _format_code   s    z&AbstractPythonCodePrinter._format_codec                 C   s
   d |S )Nz{}rk   ra   Z
codestringrb   rb   rc   _get_statement   s    z(AbstractPythonCodePrinter._get_statementc                 C   s
   d |S )Nz  # {}r   )ra   textrb   rb   rc   _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)ra   oprg   rb   rb   rc   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)ra   r   rg   NZNhalfrb   rb   rc   r      s    z2AbstractPythonCodePrinter._expand_reduce_binary_opc                 C   s   dS )Nzfloat('nan')rb   ra   rp   rb   rb   rc   
_print_NaN   s    z$AbstractPythonCodePrinter._print_NaNc                 C   s   dS )Nzfloat('inf')rb   r   rb   rb   rc   _print_Infinity   s    z)AbstractPythonCodePrinter._print_Infinityc                 C   s   dS )Nzfloat('-inf')rb   r   rb   rb   rc   _print_NegativeInfinity   s    z1AbstractPythonCodePrinter._print_NegativeInfinityc                 C   s
   |  |S r[   )r   r   rb   rb   rc   _print_ComplexInfinity   s    z0AbstractPythonCodePrinter._print_ComplexInfinityc                    s$   t | djt fdd|j S )Nz{} % {}c                    s    |  S r[   )parenthesize)xPRECra   rb   rc   rd      re   z6AbstractPythonCodePrinter._print_Mod.<locals>.<lambda>)r   rk   rn   rg   r   rb   r   rc   
_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   rp   condappendr]   rm   )ra   rp   resultir_   rP   crb   rb   rc   _print_Piecewise   s(    







z*AbstractPythonCodePrinter._print_Piecewisec                    sR   ddddddd}|j |v rF| |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   rk   r   _print_Relational)ra   rp   r   r   r   r   rb   rc   r      s    
z+AbstractPythonCodePrinter._print_Relationalc                 C   s   ddl m} | ||S )Nr   )	Piecewise)$sympy.functions.elementary.piecewiser   r]   rewrite)ra   rp   r   rb   rb   rc   
_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]   )ry   r   r   r   r`   rb   rc   	<genexpr>   s   z7AbstractPythonCodePrinter._print_Sum.<locals>.<genexpr>z"(builtins.sum({function} {loops})) )functionloops)limitsrk   r]   r   rm   )ra   rp   r   rb   r`   rc   
_print_Sum   s    

z$AbstractPythonCodePrinter._print_Sumc                 C   s   dS )NZ1jrb   r   rb   rb   rc   _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]   )ra   rp   r   r   rb   rb   rc   _print_KroneckerDelta  s
    
z/AbstractPythonCodePrinter._print_KroneckerDeltac                 C   s,   |j j}| j||}d|| | f S )N%s(%s))ri   rj   rh   r   r]   tolist)ra   rp   rf   funcrb   rb   rc   _print_MatrixBase  s    z+AbstractPythonCodePrinter._print_MatrixBasec                 C   s
   |  |S r[   )r   r   rb   rb   rc   rd     re   z"AbstractPythonCodePrinter.<lambda>c                    s   d  fdd|dD S )N
c                    s   g | ]} j | qS rb   )tab)ry   liner`   rb   rc   r|     re   z@AbstractPythonCodePrinter._indent_codestring.<locals>.<listcomp>)rm   r   r   rb   r`   rc   _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                    s
     | S r[   r\   r^   r`   rb   rc   rd   !  re   zEAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<lambda>z def {name}({parameters}):
{body}rZ   c                    s   g | ]}  |jqS rb   )r]   symbol)ry   varr`   rb   rc   r|   $  re   zGAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<listcomp>)rf   
parametersbody)rm   rn   r   rk   r]   rf   r   r   )ra   fdr   rb   r`   rc   _print_FunctionDefinition   s    
z3AbstractPythonCodePrinter._print_FunctionDefinitionc                    s6   d t fdd|j}dj |j |dS )Nr   c                    s
     | S r[   r\   r^   r`   rb   rc   rd   )  re   z8AbstractPythonCodePrinter._print_While.<locals>.<lambda>zwhile {cond}:
{body})r   r   )rm   rn   r   rk   r]   	conditionr   )ra   Zwhlr   rb   r`   rc   _print_While(  s
    
z&AbstractPythonCodePrinter._print_Whilec                 C   s    d|  |jj|  |jjf S r   )r]   variabler   r   )ra   declrb   rb   rc   _print_Declaration/  s    z,AbstractPythonCodePrinter._print_Declarationc                 C   s   |j \}d| | S )Nz	return %s)rg   r]   )ra   retr_   rb   rb   rc   _print_Return5  s    z'AbstractPythonCodePrinter._print_Returnc                    s^   d t fdd|j}|jd kr8d |j|}|jd krV|d |j 7 }d| S )NrZ   c                    s
     | S r[   r\   r^   r`   rb   rc   rd   :  re   z8AbstractPythonCodePrinter._print_Print.<locals>.<lambda>z	{} % ({})z	, file=%sz	print(%s))rm   rn   
print_argsformat_stringrk   r]   file)ra   Zprntr   rb   r`   rc   _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]   )ra   strmrb   rb   rc   _print_StreamC  s
    

z'AbstractPythonCodePrinter._print_Streamc                 C   s   dS )Nr'   rb   )ra   r_   rb   rb   rc   _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u r| |}| tj	}| |j}| d| d| dS |jtj
u 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   )
ra   rp   rationalrI   r   r   r_   numbase_strZexp_strrb   rb   rc   _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__rb   rb   r   rc   ru   M   s~   



ru   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   s2   ddl m} z
||W S  ty,   | Y S 0 d S )Nr   )convert_indexed_to_array)Z4sympy.tensor.array.expressions.conv_indexed_to_arrayr  	Exception)ra   indexedr  rb   rb   rc   	_arrayify  s
    
zArrayPrinter._arrayifyc                 C   s   |   }d}d}dd |D }g }|D ]J}g }	t|D ].}
||v rR|	||  n
|	| |d7 }q6||	 q&i }g }g }|D ]f}
|
D ]T}||vrt|}|||< n|| }||7 }||v r||vr|| q|| q|d7 }q|d d }|||fS )Nr   r   c                 S   s    i | ]}|D ]}|t |qqS rb   )r+   )ry   r   jrb   rb   rc   r}     re   z3ArrayPrinter._get_einsum_string.<locals>.<dictcomp>r   ,r   ) _get_letter_generator_for_einsumranger   next)ra   subrankscontraction_indicesletterscontraction_stringcounterdindicesZrank_argZlindicesr   mappingletters_freeletters_dumr  lrb   rb   rc   _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   )ra   r   rb   rb   rc   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 rb   )r  )ry   r  r!  rb   rc   r|     re   zEArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>.<listcomp>)rm   r  ry   r   r0  rb   rc   r|     re   z:ArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>%s("%s", %s)r   rZ   c                    s   g | ]}  |qS rb   r\   ry   r_   r`   rb   rc   r|     re   )r  rm   r  rl   _module_einsumrg   )ra   rp   r"  rb   )r!  ra   rc   _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\   r3  r`   rb   rc   r|     re   z8ArrayPrinter._print_ArrayContraction.<locals>.<listcomp>c                    s   g | ]}d   | qS r9  r\   r3  r`   rb   rc   r|     re   r2  r   {}->{}r   )0sympy.tensor.array.expressions.array_expressionsr8  rp   r   
isinstancerm   rg   r  r]   r   shaper*  rl   r4  r5  rk   sorted)
ra   rp   r8  r   r   elemsranksr"  r'  r(  rb   r`   rc   _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   r7  c                    s   g | ]}  |qS rb   r\   r1  r`   rb   rc   r|     re   z5ArrayPrinter._print_ArrayDiagonal.<locals>.<listcomp>r2  r   r:  r   rZ   )r;  r8  listdiagonal_indicesr<  rp   r  rg   r*  rl   r4  r5  rk   rm   )	ra   rp   r8  rC  r  r?  Zdiagonal_stringr'  r(  rb   r`   rc   _print_ArrayDiagonal  s    

z!ArrayPrinter._print_ArrayDiagonalc                 C   s2   d|  | jd | j | |j| |jjf S )Nr   r   )rl   r4  Z
_transposer]   rp   permutation
array_formr   rb   rb   rc   _print_PermuteDims  s
    
zArrayPrinter._print_PermuteDimsc                 C   s   |  | jd | j |jS )Nr   )r   r4  _addrg   r   rb   rb   rc   _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   r4  Z_onesrm   rn   r]   rg   r   rb   rb   rc   _print_OneArray  s    zArrayPrinter._print_OneArrayc                 C   s.   d|  | jd | j dt| j|jf S rJ  )rl   r4  Z_zerosrm   rn   r]   rg   r   rb   rb   rc   _print_ZeroArray  s    zArrayPrinter._print_ZeroArrayc                 C   s0   |  | |j}|  | |j}d||f S r   )r]   r  r   r   )ra   rp   r   r   rb   rb   rc   _print_Assignment  s    zArrayPrinter._print_Assignmentc                 C   s
   |  |S r[   )_print_ArraySymbolr   rb   rb   rc   _print_IndexedBase  s    zArrayPrinter._print_IndexedBaseN)rj   r  r  r  r*  r  r6  rA  rD  rG  rI  rK  rL  rM  rO  rb   rb   rb   rc   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   ra   rP   rb   rb   rc   _print_sign  s    zPythonCodePrinter._print_signc                 C   s$   t |}| jd | |jd | S )Nr   r   )r   r  r   rg   )ra   rp   r   rb   rb   rc   
_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 rb   r\   )ry   indr`   rb   rc   r|   &  re   z4PythonCodePrinter._print_Indexed.<locals>.<listcomp>)rg   rk   r   rm   )ra   rp   r   indexrb   r`   rc   _print_Indexed#  s    
z PythonCodePrinter._print_IndexedFc                 C   s   | j ||dS )N)r  r  ra   rp   r  rb   rb   rc   
_print_Pow(  s    zPythonCodePrinter._print_Powc                 C   s   d |j|jS )Nz{}/{})rk   pqr   rb   rb   rc   _print_Rational+  s    z!PythonCodePrinter._print_Rationalc                 C   s
   |  |S r[   r^  r   rb   rb   rc   _print_Half.  s    zPythonCodePrinter._print_Halfc                 C   s   |  t|jd dS )Nr   r   )r   r   rg   r   rb   rb   rc   _print_frac1  s    zPythonCodePrinter._print_fracc                    sd   t  |}|| jv r@| jd r2d}t|||| jd  S d|v 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)ra   rp   rf   msgr   rb   rc   rd  4  s    

zPythonCodePrinter._print_Symbol)F)rj   r  r  rT  rU  rX  r[  r^  r`  ra  rd  r   Z_print_not_supported_print_lowergamma_print_uppergamma_print_fresnelc_print_fresnelsr  rb   rb   r   rc   rP    s   
rP  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'

    )rP  doprint)rp   r   rb   rb   rc   pycodeP  s    rl  z
log1p log2c                 C   s    g | ]\}}|t vr||fqS rb   )_not_in_mpmathrx   rb   rb   rc   r|   k  re   r|   betafracfresnelcfresnelssignrM   hypermeijergbesseljbesselybesselibesselk)rn  ro  rp  rq  rr  rM   rs  rt  ru  rv  rw  rx  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_varlower_limitZupper_limitrb   rb   rc   _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
    Z_mpmathcodezPython with mpmathc                 C   s   g | ]\}}|d | fqS zmpmath.rb   rx   rb   rb   rc   r|     re   zMpmathPrinter.<listcomp>c                 C   s   i | ]\}}|d | qS r  rb   rx   rb   rb   rc   r}     re   zMpmathPrinter.<dictcomp>c                 C   s(   t ttt|j}dj| d|dS )Nz{func}({args})
mpmath.mpf)r   rg   )r   tuplern   int_mpf_rk   rl   )ra   rP   rg   rb   rb   rc   _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\  )rk   rl   r]   r]  r\  rS  rb   rb   rc   r^    s
    

zMpmathPrinter._print_Rationalc                 C   s
   |  |S r[   r_  rS  rb   rb   rc   r`    s    zMpmathPrinter._print_Halfc                 C   s4   d | d| |jd | |jd | dS )Nz{}({}, {}, {})mpmath.gammaincr   r   z
mpmath.infrR  rS  rb   rb   rc   rh    s    zMpmathPrinter._print_uppergammac                 C   s,   d | d| |jd | |jd S )Nz{}({}, 0, {})r  r   r   rR  rS  rb   rb   rc   rg    s
    zMpmathPrinter._print_lowergammac                 C   s   d | d| |jd S )Nz{0}({1})/{0}(2)
mpmath.logr   rR  rS  rb   rb   rc   _print_log2  s    zMpmathPrinter._print_log2c                 C   s   d | d| |jd S )Nz{}({}+1)r  r   rR  rS  rb   rb   rc   _print_log1p  s    zMpmathPrinter._print_log1pFc                 C   s   | j ||ddS )Nzmpmath.sqrtr  rI   rY  rZ  rb   rb   rc   r[    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  rn   r]   )ry   r)  r`   rb   rc   r     re   z0MpmathPrinter._print_Integral.<locals>.<genexpr>)r  rk   rl   rm   rn   r]   rg   )ra   rP   r  r   rb   r`   rc   _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  r^  r`  rh  rg  r  r  r[  r  rb   rb   rb   rc   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                    s
     | S r[   r\   r^   r`   rb   rc   rd     re   z.SymPyPrinter._print_Function.<locals>.<lambda>)r   r  rl   rj   rm   rn   rg   )ra   rp   modrb   r`   rc   _print_Function  s    zSymPyPrinter._print_FunctionFc                 C   s   | j ||ddS )Nz
sympy.sqrtr  rY  rZ  rb   rb   rc   r[    s    zSymPyPrinter._print_PowN)F)rj   r  r  r
  r  r[  rb   rb   rb   rc   r    s   r  N)#r  collectionsr   	itertoolsr   
sympy.corer   Zsympy.core.modr   r   codeprinterr   r  r  r  r  rr   rt   ru   r  rP  r   rz   setattrrl  r   rm  r  Z
_in_mpmathr   r  r  r  r  r  rb   rb   rb   rc   <module>   s   !	  F 	0

D
