o
    oh.a                     @   s6  d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m	Z	 ddl
mZ h d	Zd
dddZi ddddddddddddddddddddddddddddddddddd d!d"d#d#d$d%d&d'd(d)d*d+d,Zd-d.d-d/d0d0d1Zd2d3 Zd4d5 ZG d6d7 d7eZG d8d9 d9ZG d:d; 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@dA e D Zeefi dBdCdDdEdFdGdHdIdJdKdLdMdNZd-d.dOdPdQd0d/dRdSZdTdU Z G dVdW dWeZ!e!jD ]
Zee!d<e e qeD ]Zee!d<e e qG dXdY dYeZ"dZS )[zy
Python code printers

This module contains Python code printers for plain Python as well as NumPy & SciPy enabled code.
    )defaultdict)chain)S)Mod   )
precedence)CodePrinter>!   asifinisoranddefdelfornottryNoneTrueelifelsefrompasswithFalsebreakclassraisewhileyieldassertexceptglobalimportlambdareturnfinallycontinuenonlocalabsminmax)AbsMinMaxacosacoshasinasinhatanatan2atanhceilingceilcoscosherferfcexpexpm1	factorialfloorgammahypotisnanlgammaloglog10log1plog2sinsinhsqrttantanh)rB   rC   loggammarE   lnrF   rG   rH   rI   rJ   SqrtrL   rM   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       | ]}  |V  qd S N_print.0argself i/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/printing/pycode.py	<genexpr>F       z$_print_known_func.<locals>.<genexpr>)nameargs)known_functions	__class____name__format_module_formatjoinrj   rd   exprknownre   rc   rf   _print_known_funcC   s   rt   c                 C   s   | j |jj }| |S r]   )known_constantsrl   rm   ro   rq   re   re   rf   _print_known_constI   s   
rv   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dU fdd	Zdd ZdVd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 Z7dLdM Z8dNdO Z9dPdQ Z:dWdSdTZ;  Z<S )XAbstractPythonCodePrinter_pythoncodePythonNz    c                 C      g | ]
\}}|d | fqS zmath.re   ra   kvre   re   rf   
<listcomp>V       z$AbstractPythonCodePrinter.<listcomp>c                 C      i | ]	\}}|d | qS r{   re   r|   re   re   rf   
<dictcomp>X       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sysrn   version_infomajor
ValueErrorr   r   setmodule_importsdict_kfgetrk   _kcru   )rd   settingsstdr   rl   re   rf   r   d   s   


z"AbstractPythonCodePrinter.__init__c                 C   s   d||f S Nz%s = %sre   )rd   ri   valuere   re   rf   _declare_number_constx   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   rp   addr   )rd   fqnregisterpartsre   re   rf   ro   {   s   
"
"z(AbstractPythonCodePrinter._module_formatc                 C   s   |S r]   re   )rd   linesre   re   rf   _format_code      z&AbstractPythonCodePrinter._format_codec                 C   
   d |S )Nz{}rn   rd   
codestringre   re   rf   _get_statement      
z(AbstractPythonCodePrinter._get_statementc                 C   r   )Nz  # {}r   )rd   textre   re   rf   _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_   ro   _expand_fold_binary_op)rd   oprj   re   re   rf   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_   ro   _expand_reduce_binary_op)rd   r   rj   NNhalfre   re   rf   r      s   z2AbstractPythonCodePrinter._expand_reduce_binary_opc                 C      dS )Nzfloat('nan')re   rd   rr   re   re   rf   
_print_NaN   r   z$AbstractPythonCodePrinter._print_NaNc                 C   r   )Nzfloat('inf')re   r   re   re   rf   _print_Infinity   r   z)AbstractPythonCodePrinter._print_Infinityc                 C   r   )Nzfloat('-inf')re   r   re   re   rf   _print_NegativeInfinity   r   z1AbstractPythonCodePrinter._print_NegativeInfinityc                 C   
   |  |S r]   )r   r   re   re   rf   _print_ComplexInfinity   r   z0AbstractPythonCodePrinter._print_ComplexInfinityc                    s$   t | dj fdd|jD  S )Nz{} % {}c                 3   s    | ]	} | V  qd S r]   )parenthesize)ra   xPRECrd   re   rf   rg      s    z7AbstractPythonCodePrinter._print_Mod.<locals>.<genexpr>)r   rn   rj   r   re   r   rf   
_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) )rj   rr   condappendr_   rp   )rd   rr   resultirb   rQ   cre   re   rf   _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   rn   r   _print_Relational)rd   rr   r   r   r   r   re   rf   r      s   
z+AbstractPythonCodePrinter._print_Relationalc                 C   s   ddl m} | ||S )Nr   )	Piecewise)$sympy.functions.elementary.piecewiser   r_   rewrite)rd   rr   r   re   re   rf   
_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)rn   r_   )ra   r   r   r   rc   re   rf   rg      s    
z7AbstractPythonCodePrinter._print_Sum.<locals>.<genexpr>z"(builtins.sum({function} {loops})) )functionloops)limitsrn   r_   r   rp   )rd   rr   r   re   rc   rf   
_print_Sum   s   

z$AbstractPythonCodePrinter._print_Sumc                 C   r   )N1jre   r   re   re   rf   _print_ImaginaryUnit  r   z.AbstractPythonCodePrinter._print_ImaginaryUnitc                 C   s$   |j \}}dj| || |dS )Nz(1 if {a} == {b} else 0))r   r   )rj   rn   r_   )rd   rr   r   r   re   re   rf   _print_KroneckerDelta  s
   
z/AbstractPythonCodePrinter._print_KroneckerDeltac                 C   s,   |j j}| j||}d|| | f S )N%s(%s))rl   rm   rk   r   r_   tolist)rd   rr   ri   funcre   re   rf   _print_MatrixBase  s   z+AbstractPythonCodePrinter._print_MatrixBasec                 C   r   r]   )r   r   re   re   rf   <lambda>  s   
 z"AbstractPythonCodePrinter.<lambda>c                    s   d  fdd|dD S )N
c                    s   g | ]} j | qS re   )tab)ra   linerc   re   rf   r         z@AbstractPythonCodePrinter._indent_codestring.<locals>.<listcomp>)rp   r   r   re   rc   rf   _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   r\   r]   r^   r`   rc   re   rf   rg   "  rh   zFAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<genexpr>z def {name}({parameters}):
{body}r[   c                    s   g | ]}  |jqS re   )r_   symbol)ra   varrc   re   rf   r   %  s    zGAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<listcomp>)ri   
parametersbody)rp   r   rn   r_   ri   r   r   )rd   fdr   re   rc   rf   _print_FunctionDefinition!  s   
z3AbstractPythonCodePrinter._print_FunctionDefinitionc                    s6   d  fdd|jD }dj |j |dS )Nr   c                 3   r\   r]   r^   r`   rc   re   rf   rg   *  rh   z9AbstractPythonCodePrinter._print_While.<locals>.<genexpr>zwhile {cond}:
{body})r   r   )rp   r   rn   r_   	conditionr   )rd   whlr   re   rc   rf   _print_While)  s
   
z&AbstractPythonCodePrinter._print_Whilec                 C   s    d|  |jj|  |jjf S r   )r_   variabler   r   )rd   declre   re   rf   _print_Declaration0  s   z,AbstractPythonCodePrinter._print_Declarationc                 C   r   )Nr   re   )rd   btre   re   rf   _print_BreakToken6  r   z+AbstractPythonCodePrinter._print_BreakTokenc                 C      |j \}d| | S )Nz	return %srj   r_   )rd   retrb   re   re   rf   _print_Return9     z'AbstractPythonCodePrinter._print_Returnc                 C   r  )Nzraise %sr  )rd   rsrb   re   re   rf   _print_Raise=  r  z&AbstractPythonCodePrinter._print_Raisec                 C   r  )NzRuntimeError(%s)r  )rd   remessagere   re   rf   _print_RuntimeError_A  r  z.AbstractPythonCodePrinter._print_RuntimeError_c                    sj   d  fdd|jD }ddlm} |j|kr"d |j|}|jd kr1|d |j 7 }d| S )	Nr[   c                 3   r\   r]   r^   r`   rc   re   rf   rg   F  rh   z9AbstractPythonCodePrinter._print_Print.<locals>.<genexpr>r   )nonez{} % ({}), end=""z	, file=%sz	print(%s))rp   
print_argssympy.codegen.astr  format_stringrn   r_   file)rd   prntr  r  re   rc   rf   _print_PrintE  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)strri   ro   r_   )rd   strmre   re   rf   _print_StreamQ  s
   

z'AbstractPythonCodePrinter._print_Streamc                 C   r   )Nr   re   )rd   rb   re   re   rf   _print_NoneTokenY  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   rb   /r   r   Fstrictz{}**{})r   r=   r   Halfro   r_   basern   is_commutativeOneNegativeOner   )
rd   rr   rationalrK   r   r   rb   numbase_strexp_strre   re   rf   _hprint_Pow\  s$   +


z%AbstractPythonCodePrinter._hprint_Powr]   )T)Fr  )=rm   
__module____qualname__printmethodlanguage_kwreserved_wordsmodulesr   r   r   _known_functionsitems_known_functions_mathr   _known_constants_mathr   
_operatorsr   _default_settingsr   r   ro   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  r  r  r(  __classcell__re   re   r   rf   rw   N   s    


rw   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.from_indexed_to_arrayr@  	Exception)rd   indexedr@  re   re   rf   	_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 re   )r+   )ra   r   jre   re   rf   r          z3ArrayPrinter._get_einsum_string.<locals>.<dictcomp>r   ,r   ) _get_letter_generator_for_einsumranger   next)rd   subrankscontraction_indicesletterscontraction_stringcounterdindicesrank_arglindicesr   mappingletters_freeletters_dumrE  lre   re   rf   _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)rI  chrr   )rd   r   re   re   rf   rH    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 )NrG  c                    s(   g | ]}d   fddt|D qS )r   c                    s   g | ]}t  qS re   )rJ  )ra   rE  rM  re   rf   r     s    zEArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>.<listcomp>)rp   rI  ra   r   r^  re   rf   r     s   ( z:ArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>%s("%s", %s)r   r[   c                       g | ]}  |qS re   r^   r`   rc   re   rf   r     r   )rH  rp   rK  ro   _module_einsumrj   )rd   rr   rN  re   )rM  rd   rf   _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   ArrayTensorProductrG  c                       g | ]	}d   | qS z%sr^   r`   rc   re   rf   r     r   z8ArrayPrinter._print_ArrayContraction.<locals>.<listcomp>c                    rg  rh  r^   r`   rc   re   rf   r     r   r`  r   {}->{}r   )0sympy.tensor.array.expressions.array_expressionsrf  rr   rL  
isinstancerp   rj   rK  r_   r   shaperX  ro   rb  rc  rn   sorted)
rd   rr   rf  r   rL  elemsranksrN  rU  rV  re   rc   rf   _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   re  c                    ra  re   r^   r_  rc   re   rf   r     r   z5ArrayPrinter._print_ArrayDiagonal.<locals>.<listcomp>r`  r   ri  r   r[   )rj  rf  listdiagonal_indicesrk  rr   rK  rj   rX  ro   rb  rc  rn   rp   )	rd   rr   rf  rr  rK  rn  diagonal_stringrU  rV  re   rc   rf   _print_ArrayDiagonal  s   

z!ArrayPrinter._print_ArrayDiagonalc                 C   s2   d|  | jd | j | |j| |jjf S )Nr   r   )ro   rb  
_transposer_   rr   permutation
array_formr   re   re   rf   _print_PermuteDims  s
   
zArrayPrinter._print_PermuteDimsc                 C   s   |  | jd | j |jS )Nr   )r   rb  _addrj   r   re   re   rf   _print_ArrayAdd  s   zArrayPrinter._print_ArrayAddc                 C   .   d|  | jd | j dt| j|jf S Nz	%s((%s,))r   rG  )ro   rb  _onesrp   mapr_   rj   r   re   re   rf   _print_OneArray     zArrayPrinter._print_OneArrayc                 C   r{  r|  )ro   rb  _zerosrp   r~  r_   rj   r   re   re   rf   _print_ZeroArray  r  zArrayPrinter._print_ZeroArrayc                 C   s0   |  | |j}|  | |j}d||f S r   )r_   rD  r   r   )rd   rr   r   r   re   re   rf   _print_Assignment  s   zArrayPrinter._print_Assignmentc                 C   r   r]   )_print_ArraySymbolr   re   re   rf   _print_IndexedBase#  r   zArrayPrinter._print_IndexedBaseN)rm   r)  r*  rD  rX  rH  rd  rp  rt  rx  rz  r  r  r  r  re   re   re   rf   r?    s    #	r?  c                       sv   e Zd Zd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   )frQ   rn   ro   r_   rj   rd   rQ   re   re   rf   _print_sign)  s   zPythonCodePrinter._print_signc                 C   s$   t |}| jd | |jd | S )Nr   r   )r   r4  r   rj   )rd   rr   r   re   re   rf   
_print_Not-  r   zPythonCodePrinter._print_Notc                 C   s   |j S r]   )ri   r   re   re   rf   r  1  s   z$PythonCodePrinter._print_IndexedBasec                    s<   |j d }|j dd  }dt|d fdd|D S )Nr   r   z{}[{}]r[   c                    ra  re   r^   )ra   indrc   re   rf   r   7  r   z4PythonCodePrinter._print_Indexed.<locals>.<listcomp>)rj   rn   r  rp   )rd   rr   r   indexre   rc   rf   _print_Indexed4  s   
$z PythonCodePrinter._print_IndexedFc                 C   s   | j ||dS )N)r$  r(  rd   rr   r$  re   re   rf   
_print_Pow9  s   zPythonCodePrinter._print_Powc                 C   s   d |j|jS )Nz{}/{})rn   pqr   re   re   rf   _print_Rational<     z!PythonCodePrinter._print_Rationalc                 C   r   r]   r  r   re   re   rf   _print_Half?  r   zPythonCodePrinter._print_Halfc                 C   s   |  t|jd dS )Nr   r   )r   r   rj   r   re   re   rf   _print_fracB  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   rn   replace)rd   rr   ri   msgr   re   rf   r  E  s   

zPythonCodePrinter._print_SymbolF)rm   r)  r*  r  r  r  r  r  r  r  r  r  r   _print_not_supported_print_lowergamma_print_uppergamma_print_fresnelc_print_fresnelsr>  re   re   r   rf   r  '  s    
r  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'

    )r  doprint)rr   r   re   re   rf   pycodea  s   r  z
log1p log2c                 C   s    g | ]\}}|t vr||fqS re   )_not_in_mpmathr|   re   re   rf   r   |  rF  r   betafracfresnelcfresnelssignrN   hypermeijergbesseljbesselybesselibesselk)r  r  r  r  r  rN   r  r  r  r  r  r  phieulercatalanninf)rU   rV   GoldenRatio
EulerGammaCatalanrY   rX   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_limitre   re   rf   _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   rz   zmpmath.re   r|   re   re   rf   r     r   zMpmathPrinter.<listcomp>c                 C   r   r  re   r|   re   re   rf   r     r   zMpmathPrinter.<dictcomp>c                 C   s(   t ttt|j}dj| d|dS )Nz{func}({args})
mpmath.mpf)r   rj   )r  tupler~  int_mpf_rn   ro   )rd   rQ   rj   re   re   rf   _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  )rn   ro   r_   r  r  r  re   re   rf   r    s
   

zMpmathPrinter._print_Rationalc                 C   r   r]   r  r  re   re   rf   r    r   zMpmathPrinter._print_Halfc                 C   s4   d | d| |jd | |jd | dS )Nz{}({}, {}, {})mpmath.gammaincr   r   z
mpmath.infr  r  re   re   rf   r    s   zMpmathPrinter._print_uppergammac                 C   s,   d | d| |jd | |jd S )Nz{}({}, 0, {})r  r   r   r  r  re   re   rf   r    s
   zMpmathPrinter._print_lowergammac                 C      d | d| |jd S )Nz{0}({1})/{0}(2)z
mpmath.logr   r  r  re   re   rf   _print_log2     zMpmathPrinter._print_log2c                 C   r  )Nz{}({})zmpmath.log1pr   r  r  re   re   rf   _print_log1p  r  zMpmathPrinter._print_log1pFc                 C      | j ||ddS )Nzmpmath.sqrtr$  rK   r  r  re   re   rf   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.quadr[   r   c                 3   s$    | ]}d t t j| V  qdS )z(%s, %s)N)r  r~  r_   )ra   rW  rc   re   rf   rg     s   " z0MpmathPrinter._print_Integral.<locals>.<genexpr>)r  rn   ro   rp   r~  r_   rj   )rd   rQ   r  r   re   rc   rf   _print_Integral  s   zMpmathPrinter._print_IntegralNr  )rm   r)  r*  __doc__r+  r,  r   r   r0  r1  _known_functions_mpmathr   _known_constants_mpmathr   r  r  r  r  r  r  r  r  r  re   re   re   rf   r    s$    

r  c                   @   s0   e Zd ZdZeejddZdd Zd	ddZdS )
SymPyPrinterzPython with SymPyFr  c                    sH   |j jpd}d ||rdnd |j j d fdd|jD f S )Nr   r   r   r[   c                 3   r\   r]   r^   r`   rc   re   rf   rg     rh   z/SymPyPrinter._print_Function.<locals>.<genexpr>)r   r)  ro   rm   rp   rj   )rd   rr   modre   rc   rf   _print_Function  s   zSymPyPrinter._print_Functionc                 C   r  )Nz
sympy.sqrtr  r  r  re   re   rf   r    r  zSymPyPrinter._print_PowNr  )	rm   r)  r*  r,  r   rw   r5  r  r  re   re   re   rf   r    s    r  N)#r  collectionsr   	itertoolsr   
sympy.corer   sympy.core.modr   r   codeprinterr   r-  r0  r2  r3  rt   rv   rw   r?  r  r   r}   setattrr  r   r  r1  
_in_mpmathr   r  r  r  r  r  re   re   re   rf   <module>   s    	
"	  S 	
3

D