B
    e‹d& ã               @   sì   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lmZ ddlmZmZ ddlmZmZmZ dd	lmZ dd
lmZmZ ddlmZmZmZ G dd„ deƒZG dd„ deƒZG dd„ deƒZ eeƒddd„ƒZ!ddd„Z"eZ#dS )z
A MathML printer.
é    )ÚAnyÚDict)ÚMul)ÚS)Údefault_sort_key)Úsympify)Úsplit_super_subÚrequires_partial)Úprecedence_traditionalÚ
PRECEDENCEÚPRECEDENCE_TRADITIONAL)Úgreek_unicode)ÚPrinterÚprint_function)Úprec_to_dpsÚrepr_dpsÚto_strc               @   sT   e Zd ZdZddddddddddddi d	d
œZddd„Zdd„ Zdd„ Zdd„ ZdS )ÚMathMLPrinterBasez^Contains common code required for MathMLContentPrinter and
    MathMLPresentationPrinter.
    Nzutf-8FZabbreviatedú[ÚplainTz&#xB7;)ÚorderÚencodingÚfold_frac_powersZfold_func_bracketsÚfold_short_fracZinv_trig_styleÚln_notationZlong_frac_ratioÚ	mat_delimÚmat_symbol_styleÚ
mul_symbolÚroot_notationZsymbol_namesÚmul_symbol_mathml_numbersc                sN   t  ˆ|¡ ddlm}m} |ƒ ˆ_G dd„ d|ƒ‰ ‡ ‡fdd„}|ˆj_d S )Nr   )ÚDocumentÚTextc               @   s   e Zd Zddd„ZdS )z+MathMLPrinterBase.__init__.<locals>.RawTextÚ c             S   s    | j r| d || j |¡¡ d S )Nz{}{}{})ÚdataÚwriteÚformat)ÚselfÚwriterÚindentÚ	addindentÚnewl© r+   úb/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/sympy/printing/mathml.pyÚwritexml5   s    z4MathMLPrinterBase.__init__.<locals>.RawText.writexmlN)r"   r"   r"   )Ú__name__Ú
__module__Ú__qualname__r-   r+   r+   r+   r,   ÚRawText4   s   r1   c                s   ˆ ƒ }| |_ ˆj|_|S )N)r#   ÚdomZownerDocument)r#   Úr)r1   r&   r+   r,   ÚcreateRawTextNode9   s    z5MathMLPrinterBase.__init__.<locals>.createRawTextNode)r   Ú__init__Úxml.dom.minidomr    r!   r2   ÚcreateTextNode)r&   Úsettingsr    r!   r4   r+   )r1   r&   r,   r5   *   s    zMathMLPrinterBase.__init__c             C   s,   t  | |¡}| ¡ }| dd¡}| ¡ }|S )z2
        Prints the expression as MathML.
        ÚasciiÚxmlcharrefreplace)r   Ú_printZtoxmlÚencodeÚdecode)r&   ÚexprZmathMLZunistrZxmlbstrÚresr+   r+   r,   ÚdoprintA   s
    zMathMLPrinterBase.doprintc                sV   ddl m}m}m‰ m‰ d‡ ‡fdd„	}|j| _||_d‡fdd„	}|j| _||_d S )	Nr   )ÚElementr!   ÚNodeÚ_write_datar"   c       	         s  |  |d | j ¡ |  ¡ }t| ¡ ƒ}| ¡  x4|D ],}|  d| ¡ ˆ||| jƒ |  d¡ q6W | jrü|  d¡ t| jƒdkr®| jd j	ˆ j
kr®| jd  |ddd¡ n8|  |¡ x"| jD ]}| ||| ||¡ qÀW |  |¡ |  d| j|f ¡ n|  d	| ¡ d S )
Nú<z %s="ú"ú>é   r   r"   z</%s>%sz/>%s)r$   ZtagNameZ_get_attributesÚlistÚkeysÚsortÚvalueZ
childNodesÚlenZnodeTypeZ	TEXT_NODEr-   )	r&   r'   r(   r)   r*   ÚattrsZa_namesÚa_nameÚnode)rB   rC   r+   r,   r-   U   s(    



z/MathMLPrinterBase.apply_patch.<locals>.writexmlc                s   ˆ |d|| j |f ƒ d S )Nz%s%s%s)r#   )r&   r'   r(   r)   r*   )rC   r+   r,   r-   t   s    )r"   r"   r"   )r"   r"   r"   )r6   rA   r!   rB   rC   r-   Ú_Element_writexml_oldÚ_Text_writexml_old)r&   rA   r!   r-   r+   )rB   rC   r,   Úapply_patchK   s    zMathMLPrinterBase.apply_patchc             C   s$   ddl m}m} | j|_| j|_d S )Nr   )rA   r!   )r6   rA   r!   rP   r-   rQ   )r&   rA   r!   r+   r+   r,   Úrestore_patchy   s    zMathMLPrinterBase.restore_patch)N)	r.   r/   r0   Ú__doc__Z_default_settingsr5   r@   rR   rS   r+   r+   r+   r,   r      s&   

.r   c               @   s:  e Zd ZdZdZdd„ Zdd„ ZdHd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"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ ZeZeZd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Z d8d9„ Z!d:d;„ Z"d<d=„ Z#d>d?„ Z$d@dA„ Z%e"Z&e"Z'e"Z(dBdC„ Z)dDdE„ Z*dFdG„ Z+dS )IÚMathMLContentPrinterz}Prints an expression to the Content MathML markup language.

    References: https://www.w3.org/TR/MathML2/chapter4.html
    Z_mathml_contentc          6   C   s¨   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-d.d/d0d1d2œ5}x&|j jD ]}|j}||krz|| S qzW |j j}| ¡ S )3z)Returns the MathML tag for an expression.ÚplusÚtimesÚdiffÚcnÚpowerÚmaxÚminÚabsÚandÚorÚxorÚnotZimpliesÚciÚintÚsumÚsinÚcosÚtanÚcotÚcscÚsecÚsinhÚcoshÚtanhÚcothÚcschÚsechÚarcsinÚarcsinhÚarccosÚarccoshÚarctanÚarctanhÚarccotZarccothZarcsecZarcsechZarccscZarccschÚlnÚeqZneqZgeqZleqÚgtÚltÚunionZ	intersect)5ÚAddr   Ú
DerivativeÚNumberrc   ÚPowZMaxZMinZAbsÚAndÚOrZXorÚNotZImpliesÚSymbolÚMatrixSymbolZRandomSymbolÚIntegralÚSumre   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   ÚasinÚasinhÚacosÚacoshÚatanÚatanhÚatan2ÚacotZacothZasecZasechZacscZacschÚlogÚEqualityÚ
UnequalityÚGreaterThanÚLessThanÚStrictGreaterThanÚStrictLessThanÚUnionÚIntersection)Ú	__class__Ú__mro__r.   Úlower)r&   ÚeÚ	translateÚclsÚnr+   r+   r,   Ú
mathml_tag†   sv    zMathMLContentPrinter.mathml_tagc       	      C   sD  |  ¡ r<| j d¡}| | j d¡¡ | |  | ¡¡ |S ddlm} ||ƒ\}}|tjk	r | j d¡}| | j d¡¡ | |  	|¡¡ | |  	|¡¡ |S | 
¡ \}}|tjkrÐt|ƒdkrÐ|  	|d ¡S | jdkrèt |¡ ¡ }| j d¡}| | j d¡¡ |dkr | |  	|¡¡ x|D ]}| |  	|¡¡ q&W |S )	NÚapplyÚminusr   )ÚfractionÚdividerG   ÚoldrW   )Úcould_extract_minus_signr2   ÚcreateElementÚappendChildÚ
_print_MulÚsympy.simplifyr£   r   ÚOner;   Úas_coeff_mulrL   r   r   Ú
_from_argsÚas_ordered_factors)	r&   r>   Úxr£   ÚnumerÚdenomÚcoeffÚtermsÚtermr+   r+   r,   r©   È   s2    



zMathMLContentPrinter._print_MulNc             C   s  | j ||d}|  |d ¡}g }x¢|dd … D ]’}| ¡ r| j d¡}| | j d¡¡ | |¡ | |  | ¡¡ |}||d krÀ| |¡ q.| |¡ |  |¡}||d kr.| |  |¡¡ q.W t|ƒdkrÔ|S | j d¡}| | j d¡¡ x|r| | d¡¡ qôW |S )N)r   r   rG   r¡   r¢   éÿÿÿÿrV   )	Ú_as_ordered_termsr;   r¦   r2   r§   r¨   ÚappendrL   Úpop)r&   r>   r   ÚargsZlastProcessedZ	plusNodesÚargr¯   r+   r+   r,   Ú
_print_Addë   s.    


zMathMLContentPrinter._print_Addc             C   s²   |j d jdkrtdƒ‚| j d¡}xˆt|j ƒD ]z\}\}}|t|j ƒd krt|dkrt| j d¡}| |  |¡¡ n,| j d¡}| |  |¡¡ | |  |¡¡ | |¡ q0W |S )Nrµ   Tz¼All Piecewise expressions must contain an (expr, True) statement to be used as a default condition. Without one, the generated expression may not evaluate to anything under some condition.Z	piecewiserG   Z	otherwiseÚpiece)	r¹   ZcondÚ
ValueErrorr2   r§   Ú	enumeraterL   r¨   r;   )r&   r>   ÚrootÚirœ   Úcr¼   r+   r+   r,   Ú_print_Piecewise  s    z%MathMLContentPrinter._print_Piecewisec          	   C   sf   | j  d¡}xTt|jƒD ]F}| j  d¡}x*t|jƒD ]}| |  |||f ¡¡ q4W | |¡ qW |S )NÚmatrixZ	matrixrow)r2   r§   ÚrangeÚrowsÚcolsr¨   r;   )r&   Úmr¯   rÀ   Zx_rÚjr+   r+   r,   Ú_print_MatrixBase  s    z&MathMLContentPrinter._print_MatrixBasec             C   s°   |j dkr2| j d¡}| | j t|jƒ¡¡ |S | j d¡}| | j d¡¡ | j d¡}| | j t|jƒ¡¡ | j d¡}| | j t|j ƒ¡¡ | |¡ | |¡ |S )NrG   rY   r¡   r¤   )Úqr2   r§   r¨   r7   ÚstrÚp)r&   rœ   r¯   ÚxnumZxdenomr+   r+   r,   Ú_print_Rational%  s    


z$MathMLContentPrinter._print_Rationalc             C   s–   | j  d¡}| | j  |  |¡¡¡ | j  d¡}| j  d¡}| |  |jd ¡¡ | |  |jd ¡¡ | |¡ | |¡ | |  |jd ¡¡ |S )Nr¡   ÚbvarÚlowlimitrG   é   r   )r2   r§   r¨   r    r;   r¹   )r&   rœ   r¯   Úx_1Úx_2r+   r+   r,   Ú_print_Limit7  s    

z!MathMLContentPrinter._print_Limitc             C   s   | j  d¡S )NZ
imaginaryi)r2   r§   )r&   rœ   r+   r+   r,   Ú_print_ImaginaryUnitE  s    z)MathMLContentPrinter._print_ImaginaryUnitc             C   s   | j  d¡S )NZ
eulergamma)r2   r§   )r&   rœ   r+   r+   r,   Ú_print_EulerGammaH  s    z&MathMLContentPrinter._print_EulerGammac             C   s"   | j  d¡}| | j  d¡¡ |S )zvWe use unicode #x3c6 for Greek letter phi as defined here
        http://www.w3.org/2003/entities/2007doc/isogrk1.htmlrY   u   Ï†)r2   r§   r¨   r7   )r&   rœ   r¯   r+   r+   r,   Ú_print_GoldenRatioK  s    z'MathMLContentPrinter._print_GoldenRatioc             C   s   | j  d¡S )NZexponentiale)r2   r§   )r&   rœ   r+   r+   r,   Ú_print_Exp1R  s    z MathMLContentPrinter._print_Exp1c             C   s   | j  d¡S )NÚpi)r2   r§   )r&   rœ   r+   r+   r,   Ú	_print_PiU  s    zMathMLContentPrinter._print_Pic             C   s   | j  d¡S )NÚinfinity)r2   r§   )r&   rœ   r+   r+   r,   Ú_print_InfinityX  s    z$MathMLContentPrinter._print_Infinityc             C   s   | j  d¡S )NZ
notanumber)r2   r§   )r&   rœ   r+   r+   r,   Ú
_print_NaN[  s    zMathMLContentPrinter._print_NaNc             C   s   | j  d¡S )NZemptyset)r2   r§   )r&   rœ   r+   r+   r,   Ú_print_EmptySet^  s    z$MathMLContentPrinter._print_EmptySetc             C   s   | j  d¡S )NÚtrue)r2   r§   )r&   rœ   r+   r+   r,   Ú_print_BooleanTruea  s    z'MathMLContentPrinter._print_BooleanTruec             C   s   | j  d¡S )NÚfalse)r2   r§   )r&   rœ   r+   r+   r,   Ú_print_BooleanFalsed  s    z(MathMLContentPrinter._print_BooleanFalsec             C   s4   | j  d¡}| | j  d¡¡ | | j  d¡¡ |S )Nr¡   r¢   rÛ   )r2   r§   r¨   )r&   rœ   r¯   r+   r+   r,   Ú_print_NegativeInfinityg  s    z,MathMLContentPrinter._print_NegativeInfinityc                s*   ‡ ‡‡fdd„‰t ˆ jƒ}| ¡  ˆ|ƒS )Nc                s8  ˆj  d¡}| ˆj  ˆ ˆ ¡¡¡ ˆj  d¡}| ˆ | d d ¡¡ | |¡ t| d ƒdkr¾ˆj  d¡}| ˆ | d d ¡¡ | |¡ ˆj  d¡}| ˆ | d d ¡¡ | |¡ t| d ƒdkrüˆj  d¡}| ˆ | d d ¡¡ | |¡ t| ƒdkr| ˆ ˆ j¡¡ n| ˆ| dd … ƒ¡ |S )	Nr¡   rÏ   r   é   rÐ   rG   ZuplimitrÑ   )r2   r§   r¨   r    r;   rL   Úfunction)Úlimitsr¯   Z	bvar_elemÚlow_elemÚup_elem)rœ   Ú
lime_recurr&   r+   r,   ré   n  s(    



z8MathMLContentPrinter._print_Integral.<locals>.lime_recur)rH   ræ   Úreverse)r&   rœ   ræ   r+   )rœ   ré   r&   r,   Ú_print_Integralm  s    
z$MathMLContentPrinter._print_Integralc             C   s
   |   |¡S )N)rë   )r&   rœ   r+   r+   r,   Ú
_print_SumŠ  s    zMathMLContentPrinter._print_Sumc                sB  ˆ j  ˆ  |¡¡}‡ fdd„}dd„ ‰t|jƒ\}}}ˆ|ƒ}‡fdd„|D ƒ}‡fdd„|D ƒ}ˆ j  d¡}| ˆ j  |¡¡ |sÌ|sœ| ˆ j  |¡¡ n.ˆ j  d	¡}| |¡ | ||ƒ¡ | |¡ nr|sˆ j  d
¡}	|	 |¡ |	 ||ƒ¡ | |	¡ n<ˆ j  d¡}
|
 |¡ |
 ||ƒ¡ |
 ||ƒ¡ | |
¡ |S )Nc                s´   t | ƒdkrŠˆ j d¡}xlt| ƒD ]`\}}|dkrZˆ j d¡}| ˆ j d¡¡ | |¡ ˆ j d¡}| ˆ j |¡¡ | |¡ q"W |S ˆ j d¡}| ˆ j | d ¡¡ |S d S )NrG   zmml:mrowr   zmml:moú zmml:mi)rL   r2   r§   r¾   r¨   r7   )ÚitemsÚmrowrÀ   ÚitemÚmoÚmi)r&   r+   r,   Újoin’  s    
z0MathMLContentPrinter._print_Symbol.<locals>.joinc             S   s   | t krt  | ¡S | S d S )N)r   Úget)Úsr+   r+   r,   r   ¤  s    
z5MathMLContentPrinter._print_Symbol.<locals>.translatec                s   g | ]}ˆ |ƒ‘qS r+   r+   )Ú.0Úsup)r   r+   r,   ú
<listcomp>¬  s    z6MathMLContentPrinter._print_Symbol.<locals>.<listcomp>c                s   g | ]}ˆ |ƒ‘qS r+   r+   )rö   Úsub)r   r+   r,   rø   ­  s    zmml:mizmml:msubzmml:msupzmml:msubsup)r2   r§   r    r   Únamer¨   r7   )r&   Úsymrb   ró   rú   ÚsupersÚsubsÚmnameÚmsubÚmsupÚmsubsupr+   )r&   r   r,   Ú_print_Symbol  s6    



z"MathMLContentPrinter._print_Symbolc             C   sô   | j d r¤|jjr¤|jjdkr¤| j d¡}| | j d¡¡ |jjdkrŽ| j d¡}| j d¡}| | j t	|jjƒ¡¡ | |¡ | |¡ | |  
|j¡¡ |S | j d¡}| j |  |¡¡}| |¡ | |  
|j¡¡ | |  
|j¡¡ |S )Nr   rG   r¡   r¿   rÑ   ÚdegreerY   )Ú	_settingsÚexpÚis_RationalrÌ   r2   r§   r¨   rÊ   r7   rË   r;   Úbaser    )r&   rœ   r¯   ZxmldegZxmlcnrÒ   r+   r+   r,   Ú
_print_PowÊ  s$    


zMathMLContentPrinter._print_Powc             C   s,   | j  |  |¡¡}| | j  t|ƒ¡¡ |S )N)r2   r§   r    r¨   r7   rË   )r&   rœ   r¯   r+   r+   r,   Ú_print_Numberá  s    z"MathMLContentPrinter._print_Numberc             C   s:   | j  |  |¡¡}t|jt|jƒƒ}| | j  |¡¡ |S )N)	r2   r§   r    Úmlib_to_strÚ_mpf_r   Ú_precr¨   r7   )r&   rœ   r¯   Zrepr_er+   r+   r,   Ú_print_Floatæ  s    z!MathMLContentPrinter._print_Floatc             C   s¼   | j  d¡}|  |¡}t|jƒr$d}| | j  |¡¡ | j  d¡}xXt|jƒD ]J\}}| |  |¡¡ |dkrN| j  d¡}| |  t	|ƒ¡¡ | |¡ qNW | |¡ | |  |j¡¡ |S )Nr¡   ZpartialdiffrÏ   rG   r  )
r2   r§   r    r	   r>   r¨   ÚreversedÚvariable_countr;   r   )r&   rœ   r¯   Zdiff_symbolrÒ   rû   rW   r  r+   r+   r,   Ú_print_Derivativeì  s    


z&MathMLContentPrinter._print_Derivativec             C   sH   | j  d¡}| | j  |  |¡¡¡ x|jD ]}| |  |¡¡ q,W |S )Nr¡   )r2   r§   r¨   r    r¹   r;   )r&   rœ   r¯   rº   r+   r+   r,   Ú_print_Functionÿ  s
    z$MathMLContentPrinter._print_Functionc             C   s6   | j  |  |¡¡}x|jD ]}| |  |¡¡ qW |S )N)r2   r§   r    r¹   r¨   r;   )r&   rœ   r¯   rº   r+   r+   r,   Ú_print_Basic  s    z!MathMLContentPrinter._print_Basicc             C   sL   | j  d¡}| j  |  |¡¡}| |¡ x|jD ]}| |  |¡¡ q0W |S )Nr¡   )r2   r§   r    r¨   r¹   r;   )r&   rœ   r¯   rÒ   rº   r+   r+   r,   Ú_print_AssocOp  s    
z#MathMLContentPrinter._print_AssocOpc             C   sL   | j  d¡}| | j  |  |¡¡¡ | |  |j¡¡ | |  |j¡¡ |S )Nr¡   )r2   r§   r¨   r    r;   ÚlhsÚrhs)r&   rœ   r¯   r+   r+   r,   Ú_print_Relational  s
    z&MathMLContentPrinter._print_Relationalc             C   s.   | j  d¡}x|D ]}| |  |¡¡ qW |S )zfMathML reference for the <list> element:
        http://www.w3.org/TR/MathML2/chapter4.html#contm.listrH   )r2   r§   r¨   r;   )r&   ÚseqÚdom_elementrð   r+   r+   r,   Ú_print_list  s    
z MathMLContentPrinter._print_listc             C   s,   | j  |  |¡¡}| | j  t|ƒ¡¡ |S )N)r2   r§   r    r¨   r7   rË   )r&   rÌ   r  r+   r+   r,   Ú
_print_int#  s    zMathMLContentPrinter._print_intc             C   s0   | j  d¡}x|jD ]}| |  |¡¡ qW |S )NÚset)r2   r§   r¹   r¨   r;   )r&   rœ   r¯   rº   r+   r+   r,   Ú_print_FiniteSet,  s    z%MathMLContentPrinter._print_FiniteSetc             C   sB   | j  d¡}| | j  d¡¡ x|jD ]}| |  |¡¡ q&W |S )Nr¡   Zsetdiff)r2   r§   r¨   r¹   r;   )r&   rœ   r¯   rº   r+   r+   r,   Ú_print_Complement2  s
    z&MathMLContentPrinter._print_Complementc             C   sB   | j  d¡}| | j  d¡¡ x|jD ]}| |  |¡¡ q&W |S )Nr¡   Zcartesianproduct)r2   r§   r¨   r¹   r;   )r&   rœ   r¯   rº   r+   r+   r,   Ú_print_ProductSet9  s
    z&MathMLContentPrinter._print_ProductSet)N),r.   r/   r0   rT   Úprintmethodr    r©   r»   rÂ   rÉ   rÎ   rÔ   rÕ   rÖ   r×   rØ   rÚ   rÜ   rÝ   rÞ   rà   râ   rã   rë   rì   r  Ú_print_MatrixSymbolÚ_print_RandomSymbolr  r	  r  r  r  r  r  r  r  r  Ú_print_ImpliesÚ
_print_NotÚ
_print_Xorr  r  r  r+   r+   r+   r,   rU      sR   B#
	8rU   c               @   sD  e Zd ZdZdZdd„ Zddd„Zdd	„ Zddd„Zdd„ Z	d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'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zdd6d7„Zd8d9„ ZeZd:d;„ Z d<d=„ Z!d>d?„ Z"d@dA„ Z#dBdC„ Z$dDdE„ Z%dFdG„ Z&dHdI„ Z'dJdK„ Z(dLdM„ Z)dNdO„ Z*dPdQ„ Z+dRdS„ Z,dTdU„ Z-dVdW„ Z.ddXdY„Z/e/Z0dZd[„ Z1dd\d]„Z2dd^d_„Z3d`da„ Z4dbdc„ Z5ddde„ Z6dfdg„ Z7dhdi„ Z8djdk„ Z9dldm„ Z:dndo„ Z;dpdq„ Z<e<Z=drds„ Z>dtdu„ Z?dvdw„ Z@dxdy„ ZAdzd{„ ZBd|d}„ ZCd~d„ ZDd€d„ ZEd‚dƒ„ ZFeFZGeFZHd„d…„ ZId†d‡„ ZJdˆd‰„ ZKeK ZLZMdŠd‹„ ZNdŒd„ ZOdŽd„ ZPdd‘„ ZQd’d“„ ZRd”d•„ ZSd–d—„ ZTd˜d™„ ZUdšd›„ ZVdœd„ ZWdždŸ„ ZXd d¡„ ZYd¢d£„ ZZd¤d¥„ Z[d¦d§„ Z\d¨d©„ Z]dªd«„ Z^d¬d­„ Z_d®d¯„ Z`d°d±„ Zad²d³„ ZbebZcd´dµ„ Zdd¶d·„ Zed¸d¹„ Zfdºd»„ Zgd¼d½„ Zhd¾d¿„ ZidÀdÁ„ ZjdÂdÃ„ ZkdÄdÅ„ ZldÆdÇ„ ZmdÈdÉ„ ZndÊdË„ ZodÌdÍ„ ZpdÎdÏ„ ZqdÐdÑ„ ZrdÒdÓ„ ZsdÔdÕ„ ZtdÖd×„ ZudØdÙ„ ZvdÚdÛ„ ZwdÜdÝ„ ZxdÞdß„ Zydàdá„ Zzdâdã„ Z{dädå„ Z|dædç„ Z}dèdé„ Z~dêdë„ Zdìdí„ Z€dîdï„ Zdð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 (	  ÚMathMLPresentationPrinterz‚Prints an expression to the Presentation MathML markup language.

    References: https://www.w3.org/TR/MathML2/chapter3.html
    Z_mathml_presentationc          0      sº   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+œ/}‡ fd,d-„}x&|j jD ]}|j}||krz|| S qzW |j jd.krª|ƒ S |j j}| ¡ S )/z)Returns the MathML tag for an expression.Úmnz&#x2192;z&dd;rò   z&int;z&#x2211;re   rf   rg   rh   rq   rr   rs   rt   ru   rv   rw   ú=z&#x2260;z&#x2265;z&#x2264;rF   rD   z&#x3A6;z&#x3B6;z&#x3B7;z&#x39A;z&#x3B3;z&#x393;z&#x3D5;z&#x3BB;z&#x3BD;z&#x3A9;r   ÚCÚWz&#x398;ÚTrueÚFalseÚNonez	S&#x2032;z	C&#x2032;)/r   ZLimitr~   rc   r„   r†   r‡   re   rf   rg   rh   rˆ   r‰   rŠ   r‹   rŒ   r   r   rŽ   r‘   r’   r“   r”   r•   r–   ZlerchphiÚzetaZdirichlet_etaZ
elliptic_kZ
lowergammaZ
uppergammaÚgammaZtotientZreduced_totientZprimenuZ
primeomegaZfresnelsZfresnelcZLambertWZ	HeavisideZBooleanTrueZBooleanFalseZNoneTypeZmathieusZmathieucZmathieusprimeZmathieucprimec                  sz   ˆ j d d ksˆ j d dkr dS ˆ j d dkr2dS ˆ j d dkrDdS ˆ j d dkrVd	S tˆ j d tƒslt‚n
ˆ j d S d S )
Nr   r,  z&InvisibleTimes;rW   z&#xD7;Údotz&#xB7;Zldotz&#x2024;)r  Ú
isinstancerË   Ú	TypeErrorr+   )r&   r+   r,   Úmul_symbol_selection~  s    zBMathMLPresentationPrinter.mathml_tag.<locals>.mul_symbol_selectionr   )r™   rš   r.   r›   )r&   rœ   r   r2  rž   rŸ   r+   )r&   r,   r    J  sp    z$MathMLPresentationPrinter.mathml_tagFc             C   sJ   t |ƒ}||k s|s<||kr<| j d¡}| |  |¡¡ |S |  |¡S d S )NÚmfenced)r
   r2   r§   r¨   r;   )r&   rð   ÚlevelÚstrictZprec_valÚbracr+   r+   r,   Úparenthesize–  s    z&MathMLPresentationPrinter.parenthesizec                sd   ‡ fdd„}ˆ j  d¡}| ¡ rVˆ j  d¡}| ˆ j  d¡¡ | |¡ || |ƒ}n
|||ƒ}|S )Nc                sŽ  ddl m} || ƒ\}}|tjk	rŠˆ j d¡}ˆ jd rTtt| ƒƒdk rT| 	dd¡ ˆ  
|¡}ˆ  
|¡}| |¡ | |¡ | |¡ |S |  ¡ \}}	|tjkrÄt|	ƒdkrÄ| ˆ  
|	d ¡¡ |S ˆ jd	krÜt |	¡ ¡ }	|dkr(ˆ  
|¡}
ˆ j d
¡}| ˆ j ˆ  | ¡¡¡ | |
¡ | |¡ x`|	D ]X}| ˆ  |td ¡¡ ||	d ks.ˆ j d
¡}| ˆ j ˆ  | ¡¡¡ | |¡ q.W |S )Nr   )r£   Úmfracr   é   Úbevelledrß   rG   r¥   rñ   r   rµ   )rª   r£   r   r«   r2   r§   r  rL   rË   ÚsetAttributer;   r¨   r¬   r   r   r­   r®   r7   r    r7  r   )r>   rï   r£   r°   r±   ÚfracrÍ   Zxdenr²   r³   r¯   Úyr´   )r&   r+   r,   Úmultiply¡  s>    











z6MathMLPresentationPrinter._print_Mul.<locals>.multiplyrï   rñ   ú-)r2   r§   r¦   r¨   r7   )r&   r>   r>  rï   r¯   r+   )r&   r,   r©   Ÿ  s    "

z$MathMLPresentationPrinter._print_MulNc             C   s¸   | j  d¡}| j||d}| |  |d ¡¡ x„|dd … D ]t}| ¡ rt| j  d¡}| | j  d¡¡ |  | ¡}n(| j  d¡}| | j  d¡¡ |  |¡}| |¡ | |¡ q<W |S )Nrï   )r   r   rG   rñ   r?  ú+)r2   r§   r¶   r¨   r;   r¦   r7   )r&   r>   r   rï   r¹   rº   r¯   r=  r+   r+   r,   r»   Î  s    

z$MathMLPresentationPrinter._print_Addc          	   C   sÊ   | j  d¡}xjt|jƒD ]\}| j  d¡}x@t|jƒD ]2}| j  d¡}| |  |||f ¡¡ | |¡ q4W | |¡ qW | jd dkrŠ|S | j  d¡}| jd dkr¼| dd	¡ | d
d¡ | |¡ |S )NZmtableZmtrZmtdr   r"   r3  r   Úcloseú]Úopen)	r2   r§   rÄ   rÅ   rÆ   r¨   r;   r  r;  )r&   rÇ   ÚtablerÀ   r¯   rÈ   r=  r6  r+   r+   r,   rÉ   â  s     
z+MathMLPresentationPrinter._print_MatrixBasec             C   s¶   |j dk r|j  }n|j }| j d¡}|s4| jd r@| dd¡ | |  |¡¡ | |  |j¡¡ |j dk r®| j d¡}| j d¡}| | j d¡¡ | |¡ | |¡ |S |S d S )	Nr   r8  r   r:  rß   rï   rñ   r?  )	rÌ   r2   r§   r  r;  r¨   r;   rÊ   r7   )r&   rœ   ÚfoldedrÌ   r¯   rï   rñ   r+   r+   r,   Ú_get_printed_Rationalô  s     




z/MathMLPresentationPrinter._get_printed_Rationalc             C   s(   |j dkr|  |j¡S |  || jd ¡S )NrG   r   )rÊ   r;   rÌ   rF  r  )r&   rœ   r+   r+   r,   rÎ     s    
z)MathMLPresentationPrinter._print_Rationalc       	      C   sÜ   | j  d¡}| j  d¡}| j  d¡}| | j  d¡¡ | j  d¡}|  |jd ¡}| j  d¡}| | j  |  |¡¡¡ |  |jd ¡}| |¡ | |¡ | |¡ | |¡ | |¡ | |¡ | |  |jd ¡¡ |S )	Nrï   Úmunderrò   ÚlimrG   rñ   rÑ   r   )r2   r§   r¨   r7   r;   r¹   r    )	r&   rœ   rï   rG  rò   r¯   rÒ   ÚarrowrÓ   r+   r+   r,   rÔ     s"    





z&MathMLPresentationPrinter._print_Limitc             C   s"   | j  d¡}| | j  d¡¡ |S )Nrò   z&ImaginaryI;)r2   r§   r¨   r7   )r&   rœ   r¯   r+   r+   r,   rÕ   %  s    z.MathMLPresentationPrinter._print_ImaginaryUnitc             C   s"   | j  d¡}| | j  d¡¡ |S )Nrò   z&#x3A6;)r2   r§   r¨   r7   )r&   rœ   r¯   r+   r+   r,   r×   *  s    z,MathMLPresentationPrinter._print_GoldenRatioc             C   s"   | j  d¡}| | j  d¡¡ |S )Nrò   z&ExponentialE;)r2   r§   r¨   r7   )r&   rœ   r¯   r+   r+   r,   rØ   /  s    z%MathMLPresentationPrinter._print_Exp1c             C   s"   | j  d¡}| | j  d¡¡ |S )Nrò   z&pi;)r2   r§   r¨   r7   )r&   rœ   r¯   r+   r+   r,   rÚ   4  s    z#MathMLPresentationPrinter._print_Pic             C   s"   | j  d¡}| | j  d¡¡ |S )Nrò   z&#x221E;)r2   r§   r¨   r7   )r&   rœ   r¯   r+   r+   r,   rÜ   9  s    z)MathMLPresentationPrinter._print_Infinityc             C   sL   | j  d¡}| j  d¡}| | j  d¡¡ |  |¡}| |¡ | |¡ |S )Nrï   rñ   r?  )r2   r§   r¨   r7   rÜ   )r&   rœ   rï   r=  r¯   r+   r+   r,   rã   >  s    


z1MathMLPresentationPrinter._print_NegativeInfinityc             C   s"   | j  d¡}| | j  d¡¡ |S )Nrò   z&#x210F;)r2   r§   r¨   r7   )r&   rœ   r¯   r+   r+   r,   Ú_print_HBarG  s    z%MathMLPresentationPrinter._print_HBarc             C   s"   | j  d¡}| | j  d¡¡ |S )Nrò   z&#x3B3;)r2   r§   r¨   r7   )r&   rœ   r¯   r+   r+   r,   rÖ   L  s    z+MathMLPresentationPrinter._print_EulerGammac             C   s"   | j  d¡}| | j  d¡¡ |S )Nrò   ZTribonacciConstant)r2   r§   r¨   r7   )r&   rœ   r¯   r+   r+   r,   Ú_print_TribonacciConstantQ  s    z3MathMLPresentationPrinter._print_TribonacciConstantc             C   s8   | j  d¡}| |  |jd ¡¡ | | j  d¡¡ |S )Nr   r   z&#x2020;)r2   r§   r¨   r;   r¹   r7   )r&   rœ   r   r+   r+   r,   Ú_print_DaggerV  s    z'MathMLPresentationPrinter._print_Daggerc             C   sd   | j  d¡}| |  |jd ¡¡ | j  d¡}| | j  d¡¡ | |¡ | |  |jd ¡¡ |S )Nrï   r   rñ   z&#x2208;rG   )r2   r§   r¨   r;   r¹   r7   )r&   rœ   rï   rñ   r+   r+   r,   Ú_print_Contains\  s    
z)MathMLPresentationPrinter._print_Containsc             C   s"   | j  d¡}| | j  d¡¡ |S )Nrò   z&#x210B;)r2   r§   r¨   r7   )r&   rœ   r¯   r+   r+   r,   Ú_print_HilbertSpacee  s    z-MathMLPresentationPrinter._print_HilbertSpacec             C   s8   | j  d¡}| | j  d¡¡ | |  |jd ¡¡ |S )Nr   z	&#x1D49E;r   )r2   r§   r¨   r7   r;   r¹   )r&   rœ   r   r+   r+   r,   Ú_print_ComplexSpacej  s    z-MathMLPresentationPrinter._print_ComplexSpacec             C   s"   | j  d¡}| | j  d¡¡ |S )Nrò   z&#x2131;)r2   r§   r¨   r7   )r&   rœ   r¯   r+   r+   r,   Ú_print_FockSpacep  s    z*MathMLPresentationPrinter._print_FockSpacec       	      C   sÀ  ddddœ}| j  d¡}t|jƒdkrntdd„ |jD ƒƒrn| j  d	¡}| | j  |t|jƒ ¡¡ | |¡ nàxÞt|jƒD ]Ð}| j  d	¡}| | j  |d
 ¡¡ t|ƒd
kr¶| |¡ t|ƒdkrö| j  d¡}| |¡ | |  |d
 ¡¡ | |¡ t|ƒdkrz| j  d¡}| |¡ | |  |d
 ¡¡ | |  |d ¡¡ | |¡ qzW | | j	|j
td dd¡ xPt|jƒD ]B}| j  d	¡}| | j  d¡¡ | |¡ | |  |d ¡¡ qvW |S )Nz&#x222B;z&#x222C;z&#x222D;)rG   rÑ   rä   rï   rä   c             s   s   | ]}t |ƒd kV  qdS )rG   N)rL   )rö   rH  r+   r+   r,   ú	<genexpr>z  s    z<MathMLPresentationPrinter._print_Integral.<locals>.<genexpr>rñ   rG   rÑ   r   r  r   T)r5  z&dd;r   )r2   r§   rL   ræ   Úallr¨   r7   r  r;   r7  rå   r   )	r&   r>   Z
intsymbolsrï   rñ   rH  r   r  Údr+   r+   r,   rë   v  s<    "





z)MathMLPresentationPrinter._print_Integralc             C   s@  t |jƒ}| j d¡}|  |d d ¡}|  |d d ¡}| j d¡}| | j |  |¡¡¡ | j d¡}|  |d d ¡}| j d¡}	|	 | j d¡¡ | |¡ | |	¡ | |¡ | |¡ | |¡ | |¡ | j d¡}
|
 |¡ tt	|j
ƒƒdkr|
 |  |j
¡¡ n(| j d¡}| |  |j
¡¡ |
 |¡ |
S )	NZ
munderoverr   rG   rÑ   rñ   rï   r'  r3  )rH   ræ   r2   r§   r;   r¨   r7   r    rL   rË   rå   )r&   rœ   ræ   Zsubsuprç   rè   ZsummandÚlowÚvarÚequalrï   Zfencer+   r+   r,   rì   œ  s0    








z$MathMLPresentationPrinter._print_Sumr   c       	         s0  ‡ fdd„}dd„ ‰t |jƒ\}}}ˆ|ƒ}‡fdd„|D ƒ}‡fdd„|D ƒ}ˆ j d¡}| ˆ j |¡¡ t|ƒd	kr²t|ƒd	krŒ|}n$ˆ j d
¡}| |¡ | ||ƒ¡ ndt|ƒd	kräˆ j d¡}| |¡ | ||ƒ¡ n2ˆ j d¡}| |¡ | ||ƒ¡ | ||ƒ¡ |dkr,| dd¡ |S )Nc                s´   t | ƒdkrŠˆ j d¡}xlt| ƒD ]`\}}|dkrZˆ j d¡}| ˆ j d¡¡ | |¡ ˆ j d¡}| ˆ j |¡¡ | |¡ q"W |S ˆ j d¡}| ˆ j | d ¡¡ |S d S )NrG   rï   r   rñ   rí   rò   )rL   r2   r§   r¾   r¨   r7   )rî   rï   rÀ   rð   rñ   rò   )r&   r+   r,   ró   ¼  s    
z5MathMLPresentationPrinter._print_Symbol.<locals>.joinc             S   s   | t krt  | ¡S | S d S )N)r   rô   )rõ   r+   r+   r,   r   Î  s    
z:MathMLPresentationPrinter._print_Symbol.<locals>.translatec                s   g | ]}ˆ |ƒ‘qS r+   r+   )rö   r÷   )r   r+   r,   rø   Ö  s    z;MathMLPresentationPrinter._print_Symbol.<locals>.<listcomp>c                s   g | ]}ˆ |ƒ‘qS r+   r+   )rö   rù   )r   r+   r,   rø   ×  s    rò   r   rÿ   r   r  ÚboldÚmathvariant)r   rú   r2   r§   r¨   r7   rL   r;  )	r&   rû   Ústyleró   rú   rü   rý   rþ   r¯   r+   )r&   r   r,   r  »  s2    



z'MathMLPresentationPrinter._print_Symbolc             C   s   | j || jd dS )Nr   )rY  )r  r  )r&   rû   r+   r+   r,   r   ñ  s    z-MathMLPresentationPrinter._print_MatrixSymbolc             C   s2   | j  d¡}| dd¡ | |  |jd ¡¡ |S )NZmencloseÚnotationÚtopr   )r2   r§   r;  r¨   r;   r¹   )r&   r>   Úencr+   r+   r,   Ú_print_conjugate÷  s    z*MathMLPresentationPrinter._print_conjugatec             C   sN   | j  d¡}| |  |td ¡¡ | j  d¡}| | j  |¡¡ | |¡ |S )Nrï   ZFuncrñ   )r2   r§   r¨   r7  r   r7   )r&   Úopr>   Úrowrñ   r+   r+   r,   Ú_print_operator_afterý  s    
z/MathMLPresentationPrinter._print_operator_afterc             C   s   |   d|jd ¡S )Nú!r   )r`  r¹   )r&   r>   r+   r+   r,   Ú_print_factorial  s    z*MathMLPresentationPrinter._print_factorialc             C   s   |   d|jd ¡S )Nz!!r   )r`  r¹   )r&   r>   r+   r+   r,   Ú_print_factorial2  s    z+MathMLPresentationPrinter._print_factorial2c             C   s^   | j  d¡}| j  d¡}| dd¡ | |  |jd ¡¡ | |  |jd ¡¡ | |¡ |S )Nr3  r8  ZlinethicknessÚ0r   rG   )r2   r§   r;  r¨   r;   r¹   )r&   r>   r6  r<  r+   r+   r,   Ú_print_binomial  s    
z)MathMLPresentationPrinter._print_binomialc             C   sd  |j jrÐt|j jƒdkrÐ|j jdkrÐ| jd rÐ|j jdkrX| j d¡}| |  	|j
¡¡ |j jdkr–| j d¡}| |  	|j
¡¡ | |  	|j j¡¡ |j jdkrÌ| j d¡}| |  	d¡¡ | |¡ |S |S |j jrž|j jdkrž|j jr\| j d¡}| |  	d¡¡ | j d¡}| |  |j
td	 ¡¡ | |  |j  | jd
 ¡¡ | |¡ |S | j d¡}| |  |j
td	 ¡¡ | |  |j | jd
 ¡¡ |S |j jr*| j d¡}| |  	d¡¡ |j dkrä| |  	|j
¡¡ nB| j d¡}| |  |j
td	 ¡¡ | |  	|j  ¡¡ | |¡ |S | j d¡}| |  |j
td	 ¡¡ | |  	|j ¡¡ |S )NrG   r   rÑ   ZmsqrtZmrootrµ   r8  r   r€   r   )r  r  r]   rÌ   rÊ   r  r2   r§   r¨   r;   r  Zis_negativer7  r   rF  )r&   rœ   r¯   r<  r[  r+   r+   r,   r    sX    $





z$MathMLPresentationPrinter._print_Powc             C   s,   | j  |  |¡¡}| | j  t|ƒ¡¡ |S )N)r2   r§   r    r¨   r7   rË   )r&   rœ   r¯   r+   r+   r,   r	  J  s    z'MathMLPresentationPrinter._print_Numberc             C   sL   | j  d¡}| dd¡ | dd¡ | |  |j¡¡ | |  |j¡¡ |S )Nr3  rA  u   âŸ©rC  u   âŸ¨)r2   r§   r;  r¨   r;   r\   r[   )r&   rÀ   r6  r+   r+   r,   Ú_print_AccumulationBoundsO  s    z3MathMLPresentationPrinter._print_AccumulationBoundsc             C   s¤  t |jƒrd}n
|  |¡}| j d¡}d}x¨t|jƒD ]š\}}||7 }|dkr”| j d¡}| j d¡}| | j |¡¡ | |¡ | |  	|¡¡ n| j d¡}| | j |¡¡ | |¡ |  	|¡}	| |	¡ q6W | j d¡}
|dkr0| j d¡}| j d¡}| | j |¡¡ | |¡ | |  	|¡¡ n| j d¡}| | j |¡¡ |
 |¡ | j d¡}| j d¡}| |
¡ | |¡ | |¡ | |  	|j¡¡ |S )Nz&#x2202;rï   r   rÑ   r   rñ   r8  )
r	   r>   r    r2   r§   r  r  r¨   r7   r;   )r&   rœ   rS  rÇ   Údimrû   Únumr¯   Zxxr=  Zmnumrï   r<  r+   r+   r,   r  W  sF    










z+MathMLPresentationPrinter._print_Derivativec             C   s    | j  d¡}| j  d¡}|  |¡dkrD| jd rD| | j  d¡¡ n| | j  |  |¡¡¡ | j  d¡}x|jD ]}| |  |¡¡ qpW | |¡ | |¡ |S )Nrï   rò   r   r   rx   r3  )r2   r§   r    r  r¨   r7   r¹   r;   )r&   rœ   rï   r¯   r=  rº   r+   r+   r,   r  ‡  s    

z)MathMLPresentationPrinter._print_Functionc             C   sh  t |jƒ}t|j|dd}| jd }| j d¡}d|kr| d¡\}}|d dkr`|dd … }| j d	¡}| | j 	|¡¡ | |¡ | j d
¡}	|	 | j 	|¡¡ | |	¡ | j d¡}
| j d	¡}| | j 	d¡¡ |
 |¡ | j d	¡}| | j 	|¡¡ |
 |¡ | |
¡ |S |dkr.|  
d ¡S |dkrB|  d ¡S | j d	¡}| | j 	|¡¡ |S d S )NT)Zstrip_zerosr   rï   rœ   r   r@  rG   r&  rñ   r   Ú10z+infz-inf)r   r  r
  r  r  r2   r§   Úsplitr¨   r7   rÜ   rã   )r&   r>   ZdpsZstr_realÚ	separatorrï   Zmantr  r&  rñ   r   r+   r+   r,   r  •  s<    











z&MathMLPresentationPrinter._print_Floatc             C   s   | j  d¡}| j  d¡}| j  d¡}| | j  d¡¡ | |¡ | |  |jd ¡¡ | |¡ | j  d¡}| |  |jd ¡¡ | |¡ |S )Nrï   rÿ   rò   ZLir   r3  rG   )r2   r§   r¨   r7   r;   r¹   )r&   r>   rï   rÇ   rò   r6  r+   r+   r,   Ú_print_polylog¼  s    


z(MathMLPresentationPrinter._print_polylogc             C   st   | j  d¡}| j  d¡}| | j  |  |¡¡¡ | |¡ | j  d¡}x|jD ]}| |  |¡¡ qNW | |¡ |S )Nrï   rò   r3  )r2   r§   r¨   r7   r    r¹   r;   )r&   rœ   rï   rò   r6  rº   r+   r+   r,   r  Ê  s    

z&MathMLPresentationPrinter._print_Basicc             C   sF   | j  d¡}| j  d¡}x|jD ]}| |  |¡¡ q W | |¡ |S )Nrï   r3  )r2   r§   r¹   r¨   r;   )r&   rœ   rï   r¯   rº   r+   r+   r,   Ú_print_TupleÕ  s    
z&MathMLPresentationPrinter._print_Tuplec             C   sÂ   | j  d¡}| j  d¡}|j|jkrP| dd¡ | dd¡ | |  |j¡¡ nd|jrd| dd¡ n| dd¡ |jr„| dd	¡ n| dd
¡ | |  |j¡¡ | |  |j¡¡ | |¡ |S )Nrï   r3  rA  Ú}rC  Ú{ú)rB  ú(r   )	r2   r§   ÚstartÚendr;  r¨   r;   Z
right_openZ	left_open)r&   rÀ   rï   r6  r+   r+   r,   Ú_print_IntervalÝ  s     
z)MathMLPresentationPrinter._print_Intervalc             C   sT   | j  d¡}| j  d¡}| dd¡ | dd¡ | |  |jd ¡¡ | |¡ |S )Nrï   r3  rA  ú|rC  r   )r2   r§   r;  r¨   r;   r¹   )r&   r>   r  rï   r¯   r+   r+   r,   Ú
_print_Absõ  s    
z$MathMLPresentationPrinter._print_Absc             C   sj   | j  d¡}| j  d¡}| dd¡ | | j  |¡¡ | |¡ | j  d¡}| |  |¡¡ | |¡ |S )Nrï   rò   rX  Zfrakturr3  )r2   r§   r;  r¨   r7   r;   )r&   rÁ   r>   rï   rò   r6  r+   r+   r,   Ú_print_re_im   s    

z&MathMLPresentationPrinter._print_re_imc             C   s   |   d|jd ¡S )NÚRr   )rw  r¹   )r&   r>   r  r+   r+   r,   Ú	_print_re  s    z#MathMLPresentationPrinter._print_rec             C   s   |   d|jd ¡S )NÚIr   )rw  r¹   )r&   r>   r  r+   r+   r,   Ú	_print_im  s    z#MathMLPresentationPrinter._print_imc             C   s^   | j  d¡}| j  d¡}| | j  |  |¡¡¡ | |¡ x|jD ]}| |  |¡¡ qBW |S )Nrï   rò   )r2   r§   r¨   r7   r    r¹   r;   )r&   rœ   rï   rò   rº   r+   r+   r,   r    s    
z(MathMLPresentationPrinter._print_AssocOpc             C   s~   | j  d¡}| |  |jd |¡¡ xT|jdd … D ]B}| j  d¡}| | j  |¡¡ |  ||¡}| |¡ | |¡ q4W |S )Nrï   r   rG   rñ   )r2   r§   r¨   r7  r¹   r7   )r&   r>   ÚsymbolÚprecrï   rº   r¯   r=  r+   r+   r,   Ú_print_SetOp  s    
z&MathMLPresentationPrinter._print_SetOpc             C   s   t d }|  |d|¡S )Nr—   z&#x222A;)r   r~  )r&   r>   r}  r+   r+   r,   Ú_print_Union%  s    z&MathMLPresentationPrinter._print_Unionc             C   s   t d }|  |d|¡S )Nr˜   z&#x2229;)r   r~  )r&   r>   r}  r+   r+   r,   Ú_print_Intersection)  s    z-MathMLPresentationPrinter._print_Intersectionc             C   s   t d }|  |d|¡S )NZ
Complementz&#x2216;)r   r~  )r&   r>   r}  r+   r+   r,   r  -  s    z+MathMLPresentationPrinter._print_Complementc             C   s   t d }|  |d|¡S )NZSymmetricDifferencez&#x2206;)r   r~  )r&   r>   r}  r+   r+   r,   Ú_print_SymmetricDifference1  s    z4MathMLPresentationPrinter._print_SymmetricDifferencec             C   s   t d }|  |d|¡S )NZ
ProductSetz&#x00d7;)r   r~  )r&   r>   r}  r+   r+   r,   r  5  s    z+MathMLPresentationPrinter._print_ProductSetc             C   s   |   |j¡S )N)Ú
_print_setr¹   )r&   rõ   r+   r+   r,   r  9  s    z*MathMLPresentationPrinter._print_FiniteSetc             C   sR   t |td}| j d¡}| dd¡ | dd¡ x|D ]}| |  |¡¡ q6W |S )N)Úkeyr3  rA  rn  rC  ro  )Úsortedr   r2   r§   r;  r¨   r;   )r&   rõ   rî   r6  rð   r+   r+   r,   r‚  <  s    
z$MathMLPresentationPrinter._print_setc             C   sà   | j  d¡}|d jrL|d jsL| j  d¡}| |  |d ¡¡ | |¡ n| |  |d ¡¡ xz|dd … D ]j}| j  d¡}| | j  |¡¡ |jrº|jsº| j  d¡}| |  |¡¡ n
|  |¡}| |¡ | |¡ qnW |S )Nrï   r   r3  rG   rñ   )r2   r§   Ú
is_BooleanZis_Notr¨   r;   r7   )r&   r¹   r|  rï   r6  rº   r¯   r=  r+   r+   r,   Ú_print_LogOpG  s     

z&MathMLPresentationPrinter._print_LogOpc             C   s¼  ddl m} ||jkr"|  |j¡S t||ƒr:| ¡  ¡ }n
d|fg}| j d¡}xd|D ]Z\}}t	|j
 ¡ ƒ}|jdd„ d x0t|ƒD ]"\}\}	}
|
dkrà|rÎ| j d¡}| | j d	¡¡ | |¡ | |  |	¡¡ qŒ|
d
kr$| j d¡}| | j d¡¡ | |¡ | |  |	¡¡ qŒ|rR| j d¡}| | j d	¡¡ | |¡ | j d¡}| |  |
¡¡ | |¡ | j d¡}| | j d¡¡ | |¡ | |  |	¡¡ qŒW qXW |S )Nr   )ÚVectorrï   c             S   s   | d   ¡ S )Nr   )Ú__str__)r¯   r+   r+   r,   Ú<lambda>i  ó    zAMathMLPresentationPrinter._print_BasisDependent.<locals>.<lambda>)rƒ  rG   rñ   r@  rµ   r?  r3  z&InvisibleTimes;)Zsympy.vectorr‡  Úzeror;   r0  Zseparaterî   r2   r§   rH   Ú
componentsrJ   r¾   r¨   r7   )r&   r>   r‡  rî   rï   ÚsystemZvectZ
inneritemsrÀ   ÚkÚvrñ   Zmbracr+   r+   r,   Ú_print_BasisDependent[  sD    








z/MathMLPresentationPrinter._print_BasisDependentc             C   s   t |jtd}|  |d¡S )N)rƒ  z&#x2227;)r„  r¹   r   r†  )r&   r>   r¹   r+   r+   r,   Ú
_print_And…  s    z$MathMLPresentationPrinter._print_Andc             C   s   t |jtd}|  |d¡S )N)rƒ  z&#x2228;)r„  r¹   r   r†  )r&   r>   r¹   r+   r+   r,   Ú	_print_Or‰  s    z#MathMLPresentationPrinter._print_Orc             C   s   t |jtd}|  |d¡S )N)rƒ  z&#x22BB;)r„  r¹   r   r†  )r&   r>   r¹   r+   r+   r,   r$    s    z$MathMLPresentationPrinter._print_Xorc             C   s   |   |jd¡S )Nz&#x21D2;)r†  r¹   )r&   r>   r+   r+   r,   r"  ‘  s    z(MathMLPresentationPrinter._print_Impliesc             C   s   t |jtd}|  |d¡S )N)rƒ  z&#x21D4;)r„  r¹   r   r†  )r&   r>   r¹   r+   r+   r,   Ú_print_Equivalent”  s    z+MathMLPresentationPrinter._print_Equivalentc             C   s‚   | j  d¡}| j  d¡}| | j  d¡¡ | |¡ |jd jrd| j  d¡}| |  |jd ¡¡ n|  |jd ¡}| |¡ |S )Nrï   rñ   z&#xAC;r   r3  )r2   r§   r¨   r7   r¹   r…  r;   )r&   rœ   rï   rñ   r¯   r+   r+   r,   r#  ˜  s    

z$MathMLPresentationPrinter._print_Notc             C   s(   | j  d¡}| | j  |  |¡¡¡ |S )Nrò   )r2   r§   r¨   r7   r    )r&   rœ   rò   r+   r+   r,   Ú_print_bool¥  s    z%MathMLPresentationPrinter._print_boolc             C   s(   | j  d¡}| | j  |  |¡¡¡ |S )Nrò   )r2   r§   r¨   r7   r    )r&   rœ   rò   r+   r+   r,   Ú_print_NoneType­  s    z)MathMLPresentationPrinter._print_NoneTypec             C   s2  d}| j  d¡}| dd¡ | dd¡ |jjr`|jjr`|jjrP|ddd	|f}qÜ|d	dd|f}n||jjr‚||d |j |d f}nZ|jjr¦t|ƒ}t	|ƒt	|ƒ|f}n6t
|ƒd
krÔt|ƒ}t	|ƒt	|ƒ||d f}nt|ƒ}xP|D ]H}||kr| j  d¡}| | j  |¡¡ | |¡ qâ| |  |¡¡ qâW |S )Nu   â€¦r3  rA  rn  rC  ro  rµ   r   rG   é   rò   )r2   r§   r;  rr  Úis_infiniteÚstopÚstepZis_positiveÚiterÚnextrL   Útupler¨   r7   r;   )r&   rõ   Údotsr6  ZprintsetÚitÚelrò   r+   r+   r,   Ú_print_Range²  s0    

z&MathMLPresentationPrinter._print_Rangec             C   s„   t |jtd}| j d¡}| j d¡}| | j t|jƒ 	¡ ¡¡ | |¡ | j d¡}x|D ]}| |  
|¡¡ q^W | |¡ |S )N)rƒ  rï   rñ   r3  )r„  r¹   r   r2   r§   r¨   r7   rË   Úfuncr›   r;   )r&   r>   r¹   rï   rñ   r6  r|  r+   r+   r,   Ú_hprint_variadic_functionÒ  s    


z3MathMLPresentationPrinter._hprint_variadic_functionc             C   s6   | j  d¡}| |  d ¡¡ | |  |jd ¡¡ |S )Nr   r   )r2   r§   r¨   rØ   r;   r¹   )r&   r>   r   r+   r+   r,   Ú
_print_expà  s    z$MathMLPresentationPrinter._print_expc             C   sb   | j  d¡}| |  |j¡¡ | j  d¡}| | j  |  |¡¡¡ | |¡ | |  |j¡¡ |S )Nrï   rñ   )r2   r§   r¨   r;   r  r7   r    r  )r&   rœ   rï   r¯   r+   r+   r,   r  æ  s    
z+MathMLPresentationPrinter._print_Relationalc             C   s,   | j  |  |¡¡}| | j  t|ƒ¡¡ |S )N)r2   r§   r    r¨   r7   rË   )r&   rÌ   r  r+   r+   r,   r  ï  s    z$MathMLPresentationPrinter._print_intc             C   sŠ   | j  d¡}|j\}}| j  d¡}| dd¡ | | j  |j| ¡¡ | |¡ | j  d¡}| dd¡ | | j  |j¡¡ | |¡ |S )Nrÿ   rò   rX  rW  )r2   r§   Ú_idr;  r¨   r7   Z_variable_namesÚ_name)r&   rœ   rÿ   Úindexr  rò   r+   r+   r,   Ú_print_BaseScalarô  s    


z+MathMLPresentationPrinter._print_BaseScalarc             C   sÈ   | j  d¡}|j\}}| j  d¡}| j  d¡}| dd¡ | | j  |j| ¡¡ | |¡ | j  d¡}| | j  d¡¡ | |¡ | |¡ | j  d¡}| dd¡ | | j  |j¡¡ | |¡ |S )Nrÿ   Úmoverrò   rX  rW  rñ   ú^)r2   r§   r¤  r;  r¨   r7   Z_vector_namesr¥  )r&   rœ   rÿ   r¦  r  r¨  rò   rñ   r+   r+   r,   Ú_print_BaseVector  s     




z+MathMLPresentationPrinter._print_BaseVectorc             C   sl   | j  d¡}| j  d¡}| dd¡ | | j  d¡¡ | |¡ | j  d¡}| | j  d¡¡ | |¡ |S )Nr¨  rò   rX  rW  rd  rñ   r©  )r2   r§   r;  r¨   r7   )r&   rœ   r¨  rò   rñ   r+   r+   r,   Ú_print_VectorZero  s    

z+MathMLPresentationPrinter._print_VectorZeroc             C   sp   | j  d¡}|j}|j}| |  |td ¡¡ | j  d¡}| | j  d¡¡ | |¡ | |  |td ¡¡ |S )Nrï   r   rñ   z&#xD7;)r2   r§   Ú_expr1Ú_expr2r¨   r7  r   r7   )r&   r>   rï   Úvec1Úvec2rñ   r+   r+   r,   Ú_print_Cross  s    
z&MathMLPresentationPrinter._print_Crossc             C   sx   | j  d¡}| j  d¡}| | j  d¡¡ | |¡ | j  d¡}| | j  d¡¡ | |¡ | |  |jtd ¡¡ |S )Nrï   rñ   z&#x2207;z&#xD7;r   )r2   r§   r¨   r7   r7  Ú_exprr   )r&   r>   rï   rñ   r+   r+   r,   Ú_print_Curl)  s    

z%MathMLPresentationPrinter._print_Curlc             C   sx   | j  d¡}| j  d¡}| | j  d¡¡ | |¡ | j  d¡}| | j  d¡¡ | |¡ | |  |jtd ¡¡ |S )Nrï   rñ   z&#x2207;z&#xB7;r   )r2   r§   r¨   r7   r7  r±  r   )r&   r>   rï   rñ   r+   r+   r,   Ú_print_Divergence4  s    

z+MathMLPresentationPrinter._print_Divergencec             C   sp   | j  d¡}|j}|j}| |  |td ¡¡ | j  d¡}| | j  d¡¡ | |¡ | |  |td ¡¡ |S )Nrï   r   rñ   z&#xB7;)r2   r§   r¬  r­  r¨   r7  r   r7   )r&   r>   rï   r®  r¯  rñ   r+   r+   r,   Ú
_print_Dot?  s    
z$MathMLPresentationPrinter._print_Dotc             C   sP   | j  d¡}| j  d¡}| | j  d¡¡ | |¡ | |  |jtd ¡¡ |S )Nrï   rñ   z&#x2207;r   )r2   r§   r¨   r7   r7  r±  r   )r&   r>   rï   rñ   r+   r+   r,   Ú_print_GradientJ  s    
z)MathMLPresentationPrinter._print_Gradientc             C   sP   | j  d¡}| j  d¡}| | j  d¡¡ | |¡ | |  |jtd ¡¡ |S )Nrï   rñ   z&#x2206;r   )r2   r§   r¨   r7   r7  r±  r   )r&   r>   rï   rñ   r+   r+   r,   Ú_print_LaplacianR  s    
z*MathMLPresentationPrinter._print_Laplacianc             C   s.   | j  d¡}| dd¡ | | j  d¡¡ |S )Nrò   rX  Únormalz&#x2124;)r2   r§   r;  r¨   r7   )r&   rœ   r¯   r+   r+   r,   Ú_print_IntegersZ  s    z)MathMLPresentationPrinter._print_Integersc             C   s.   | j  d¡}| dd¡ | | j  d¡¡ |S )Nrò   rX  r·  z&#x2102;)r2   r§   r;  r¨   r7   )r&   rœ   r¯   r+   r+   r,   Ú_print_Complexes`  s    z*MathMLPresentationPrinter._print_Complexesc             C   s.   | j  d¡}| dd¡ | | j  d¡¡ |S )Nrò   rX  r·  z&#x211D;)r2   r§   r;  r¨   r7   )r&   rœ   r¯   r+   r+   r,   Ú_print_Realsf  s    z&MathMLPresentationPrinter._print_Realsc             C   s.   | j  d¡}| dd¡ | | j  d¡¡ |S )Nrò   rX  r·  z&#x2115;)r2   r§   r;  r¨   r7   )r&   rœ   r¯   r+   r+   r,   Ú_print_Naturalsl  s    z)MathMLPresentationPrinter._print_Naturalsc             C   sV   | j  d¡}| j  d¡}| dd¡ | | j  d¡¡ | |¡ | |  tj¡¡ |S )Nrÿ   rò   rX  r·  z&#x2115;)r2   r§   r;  r¨   r7   r;   r   ZZero)r&   rœ   rù   r¯   r+   r+   r,   Ú_print_Naturals0r  s    
z*MathMLPresentationPrinter._print_Naturals0c             C   s|   |j d |j d  }|j d }| j d¡}| j d¡}| dd¡ | dd	¡ | |  |¡¡ | |¡ | |  |¡¡ |S )
Nr   rG   rÑ   r   r3  rA  u   âŸ©rC  u   âŸ¨)r¹   r2   r§   r;  r¨   r;   )r&   r>   ÚshiftrZ   r÷   r6  r+   r+   r,   Ú_print_SingularityFunction{  s    

z4MathMLPresentationPrinter._print_SingularityFunctionc             C   s"   | j  d¡}| | j  d¡¡ |S )Nrò   ÚNaN)r2   r§   r¨   r7   )r&   rœ   r¯   r+   r+   r,   rÝ   ‡  s    z$MathMLPresentationPrinter._print_NaNc             C   s´   | j  d¡}| j  d¡}| | j  |¡¡ | |¡ | |  |jd ¡¡ t|jƒdkr\|S | j  d¡}| j  d¡}x&|jdd … D ]}| |  |¡¡ q„W | |¡ | |¡ |S )Nrÿ   rò   r   rG   rï   r3  )r2   r§   r¨   r7   r;   r¹   rL   )r&   rœ   rú   rù   rò   rï   r=  rº   r+   r+   r,   Ú_print_number_functionŒ  s    


z0MathMLPresentationPrinter._print_number_functionc             C   s   |   |d¡S )NÚB)rÀ  )r&   rœ   r+   r+   r,   Ú_print_bernoulliŸ  s    z*MathMLPresentationPrinter._print_bernoullic             C   s   |   |d¡S )Nr(  )rÀ  )r&   rœ   r+   r+   r,   Ú_print_catalan¤  s    z(MathMLPresentationPrinter._print_catalanc             C   s   |   |d¡S )NÚE)rÀ  )r&   rœ   r+   r+   r,   Ú_print_euler§  s    z&MathMLPresentationPrinter._print_eulerc             C   s   |   |d¡S )NÚF)rÀ  )r&   rœ   r+   r+   r,   Ú_print_fibonacciª  s    z*MathMLPresentationPrinter._print_fibonaccic             C   s   |   |d¡S )NÚL)rÀ  )r&   rœ   r+   r+   r,   Ú_print_lucas­  s    z&MathMLPresentationPrinter._print_lucasc             C   s   |   |d¡S )Nz&#x03B3;)rÀ  )r&   rœ   r+   r+   r,   Ú_print_stieltjes°  s    z*MathMLPresentationPrinter._print_stieltjesc             C   s   |   |d¡S )NÚT)rÀ  )r&   rœ   r+   r+   r,   Ú_print_tribonacci³  s    z+MathMLPresentationPrinter._print_tribonaccic             C   s`   | j  d¡}| j  d¡}| | j  d¡¡ | |¡ | j  d¡}| | j  d¡¡ | |¡ |S )Nr¨  rñ   z&#x221E;ú~)r2   r§   r¨   r7   )r&   rœ   r¯   rñ   r+   r+   r,   Ú_print_ComplexInfinity¶  s    

z0MathMLPresentationPrinter._print_ComplexInfinityc             C   s"   | j  d¡}| | j  d¡¡ |S )Nrñ   z&#x2205;)r2   r§   r¨   r7   )r&   rœ   r¯   r+   r+   r,   rÞ   À  s    z)MathMLPresentationPrinter._print_EmptySetc             C   s"   | j  d¡}| | j  d¡¡ |S )Nrñ   z	&#x1D54C;)r2   r§   r¨   r7   )r&   rœ   r¯   r+   r+   r,   Ú_print_UniversalSetÅ  s    z-MathMLPresentationPrinter._print_UniversalSetc             C   sŒ   ddl m} |j}| j d¡}t||ƒsP| j d¡}| |  |¡¡ | |¡ n| |  |¡¡ | j d¡}| | j d¡¡ | |¡ |S )Nr   )r…   r   r3  rñ   z&#x2020;)	Úsympy.matricesr…   rº   r2   r§   r0  r¨   r;   r7   )r&   r>   r…   Úmatr÷   r6  rñ   r+   r+   r,   Ú_print_AdjointÊ  s    

z(MathMLPresentationPrinter._print_Adjointc             C   sŒ   ddl m} |j}| j d¡}t||ƒsP| j d¡}| |  |¡¡ | |¡ n| |  |¡¡ | j d¡}| | j d¡¡ | |¡ |S )Nr   )r…   r   r3  rñ   rË  )	rÐ  r…   rº   r2   r§   r0  r¨   r;   r7   )r&   r>   r…   rÑ  r÷   r6  rñ   r+   r+   r,   Ú_print_TransposeÙ  s    

z*MathMLPresentationPrinter._print_Transposec             C   st   ddl m} |j}| j d¡}t||ƒsP| j d¡}| |  |¡¡ | |¡ n| |  |¡¡ | |  d¡¡ |S )Nr   )r…   r   r3  rµ   )rÐ  r…   rº   r2   r§   r0  r¨   r;   )r&   r>   r…   rÑ  r÷   r6  r+   r+   r,   Ú_print_Inverseè  s    
z(MathMLPresentationPrinter._print_Inversec             C   s*  ddl m} | j d¡}|j}t|d tƒrJ|d  ¡ t|dd … ƒ }nt|ƒ}t||ƒr´| 	¡ r´|d dkr~|dd … }n|d  |d< | j d¡}| 
| j d¡¡ | 
|¡ xT|d d… D ]D}| 
|  |t|ƒd¡¡ | j d¡}| 
| j d	¡¡ | 
|¡ qÂW | 
|  |d t|ƒd¡¡ |S )
Nr   )ÚMatMulrï   rG   rµ   rñ   r?  Fz&InvisibleTimes;)Z!sympy.matrices.expressions.matmulrÕ  r2   r§   r¹   r0  r   r®   rH   r¦   r¨   r7   r7  r
   )r&   r>   rÕ  r¯   r¹   rñ   rº   r+   r+   r,   Ú_print_MatMulõ  s,    
z'MathMLPresentationPrinter._print_MatMulc             C   s|   ddl m} |j|j }}| j d¡}t||ƒsX| j d¡}| |  |¡¡ | |¡ n| |  |¡¡ | |  |¡¡ |S )Nr   )r…   r   r3  )	rÐ  r…   r  r  r2   r§   r0  r¨   r;   )r&   r>   r…   r  r  r÷   r6  r+   r+   r,   Ú_print_MatPow  s    
z'MathMLPresentationPrinter._print_MatPowc             C   sˆ   | j  d¡}|j}xT|d d… D ]D}| |  |t|ƒd¡¡ | j  d¡}| | j  d¡¡ | |¡ q W | |  |d t|ƒd¡¡ |S )Nrï   rµ   Frñ   z&#x2218;)r2   r§   r¹   r¨   r7  r
   r7   )r&   r>   r¯   r¹   rº   rñ   r+   r+   r,   Ú_print_HadamardProduct  s    z0MathMLPresentationPrinter._print_HadamardProductc             C   s"   | j  d¡}| | j  d¡¡ |S )Nr&  z&#x1D7D8)r2   r§   r¨   r7   )r&   ÚZr¯   r+   r+   r,   Ú_print_ZeroMatrix,  s    z+MathMLPresentationPrinter._print_ZeroMatrixc             C   s"   | j  d¡}| | j  d¡¡ |S )Nr&  z&#x1D7D9)r2   r§   r¨   r7   )r&   rÙ  r¯   r+   r+   r,   Ú_print_OneMatrix1  s    z*MathMLPresentationPrinter._print_OneMatrixc             C   s"   | j  d¡}| | j  d¡¡ |S )Nrò   z	&#x1D540;)r2   r§   r¨   r7   )r&   rz  r¯   r+   r+   r,   Ú_print_Identity6  s    z)MathMLPresentationPrinter._print_Identityc             C   sT   | j  d¡}| j  d¡}| dd¡ | dd¡ | |  |jd ¡¡ | |¡ |S )Nrï   r3  rA  u   âŒ‹rC  u   âŒŠr   )r2   r§   r;  r¨   r;   r¹   )r&   rœ   rï   r¯   r+   r+   r,   Ú_print_floor;  s    
z&MathMLPresentationPrinter._print_floorc             C   sT   | j  d¡}| j  d¡}| dd¡ | dd¡ | |  |jd ¡¡ | |¡ |S )Nrï   r3  rA  u   âŒ‰rC  u   âŒˆr   )r2   r§   r;  r¨   r;   r¹   )r&   rœ   rï   r¯   r+   r+   r,   Ú_print_ceilingD  s    
z(MathMLPresentationPrinter._print_ceilingc             C   sž   | j  d¡}| j  d¡}|jd }t|ƒdkr>|  |d ¡}n
|  |¡}| |¡ | j  d¡}| | j  d¡¡ | |¡ | |  |jd ¡¡ | |¡ |S )Nr3  rï   r   rG   rñ   z&#x21A6;)r2   r§   r¹   rL   r;   r¨   r7   )r&   rœ   r¯   rï   Úsymbolsrñ   r+   r+   r,   Ú_print_LambdaM  s    




z'MathMLPresentationPrinter._print_Lambdac             C   s.   | j  d¡}x|D ]}| |  |¡¡ qW |S )Nr3  )r2   r§   r¨   r;   )r&   rœ   r¯   rÀ   r+   r+   r,   Ú_print_tuple]  s    
z&MathMLPresentationPrinter._print_tuplec             C   s   |   |j¡S )N)r;   Úlabel)r&   rœ   r+   r+   r,   Ú_print_IndexedBasec  s    z,MathMLPresentationPrinter._print_IndexedBasec             C   s\   | j  d¡}| |  |j¡¡ t|jƒdkrF| |  |jd ¡¡ |S | |  |j¡¡ |S )Nrÿ   rG   r   )r2   r§   r¨   r;   r  rL   Úindices)r&   rœ   r¯   r+   r+   r,   Ú_print_Indexedf  s    z(MathMLPresentationPrinter._print_Indexedc             C   sz   | j  d¡}| | j|jtd dd¡ | j  d¡}| dd¡ | dd¡ x|jD ]}| |  |¡¡ qTW | |¡ |S )	Nrÿ   ZAtomT)r5  r3  rA  r"   rC  )	r2   r§   r¨   r7  Úparentr   r;  rä  r;   )r&   rœ   r¯   r6  rÀ   r+   r+   r,   Ú_print_MatrixElemento  s    
z.MathMLPresentationPrinter._print_MatrixElementc             C   sz   | j  d¡}| j  d¡}| | j  d¡¡ | |¡ | j  d¡}| dd¡ x|jD ]}| |  |¡¡ qTW | |¡ |S )Nrï   rò   z	&#x1d5a5;r3  Ú
separatorsru  )r2   r§   r¨   r7   r;  r¹   r;   )r&   rœ   r¯   rò   r=  rÀ   r+   r+   r,   Ú_print_elliptic_fz  s    

z+MathMLPresentationPrinter._print_elliptic_fc             C   sz   | j  d¡}| j  d¡}| | j  d¡¡ | |¡ | j  d¡}| dd¡ x|jD ]}| |  |¡¡ qTW | |¡ |S )Nrï   rò   z	&#x1d5a4;r3  rè  ru  )r2   r§   r¨   r7   r;  r¹   r;   )r&   rœ   r¯   rò   r=  rÀ   r+   r+   r,   Ú_print_elliptic_e†  s    

z+MathMLPresentationPrinter._print_elliptic_ec             C   s–   | j  d¡}| j  d¡}| | j  d¡¡ | |¡ | j  d¡}t|jƒdkr\| dd¡ n| dd¡ x|jD ]}| |  |¡¡ qpW | |¡ |S )	Nrï   rò   z	&#x1d6f1;r3  rÑ   rè  ru  z;|)r2   r§   r¨   r7   rL   r¹   r;  r;   )r&   rœ   r¯   rò   r=  rÀ   r+   r+   r,   Ú_print_elliptic_pi’  s    

z,MathMLPresentationPrinter._print_elliptic_pic             C   sJ   | j  d¡}| j  d¡}| | j  d¡¡ | |¡ | |  |j¡¡ |S )Nrï   rò   ZEi)r2   r§   r¨   r7   r;   r¹   )r&   rœ   r¯   rò   r+   r+   r,   Ú	_print_Ei¡  s    
z#MathMLPresentationPrinter._print_Eic             C   s~   | j  d¡}| j  d¡}| j  d¡}| | j  d¡¡ | |¡ | |  |jd ¡¡ | |¡ | |  |jdd … ¡¡ |S )Nrï   rÿ   rñ   rÄ  r   rG   )r2   r§   r¨   r7   r;   r¹   )r&   rœ   r¯   r=  rñ   r+   r+   r,   Ú_print_expint©  s    

z'MathMLPresentationPrinter._print_expintc             C   s˜   | j  d¡}| j  d¡}| j  d¡}| | j  d¡¡ | |¡ | |  |jd ¡¡ | |  |jdd… ¡¡ | |¡ | |  |jdd … ¡¡ |S )Nrï   r  rñ   ÚPr   rG   rä   )r2   r§   r¨   r7   r;   r¹   )r&   rœ   r¯   r=  rñ   r+   r+   r,   Ú_print_jacobi´  s    

z'MathMLPresentationPrinter._print_jacobic             C   s˜   | j  d¡}| j  d¡}| j  d¡}| | j  d¡¡ | |¡ | |  |jd ¡¡ | |  |jdd… ¡¡ | |¡ | |  |jdd … ¡¡ |S )Nrï   r  rñ   r(  r   rG   rÑ   )r2   r§   r¨   r7   r;   r¹   )r&   rœ   r¯   r=  rñ   r+   r+   r,   Ú_print_gegenbauerÀ  s    

z+MathMLPresentationPrinter._print_gegenbauerc             C   s~   | j  d¡}| j  d¡}| j  d¡}| | j  d¡¡ | |¡ | |  |jd ¡¡ | |¡ | |  |jdd … ¡¡ |S )Nrï   rÿ   rñ   rË  r   rG   )r2   r§   r¨   r7   r;   r¹   )r&   rœ   r¯   r=  rñ   r+   r+   r,   Ú_print_chebyshevtÌ  s    

z+MathMLPresentationPrinter._print_chebyshevtc             C   s~   | j  d¡}| j  d¡}| j  d¡}| | j  d¡¡ | |¡ | |  |jd ¡¡ | |¡ | |  |jdd … ¡¡ |S )Nrï   rÿ   rñ   ÚUr   rG   )r2   r§   r¨   r7   r;   r¹   )r&   rœ   r¯   r=  rñ   r+   r+   r,   Ú_print_chebyshevu×  s    

z+MathMLPresentationPrinter._print_chebyshevuc             C   s~   | j  d¡}| j  d¡}| j  d¡}| | j  d¡¡ | |¡ | |  |jd ¡¡ | |¡ | |  |jdd … ¡¡ |S )Nrï   rÿ   rñ   rî  r   rG   )r2   r§   r¨   r7   r;   r¹   )r&   rœ   r¯   r=  rñ   r+   r+   r,   Ú_print_legendreâ  s    

z)MathMLPresentationPrinter._print_legendrec             C   s˜   | j  d¡}| j  d¡}| j  d¡}| | j  d¡¡ | |¡ | |  |jd ¡¡ | |  |jdd… ¡¡ | |¡ | |  |jdd … ¡¡ |S )Nrï   r  rñ   rî  r   rG   rÑ   )r2   r§   r¨   r7   r;   r¹   )r&   rœ   r¯   r=  rñ   r+   r+   r,   Ú_print_assoc_legendreí  s    

z/MathMLPresentationPrinter._print_assoc_legendrec             C   s~   | j  d¡}| j  d¡}| j  d¡}| | j  d¡¡ | |¡ | |  |jd ¡¡ | |¡ | |  |jdd … ¡¡ |S )Nrï   rÿ   rñ   rÈ  r   rG   )r2   r§   r¨   r7   r;   r¹   )r&   rœ   r¯   r=  rñ   r+   r+   r,   Ú_print_laguerreù  s    

z)MathMLPresentationPrinter._print_laguerrec             C   s˜   | j  d¡}| j  d¡}| j  d¡}| | j  d¡¡ | |¡ | |  |jd ¡¡ | |  |jdd… ¡¡ | |¡ | |  |jdd … ¡¡ |S )Nrï   r  rñ   rÈ  r   rG   rÑ   )r2   r§   r¨   r7   r;   r¹   )r&   rœ   r¯   r=  rñ   r+   r+   r,   Ú_print_assoc_laguerre  s    

z/MathMLPresentationPrinter._print_assoc_laguerrec             C   s~   | j  d¡}| j  d¡}| j  d¡}| | j  d¡¡ | |¡ | |  |jd ¡¡ | |¡ | |  |jdd … ¡¡ |S )Nrï   rÿ   rñ   ÚHr   rG   )r2   r§   r¨   r7   r;   r¹   )r&   rœ   r¯   r=  rñ   r+   r+   r,   Ú_print_hermite  s    

z(MathMLPresentationPrinter._print_hermite)F)N)N)r   )N)N)N)‹r.   r/   r0   rT   r  r    r7  r©   r»   rÉ   rF  rÎ   rÔ   rÕ   r×   rØ   rÚ   rÜ   rã   rJ  rÖ   rK  rL  rM  rN  rO  rP  rë   rì   r  r   r!  r]  r`  rb  rc  re  r  r	  rf  r  r  r  rl  r  rm  rt  rv  Z_print_Determinantrw  ry  r{  r  r~  r  r€  r  r  r  r  r‚  Z_print_frozensetr†  r  r‘  r’  r$  r"  r“  r#  r”  rà   râ   r•  r   r¢  Z
_print_MinZ
_print_Maxr£  r  r  r§  rª  r«  r°  r²  r³  r´  rµ  r¶  r¸  r¹  rº  r»  r¼  r¾  rÝ   rÀ  rÂ  Z_print_bellrÃ  rÅ  rÇ  rÉ  rÊ  rÌ  rÎ  rÞ   rÏ  rÒ  rÓ  rÔ  rÖ  r×  rØ  rÚ  rÛ  rÜ  rÝ  rÞ  rà  rá  rã  rå  rç  ré  rê  rë  rì  rí  rï  rð  rñ  ró  rô  rõ  rö  r÷  rù  r+   r+   r+   r,   r%  C  s  L	/		&6	60'			* 		
			r%  Úcontentc             K   s(   |dkrt |ƒ | ¡S t|ƒ | ¡S dS )zŠReturns the MathML representation of expr. If printer is presentation
    then prints Presentation MathML else prints content MathML.
    ÚpresentationN)r%  r@   rU   )r>   Úprinterr8   r+   r+   r,   Úmathml  s    rý  c             K   sL   |dkrt |ƒ}nt|ƒ}| t| ƒ¡}| ¡  | ¡ }| ¡  t|ƒ dS )a  
    Prints a pretty representation of the MathML code for expr. If printer is
    presentation then prints Presentation MathML else prints content MathML.

    Examples
    ========

    >>> ##
    >>> from sympy import print_mathml
    >>> from sympy.abc import x
    >>> print_mathml(x+1) #doctest: +NORMALIZE_WHITESPACE
    <apply>
        <plus/>
        <ci>x</ci>
        <cn>1</cn>
    </apply>
    >>> print_mathml(x+1, printer='presentation')
    <mrow>
        <mi>x</mi>
        <mo>+</mo>
        <mn>1</mn>
    </mrow>

    rû  N)r%  rU   r;   r   rR   ZtoprettyxmlrS   Úprint)r>   rü  r8   rõ   ÚxmlZ
pretty_xmlr+   r+   r,   Úprint_mathml'  s    
r   N)rú  )rú  )$rT   Útypingr   r   ZtDictZsympy.core.mulr   Zsympy.core.singletonr   Zsympy.core.sortingr   Zsympy.core.sympifyr   Zsympy.printing.conventionsr   r	   Zsympy.printing.precedencer
   r   r   Z&sympy.printing.pretty.pretty_symbologyr   Zsympy.printing.printerr   r   Zmpmath.libmpr   r   r   r
  r   rU   r%  rý  r   ZMathMLPrinterr+   r+   r+   r,   Ú<module>   s>   k   G           d

&