U
    9%e^                  !   @   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)ZAbsZMinZ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)r-   r.   r/   r0   r1   r2   r3   Zceilingr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   loggammar@   lnrA   rB   rC   rD   rE   ZSqrtrG   rH   epiinfnan)Exp1PiEInfinityNaNZ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 T/var/www/html/Darija-Ai-API/env/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joinra   r\   exprZknownr]   r[   r^   _print_known_funcB   s    rj   c                 C   s   | j |jj }| |S rU   )known_constantsrc   rd   rf   rh   r]   r]   r^   _print_known_constH   s    rl   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.r]   rY   kvr]   r]   r^   
<listcomp>U   s     z$AbstractPythonCodePrinter.<listcomp>c                 C   s   i | ]\}}|d | qS ro   r]   rp   r]   r]   r^   
<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{}rv   zOnly Python 3 is supported.rw   Zuser_constants)super__init__	_settingssysre   version_infomajor
ValueErrorr{   r   setmodule_importsdict_kfgetrb   _kcrk   )r\   settingsZstdr   rc   r]   r^   r}   c   s"    

  z"AbstractPythonCodePrinter.__init__c                 C   s   d||f S Nz%s = %sr]   )r\   r`   valuer]   r]   r^   _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   rz   (r   [)splitlenr   rg   addr~   )r\   Zfqnregisterpartsr]   r]   r^   rf   z   s    
"
z(AbstractPythonCodePrinter._module_formatc                 C   s   |S rU   r]   )r\   linesr]   r]   r^   _format_code   s    z&AbstractPythonCodePrinter._format_codec                 C   s
   d |S )Nz{}re   r\   Z
codestringr]   r]   r^   _get_statement   s    z(AbstractPythonCodePrinter._get_statementc                 C   s
   d |S )Nz  # {}r   )r\   textr]   r]   r^   _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   rW   rf   _expand_fold_binary_op)r\   opra   r]   r]   r^   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   rW   rf   _expand_reduce_binary_op)r\   r   ra   NZNhalfr]   r]   r^   r      s    z2AbstractPythonCodePrinter._expand_reduce_binary_opc                 C   s   dS )Nzfloat('nan')r]   r\   ri   r]   r]   r^   
_print_NaN   s    z$AbstractPythonCodePrinter._print_NaNc                 C   s   dS )Nzfloat('inf')r]   r   r]   r]   r^   _print_Infinity   s    z)AbstractPythonCodePrinter._print_Infinityc                 C   s   dS )Nzfloat('-inf')r]   r   r]   r]   r^   _print_NegativeInfinity   s    z1AbstractPythonCodePrinter._print_NegativeInfinityc                 C   s
   |  |S rU   )r   r   r]   r]   r^   _print_ComplexInfinity   s    z0AbstractPythonCodePrinter._print_ComplexInfinityc                    s$   t | dj fdd|jD  S )Nz{} % {}c                 3   s   | ]} | V  qd S rU   )parenthesize)rY   xPRECr\   r]   r^   r_      s     z7AbstractPythonCodePrinter._print_Mod.<locals>.<genexpr>)r   re   ra   r   r]   r   r^   
_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) )ra   ri   condappendrW   rg   )r\   ri   resultirZ   rK   cr]   r]   r^   _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equal	not_equallessZ
less_equalZgreaterZgreater_equal)z==z!=<z<=>z>=z({lhs} {op} {rhs}))r   lhsrhs)Zrel_oprW   r   r   re   r|   _print_Relational)r\   ri   r   r   r   r   r]   r^   r      s    
z+AbstractPythonCodePrinter._print_Relationalc                 C   s   ddl m} | ||S )Nr   )	Piecewise)Z$sympy.functions.elementary.piecewiser   rW   Zrewrite)r\   ri   r   r]   r]   r^   
_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)re   rW   )rY   r   r   r   r[   r]   r^   r_      s   z7AbstractPythonCodePrinter._print_Sum.<locals>.<genexpr>z"(builtins.sum({function} {loops})) )functionloops)limitsre   rW   r   rg   )r\   ri   r   r]   r[   r^   
_print_Sum   s    

z$AbstractPythonCodePrinter._print_Sumc                 C   s   dS )NZ1jr]   r   r]   r]   r^   _print_ImaginaryUnit  s    z.AbstractPythonCodePrinter._print_ImaginaryUnitc                 C   s$   |j \}}dj| || |dS )Nz(1 if {a} == {b} else 0))r   r   )ra   re   rW   )r\   ri   r   r   r]   r]   r^   _print_KroneckerDelta  s
    
z/AbstractPythonCodePrinter._print_KroneckerDeltac                 C   s,   |j j}| j||}d|| | f S )N%s(%s))rc   rd   rb   r   rW   tolist)r\   ri   r`   funcr]   r]   r^   _print_MatrixBase  s    z+AbstractPythonCodePrinter._print_MatrixBasec                 C   s
   |  |S rU   )r   r   r]   r]   r^   <lambda>      z"AbstractPythonCodePrinter.<lambda>c                    s   d  fdd|dD S )N
c                    s   g | ]} j | qS r]   )tab)rY   liner[   r]   r^   rs     s     z@AbstractPythonCodePrinter._indent_codestring.<locals>.<listcomp>)rg   r   r   r]   r[   r^   _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 rU   rV   rX   r[   r]   r^   r_   !  s     zFAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<genexpr>z def {name}({parameters}):
{body}rT   c                    s   g | ]}  |jqS r]   )rW   symbol)rY   varr[   r]   r^   rs   $  s     zGAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<listcomp>)r`   
parametersbody)rg   r   re   rW   r`   r   r   )r\   fdr   r]   r[   r^   _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 rU   rV   rX   r[   r]   r^   r_   )  s     z9AbstractPythonCodePrinter._print_While.<locals>.<genexpr>zwhile {cond}:
{body})r   r   )rg   r   re   rW   	conditionr   )r\   Zwhlr   r]   r[   r^   _print_While(  s
    
z&AbstractPythonCodePrinter._print_Whilec                 C   s    d|  |jj|  |jjf S r   )rW   variabler   r   )r\   declr]   r]   r^   _print_Declaration/  s    z,AbstractPythonCodePrinter._print_Declarationc                 C   s   |j \}d| | S )Nz	return %s)ra   rW   )r\   retrZ   r]   r]   r^   _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 )NrT   c                 3   s   | ]}  |V  qd S rU   rV   rX   r[   r]   r^   r_   :  s     z9AbstractPythonCodePrinter._print_Print.<locals>.<genexpr>z	{} % ({})z	, file=%sz	print(%s))rg   
print_argsformat_stringre   rW   file)r\   Zprntr   r]   r[   r^   _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)strr`   rf   rW   )r\   strmr]   r]   r^   _print_StreamC  s
    

z'AbstractPythonCodePrinter._print_Streamc                 C   s   dS )Nr&   r]   )r\   rZ   r]   r]   r^   _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   rZ   /r   r   F)strictz{}**{})r   r9   r   ZHalfrf   rW   basere   Zis_commutativeZOneZNegativeOner   )
r\   ri   rationalrF   r   r   rZ   numZbase_strZexp_strr]   r]   r^   _hprint_PowN  s$    +


z%AbstractPythonCodePrinter._hprint_Pow)N)T)Fr   ):rd   
__module____qualname__printmethodlanguage_kwreserved_wordsmodulesr   r   r   _known_functionsitems_known_functions_mathr   _known_constants_mathr   
_operatorsr   Z_default_settingsr}   r   rf   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__r]   r]   r   r^   rm   M   s~   



rm   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)r\   Zindexedr   r]   r]   r^   	_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 r]   )r+   )rY   r   jr]   r]   r^   rt     s
        z3ArrayPrinter._get_einsum_string.<locals>.<dictcomp>r   ,r   ) _get_letter_generator_for_einsumranger   next)r\   subrankscontraction_indicesletterscontraction_stringcounterdindicesZrank_argZlindicesr   mappingletters_freeletters_dumr  lr]   r]   r^   _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   )r\   r   r]   r]   r^   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 r]   )r  )rY   r  r
  r]   r^   rs     s     zEArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>.<listcomp>)rg   r  rY   r   r  r]   r^   rs     s     z:ArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>%s("%s", %s)r   rT   c                    s   g | ]}  |qS r]   rV   rX   r[   r]   r^   rs     s     )r  rg   r  rf   _module_einsumra   )r\   ri   r  r]   )r
  r\   r^   _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%srV   rX   r[   r]   r^   rs     s     z8ArrayPrinter._print_ArrayContraction.<locals>.<listcomp>c                    s   g | ]}d   | qS r!  rV   rX   r[   r]   r^   rs     s     r  r   {}->{}r   )0sympy.tensor.array.expressions.array_expressionsr   ri   r	  
isinstancerg   ra   r  rW   r   shaper  rf   r  r  re   sorted)
r\   ri   r   r   r	  elemsZranksr  r  r  r]   r[   r^   _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 r]   rV   r  r[   r]   r^   rs     s     z5ArrayPrinter._print_ArrayDiagonal.<locals>.<listcomp>r  r   r"  r   rT   )r#  r   listdiagonal_indicesr$  ri   r  ra   r  rf   r  r  re   rg   )	r\   ri   r   r*  r  r'  Zdiagonal_stringr  r  r]   r[   r^   _print_ArrayDiagonal  s    

z!ArrayPrinter._print_ArrayDiagonalc                 C   s2   d|  | jd | j | |j| |jjf S )Nr   r   )rf   r  Z
_transposerW   ri   ZpermutationZ
array_formr   r]   r]   r^   _print_PermuteDims  s
    
zArrayPrinter._print_PermuteDimsc                 C   s   |  | jd | j |jS )Nr   )r   r  _addra   r   r]   r]   r^   _print_ArrayAdd  s    zArrayPrinter._print_ArrayAddc                 C   s.   d|  | jd | j dt| j|jf S Nz	%s((%s,))r   r  )rf   r  Z_onesrg   maprW   ra   r   r]   r]   r^   _print_OneArray  s    zArrayPrinter._print_OneArrayc                 C   s.   d|  | jd | j dt| j|jf S r/  )rf   r  Z_zerosrg   r0  rW   ra   r   r]   r]   r^   _print_ZeroArray  s    zArrayPrinter._print_ZeroArrayc                 C   s0   |  | |j}|  | |j}d||f S r   )rW   r  r   r   )r\   ri   r   r   r]   r]   r^   _print_Assignment  s    zArrayPrinter._print_Assignmentc                 C   s
   |  |S rU   )Z_print_ArraySymbolr   r]   r]   r^   _print_IndexedBase  s    zArrayPrinter._print_IndexedBaseN)rd   r   r   r  r  r  r  r(  r+  r,  r.  r1  r2  r3  r4  r]   r]   r]   r^   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   )frK   re   rf   rW   ra   r\   rK   r]   r]   r^   _print_sign  s     zPythonCodePrinter._print_signc                 C   s$   t |}| jd | |jd | S )Nr   r   )r   r   r   ra   )r\   ri   r   r]   r]   r^   
_print_Not  s    zPythonCodePrinter._print_Notc                    s<   |j d }|j dd  }dt|d fdd|D S )Nr   r   z{}[{}]rT   c                    s   g | ]}  |qS r]   rV   )rY   indr[   r]   r^   rs   &  s     z4PythonCodePrinter._print_Indexed.<locals>.<listcomp>)ra   re   r   rg   )r\   ri   r   indexr]   r[   r^   _print_Indexed#  s    
z PythonCodePrinter._print_IndexedFc                 C   s   | j ||dS )N)r   r   r\   ri   r   r]   r]   r^   
_print_Pow(  s    zPythonCodePrinter._print_Powc                 C   s   d |j|jS )Nz{}/{})re   pqr   r]   r]   r^   _print_Rational+  s    z!PythonCodePrinter._print_Rationalc                 C   s
   |  |S rU   rC  r   r]   r]   r^   _print_Half.  s    zPythonCodePrinter._print_Halfc                 C   s   |  t|jd dS )Nr   r   )r   r   ra   r   r]   r]   r^   _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   re   replace)r\   ri   r`   msgr   r]   r^   rI  4  s    

zPythonCodePrinter._print_Symbol)F)rd   r   r   r9  r:  r=  r@  rC  rE  rF  rI  r   Z_print_not_supported_print_lowergamma_print_uppergammaZ_print_fresnelcZ_print_fresnelsr   r]   r]   r   r^   r5    s   
r5  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'

    )r5  Zdoprint)ri   r   r]   r]   r^   pycodeP  s    rN  z
log1p log2c                 C   s    g | ]\}}|t kr||fqS r]   )_not_in_mpmathrp   r]   r]   r^   rs   k  s      rs   betafracfresnelcfresnelssignrI   hypermeijergbesseljbesselybesselibesselk)rP  rQ  rR  rS  rT  rI   rU  rV  rW  rX  rY  rZ  phiZeulercatalanZninf)rO   rP   ZGoldenRatioZ
EulerGammaZCatalanrS   rR   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_limitr]   r]   r^   _unpack_integral_limits  s    

ra  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.r]   rp   r]   r]   r^   rs     s     zMpmathPrinter.<listcomp>c                 C   s   i | ]\}}|d | qS rc  r]   rp   r]   r]   r^   rt     s      zMpmathPrinter.<dictcomp>c                 C   s(   t ttt|j}dj| d|dS )Nz{func}({args})
mpmath.mpf)r   ra   )r   tupler0  intZ_mpf_re   rf   )r\   rK   ra   r]   r]   r^   _print_Float  s    zMpmathPrinter._print_Floatc                 C   s&   dj | d| |j| |jdS )Nz{func}({p})/{func}({q})rd  )r   rB  rA  )re   rf   rW   rB  rA  r8  r]   r]   r^   rC    s
    

zMpmathPrinter._print_Rationalc                 C   s
   |  |S rU   rD  r8  r]   r]   r^   rE    s    zMpmathPrinter._print_Halfc                 C   s4   d | d| |jd | |jd | dS )Nz{}({}, {}, {})mpmath.gammaincr   r   z
mpmath.infr7  r8  r]   r]   r^   rM    s    zMpmathPrinter._print_uppergammac                 C   s,   d | d| |jd | |jd S )Nz{}({}, 0, {})rh  r   r   r7  r8  r]   r]   r^   rL    s
    zMpmathPrinter._print_lowergammac                 C   s   d | d| |jd S )Nz{0}({1})/{0}(2)z
mpmath.logr   r7  r8  r]   r]   r^   _print_log2  s     zMpmathPrinter._print_log2c                 C   s   d | d| |jd S )Nz{}({})zmpmath.log1pr   r7  r8  r]   r]   r^   _print_log1p  s     zMpmathPrinter._print_log1pFc                 C   s   | j ||ddS )Nzmpmath.sqrtr   rF   r>  r?  r]   r]   r^   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.quadrT   r   c                 3   s"   | ]}d t t j| V  qdS )z(%s, %s)N)re  r0  rW   )rY   r  r[   r]   r^   r_     s     z0MpmathPrinter._print_Integral.<locals>.<genexpr>)ra  re   rf   rg   r0  rW   ra   )r\   rK   r`  r   r]   r[   r^   _print_Integral  s    zMpmathPrinter._print_IntegralN)F)rd   r   r   __doc__r   r   r   r   r   r   _known_functions_mpmathr   _known_constants_mpmathr   rg  rC  rE  rM  rL  ri  rj  r@  rl  r]   r]   r]   r^   rb    s"   

rb  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   rT   c                 3   s   | ]}  |V  qd S rU   rV   rX   r[   r]   r^   r_     s     z/SymPyPrinter._print_Function.<locals>.<genexpr>)r   r   rf   rd   rg   ra   )r\   ri   modr]   r[   r^   _print_Function  s    zSymPyPrinter._print_FunctionFc                 C   s   | j ||ddS )Nz
sympy.sqrtrk  r>  r?  r]   r]   r^   r@    s    zSymPyPrinter._print_PowN)F)rd   r   r   r   rr  r@  r]   r]   r]   r^   rp    s   rp  N)#rm  collectionsr   	itertoolsr   Z
sympy.corer   Zsympy.core.modr   r   Zcodeprinterr   r   r   r   r   rj   rl   rm   r   r5  r   rq   setattrrN  r   rO  r   Z
_in_mpmathr   rn  ro  ra  rb  rp  r]   r]   r]   r^   <module>   s                                !	  F 	0
D
