o
    Rhi                     @   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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,d-Zd.d/d.d0d1d1d2Zd3d4 Zd5d6 ZG d7d8 d8eZG d9d: d: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dlmZ dd@lmZ dd*d$dd(d+ddddd)d,ddddAZd/d.d0dBdCZG dDdE dEeZejD ]Zeed=e ej qeD ]Zeed=e ej qdF ZdGdH e D Z e!e fi dIdJdKdLdMdNdOdPdQdRdSdTdUZ"d.d/dVdWdXd1d0dYdZZ#d[d\ Z$G d]d^ d^eZ%e%jD ]Zee%d=e e qCe#D ]Zee%d=e e qQG d_d` d`eZ&daS )bzy
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isinfisnanlgammaloglog10log1plog2sinsinhsqrttantanh)rB   rC   rD   loggammarF   lnrG   rH   rI   rJ   rK   SqrtrM   rN   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 W/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/sympy/printing/pycode.py	<genexpr>G       z$_print_known_func.<locals>.<genexpr>)nameargs)known_functions	__class____name__format_module_formatjoinrk   re   exprknownrf   rd   rg   _print_known_funcD   s   ru   c                 C   s   | j |jj }| |S r^   )known_constantsrm   rn   rp   rr   rf   rf   rg   _print_known_constJ   s   
rw   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.rf   rb   kvrf   rf   rg   
<listcomp>W       z$AbstractPythonCodePrinter.<listcomp>c                 C      i | ]	\}}|d | qS r|   rf   r}   rf   rf   rg   
<dictcomp>Y       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sysro   version_infomajor
ValueErrorr   r   setmodule_importsdict_kfgetrl   _kcrv   )re   settingsstdr   rm   rf   rg   r   e   s   


z"AbstractPythonCodePrinter.__init__c                 C   s   d||f S Nz%s = %srf   )re   rj   valuerf   rf   rg   _declare_number_consty   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   rq   addr   )re   fqnregisterpartsrf   rf   rg   rp   |   s   
"
"z(AbstractPythonCodePrinter._module_formatc                 C   s   |S r^   rf   )re   linesrf   rf   rg   _format_code      z&AbstractPythonCodePrinter._format_codec                 C   
   d |S )Nz{}ro   re   
codestringrf   rf   rg   _get_statement      
z(AbstractPythonCodePrinter._get_statementc                 C   r   )Nz  # {}r   )re   textrf   rf   rg   _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`   rp   _expand_fold_binary_op)re   oprk   rf   rf   rg   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 reduction 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`   rp   _expand_reduce_binary_op)re   r   rk   NNhalfrf   rf   rg   r      s   z2AbstractPythonCodePrinter._expand_reduce_binary_opc                 C      dS )Nzfloat('nan')rf   re   rs   rf   rf   rg   
_print_NaN   r   z$AbstractPythonCodePrinter._print_NaNc                 C   r   )Nzfloat('inf')rf   r   rf   rf   rg   _print_Infinity   r   z)AbstractPythonCodePrinter._print_Infinityc                 C   r   )Nzfloat('-inf')rf   r   rf   rf   rg   _print_NegativeInfinity   r   z1AbstractPythonCodePrinter._print_NegativeInfinityc                 C   
   |  |S r^   )r   r   rf   rf   rg   _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)rb   xPRECre   rf   rg   rh      s    z7AbstractPythonCodePrinter._print_Mod.<locals>.<genexpr>)r   ro   rk   r   rf   r   rg   
_print_Mod   s   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) )rk   rs   condappendr`   rq   )re   rs   resultirc   rR   crf   rf   rg   _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   ro   r   _print_Relational)re   rs   r   r   r   r   rf   rg   r      s   
z+AbstractPythonCodePrinter._print_Relationalc                 C   s   ddl m} | ||S )Nr   )	Piecewise)$sympy.functions.elementary.piecewiser   r`   rewrite)re   rs   r   rf   rf   rg   
_print_ITE   s   z$AbstractPythonCodePrinter._print_ITEc                    s:    fdd|j d d d 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)ro   r`   )rb   r   r   r   rd   rf   rg   rh      s    
z7AbstractPythonCodePrinter._print_Sum.<locals>.<genexpr>r   z"(builtins.sum({function} {loops})) )functionloops)limitsro   r`   r   rq   )re   rs   r   rf   rd   rg   
_print_Sum   s   

z$AbstractPythonCodePrinter._print_Sumc                 C   r   )N1jrf   r   rf   rf   rg   _print_ImaginaryUnit  r   z.AbstractPythonCodePrinter._print_ImaginaryUnitc                 C   s$   |j \}}dj| || |dS )Nz(1 if {a} == {b} else 0))r   r   )rk   ro   r`   )re   rs   r   r   rf   rf   rg   _print_KroneckerDelta  s
   
z/AbstractPythonCodePrinter._print_KroneckerDeltac                 C   s,   |j j}| j||}d|| | f S )N%s(%s))rm   rn   rl   r   r`   tolist)re   rs   rj   funcrf   rf   rg   _print_MatrixBase  s   z+AbstractPythonCodePrinter._print_MatrixBasec                 C   r   r^   )r   r   rf   rf   rg   <lambda>  s   
 z"AbstractPythonCodePrinter.<lambda>c                    s   d  fdd|dD S )N
c                    s   g | ]} j | qS rf   )tab)rb   linerd   rf   rg   r          z@AbstractPythonCodePrinter._indent_codestring.<locals>.<listcomp>)rq   r   r   rf   rd   rg   _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_   ra   rd   rf   rg   rh   #  ri   zFAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<genexpr>z def {name}({parameters}):
{body}r\   c                    s   g | ]}  |jqS rf   )r`   symbol)rb   varrd   rf   rg   r   &  s    zGAbstractPythonCodePrinter._print_FunctionDefinition.<locals>.<listcomp>)rj   
parametersbody)rq   r   ro   r`   rj   r   r   )re   fdr   rf   rd   rg   _print_FunctionDefinition"  s   
z3AbstractPythonCodePrinter._print_FunctionDefinitionc                    s6   d  fdd|jD }dj |j |dS )Nr   c                 3   r]   r^   r_   ra   rd   rf   rg   rh   +  ri   z9AbstractPythonCodePrinter._print_While.<locals>.<genexpr>zwhile {cond}:
{body})r   r   )rq   r   ro   r`   	conditionr   )re   whlr   rf   rd   rg   _print_While*  s
   
z&AbstractPythonCodePrinter._print_Whilec                 C   s    d|  |jj|  |jjf S r   )r`   variabler   r   )re   declrf   rf   rg   _print_Declaration1  s   z,AbstractPythonCodePrinter._print_Declarationc                 C   r   )Nr   rf   )re   btrf   rf   rg   _print_BreakToken7  r   z+AbstractPythonCodePrinter._print_BreakTokenc                 C      |j \}d| | S )Nz	return %srk   r`   )re   retrc   rf   rf   rg   _print_Return:     z'AbstractPythonCodePrinter._print_Returnc                 C   r  )Nzraise %sr  )re   rsrc   rf   rf   rg   _print_Raise>  r  z&AbstractPythonCodePrinter._print_Raisec                 C   r  )NzRuntimeError(%s)r  )re   remessagerf   rf   rg   _print_RuntimeError_B  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_   ra   rd   rf   rg   rh   G  ri   z9AbstractPythonCodePrinter._print_Print.<locals>.<genexpr>r   )nonez{} % ({}), end=""z	, file=%sz	print(%s))rq   
print_argssympy.codegen.astr  format_stringro   r`   file)re   prntr  r  rf   rd   rg   _print_PrintF  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)strrj   rp   r`   )re   strmrf   rf   rg   _print_StreamR  s
   

z'AbstractPythonCodePrinter._print_Streamc                 C   r   )Nr   rf   )re   rc   rf   rf   rg   _print_NoneTokenZ  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   rc   /r   r   Fstrictz{}**{})r   r=   r   Halfrp   r`   basero   is_commutativeOneNegativeOner   )
re   rs   rationalrL   r   r   rc   numbase_strexp_strrf   rf   rg   _hprint_Pow]  s$   +


z%AbstractPythonCodePrinter._hprint_Powr^   )T)Fr  )=rn   
__module____qualname__printmethodlanguage_kwreserved_wordsmodulesr   r   r   _known_functionsitems_known_functions_mathr   _known_constants_mathr   
_operatorsr   _default_settingsr   r   rp   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__rf   rf   r   rg   rx   O   s    


rx   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)re   indexedr@  rf   rf   rg   	_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 rf   )r+   )rb   r   jrf   rf   rg   r          z3ArrayPrinter._get_einsum_string.<locals>.<dictcomp>r   ,r   ) _get_letter_generator_for_einsumranger   next)re   subrankscontraction_indicesletterscontraction_stringcounterdindicesrank_arglindicesr   mappingletters_freeletters_dumrE  lrf   rf   rg   _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   )re   r   rf   rf   rg   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 rf   )rJ  )rb   rE  rM  rf   rg   r     s    zEArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>.<listcomp>)rq   rI  rb   r   r^  rf   rg   r     s   ( z:ArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>%s("%s", %s)r   r\   c                       g | ]}  |qS rf   r_   ra   rd   rf   rg   r     r   )rH  rq   rK  rp   _module_einsumrk   )re   rs   rN  rf   )rM  re   rg   _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_   ra   rd   rf   rg   r     r   z8ArrayPrinter._print_ArrayContraction.<locals>.<listcomp>c                    rg  rh  r_   ra   rd   rf   rg   r     r   r`  r   {}->{}r   )0sympy.tensor.array.expressions.array_expressionsrf  rs   rL  
isinstancerq   rk   rK  r`   r   shaperX  rp   rb  rc  ro   sorted)
re   rs   rf  r   rL  elemsranksrN  rU  rV  rf   rd   rg   _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  rf   r_   r_  rd   rf   rg   r      r   z5ArrayPrinter._print_ArrayDiagonal.<locals>.<listcomp>r`  r   ri  r   r\   )rj  rf  listdiagonal_indicesrk  rs   rK  rk   rX  rp   rb  rc  ro   rq   )	re   rs   rf  rr  rK  rn  diagonal_stringrU  rV  rf   rd   rg   _print_ArrayDiagonal  s   

z!ArrayPrinter._print_ArrayDiagonalc                 C   s2   d|  | jd | j | |j| |jjf S )Nr   r   )rp   rb  
_transposer`   rs   permutation
array_formr   rf   rf   rg   _print_PermuteDims  s
   
zArrayPrinter._print_PermuteDimsc                 C   s   |  | jd | j |jS )Nr   )r   rb  _addrk   r   rf   rf   rg   _print_ArrayAdd     zArrayPrinter._print_ArrayAddc                 C   .   d|  | jd | j dt| j|jf S Nz	%s((%s,))r   rG  )rp   rb  _onesrq   mapr`   rk   r   rf   rf   rg   _print_OneArray     zArrayPrinter._print_OneArrayc                 C   r|  r}  )rp   rb  _zerosrq   r  r`   rk   r   rf   rf   rg   _print_ZeroArray  r  zArrayPrinter._print_ZeroArrayc                 C   s0   |  | |j}|  | |j}d||f S r   )r`   rD  r   r   )re   rs   r   r   rf   rf   rg   _print_Assignment  s   zArrayPrinter._print_Assignmentc                 C   r   r^   )_print_ArraySymbolr   rf   rf   rg   _print_IndexedBase$  r   zArrayPrinter._print_IndexedBaseN)rn   r)  r*  rD  rX  rH  rd  rp  rt  rx  rz  r  r  r  r  rf   rf   rf   rg   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   )frR   ro   rp   r`   rk   re   rR   rf   rf   rg   _print_sign*  s   zPythonCodePrinter._print_signc                 C   s(   t |}| jd d | |jd | S )Nr   r   r   )r   r4  r   rk   )re   rs   r   rf   rf   rg   
_print_Not.  s    zPythonCodePrinter._print_Notc                 C   s   |j S r^   )rj   r   rf   rf   rg   r  2  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  rf   r_   )rb   indrd   rf   rg   r   8  r   z4PythonCodePrinter._print_Indexed.<locals>.<listcomp>)rk   ro   r  rq   )re   rs   r   indexrf   rd   rg   _print_Indexed5  s   
$z PythonCodePrinter._print_IndexedFc                 C   s   | j ||dS )N)r$  r(  re   rs   r$  rf   rf   rg   
_print_Pow:     zPythonCodePrinter._print_Powc                 C   s   d |j|jS )Nz{}/{})ro   pqr   rf   rf   rg   _print_Rational=     z!PythonCodePrinter._print_Rationalc                 C   r   r^   r  r   rf   rf   rg   _print_Half@  r   zPythonCodePrinter._print_Halfc                 C   s   |  t|jd dS )Nr   r   )r   r   rk   r   rf   rf   rg   _print_fracC  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   ro   replace)re   rs   rj   msgr   rf   rg   r  F  s   

zPythonCodePrinter._print_SymbolF)rn   r)  r*  r  r  r  r  r  r  r  r  r  r   _print_not_supported_print_lowergamma_print_uppergamma_print_fresnelc_print_fresnelsr>  rf   rf   r   rg   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)rs   r   rf   rf   rg   pycodeb  s   r  )r  )r=   rL   rF   r9   rJ   rM   r0   r2   r4   r:   rK   rN   r1   r3   r6   z-inf)rW   rX   rY   NegativeInfinityc                       st   e Zd ZdZdZdZeee	 Z
dd e	 D ZdddZd	d
 Z fddZdd Zdd Zdd Z  ZS )CmathPrinterz# Printer for Python's cmath module 
_cmathcodezPython with cmathc                 C   r   )cmath.rf   r}   rf   rf   rg   r     r   zCmathPrinter.<dictcomp>Fc                 C      | j ||ddS )Nz
cmath.sqrtr$  rL   r  r  rf   rf   rg   r    r  zCmathPrinter._print_Powc                 C   s   dj | d| |dS )Nz{func}({val})z	cmath.mpf)r   valro   rp   r`   r  rf   rf   rg   _print_Float  r{  zCmathPrinter._print_Floatc                    sF   |j j}|| jv rd| j|  ddt| j|j dS t |S )Nr  r   r\   r   )	r   rn   r   rq   r  r`   rk   r   _print_Function)re   rs   	func_namer   rf   rg   ru     s   
(zCmathPrinter._print_known_funcc                 C   s   | j |jj S r^   )r   rm   rn   r   rf   rf   rg   rw     r  zCmathPrinter._print_known_constc                 C      d|  |jd  dS )zPrints `re(z)` as `z.real`r   r   z).realr`   rk   r   rf   rf   rg   	_print_re     zCmathPrinter._print_rec                 C   r  )zPrints `im(z)` as `z.imag`r   r   z).imagr  r   rf   rf   rg   	_print_im  r  zCmathPrinter._print_imr  )rn   r)  r*  __doc__r+  r,  r   r   _known_functions_cmathr1  r   _known_constants_cmathr   r  r  ru   rw   r  r  r>  rf   rf   r   rg   r    s    
r  z
log1p log2c                 C   s    g | ]\}}|t vr||fqS rf   )_not_in_mpmathr}   rf   rf   rg   r     rF  r   betafracfresnelcfresnelssignrO   hypermeijergbesseljbesselybesselibesselk)r  r  r  r  r  rO   r  r  r  r  r  r  phieulercatalanninf)rV   rW   GoldenRatio
EulerGammaCatalanrZ   rY   r  c                 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_limitrf   rf   rg   _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d ZdS )MpmathPrinterzH
    Lambda printer for mpmath which maintains precision for floats
    _mpmathcodezPython with mpmathc                 C   r{   zmpmath.rf   r}   rf   rf   rg   r     r   zMpmathPrinter.<listcomp>c                 C   r   r  rf   r}   rf   rf   rg   r     r   zMpmathPrinter.<dictcomp>c                 C   s(   t ttt|j}dj| d|dS )Nz{func}({args})
mpmath.mpf)r   rk   )r  tupler  int_mpf_ro   rp   )re   rR   rk   rf   rf   rg   r    s   zMpmathPrinter._print_Floatc                 C   s&   dj | d| |j| |jdS )Nz{func}({p})/{func}({q})r  )r   r  r  )ro   rp   r`   r  r  r  rf   rf   rg   r  	  s
   

zMpmathPrinter._print_Rationalc                 C   r   r^   r  r  rf   rf   rg   r    r   zMpmathPrinter._print_Halfc                 C   s4   d | d| |jd | |jd | dS )Nz{}({}, {}, {})mpmath.gammaincr   r   z
mpmath.infr  r  rf   rf   rg   r    s   zMpmathPrinter._print_uppergammac                 C   s,   d | d| |jd | |jd S )Nz{}({}, 0, {})r  r   r   r  r  rf   rf   rg   r    s
   zMpmathPrinter._print_lowergammac                 C      d | d| |jd S )Nz{0}({1})/{0}(2)z
mpmath.logr   r  r  rf   rf   rg   _print_log2      zMpmathPrinter._print_log2c                 C   r  )Nz{}({})zmpmath.log1pr   r  r  rf   rf   rg   _print_log1p$  r  zMpmathPrinter._print_log1pFc                 C   r  )Nzmpmath.sqrtr  r  r  rf   rf   rg   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`   )rb   rW  rd   rf   rg   rh   2  s   " z0MpmathPrinter._print_Integral.<locals>.<genexpr>)r  ro   rp   rq   r  r`   rk   )re   rR   r  r   rf   rd   rg   _print_Integral+  s   zMpmathPrinter._print_Integralc                 C   s&   |\}|\}d | d| ||S )Nz{}({}, derivative={})zmpmath.zetar  )re   rk   
seq_ordersrc   deriv_orderrf   rf   rg   _print_Derivative_zeta5  s   
z$MpmathPrinter._print_Derivative_zetaNr  )rn   r)  r*  r  r+  r,  r   r   r0  r1  _known_functions_mpmathr   _known_constants_mpmathr   r  r  r  r  r  r  r  r  r  r  rf   rf   rf   rg   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_   ra   rd   rf   rg   rh   Q  ri   z/SymPyPrinter._print_Function.<locals>.<genexpr>)r   r)  rp   rn   rq   rk   )re   rs   modrf   rd   rg   r  N  s   zSymPyPrinter._print_Functionc                 C   r  )Nz
sympy.sqrtr  r  r  rf   rf   rg   r  S  r  zSymPyPrinter._print_PowNr  )	rn   r)  r*  r,  r   rx   r5  r  r  rf   rf   rf   rg   r  E  s    r  N)'r  collectionsr   	itertoolsr   
sympy.corer   sympy.core.modr   r   codeprinterr   r-  r0  r2  r3  ru   rw   rx   r?  r  r   r~   setattrr  sympy.printing.pycoder  r  r  r   r  r1  
_in_mpmathr   r  r  r  r  r  rf   rf   rf   rg   <module>   s   	
#	  S 	
3
#

M