B
    }œ[Ð  ã               @   sb  d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 dd„ dfgd	d„ d
fgdd„ dfgdd„ dfgdd„ dfgdd„ dfgdd„ dfgdd„ dfgdd„ dfgdd„ dfgdd„ dfgdd„ dfgdd„ d fgd!d„ d"fgd#d„ d$fgd%d„ d&fgd'd„ d(fgd)d„ d*fgd+d„ d,fgd-d„ d.fgd/d„ d0fgd1d„ d2fgd3œZ
G d4d5„ d5eƒZd6d7„ Zd8S )9z
Mathematica code printer
é    )Úprint_functionÚdivision)ÚCodePrinter)Ú
StrPrinter)Ú
precedencec             C   s   dS )NT© )Úxr   r   ú9lib/python3.7/site-packages/sympy/printing/mathematica.pyÚ<lambda>   s    r
   ZExpc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZLogc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZSinc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZCosc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZTanc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZCotc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZArcSinc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZArcCosc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZArcTanc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZSinhc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZCoshc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZTanhc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZCothc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZSechc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZCschc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZArcSinhc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZArcCoshc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZArcTanhc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZArcCothc             C   s   dS )NTr   )r   r   r   r	   r
      s    ZArcSechc             C   s   dS )NTr   )r   r   r   r	   r
       s    ZArcCschc             C   s   dS )NTr   )r   r   r   r	   r
   !   s    Z	Conjugate)ÚexpÚlogZsinZcosZtanZcotZasinZacosZatanZsinhZcoshZtanhZcothZsechZcschZasinhZacoshZatanhZacothZasechZacschÚ	conjugatec                   s¤   e Zd ZdZdZdddi dddœZeƒ Zeƒ Zi fd	d
„Z	e
jZdd„ Z‡ fdd„Zdd„ Zdd„ Zdd„ Zdd„ ZeZeZdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )ÚMCodePrinterz]A printer to convert python expressions to
    strings of the Wolfram's Mathematica code
    Z_mcodeNÚautoé   TF)ÚorderZ	full_precZ	precisionÚuser_functionsZhumanZallow_unknown_functionsc             C   sd   t  | |¡ ttƒ| _| di ¡}x<| ¡ D ]0\}}t|tƒs,dd„ |fg||< | j |¡ q,W dS )z+Register function mappings supplied by userr   c              W   s   dS )NTr   )r   r   r   r	   r
   ?   s    z'MCodePrinter.__init__.<locals>.<lambda>N)	r   Ú__init__ÚdictÚknown_functionsÚgetÚitemsÚ
isinstanceÚlistÚupdate)ÚselfÚsettingsZ	userfuncsÚkÚvr   r   r	   r   8   s    

zMCodePrinter.__init__c             C   s(   t |ƒ}d|  |j|¡|  |j|¡f S )Nz%s^%s)r   ÚparenthesizeÚbaser   )r   ÚexprÚPRECr   r   r	   Ú
_print_PowD   s    zMCodePrinter._print_Powc                sX   t |ƒ‰ | ¡ \}}ttˆƒ |j|Ž ¡}|rT|d7 }|d ‡ ‡fdd„|D ƒ¡7 }|S )NÚ*z**c             3   s   | ]}ˆ  |ˆ ¡V  qd S )N)r   )Ú.0Úa)r"   r   r   r	   ú	<genexpr>O   s    z*MCodePrinter._print_Mul.<locals>.<genexpr>)r   Zargs_cncÚsuperr   Ú
_print_MulÚfuncÚjoin)r   r!   ÚcZncZres)Ú	__class__)r"   r   r	   r)   I   s    zMCodePrinter._print_Mulc             C   s   dS )NZPir   )r   r!   r   r   r	   Ú	_print_PiR   s    zMCodePrinter._print_Pic             C   s   dS )NZInfinityr   )r   r!   r   r   r	   Ú_print_InfinityU   s    zMCodePrinter._print_Infinityc             C   s   dS )Nz	-Infinityr   )r   r!   r   r   r	   Ú_print_NegativeInfinityX   s    z$MCodePrinter._print_NegativeInfinityc                s    dd  ‡ fdd„|D ƒ¡ d S )NÚ{z, c             3   s   | ]}ˆ   |¡V  qd S )N)Údoprint)r%   r&   )r   r   r	   r'   \   s    z+MCodePrinter._print_list.<locals>.<genexpr>Ú})r+   )r   r!   r   )r   r	   Ú_print_list[   s    zMCodePrinter._print_listc             C   sh   |j j| jkrN| j|j j }x0|D ](\}}||jŽ r"d||  |jd¡f S q"W |j jd|  |jd¡  S )Nz%s[%s]z, z[%s])r*   Ú__name__r   ÚargsZ	stringify)r   r!   Z
cond_mfuncZcondZmfuncr   r   r	   Ú_print_Function`   s    
zMCodePrinter._print_Functionc                s\   t |jƒdkr6|jd dd … s6|jd |jd g}n|j}dd ‡ fdd„|D ƒ¡ d S )Né   r   zHold[Integrate[z, c             3   s   | ]}ˆ   |¡V  qd S )N)r2   )r%   r&   )r   r   r	   r'   m   s    z/MCodePrinter._print_Integral.<locals>.<genexpr>z]])ÚlenZ	variablesZlimitsr6   r+   )r   r!   r6   r   )r   r	   Ú_print_Integralh   s     zMCodePrinter._print_Integralc                s"   dd  ‡ fdd„|jD ƒ¡ d S )Nz	Hold[Sum[z, c             3   s   | ]}ˆ   |¡V  qd S )N)r2   )r%   r&   )r   r   r	   r'   p   s    z*MCodePrinter._print_Sum.<locals>.<genexpr>z]])r+   r6   )r   r!   r   )r   r	   Ú
_print_Sumo   s    zMCodePrinter._print_Sumc                s<   |j }dd„ |jD ƒ}dd ‡ fdd„|g| D ƒ¡ d S )Nc             S   s$   g | ]}|d  d kr|d n|‘qS )r8   r   r   )r%   Úir   r   r	   ú
<listcomp>t   s    z2MCodePrinter._print_Derivative.<locals>.<listcomp>zHold[D[z, c             3   s   | ]}ˆ   |¡V  qd S )N)r2   )r%   r&   )r   r   r	   r'   u   s    z1MCodePrinter._print_Derivative.<locals>.<genexpr>z]])r!   Zvariable_countr+   )r   r!   ZdexprZdvarsr   )r   r	   Ú_print_Derivativer   s    zMCodePrinter._print_Derivative)r5   Ú
__module__Ú__qualname__Ú__doc__ZprintmethodZ_default_settingsÚsetZ_number_symbolsZ_not_supportedr   r   r2   r#   r)   r.   r/   r0   r4   Z_print_tupleZ_print_Tupler7   r:   r;   r>   Ú__classcell__r   r   )r-   r	   r   &   s0   
	r   c             K   s   t |ƒ | ¡S )a  Converts an expr to a string of the Wolfram Mathematica code

    Examples
    ========

    >>> from sympy import mathematica_code as mcode, symbols, sin
    >>> x = symbols('x')
    >>> mcode(sin(x).series(x).removeO())
    '(1/120)*x^5 - 1/6*x^3 + x'
    )r   r2   )r!   r   r   r   r	   Úmathematica_codex   s    rD   N)rA   Z
__future__r   r   Zsympy.printing.codeprinterr   Zsympy.printing.strr   Zsympy.printing.precedencer   r   r   rD   r   r   r   r	   Ú<module>   s8   R