o
     ôj¨i  ã                   @   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ƒ q¡eD ]
Zeed=e eƒ q®d>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ƒ qíeD ]Zeed=e ejƒ qûdF ¡ 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>!   ÚcontinueÚwhileÚexceptÚglobalÚreturnÚelseÚisÚclassÚandÚelifÚifÚFalseÚasÚwithÚdefÚorÚpassÚraiseÚnonlocalÚyieldÚassertÚimportÚinÚTrueÚforÚdelÚlambdaÚNoneÚtryÚbreakÚfinallyÚnotÚfromÚ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© úh/var/www/html/academy/tools/voices/clone/cosy-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ÚAbstractPythonCodePrinterZ_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†   Z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   Z
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   ÚNZ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¹   )NZ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   Z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_argsZsympy.codegen.astr  Úformat_stringro   r`   Úfile)re   Z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_strZ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ê   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  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)Z4sympy.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ÚindicesZrank_argZlindicesrË   ÚmappingÚletters_freeÚletters_dumr3  Ú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ƒ‚)Néa   é{   éA   é[   zout of letters)r7  Úchrr’   )re   rË   rf   rf   rg   r6  Ì  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 )Nr5  c                    s(   g | ]}d   ‡ fdd„t|ƒD ƒ¡‘qS )rÇ   c                    s   g | ]}t ˆ ƒ‘qS rf   )r8  )rb   r3  ©r;  rf   rg   r   Õ  s    zEArrayPrinter._print_ArrayTensorProduct.<locals>.<listcomp>.<listcomp>)rq   r7  ©rb   rË   rJ  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ï   )r6  rq   r9  rp   Ú_moduleÚ_einsumrk   )re   rs   r<  rf   )r;  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   ©ÚArrayTensorProductr5  c                    ó   g | ]	}d ˆ   |¡ ‘qS ©z%sr_   ra   rd   rf   rg   r   â  rƒ   z8ArrayPrinter._print_ArrayContraction.<locals>.<listcomp>c                    rS  rT  r_   ra   rd   rf   rg   r   í  rƒ   rL  rŸ   ú{}->{}rÇ   )Ú0sympy.tensor.array.expressions.array_expressionsrR  rs   r:  Ú
isinstancerq   rk   r9  r`   r¤   ÚshaperD  rp   rN  rO  ro   Úsorted)
re   rs   rR  r  r:  ÚelemsÚranksr<  rA  rB  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   rQ  c                    rM  rf   r_   rK  rd   rf   rg   r      rï   z5ArrayPrinter._print_ArrayDiagonal.<locals>.<listcomp>rL  rŸ   rU  rÇ   r\   )rV  rR  ÚlistÚdiagonal_indicesrW  rs   r9  rk   rD  rp   rN  rO  ro   rq   )	re   rs   rR  r^  r9  rZ  Zdiagonal_stringrA  rB  rf   rd   rg   Ú_print_ArrayDiagonalö  s   

ýz!ArrayPrinter._print_ArrayDiagonalc                 C   s2   d|   | jd | j ¡|  |j¡|  |jj¡f S )Nr³   rŸ   )rp   rN  Ú
_transposer`   rs   ÚpermutationÚ
array_formrº   rf   rf   rg   Ú_print_PermuteDims  s
   
ýzArrayPrinter._print_PermuteDimsc                 C   s   |   | jd | j |j¡S )NrŸ   )r´   rN  Ú_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Ÿ   r5  )rp   rN  Z_onesrq   Úmapr`   rk   rº   rf   rf   rg   Ú_print_OneArray  ó   þzArrayPrinter._print_OneArrayc                 C   rg  rh  )rp   rN  Ú_zerosrq   ri  r`   rk   rº   rf   rf   rg   Ú_print_ZeroArray  rk  zArrayPrinter._print_ZeroArrayc                 C   s0   |   |  |j¡¡}|   |  |j¡¡}d||f S rœ   )r`   r2  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!  r2  rD  r6  rP  r\  r_  rc  re  rj  rm  rn  rp  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   r+  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   rp  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                    rM  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 )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’   ro   Úreplace)re   rs   rj   Úmsgr›   rf   rg   r‡  F  s   

zPythonCodePrinter._print_Symbol©F)rn   r   r!  ru  rv  rp  ry  r|  r€  rƒ  r„  r‡  r   Z_print_not_supportedÚ_print_lowergammaÚ_print_uppergammaÚ_print_fresnelcÚ_print_fresnelsr-  rf   rf   r›   rg   rq  (  s    
rq  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'

    )rq  Údoprint)rs   r™   rf   rf   rg   Úpycodeb  s   r�  )rq  )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 Z
_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   rz  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`   rt  rf   rf   rg   Ú_print_Float¦  rf  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   ri  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_cmathr(  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   Ã  r4  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É   )Zintegral_exprÚintegration_varsrã   Zintegration_rangeZintegration_varZlower_limitZ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
    Z_mpmathcodezPython with mpmathc                 C   rz   ©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  Útupleri  Ú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~  rt  rf   rf   rg   r€  	  s
   

ýzMpmathPrinter._print_Rationalc                 C   r¾   r^   r‚  rt  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.infrs  rt  rf   rf   rg   rŒ    s   üzMpmathPrinter._print_uppergammac                 C   s,   d  |  d¡|  |jd ¡|  |jd ¡¡S )Nz{}({}, 0, {})rÀ  r   r   rs  rt  rf   rf   rg   r‹    s
   ýzMpmathPrinter._print_lowergammac                 C   ó   d  |  d¡|  |jd ¡¡S )Nz{0}({1})/{0}(2)z
mpmath.logr   rs  rt  rf   rf   rg   Ú_print_log2   ó   ÿzMpmathPrinter._print_log2c                 C   rÁ  )Nz{}({})zmpmath.log1pr   rs  rt  rf   rf   rg   Ú_print_log1p$  rÃ  zMpmathPrinter._print_log1pFc                 C   r”  )Nzmpmath.sqrtr•  rz  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½  ri  r`   )rb   rC  rd   rf   rg   rh   2  s   €" z0MpmathPrinter._print_Integral.<locals>.<genexpr>)r¹  ro   rp   rq   ri  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   Z
seq_ordersrc   Zderiv_orderrf   rf   rg   Ú_print_Derivative_zeta5  s   
þz$MpmathPrinter._print_Derivative_zetaNrŠ  )rn   r   r!  r   r"  r#  r•   r   r'  r(  Ú_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•  rz  r{  rf   rf   rg   r|  S  r�  zSymPyPrinter._print_PowNrŠ  )	rn   r   r!  r#  r•   rx   r,  r™  r|  rf   rf   rf   rg   rÉ  E  s    þrÉ  N)'r   Úcollectionsr   Ú	itertoolsr   Ú
sympy.corer   Zsympy.core.modr   r   Úcodeprinterr   r$  r'  r)  r*  ru   rw   rx   r.  rq  r–   r}   Úsetattrr�  Úsympy.printing.pycoder¡  r¢  r’  r£   r£  r(  Z
_in_mpmathr•   rÇ  rÈ  r¹  rº  rÉ  rf   rf   rf   rg   Ú<module>   s   ýÿþýüûúùø	÷
öõôóòñðïá#ú	  S 	
3ñü
#
ôø
M