
    Ed&                    (   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e          Z G d de          Z G d de          Z  ee          dd            Z!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                   N    e Zd ZdZddddddddddddi d	d
ZddZd Zd Zd ZdS )MathMLPrinterBasez^Contains common code required for MathMLContentPrinter and
    MathMLPresentationPrinter.
    Nzutf-8Fabbreviated[plainT&#xB7;)orderencodingfold_frac_powersfold_func_bracketsfold_short_fracinv_trig_styleln_notationlong_frac_ratio	mat_delimmat_symbol_style
mul_symbolroot_notationsymbol_namesmul_symbol_mathml_numbersc                      t          j         |           ddlm}m}  |             _         G d d|           fd}| j        _        d S )Nr   )DocumentTextc                       e Zd ZddZdS )+MathMLPrinterBase.__init__.<locals>.RawText c                 v    | j         r1|                    d                    || j         |                     d S d S )Nz{}{}{})datawriteformat)selfwriterindent	addindentnewls        5lib/python3.11/site-packages/sympy/printing/mathml.pywritexmlz4MathMLPrinterBase.__init__.<locals>.RawText.writexml5   sC    9 KLLD!I!IJJJJJK K    Nr-   r-   r-   )__name__
__module____qualname__r8    r9   r7   RawTextr,   4   s.        K K K K K Kr9   r?   c                 B                 }| |_         j        |_        |S N)r/   domownerDocument)r/   rr?   r2   s     r7   createRawTextNodez5MathMLPrinterBase.__init__.<locals>.createRawTextNode9   s#    		AAF"hAOHr9   )r   __init__xml.dom.minidomr)   r*   rB   createTextNode)r2   settingsr)   r*   rE   r?   s   `    @r7   rF   zMathMLPrinterBase.__init__*   s    x(((222222228::	K 	K 	K 	K 	Kd 	K 	K 	K
	 	 	 	 	 	 #4r9   c                     t          j        | |          }|                                }|                    dd          }|                                }|S )z2
        Prints the expression as MathML.
        asciixmlcharrefreplace)r   _printtoxmlencodedecode)r2   exprmathMLunistrxmlbstrress         r7   doprintzMathMLPrinterBase.doprintA   sJ     d++--)<==nn
r9   c                     ddl m}m}mm dfd	}|j        | _        ||_        dfd	}|j        | _        ||_        d S )Nr   )Elementr*   Node_write_datar-   c                 d   |                     |dz   | j        z              |                                 }t          |                                          }|                                 |D ]F}|                     d|z              
|||         j                   |                     d           G| j        r|                     d           t          | j                  dk    r?| j        d         j	        	j
        k    r$| j        d                             |ddd           nO|                     |           | j        D ]}|                    |||z   ||           |                     |           |                     d| j        d|           d S |                     d	|z             d S )
N<z %s="">   r   r-   z</z/>%s)r0   tagName_get_attributeslistkeyssortvalue
childNodeslennodeType	TEXT_NODEr8   )r2   r3   r4   r5   r6   attrsa_namesa_namenoderY   rZ   s            r7   r8   z/MathMLPrinterBase.apply_patch.<locals>.writexmlU   s    LL#4555((**E5::<<((GLLNNN! # #X.///FE&M$7888T"""" .S!!!((A- )*3t~E)OA&//BCCCCLL&&& $ I I"FY$6	4I I I ILL((($,,,=>>>>>Vt_-----r9   c                 6     ||| j         |           d S rA   )r/   )r2   r3   r4   r5   r6   rZ   s        r7   r8   z/MathMLPrinterBase.apply_patch.<locals>.writexmlt   s*    KFFDIItt DEEEEEr9   r:   )rG   rX   r*   rY   rZ   r8   _Element_writexml_old_Text_writexml_old)r2   rX   r*   r8   rY   rZ   s       @@r7   apply_patchzMathMLPrinterBase.apply_patchK   s     	EDDDDDDDDDDD	. 	. 	. 	. 	. 	. 	.8 &-%5"#	F 	F 	F 	F 	F 	F"&- r9   c                 F    ddl m}m} | j        |_        | j        |_        d S )Nr   )rX   r*   )rG   rX   r*   ro   r8   rp   )r2   rX   r*   s      r7   restore_patchzMathMLPrinterBase.restore_patchy   s3    111111115/r9   rA   )	r;   r<   r=   __doc___default_settingsrF   rV   rq   rs   r>   r9   r7   r   r      s         
 !#'#%- "4 4 4 4.  ,! ,! ,!\0 0 0 0 0r9   r   c                       e Zd ZdZdZd Zd Zd&dZd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZeZeZd Zd Zd Zd Zd Z d Z!d Z"d  Z#d! Z$d" Z%e"Z&e"Z'e"Z(d# Z)d$ Z*d% Z+dS )'MathMLContentPrinterz}Prints an expression to the Content MathML markup language.

    References: https://www.w3.org/TR/MathML2/chapter4.html
    _mathml_contentc                    i ddddddddd	dd
dddddddddddddddddddddddi d d	d!d"d#d#d$d$d%d%d&d&d'd'd(d(d)d)d*d*d+d+d,d,d-d-d.d.d/d0d1d2d3d4i d5d6d7d8d9d:d;d8d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdX}|j         j        D ]}|j        }||v r
||         c S |j         j        }|                                S )Y)Returns the MathML tag for an expression.Addplusr   times
DerivativediffNumbercnintPowpowerMaxmaxMinminAbsabsAndandOrorXorxorNotnotImpliesimpliesSymbolciMatrixSymbolRandomSymbolIntegralSumsumsincostancotcscsecsinhcoshtanhcothcschsechasinarcsinasinharcsinhacosarccosacosharccoshatanarctanatanharctanhatan2acotarccotacotharccothasecarcsecasecharcsechacscarccscacscharccschloglnEqualityeq
UnequalityneqGreaterThangeqLessThanleqStrictGreaterThangtStrictLessThanltunion	intersect)UnionIntersection	__class____mro__r;   lower)r2   e	translateclsns        r7   
mathml_tagzMathMLContentPrinter.mathml_tag   s   6
66
76
 &6
 d	6

 46
 76
 56
 56
 56
 56
 $6
 56
 56
 y6
 d6
  D!6
" D#6
 6
$ %6
& 5'6
( 5)6
* 5+6
, 5-6
. 5/6
0 516
2 536
4 F56
6 F76
8 F96
: F;6
< F=6
> F?6
@ HA6
B YC6
D HE6
 6
 6
F YG6
H HI6
J YK6
L XM6
N HO6
P YQ6
R HS6
T YU6
V HW6
X YY6
Z 4[6
\ ]6
^ %_6
` 5a6
b c6
d  e6
f dg6
 6
h 'k6
 6
 6
	p ;& 	$ 	$CAI~ $ |###$ K wwyyr9   c                    |                                 rr| j                            d          }|                    | j                            d                     |                    |                     |                      |S ddlm}  ||          \  }}|t          j        ur| j                            d          }|                    | j                            d                     |                    | 	                    |                     |                    | 	                    |                     |S |
                                \  }}|t          j        u r.t          |          dk    r| 	                    |d                   S | j        dk    r&t          j        |                                          }| j                            d          }|                    | j                            d                     |dk    r(|                    | 	                    |                     |D ]*}|                    | 	                    |                     +|S )	Napplyminusr   fractiondivider_   oldr}   )could_extract_minus_signrB   createElementappendChild
_print_Mulsympy.simplifyr   r   OnerM   as_coeff_mulrg   r   r   
_from_argsas_ordered_factors)	r2   rQ   xr   numerdenomcoefftermsterms	            r7   r   zMathMLContentPrinter._print_Mul   s(   ((** 	&&w//AMM$(0099:::MM$//4%00111H++++++x~~u 	&&w//AMM$(00::;;;MM$++e,,---MM$++e,,---H((**uAE> 	)c%jjAo 	) ;;uQx(((: 	?N5))<<>>EH""7++	dh,,W55666A: 	.MM$++e,,--- 	- 	-DMM$++d++,,,,r9   Nc                    |                      ||          }|                     |d                   }g }|dd          D ]}|                                r| j                            d          }|                    | j                            d                     |                    |           |                    |                     |                      |}||d         k    r|                    |           |                    |           |                     |          }||d         k    r(|                    |                     |                      t          |          dk    r|S | j                            d          }|                    | j                            d                     |r*|                    |                    d                     |*|S )Nr   r   r_   r   r   r|   )	_as_ordered_termsrM   r   rB   r   r   appendrg   pop)r2   rQ   r   argslastProcessed	plusNodesargr   s           r7   
_print_AddzMathMLContentPrinter._print_Add   s   %%d%%88DG,,	8 	7 	7C++-- 7H**733dh44W==>>>m,,,dkk3$//000 !$r(? 4$$]333  /// $C 0 0$r(? 7$$T[[%5%5666y>>Q 	!  H""7++	dh,,V44555 	,MM)--**+++  	,r9   c                    |j         d         j        dk    rt          d          | j                            d          }t          |j                   D ]\  }\  }}|t          |j                   dz
  k    rI|dk    rC| j                            d          }|                    |                     |                     nj| j                            d          }|                    |                     |                     |                    |                     |                     |                    |           |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.	piecewiser_   	otherwisepiece)	r   cond
ValueErrorrB   r   	enumeraterg   r   rM   )r2   rQ   rootir   cr   s          r7   _print_Piecewisez%MathMLContentPrinter._print_Piecewise  s1   9R=% 	0  / 0 0 0
 x%%k22"49-- 	$ 	$IAv1C	NNQ&& 219 2..{;;!!$++a..1111..w77!!$++a..111!!$++a..111U####r9   c           	      T   | j                             d          }t          |j                  D ]x}| j                             d          }t          |j                  D ]2}|                    |                     |||f                              3|                    |           y|S )Nmatrix	matrixrow)rB   r   rangerowscolsr   rM   )r2   mr   r  x_rjs         r7   _print_MatrixBasez&MathMLContentPrinter._print_MatrixBase  s    H""8,,qv 	 	A(((55C16]] 6 6AadG 4 45555MM#r9   c                    |j         dk    r[| j                            d          }|                    | j                            t          |j                                       |S | j                            d          }|                    | j                            d                     | j                            d          }|                    | j                            t          |j                                       | j                            d          }|                    | j                            t          |j                                        |                    |           |                    |           |S )Nr_   r   r   r   )qrB   r   r   rH   strp)r2   r   r   xnumxdenoms        r7   _print_Rationalz$MathMLContentPrinter._print_Rational%  s6   3!8 	&&t,,AMM$(11#ac((;;<<<HH""7++	dh,,X66777x%%d++00QS::;;;''--48223qs88<<===	d	fr9   c                    | j                             d          }|                    | j                             |                     |                               | j                             d          }| j                             d          }|                    |                     |j        d                              |                    |                     |j        d                              |                    |           |                    |           |                    |                     |j        d                              |S )Nr   bvarlowlimitr_      r   )rB   r   r   r   rM   r   )r2   r   r   x_1x_2s        r7   _print_Limitz!MathMLContentPrinter._print_Limit7  s   H""7++	dh,,T__Q-?-?@@AAAh$$V,,h$$Z00AF1I..///AF1I..///	c	c	dkk!&),,---r9   c                 6    | j                             d          S )N
imaginaryirB   r   r2   r   s     r7   _print_ImaginaryUnitz)MathMLContentPrinter._print_ImaginaryUnitE      x%%l333r9   c                 6    | j                             d          S )N
eulergammar"  r#  s     r7   _print_EulerGammaz&MathMLContentPrinter._print_EulerGammaH  r%  r9   c                     | j                             d          }|                    | j                             d                     |S )zvWe use unicode #x3c6 for Greek letter phi as defined here
        http://www.w3.org/2003/entities/2007doc/isogrk1.htmlr   u   φrB   r   r   rH   r2   r   r   s      r7   _print_GoldenRatioz'MathMLContentPrinter._print_GoldenRatioK  sA     H""4((	dh--.JKKLLLr9   c                 6    | j                             d          S )Nexponentialer"  r#  s     r7   _print_Exp1z MathMLContentPrinter._print_Exp1R  s    x%%n555r9   c                 6    | j                             d          S )Npir"  r#  s     r7   	_print_PizMathMLContentPrinter._print_PiU  s    x%%d+++r9   c                 6    | j                             d          S )Ninfinityr"  r#  s     r7   _print_Infinityz$MathMLContentPrinter._print_InfinityX      x%%j111r9   c                 6    | j                             d          S )N
notanumberr"  r#  s     r7   
_print_NaNzMathMLContentPrinter._print_NaN[  r%  r9   c                 6    | j                             d          S )Nemptysetr"  r#  s     r7   _print_EmptySetz$MathMLContentPrinter._print_EmptySet^  r6  r9   c                 6    | j                             d          S )Ntruer"  r#  s     r7   _print_BooleanTruez'MathMLContentPrinter._print_BooleanTruea  s    x%%f---r9   c                 6    | j                             d          S )Nfalser"  r#  s     r7   _print_BooleanFalsez(MathMLContentPrinter._print_BooleanFalsed  s    x%%g...r9   c                     | j                             d          }|                    | j                             d                     |                    | j                             d                     |S )Nr   r   r4  )rB   r   r   r+  s      r7   _print_NegativeInfinityz,MathMLContentPrinter._print_NegativeInfinityg  s`    H""7++	dh,,W55666	dh,,Z88999r9   c                 |      fdt          j                  }|                                  |          S )Nc                    j                             d          }|                    j                                                                                j                             d          }|                                        | d         d                              |                    |           t          | d                   dk    rƉj                             d          }|                                        | d         d                              |                    |           j                             d          }|                                        | d         d                              |                    |           t          | d                   dk    rcj                             d          }|                                        | d         d                              |                    |           t          |           dk    r.|                                        j                             n&|                     | dd                               |S )	Nr   r  r      r  r_   uplimitr  )rB   r   r   r   rM   rg   function)limitsr   	bvar_elemlow_elemup_elemr   
lime_recurr2   s        r7   rN  z8MathMLContentPrinter._print_Integral.<locals>.lime_recurn  s   &&w//AMM$(001C1CDDEEE..v66I!!$++fQil";";<<<MM)$$$6!9~~" '811*==$$T[[1%>%>???h'''(00;;##DKKq	!$=$=>>>g&&&6!9~~" '(00;;##DKKq	!$=$=>>>g&&&6{{a 6dkk!*556666jj44555Hr9   )rb   rJ  reverse)r2   r   rJ  rN  s   `` @r7   _print_Integralz$MathMLContentPrinter._print_Integralm  sW    	 	 	 	 	 	 	0 ahz&!!!r9   c                 ,    |                      |          S rA   )rP  r#  s     r7   
_print_SumzMathMLContentPrinter._print_Sum  s     ##A&&&r9   c                 v     j                                                  |                    } fd}d t          |j                  \  }}} |          }fd|D             }fd|D             } j                             d          }|                     j                             |                     |s|s/|                     j                             |                     nH j                             d          }|                    |           |                     ||                     |                    |           n|sc j                             d          }	|	                    |           |	                     ||                     |                    |	           n j                             d          }
|
                    |           |
                     ||                     |
                     ||                     |                    |
           |S )	Nc                    t          |           dk    rj                            d          }t          |           D ]\  }}|dk    r\j                            d          }|                    j                            d                     |                    |           j                            d          }|                    j                            |                     |                    |           |S j                            d          }|                    j                            | d                              |S )Nr_   zmml:mrowr   zmml:mo mml:mirg   rB   r   r  r   rH   itemsmrowr  itemmomir2   s         r7   joinz0MathMLContentPrinter._print_Symbol.<locals>.join  s/   5zzA~ x--j99(// ) )GAt1u -!X33H==tx'>'>s'C'CDDD((,,,//99BNN48#:#:4#@#@AAA$$R((((X++H55tx66uQx@@AAA	r9   c                 @    | t           v rt          j        |           S | S rA   r   getss    r7   r   z5MathMLContentPrinter._print_Symbol.<locals>.translate  %    M! $(+++r9   c                 &    g | ]} |          S r>   r>   .0supr   s     r7   
<listcomp>z6MathMLContentPrinter._print_Symbol.<locals>.<listcomp>  !    333S))C..333r9   c                 &    g | ]} |          S r>   r>   rg  subr   s     r7   ri  z6MathMLContentPrinter._print_Symbol.<locals>.<listcomp>  !    ///3		#///r9   rV  zmml:msubzmml:msupzmml:msubsup)rB   r   r   r	   namer   rH   )r2   symr   r^  ro  superssubsmnamemsubmsupmsubsupr   s   `          @r7   _print_Symbolz"MathMLContentPrinter._print_Symbol  sF   X##DOOC$8$899	 	 	 	 	$	 	 	 -SX66fdy3333F333////$///&&x00$(11$77888 	( %tx66t<<====x--j99  '''  d,,,t$$$$ 
(x--j99  '''  f...t$$$$(00??##E***##DDJJ///##DDLL111w'''	r9   c                    | j         d         rF|j        j        r9|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%   r_   r   r  r  degreer   )	_settingsexpis_Rationalr  rB   r   r   r  rH   r  rM   baser   )r2   r   r   xmldegxmlcnr  s         r7   
_print_PowzMathMLContentPrinter._print_Pow  s    N?+ 	0A 	EGqL	&&w//AMM$(0088999uw!| &//99..t44!!$("9"9#aeg,,"G"GHHH""5)))f%%%MM$++af--...HH""7++h$$T__Q%7%788	c	dkk!&))***	dkk!%(()))r9   c                     | j                             |                     |                    }|                    | j                             t          |                               |S rA   rB   r   r   r   rH   r  r+  s      r7   _print_Numberz"MathMLContentPrinter._print_Number  P    H""4??1#5#566	dh--c!ff55666r9   c                    | j                             |                     |                    }t          |j        t          |j                            }|                    | j                             |                     |S rA   )	rB   r   r   mlib_to_str_mpf_r   _precr   rH   )r2   r   r   repr_es       r7   _print_Floatz!MathMLContentPrinter._print_Float  se    H""4??1#5#566QWhqw&7&788	dh--f55666r9   c                    | j                             d          }|                     |          }t          |j                  rd}|                    | j                             |                     | j                             d          }t          |j                  D ]\  }}|                    |                     |                     |dk    rd| j                             d          }|                    |                     t          |                               |                    |           |                    |           |                    |                     |j                             |S )Nr   partialdiffr  r_   ry  )
rB   r   r   r
   rQ   r   reversedvariable_countrM   r   )r2   r   r   diff_symbolr  rp  r}   ry  s           r7   _print_Derivativez&MathMLContentPrinter._print_Derivative  sC   H""7++ooa((AF## 	('K	dh,,[99:::h$$V,,"1#344 	( 	(JCOODKK,,---qy (//99""4;;wu~~#>#>???'''	c	dkk!&))***r9   c                    | j                             d          }|                    | j                             |                     |                               |j        D ]*}|                    |                     |                     +|S Nr   )rB   r   r   r   r   rM   r2   r   r   r   s       r7   _print_Functionz$MathMLContentPrinter._print_Function  s|    H""7++	dh,,T__Q-?-?@@AAA6 	, 	,CMM$++c**++++r9   c                     | j                             |                     |                    }|j        D ]*}|                    |                     |                     +|S rA   )rB   r   r   r   r   rM   r  s       r7   _print_Basicz!MathMLContentPrinter._print_Basic  sZ    H""4??1#5#5666 	, 	,CMM$++c**++++r9   c                 "   | j                             d          }| j                             |                     |                    }|                    |           |j        D ]*}|                    |                     |                     +|S r  )rB   r   r   r   r   rM   )r2   r   r   r  r   s        r7   _print_AssocOpz#MathMLContentPrinter._print_AssocOp  s    H""7++h$$T__Q%7%788	c6 	, 	,CMM$++c**++++r9   c                 n   | j                             d          }|                    | j                             |                     |                               |                    |                     |j                             |                    |                     |j                             |S r  )rB   r   r   r   rM   lhsrhsr+  s      r7   _print_Relationalz&MathMLContentPrinter._print_Relational  s    H""7++	dh,,T__Q-?-?@@AAA	dkk!%(()))	dkk!%(()))r9   c                     | j                             d          }|D ]*}|                    |                     |                     +|S )zfMathML reference for the <list> element:
        http://www.w3.org/TR/MathML2/chapter4.html#contm.listrb   rB   r   r   rM   )r2   seqdom_elementr[  s       r7   _print_listz MathMLContentPrinter._print_list  sQ     h,,V44 	7 	7D##DKK$5$56666r9   c                     | j                             |                     |                    }|                    | j                             t          |                               |S rA   r  r2   r  r  s      r7   
_print_intzMathMLContentPrinter._print_int#  S    h,,T__Q-?-?@@ 7 7A ? ?@@@r9   c                     | j                             d          }|j        D ]*}|                    |                     |                     +|S )NsetrB   r   r   r   rM   r  s       r7   _print_FiniteSetz%MathMLContentPrinter._print_FiniteSet,  sN    H""5))6 	, 	,CMM$++c**++++r9   c                     | j                             d          }|                    | j                             d                     |j        D ]*}|                    |                     |                     +|S )Nr   setdiffrB   r   r   r   rM   r  s       r7   _print_Complementz&MathMLContentPrinter._print_Complement2  sp    H""7++	dh,,Y778886 	, 	,CMM$++c**++++r9   c                     | j                             d          }|                    | j                             d                     |j        D ]*}|                    |                     |                     +|S )Nr   cartesianproductr  r  s       r7   _print_ProductSetz&MathMLContentPrinter._print_ProductSet9  sq    H""7++	dh,,-?@@AAA6 	, 	,CMM$++c**++++r9   rA   ),r;   r<   r=   rt   printmethodr   r   r   r  r  r  r  r$  r(  r,  r/  r2  r5  r9  r<  r?  rB  rD  rP  rR  rw  _print_MatrixSymbol_print_RandomSymbolr  r  r  r  r  r  r  r  r  r  _print_Implies
_print_Not
_print_Xorr  r  r  r>   r9   r7   rw   rw      sM         $K@ @ @D! ! !F   8  *    $  4 4 44 4 4  6 6 6, , ,2 2 24 4 42 2 2. . ./ / /  " " ":' ' '
6 6 6p ('  .  
    &            
 $NJJ        r9   rw   c                   8   e Zd ZdZdZd ZddZd ZddZd	 Z	dd
Z
d Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZddZd ZeZd  Z d! Z!d" Z"d# Z#d$ Z$d% Z%d& Z&d' Z'd( Z(d) Z)d* Z*d+ Z+d, Z,d- Z-d. Z.dd/Z/e/Z0d0 Z1dd1Z2dd2Z3d3 Z4d4 Z5d5 Z6d6 Z7d7 Z8d8 Z9d9 Z:d: Z;d; Z<e<Z=d< Z>d= Z?d> Z@d? ZAd@ ZBdA ZCdB ZDdC ZEdD ZFeFZGeFZHdE ZIdF ZJdG ZKeKxZLZMdH ZNdI ZOdJ ZPdK ZQdL ZRdM ZSdN ZTdO ZUdP ZVdQ ZWdR ZXdS ZYdT ZZdU Z[dV Z\dW Z]dX Z^dY Z_dZ Z`d[ Zad\ ZbebZcd] Zdd^ Zed_ Zfd` Zgda Zhdb Zidc Zjdd Zkde Zldf Zmdg Zndh Zodi Zpdj Zqdk Zrdl Zsdm Ztdn Zudo Zvdp Zwdq Zxdr Zyds Zzdt Z{du Z|dv Z}dw Z~dx Zdy Zdz Zd{ Zd| Zd} Zd~ Zd Zd Zd Zd Zd ZdS )MathMLPresentationPrinterzPrints an expression to the Presentation MathML markup language.

    References: https://www.w3.org/TR/MathML2/chapter3.html
    _mathml_presentationc                     i dddddddddd	d
dddddddddddddddddddddddi ddd dd!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d8d:d;d<d=d>d?d@dAdBdCdDdEdFd@dAdGdHdI} fdJ}|j         j        D ]}|j        }||v r
||         c S |j         j        dKk    r
 |            S |j         j        }|                                S )Lrz   r   mnLimitz&#x2192;r~   &dd;r   r   r]  r   z&int;r   z&#x2211;r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   =r   z&#x2260;r   z&#x2265;r   z&#x2264;r   r^   r   r\   lerchphi&#x3A6;zetaz&#x3B6;dirichlet_etaz&#x3B7;
elliptic_kz&#x39A;
lowergamma&#x3B3;
uppergammaz&#x393;gammatotientz&#x3D5;reduced_totientz&#x3BB;z&#x3BD;z&#x3A9;r   CWz&#x398;TrueFalseNonez	S&#x2032;z	C&#x2032;)primenu
primeomegafresnelsfresnelcLambertW	HeavisideBooleanTrueBooleanFalseNoneTypemathieusmathieucmathieusprimemathieucprimec                      j         d          j         d         dk    rdS  j         d         dk    rdS  j         d         dk    rdS  j         d         dk    rd	S t           j         d         t                    st           j         d         S )
Nr$   r  &InvisibleTimes;r}   &#xD7;dotr   ldotz&#x2024;)rz  
isinstancer  	TypeError)r2   s   r7   mul_symbol_selectionzBMathMLPresentationPrinter.mathml_tag.<locals>.mul_symbol_selection~  s    |, 4N<0F:4))-8 	4x-6 4x-7 4!z| <cBB 4~l33r9   r   r   )r2   r   r   r  r   r   s   `     r7   r   z$MathMLPresentationPrinter.mathml_tagJ  s{   0
d0
Z0
 &0
 4	0

 d0
 0
 :0
 50
 50
 50
 50
 H0
 Y0
 H0
 Y0
  H!0
" Y#0
 0
$ H%0
& X'0
( )0
* *+0
, :-0
. 
/0
0  10
2 c30
4 	50
6 I70
8 Y90
: );0
< )=0
> )?0
@ YA0
B yC0
D yE0
 0
F !#"!#((_0
 0
 0
	d	4 	4 	4 	4 	4 ;& 	$ 	$CAI~ $ |###$ ;5( 	*'')))K wwyyr9   Fc                     t          |          }||k     s|sJ||k    rD| j                            d          }|                    |                     |                     |S |                     |          S Nmfenced)r   rB   r   r   rM   )r2   r[  levelstrictprec_valbracs         r7   parenthesizez&MathMLPresentationPrinter.parenthesize  s{    )$//u 	%v 	%8u3D 	%8)))44DT[[..///K;;t$$$r9   c                 Z     fd} j                             d          }|                                rj j                             d          }|                     j                             d                     |                    |            || |          }n |||          }|S )Nc                    ddl m}  ||           \  }}|t          j        urȉj                            d          }j        d         r6t          t          |                     dk     r|	                    dd           
                    |          }
                    |          }|                    |           |                    |           |                    |           |S |                                 \  }}	|t          j        u rCt          |	          dk    r0|                    
                    |	d                              |S j        d	k    r&t          j        |	                                          }	|dk    r
                    |          }
j                            d
          }|                    j                                                |                                |                    |
           |                    |           |	D ]}|                                        |t(          d                              ||	d         k    soj                            d
          }|                    j                                                |                                |                    |           |S )Nr   r   mfracr      bevelledr>  r_   r   r\  r   r   )r   r   r   r   rB   r   rz  rg   r  setAttributerM   r   r   r   r   r   r   rH   r   r  r   )rQ   rZ  r   r   r   fracr  xdenr   r   r   yr   r2   s                r7   multiplyz6MathMLPresentationPrinter._print_Mul.<locals>.multiply  s   //////#8D>>LE5AE! 	x--g66>"34 :SYY!9K :%%j&999{{5)){{5))  &&&  &&&  &&&,,..LE5~ #e**/   U1X!6!6777zU" Cu--@@BBz $KK&&H**400dh55dood6K6KLLMMM  ###  ### ( (  !2!24E9J!K!KLLLuRy( (..t44AMM$("9"9$//$:O:O"P"PQQQ$$Q'''Kr9   rZ  r\  -)rB   r   r   r   rH   )r2   rQ   r  rZ  r   s   `    r7   r   z$MathMLPresentationPrinter._print_Mul  s    !	 !	 !	 !	 !	D x%%f--((** 	(&&t,,AMM$(11#66777Q8TE4((DD8D$''Dr9   Nc                    | j                             d          }|                     ||          }|                    |                     |d                              |dd          D ]}|                                r^| j                             d          }|                    | j                             d                     |                     |           }n\| j                             d          }|                    | j                             d                     |                     |          }|                    |           |                    |           |S )NrZ  r   r   r_   r\  r  +)rB   r   r   r   rM   r   rH   )r2   rQ   r   rZ  r   r   r   r  s           r7   r   z$MathMLPresentationPrinter._print_Add  sD   x%%f--%%d%%88T!W--...8 	  	 C++-- 	%H**400dh55c::;;;KK%% H**400dh55c::;;;KK$$QQr9   c           	         | j                             d          }t          |j                  D ]}| j                             d          }t          |j                  D ]a}| j                             d          }|                    |                     |||f                              |                    |           b|                    |           | j        d         dk    r|S | j                             d          }| j        d         dk    r,|                    dd	           |                    d
d           |                    |           |S )Nmtablemtrmtdr"   r-   r  r   close]open)	rB   r   r  r  r  r   rM   rz  r  )r2   r  tabler  r   r  r  r  s           r7   r  z+MathMLPresentationPrinter._print_MatrixBase  sH   &&x00qv 	! 	!A&&u--A16]] ! !H**511dkk!AqD'22333a    a    >+&", 	Lx%%i00>+&#- 	+gs+++fc***r9   c                    |j         dk     r	|j          }n|j         }| j                            d          }|s| j        d         r|                    dd           |                    |                     |                     |                    |                     |j                             |j         dk     r| j                            d          }| j                            d          }|                    | j                            d                     |                    |           |                    |           |S |S )	Nr   r  r   r  r>  rZ  r\  r  )	r  rB   r   rz  r  r   rM   r  rH   )r2   r   foldedr  r   rZ  r\  s          r7   _get_printed_Rationalz/MathMLPresentationPrinter._get_printed_Rational  s*   37 	AAAH""7++ 	/T^$56 	/NN:v...	dkk!nn%%%	dkk!#&&'''37 	8))&11D''--BNN4822377888R   QKHr9   c                     |j         dk    r|                     |j                  S |                     || j        d                   S )Nr_   r   )r  rM   r  r  rz  r#  s     r7   r  z)MathMLPresentationPrinter._print_Rational  sB    3!8 	$;;qs###))!T^<M-NOOOr9   c                    | j                             d          }| j                             d          }| j                             d          }|                    | j                             d                     | j                             d          }|                     |j        d                   }| j                             d          }|                    | j                             |                     |                               |                     |j        d                   }|                    |           |                    |           |                    |           |                    |           |                    |           |                    |           |                    |                     |j        d                              |S )	NrZ  munderr]  limr_   r\  r  r   )rB   r   r   rH   rM   r   r   )	r2   r   rZ  r  r]  r   r  arrowr  s	            r7   r  z&MathMLPresentationPrinter._print_Limit  s   x%%f--''11X##D))
tx..u55666H""6**kk!&)$$&&t,,$(11$//!2D2DEEFFFkk!&)$$	c	e	c21   QVAY//000r9   c                     | j                             d          }|                    | j                             d                     |S )Nr]  z&ImaginaryI;r*  r+  s      r7   r$  z.MathMLPresentationPrinter._print_ImaginaryUnit%  s>    H""4((	dh--n==>>>r9   c                     | j                             d          }|                    | j                             d                     |S )Nr]  r  r*  r+  s      r7   r,  z,MathMLPresentationPrinter._print_GoldenRatio*  >    H""4((	dh--i88999r9   c                     | j                             d          }|                    | j                             d                     |S )Nr]  z&ExponentialE;r*  r+  s      r7   r/  z%MathMLPresentationPrinter._print_Exp1/  s?    H""4((	dh--.>??@@@r9   c                     | j                             d          }|                    | j                             d                     |S )Nr]  z&pi;r*  r+  s      r7   r2  z#MathMLPresentationPrinter._print_Pi4  s>    H""4((	dh--f55666r9   c                     | j                             d          }|                    | j                             d                     |S )Nr]  &#x221E;r*  r+  s      r7   r5  z)MathMLPresentationPrinter._print_Infinity9  >    H""4((	dh--j99:::r9   c                 F   | j                             d          }| j                             d          }|                    | j                             d                     |                     |          }|                    |           |                    |           |S )NrZ  r\  r  )rB   r   r   rH   r5  )r2   r   rZ  r  r   s        r7   rD  z1MathMLPresentationPrinter._print_NegativeInfinity>  s    x%%f--H""4((	dh--c22333  ##r9   c                     | j                             d          }|                    | j                             d                     |S )Nr]  z&#x210F;r*  r+  s      r7   _print_HBarz%MathMLPresentationPrinter._print_HBarG  r  r9   c                     | j                             d          }|                    | j                             d                     |S )Nr]  r  r*  r+  s      r7   r(  z+MathMLPresentationPrinter._print_EulerGammaL  r  r9   c                     | j                             d          }|                    | j                             d                     |S )Nr]  TribonacciConstantr*  r+  s      r7   _print_TribonacciConstantz3MathMLPresentationPrinter._print_TribonacciConstantQ  s?    H""4((	dh--.BCCDDDr9   c                     | j                             d          }|                    |                     |j        d                              |                    | j                             d                     |S )Nru  r   &#x2020;rB   r   r   rM   r   rH   r2   r   ru  s      r7   _print_Daggerz'MathMLPresentationPrinter._print_DaggerV  sf    x%%f--QVAY//00000<<===r9   c                    | j                             d          }|                    |                     |j        d                              | j                             d          }|                    | j                             d                     |                    |           |                    |                     |j        d                              |S )NrZ  r   r\  z&#x2208;r_   r  )r2   r   rZ  r\  s       r7   _print_Containsz)MathMLPresentationPrinter._print_Contains\  s    x%%f--QVAY//000X##D))
tx..z::;;;QVAY//000r9   c                     | j                             d          }|                    | j                             d                     |S )Nr]  z&#x210B;r*  r+  s      r7   _print_HilbertSpacez-MathMLPresentationPrinter._print_HilbertSpacee  r  r9   c                     | j                             d          }|                    | j                             d                     |                    |                     |j        d                              |S )Nru  z	&#x1D49E;r   rB   r   r   rH   rM   r   r  s      r7   _print_ComplexSpacez-MathMLPresentationPrinter._print_ComplexSpacej  sf    x%%f--00==>>>QVAY//000r9   c                     | j                             d          }|                    | j                             d                     |S )Nr]  z&#x2131;r*  r+  s      r7   _print_FockSpacez*MathMLPresentationPrinter._print_FockSpacep  r  r9   c                    dddd}| j                             d          }t          |j                  dk    rt	          d |j        D                       rv| j                             d          }|                    | j                             |t          |j                                                |                    |           nt          |j                  D ]}| j                             d          }|                    | j                             |d	                              t          |          d	k    r|                    |           t          |          d
k    rr| j                             d          }|                    |           |                    |                     |d	                              |                    |           t          |          dk    r| j                             d          }|                    |           |                    |                     |d	                              |                    |                     |d
                              |                    |           |                    | 	                    |j
        t          d         d                     t          |j                  D ]}| j                             d          }|                    | j                             d                     |                    |           |                    |                     |d                              |S )Nz&#x222B;z&#x222C;z&#x222D;)r_   r  rG  rZ  rG  c              3   <   K   | ]}t          |          d k    V  dS )r_   N)rg   )rg  r  s     r7   	<genexpr>z<MathMLPresentationPrinter._print_Integral.<locals>.<genexpr>z  s,      (N(N3SQ(N(N(N(N(N(Nr9   r\  r_   r  ru  rv  r   Tr  r  r   )rB   r   rg   rJ  allr   rH   r  rM   r  rI  r   )	r2   rQ   
intsymbolsrZ  r\  r  ru  rv  ds	            r7   rP  z)MathMLPresentationPrinter._print_Integralv  s   #
zBB
x%%f--t{q  	.S(N(N$+(N(N(N%N%N 	.''--BNN4822:c$+>N>N3OPPQQQR      ,, . .X++D11tx66z!}EEFFFs88q= )$$R(((s88q= +811&99D$$R((($$T[[Q%8%8999$$T***s88q= ."h44Y??G''+++''CF(;(;<<<''CF(;(;<<<$$W---**4=*U:K26 + 8 8 	9 	9 	9 DK(( 	2 	2C&&t,,AMM$(11&99:::QT[[Q001111r9   c                 V   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 )	N
munderoverr   r_   r  r\  rZ  r  r  )rb   rJ  rB   r   rM   r   rH   r   rg   r  rI  )r2   r   rJ  subsuprL  rM  summandlowvarequalrZ  fences               r7   rR  z$MathMLPresentationPrinter._print_Sum  s/   ah''55;;vay|,,++fQil++(((..DH33DOOA4F4FGGHHHh$$V,,kk&)A,''&&t,,$(11#66777!!!7###37###x%%f--   s1:1$ 	$T[[445555H**955Edkk!*55666U###r9   r   c                    	  fd}d 	t          |j                  \  }}} 	|          }	fd|D             }	fd|D             } j                            d          }|                     j                            |                     t          |          dk    ret          |          dk    r|}n j                            d          }|                    |           |                     ||                     nt          |          dk    rN j                            d          }|                    |           |                     ||                     nk j                            d	          }|                    |           |                     ||                     |                     ||                     |d
k    r|                    dd
           |S )Nc                    t          |           dk    rj                            d          }t          |           D ]\  }}|dk    r\j                            d          }|                    j                            d                     |                    |           j                            d          }|                    j                            |                     |                    |           |S j                            d          }|                    j                            | d                              |S )Nr_   rZ  r   r\  rU  r]  rW  rX  s         r7   r^  z5MathMLPresentationPrinter._print_Symbol.<locals>.join  s/   5zzA~ x--f55(// ) )GAt1u -!X33D99tx'>'>s'C'CDDD((,,,//55BNN48#:#:4#@#@AAA$$R((((X++D11tx66uQx@@AAA	r9   c                 @    | t           v rt          j        |           S | S rA   r`  rb  s    r7   r   z:MathMLPresentationPrinter._print_Symbol.<locals>.translate  rd  r9   c                 &    g | ]} |          S r>   r>   rf  s     r7   ri  z;MathMLPresentationPrinter._print_Symbol.<locals>.<listcomp>  rj  r9   c                 &    g | ]} |          S r>   r>   rl  s     r7   ri  z;MathMLPresentationPrinter._print_Symbol.<locals>.<listcomp>  rn  r9   r]  r   rt  ru  rv  boldmathvariant)r	   ro  rB   r   r   rH   rg   r  )
r2   rp  styler^  ro  rq  rr  rs  r   r   s
   `        @r7   rw  z'MathMLPresentationPrinter._print_Symbol  s   	 	 	 	 	$	 	 	 -SX66fdy3333F333////$///&&t,,$(11$77888v;;! 	,4yyA~ *H**622e$$$dd4jj))))4yyA~ ,H**622e$$$dd6ll++++H**955e$$$dd4jj)))dd6ll+++F? 	2NN=&111r9   c                 F    |                      || j        d                   S )Nr#   )r<  )rw  rz  )r2   rp  s     r7   r  z-MathMLPresentationPrinter._print_MatrixSymbol  s/    !!#(,7I(J " L L 	Lr9   c                     | j                             d          }|                    dd           |                    |                     |j        d                              |S )Nmenclosenotationtopr   rB   r   r  r   rM   r   )r2   rQ   encs      r7   _print_conjugatez*MathMLPresentationPrinter._print_conjugate  sV    h$$Z00U+++DIaL11222
r9   c                 Z   | j                             d          }|                    |                     |t          d                              | j                             d          }|                    | j                             |                     |                    |           |S )NrZ  Funcr\  )rB   r   r   r  r   rH   )r2   oprQ   rowr\  s        r7   _print_operator_afterz/MathMLPresentationPrinter._print_operator_after  s    h$$V,,))$
60BCCDDDX##D))
tx..r22333
r9   c                 D    |                      d|j        d                   S )N!r   rI  r   r2   rQ   s     r7   _print_factorialz*MathMLPresentationPrinter._print_factorial  s    ))#ty|<<<r9   c                 D    |                      d|j        d                   S )Nz!!r   rL  rM  s     r7   _print_factorial2z+MathMLPresentationPrinter._print_factorial2  s    ))$	!===r9   c                    | j                             d          }| j                             d          }|                    dd           |                    |                     |j        d                              |                    |                     |j        d                              |                    |           |S )Nr  r  linethickness0r   r_   rB  )r2   rQ   r  r  s       r7   _print_binomialz)MathMLPresentationPrinter._print_binomial  s    x%%i00x%%g../3///TYq\22333TYq\22333r9   c                 	   |j         j        rt          |j         j                  dk    rj|j         j        dk    rY| j        d         rK|j         j        dk    rG| j                            d          }|                    | 	                    |j
                             |j         j        dk    ry| j                            d          }|                    | 	                    |j
                             |                    | 	                    |j         j                             |j         j        dk    rY| 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
                             n| j                            d          }|                    |                     |j
        t          d	                              |                    | 	                    |j                               |                    |           |S | j                            d          }|                    |                     |j
        t          d	                              |                    | 	                    |j                              |S )Nr_   r%   r  msqrtmrootr   r  ru  r   r   )r{  r|  r   r  r  rz  rB   r   r   rM   r}  is_negativer  r   r  )r2   r   r   r  rA  s        r7   r  z$MathMLPresentationPrinter._print_Pow  s    E 	#aeg,,!"3 	1 	/	uw!| 3H**733dkk!&11222uw!| 4H**733dkk!&11222dkk!%'22333uw"} x--g66  Q000  ###5 	A 	u  h,,W55A///H**622d//
58IJJKKKd88!%$(N3E$FH H I I I"""
H**622d//
58IJJKKKd88$(N3E$FH H I I I5 
	h,,W55A///5B; 'OODKK$7$78888..v66AMM$"3"3AFJu<M"N"NOOOMM$++quf"5"5666OOA&&&
H""6**	d''
50ABBCCC	dkk!%(()))r9   c                     | j                             |                     |                    }|                    | j                             t          |                               |S rA   r  r+  s      r7   r  z'MathMLPresentationPrinter._print_NumberJ  r  r9   c                 F   | j                             d          }|                    dd           |                    dd           |                    |                     |j                             |                    |                     |j                             |S )Nr  r     ⟩r     ⟨)rB   r   r  r   rM   r   r   )r2   r  r  s      r7   _print_AccumulationBoundsz3MathMLPresentationPrinter._print_AccumulationBoundsO  s    x%%i00'8,,,&(+++QU++,,,QU++,,,r9   c                    t          |j                  rd}n|                     |          }| j                            d          }d}t          |j                  D ]6\  }}||z  }|dk    r| j                            d          }| j                            d          }|                    | j                            |                     |                    |           |                    | 	                    |                     nG| j                            d          }|                    | j                            |                     |                    |           | 	                    |          }	|                    |	           8| j                            d          }
|dk    r| j                            d          }| j                            d          }|                    | j                            |                     |                    |           |                    | 	                    |                     nG| j                            d          }|                    | j                            |                     |
                    |           | j                            d          }| j                            d          }|                    |
           |                    |           |                    |           |                    | 	                    |j                             |S )Nz&#x2202;rZ  r   r  ru  r\  r  )
r
   rQ   r   rB   r   r  r  r   rH   rM   )r2   r   r,  r  dimrp  numr   xxr  mnumrZ  r  s                r7   r  z+MathMLPresentationPrinter._print_DerivativeW  s   AF## 	#AA""A H""6** !122 	 	HC3JCax :H**622X++D11tx66q99:::b!!!dkk#..////H**400dh55a88999MM!C  AMM!x%%f--!8 	6&&v..A''--BNN4822155666MM"MM$++c**++++&&t,,AMM$(11!44555x%%f--x%%g.. 	QV,,---r9   c                    | j                             d          }| j                             d          }|                     |          dk    r;| j        d         r.|                    | j                             d                     n@|                    | j                             |                     |                               | j                             d          }|j        D ]*}|                    |                     |                     +|                    |           |                    |           |S )NrZ  r]  r   r    r   r  )rB   r   r   rz  r   rH   r   rM   )r2   r   rZ  r   r  r   s         r7   r  z)MathMLPresentationPrinter._print_Function  s   x%%f--H""4((??1& 	G4>-+H 	GMM$(11$778888MM$(11$//!2D2DEEFFFH""9--6 	, 	,CMM$++c**++++r9   c                 L   t          |j                  }t          |j        |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    r|                     d           S | j                            d	          }|                    | j        	                    |                     |S )NT)strip_zerosr'   rZ  r   r   r  r_   r  r\  ru  10z+infz-inf)r   r  r  r  rz  rB   r   splitr   rH   r5  rD  )r2   rQ   dpsstr_real	separatorrZ  mantr{  r  r\  ru  s              r7   r  z&MathMLPresentationPrinter._print_Float  sa   $*%%tz3DAAA N#>?	x%%f--(? 	"..--KT31v} !""g''--BNN4822488999R   ''--BNN48229==>>>R   8))&11D''--BNN4822488999R   ''--BNN4822377888R   T"""K 	''--- 	//555''--BNN48228<<===Ir9   c                 z   | j                             d          }| j                             d          }| j                             d          }|                    | j                             d                     |                    |           |                    |                     |j        d                              |                    |           | j                             d          }|                    |                     |j        d                              |                    |           |S )NrZ  rt  r]  Lir   r  r_   r"  )r2   rQ   rZ  r  r]  r  s         r7   _print_polylogz(MathMLPresentationPrinter._print_polylog  s   x%%f--H""6**X##D))
tx..t44555	b	dkk$)A,//000x%%i00TYq\22333r9   c                    | j                             d          }| j                             d          }|                    | j                             |                     |                               |                    |           | j                             d          }|j        D ]*}|                    |                     |                     +|                    |           |S )NrZ  r]  r  rB   r   r   rH   r   r   rM   )r2   r   rZ  r]  r  r   s         r7   r  z&MathMLPresentationPrinter._print_Basic  s    x%%f--X##D))
tx..tq/A/ABBCCCx%%i006 	/ 	/CT[[--....r9   c                     | j                             d          }| j                             d          }|j        D ]*}|                    |                     |                     +|                    |           |S )NrZ  r  r  )r2   r   rZ  r   r   s        r7   _print_Tuplez&MathMLPresentationPrinter._print_Tuple  sw    x%%f--H""9--6 	, 	,CMM$++c**++++r9   c                    | j                             d          }| j                             d          }|j        |j        k    rZ|                    dd           |                    dd           |                    |                     |j                             n|j        r|                    dd           n|                    dd           |j        r|                    dd	           n|                    dd
           |                    |                     |j                             |                    |                     |j                             |                    |           |S )NrZ  r  r  }r  {)r  (r   )	rB   r   startendr  r   rM   
right_open	left_open)r2   r  rZ  r  s       r7   _print_Intervalz)MathMLPresentationPrinter._print_Interval  s]   x%%f--x%%i007ae 	1gs+++fc***T[[112222| 0!!'3////!!'3///{ /!!&#....!!&#...T[[11222T[[//000r9   c                 V   | j                             d          }| j                             d          }|                    dd           |                    dd           |                    |                     |j        d                              |                    |           |S )NrZ  r  r  |r  r   rB  )r2   rQ   r{  rZ  r   s        r7   
_print_Absz$MathMLPresentationPrinter._print_Abs  s    x%%f--H""9--	w$$$	vs###	dkk$)A,//000r9   c                    | j                             d          }| j                             d          }|                    dd           |                    | j                             |                     |                    |           | j                             d          }|                    |                     |                     |                    |           |S )NrZ  r]  r;  frakturr  )rB   r   r  r   rH   rM   )r2   r  rQ   rZ  r]  r  s         r7   _print_re_imz&MathMLPresentationPrinter._print_re_im   s    x%%f--X##D))
y111
tx..q11222x%%i00T**+++r9   c                 D    |                      d|j        d                   S )NRr   r  r   r2   rQ   r{  s      r7   	_print_rez#MathMLPresentationPrinter._print_re        dil333r9   c                 D    |                      d|j        d                   S )NIr   r  r  s      r7   	_print_imz#MathMLPresentationPrinter._print_im  r  r9   c                 |   | j                             d          }| j                             d          }|                    | j                             |                     |                               |                    |           |j        D ]*}|                    |                     |                     +|S )NrZ  r]  rp  )r2   r   rZ  r]  r   s        r7   r  z(MathMLPresentationPrinter._print_AssocOp  s    x%%f--X##D))
tx..tq/A/ABBCCC6 	/ 	/CT[[--....r9   c                    | j                             d          }|                    |                     |j        d         |                     |j        dd          D ]}| j                             d          }|                    | j                             |                     |                     ||          }|                    |           |                    |           |S )NrZ  r   r_   r\  )rB   r   r   r  r   rH   )r2   rQ   symbolprecrZ  r   r   r  s           r7   _print_SetOpz&MathMLPresentationPrinter._print_SetOp  s    x%%f--**49Q<>>???9QRR= 	  	 C&&t,,AMM$(11&99:::!!#t,,AQQr9   c                 J    t           d         }|                     |d|          S )Nr   z&#x222A;r   r  r2   rQ   r  s      r7   _print_Unionz&MathMLPresentationPrinter._print_Union%  s$    %g.  z4888r9   c                 J    t           d         }|                     |d|          S )Nr   z&#x2229;r  r  s      r7   _print_Intersectionz-MathMLPresentationPrinter._print_Intersection)  s$    %n5  z4888r9   c                 J    t           d         }|                     |d|          S )N
Complementz&#x2216;r  r  s      r7   r  z+MathMLPresentationPrinter._print_Complement-  $    %l3  z4888r9   c                 J    t           d         }|                     |d|          S )NSymmetricDifference&#x2206;r  r  s      r7   _print_SymmetricDifferencez4MathMLPresentationPrinter._print_SymmetricDifference1  s%    %&;<  z4888r9   c                 J    t           d         }|                     |d|          S )N
ProductSetz&#x00d7;r  r  s      r7   r  z+MathMLPresentationPrinter._print_ProductSet5  r  r9   c                 6    |                      |j                  S rA   )
_print_setr   )r2   rc  s     r7   r  z*MathMLPresentationPrinter._print_FiniteSet9  s    qv&&&r9   c                    t          |t                    }| j                            d          }|                    dd           |                    dd           |D ]*}|                    |                     |                     +|S )Nkeyr  r  rt  r  ru  )sortedr   rB   r   r  r   rM   )r2   rc  rY  r  r[  s        r7   r  z$MathMLPresentationPrinter._print_set<  s    q.///x%%i00'3'''&#&&& 	0 	0DT[[..////r9   c                 N   | j                             d          }|d         j        rk|d         j        s^| j                             d          }|                    |                     |d                              |                    |           n.|                    |                     |d                              |dd          D ]}| j                             d          }|                    | j                             |                     |j        rJ|j        sC| j                             d          }|                    |                     |                     n|                     |          }|                    |           |                    |           |S )NrZ  r   r  r_   r\  )rB   r   
is_Booleanis_Notr   rM   rH   )r2   r   r  rZ  r  r   r   r  s           r7   _print_LogOpz&MathMLPresentationPrinter._print_LogOpG  s   x%%f--7 	3d1gn 	38)))44DT[[a11222T""""T[[a112228 		  		 C&&t,,AMM$(11&99:::~ %cj %H**955dkk#..////KK$$QQr9   c                 n   ddl m} ||j        k    r|                     |j                  S t	          ||          r'|                                                                }nd|fg}| j                            d          }|D ]\  }}t          |j
                                                  }|                    d            t          |          D ][\  }\  }	}
|
dk    r|r\| j                            d          }|                    | j                            d                     |                    |           |                    |                     |	                     |
d	k    r| j                            d          }|                    | j                            d
                     |                    |           |                    |                     |	                     "|r\| j                            d          }|                    | j                            d                     |                    |           | j                            d          }|                    |                     |
                     |                    |           | j                            d          }|                    | j                            d                     |                    |           |                    |                     |	                     ]|S )Nr   )VectorrZ  c                 6    | d                                          S )Nr   )__str__)r   s    r7   <lambda>zAMathMLPresentationPrinter._print_BasisDependent.<locals>.<lambda>i  s    1Q4<<>> r9   r  r_   r\  r  r   r  r  r  )sympy.vectorr  zerorM   r  separaterY  rB   r   rb   
componentsrd   r  r   rH   )r2   rQ   r  rY  rZ  systemvect
inneritemsr  kvr\  mbracs                r7   _print_BasisDependentz/MathMLPresentationPrinter._print_BasisDependent[  s   ''''''49 	*;;ty)))dF## 	 MMOO))++EEYKEx%%f--! 	5 	5LFDdo335566JOO"9"9O:::&z22 5 5	6Aq6 5 -!X33D99tx'>'>s'C'CDDD((,,,$$T[[^^4444"W 5//55BNN48#:#:3#?#?@@@$$R((($$T[[^^4444 -!X33D99tx'>'>s'C'CDDD((,,, H229==E%%dkk!nn555$$U+++//55BNN48#:#:;M#N#NOOO$$R((($$T[[^^4444/50 r9   c                 d    t          |j        t                    }|                     |d          S )Nr  z&#x2227;r  r   r   r  r2   rQ   r   s      r7   
_print_Andz$MathMLPresentationPrinter._print_And  -    di%5666  z222r9   c                 d    t          |j        t                    }|                     |d          S )Nr  z&#x2228;r  r  s      r7   	_print_Orz#MathMLPresentationPrinter._print_Or  r  r9   c                 d    t          |j        t                    }|                     |d          S )Nr  z&#x22BB;r  r  s      r7   r  z$MathMLPresentationPrinter._print_Xor  r  r9   c                 8    |                      |j        d          S )Nz&#x21D2;)r  r   rM  s     r7   r  z(MathMLPresentationPrinter._print_Implies  s      J777r9   c                 d    t          |j        t                    }|                     |d          S )Nr  z&#x21D4;r  r  s      r7   _print_Equivalentz+MathMLPresentationPrinter._print_Equivalent  r  r9   c                    | j                             d          }| j                             d          }|                    | j                             d                     |                    |           |j        d         j        rN| j                             d          }|                    |                     |j        d                              n |                     |j        d                   }|                    |           |S )NrZ  r\  z&#xAC;r   r  )rB   r   r   rH   r   r  rM   )r2   r   rZ  r\  r   s        r7   r  z$MathMLPresentationPrinter._print_Not  s    x%%f--X##D))
tx..x88999F1I  	'&&y11AMM$++afQi001111AF1I&&Ar9   c                     | j                             d          }|                    | j                             |                     |                               |S Nr]  rB   r   r   rH   r   r2   r   r]  s      r7   _print_boolz%MathMLPresentationPrinter._print_bool  J    X##D))
tx..tq/A/ABBCCC	r9   c                     | j                             d          }|                    | j                             |                     |                               |S r  r  r  s      r7   _print_NoneTypez)MathMLPresentationPrinter._print_NoneType  r  r9   c                    d}| j                             d          }|                    dd           |                    dd           |j        j        r(|j        j        r|j        j        r|ddd	|f}n|d	dd|f}n|j        j        r||d         |j        z
  |d         f}n|j        j        r/t          |          }t          |          t          |          |f}nXt          |          d
k    r6t          |          }t          |          t          |          ||d         f}nt          |          }|D ]}||k    r]| j                             d          }|                    | j                             |                     |                    |           e|                    |                     |                     |S )Nu   …r  r  rt  r  ru  r   r   r_      r]  )rB   r   r  rx  is_infinitestopstepis_positiveiternextrg   tupler   rH   rM   )r2   rc  dotsr  printsetitelr]  s           r7   _print_Rangez&MathMLPresentationPrinter._print_Range  s   x%%i00'3'''&#&&&7 	 16#5 	 v! 0Q4/Ar4/W  		 QrUQV^QrU2HHV 	 aBBxxb4/HHVVaZ 	 aBBxxb426HHQxxH 	2 	2BTz 2X++D11tx66t<<===  $$$$  R1111r9   c                 (   t          |j        t                    }| j                            d          }| j                            d          }|                    | j                            t          |j                  	                                                     |                    |           | j                            d          }|D ]*}|                    | 
                    |                     +|                    |           |S )Nr  rZ  r\  r  )r  r   r   rB   r   r   rH   r  funcr   rM   )r2   rQ   r   rZ  r\  r  r  s          r7   _hprint_variadic_functionz3MathMLPresentationPrinter._hprint_variadic_function  s    di%5666x%%f--X##D))
tx..DI/E/E/G/GHHIIIx%%i00 	2 	2FT[[001111r9   c                     | j                             d          }|                    |                     d                      |                    |                     |j        d                              |S )Nru  r   )rB   r   r   r/  rM   r   )r2   rQ   ru  s      r7   
_print_expz$MathMLPresentationPrinter._print_exp  sd    x%%f--))$//000TYq\22333r9   c                    | j                             d          }|                    |                     |j                             | j                             d          }|                    | j                             |                     |                               |                    |           |                    |                     |j                             |S )NrZ  r\  )rB   r   r   rM   r  rH   r   r  r2   r   rZ  r   s       r7   r  z+MathMLPresentationPrinter._print_Relational  s    x%%f--QU++,,,H""4((	dh--dooa.@.@AABBBQU++,,,r9   c                     | j                             |                     |                    }|                    | j                             t          |                               |S rA   r  r  s      r7   r  z$MathMLPresentationPrinter._print_int  r  r9   c                 6   | j                             d          }|j        \  }}| j                             d          }|                    dd           |                    | j                             |j        |                              |                    |           | j                             d          }|                    dd           |                    | j                             |j                             |                    |           |S )Nrt  r]  r;  r:  )rB   r   _idr  r   rH   _variable_names_name)r2   r   rt  indexr  r]  s         r7   _print_BaseScalarz+MathMLPresentationPrinter._print_BaseScalar  s    x%%f--vX##D))
v...
tx..v/Ee/LMMNNNX##D))
v...
tx..v|<<===r9   c                 L   | j                             d          }|j        \  }}| j                             d          }| j                             d          }|                    dd           |                    | j                             |j        |                              |                    |           | j                             d          }|                    | j                             d                     |                    |           |                    |           | j                             d          }|                    dd           |                    | j                             |j                             |                    |           |S )Nrt  moverr]  r;  r:  r\  ^)rB   r   r  r  r   rH   _vector_namesr  )r2   r   rt  r  r  r  r]  r\  s           r7   _print_BaseVectorz+MathMLPresentationPrinter._print_BaseVector  sc   x%%f--v&&w//X##D))
v...
tx..v/CE/JKKLLL"X##D))
tx..s33444"X##D))
v...
tx..v|<<===r9   c                    | j                             d          }| j                             d          }|                    dd           |                    | j                             d                     |                    |           | j                             d          }|                    | j                             d                     |                    |           |S )Nr  r]  r;  r:  rS  r\  r  rB   r   r  r   rH   )r2   r   r  r]  r\  s        r7   _print_VectorZeroz+MathMLPresentationPrinter._print_VectorZero  s    &&w//X##D))
v...
tx..s33444"X##D))
tx..s33444"r9   c                    | j                             d          }|j        }|j        }|                    |                     |t          d                              | j                             d          }|                    | j                             d                     |                    |           |                    |                     |t          d                              |S )NrZ  r   r\  r  rB   r   _expr1_expr2r   r  r   rH   r2   rQ   rZ  vec1vec2r\  s         r7   _print_Crossz&MathMLPresentationPrinter._print_Cross      x%%f--{{**4E1BCCDDDX##D))
tx..x88999**4E1BCCDDDr9   c                    | j                             d          }| j                             d          }|                    | j                             d                     |                    |           | j                             d          }|                    | j                             d                     |                    |           |                    |                     |j        t          d                              |S )NrZ  r\  &#x2207;r  r   rB   r   r   rH   r  _exprr   r2   rQ   rZ  r\  s       r7   _print_Curlz%MathMLPresentationPrinter._print_Curl)      x%%f--X##D))
tx..z::;;;X##D))
tx..x88999**4:z%7HIIJJJr9   c                    | j                             d          }| j                             d          }|                    | j                             d                     |                    |           | j                             d          }|                    | j                             d                     |                    |           |                    |                     |j        t          d                              |S )NrZ  r\  r  r   r   r  r  s       r7   _print_Divergencez+MathMLPresentationPrinter._print_Divergence4  r  r9   c                    | j                             d          }|j        }|j        }|                    |                     |t          d                              | j                             d          }|                    | j                             d                     |                    |           |                    |                     |t          d                              |S )NrZ  r   r\  r   r  r  s         r7   
_print_Dotz$MathMLPresentationPrinter._print_Dot?  r  r9   c                 d   | j                             d          }| j                             d          }|                    | j                             d                     |                    |           |                    |                     |j        t          d                              |S )NrZ  r\  r  r   r  r  s       r7   _print_Gradientz)MathMLPresentationPrinter._print_GradientJ      x%%f--X##D))
tx..z::;;;**4:z%7HIIJJJr9   c                 d   | j                             d          }| j                             d          }|                    | j                             d                     |                    |           |                    |                     |j        t          d                              |S )NrZ  r\  r  r   r  r  s       r7   _print_Laplacianz*MathMLPresentationPrinter._print_LaplacianR  r  r9   c                     | j                             d          }|                    dd           |                    | j                             d                     |S )Nr]  r;  normalz&#x2124;r  r+  s      r7   _print_Integersz)MathMLPresentationPrinter._print_IntegersZ  R    H""4((	}h///	dh--j99:::r9   c                     | j                             d          }|                    dd           |                    | j                             d                     |S )Nr]  r;  r  z&#x2102;r  r+  s      r7   _print_Complexesz*MathMLPresentationPrinter._print_Complexes`  r  r9   c                     | j                             d          }|                    dd           |                    | j                             d                     |S )Nr]  r;  r  z&#x211D;r  r+  s      r7   _print_Realsz&MathMLPresentationPrinter._print_Realsf  r  r9   c                     | j                             d          }|                    dd           |                    | j                             d                     |S )Nr]  r;  r  &#x2115;r  r+  s      r7   _print_Naturalsz)MathMLPresentationPrinter._print_Naturalsl  r  r9   c                    | j                             d          }| j                             d          }|                    dd           |                    | j                             d                     |                    |           |                    |                     t          j                             |S )Nrt  r]  r;  r  r  )rB   r   r  r   rH   rM   r   Zero)r2   r   rm  r   s       r7   _print_Naturals0z*MathMLPresentationPrinter._print_Naturals0r  s    h$$V,,H""4((	}h///	dh--j99:::AF++,,,
r9   c                    |j         d         |j         d         z
  }|j         d         }| j                            d          }| j                            d          }|                    dd           |                    dd	           |                    |                     |                     |                    |           |                    |                     |                     |S )
Nr   r_   r  ru  r  r  r[  r  r\  )r   rB   r   r  r   rM   )r2   rQ   shiftr   rh  r  s         r7   _print_SingularityFunctionz4MathMLPresentationPrinter._print_SingularityFunction{  s    	!ty|+	!h$$V,,x%%i00'8,,,&(+++U++,,,E**+++
r9   c                     | j                             d          }|                    | j                             d                     |S )Nr]  NaNr*  r+  s      r7   r9  z$MathMLPresentationPrinter._print_NaN  s>    H""4((	dh--e44555r9   c                    | j                             d          }| j                             d          }|                    | j                             |                     |                    |           |                    |                     |j        d                              t          |j                  dk    r|S | j                             d          }| j                             d          }|j        dd          D ]*}|                    |                     |                     +|                    |           |                    |           |S )Nrt  r]  r   r_   rZ  r  )rB   r   r   rH   rM   r   rg   )r2   r   ro  rm  r]  rZ  r  r   s           r7   _print_number_functionz0MathMLPresentationPrinter._print_number_function  s1    h$$V,,X##D))
tx..t44555AF1I..///qv;;! 	Jx%%f--H""9--6!"": 	, 	,CMM$++c**++++r9   c                 .    |                      |d          S )NBr  r#  s     r7   _print_bernoulliz*MathMLPresentationPrinter._print_bernoulli      **1c222r9   c                 .    |                      |d          S )Nr  r"  r#  s     r7   _print_catalanz(MathMLPresentationPrinter._print_catalan  r$  r9   c                 .    |                      |d          S )NEr"  r#  s     r7   _print_eulerz&MathMLPresentationPrinter._print_euler  r$  r9   c                 .    |                      |d          S )NFr"  r#  s     r7   _print_fibonacciz*MathMLPresentationPrinter._print_fibonacci  r$  r9   c                 .    |                      |d          S )NLr"  r#  s     r7   _print_lucasz&MathMLPresentationPrinter._print_lucas  r$  r9   c                 .    |                      |d          S )Nz&#x03B3;r"  r#  s     r7   _print_stieltjesz*MathMLPresentationPrinter._print_stieltjes  s    **1j999r9   c                 .    |                      |d          S )NTr"  r#  s     r7   _print_tribonacciz+MathMLPresentationPrinter._print_tribonacci  r$  r9   c                    | j                             d          }| j                             d          }|                    | j                             d                     |                    |           | j                             d          }|                    | j                             d                     |                    |           |S )Nr  r\  r  ~r*  )r2   r   r   r\  s       r7   _print_ComplexInfinityz0MathMLPresentationPrinter._print_ComplexInfinity  s    H""7++X##D))
tx..z::;;;	bX##D))
tx..s33444	br9   c                     | j                             d          }|                    | j                             d                     |S )Nr\  z&#x2205;r*  r+  s      r7   r<  z)MathMLPresentationPrinter._print_EmptySet  r  r9   c                     | j                             d          }|                    | j                             d                     |S )Nr\  z	&#x1D54C;r*  r+  s      r7   _print_UniversalSetz-MathMLPresentationPrinter._print_UniversalSet  >    H""4((	dh--k::;;;r9   c                 ,   ddl m} |j        }| j                            d          }t          ||          sX| j                            d          }|                    |                     |                     |                    |           n(|                    |                     |                     | j                            d          }|                    | j                            d                     |                    |           |S )Nr   r   ru  r  r\  r  	sympy.matricesr   r   rB   r   r  r   rM   rH   r2   rQ   r   matrh  r  r\  s          r7   _print_Adjointz(MathMLPresentationPrinter._print_Adjoint  s    //////hh$$V,,#|,, 	.8)))44DT[[--...OOD!!!!OODKK,,---X##D))
tx..z::;;;
r9   c                 ,   ddl m} |j        }| j                            d          }t          ||          sX| j                            d          }|                    |                     |                     |                    |           n(|                    |                     |                     | j                            d          }|                    | j                            d                     |                    |           |S )Nr   r=  ru  r  r\  r3  r>  r@  s          r7   _print_Transposez*MathMLPresentationPrinter._print_Transpose  s    //////hh$$V,,#|,, 	.8)))44DT[[--...OOD!!!!OODKK,,---X##D))
tx..s33444
r9   c                    ddl m} |j        }| j                            d          }t          ||          sX| j                            d          }|                    |                     |                     |                    |           n(|                    |                     |                     |                    |                     d                     |S )Nr   r=  ru  r  r   )r?  r   r   rB   r   r  r   rM   )r2   rQ   r   rA  rh  r  s         r7   _print_Inversez(MathMLPresentationPrinter._print_Inverse  s    //////hh$$V,,#|,, 	.8)))44DT[[--...OOD!!!!OODKK,,---B(((
r9   c           	         ddl m} | j                            d          }|j        }t          |d         t                    r3|d                                         t          |dd                    z   }nt          |          }t          ||          r|	                                r|d         dk    r|dd          }n|d          |d<   | j                            d          }|
                    | j                            d                     |
                    |           |d d         D ]}|
                    |                     |t          |          d                     | j                            d          }|
                    | j                            d	                     |
                    |           |
                    |                     |d         t          |          d                     |S )
Nr   )MatMulrZ  r_   r   r\  r  Fr  )!sympy.matrices.expressions.matmulrH  rB   r   r   r  r   r   rb   r   r   rH   r  r   )r2   rQ   rH  r   r   r\  r   s          r7   _print_MatMulz'MathMLPresentationPrinter._print_MatMul  s   <<<<<<H""6**yd1gs## 	7--//$tABBx..@DD::DdF## 	(E(E(G(G 	Aw"} #ABBx7(Q''--BNN4822377888MM"9 	 	CMM$++C1G1M1M,13 3 4 4 4''--BNN48223EFFGGGMM"	d''R2H2N2N(-/ / 	0 	0 	0r9   c                    ddl m} |j        |j        }}| j                            d          }t          ||          sX| j                            d          }|                    |                     |                     |                    |           n(|                    |                     |                     |                    |                     |                     |S )Nr   r=  ru  r  )	r?  r   r}  r{  rB   r   r  r   rM   )r2   rQ   r   r}  r{  rh  r  s          r7   _print_MatPowz'MathMLPresentationPrinter._print_MatPow  s    //////Itxch$$V,,$-- 	/8)))44DT[[..///OOD!!!!OODKK--...C(()))
r9   c           	         | j                             d          }|j        }|d d         D ]}|                    |                     |t          |          d                     | j                             d          }|                    | j                             d                     |                    |           |                    |                     |d         t          |          d                     |S )NrZ  r   Fr\  z&#x2218;)rB   r   r   r   r  r   rH   )r2   rQ   r   r   r   r\  s         r7   _print_HadamardProductz0MathMLPresentationPrinter._print_HadamardProduct  s    H""6**y9 	 	CMM!!#'=d'C'CUKKM M M''--BNN4822:>>???MM"	d2h(>t(D(DeLL	N 	N 	Nr9   c                     | j                             d          }|                    | j                             d                     |S )Nr  z&#x1D7D8r*  r2   Zr   s      r7   _print_ZeroMatrixz+MathMLPresentationPrinter._print_ZeroMatrix,  r  r9   c                     | j                             d          }|                    | j                             d                     |S )Nr  z&#x1D7D9r*  rP  s      r7   _print_OneMatrixz*MathMLPresentationPrinter._print_OneMatrix1  r  r9   c                     | j                             d          }|                    | j                             d                     |S )Nr]  z	&#x1D540;r*  )r2   r  r   s      r7   _print_Identityz)MathMLPresentationPrinter._print_Identity6  r;  r9   c                 V   | j                             d          }| j                             d          }|                    dd           |                    dd           |                    |                     |j        d                              |                    |           |S )NrZ  r  r  u   ⌋r  u   ⌊r   rB  r  s       r7   _print_floorz&MathMLPresentationPrinter._print_floor;      x%%f--H""9--	w)))	vx(((	dkk!&),,---r9   c                 V   | j                             d          }| j                             d          }|                    dd           |                    dd           |                    |                     |j        d                              |                    |           |S )NrZ  r  r  u   ⌉r  u   ⌈r   rB  r  s       r7   _print_ceilingz(MathMLPresentationPrinter._print_ceilingD  rY  r9   c                    | j                             d          }| j                             d          }|j        d         }t          |          dk    r|                     |d                   }n|                     |          }|                    |           | j                             d          }|                    | j                             d                     |                    |           |                    |                     |j        d                              |                    |           |S )Nr  rZ  r   r_   r\  z&#x21A6;)rB   r   r   rg   rM   r   rH   )r2   r   r   rZ  symbolsr\  s         r7   _print_Lambdaz'MathMLPresentationPrinter._print_LambdaM  s   H""9--x%%f--&)w<<1 	+kk'!*--GGkk'**G!!!X##D))
tx..z::;;;QVAY//000	dr9   c                     | j                             d          }|D ]*}|                    |                     |                     +|S r  r  )r2   r   r   r  s       r7   _print_tuplez&MathMLPresentationPrinter._print_tuple]  sJ    H""9-- 	* 	*AMM$++a..))))r9   c                 6    |                      |j                  S rA   )rM   labelr#  s     r7   _print_IndexedBasez,MathMLPresentationPrinter._print_IndexedBasec  s    {{17###r9   c                    | j                             d          }|                    |                     |j                             t          |j                  dk    r5|                    |                     |j        d                              |S |                    |                     |j                             |S )Nrt  r_   r   )rB   r   r   rM   r}  rg   indicesr+  s      r7   _print_Indexedz(MathMLPresentationPrinter._print_Indexedf  s    H""6**	dkk!&))***qy>>Q 	MM$++ail33444H	dkk!),,---r9   c                    | j                             d          }|                    |                     |j        t
          d         d                     | j                             d          }|                    dd           |                    dd           |j        D ]*}|                    |                     |                     +|                    |           |S )	Nrt  AtomTr)  r  r  r-   r  )	rB   r   r   r  parentr   r  re  rM   )r2   r   r   r  r  s        r7   _print_MatrixElementz.MathMLPresentationPrinter._print_MatrixElemento  s    H""6**	d''*V2Dt'TTUUUx%%i00'2&&&&"%%% 	- 	-AT[[^^,,,,	dr9   c                    | j                             d          }| j                             d          }|                    | j                             d                     |                    |           | j                             d          }|                    dd           |j        D ]*}|                    |                     |                     +|                    |           |S )NrZ  r]  z	&#x1d5a5;r  
separatorsr~  rB   r   r   rH   r  r   rM   r2   r   r   r]  r  r  s         r7   _print_elliptic_fz+MathMLPresentationPrinter._print_elliptic_fz      H""6**X##D))
tx..{;;<<<	bH""9--	|S))) 	* 	*AMM$++a..))))	ar9   c                    | j                             d          }| j                             d          }|                    | j                             d                     |                    |           | j                             d          }|                    dd           |j        D ]*}|                    |                     |                     +|                    |           |S )NrZ  r]  z	&#x1d5a4;r  rl  r~  rm  rn  s         r7   _print_elliptic_ez+MathMLPresentationPrinter._print_elliptic_e  rp  r9   c                 >   | j                             d          }| j                             d          }|                    | j                             d                     |                    |           | j                             d          }t	          |j                  dk    r|                    dd           n|                    dd           |j        D ]*}|                    |                     |                     +|                    |           |S )	NrZ  r]  z	&#x1d6f1;r  r  rl  r~  z;|)rB   r   r   rH   rg   r   r  rM   rn  s         r7   _print_elliptic_piz,MathMLPresentationPrinter._print_elliptic_pi  s    H""6**X##D))
tx..{;;<<<	bH""9--qv;;! 	/NN<----NN<... 	* 	*AMM$++a..))))	ar9   c                 L   | j                             d          }| j                             d          }|                    | j                             d                     |                    |           |                    |                     |j                             |S )NrZ  r]  Eir"  )r2   r   r   r]  s       r7   	_print_Eiz#MathMLPresentationPrinter._print_Ei  s    H""6**X##D))
tx..t44555	b	dkk!&))***r9   c                     | j                             d          }| j                             d          }| j                             d          }|                    | j                             d                     |                    |           |                    |                     |j        d                              |                    |           |                    |                     |j        dd                               |S )NrZ  rt  r\  r(  r   r_   r"  r2   r   r   r  r\  s        r7   _print_expintz'MathMLPresentationPrinter._print_expint      H""6**H""6**X##D))
tx..s33444	b	dkk!&),,---	a	dkk!&*--...r9   c                    | j                             d          }| j                             d          }| j                             d          }|                    | j                             d                     |                    |           |                    |                     |j        d                              |                    |                     |j        dd                              |                    |           |                    |                     |j        dd                               |S )NrZ  rv  r\  Pr   r_   rG  r"  ry  s        r7   _print_jacobiz'MathMLPresentationPrinter._print_jacobi      H""6**H""9--X##D))
tx..s33444	b	dkk!&),,---	dkk!&1+..///	a	dkk!&*--...r9   c                    | j                             d          }| j                             d          }| j                             d          }|                    | j                             d                     |                    |           |                    |                     |j        d                              |                    |                     |j        dd                              |                    |           |                    |                     |j        dd                               |S )NrZ  rv  r\  r  r   r_   r  r"  ry  s        r7   _print_gegenbauerz+MathMLPresentationPrinter._print_gegenbauer  r  r9   c                     | j                             d          }| j                             d          }| j                             d          }|                    | j                             d                     |                    |           |                    |                     |j        d                              |                    |           |                    |                     |j        dd                               |S )NrZ  rt  r\  r3  r   r_   r"  ry  s        r7   _print_chebyshevtz+MathMLPresentationPrinter._print_chebyshevt  r{  r9   c                     | j                             d          }| j                             d          }| j                             d          }|                    | j                             d                     |                    |           |                    |                     |j        d                              |                    |           |                    |                     |j        dd                               |S )NrZ  rt  r\  Ur   r_   r"  ry  s        r7   _print_chebyshevuz+MathMLPresentationPrinter._print_chebyshevu  r{  r9   c                     | j                             d          }| j                             d          }| j                             d          }|                    | j                             d                     |                    |           |                    |                     |j        d                              |                    |           |                    |                     |j        dd                               |S )NrZ  rt  r\  r}  r   r_   r"  ry  s        r7   _print_legendrez)MathMLPresentationPrinter._print_legendre  r{  r9   c                    | j                             d          }| j                             d          }| j                             d          }|                    | j                             d                     |                    |           |                    |                     |j        d                              |                    |                     |j        dd                              |                    |           |                    |                     |j        dd                               |S )NrZ  rv  r\  r}  r   r_   r  r"  ry  s        r7   _print_assoc_legendrez/MathMLPresentationPrinter._print_assoc_legendre  r  r9   c                     | j                             d          }| j                             d          }| j                             d          }|                    | j                             d                     |                    |           |                    |                     |j        d                              |                    |           |                    |                     |j        dd                               |S )NrZ  rt  r\  r.  r   r_   r"  ry  s        r7   _print_laguerrez)MathMLPresentationPrinter._print_laguerre  r{  r9   c                    | j                             d          }| j                             d          }| j                             d          }|                    | j                             d                     |                    |           |                    |                     |j        d                              |                    |                     |j        dd                              |                    |           |                    |                     |j        dd                               |S )NrZ  rv  r\  r.  r   r_   r  r"  ry  s        r7   _print_assoc_laguerrez/MathMLPresentationPrinter._print_assoc_laguerre  r  r9   c                     | j                             d          }| j                             d          }| j                             d          }|                    | j                             d                     |                    |           |                    |                     |j        d                              |                    |           |                    |                     |j        dd                               |S )NrZ  rt  r\  Hr   r_   r"  ry  s        r7   _print_hermitez(MathMLPresentationPrinter._print_hermite  r{  r9   )FrA   )r   )r;   r<   r=   rt   r  r   r  r   r   r  r  r  r  r$  r,  r/  r2  r5  rD  r  r(  r  r  r  r   r#  r%  rP  rR  rw  r  r  rD  rI  rN  rP  rT  r  r  r]  r  r  r  rn  r  rr  r|  r  _print_Determinantr  r  r  r  r  r  r  r  r  r  r  r  _print_frozensetr  r  r  r  r  r  r  r  r  r?  rB  r  r  r  
_print_Min
_print_Maxr  r  r  r  r  r  r  r   r  r  r  r
  r  r  r  r  r  r  r9  r  r#  _print_bellr&  r)  r,  r/  r1  r4  r7  r<  r:  rB  rD  rF  rJ  rL  rN  rR  rT  rV  rX  r[  r^  r`  rc  rf  rj  ro  rr  rt  rw  rz  r~  r  r  r  r  r  r  r  r  r>   r9   r7   r  r  C  s         )KJ J JX% % % %- - -^   (  $   (P P P  ,  
  
  
  
  
    
  
  
      
    $ $ $L  >4 4 4 4lL L L (    = = => > >  4 4 4l  
  . . .`  % % %N  	 	 	    0    $	 	 	4 4 4 44 4 4 4  	 	 	9 9 99 9 99 9 99 9 99 9 9' ' '   "  (' ' 'T3 3 33 3 33 3 38 8 83 3 3    
 %%  
  @
 
 
 87J      
    $	 	 		 	 		 	 		 	 		 	 	              
 
 
  
  &3 3 3 #K3 3 33 3 33 3 33 3 3: : :3 3 3    
  
        :      
  
  
         $ $ $  	 	 	
 
 

 
 
    	 	 	
 
 

 
 
	 	 		 	 		 	 	
 
 
	 	 	
 
 
	 	 	 	 	r9   r  contentc                     |dk    r"t          |                              |           S t          |                              |           S )zReturns the MathML representation of expr. If printer is presentation
    then prints Presentation MathML else prints content MathML.
    presentation)r  rV   rw   )rQ   printerrI   s      r7   mathmlr    sI    
 .  <(22::4@@@#H--55d;;;r9   c                 *   |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  rw   rM   r   rq   toprettyxmlrs   print)rQ   r  rI   rc  xml
pretty_xmls         r7   print_mathmlr  '  s    2 .  +%h// **
((74==
!
!CMMOOO""JOO	*r9   N)r  )$rt   typingr   r   tDictsympy.core.mulr   sympy.core.singletonr   sympy.core.sortingr   sympy.core.sympifyr   sympy.printing.conventionsr	   r
   sympy.printing.precedencer   r   r   &sympy.printing.pretty.pretty_symbologyr   sympy.printing.printerr   r   mpmath.libmpr   r   r   r  r   rw   r  r  r  MathMLPrinterr>   r9   r7   <module>r     s    & % % % % % % %       " " " " " " / / / / / / & & & & & & H H H H H H H H? ? ? ? ? ? ? ? ? ? @ @ @ @ @ @ : : : : : : : : E E E E E E E E E Eh0 h0 h0 h0 h0 h0 h0 h0V    ,   HV V V V V 1 V V Vr. !""< < < #"<" " " "L %r9   