a
    ݶDf&                    @  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 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.
    )annotations)Any)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                   @  s^   e Zd ZU dZddddddddddddi d	d
Zded< 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[plainT&#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_numberszdict[str, Any]_default_settingsc                   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/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/sympy/printing/mathml.pywritexml6   s    z4MathMLPrinterBase.__init__.<locals>.RawText.writexmlN)r$   r$   r$   )__name__
__module____qualname__r0   r.   r.   r.   r/   RawText5   s   r4   c                   s     }| |_ j|_|S N)r%   domZownerDocument)r%   rr4   r)   r.   r/   createRawTextNode:   s    z5MathMLPrinterBase.__init__.<locals>.createRawTextNode)r   __init__xml.dom.minidomr"   r#   r6   createTextNode)r)   settingsr"   r#   r9   r.   r8   r/   r:   +   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/   doprintB   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| }|  |D ],}| d|  ||| j | d q4| jr| d t| jdkr| jd j	 j
kr| jd |ddd n4| | | jD ]}|||| || q| | | d| j|f  n| d	|  d S )
N<z %s="">   r   r$   z</%s>%sz/>%s)r&   ZtagNameZ_get_attributeslistkeyssortvalue
childNodeslenZnodeTypeZ	TEXT_NODEr0   )	r)   r*   r+   r,   r-   attrsZa_namesZa_namenoderG   rH   r.   r/   r0   V   s,    



z/MathMLPrinterBase.apply_patch.<locals>.writexmlc                   s    |d|| j |f  d S )Nz%s%s%s)r%   r(   )rH   r.   r/   r0   u   s    )r$   r$   r$   )r$   r$   r$   )r;   rF   r#   rG   rH   r0   _Element_writexml_old_Text_writexml_old)r)   rF   r#   r0   r.   rU   r/   apply_patchL   s    zMathMLPrinterBase.apply_patchc                 C  s$   ddl m}m} | j|_| j|_d S )Nr   )rF   r#   )r;   rF   r#   rV   r0   rW   )r)   rF   r#   r.   r.   r/   restore_patchz   s    zMathMLPrinterBase.restore_patch)N)
r1   r2   r3   __doc__r!   __annotations__r:   rE   rX   rY   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/d0d1d25}|j jD ]}|j}||v rx||   S qx|j j}| S )3)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Numberrk   PowZMaxZMinZAbsAndOrZXorNotZImpliesSymbolMatrixSymbolZRandomSymbolIntegralSumrm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   asinasinhacosacoshatanatanhatan2acotZacothZasecZasechZacscZacschlogEquality
UnequalityGreaterThanLessThanStrictGreaterThanStrictLessThanUnionIntersection	__class____mro__r1   lower)r)   e	translateclsnr.   r.   r/   
mathml_tag   sx    8zMathMLContentPrinter.mathml_tagc           	      C  s@  |  r<| jd}|| jd || |  |S ddlm} ||\}}|tjur| jd}|| jd || 	| || 	| |S |
 \}}|tju rt|dkr| 	|d S | jdkrt| }| jd}|| jd |dkr || 	| |D ]}|| 	| q$|S )	Napplyminusr   fractiondividerL   oldr_   )could_extract_minus_signr6   createElementappendChild
_print_Mulsympy.simplifyr   r   Oner@   as_coeff_mulrR   r   r   
_from_argsas_ordered_factors)	r)   rC   xr   numerdenomcoefftermstermr.   r.   r/   r      s2    


zMathMLContentPrinter._print_MulNc                 C  s
  | j ||d}| |d }g }|dd  D ]}| r| jd}|| jd || || |  |}||d kr|| q,|| | |}||d kr,|| | q,t|dkr|S | jd}|| jd |r||d q|S )Nr   r   rL   r   r   r^   )	_as_ordered_termsr@   r   r6   r   r   appendrR   pop)r)   rC   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}t|j D ]z\}\}}|t|j d krr|dkrr| jd}|| | n,| jd}|| | || | || q.|S )Nr   TzAll 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	piecewiserL   Z	otherwisepiece)	r   Zcond
ValueErrorr6   r   	enumeraterR   r   r@   )r)   rC   rootir   cr   r.   r.   r/   _print_Piecewise  s    z%MathMLContentPrinter._print_Piecewisec              	   C  s^   | j d}t|jD ]B}| j d}t|jD ]}|| |||f  q0|| q|S )NZmatrixZ	matrixrow)r6   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 )NrL   ra   r   r   )qr6   r   r   r<   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lowlimitrL      r   )r6   r   r   r   r@   r   )r)   r   r   x_1x_2r.   r.   r/   _print_Limit8  s    

z!MathMLContentPrinter._print_Limitc                 C  s   | j dS )NZ
imaginaryir6   r   r)   r   r.   r.   r/   _print_ImaginaryUnitF  s    z)MathMLContentPrinter._print_ImaginaryUnitc                 C  s   | j dS )NZ
eulergammar   r   r.   r.   r/   _print_EulerGammaI  s    z&MathMLContentPrinter._print_EulerGammac                 C  s"   | j d}|| j d |S )zwWe use unicode #x3c6 for Greek letter phi as defined here
        https://www.w3.org/2003/entities/2007doc/isogrk1.htmlra   u   φr6   r   r   r<   r)   r   r   r.   r.   r/   _print_GoldenRatioL  s    z'MathMLContentPrinter._print_GoldenRatioc                 C  s   | j dS )NZexponentialer   r   r.   r.   r/   _print_Exp1S  s    z MathMLContentPrinter._print_Exp1c                 C  s   | j dS )Npir   r   r.   r.   r/   	_print_PiV  s    zMathMLContentPrinter._print_Pic                 C  s   | j dS )Ninfinityr   r   r.   r.   r/   _print_InfinityY  s    z$MathMLContentPrinter._print_Infinityc                 C  s   | j dS )NZ
notanumberr   r   r.   r.   r/   
_print_NaN\  s    zMathMLContentPrinter._print_NaNc                 C  s   | j dS )NZemptysetr   r   r.   r.   r/   _print_EmptySet_  s    z$MathMLContentPrinter._print_EmptySetc                 C  s   | j dS )Ntruer   r   r.   r.   r/   _print_BooleanTrueb  s    z'MathMLContentPrinter._print_BooleanTruec                 C  s   | j dS )Nfalser   r   r.   r.   r/   _print_BooleanFalsee  s    z(MathMLContentPrinter._print_BooleanFalsec                 C  s4   | j d}|| j d || j d |S )Nr   r   r   )r6   r   r   r   r.   r.   r/   _print_NegativeInfinityh  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   rL   Zuplimitr   )r6   r   r   r   r@   rR   function)limitsr   Z	bvar_elemlow_elemup_elemr   
lime_recurr)   r.   r/   r   o  s(    



z8MathMLContentPrinter._print_Integral.<locals>.lime_recur)rM   r   reverse)r)   r   r   r.   r   r/   _print_Integraln  s    
z$MathMLContentPrinter._print_Integralc                 C  s
   |  |S r5   )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}t| D ]`\}}|dkrX jd}| jd ||  jd}| j| || q |S  jd}| j| d  |S d S )NrL   zmml:mrowr   zmml:mo mml:mirR   r6   r   r   r   r<   itemsmrowr   itemmomir)   r.   r/   join  s    
z0MathMLContentPrinter._print_Symbol.<locals>.joinc                 S  s   | t v rt | S | S d S r5   r   getsr.   r.   r/   r     s    
z5MathMLContentPrinter._print_Symbol.<locals>.translatec                   s   g | ]} |qS r.   r.   .0supr   r.   r/   
<listcomp>      z6MathMLContentPrinter._print_Symbol.<locals>.<listcomp>c                   s   g | ]} |qS r.   r.   r  subr  r.   r/   r    r  r   zmml:msubzmml:msupzmml:msubsup)r6   r   r   r   namer   r<   )r)   symrj   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   rL   r   r   r   degreera   )	_settingsexpis_Rationalr   r6   r   r   r   r<   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 r5   r6   r   r   r   r<   r   r   r.   r.   r/   _print_Number  s    z"MathMLContentPrinter._print_Numberc                 C  s:   | j | |}t|jt|j}|| j | |S r5   )	r6   r   r   mlib_to_str_mpf_r   _precr   r<   )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}t|jD ]J\}}|| | |dkrL| j d}|| t	| || qL|| || |j |S )Nr   Zpartialdiffr   rL   r  )
r6   r   r   r	   rC   r   reversedvariable_countr@   r   )r)   r   r   Zdiff_symbolr   r  r_   r  r.   r.   r/   _print_Derivative  s    


z&MathMLContentPrinter._print_Derivativec                 C  sD   | j d}|| j | | |jD ]}|| | q*|S Nr   )r6   r   r   r   r   r@   r)   r   r   r   r.   r.   r/   _print_Function   s
    
z$MathMLContentPrinter._print_Functionc                 C  s2   | j | |}|jD ]}|| | q|S r5   )r6   r   r   r   r   r@   r-  r.   r.   r/   _print_Basic  s    
z!MathMLContentPrinter._print_Basicc                 C  sH   | j d}| j | |}|| |jD ]}|| | q.|S r,  )r6   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 r,  )r6   r   r   r   r@   lhsrhsr   r.   r.   r/   _print_Relational  s
    z&MathMLContentPrinter._print_Relationalc                 C  s*   | j d}|D ]}|| | q|S )zgMathML reference for the <list> element:
        https://www.w3.org/TR/MathML2/chapter4.html#contm.listrM   r6   r   r   r@   )r)   seqdom_elementr  r.   r.   r/   _print_list  s    z MathMLContentPrinter._print_listc                 C  s,   | j | |}|| j t| |S r5   r#  r)   r   r6  r.   r.   r/   
_print_int$  s    zMathMLContentPrinter._print_intc                 C  s,   | j d}|jD ]}|| | q|S )Nsetr6   r   r   r   r@   r-  r.   r.   r/   _print_FiniteSet-  s    
z%MathMLContentPrinter._print_FiniteSetc                 C  s>   | j d}|| j d |jD ]}|| | q$|S )Nr   Zsetdiffr6   r   r   r   r@   r-  r.   r.   r/   _print_Complement3  s
    
z&MathMLContentPrinter._print_Complementc                 C  s>   | j d}|| j d |jD ]}|| | q$|S )Nr   Zcartesianproductr=  r-  r.   r.   r/   _print_ProductSet:  s
    
z&MathMLContentPrinter._print_ProductSet)N),r1   r2   r3   rZ   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/  r0  r3  r7  r9  _print_Implies
_print_Not
_print_Xorr<  r>  r?  r.   r.   r.   r/   r\      sR   B#
	8r\   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 ZDdd ZEdd ZFeFZGeFZHdd ZIdd ZJdd ZKeK ZLZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd Zadd ZbebZcdd Zddd Zedd Zfdd Zgdd Zhdd Zidd ZjddÄ Zkddń ZlddǄ ZmddɄ Zndd˄ Zodd̈́ Zpddτ Zqddф Zrddӄ ZsddՄ Ztddׄ Zuddل Zvddۄ Zwdd݄ Zxdd߄ Zydd Zzdd Z{dd Z|dd Z}dd Z~dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d Zd
S (	  MathMLPresentationPrinterzPrints 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-}|j jD ]}|j}||v rx||   S qx|j jd.kr| S |j j}| S )/r]   mnz&#x2192;&dd;r  z&int;z&#x2211;rm   rn   ro   rp   ry   rz   r{   r|   r}   r~   r   =z&#x2260;z&#x2265;z&#x2264;rK   rI   &#x3A6;z&#x3B6;z&#x3B7;z&#x39A;&#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   rk   r   r   r   rm   rn   ro   rp   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 u 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   rP  &InvisibleTimes;r_   &#xD7;dotr   Zldotz&#x2024;)r  
isinstancer   	TypeErrorr.   r  r.   r/   mul_symbol_selection  s    zBMathMLPresentationPrinter.mathml_tag.<locals>.mul_symbol_selectionr   r   )r)   r   r   rX  r   r   r.   r  r/   r   K  sr    2z$MathMLPresentationPrinter.mathml_tagFc                 C  sJ   t |}||k s|s<||kr<| jd}|| | |S | |S d S Nmfenced)r
   r6   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ur jd} jd rTtt| dk rT|	dd  
|} 
|}|| || || |S |  \}}	|tju rt|	dkr| 
|	d  |S  jd	krt|	 }	|dkr( 
|}
 jd
}| j |  ||
 || |	D ]X}| |td  ||	d ks, jd
}| j |  || q,|S )Nr   r   mfracr      bevelledr   rL   r   r  r   r   )r   r   r   r   r6   r   r  rR   r   setAttributer@   r   r   r   r   r   r   r<   r   r^  r   )rC   r  r   r   r   fracr   Zxdenr   r   r   yr   r  r.   r/   multiply  s>    










z6MathMLPresentationPrinter._print_Mul.<locals>.multiplyr  r  -)r6   r   r   r   r<   )r)   rC   re  r  r   r.   r  r/   r     s    "

z$MathMLPresentationPrinter._print_MulNc                 C  s   | j d}| j||d}|| |d  |dd  D ]t}| rr| j d}|| j d | | }n(| j d}|| j d | |}|| || q:|S )Nr  r   r   rL   r  rf  +)r6   r   r   r   r@   r   r<   )r)   rC   r   r  r   r   r   rd  r.   r.   r/   r     s    

z$MathMLPresentationPrinter._print_Addc              	   C  s   | j d}t|jD ]X}| j d}t|jD ]2}| j d}|| |||f  || q0|| q| jd dkr|S | j d}| jd dkr|dd	 |d
d || |S )NZmtableZmtrZmtdr   r$   rZ  r   close]open)	r6   r   r   r   r   r   r@   r  rb  )r)   r   tabler   r   r   rd  r]  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   r_  r   ra  r   r  r  rf  )	r   r6   r   r  rb  r   r@   r   r<   )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 )NrL   r   )r   r@   r   rm  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  limrL   r  r   r   )r6   r   r   r<   r@   r   r   )	r)   r   r  rn  r  r   r   Zarrowr   r.   r.   r/   r     s"    





z&MathMLPresentationPrinter._print_Limitc                 C  s"   | j d}|| j d |S )Nr  z&ImaginaryI;r   r   r.   r.   r/   r   &  s    z.MathMLPresentationPrinter._print_ImaginaryUnitc                 C  s"   | j d}|| j d |S )Nr  rJ  r   r   r.   r.   r/   r   +  s    z,MathMLPresentationPrinter._print_GoldenRatioc                 C  s"   | j d}|| j d |S )Nr  z&ExponentialE;r   r   r.   r.   r/   r   0  s    z%MathMLPresentationPrinter._print_Exp1c                 C  s"   | j d}|| j d |S )Nr  z&pi;r   r   r.   r.   r/   r   5  s    z#MathMLPresentationPrinter._print_Pic                 C  s"   | j d}|| j d |S )Nr  &#x221E;r   r   r.   r.   r/   r   :  s    z)MathMLPresentationPrinter._print_Infinityc                 C  sL   | j d}| j d}|| j d | |}|| || |S )Nr  r  rf  )r6   r   r   r<   r   )r)   r   r  rd  r   r.   r.   r/   r   ?  s    


z1MathMLPresentationPrinter._print_NegativeInfinityc                 C  s"   | j d}|| j d |S )Nr  z&#x210F;r   r   r.   r.   r/   _print_HBarH  s    z%MathMLPresentationPrinter._print_HBarc                 C  s"   | j d}|| j d |S )Nr  rK  r   r   r.   r.   r/   r   M  s    z+MathMLPresentationPrinter._print_EulerGammac                 C  s"   | j d}|| j d |S )Nr  ZTribonacciConstantr   r   r.   r.   r/   _print_TribonacciConstantR  s    z3MathMLPresentationPrinter._print_TribonacciConstantc                 C  s8   | j d}|| |jd  || j d |S )Nr  r   &#x2020;r6   r   r   r@   r   r<   r)   r   r  r.   r.   r/   _print_DaggerW  s    z'MathMLPresentationPrinter._print_Daggerc                 C  sd   | j d}|| |jd  | j d}|| j d || || |jd  |S )Nr  r   r  z&#x2208;rL   rt  )r)   r   r  r  r.   r.   r/   _print_Contains]  s    
z)MathMLPresentationPrinter._print_Containsc                 C  s"   | j d}|| j d |S )Nr  z&#x210B;r   r   r.   r.   r/   _print_HilbertSpacef  s    z-MathMLPresentationPrinter._print_HilbertSpacec                 C  s8   | j d}|| j d || |jd  |S )Nr  z	&#x1D49E;r   r6   r   r   r<   r@   r   ru  r.   r.   r/   _print_ComplexSpacek  s    z-MathMLPresentationPrinter._print_ComplexSpacec                 C  s"   | j d}|| j d |S )Nr  z&#x2131;r   r   r.   r.   r/   _print_FockSpaceq  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  || nt|jD ]}| j d	}|| j |d
  t|d
kr|| t|dkr| j d}|| || |d
  || t|dkrx| j d}|| || |d
  || |d  || qx|| j	|j
td dd t|jD ]B}| j d	}|| j d || || |d  qp|S )Nz&#x222B;z&#x222C;z&#x222D;)rL   r   r   r  r   c                 s  s   | ]}t |d kV  qdS )rL   N)rR   )r  ro  r.   r.   r/   	<genexpr>{  r  z<MathMLPresentationPrinter._print_Integral.<locals>.<genexpr>r  rL   r   r  r  r   Tr\  rH  r   )r6   r   rR   r   allr   r<   r)  r@   r^  r   r   )	r)   rC   Z
intsymbolsr  r  ro  r  r  dr.   r.   r/   r   w  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   rL   r   r  r  rI  rZ  )rM   r   r6   r   r@   r   r<   r   rR   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rt|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}t| D ]`\}}|dkrX jd}| jd ||  jd}| j| || q |S  jd}| j| d  |S d S )NrL   r  r   r  r   r  r   r   r  r.   r/   r    s    
z5MathMLPresentationPrinter._print_Symbol.<locals>.joinc                 S  s   | t v rt | S | S d S r5   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  z;MathMLPresentationPrinter._print_Symbol.<locals>.<listcomp>c                   s   g | ]} |qS r.   r.   r  r  r.   r/   r    r  r  r   r  r  r  boldmathvariant)r   r  r6   r   r   r<   rR   rb  )	r)   r  styler  r  r  r  r  r   r.   r  r/   r    s2    



z'MathMLPresentationPrinter._print_Symbolc                 C  s   | j || jd dS )Nr   )r  )r  r  )r)   r  r.   r.   r/   rA    s    z-MathMLPresentationPrinter._print_MatrixSymbolc                 C  s2   | j d}|dd || |jd  |S )NZmenclosenotationtopr   r6   r   rb  r   r@   r   )r)   rC   encr.   r.   r/   _print_conjugate  s    z*MathMLPresentationPrinter._print_conjugatec                 C  sN   | j d}|| |td  | j d}|| j | || |S )Nr  ZFuncr  )r6   r   r   r^  r   r<   )r)   oprC   rowr  r.   r.   r/   _print_operator_after  s    
z/MathMLPresentationPrinter._print_operator_afterc                 C  s   |  d|jd S )N!r   r  r   r)   rC   r.   r.   r/   _print_factorial  s    z*MathMLPresentationPrinter._print_factorialc                 C  s   |  d|jd S )Nz!!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 )NrZ  r_  Zlinethickness0r   rL   r  )r)   rC   r]  rc  r.   r.   r/   _print_binomial  s    
z)MathMLPresentationPrinter._print_binomialc                 C  sd  |j jrt|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 )NrL   r   r   ZmsqrtZmrootr   r_  r  r   r   )r  r   re   r   r   r  r6   r   r   r@   r!  Zis_negativer^  r   rm  )r)   r   r   rc  r  r.   r.   r/   r"    s^    $




z$MathMLPresentationPrinter._print_Powc                 C  s,   | j | |}|| j t| |S r5   r#  r   r.   r.   r/   r$  K  s    z'MathMLPresentationPrinter._print_Numberc                 C  sL   | j d}|dd |dd || |j || |j |S )NrZ  rh     ⟩rj     ⟨)r6   r   rb  r   r@   rd   rc   )r)   r   r]  r.   r.   r/   _print_AccumulationBoundsP  s    z3MathMLPresentationPrinter._print_AccumulationBoundsc                 C  s  t |jrd}n
| |}| jd}d}t|jD ]\}}||7 }|dkr| jd}| jd}|| j| || || 	| n| jd}|| j| || | 	|}	||	 q4| jd}
|dkr,| jd}| jd}|| j| || || 	| n| jd}|| j| |
| | jd}| jd}||
 || || || 	|j |S )Nz&#x2202;r  r   r   r  r  r_  )
r	   rC   r   r6   r   r)  r*  r   r<   r@   )r)   r   r  r   Zdimr  numr   xxrd  Zmnumr  rc  r.   r.   r/   r+  X  sF    










z+MathMLPresentationPrinter._print_Derivativec                 C  s   | j d}| j d}| |dkrD| jd rD|| j d n|| j | | | j d}|jD ]}|| | qn|| || |S )Nr  r  r   r   r   rZ  )r6   r   r   r  r   r<   r   r@   )r)   r   r  r   rd  r   r.   r.   r/   r.    s    


z)MathMLPresentationPrinter._print_Functionc                 C  sh  t |j}t|j|dd}| jd }| jd}d|v 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   rg  rL   rG  r  r  10z+infz-inf)r   r'  r%  r&  r  r6   r   splitr   r<   r   r   )r)   rC   ZdpsZstr_real	separatorr  Zmantr  rG  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   rZ  rL   ry  )r)   rC   r  r   r  r]  r.   r.   r/   _print_polylog  s    


z(MathMLPresentationPrinter._print_polylogc                 C  sp   | j d}| j d}|| j | | || | j d}|jD ]}|| | qL|| |S )Nr  r  rZ  r6   r   r   r<   r   r   r@   )r)   r   r  r  r]  r   r.   r.   r/   r/    s    


z&MathMLPresentationPrinter._print_Basicc                 C  sB   | j d}| j d}|jD ]}|| | q|| |S )Nr  rZ  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  rZ  rh  }rj  {)ri  (r   )	r6   r   startendrb  r   r@   Z
right_openZ	left_open)r)   r   r  r]  r.   r.   r/   _print_Interval  s     
z)MathMLPresentationPrinter._print_Intervalc                 C  sT   | j d}| j d}|dd |dd || |jd  || |S )Nr  rZ  rh  |rj  r   r  )r)   rC   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  r  ZfrakturrZ  )r6   r   rb  r   r<   r@   )r)   r   rC   r  r  r]  r.   r.   r/   _print_re_im  s    

z&MathMLPresentationPrinter._print_re_imc                 C  s   |  d|jd S )NRr   r  r   r)   rC   r  r.   r.   r/   	_print_re  s    z#MathMLPresentationPrinter._print_rec                 C  s   |  d|jd S )NIr   r  r  r.   r.   r/   	_print_im  s    z#MathMLPresentationPrinter._print_imc                 C  sZ   | j d}| j d}|| j | | || |jD ]}|| | q@|S )Nr  r  r  )r)   r   r  r  r   r.   r.   r/   r0    s    

z(MathMLPresentationPrinter._print_AssocOpc                 C  sz   | j d}|| |jd | |jdd  D ]B}| j d}|| j | | ||}|| || q2|S )Nr  r   rL   r  )r6   r   r   r^  r   r<   )r)   rC   symbolprecr  r   r   rd  r.   r.   r/   _print_SetOp  s    
z&MathMLPresentationPrinter._print_SetOpc                 C  s   t d }| |d|S )Nr   z&#x222A;r   r  r)   rC   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/   _print_Intersection*  s    z-MathMLPresentationPrinter._print_Intersectionc                 C  s   t d }| |d|S )NZ
Complementz&#x2216;r  r  r.   r.   r/   r>  .  s    z+MathMLPresentationPrinter._print_Complementc                 C  s   t d }| |d|S )NZSymmetricDifference&#x2206;r  r  r.   r.   r/   _print_SymmetricDifference2  s    z4MathMLPresentationPrinter._print_SymmetricDifferencec                 C  s   t d }| |d|S )NZ
ProductSetz&#x00d7;r  r  r.   r.   r/   r?  6  s    z+MathMLPresentationPrinter._print_ProductSetc                 C  s   |  |jS r5   )
_print_setr   )r)   r
  r.   r.   r/   r<  :  s    z*MathMLPresentationPrinter._print_FiniteSetc                 C  sN   t |td}| jd}|dd |dd |D ]}|| | q4|S )NkeyrZ  rh  r  rj  r  )sortedr   r6   r   rb  r   r@   )r)   r
  r   r]  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  |dd  D ]j}| j d}|| j | |jr|js| j d}|| | n
| |}|| || ql|S )Nr  r   rZ  rL   r  )r6   r   
is_BooleanZis_Notr   r@   r<   )r)   r   r  r  r]  r   r   rd  r.   r.   r/   _print_LogOpH  s     

z&MathMLPresentationPrinter._print_LogOpc                 C  s  ddl m} ||jkr"| |jS t||r:|  }n
d|fg}| jd}|D ]T\}}t	|j
 }|jdd d t|D ]"\}\}	}
|
dkr|r| jd}|| jd	 || || |	 q|
d
kr| jd}|| jd || || |	 q|rJ| jd}|| jd	 || | jd}|| |
 || | jd}|| jd || || |	 qqT|S )Nr   )Vectorr  c                 S  s   | d   S )Nr   )__str__)r   r.   r.   r/   <lambda>j  r  zAMathMLPresentationPrinter._print_BasisDependent.<locals>.<lambda>r  rL   r  rg  r   rf  rZ  rS  )Zsympy.vectorr  Zzeror@   rV  Zseparater   r6   r   rM   
componentsrO   r   r   r<   )r)   rC   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 )Nr  z&#x2227;r  r   r   r  r)   rC   r   r.   r.   r/   
_print_And  s    z$MathMLPresentationPrinter._print_Andc                 C  s   t |jtd}| |dS )Nr  z&#x2228;r  r  r.   r.   r/   	_print_Or  s    z#MathMLPresentationPrinter._print_Orc                 C  s   t |jtd}| |dS )Nr  z&#x22BB;r  r  r.   r.   r/   rE    s    z$MathMLPresentationPrinter._print_Xorc                 C  s   |  |jdS )Nz&#x21D2;)r  r   r  r.   r.   r/   rC    s    z(MathMLPresentationPrinter._print_Impliesc                 C  s   t |jtd}| |dS )Nr  z&#x21D4;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   rZ  )r6   r   r   r<   r   r  r@   )r)   r   r  r  r   r.   r.   r/   rD    s    

z$MathMLPresentationPrinter._print_Notc                 C  s(   | j d}|| j | | |S Nr  r6   r   r   r<   r   r)   r   r  r.   r.   r/   _print_bool  s    z%MathMLPresentationPrinter._print_boolc                 C  s(   | j d}|| j | | |S r  r  r  r.   r.   r/   _print_NoneType  s    z)MathMLPresentationPrinter._print_NoneTypec                 C  s.  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rt|}t	|t	||f}n6t
|d
krt|}t	|t	|||d f}nt|}|D ]H}||kr| j d}|| j | || q|| | q|S )Nu   …rZ  rh  r  rj  r  r   r   rL      r  )r6   r   rb  r  is_infinitestopstepZis_positiveiternextrR   tupler   r<   r@   )r)   r
  dotsr]  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}|D ]}|| 
| q\|| |S )Nr  r  r  rZ  )r  r   r   r6   r   r   r<   r   funcr   r@   )r)   rC   r   r  r  r]  r  r.   r.   r/   _hprint_variadic_function  s    

z3MathMLPresentationPrinter._hprint_variadic_functionc                 C  s6   | j d}|| d  || |jd  |S )Nr  r   )r6   r   r   r   r@   r   )r)   rC   r  r.   r.   r/   
_print_exp  s    z$MathMLPresentationPrinter._print_expc                 C  sb   | j d}|| |j | j d}|| j | | || || |j |S )Nr  r  )r6   r   r   r@   r1  r<   r   r2  r)   r   r  r   r.   r.   r/   r3    s    
z+MathMLPresentationPrinter._print_Relationalc                 C  s,   | j | |}|| j t| |S r5   r#  r8  r.   r.   r/   r9    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  r  r  )r6   r   _idrb  r   r<   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  r  r  r  ^)r6   r   r  rb  r   r<   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  r  r  r  r  r  r6   r   rb  r   r<   )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  rT  r6   r   Z_expr1Z_expr2r   r^  r   r<   r)   rC   r  Zvec1Z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  &#x2207;rT  r   r6   r   r   r<   r^  Z_exprr   r)   rC   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  r  r   r   r  r  r.   r.   r/   _print_Divergence5  s    

z+MathMLPresentationPrinter._print_Divergencec                 C  sp   | j d}|j}|j}|| |td  | j d}|| j d || || |td  |S )Nr  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  r  r   r  r  r.   r.   r/   _print_GradientK  s    
z)MathMLPresentationPrinter._print_Gradientc                 C  sP   | j d}| j d}|| j d || || |jtd  |S )Nr  r  r  r   r  r  r.   r.   r/   _print_LaplacianS  s    
z*MathMLPresentationPrinter._print_Laplacianc                 C  s.   | j d}|dd || j d |S )Nr  r  normalz&#x2124;r  r   r.   r.   r/   _print_Integers[  s    z)MathMLPresentationPrinter._print_Integersc                 C  s.   | j d}|dd || j d |S )Nr  r  r  z&#x2102;r  r   r.   r.   r/   _print_Complexesa  s    z*MathMLPresentationPrinter._print_Complexesc                 C  s.   | j d}|dd || j d |S )Nr  r  r  z&#x211D;r  r   r.   r.   r/   _print_Realsg  s    z&MathMLPresentationPrinter._print_Realsc                 C  s.   | j d}|dd || j d |S )Nr  r  r  &#x2115;r  r   r.   r.   r/   _print_Naturalsm  s    z)MathMLPresentationPrinter._print_Naturalsc                 C  sV   | j d}| j d}|dd || j d || || tj |S )Nr  r  r  r  r  )r6   r   rb  r   r<   r@   r   ZZero)r)   r   r  r   r.   r.   r/   _print_Naturals0s  s    
z*MathMLPresentationPrinter._print_Naturals0c                 C  s|   |j d |j d  }|j d }| jd}| jd}|dd |dd	 || | || || | |S )
Nr   rL   r   r  rZ  rh  r  rj  r  )r   r6   r   rb  r   r@   )r)   rC   shiftrb   r  r]  r.   r.   r/   _print_SingularityFunction|  s    

z4MathMLPresentationPrinter._print_SingularityFunctionc                 C  s"   | j d}|| j d |S )Nr  NaNr   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}|jdd  D ]}|| | q|| || |S )Nr  r  r   rL   r  rZ  )r6   r   r   r<   r@   r   rR   )r)   r   r  r  r  r  rd  r   r.   r.   r/   _print_number_function  s    


z0MathMLPresentationPrinter._print_number_functionc                 C  s   |  |dS )NBr  r   r.   r.   r/   _print_bernoulli  s    z*MathMLPresentationPrinter._print_bernoullic                 C  s   |  |dS )NrL  r   r   r.   r.   r/   _print_catalan  s    z(MathMLPresentationPrinter._print_catalanc                 C  s   |  |dS )NEr   r   r.   r.   r/   _print_euler  s    z&MathMLPresentationPrinter._print_eulerc                 C  s   |  |dS )NFr   r   r.   r.   r/   _print_fibonacci  s    z*MathMLPresentationPrinter._print_fibonaccic                 C  s   |  |dS )NLr   r   r.   r.   r/   _print_lucas  s    z&MathMLPresentationPrinter._print_lucasc                 C  s   |  |dS )Nz&#x03B3;r   r   r.   r.   r/   _print_stieltjes  s    z*MathMLPresentationPrinter._print_stieltjesc                 C  s   |  |dS )NTr   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  rp  ~r   )r)   r   r   r  r.   r.   r/   _print_ComplexInfinity  s    

z0MathMLPresentationPrinter._print_ComplexInfinityc                 C  s"   | j d}|| j d |S )Nr  z&#x2205;r   r   r.   r.   r/   r     s    z)MathMLPresentationPrinter._print_EmptySetc                 C  s"   | j d}|| j d |S )Nr  z	&#x1D54C;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  rZ  r  rs  	sympy.matricesr   r   r6   r   rV  r   r@   r<   r)   rC   r   matr  r]  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  rZ  r  r
  r  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  rZ  r   )r  r   r   r6   r   rV  r   r@   )r)   rC   r   r  r  r]  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 |
| |d d D ]D}|
| |t|d | jd}|
| jd	 |
| q|
| |d t|d |S )
Nr   )MatMulr  rL   r   r  rf  FrS  )Z!sympy.matrices.expressions.matmulr  r6   r   r   rV  r   r   rM   r   r   r<   r^  r
   )r)   rC   r  r   r   r  r   r.   r.   r/   _print_MatMul  s0    
z'MathMLPresentationPrinter._print_MatMulc                 C  s|   ddl m} |j|j }}| jd}t||sX| jd}|| | || n|| | || | |S )Nr   r  r  rZ  )	r  r   r!  r  r6   r   rV  r   r@   )r)   rC   r   r!  r  r  r]  r.   r.   r/   _print_MatPow  s    
z'MathMLPresentationPrinter._print_MatPowc                 C  s   | j d}|j}|d d D ]D}|| |t|d | j d}|| j d || q|| |d t|d |S )Nr  r   Fr  z&#x2218;)r6   r   r   r   r^  r
   r<   )r)   rC   r   r   r   r  r.   r.   r/   _print_HadamardProduct   s    z0MathMLPresentationPrinter._print_HadamardProductc                 C  s"   | j d}|| j d |S )NrG  z&#x1D7D8r   r)   Zr   r.   r.   r/   _print_ZeroMatrix-  s    z+MathMLPresentationPrinter._print_ZeroMatrixc                 C  s"   | j d}|| j d |S )NrG  z&#x1D7D9r   r  r.   r.   r/   _print_OneMatrix2  s    z*MathMLPresentationPrinter._print_OneMatrixc                 C  s"   | j d}|| j d |S )Nr  z	&#x1D540;r   )r)   r  r   r.   r.   r/   _print_Identity7  s    z)MathMLPresentationPrinter._print_Identityc                 C  sT   | j d}| j d}|dd |dd || |jd  || |S )Nr  rZ  rh  u   ⌋rj  u   ⌊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  rZ  rh  u   ⌉rj  u   ⌈r   r  r  r.   r.   r/   _print_ceilingE  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 )NrZ  r  r   rL   r  z&#x21A6;)r6   r   r   rR   r@   r   r<   )r)   r   r   r  symbolsr  r.   r.   r/   _print_LambdaN  s    




z'MathMLPresentationPrinter._print_Lambdac                 C  s*   | j d}|D ]}|| | q|S rY  r4  )r)   r   r   r   r.   r.   r/   _print_tuple^  s    z&MathMLPresentationPrinter._print_tuplec                 C  s   |  |jS r5   )r@   labelr   r.   r.   r/   _print_IndexedBased  s    z,MathMLPresentationPrinter._print_IndexedBasec                 C  s\   | j d}|| |j t|jdkrF|| |jd  |S || |j |S )Nr  rL   r   )r6   r   r   r@   r!  rR   indicesr   r.   r.   r/   _print_Indexedg  s    z(MathMLPresentationPrinter._print_Indexedc                 C  sv   | j d}|| j|jtd dd | j d}|dd |dd |jD ]}|| | qR|| |S )	Nr  ZAtomTr}  rZ  rh  r$   rj  )	r6   r   r   r^  parentr   rb  r'  r@   )r)   r   r   r]  r   r.   r.   r/   _print_MatrixElementp  s    

z.MathMLPresentationPrinter._print_MatrixElementc                 C  sv   | j d}| j d}|| j d || | j d}|dd |jD ]}|| | qR|| |S )Nr  r  z	&#x1d5a5;rZ  
separatorsr  r6   r   r   r<   rb  r   r@   r)   r   r   r  rd  r   r.   r.   r/   _print_elliptic_f{  s    


z+MathMLPresentationPrinter._print_elliptic_fc                 C  sv   | j d}| j d}|| j d || | j d}|dd |jD ]}|| | qR|| |S )Nr  r  z	&#x1d5a4;rZ  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 |jD ]}|| | qn|| |S )	Nr  r  z	&#x1d6f1;rZ  r   r+  r  z;|)r6   r   r   r<   rR   r   rb  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Eiry  )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   rL   ry  r)   r   r   rd  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   rL   r   ry  r2  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  rL  r   rL   r   ry  r2  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   rL   ry  r2  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   rL   ry  r2  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  r4  r   rL   ry  r2  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  r4  r   rL   r   ry  r2  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   rL   ry  r2  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   rL   r   ry  r2  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   rL   ry  r2  r.   r.   r/   _print_hermite  s    

z(MathMLPresentationPrinter._print_hermite)F)N)N)r   )N)N)N)r1   r2   r3   rZ   r@  r   r^  r   r   r   rm  r   r   r   r   r   r   r   r   rq  r   rr  rv  rw  rx  rz  r{  r   r   r  rA  rB  r  r  r  r  r  r"  r$  r  r+  r.  r(  r  r/  r  r  r  Z_print_Determinantr  r  r  r0  r  r  r  r>  r  r?  r<  r  Z_print_frozensetr  r  r  r  rE  rC  r  rD  r  r   r   r  r  r  Z
_print_MinZ
_print_Maxr  r3  r9  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/  r0  r1  r3  r5  r6  r7  r9  r:  r;  r<  r=  r?  r.   r.   r.   r/   rF  D  s  L	/		&6	60'			* 		
			rF  contentc                 K  s(   |dkrt || S t|| S dS )zReturns the MathML representation of expr. If printer is presentation
    then prints Presentation MathML else prints content MathML.
    presentationN)rF  rE   r\   )rC   printerr=   r.   r.   r/   mathml  s    rC  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>

    rA  N)rF  r\   r@   r   rX   ZtoprettyxmlrY   print)rC   rB  r=   r
  xmlZ
pretty_xmlr.   r.   r/   print_mathml(  s    
rF  N)r@  )r@  )$rZ   
__future__r   typingr   Z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   r\   rF  rC  rF  ZMathMLPrinterr.   r.   r.   r/   <module>   s@   k   G           d

&