
    g             	         U d Z ddlmZ ddlmZmZmZ ddlZddlm	Z	m
Z
mZmZmZmZmZmZ ddlmZ ddlmZ ddlmZ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#m$Z$ ddl%m&Z& ddl'm(Z(m)Z) ddl*m+Z+m,Z, ddl%m-Z-m.Z. ddl/m0Z0m1Z2 ddl3m4Z4m5Z5 ddl6Z6erddl7m8Z8 ddl9m:Z: g dZ;i dddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8i d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKd,dLdMdNdDdOdPdQdRdSdTdUdVdWdXdYdZd[Z<h d\Z=i d]d^ d_d` dadb dcdd dedf dgdh didj dkdl dmdn dodp dqdr dsdt dudv dwdx dydz d{d| d}d~ d d d d d d d dZ>de?d<    e@e          ZA e6jB        d           e6jB        d          fZCddZD G d de(          ZEddZF e)eE          d             ZGd ZHddZIdS )zC
A Printer which converts an expression into its LaTeX equivalent.
    )annotations)AnyCallableTYPE_CHECKINGN)AddFloatModMulNumberSSymbolExpr)greeks)Tuple)FunctionAppliedUndef
Derivative)AssocOp)Pow)default_sort_key)SympifyError)trueBooleanTrueBooleanFalse)precedence_traditional)Printerprint_function)split_super_subrequires_partial)
precedence
PRECEDENCE)prec_to_dpsto_str)has_varietysift)	NDimArray)BasisDependent)arcsinarccosarctansincostansinhcoshtanhsqrtlnlogseccsccotcothreimfracrootargAlphaz
\mathrm{A}Betaz
\mathrm{B}Gamma\GammaDeltaz\DeltaEpsilonz
\mathrm{E}Zetaz
\mathrm{Z}Etaz
\mathrm{H}Thetaz\ThetaIotaz
\mathrm{I}Kappaz
\mathrm{K}Lambdaz\LambdaMuz
\mathrm{M}Nuz
\mathrm{N}Xiz\XiomicronoOmicronz
\mathrm{O}Piz\PiRhoz
\mathrm{P}Sigmaz\SigmaTauz
\mathrm{T}Upsilonz\UpsilonPhiz\PhiChiz
\mathrm{X}Psiz\PsiOmegaz\Omegalamdaz\lambdaLamdakhiz\chiKhi
varepsilonz\varepsilonvarkappaz	\varkappavarphiz\varphivarpiz\varpivarrhoz\varrhoz	\varsigmaz	\vartheta)varsigmavartheta>
   wpellethmhobethhbaralephgimeldalethhslashmathringc                    d| z   dz   S )Nz
\mathring{} ss    P/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/printing/latex.py<lambda>rt   [   s    -/$.     ddddotc                    d| z   dz   S )Nz\ddddot{ro   rp   rq   s    rs   rt   rt   \   s    Ad* ru   dddotc                    d| z   dz   S )Nz\dddot{ro   rp   rq   s    rs   rt   rt   ]       z!|D( ru   ddotc                    d| z   dz   S )Nz\ddot{ro   rp   rq   s    rs   rt   rt   ^   s    ik$& ru   dotc                    d| z   dz   S )Nz\dot{ro   rp   rq   s    rs   rt   rt   _       XaZ_ ru   checkc                    d| z   dz   S )Nz\check{ro   rp   rq   s    rs   rt   rt   `   rz   ru   brevec                    d| z   dz   S )Nz\breve{ro   rp   rq   s    rs   rt   rt   a   rz   ru   acutec                    d| z   dz   S )Nz\acute{ro   rp   rq   s    rs   rt   rt   b   rz   ru   gravec                    d| z   dz   S )Nz\grave{ro   rp   rq   s    rs   rt   rt   c   rz   ru   tildec                    d| z   dz   S )Nz\tilde{ro   rp   rq   s    rs   rt   rt   d   rz   ru   hatc                    d| z   dz   S )Nz\hat{ro   rp   rq   s    rs   rt   rt   e   r   ru   barc                    d| z   dz   S )Nz\bar{ro   rp   rq   s    rs   rt   rt   f   r   ru   vecc                    d| z   dz   S )Nz\vec{ro   rp   rq   s    rs   rt   rt   g   r   ru   primec                    d| z   dz   S N{z}'rp   rq   s    rs   rt   rt   h   s    s1uTz ru   prmc                    d| z   dz   S r   rp   rq   s    rs   rt   rt   i   s    SU4Z ru   boldc                    d| z   dz   S Nz\boldsymbol{ro   rp   rq   s    rs   rt   rt   k   s    oa', ru   bmc                    d| z   dz   S r   rp   rq   s    rs   rt   rt   l   s    OA%d* ru   c                    d| z   dz   S )Nz	\mathcal{ro   rp   rq   s    rs   rt   rt   m       \!^D( ru   c                    d| z   dz   S )Nz	\mathscr{ro   rp   rq   s    rs   rt   rt   n   r   ru   c                    d| z   dz   S )Nz
\mathfrak{ro   rp   rq   s    rs   rt   rt   o   s    mAod* ru   c                    d| z   dz   S )Nz\left\|{z	}\right\|rp   rq   s    rs   rt   rt   q   s    k!mL0 ru   c                    d| z   dz   S )Nz\left\langle{z}\right\ranglerp   rq   s    rs   rt   rt   r   s    %a'(99 ru   c                    d| z   dz   S Nz\left|{z}\right|rp   rq   s    rs   rt   rt   s       Z\+- ru   c                    d| z   dz   S r   rp   rq   s    rs   rt   rt   t   r   ru   )calscrfraknormavgabsmagzdict[str, Callable[[str], str]]modifier_dictz[0-9][} ]*$z(\d|\\frac{\d+}{\d+})rr   strreturnc                    |                      dd          } dD ]}|                      |d|z             } |                      dd          } |                      dd          } | S )z
    Escape a string such that latex interprets it as plaintext.

    We cannot use verbatim easily with mathjax, so escaping is easier.
    Rules from https://tex.stackexchange.com/a/34586/41112.
    \z\textbackslashz&%$#_{}~z\textasciitilde^z\textasciicircum)replace)rr   cs     rs   latex_escaper      sm     	
		$)**A # #IIa""			#)**A			#*++AHru   c            
      P    e Zd ZU dZi dddddddddd	d
ddddddddddddddddi dddddddddddddddZded<   dbd Zdcd#Zdcd$Zdddcd%Z	d& Z
dcd'Zded)Zded*Zddded+Zded,Zded-Zded.Zdfd0Zd1 Zdgd4ZeZeZd5 Zdbd6Zd7 Zd8 Zd9 Zd: Zd; Zd< Zd= Zd> Z d? Z!d@ Z"dhdBZ#dC Z$dD Z%didFZ&djdHZ'dI Z(dJ Z)dK Z*dkdMZ+dN Z,dO Z-dP Z.dQ Z/dR Z0dS Z1dT Z2dldVZ3dbdmdXZ4dY Z5dZ Z6e7d[             Z8d\ Z9d] Z:d^ Z;dbdcd_Z<e<xZ=Z>dbd`Z?dbdaZ@dbdbZAdbdcZBdbddZCdbdeZDdf ZEdg ZFdh ZGdi ZHdj ZIdbdkZJdbdlZKdbdmZLdbdnZMdbdoZNdbdpZOdbdqZPdbdrZQdbdsZRdbdtZSdbduZTdndwZUdbdxZVdbdyZWdbdzZXdbdcd{ZYeYZZdbd|Z[dbd}Z\dbd~Z]dbdZ^dbdZ_dbdZ`dbdZadbdZbdbdZcdbdZddodZedcdZfdbdZgdbdZhdbdZidbdZjdbdZkdbdZldbdZmdbdZndbdZodbdZpdpdcdZqdpdcdZrdbdZsdbdZtdbdZudbdZvdbdZwdbdZxdbdZydbdZzdbdZ{dbdZ|dbdZ}dbdZ~dbdZdbdZdbdZdbdZdbdZdbdZdbdZdbdZdbdZdbdZdqdZdbdZdbdZdbdZdbdZd Zd ZdrdsdZeZdrdtdZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdbdÄZdĄ Zdń ZdƄ ZdǄ ZdȄ ZdɄ Zdʄ Zd˄ Zd̄ Zdud΄ZdvdфZd҄ Zdӄ ZdԄ ZdՄ Zdք Zdׄ Zd؄ Zdل Zdڄ ZdbdۄZd܄ Zd݄ Zdބ Zd߄ Zd Zd Zd ZdbdZdbdZdbdZdbdZdbdZd Zd Zd ZeZd ZŐdbdZƐdbdZǐdbdZȐdbdZɐdbdZʐdbdZːdbdZ̐dbdZd ZeZeZeZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd 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d Zd Zd Zd Zd Zd Zd Zd ZdbdZdbdZdw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dbd*Zd+ Zd, Z	d- Z
d. Zd/ Zd0 Zd1 Zd2 Zd3 Zd4 Zd5 Zd6 Zd7 Zd8 ZeZd9 Zd: Zd; Zd< Zd= Zd> Zd? Zd@ ZdA ZdB Z dC Z!dD Z"dE Z#dF Z$dG Z%dH Z&dI Z'dJ Z(dK Z)dL Z*dM Z+dN Z,dO Z-dP Z.dQ Z/dbdRZ0dbdSZ1dbdTZ2dbdUZ3dbdVZ4dbdWZ5dX Z6dY Z7dZ Z8d[ Z9d\ Z:d] Z;d^ Z<d_ Z=d` Z> fdaZ? xZ@S (x  LatexPrinter_latex	full_precFfold_frac_powersfold_func_bracketsfold_short_fracNinv_trig_styleabbreviateditexln_notationlong_frac_ratio	mat_delim[mat_strmodeplain
mul_symbolordersymbol_namesroot_notationTmat_symbol_styleimaginary_unitiperiodddagger)gothic_re_imdecimal_separatorperm_cyclicparenthesize_superminmaxdiff_operatoradjoint_stylezdict[str, Any]_default_settingsc                6   t          j        | |           d| j        v r"g d}| j        d         |vrt          d          | j        d         | j        d         dk    r
d| j        d<   ddd	d
d}	 || j        d                  | j        d<   n%# t          $ r | j        d         | j        d<   Y nw xY w	 || j        d         pd         | j        d<   nW# t          $ rJ | j        d                                         dv r|d         | j        d<   n| j        d         | j        d<   Y nw xY wddd| _        dddddddd}| j        d         }|                    ||          | j        d<   ddddd }| j        d!         }|                    ||          | j        d"<   d S )#Nr   )inliner   equationz	equation*zB'mode' must be one of 'inline', 'plain', 'equation' or 'equation*'r   r   T z \,.\,  \cdot  \times )Nldotr}   timesr   mul_symbol_latexr}   mul_symbol_latex_numbers) r   r   z\,z\:\;z\quad)])(r   r   z
\mathrm{i}z\text{i}jz
\mathrm{j}z\text{j})Nr   ritir   rjtjr   imaginary_unit_latexr   z
\mathrm{d}z\text{d})Nr   rdtdr   diff_operator_latex)r   __init__	_settings
ValueErrorKeyErrorstrip_delim_dictget)selfsettingsvalid_modesmul_symbol_tableimaginary_unit_table	imag_unitdiff_operator_tabler   s           rs   r   zLatexPrinter.__init__   sP   x(((T^##( ( (K~f%[88  "= > > > >+,4v&(2204DN,-  	
 
	- !=> N-.. 	- 	- 	-|, N-...	-
	1 !=!FG N566 	1 	1 	1|,2244BC C %U+ 9:: N<0 9:	1 "%3//  
  
 N#34	1E1I1I)U^1_1_-. 	
 
 70C0G0GWd0e0e,---s%   1B B/.B/3C AD%$D%r   r   c                ,    d                     |          S )Nz\left({}\right)formatr   rr   s     rs   _add_parenszLatexPrinter._add_parens   s    !((+++ru   c                ,    d                     |          S )Nz\left( {}\right)r  r  s     rs   _add_parens_lspacezLatexPrinter._add_parens_lspace   s    "))!,,,ru   c                   t          |          }|r*|r(|                     |                     |                    S ||k     s|s.||k    r(|                     |                     |                    S |                     |          S N)r   r  _print)r   itemlevelis_negstrictprec_vals         rs   parenthesizezLatexPrinter.parenthesize   s    )$// 	7f 	7##DKK$5$5666uv8u3D3D##DKK$5$5666;;t$$$ru   c                |    d|v r7| j         d         r|                     |          S d                    |          S |S )z
        Protect superscripts in s

        If the parenthesize_super option is set, protect with parentheses, else
        wrap in braces.
        r   r   z{{{}}})r   r  r  r  s     rs   r   zLatexPrinter.parenthesize_super   sH     !88~23 *''***q)))ru   c                    t          j        | |          }| j        d         dk    r|S | j        d         dk    rd|z  S | j        d         rd|z  S | j        d         }d|d|d	|dS )
Nr   r   r   z$%s$r   z$$%s$$z\begin{ro   z\end{)r   doprintr   )r   exprtexenv_strs       rs   r  zLatexPrinter.doprint	  s    odD))>&!W,,J^F#x//S= ^F# 	Es?"nV,GG.5ggsssGGGDDru   boolc                \    |j         r|j        p|j        o|t          j        uo|j        du  S )z
        Returns True if the expression needs to be wrapped in brackets when
        printed, False otherwise. For example: a + b => True; a => False;
        10 => False; -10 => True.
        F)
is_Integeris_nonnegativeis_Atomr   NegativeOneis_Rationalr   r  s     rs   _needs_bracketszLatexPrinter._needs_brackets  sH     _<)< J I$am*C +H.2.>%.GK 	Kru   c                    |                      |          sdS |j        r|                     |          sdS |j        r|                     |          sdS |j        s|j        rdS dS )a  
        Returns True if the expression needs to be wrapped in brackets when
        passed as an argument to a function, False otherwise. This is a more
        liberal version of _needs_brackets, in that many expressions which need
        to be wrapped in brackets when added/subtracted/raised to a power do
        not need them when passed to a function. Such an example is a*b.
        FT)r  is_Mul_mul_is_cleanis_Pow_pow_is_cleanis_Addis_Functionr  s     rs   _needs_function_bracketsz%LatexPrinter._needs_function_brackets   s     ##D)) 	5 { 	4#5#5d#;#; 	t T%7%7%=%= t  0 turu   c                Z   ddl m} ddlm} ddlm} j        r|s                                rdS n)t                    t          d         k     rdS j
        rdS j        rdS t          fdt          fD                       rdS |s t          fd|||fD                       rdS d	S )
a  
        Returns True if the expression needs to be wrapped in brackets when
        printed as part of a Mul, False otherwise. This is True for Add,
        but also for some container objects that would not need brackets
        when appearing last in a Mul, e.g. an Integral. ``last=True``
        specifies that this expr is the last to appear in a Mul.
        ``first=True`` specifies that this expr is the first to appear in
        a Mul.
        r   )Product)Sum)IntegralTr
   c              3  B   K   | ]}                     |          V  d S r  has.0xr  s     rs   	<genexpr>z3LatexPrinter._needs_mul_brackets.<locals>.<genexpr>N  -      ++qtxx{{++++++ru   c              3  B   K   | ]}                     |          V  d S r  r,  r.  s     rs   r1  z3LatexPrinter._needs_mul_brackets.<locals>.<genexpr>Q  s-      BBADHHQKKBBBBBBru   F)sympy.concrete.productsr(  sympy.concrete.summationsr)  sympy.integrals.integralsr*  r   could_extract_minus_signr   r!   is_Relationalis_Piecewiseanyr	   )r   r  firstlastr(  r)  r*  s    `     rs   _needs_mul_bracketsz LatexPrinter._needs_mul_brackets7  s    	433333111111666666; 	 T::<< t#D))Ju,===4 	4 	4++++SF+++++ 	4 	BBBB(GS)ABBBBB	4uru   c                r    j         rdS t          fdt          fD                       rdS j        rdS dS )z
        Returns True if the expression needs to be wrapped in brackets when
        printed as part of an Add, False otherwise.  This is False for most
        things.
        Tc              3  B   K   | ]}                     |          V  d S r  r,  r.  s     rs   r1  z3LatexPrinter._needs_add_brackets.<locals>.<genexpr>^  r2  ru   F)r8  r:  r	   r$  r  s    `rs   _needs_add_bracketsz LatexPrinter._needs_add_bracketsV  sU      	4++++SF+++++ 	4; 	4uru   c                .    |j         D ]}|j        r dS dS )NFT)argsr%  )r   r  r<   s      rs   r!  zLatexPrinter._mul_is_cleand  s.    9 	 	C uutru   c                8    |                      |j                   S r  )r  baser  s     rs   r#  zLatexPrinter._pow_is_cleanj  s    ''	2222ru   r  c                    |	d|d|dS |S )N\left(	\right)^{ro   rp   r   r  exps      rs   _do_exponentzLatexPrinter._do_exponentm  s!    ??.2ddCCC88Kru   c                                           |j        j                  }|j        r> fd|j        D             }d}|                    |d                    |                    S d                    |          S )Nc                :    g | ]}                     |          S rp   r	  )r/  rM   r   s     rs   
<listcomp>z-LatexPrinter._print_Basic.<locals>.<listcomp>v  s#    444Q$++a..444ru   z"\operatorname{{{}}}\left({}\right), z\text{{{}}})_deal_with_super_sub	__class____name__rB  r  join)r   r  namelsrr   s   `    rs   _print_BasiczLatexPrinter._print_Basics  sw    (()@AA9 	/4444$)444B5A88D$))B--000!((...ru   e!bool | BooleanTrue | BooleanFalsec                    d|z  S N	\text{%s}rp   r   rW  s     rs   _print_boolzLatexPrinter._print_bool|      aru   c                    d|z  S rZ  rp   r\  s     rs   _print_NoneTypezLatexPrinter._print_NoneType  r^  ru   c                   |                      ||          }d}t          |          D ]b\  }}|dk    rn"|                                r	|dz  }| }n|dz  }|                     |          }|                     |          rd|z  }||z  }c|S )N)r   r   r    -  + \left(%s\right))_as_ordered_terms	enumerater7  r	  r@  )r   r  r   termsr  r   termterm_texs           rs   
_print_AddzLatexPrinter._print_Add  s    &&t5&99 '' 	 	GAtAvv..00 uuu{{4((H''-- 9-88OCC
ru   c                L   ddl m} |j        dk    rdS  ||          }|j        }|j        }|j        d         |dz
  k    r
||dz
  ggz   }d}|D ](}|t          |                              dd          z  })|                    d	d
          }|                    dd          }|S )Nr   Permutation\left( \right)   r   ,r   r   \left( r   \right)) sympy.combinatorics.permutationsrm  sizecyclic_form
array_formr   r   )r   r  rm  	expr_permsizri  r   s          rs   _print_CyclezLatexPrinter._print_Cycle  s    @@@@@@9>>$${4  $	i?2#'))!cAgYK/I 	3 	3AAsE222HH##C44##C44ru   c                    ddl m} ddlm} |j        }| |d| dddd	           n j                            d
d          }|r                     |          S |j        dk    rdS  fd|j	        D             } fdt          t          |                    D             }d                    |          }d                    |          }d                    ||f          }	d|	z  S )Nr   rl  )sympy_deprecation_warningzw
                Setting Permutation.print_cyclic is deprecated. Instead use
                init_printing(perm_cyclic=z).
                z1.6z#deprecated-permutation-print_cyclic   )deprecated_since_versionactive_deprecations_target
stacklevelr   Trn  c                :    g | ]}                     |          S rp   rM  r/  r<   r   s     rs   rN  z3LatexPrinter._print_Permutation.<locals>.<listcomp>  s%    ===cS!!===ru   c                :    g | ]}                     |          S rp   rM  r  s     rs   rN  z3LatexPrinter._print_Permutation.<locals>.<listcomp>  s%    ???cS!!???ru    &  \\ z \begin{pmatrix} %s \end{pmatrix})rt  rm  sympy.utilities.exceptionsr|  print_cyclicr   r   rz  ru  rw  rangelenrS  )
r   r  rm  r|  r   lowerupperrow1row2mats
   `         rs   _print_PermutationzLatexPrinter._print_Permutation  s@   @@@@@@HHHHHH!."%%+6   */+P     .,,]DAAK 	+$$T***9>>$$====T_===????U3u::->->???zz%  zz%  llD$<((2S88ru   c                t    |j         \  }}d|                     |          d|                     |          dS )Nz\sigma_{z}(r   )rB  r	  )r   r  permvars       rs   _print_AppliedPermutationz&LatexPrinter._print_AppliedPermutation  s>    I	cc%)[[%6%6%6%6C8H8H8H8HIIru   c                0   t          |j                  }| j        d         rdnd}d| j        v r| j        d         nd }d| j        v r| j        d         nd }t          |j        ||||          }| j        d         }d|v r_|                    d          \  }}	|	d	         d
k    r
|	dd          }	| j        d         dk    r|                    dd          }||d|	dS |dk    rdS |dk    rdS | j        d         dk    r|                    dd          }|S )Nr   FTr   r   )strip_zeros	min_fixed	max_fixedr   rW  r   +rp  r   comma.z{,}z10^{ro   z+infz\inftyz-infz- \infty)r"   _precr   mlib_to_str_mpf_splitr   )
r   r  dpsr   lowhighstr_real	separatormantrI  s
             rs   _print_FloatzLatexPrinter._print_Float  sL   $*%%4>$','>'>dnU##D(-(?(?t~e$$Ttz3ES\`aaa N#=>	(??"..--KT31v}}!""g~12g==||C..%)T999ccc::9;~12g==#++C66Oru   c                    |j         }|j        }|                     |t          d                   d|                     |t          d                   S )Nr
   r   _expr1_expr2r  r!   r   r  vec1vec2s       rs   _print_CrosszLatexPrinter._print_Cross  sU    {{"&"3"3D*U:K"L"L"L"L"&"3"3D*U:K"L"L"LN 	Nru   c                X    |j         }d|                     |t          d                   z  S )Nz\nabla\times %sr
   _exprr  r!   r   r  r   s      rs   _print_CurlzLatexPrinter._print_Curl  s)    j!D$5$5c:e;L$M$MMMru   c                X    |j         }d|                     |t          d                   z  S )Nz\nabla\cdot %sr
   r  r  s      rs   _print_DivergencezLatexPrinter._print_Divergence  s)    j 4#4#4S*U:K#L#LLLru   c                    |j         }|j        }|                     |t          d                   d|                     |t          d                   S )Nr
   r   r  r  s       rs   
_print_DotzLatexPrinter._print_Dot  sU    {{!%!2!24E9J!K!K!K!K!%!2!24E9J!K!K!KM 	Mru   c                X    |j         }d|                     |t          d                   z  S )Nz	\nabla %sr
   r  r   r  funcs      rs   _print_GradientzLatexPrinter._print_Gradient  )    zd//j6GHHHHru   c                X    |j         }d|                     |t          d                   z  S )Nz	\Delta %sr
   r  r  s      rs   _print_LaplacianzLatexPrinter._print_Laplacian  r  ru   r   c                    ddl m}  j        d          j        d         d! fd}d! fdt          |t                    rG|j        }|d         t          j        u s!t          d	 |d
d          D                       r |          S d}|	                                r| }d}|j
        r|dz  }d}nd} ||d          \  }}|t          j        u r)t          d
dd          |j        vr| ||          z  }n ||          }	 ||          }
t          |
                                          } j        d         } j        d         r:|dk    r4d|
vr0                     |d          r|d|	d|
z  }nn||	d|
z  }nb|St          |	                                          ||z  k    r*                     |d          r|d|
dd|	dz  }n|j        rt          j        }t          j        }|j        D ]n}                     |d          sJt           |||z                                                      ||z  k    s|j        |j        cxu rdu r	n n||z  }i||z  }o                     |d          r%|d ||          d|
dd ||          d	z  }n=|d ||          d|
d ||          z  }n|d|
d|	z  }n|d|	d|
dz  }|r|d z  }|S )"Nr   )fractionr   r   r   r   c                4   | j         s"t                              |                     S j        dvr|                                 }nt          | j                  }t          |d d          \  }}t          |d d          \  }} ||z   |z             S )N)oldnonec                    t          | d          p9t          | d          p)t          | t                    ot          | j        d          S )N_scale_factoris_physical_constant)hasattr
isinstancer   rD  r0  s    rs   rt   z:LatexPrinter._print_Mul.<locals>.convert.<locals>.<lambda>  sN    ?8S8S8yW^_`bxWyWy 8H)!S11  G&qv/EFF ru   T)binaryc                "    t          | d          S )Nr  )r  r  s    rs   rt   z:LatexPrinter._print_Mul.<locals>.convert.<locals>.<lambda>  s    ?8S8S ru   )r   r   r	  r   as_ordered_factorslistrB  r%   )r  rB  unitsnonunitsprefixesconvert_argsr   s        rs   convertz(LatexPrinter._print_Mul.<locals>.convert  s    ; A4;;t,,---:_442244DD	??D #'t .H .HPT#V #V #Vx #'u.S.S\`"a"a"a%#|Hx$7%$?@@@ru   c           	        dx}}t          |           D ]\  }}                    |          }t          |d          st          |d          s                    ||dk    |t	          |           dz
  k              rd|z  }t
          d                             |          r&t
          d                             |          r|z  }n|r|z  }n|r|z  }||z  }|}|S )Nr   r  r  r   rp  )r;  r<  rd  )rf  r	  r  r=  r  _between_two_numbers_psearchmatch)	rB  _texlast_term_texr   rh  ri  	numbersepr   r  s	         rs   r  z-LatexPrinter._print_Mul.<locals>.convert_args  s   #%%D=$T?? ) )4;;t,,o66 &'$H^:_:_ &//Q!V673t99q=6H 0 K K A#5#@.q188GG *.q177AA* 	) *	) &I%D  (Kru   c              3  @   K   | ]}t          |t                    V  d S r  )r  r   )r/  r<   s     rs   r1  z*LatexPrinter._print_Mul.<locals>.<genexpr>:  s,      &S&S3z#v'>'>&S&S&S&S&S&Sru   rp  F- r   Tr   )exactro  )evaluater   r      r   )r<  rF  z
\right) / z / z	\frac{1}{ro   rs  \frac{}{r   r   r   )sympy.simplifyr  r   r  r
   rB  r   Oner:  r7  r$  r   r  r  r=  r   is_commutative)r   r  r  r  rB  include_parensr  numerdenomsnumersdenomldenomratioabr0  r  r  r  s   `               @@@rs   
_print_MulzLatexPrinter._print_Mul  s$   ++++++(:;	(BC		A 	A 	A 	A 	A 	A 	A 	 	 	 	 	 	 	 	8 dC   	*9DAw!%3&S&S$qrr(&S&S&S#S#S#|D)))((** 	5DC{ &s
!%CxD111uAE>>c!R%888	II 774== CC WU^^FWU^^F((FN#45E~/0 !;Vq[[v%%++E+>> 9CfffffEECC88CC"''%,66++E+== MC!66999fff6 6CC\ MAA"Z # #33AE3BB # #GGAaCLL$6$6$8$8 9 9E&L H H!"!1Q5E!N!N!N!N!N!N!N!N!NFAAFAA///== J&wqzzzz666999ggajjjj J J &wqzzzz66699ggajjj J J C&&&))VVLLCC666666:: 	3JC
ru   c                    |j         r9|                     |                                                                          S |                     |                                          S r  )
is_aliasedr	  as_polyas_exprr  s     rs   _print_AlgebraicNumberz#LatexPrinter._print_AlgebraicNumberz  sL    ? 	/;;t||~~5577888;;t||~~...ru   c                    |                      |j                  }|j        rd| dS |                      |j                                                  }d| d| dS )NrF  rs  rO  )r	  pis_inertalphar  )r   r  r  r  s       rs   _print_PrimeIdealzLatexPrinter._print_PrimeIdeal  sh    KK= 	('Q''''DJ..0011,,,e,,,,ru   r   c                   |j         j        r|j         j        }|j         j        }t	          |          dk    rh|dk    rb| j        d         rU|                     |j                  }|dk    rd|z  }n| j        d         rd||fz  }nd||fz  }|j         j        rd|z  S |S | j        d	         r|dk    r| 	                    |j        t          d
                   }|j        j        r|                     |          }|j        j        r!|                     |j        |d|          S |d|d|dS |j         j        r|j        j        r|j        dk    r|j        d|j         dS |j        j        r`|j        j        }|j        j        }||z  t	          |          k    r2|j         dk    r	d|d|dS d|d|dt	          |j                   dS |                     |          S |j        j        r4|                     |j        |                     |j                             S d}|                     ||          S )Nrp  r   r  z	\sqrt{%s}r   z\root{%d}{%s}z\sqrt[%d]{%s}z\frac{1}{%s}r   r   /rI  ^{ro   ro  z\frac{1}{\frac{r  }}z\frac{1}{(\frac{z})^{z%s^{%s})rI  r  r  qr   r   r	  rD  is_negativer  r!   	is_Symbolr   r%  r  r  _helper_print_standard_power)r   r  r  r  rD  r  base_pbase_qs           rs   
_print_PowzLatexPrinter._print_Pow  sx   8 %	-XZAXZA1vv{{qAvv$.*Iv{{49--66&-CC^F+ 7*aY6CC*aY6C8' *S00J 23 -Q((Ju4EFF9& 922488D9( H;;tyAA6F;GGG(,aaa33% -$)*B -9>>)-DHHH==9( g"&)+F"&)+F#f++558r>>>AG#PP * IOPVPVPVX[\`\dXeXeXeXe#fft,,,9  	E;;tydkk$(.C.C;DDD00s;;;ru   templatec                   |                      |j                  }|                     |j        t          d                   }|j        j        r|                     |          }nu|j        j        rd|z  }nct          |j        t                    rI|
                    d          r4t          j        d|          r|                    d          r
|dd         }|||fz  S )Nr   z{%s}rF  z\\left\(\\d?d?dotrs     i)r	  rI  r  rD  r!   r  r   is_Floatr  r   
startswithr8   r  endswith)r   r  r  rI  rD  s        rs   r   z)LatexPrinter._helper_print_standard_power  s    kk$(##   Ju,=>>9 		**400DDY 	T>DDJ// 		**	-t44	 j))	
 2;D4+%%ru   c                B    |                      |j        d                   S Nr   r	  rB  r  s     rs   _print_UnevaluatedExprz#LatexPrinter._print_UnevaluatedExpr  s    {{49Q<(((ru   c                    t          |j                  dk    r*dt           fd|j        d         D                       z  }n4 fddt                              dfd|j        D                       z  }t          |j        t                    r!|d	                     |j                  z  z  }n|                     |j                  z  }|S )
Nrp  z\sum_{%s=%s}^{%s} c                :    g | ]}                     |          S rp   rM  r/  r   r   s     rs   rN  z+LatexPrinter._print_Sum.<locals>.<listcomp>  #    >>>!t{{1~~>>>ru   r   c                j    dt          fd| d         | d         | d         fD                       z  S )N%s \leq %s \leq %sc                :    g | ]}                     |          S rp   rM  r/  rr   r   s     rs   rN  zALatexPrinter._print_Sum.<locals>._format_ineq.<locals>.<listcomp>  #    FFFa4;;q>>FFFru   rp  r   r  tuplelr   s    rs   _format_ineqz-LatexPrinter._print_Sum.<locals>._format_ineq  E    ,FFFFAaD!A$!3EFFFGGH Hru   z\sum_{\substack{%s}} \\c                &    g | ]} |          S rp   rp   r/  r  r  s     rs   rN  z+LatexPrinter._print_Sum.<locals>.<listcomp>  !    !G!G!Ga,,q//!G!G!Gru   rd  	r  limitsr  r   rS  r  functionr   r	  r   r  r  r  s   `  @rs   
_print_SumzLatexPrinter._print_Sum  s    t{q  '>>>>t{1~>>>??@CCH H H H H +!G!G!G!G4;!G!G!GHHIC dmS)) 	.%DM(B(BBBCC4;;t}---C
ru   c                    t          |j                  dk    r*dt           fd|j        d         D                       z  }n4 fddt                              dfd|j        D                       z  }t          |j        t                    r!|d	                     |j                  z  z  }n|                     |j                  z  }|S )
Nrp  z\prod_{%s=%s}^{%s} c                :    g | ]}                     |          S rp   rM  r  s     rs   rN  z/LatexPrinter._print_Product.<locals>.<listcomp>  r  ru   r   c                j    dt          fd| d         | d         | d         fD                       z  S )Nr  c                :    g | ]}                     |          S rp   rM  r  s     rs   rN  zELatexPrinter._print_Product.<locals>._format_ineq.<locals>.<listcomp>  r  ru   rp  r   r  r  r  s    rs   r  z1LatexPrinter._print_Product.<locals>._format_ineq  r  ru   z\prod_{\substack{%s}} r  c                &    g | ]} |          S rp   rp   r  s     rs   rN  z/LatexPrinter._print_Product.<locals>.<listcomp>  r   ru   rd  r!  r$  s   `  @rs   _print_ProductzLatexPrinter._print_Product  s    t{q  (>>>>t{1~>>>??@CCH H H H H ,!G!G!G!G4;!G!G!GHHIC dmS)) 	.%DM(B(BBBCC4;;t}---C
ru   'BasisDependent'c                   ddl m} g }||j        k    r|j        j        S t	          ||          r'|                                                                }nd|fg}|D ]\  }}t          |j                                                  }|	                    d            |D ]\  }}	|	dk    r|
                    d|j        z              )|	dk    r|
                    d|j        z              Md	|                     |	          z   d
z   }
|
                    d|
z   |j        z              d                    |          }|d         dk    r|dd          }n
|dd          }|S )Nr   )Vectorc                6    | d                                          S r  )__str__r  s    rs   rt   z4LatexPrinter._print_BasisDependent.<locals>.<lambda>  s    !A$,,.. ru   keyrp  rc  ro  rb  rF  rs  r   -   )sympy.vectorr.  zero_latex_formr  separateitemsr  
componentssortappendr	  rS  )r   r  r.  o1r9  systemvect
inneritemskvarg_stroutstrs               rs   _print_BasisDependentz"LatexPrinter._print_BasisDependent  s   ''''''499((dF## 	 MMOO))++EEYKE! 
	? 
	?LFDdo335566JOO 8 8O999" ? ?166IIeam34444"WWIIeam34444'$++a..8:EGIIego=>>>>? ''"++!9ABBZFFABBZFru   c                    |                      |j                  }d|z   dz   dd                    t          | j         |j                            z  z   }|S )Nr   ro   _{%s}rq  )r	  rD  rS  mapindices)r   r  tex_baser  s       rs   _print_IndexedzLatexPrinter._print_Indexed  sU    ;;ty))(l3wT\***, *,  , ,
ru   c                6    |                      |j                  S r  )r	  labelr  s     rs   _print_IndexedBasezLatexPrinter._print_IndexedBase  s    {{4:&&&ru   c                Z   |                      |j                  }|j        |                      |j                  }|j        |                      |j                  }n|                      t          j                  }d                    ||          }d                    ||          S |S )Nz%{lower}\mathrel{{..}}\nobreak {upper})r  r  z{{{label}}}_{{{interval}}})rM  interval)r	  rM  r  r  r   Zeror  )r   r  rM  r  r  rP  s         rs   
_print_IdxzLatexPrinter._print_Idx  s    DJ'':!KK
++Ez%DJ//AF++@GG!5 H 2 2H/66( 7 4 4 4 ru   c           	        t          |j                  rd}n| j        d         }d}d}t          |j                  D ]u\  }}||z  }|dk    r||d|                     |          z  }.||d|                     |                     |                    d|                     |          dz  }v|dk    r
d	|d
|d}nd	|d|                     |          d|d}t          d |j        D                       r.|d| 	                    |j        t          d         dd          S |d| 	                    |j        t          d         dd          S )Nz\partialr   r   r   rp  r   r  ro   r  r  }}{c              3  >   K   | ]}|                                 V  d S r  r7  r/  r   s     rs   r1  z1LatexPrinter._print_Derivative.<locals>.<genexpr>:  s.      ??q))++??????ru   r
   Tr  r  F)r   r  r   reversedvariable_countr	  r   r:  rB  r  r!   )r   r  diff_symbolr  dimr0  nums          rs   _print_DerivativezLatexPrinter._print_Derivative$  s   DI&& 	@%KK.)>?Kt233 	: 	:FAs3JCaxx;;;A??(,(?(?A(O(O(O(O(,C(8(8(8(8: : !888&1kk3337CC  ,7;;C8H8H8H8H###NC??TY????? 	@"ssD$5$5di2<U2C9=9= %6 %? %? %? @ @
 33 1 1$)2<U2C9>9= !2 !? !? !? @ 	@ru   c                     |j         \  }}}                     |          } fd|D             } fd|D             }d                    d t          ||          D                       }d|d|dS )Nc              3  B   K   | ]}                     |          V  d S r  rM  r/  rW  r   s     rs   r1  z+LatexPrinter._print_Subs.<locals>.<genexpr>H  -      11T[[^^111111ru   c              3  B   K   | ]}                     |          V  d S r  rM  ra  s     rs   r1  z+LatexPrinter._print_Subs.<locals>.<genexpr>I  rb  ru   z\\ c              3  >   K   | ]}|d          dz   |d         z   V  dS )r   =rp  Nrp   )r/  rW  s     rs   r1  z+LatexPrinter._print_Subs.<locals>.<genexpr>J  sL       !B !B"#AaD3J1!B !B !B !B !B !Bru   z\left. z \right|_{\substack{ z }})rB  r	  rS  zip)	r   subsr  r  new
latex_expr	latex_old	latex_new
latex_subss	   `        rs   _print_SubszLatexPrinter._print_SubsE  s    c3[[&&
1111S111	1111S111	[[ !B !B'*9i'@'@!B !B !B B B

9C9CE 	Eru   c           
         dg }} j         d         t          |j                  dk    rTt          d |j        D                       r6ddt          |j                  dz
  z  z   dz   } fd	|j        D             }nt	          |j                  D ]}|d
         }|dz  }t          |          dk    r j         d         dk    r j         d         s|dz  }t          |          dk    r>|d                     |d                   d                     |d                   dz  }t          |          dk    r!|d                     |d                   z  z  }|                    d
d                     |                     |d                     |j        t          d         t          d |j        D                       d          d                    |          S )Nr   r      c              3  <   K   | ]}t          |          d k    V  dS )rp  N)r  )r/  lims     rs   r1  z/LatexPrinter._print_Integral.<locals>.<genexpr>T  s,      (N(N3SQ(N(N(N(N(N(Nru   z\ir   rp  ntc                P    g | ]"}d                      |d                   #S )\, r   rM  )r/  symbolr[  r   s     rs   rN  z0LatexPrinter._print_Integral.<locals>.<listcomp>X  sE     2 2 2!6 &1[$++fQi2H2H2HI 2 2 2ru   r   z\intr   r   r   z\limitsr4  _{}^{r  ro   ^{%s}rt  r   r
   c              3  >   K   | ]}|                                 V  d S r  rV  rW  s     rs   r1  z/LatexPrinter._print_Integral.<locals>.<genexpr>o  s/      >o>o`aq?Y?Y?[?[>o>o>o>o>o>oru   TrX  )r   r  r"  allrY  r	  insertr  r#  r!   r:  rB  rS  )r   r  r  symbolsrq  ru  r[  s   `     @rs   _print_IntegralzLatexPrinter._print_IntegralO  s/   2Wn%:; t{q  S(N(N$+(N(N(N%N%N  #s4;//!344t;C2 2 2 2 2%)[2 2 2GG  ,, S SQws88a<<~f-99$(N6$: :z)3xx1}}t{{3q6/B/B/B/B/3{{3q6/B/B/B/B D D3xx1}}w$++c!f*=*=>>qqT[[=P=P=P"QRRRR SS$"3"3DM4>u4E;>>o>oeien>o>o>o;o;o;? #4 #A #A #A  WWW---	/ 	/ru   c                   |j         \  }}}}d|                     |          z  }t          |          dk    s|t          j        t          j        fv r|d|                     |          z  z  }n1||                     |          d|                     |          dz  }t          |t                    r|d|                     |          dS |d|                     |          S )	Nz\lim_{%s \to z+-z%s}r   ro   rF  rs  r   )rB  r	  r   r   InfinityNegativeInfinityr  r   )r   r  rW  zz0dirr  s          rs   _print_LimitzLatexPrinter._print_Limits  s    	1b#Q/s88traj!2D%EEE6DKKOO++CCBS1A1A1A1ABBCa!! 	4+.33A??"ssDKKNNN33ru   r  c                   |                      |          }|                    d          }|                    d          }|t          v rd|z  }nt          |          dk    s!|                    d          s|dk    s|dk    r|}n|dk    r;|dk    r5d|dt          ||                   d	|t          ||          d         }nC|dk    rd|d|         d	||d         }n$|dk    rd|d|         d	||d         }nd
|z  }|S )ak  
        Logic to decide how to render a function to latex
          - if it is a recognized latex name, use the appropriate latex command
          - if it is a single letter, excluding sub- and superscripts, just use that letter
          - if it is a longer name, then put \operatorname{} around it and be
            mindful of undercores in the name
        r   _z\%srp  r   r   \operatorname{Nro   z\operatorname{%s})rP  findaccepted_latex_functionsr  r  r   )r   r  superscriptidxsubscriptidxrT  s        rs   _hprint_FunctionzLatexPrinter._hprint_Function  sf    ((..3yy~~+++D=DDYY!^^tt44^8I8I^_`M`M`DD!!lQ&6&6&6:#l>:::;;;\.99::;;=  !###.)))))+ !!!,''''') ,d2ru   r   c                <    |j         j        }t           d|z             r2t          |t                    s t           d|z             ||          S  fd|j        D             } j        d         }d} j        d         o3t          |          dk    o  	                    |j        d                    }g d}||v r?|d	k    rn8|d
k    r|d         dk    rdnd|dd         z   }n|dk    r|dd         }d}|d}|r|t          v rd|z  }	nPd|z  }	nJ|3                     |          }
                     |
          }
|
d|d}	n                     |          }	|r|t          v r|	dz  }	n|	dz  }	n|	dz  }	|r
||	d|z  z  }	|	d                    |          z  S )a#  
        Render functions to LaTeX, handling functions that LaTeX knows about
        e.g., sin, cos, ... by using the proper LaTeX command (\sin, \cos, ...).
        For single-letter function names, render them as regular LaTeX math
        symbols. For multi-letter function names that LaTeX does not know
        about, (e.g., Li, sech) use \operatorname{} so that the function name
        is rendered in Roman font and LaTeX handles spacing properly.

        expr is the expression involving the function
        exp is an exponent
        _print_c                T    g | ]$}t                              |                    %S rp   )r   r	  r  s     rs   rN  z0LatexPrinter._print_Function.<locals>.<listcomp>  s-    ???cCC(())???ru   r   Fr   rp  r   )asinacosatanacscasecacotasinhacoshatanhacschasechacothr   fullro  hararcNpowerTz\%s^{-1}z\operatorname{%s}^{-1}r  ro   z {%s}%s{\left(%s \right)}rx  rq  )r  rR  r  r  r   getattrrB  r   r  r&  r  r  r   rS  )r   r  rI  r  rB  r   inv_trig_power_casecan_fold_bracketsinv_trig_tablerT  func_texs   `          rs   _print_FunctionzLatexPrinter._print_Function  s7    y!4T)** =	)t\22=	)274T!1224===????TY???D "^,<=N"' $/C D !@D		Q!@11$)A,???   N ~%%!]22#v--$(HOODD$qrr(JDD#w..8D*.' ,1)" 
3333&-DD4t;DD0066228<<%-XXsss3,,T22  .333 H$DDEMDD--" 's3&#((4..((ru   c                F    |                      t          |                    S r  )r  r   r  s     rs   _print_UndefinedFunctionz%LatexPrinter._print_UndefinedFunction  s    $$SYY///ru   c                t    d|                      |j                  d|                      |j                  dS )Nr   z}_{\circ}\left({z}\right))r	  r#  r  r  s     rs   _print_ElementwiseApplyFunctionz,LatexPrinter._print_ElementwiseApplyFunction  s<     KK&&&&KK	""""
 	
ru   c                ^    ddl m} ddlm}m} ddlm} ddlm} ddl	m
} |d|d|d	|d
|d|diS )Nr   )KroneckerDelta)gamma
lowergamma)beta)
DiracDelta)rU   z\deltar@   \gammaz\operatorname{B}z\operatorname{Chi})(sympy.functions.special.tensor_functionsr  'sympy.functions.special.gamma_functionsr  r  &sympy.functions.special.beta_functionsr  'sympy.functions.special.delta_functionsr  'sympy.functions.special.error_functionsrU   )r   r  r  r  r  r  rU   s          rs   _special_function_classesz&LatexPrinter._special_function_classes  s    KKKKKKMMMMMMMM??????FFFFFF??????		I)I*, 	,ru   c                    | j         D ]1}t          ||          r|j        |j        k    r| j         |         c S 2|                     t	          |                    S r  )r  
issubclassrR  r  r   )r   r  clss      rs   _print_FunctionClassz!LatexPrinter._print_FunctionClass  sc    1 	; 	;C$$$ ;#,)F)F5c::::$$SYY///ru   c                    |j         \  }}t          |          dk    r|                     |d                   }n"|                     t          |                    }d|d|                     |          d}|S )Nrp  r   rr  z	 \mapsto  \right))rB  r  r	  r  )r   r  r|  r  s       rs   _print_LambdazLatexPrinter._print_Lambda
  sr    	w<<1kk'!*--GGkk%..11G18$++d:K:K:K:KL
ru   c                    dS )Nz\left( x \mapsto x \right)rp   r  s     rs   _print_IdentityFunctionz$LatexPrinter._print_IdentityFunction  s    ,,ru   c                     t          |j        t                    } fd|D             }dt          |j                                                  dd                    |          d}||d|dS |S )	Nr1  c                @    g | ]}d                      |          z  S )r  rM  )r/  ru  r   s     rs   rN  z:LatexPrinter._hprint_variadic_function.<locals>.<listcomp>  s*    BBB654;;v...BBBru   r   rF  rO  rs  r  ro   )sortedrB  r   r   r  r  rS  )r   r  rI  rB  texargsr  s   `     rs   _hprint_variadic_functionz&LatexPrinter._hprint_variadic_function  s    di%5666BBBBTBBB'*49~~';';'='='='='+yy'9'9'9'9;?!$ccc**Jru   c                `    d|                      |j        d                   z  }||d|dS |S )Nz\left\lfloor{%s}\right\rfloorr   r  ro   r  r   r  rI  r  s       rs   _print_floorzLatexPrinter._print_floor%  s;    .TYq\1J1JJ?!$ccc**Jru   c                `    d|                      |j        d                   z  }||d|dS |S )Nz\left\lceil{%s}\right\rceilr   r  ro   r  r  s       rs   _print_ceilingzLatexPrinter._print_ceiling-  s;    ,t{{49Q</H/HH?!$ccc**Jru   c                    | j         d         s$d|                     |j        d                   z  }n#d|                     |j        d                   z  }||d|dS |S )Nr   z\log{\left(%s \right)}r   z\ln{\left(%s \right)}r  ro   )r   r	  rB  r  s       rs   
_print_logzLatexPrinter._print_log5  si    ~m, 	G+dkk$)A,.G.GGCC*T[[1-F-FFC?!$ccc**Jru   c                `    d|                      |j        d                   z  }||d|dS |S )N\left|{%s}\right|r   r  ro   r  r  s       rs   
_print_AbszLatexPrinter._print_Abs@  s;    "T[[1%>%>>?!$ccc**Jru   c                &   | j         d         r0d|                     |j        d         t          d                   z  }n?d                    |                     |j        d         t          d                             }|                     ||          S )Nr   z\Re{%s}r   Atomz\operatorname{{re}}{{{}}}r   r  rB  r!   r  rJ  r  s       rs   	_print_rezLatexPrinter._print_reH      >.) 	kt001z&?QRRRCC.55d6G6G	RSV`agVh6i6ijjC  c***ru   c                &   | j         d         r0d|                     |j        d         t          d                   z  }n?d                    |                     |j        d         t          d                             }|                     ||          S )Nr   z\Im{%s}r   r  z\operatorname{{im}}{{{}}}r  r  s       rs   	_print_imzLatexPrinter._print_imP  r  ru   c                   ddl m}m} t          |j        d         |          r!|                     |j        d         d          S t          |j        d         |          r!|                     |j        d         d          S |j        d         j        r#d|                     |j        d                   z  S d|                     |j        d                   z  S )Nr   )
EquivalentImpliesz\not\Leftrightarrowz\not\Rightarrowz\neg \left(%s\right)z\neg %s)	sympy.logic.boolalgr  r  r  rB  _print_Equivalent_print_Implies
is_Booleanr	  )r   rW  r  r  s       rs   
_print_NotzLatexPrinter._print_NotX  s    ========afQi,, 	M))!&)5KLLLafQi)) 	F&&qvay2DEEEF1I  	7*T[[-C-CCCAF1I 6 666ru   c                F   |d         }|j         r |j        sd|                     |          z  }nd|                     |          z  }|dd          D ]N}|j         r'|j        s |d|d|                     |          dz  }0|d|d|                     |          z  }O|S )Nr   rd  r  rp  r   z \left(rs  )r  is_Notr	  )r   rB  charr<   r  s        rs   _print_LogOpzLatexPrinter._print_LogOpc  s    1g> 	+#* 	+$t{{3'7'77CC$++c***C8 	< 	<C~ <cj <t{{37G7G7G7GHHDDD$++c*:*:*:;;
ru   c                d    t          |j        t                    }|                     |d          S )Nr1  z\wedger  rB  r   r  r   rW  rB  s      rs   
_print_AndzLatexPrinter._print_Andr  s-    af"2333  y111ru   c                d    t          |j        t                    }|                     |d          S )Nr1  z\veer  r  s      rs   	_print_OrzLatexPrinter._print_Orv  s-    af"2333  w///ru   c                d    t          |j        t                    }|                     |d          S )Nr1  z\veebarr  r  s      rs   
_print_XorzLatexPrinter._print_Xorz  s-    af"2333  z222ru   c                <    |                      |j        |pd          S )Nz\Rightarrow)r  rB  )r   rW  altchars      rs   r  zLatexPrinter._print_Implies~  s      )BNCCCru   c                h    t          |j        t                    }|                     ||pd          S )Nr1  z\Leftrightarrowr  )r   rW  r  rB  s       rs   r  zLatexPrinter._print_Equivalent  s3    af"2333  w'D2DEEEru   c                `    d|                      |j        d                   z  }||d|dS |S )Nz\overline{%s}r   r  ro   r  r  s       rs   _print_conjugatezLatexPrinter._print_conjugate  s;    TYq\!:!::?!$ccc**Jru   c                p    d}d|                      |j        d                   z  }|
|d|d|S ||S )Nz\operatorname{polar\_lift}r  r   r  ro   r  )r   r  rI  r  r<   s        rs   _print_polar_liftzLatexPrinter._print_polar_lift  sN    ,#dkk$)A,&?&???#'44cc22"dCC((ru   c                t    d|                      |j        d                   z  }|                     ||          S )Nze^{%s}r   )r	  rB  rJ  r  s       rs   _print_ExpBasezLatexPrinter._print_ExpBase  s6     $++dil333  c***ru   c                    dS )NrW  rp   rH  s      rs   _print_Exp1zLatexPrinter._print_Exp1  s    sru   c                f    d|                      |j        d                   z  }|d|d|S d|z  S )Nrd  r   zK^{ro   zK%sr  r  s       rs   _print_elliptic_kzLatexPrinter._print_elliptic_k  s@     4;;ty|#<#<<??"%##ss++C<ru   c                    d|                      |j        d                   d|                      |j        d                   d}|d|d|S d|z  S )	NrF  r   	\middle| rp  rs  zF^{ro   zF%sr  r  s       rs   _print_elliptic_fzLatexPrinter._print_elliptic_f  sc     [[1&&&&DIaL(A(A(A(AC??"%##ss++C<ru   c                "   t          |j                  dk    rFd|                     |j        d                   d|                     |j        d                   d}n#d|                     |j        d                   z  }|d|d	|S d
|z  S )Nr  rF  r   r  rp  rs  rd  zE^{ro   zE%sr  rB  r	  r  s       rs   _print_elliptic_ezLatexPrinter._print_elliptic_e  s    ty>>QTYq\****DKK	!,E,E,E,EGCC %t{{49Q<'@'@@C??"%##ss++C<ru   c           	        t          |j                  dk    rgd|                     |j        d                   d|                     |j        d                   d|                     |j        d                   d}nEd|                     |j        d                   d|                     |j        d                   d}|d	|d
|S d|z  S )Nr4  rF  r   ; rp  r  r  rs  z\Pi^{ro   z\Pi%sr  r  s       rs   _print_elliptic_pizLatexPrinter._print_elliptic_pi  s    ty>>QTYq\****DKK	!,E,E,E,ETYq\****,CC  TYq\****DKK	!,E,E,E,EGC??$'CC--c>!ru   c                    |j         d         }t          |j                   dk    r|j         d         n|j         d         }d| d| d}|d|d|S d|z  S )	Nr   rp  rF  rO  rs  z\operatorname{B}^{ro   z\operatorname{B}%s)rB  r  )r   r  rI  r0  yr  s         rs   _print_betazLatexPrinter._print_beta  so    IaL	NNa//DIaLLTYq\'''Q'''??14cc::(3..ru   Bc           
           fd|j         D             }d|d         d|d         d}|d|d|d	         d|d
         d|d|
S d|d|d	         d|d
         d|S )Nc                :    g | ]}                     |          S rp   rM  r  s     rs   rN  z/LatexPrinter._print_betainc.<locals>.<listcomp>  s%    777cS!!777ru   rF  r   rO  rp  rs  r  z}_{(r  r4  z)}^{ro   z)})rB  )r   r  rI  operatorlargsr  s   `     rs   _print_betainczLatexPrinter._print_betainc  s    7777TY777(-a%(((;??=EXXuQxxxQVWXQYQYQY[^[^[^`c`cdd  9A%(((ERSHHHVYVYZZru   c                2    |                      ||d          S )NI)r	  )r  rH  s      rs   _print_betainc_regularizedz'LatexPrinter._print_betainc_regularized  s    ""4s";;;ru   c                    d|                      |j        d                   d|                      |j        d                   d}|d|d|S d|z  S )	NrF  r   rO  rp  rs  z\Gamma^{ro   z\Gamma%sr  r  s       rs   _print_uppergammazLatexPrinter._print_uppergamma  g     (,DIaL(A(A(A(A(,DIaL(A(A(A(AC ??'*ssCC00$$ru   c                    d|                      |j        d                   d|                      |j        d                   d}|d|d|S d|z  S )	NrF  r   rO  rp  rs  z\gamma^{ro   \gamma%sr  r  s       rs   _print_lowergammazLatexPrinter._print_lowergamma  r  ru   c                    d|                      |j        d                   z  }|"|                      |j                  d|d|S |                      |j                  |S Nrd  r   r  ro   )r	  rB  r  r  s       rs   _hprint_one_arg_funcz!LatexPrinter._hprint_one_arg_func  sh     4;;ty|#<#<<?#';;ty#9#9#9#9333DD"kk$)444cc::ru   c                f    d|                      |j        d                   z  }|d|d|S d|z  S )Nrd  r   z\operatorname{Chi}^{ro   z\operatorname{Chi}%sr  r  s       rs   
_print_ChizLatexPrinter._print_Chi  sA     4;;ty|#<#<<??3633<<*S00ru   c                    d|                      |j        d                   z  }|                      |j        d                   }|d|d|d|S d|d|S )Nrd  rp  r   z\operatorname{E}_{rw  ro   r  )r   r  rI  r  nus        rs   _print_expintzLatexPrinter._print_expint  sk     4;;ty|#<#<<[[1&&??68bb###ssCC  24SS99ru   c                f    d|                      |j        d                   z  }|d|d|S d|z  S )Nrd  r   zS^{ro   zS%sr  r  s       rs   _print_fresnelszLatexPrinter._print_fresnels
  @     4;;ty|#<#<<??"%##ss++C<ru   c                f    d|                      |j        d                   z  }|d|d|S d|z  S )Nrd  r   zC^{ro   zC%sr  r  s       rs   _print_fresnelczLatexPrinter._print_fresnelc  r  ru   c                z    d|                      |j        d         t          d                   z  }|	d|d|dS |S )Nz!%sr   FuncrF  rG  ro   r  rB  r!   r  s       rs   _print_subfactorialz LatexPrinter._print_subfactorial  sF    t((1z&7IJJJ??.1cc33377Jru   c                x    d|                      |j        d         t          d                   z  }||d|dS |S )Nz%s!r   r#  r  ro   r$  r  s       rs   _print_factorialzLatexPrinter._print_factorial"  sD    t((1z&7IJJJ?!$ccc**Jru   c                x    d|                      |j        d         t          d                   z  }||d|dS |S )Nz%s!!r   r#  r  ro   r$  r  s       rs   _print_factorial2zLatexPrinter._print_factorial2*  sD    ))$)A,
68JKKK?!$ccc**Jru   c                    d|                      |j        d                   d|                      |j        d                   d}||d|dS |S )Nz{\binom{r   r  rp  r  r  ro   r  r  s       rs   _print_binomialzLatexPrinter._print_binomial2  sa     %)[[1%>%>%>%>%)[[1%>%>%>%>@ ?!$ccc**Jru   c                    |j         \  }}d|                     |t          d                   z  }d|d|                     |          d}|                     ||          S )Nr  r#  r   	}^{\left(\right)}rB  r  r!   r	  rJ  )r   r  rI  nrA  rD  r  s          rs   _print_RisingFactorialz#LatexPrinter._print_RisingFactorial;  s`    y1t((Jv,>???+/44Q@  c***ru   c                    |j         \  }}d|                     |t          d                   z  }d|                     |          d|d}|                     ||          S )Nr  r#  z{\left(z
\right)}_{ro   r/  )r   r  rI  r0  rA  subr  s          rs   _print_FallingFactorialz$LatexPrinter._print_FallingFactorialC  s`    y1d'':f+=>>>+/;;q>>>>333?  c***ru   symc                   d|z  }d}|$|                     d          dk    r	|d|d}nd}|d|                     |j                  d	|                     |j                  d
}|r|                     ||          }|S )Nr  Fr   ro  r  ro   Trv  }\left(rs  )r  r	  r   argumentrJ  )r   r  rI  r5  r  need_exps         rs   _hprint_BesselBasezLatexPrinter._hprint_BesselBaseK  s    sm?xx}}""$'CC-+.33DJ0G0G0G0G+/;;t}+E+E+E+EG  	.##C--C
ru   c                    |sdS d}|d d         D ]}|d|                      |          z  z  }||                      |d                   z  }|S )Nr   ro  z%s, rM  )r   r   rr   r   s       rs   _hprint_veczLatexPrinter._hprint_vec\  se     	2SbS 	) 	)A$++a..((AA	T[[R!!!ru   c                0    |                      ||d          S )NJr:  rH  s      rs   _print_besseljzLatexPrinter._print_besselje      &&tS#666ru   c                0    |                      ||d          S )Nr  r?  rH  s      rs   _print_besselizLatexPrinter._print_besselih  rA  ru   c                0    |                      ||d          S )NKr?  rH  s      rs   _print_besselkzLatexPrinter._print_besselkk  rA  ru   c                0    |                      ||d          S )NYr?  rH  s      rs   _print_besselyzLatexPrinter._print_besselyn  rA  ru   c                0    |                      ||d          S )Nr  r?  rH  s      rs   	_print_ynzLatexPrinter._print_ynq  rA  ru   c                0    |                      ||d          S )Nr   r?  rH  s      rs   	_print_jnzLatexPrinter._print_jnt  rA  ru   c                0    |                      ||d          S )NzH^{(1)}r?  rH  s      rs   _print_hankel1zLatexPrinter._print_hankel1w      &&tS)<<<ru   c                0    |                      ||d          S )NzH^{(2)}r?  rH  s      rs   _print_hankel2zLatexPrinter._print_hankel2z  rP  ru   c                0    |                      ||d          S )Nzh^{(1)}r?  rH  s      rs   
_print_hn1zLatexPrinter._print_hn1}  rP  ru   c                0    |                      ||d          S )Nzh^{(2)}r?  rH  s      rs   
_print_hn2zLatexPrinter._print_hn2  rP  ru   r   c                l    d|                      |j        d                   z  }|
|d|d|S ||S r  r  r   r  rI  notationr  s        rs   _hprint_airyzLatexPrinter._hprint_airy  sI     4;;ty|#<#<<?#+88SSS##66&h,,ru   c                p    d|                      |j        d                   z  }|d|d|d|S |d|S )Nrd  r   r   z
^\prime}^{ro   z^\primer  rX  s        rs   _hprint_airy_primezLatexPrinter._hprint_airy_prime  sM     4;;ty|#<#<<??,4HHccc33??%-XXss33ru   c                0    |                      ||d          S NAirZ  rH  s      rs   _print_airyaizLatexPrinter._print_airyai        sD111ru   c                0    |                      ||d          S NBir`  rH  s      rs   _print_airybizLatexPrinter._print_airybi  rb  ru   c                0    |                      ||d          S r^  r\  rH  s      rs   _print_airyaiprimezLatexPrinter._print_airyaiprime      &&tS$777ru   c                0    |                      ||d          S rd  rh  rH  s      rs   _print_airybiprimezLatexPrinter._print_airybiprime  rj  ru   c                d   d|                      t          |j                            d|                      t          |j                            d|                     |j                  d|                     |j                  d|                      |j                  d}|	d|d|d	}|S )
Nz{{}_{z}F_{}\left(\begin{matrix} r  z \end{matrix}\middle| {
} \right)}r   rw  ro   )r	  r  apbqr<  r8  r  s       rs   _print_hyperzLatexPrinter._print_hyper  s      [[TW&&&&CLL(A(A(A(Atw'''')9)9$')B)B)B)Bkk$-((((	* ??"%##sss+C
ru   c                p   d|                      t          |j                            d|                      t          |j                            d|                      t          |j                            d|                      t          |j                            d|                     |j                  d|                     |j                  d|                     |j                  d|                     |j                  d|                      |j	                  d}|	d	|d|d
}|S )Nz{G_{rO  rw  rn  r   \\z \end{matrix} \middle| {ro  r   ro   )
r	  r  rp  rq  r   anr<  aotherbotherr8  r  s       rs   _print_meijergzLatexPrinter._print_meijerg  s     [[TW&&&&CLL(A(A(A(Akk#dg,,''''S\\)B)B)B)Btw'''')9)9$+)F)F)F)Ftw'''')9)9$+)F)F)F)Fkk$-((((* ??"%##sss+C
ru   c                f    d|                      |j        d                   z  }|d|d|S d|z  S )Nrd  r   z\eta^{ro   z\eta%sr  r  s       rs   _print_dirichlet_etaz!LatexPrinter._print_dirichlet_eta  s@     4;;ty|#<#<<??%(SS##..3ru   c                    t          |j                  dk    r+dt          t          | j        |j                            z  }n#d|                     |j        d                   z  }|d|d|S d|z  S )Nr  z\left(%s, %s\right)rd  r   z\zeta^{ro   z\zeta%sr  rB  r  rH  r	  r  s       rs   _print_zetazLatexPrinter._print_zeta  sv    ty>>Q(5T[$)1L1L+M+MMCC$t{{49Q<'@'@@C??&)cc33//Cru   c                    t          |j                  dk    r+dt          t          | j        |j                            z  }n#d|                     |j        d                   z  }|	d|d|dS d|z  S )	Nr  z_{%s}\left(%s\right)rG  r   r  r  ro   r  r|  r  s       rs   _print_stieltjeszLatexPrinter._print_stieltjes  sx    ty>>Q)E#dk492M2M,N,NNCCT[[1666C??'*ssCCC00S  ru   c                t    dt          t          | j        |j                            z  }|d|z  S d|d|S )Nz\left(%s, %s, %s\right)z\Phi%sz\Phi^{ro   )r  rH  r	  rB  r  s       rs   _print_lerchphizLatexPrinter._print_lerchphi  sG    (5T[$)1L1L+M+MM;s?" !$cc**ru   c                p    t          | j        |j                  \  }}d|z  }|d|d|S d|d|d|S )Nrd  z\operatorname{Li}_{ro   rw  rH  r	  rB  )r   r  rI  rr   r  r  s         rs   _print_polylogzLatexPrinter._print_polylog  sW    4;	**1 1$;;23!!SS99 3411ccc33??ru   c           	     |    t          | j        |j                  \  }}}}d|d|d|d|d	}|d|z   d|z  z   }|S )NP_{r-  rq  \right)}\left(rs  rF  \right)^{%s}r  )r   r  rI  r0  r  r  r0  r  s           rs   _print_jacobizLatexPrinter._print_jacobi  sZ    di00
1a?@qq!!!QQQJ?c/Os$;;C
ru   c                t    t          | j        |j                  \  }}}d|d|d|d}|d|z   d|z  z   }|S )NzC_{r-  r  rs  rF  r  r  r   r  rI  r0  r  r0  r  s          rs   _print_gegenbauerzLatexPrinter._print_gegenbauer  R    dk49--1aa<=AAqqq!!!D?c/Os$;;C
ru   c                l    t          | j        |j                  \  }}d|d|d}|d|z   d|z  z   }|S )NzT_{r7  rs  rF  r  r  r   r  rI  r0  r0  r  s         rs   _print_chebyshevtzLatexPrinter._print_chebyshevt  J    4;	**11*+!!QQQ/?c/Os$;;C
ru   c                l    t          | j        |j                  \  }}d|d|d}|d|z   d|z  z   }|S )NzU_{r7  rs  rF  r  r  r  s         rs   _print_chebyshevuzLatexPrinter._print_chebyshevu  r  ru   c                l    t          | j        |j                  \  }}d|d|d}|d|z   d|z  z   }|S )Nr  r7  rs  rF  r  r  r  s         rs   _print_legendrezLatexPrinter._print_legendre  r  ru   c                t    t          | j        |j                  \  }}}d|d|d|d}|d|z   d|z  z   }|S )Nr  r-  r  rs  rF  r  r  r  s          rs   _print_assoc_legendrez"LatexPrinter._print_assoc_legendre  r  ru   c                l    t          | j        |j                  \  }}d|d|d}|d|z   d|z  z   }|S )NzH_{r7  rs  rF  r  r  r  s         rs   _print_hermitezLatexPrinter._print_hermite  r  ru   c                l    t          | j        |j                  \  }}d|d|d}|d|z   d|z  z   }|S )NL_{r7  rs  rF  r  r  r  s         rs   _print_laguerrezLatexPrinter._print_laguerre  r  ru   c                t    t          | j        |j                  \  }}}d|d|d|d}|d|z   d|z  z   }|S )Nr  r-  r  rs  rF  r  r  r  s          rs   _print_assoc_laguerrez"LatexPrinter._print_assoc_laguerre  r  ru   c           	     |    t          | j        |j                  \  }}}}d|d|d|d|d	}|d|z   d|z  z   }|S )NzY_{rw  r7  rq  rs  rF  r  r  r   r  rI  r0  mthetaphir  s           rs   
_print_YnmzLatexPrinter._print_Ynm  [    t{DI661eSS23!!QQQsssC?c/Os$;;C
ru   c           	     |    t          | j        |j                  \  }}}}d|d|d|d|d	}|d|z   d|z  z   }|S )NzZ_{rw  r7  rq  rs  rF  r  r  r  s           rs   
_print_ZnmzLatexPrinter._print_Znm"  r  ru   c           
     v    t          | j        |          \  }}}|rdnd}|sdnd|z  }||d|d|d|d|
S )Nz	^{\prime}r   rx  rF  rO  rs  )rH  r	  )	r   	characterrB  r   rI  r  r  r  sups	            rs   __print_mathieu_functionsz&LatexPrinter.__print_mathieu_functions)  s`    dk4((1a#+ll.bb33<9ccc111aaaCCPPru   c                <    |                      d|j        |          S )NCr  &_LatexPrinter__print_mathieu_functionsrB  rH  s      rs   _print_mathieuczLatexPrinter._print_mathieuc/      --c49#-FFFru   c                <    |                      d|j        |          S )Nr   r  r  rH  s      rs   _print_mathieuszLatexPrinter._print_mathieus2  r  ru   c                >    |                      d|j        d|          S )Nr  Tr   rI  r  rH  s      rs   _print_mathieucprimez!LatexPrinter._print_mathieucprime5  !    --c49Dc-RRRru   c                >    |                      d|j        d|          S )Nr   Tr  r  rH  s      rs   _print_mathieusprimez!LatexPrinter._print_mathieusprime8  r  ru   c                    |j         dk    r@d}|j        }|j        dk     rd}| }| j        d         rd|||j         fz  S d|||j         fz  S |                     |j                  S )Nrp  r   r   r  r   z	%s%d / %dz%s\frac{%d}{%d})r  r  r   r	  )r   r  signr  s       rs   _print_RationalzLatexPrinter._print_Rational;  s|    6Q;;DAvzzB~/0 8#tQ&777%q$&(999;;tv&&&ru   c                @   |                      |j                  }|j        rt          d |j        D                       st	          |j                  dk    r|dz  }t	          |j                  dk    r||                      |j                  z  }n*|j        r#||                      |j        d                   z  }|dz  }t	          |j                  dk    r||                      |j                  z  }n#||                      |j        d                   z  }d|z  S )Nc              3  6   K   | ]}|t           j        k    V  d S r  )r   rQ  )r/  r  s     rs   r1  z,LatexPrinter._print_Order.<locals>.<genexpr>J  s(      >>aa16k>>>>>>ru   rp  r  r   \rightarrow zO\left(%s\right))r	  r  pointr:  r  	variables)r   r  rr   s      rs   _print_OrderzLatexPrinter._print_OrderH  s   KK	"": 	0#>>4:>>>>> 	0t~""IA4>""Q&&T[[000 4T[[!2333 A4:""T[[,,,T[[A///"Q&&ru   r   c                    | j         d                             |          }||S |                     |j        |          S )Nr   style)r   r   rP  rT  )r   r  r  rT  s       rs   _print_SymbolzLatexPrinter._print_SymbolX  sB    N>266t<<K((%(@@@ru   stringc                :   d|v r|g g }}}n:t          |          \  }}}t          |          }d |D             }d |D             }|dk    rd                    |          }|r|dd                    |          z  z  }|r|dd                    |          z  z  }|S )	Nr   c                ,    g | ]}t          |          S rp   	translater/  r  s     rs   rN  z5LatexPrinter._deal_with_super_sub.<locals>.<listcomp>h      777inn777ru   c                ,    g | ]}t          |          S rp   r  r/  r3  s     rs   rN  z5LatexPrinter._deal_with_super_sub.<locals>.<listcomp>i      333sIcNN333ru   r   \mathbf{{{}}}rx  r   rG  )r   r  r  rS  )r   r  r  rT  supersrg  s         rs   rP  z!LatexPrinter._deal_with_super_suba  s    &==!'R$&DD!0!8!8D&$T??D77777F33d333D F??#**400D  	/Gchhv....D 	-Gchhtnn,,Dru   c                    | j         d         rd}d}nd}d}d||ddd	d
}|                     |j                  d||j                 d|                     |j                  S )Nr   z\gtz\lt><re  z\geqz\leqz\neq)z==r  r  z>=z<=z!=r   )r   r	  lhsrel_oprhs)r   r  gtltcharmaps        rs   _print_RelationalzLatexPrinter._print_Relationalw  s    >&! 	BBBBB 
 
 "[[2222$T[1114;;tx3H3H3HJ 	Jru   c                     fd|j         d d         D             }|j         d         j        t          k    r<|                    d                     |j         d         j                  z             n`|                                         |j         d         j                  d                     |j         d         j                             d}|d                    |          z  S )Nc                p    g | ]2\  }}                     |          d                      |          3S ) & \text{for}\: rM  )r/  rW  r   r   s      rs   rN  z1LatexPrinter._print_Piecewise.<locals>.<listcomp>  sL     / / /q! /3kk!nnnndkk!nnnM / / /ru   ro  z%s & \text{otherwise}r  z\begin{cases} %s \end{cases}rt  )rB  condr   r<  r	  r  rS  )r   r  ecpairsr  s   `   rs   _print_PiecewisezLatexPrinter._print_Piecewise  s    / / / /#y"~/ / /9R=%%NN3;;ty}'9::; < < < < NN KK	"(:;;;; KK	"(:;;;= > > > .V[[))))ru   c           
         g }t          |j                  D ]@}|                    d                     fd||d d f         D                                  A j        d         }|& j        d         dk    rd}n|j        dk    du rd	}nd
}d}|                    d|          }|d
k    r$|                    ddd|j        z  z   dz             }|d                    |          z  S )Nr  c                :    g | ]}                     |          S rp   rM  r  s     rs   rN  z7LatexPrinter._print_matrix_contents.<locals>.<listcomp>  s#    $K$K$KT[[^^$K$K$Kru   r   r   r   smallmatrix
   Tmatrixarray \begin{%MATSTR%}%s\end{%MATSTR%}%MATSTR%r  r   r   }%sr  )r  rowsr<  rS  r   colsr   )r   r  linesliner   out_strs   `     rs   _print_matrix_contentsz#LatexPrinter._print_matrix_contents  s	   $)$$ 	N 	NDLL$K$K$K$KT$']$K$K$KLLMMMM.+?~f%11'IO,,&GG%G5//*g66goodC#di-,?%,GHHGE****ru   c                    |                      |          }| j        d         r(| j        d         }| j        |         }d|z   |z   dz   |z   }|S )Nr   \left\right)r  r   r   )r   r  r  
left_delimright_delims        rs   _print_MatrixBasezLatexPrinter._print_MatrixBase  sa    --d33>+& 	.4J*:6K+g5 "-.Gru   c                    |                      |j        t          d         d          }|                     |j                   d|                     |j                   }d| d| dS )Nr  Tr  rq  r   }_{ro   )r  parentr!   r	  r   r   )r   r  matrix_part
index_parts       rs   _print_MatrixElementz!LatexPrinter._print_MatrixElement  sl    ''Z5GPT'UUDF++CCdkk$&.A.ACC
4K44j4444ru   c                      fd}                      |j        t          d         d          dz    ||j        |j        j                  z   dz    ||j        |j        j                  z   dz   S )Nc                    t          |           } | d         dk    r| d= | d         dk    rd | d<   | d         |k    rd | d<   d                    fd| D                       S )Nr  rp  r   :c              3  J   K   | ]}|                     |          ndV  d S Nr   rM  )r/  xir   s     rs   r1  zFLatexPrinter._print_MatrixSlice.<locals>.latexslice.<locals>.<genexpr>  s5      RR"r~DKKOOO2RRRRRRru   )r  rS  )r0  r\  r   s     rs   
latexslicez3LatexPrinter._print_MatrixSlice.<locals>.latexslice  sv    QAtqyyaDtqyy!ts{{!88RRRRPQRRRRRRru   r  Tr  \left[rO  \right])r  r  r!   rowslicer  colslicer  )r   r  r  s   `  rs   _print_MatrixSlicezLatexPrinter._print_MatrixSlice  s    	S 	S 	S 	S 	S !!$+z&/A$!OOR[[
4=$+*:;;<>BC
4=$+*:;;<>HI 	Jru   c                6    |                      |j                  S r  )r	  blocksr  s     rs   _print_BlockMatrixzLatexPrinter._print_BlockMatrix  s    {{4;'''ru   c                   |j         }ddlm}m} t	          ||          s/t	          ||          s|j        rd|                     |          z  S |                     |t          |          d          }d|v rd|z  S d|z  S )Nr   MatrixSymbolBlockMatrixz\left(%s\right)^{T}Tr   z%s^{T})	r<   sympy.matricesr  r  r  is_MatrixExprr	  r  r   )r   r  r  r  r  rr   s         rs   _print_TransposezLatexPrinter._print_Transpose  s    h<<<<<<<<3-- 	$3,,	$141B	$)DKK,<,<<<!!#'=d'C'CTJJAaxx-11!|#ru   c                @    |j         }d|                     |          z  S )Nz!\operatorname{tr}\left(%s \right))r<   r	  r   r  r  s      rs   _print_TracezLatexPrinter._print_Trace  s     h3dkk#6F6FFFru   c                f   dddd}|                     | j        d         d          }|j        }ddlm}m} t          ||          s3t          ||          s#|j        rd|                     |          d	|d
S | 	                    |t          |          d          }d|v r	d|d	|d
S |d|d
S )Nz\daggerz\astz
\mathsf{H})r   star	hermitianr   r   r  rF  rG  ro   Tr   r  )r   r   r<   r  r  r  r  r  r	  r  r   )r   r  style_to_latexr   r  r  r  rr   s           rs   _print_AdjointzLatexPrinter._print_Adjoint  s    # &
 

 '**4>/+JJWWh<<<<<<<<3-- 	73,,	7141B	7 	7.2kk#.>.>.>.>NN!!#'=d'C'CTJJAaxxx23!!]]]CC%&QQ66ru   c                J    ddl m  fd}t          j                  }                                rI|d         dk    r|dd          }n|d          |d<   dd                    t          ||                    z   S d                    t          ||                    S )Nr   )MatMulc                    t          | t                    r%t          |           s                    |           n#                    | t	                    d          S NF)r  r
   r	  r  r   )r0  r  r  r   s    rs   rt   z,LatexPrinter._print_MatMul.<locals>.<lambda>  sZ    Z3-?-? F
STV\H]H] F4;;q>>>a!7!=!=uEE ru   ro  rp  r  r   )sympyr  r  rB  r7  rS  rH  )r   r  parensrB  r  s   ``  @rs   _print_MatMulzLatexPrinter._print_MatMul  s          F F F F F F DI((** 	/Aw"}}ABBx7(Q#((3vt#4#4555588C--...ru   c                    |j         }|j        rKddlm} t	          ||          rd|                     |j                  z  S d|                     |          z  S d|                     |          z  S )Nr   )r  r  )r<   r  &sympy.matrices.expressions.blockmatrixr  r  r  r  r	  )r   r  r  r  s       rs   _print_DeterminantzLatexPrinter._print_Determinant  s    h 	;JJJJJJ#{++ V+d.I.I#*.U.UUU'$++c*:*:::#d&A&A#&F&FFFru   c                   |dd|                      |j        d         t          d         d          d|                      |j        d         t          d         d          d|d	S |                      |j        d         t          d         d          d|                      |j        d         t          d         d          S )
NrF  r   r
   Tr  z \bmod rp  rG  ro   r$  rH  s      rs   
_print_ModzLatexPrinter._print_Mod  s    ??""49Q<E1B*. # 0 0 0 0""49Q<E1B*. # 0 0 0 0  "&!2!249Q<3=e3D:> "3 "@ "@ "@ "@ "&!2!249Q<3=e3D:> "3 "@ "@ "@A 	Aru   c                    |j         }t          d         | j        d                    fd|D                       S )Nr   z \circ c              3  4   K   | ]} |d           V  dS Tr  Nrp   r/  r<   r"  precs     rs   r1  z6LatexPrinter._print_HadamardProduct.<locals>.<genexpr>!  4      <<VVCd+++<<<<<<ru   rB  r!   r  rS  r   r  rB  r"  r-  s      @@rs   _print_HadamardProductz#LatexPrinter._print_HadamardProduct  sM    y% "<<<<<t<<<> > 	>ru   c                ~    t          |j                  t          d         k     rd}nd}|                     ||          S )Nr
   z%s^{\circ \left({%s}\right)}z%s^{\circ {%s}})r   rI  r!   r   )r   r  r  s      rs   _print_HadamardPowerz!LatexPrinter._print_HadamardPower#  s>    !$(++j.???6HH)H00x@@@ru   c                    |j         }t          d         | j        d                    fd|D                       S )Nr   	 \otimes c              3  4   K   | ]} |d           V  dS r+  rp   r,  s     rs   r1  z7LatexPrinter._print_KroneckerProduct.<locals>.<genexpr>0  r.  ru   r/  r0  s      @@rs   _print_KroneckerProductz$LatexPrinter._print_KroneckerProduct*  sO    y% "  <<<<<t<<<> > 	>ru   c                V   |j         |j        }}ddlm} t	          ||          s6|j        r/d|                     |          d|                     |          dS |                     |          }d|v rd|d|                     |          dS |d|                     |          dS )Nr   )r  rF  rG  ro   r   r  )rD  rI  r  r  r  r  r	  )r   r  rD  rI  r  base_strs         rs   _print_MatPowzLatexPrinter._print_MatPow2  s    Itxc//////$-- 	@$2D 	@ 	@/3{{4/@/@/@/@.2kk#.>.>.>.>@ @ {{4((Hh2:((DKK<L<L<L<LMM$,HHdkk#.>.>.>.>??ru   c                F    |                      || j        d                   S )Nr   r  )r  r   r  s     rs   _print_MatrixSymbolz LatexPrinter._print_MatrixSymbol?  s+    !!$dn/ ! ! ! 	!ru   c                ,    | j         d         dk    rdndS )Nr   r   0z
\mathbf{0}r   )r   Zs     rs   _print_ZeroMatrixzLatexPrinter._print_ZeroMatrixC  (    n #*+ +ss0=	>ru   c                ,    | j         d         dk    rdndS )Nr   r   1z
\mathbf{1}r?  )r   Os     rs   _print_OneMatrixzLatexPrinter._print_OneMatrixG  rB  ru   c                ,    | j         d         dk    rdndS )Nr   r   z
\mathbb{I}z
\mathbf{I}r?  )r   r  s     rs   _print_IdentityzLatexPrinter._print_IdentityK  s(     $! #*!+ !+}}0=	>ru   c                L    |                      |j        d                   }d|z  S )Nr   zP_{%s}r  )r   Pperm_strs      rs   _print_PermutationMatrixz%LatexPrinter._print_PermutationMatrixO  s$    ;;qvay))(""ru   r&   c           
        |                                 dk    r|                     |d                   S | j        d         }|B| j        d         dk    rd}n.|                                 dk    s|j        d         dk    rd	}nd
}d}|                    d|          }|d
k    r*|                    ddd|j        d         z  z   dz             }| j        d         r(| j        d         }| j        |         }d|z   |z   dz   |z   }|                                 dk    r|dz  S d t          |                                 dz             D             }d |j        D             }t          j        | D ]C}|d         	                    |                     ||                              d}	t          |                                 dz
  dd          D ]}
t          ||
dz                      |j        |
         k     r n|	r8||
         	                    d                    ||
dz                                 ns||
         	                    |d                    ||
dz                      z             t          ||
dz                      dk    rd||
         d         z   dz   ||
         d<   |	 }	g ||
dz   <   E|d         d         }|                                 dz  dk    r||z  }|S )Nr   rp   r   r   r   r  ro  r  r  r  r  r  r  r   r   r  r   r  r  r   c                    g | ]}g S rp   rp   rW  s     rs   rN  z1LatexPrinter._print_NDimArray.<locals>.<listcomp>o  s    %I%I%IQb%I%I%Iru   rp  c                F    g | ]}t          t          |                    S rp   )r  r  rW  s     rs   rN  z1LatexPrinter._print_NDimArray.<locals>.<listcomp>p  s$    ;;;1U1XX;;;ru   Tr  r  r  r  r  )rankr	  r   shaper   r   r  	itertoolsproductr<  r  rS  )r   r  r   	block_strr  r  	level_strshape_rangesouter_ievenback_outer_ir  s               rs   _print_NDimArrayzLatexPrinter._print_NDimArrayS  s    99;;!;;tBx(((.+?~f%11'IIKK1$$$*R.B*>*>&GG%G7	%%j'::	g!))$c$*Q-6G0G%0OPPI>+& 	0"n[9J*:6K :-	9!"$/0I 99;;!r>!%I%I%		a2H2H%I%I%I	;;
;;; (,7 	/ 	/GbM  T']!;!;<<<D %diikk!mR < < / /ya011DJ|4LLLE El+22Il1n$=>>@ @ @ @ l+22!UZZ	,q.0I%J%JKM M M9\!^455::6?%l3B778:D7E	,/3x,.	,q.))A,q/99;;?a')Gru   	index_mapdictc                `   |                      |          }d }d }|D ]}|j        }||v s|r||k    r|dz  }||k    r||dz  }|j        r|dz  }n|dz  }||                      |j        d                   z  }||v r&|dz  }||                      ||                   z  }d}nd}|}||dz  }|S )	Nrq  ro   z{}^{z{}_{r   re  TF)r	  is_uprB  )	r   rT  rI  r[  r  last_valenceprev_mapindexnew_valences	            rs   _printer_tensor_indicesz$LatexPrinter._printer_tensor_indices  s   ++d## 	' 	'E+K)### K//3{**+sNG; &v%GGv%Gt{{5:a=111G	!!34;;y'7888 &LL#sNGru   c                    |j         d         j         d         }|                                }|                     ||i           S r  )rB  get_indicesrc  )r   r  rT  rI  s       rs   _print_TensorzLatexPrinter._print_Tensor  s>    y| #""$$++D'2>>>ru   c                    |j         j        d         j        d         }|j                                         }|j        }|                     |||          S r  )r  rB  re  r[  rc  )r   r  rT  rI  r[  s        rs   _print_TensorElementz!LatexPrinter._print_TensorElement  sJ    y~a %a()''))N	++D'9EEEru   c                ~                                      \  }}|d                     fd|D                       z   S )Nr   c                V    g | ]%}                     |t                              &S rp   )r  r    )r/  r<   r  r   s     rs   rN  z/LatexPrinter._print_TensMul.<locals>.<listcomp>  s1    FFF#TsJt$4$455FFFru   )!_get_args_for_traditional_printerrS  )r   r  r  rB  s   ``  rs   _print_TensMulzLatexPrinter._print_TensMul  sP    ;;==
dbggFFFFFFFF
 
 
 	
ru   c           	        g }|j         }|D ]8}|                    |                     |t          |                               9|                                 d                    |          }|                    dd          }|S )Nrc  z+ -r  )rB  r<  r  r    r;  rS  r   )r   r  r  rB  r0  rr   s         rs   _print_TensAddzLatexPrinter._print_TensAdd  s~    y 	= 	=AHHT&&q*T*:*:;;<<<<	JJqMMIIeT""ru   c                b    d|j         rdndd|                     |j        d                   dS )Nz{}r   r  r   r   ro   )r^  r	  rB  r  s     rs   _print_TensorIndexzLatexPrinter._print_TensorIndex  s=     :&CC3&&KK	!%%%%
 	
ru   c           
         t          |j                  dk    rLd                     |j        d                   d                     |j        t
          d         d          dS dt          |j                  dd	                     fd
|j        D                       d                     |j        t
          d         d          dS )Nrp  z\frac{\partial}{\partial {r   rT  r
   Fro   z\frac{\partial^{r   c                @    g | ]}d                      |          z  S )z\partial {%s}rM  r  s     rs   rN  z9LatexPrinter._print_PartialDerivative.<locals>.<listcomp>  s)    TTT*T[[^^;TTTru   r  )r  r  r	  r  r  r!   rS  r  s   ` rs   _print_PartialDerivativez%LatexPrinter._print_PartialDerivative  s    t~!###DN1-....!!$)Z->FFFF  $ DN####TTTTT^TTTUUUU!!$)Z->FFFF ru   c                6    |                      |j                  S r  )r	  rT  r  s     rs   _print_ArraySymbolzLatexPrinter._print_ArraySymbol  s    {{49%%%ru   c                     d                      |j        t          d         d          dd                     fd|j        D                       dS )Nz{{r#  Tr  rO  c                <    g | ]}                     |           S rp   rM  r  s     rs   rN  z4LatexPrinter._print_ArrayElement.<locals>.<listcomp>  s&    AAAq$++a..*AAAru   r  )r  rT  r!   rS  rI  r  s   ` rs   _print_ArrayElementz LatexPrinter._print_ArrayElement  s_     diF);TBBBBIIAAAADLAAABBBBD 	Dru   c                    dS )Nz
\mathbb{U}rp   r  s     rs   _print_UniversalSetz LatexPrinter._print_UniversalSet      }ru   c                    |#d|                      |j        d                   z  S d|                      |j        d                   d|dS )Nz$\operatorname{frac}{\left(%s\right)}r   z\operatorname{frac}{\left(z
\right)}^{ro   r  rH  s      rs   _print_fraczLatexPrinter._print_frac  sW    ;:T[[ST=V=VVV  KK	!----sss4 4ru   c                h     j         d         dk    rd}n# j         d         dk    rd}nt          d          t          |          dk    r1                                          |d                   |z             S                      |d	z                        fd
|D                                 S )Nr   r  ;r   rq  Unknown Decimal Separatorrp  r   z \  c                :    g | ]}                     |          S rp   rM  r  s     rs   rN  z-LatexPrinter._print_tuple.<locals>.<listcomp>  s#    %C%C%Cdkk!nn%C%C%Cru   )r   r   r  r  r	  rS  )r   r  seps   `  rs   _print_tuplezLatexPrinter._print_tuple  s    >-.'99CC^/0H<<CC8999t99>>**4;;tAw+?+?#+EFFF**w$$%C%C%C%Cd%C%C%CDDF F Fru   c                T      fd|j         D             }d                    |          S )Nc                :    g | ]}                     |          S rp   rM  r/  r  r   s     rs   rN  z5LatexPrinter._print_TensorProduct.<locals>.<listcomp>  #    666qDKKNN666ru   r5  rB  rS  r   r  elementss   `  rs   _print_TensorProductz!LatexPrinter._print_TensorProduct  s2    6666DI666  ***ru   c                T      fd|j         D             }d                    |          S )Nc                :    g | ]}                     |          S rp   rM  r  s     rs   rN  z4LatexPrinter._print_WedgeProduct.<locals>.<listcomp>  r  ru    \wedge r  r  s   `  rs   _print_WedgeProductz LatexPrinter._print_WedgeProduct  s2    6666DI666)))ru   c                ,    |                      |          S r  )r  r  s     rs   _print_TuplezLatexPrinter._print_Tuple  s      &&&ru   c                      j         d         dk    r$dd                     fd|D                       z  S  j         d         dk    r$dd                     fd|D                       z  S t          d	          )
Nr   r  z\left[ %s\right]z; \  c                :    g | ]}                     |          S rp   rM  r  s     rs   rN  z,LatexPrinter._print_list.<locals>.<listcomp>  #    <<<!t{{1~~<<<ru   r   , \  c                :    g | ]}                     |          S rp   rM  r  s     rs   rN  z,LatexPrinter._print_list.<locals>.<listcomp>  r  ru   r  )r   rS  r   r  s   ` rs   _print_listzLatexPrinter._print_list  s    >-.'99&<<<<t<<<==> >^/0H<<&<<<<t<<<==> > 8999ru   c                    t          |                                t                    }g }|D ]J}||         }|                    |                     |          d|                     |                     Kdd                    |          z  S )Nr1  z : z\left\{ %s\right\}r  )r  keysr   r<  r	  rS  )r   r   r  r9  r2  vals         rs   _print_dictzLatexPrinter._print_dict  s    affhh$4555 	K 	KCC&CLLdkk#&6&6&6&6C8H8H8HIJJJJ$x}}U';';;;ru   c                ,    |                      |          S r  )r  r  s     rs   _print_DictzLatexPrinter._print_Dict  s    %%%ru   c                @   t          |j                  dk    s|j        d         dk    r$d|                     |j        d                   z  }nEd|                     |j        d                   d|                     |j        d                   d}|r	d|d|d	}|S )
Nrp  r   z\delta\left(%s\right)z\delta^{\left( z \right)}\left( r  rF  rG  ro   r  r  s       rs   _print_DiracDeltazLatexPrinter._print_DiracDelta  s    ty>>Q$)A,!"3"3*T[[1-F-FFCC #4 DIaL))))4;;ty|+D+D+D+DFC 	7 	7-0SS###6C
ru   c                    |                      |j        d         |j        d         z
            }|                      |j        d                   }d|d|d}|d|d|d	|d}|S )
Nr   rp  r  z{\left\langle z \right\rangle}^{ro   z{\left({\langle z \rangle}^{z}\right)}^{r  )r   r  rI  shiftr  r  s         rs   _print_SingularityFunctionz'LatexPrinter._print_SingularityFunction#  sv    DIaL49Q<788DIaL))9>F??FKeeUUUTWTWTWXC
ru   c                t     d                      fd|j        D                       }d|z  }|r	d|d|d}|S )NrO  c              3  B   K   | ]}                     |          V  d S r  rM  r  s     rs   r1  z0LatexPrinter._print_Heaviside.<locals>.<genexpr>,  s/      AAs$++c**AAAAAAru   z\theta\left(%s\right)rF  rG  ro   )rS  pargs)r   r  rI  r  r  s   `    rs   _print_HeavisidezLatexPrinter._print_Heaviside+  sY    		AAAAdjAAAAA&. 	7 	7-0SS###6C
ru   c                
   |                      |j        d                   }|                      |j        d                   }|j        d         j        r|j        d         j        r
d|d|d}n	d|d|d}|	d|d|d}|S )	Nr   rp  z\delta_{r   ro   rO  rF  rG  )r	  rB  r  )r   r  rI  r   r   r  s         rs   _print_KroneckerDeltaz"LatexPrinter._print_KroneckerDelta2  s    KK	!%%KK	!%%9Q< 	.DIaL$8 	. 	.'(qq!!!,CC()111-C??-0SS###6C
ru   c                    t          | j        |j                  }t          d |j        D                       rdd                    |          z  }ndd                    |          z  }|r	d|d|d}|S )Nc              3  $   K   | ]}|j         V  d S r  )r  )r/  r0  s     rs   r1  z1LatexPrinter._print_LeviCivita.<locals>.<genexpr>?  s$      ,,Qqy,,,,,,ru   z\varepsilon_{%s}r   rO  rF  rG  ro   )rH  r	  rB  rz  rS  )r   r  rI  rI  r  s        rs   _print_LeviCivitazLatexPrinter._print_LeviCivita=  s    dk49--,,$),,,,, 	;%(9(99CC%		'(:(::C 	7 	7-0SS###6C
ru   c                   t          |d          r*d|                     |                                          z   S t          |d          r;d|                     |j                  z   dz   |                     |j                  z   S t          |d          rd|                     |j                  z   S |                     d           S )N
as_booleanz\text{Domain: }set \in r|  z\text{Domain on })r  r	  r  r|  r  )r   r   s     rs   _print_RandomDomainz LatexPrinter._print_RandomDomainG  s    1l## 	%%ALLNN(C(CCCQ 	%&QY)?)??(JKK&&' (Q	"" 	%'$++ai*@*@@@;;t$$$ru   c                b    t          |j        t                    }|                     |          S )Nr1  )r  rB  r   
_print_setr   rr   r9  s      rs   _print_FiniteSetzLatexPrinter._print_FiniteSetR  s)    qv#3444u%%%ru   c                >   t          |t                    }| j        d         dk    r)d                    t	          | j        |                    }nI| j        d         dk    r)d                    t	          | j        |                    }nt          d          d|z  S )	Nr1  r   r  r  r   rO  r  \left\{%s\right\})r  r   r   rS  rH  r	  r   r  s      rs   r  zLatexPrinter._print_setV  s    q.///>-.'99IIc$+u5566EE^/0H<<IIc$+u5566EE8999#e++ru   c                     fd}t                      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}nwj        fj	        dk     dk    rt                    }nQj        r6t                    }t          |          t          |          d         f}n |            S  |            S dd                     fd	|D                       z   d
z   S )Nc                    j         d         dk    rYj         d         dk    r!                    j         d                   } nd                    fdj         D                       } nfj         d         dk    r/d                    fdj         d d         D                       } n&d                    fdj         D                       } d|  d	S )
Nr   r  rp  rO  c              3  B   K   | ]}                     |          V  d S r  rM  r  s     rs   r1  zKLatexPrinter._print_Range.<locals>._print_symbolic_range.<locals>.<genexpr>j  /      $H$H#T[[%5%5$H$H$H$H$H$Hru   c              3  B   K   | ]}                     |          V  d S r  rM  r  s     rs   r1  zKLatexPrinter._print_Range.<locals>._print_symbolic_range.<locals>.<genexpr>m  s/      $L$L#T[[%5%5$L$L$L$L$L$Lru   c              3  B   K   | ]}                     |          V  d S r  rM  r  s     rs   r1  zKLatexPrinter._print_Range.<locals>._print_symbolic_range.<locals>.<genexpr>o  r  ru   z\text{Range}\left(rs  )rB  r	  rS  )contrr   r   s    rs   _print_symbolic_rangez8LatexPrinter._print_Range.<locals>._print_symbolic_ranged  s    vayA~~6!9>>;;qvay11DD99$H$H$H$H$H$H$HHHDD6!9>>99$L$L$L$L$L$L$LLLDD99$H$H$H$H$H$H$HHHD:D:::;ru   ro  r   rp  ro  T\left\{rO  c              3  N   K   | ]}|ur                     |          nd V   dS z\ldotsNrM  r/  eldotsr   s     rs   r1  z,LatexPrinter._print_Range.<locals>.<genexpr>  :      __PRbnn4;;r???)______ru   \right\})objectstartis_infinitestopstepis_positiveiternextis_emptyru  r  is_iterablerS  )r   rr   r  printsetitr  s   ``   @rs   _print_RangezLatexPrinter._print_Rangec  s   	< 	< 	< 	< 	< 	< xx7 	+16#5 	+v! 0Q4/Ar4/W  	+QrUQV^QrU2HHV 	+aBBxxb4/HHZ#
t## 88 /!WW88T"XXtQrU:,,...((***

_____V^_____` 	ru   c           
        t          |j                  dk    r|J|d|                     |j        d                   d|d|                     |j        d                   dS |d|                     |j        d                   d|                     |j        d                   dS |d|                     |j        d                   d}||d	|d}|S )
Nr  rv  r   rw  r7  rp  rs  ro   r  r  )r   r  letterrI  r  s        rs   __print_number_polynomialz&LatexPrinter.__print_number_polynomial  s    ty>>Q9? KK	!5555sss KK	!55557 7 17DIaL11114;;ty|3L3L3L3LN N #FFDKK	!$=$=$=$=>? #SSS)C
ru   c                0    |                      |d|          S Nr  &_LatexPrinter__print_number_polynomialrH  s      rs   _print_bernoullizLatexPrinter._print_bernoulli      --dC===ru   c                0    |                      |d|          S )NGr  rH  s      rs   _print_genocchizLatexPrinter._print_genocchi  r  ru   c                r    t          |j                  dk    rd                     |j        d                   d                     |j        d                   d}dd                     fd|j        d	         D                       z  }||d
|d|}n||z   }|S                      |d|          S )Nr4  zB_{r   rO  rp  ro   rd  c              3  B   K   | ]}                     |          V  d S r  rM  )r/  r  r   s     rs   r1  z+LatexPrinter._print_bell.<locals>.<genexpr>  sI       3C 3C/1 48;;r?? 3C 3C 3C 3C 3C 3Cru   r  r  r  )r  rB  r	  rS  r  )r   r  rI  tex1tex2r  s   `     rs   _print_bellzLatexPrinter._print_bell  s    ty>>Q$(KK	!$=$=$=$= $DIaL 9 9 9 9;D%

 3C 3C 3C 3C59Yq\3C 3C 3C )C )C CD&*ddCCC6TkJ--dC===ru   c                0    |                      |d|          S NFr  rH  s      rs   _print_fibonaccizLatexPrinter._print_fibonacci  r  ru   c                `    d|                      |j        d                   z  }||d|d}|S )NzL_{%s}r   r  ro   r  r  s       rs   _print_lucaszLatexPrinter._print_lucas  :    $++dil333? #SSS)C
ru   c                0    |                      |d|          S )NTr  rH  s      rs   _print_tribonaccizLatexPrinter._print_tribonacci  r  ru   c                    |#d|                      |j        d                   z  S d|d|                      |j        d                   dS )Nz\mu\left(%s\right)r   z\mu^{r7  rs  r  rH  s      rs   _print_mobiuszLatexPrinter._print_mobius  sP    ;(4;;ty|+D+DDD -0SS$++dil2K2K2K2KLLru   c           
     X    t                      t          |j        j                  dk    st          |j        j                  dk    rud                     |j                  d                     |j        d                   d                     |j                  d                     |j                  d	S |j        t          j	        u rd|j        }|
                    |dz
            |
                    |dz
            |
                    |d	z
            |
                    |          f}nM|j        t          j        u s|j        d
k    r |d d
         }|                               nt          |          }dd                     fd|D                       z   dz   S )Nr   r  z
\right\}_{re  rw  ro   r4  r  rp  ro  r  rO  c              3  N   K   | ]}|ur                     |          nd V   dS r  rM  r  s     rs   r1  z1LatexPrinter._print_SeqFormula.<locals>.<genexpr>  r  ru   r  )r  r  r  free_symbolsr  r	  formular  r   r  coeffr  lengthr<  r  rS  )r   rr   r  r  r  s   `   @rs   _print_SeqFormulazLatexPrinter._print_SeqFormula  s   xxqw#$$q((C0C,D,Dq,H,HAI&&&&AKN++++AG$$$$AF####	  7a(((6DaggdQh//1B1Bq))1774==:HHVqz!!QX\\!uHOOD!!!!QxxH

_____V^_____` 	ru   c                   |j         |j        k    rd|                     |j                   z  S |j        rd}nd}|j        rd}nd}d||                     |j                   d|                     |j                  d|S )	Nr  r   r   r   r   r  rO  r  )r  endr	  	left_open
right_open)r   r   leftrights       rs   _print_IntervalzLatexPrinter._print_Interval  s    7ae'$++ag*>*>>> { |  D$++ag....AE0B0B0B0BEEK Kru   c                t    d|                      |j                  d|                      |j                  dS )Nz\left\langle rO  z\right\rangle)r	  r   r   r   r   s     rs   _print_AccumulationBoundsz&LatexPrinter._print_AccumulationBounds  s;     QU####T[[%7%7%7%79 	9ru   c                v     t          |           fd|j        D             }d                    |          S )Nc                <    g | ]}                     |          S rp   r  r/  r   r-  r   s     rs   rN  z-LatexPrinter._print_Union.<locals>.<listcomp>  )    ???1D%%a..???ru   z \cup r   rB  rS  r   uargs_strr-  s   `  @rs   _print_UnionzLatexPrinter._print_Union  A    %a((????????~~h'''ru   c                v     t          |           fd|j        D             }d                    |          S )Nc                <    g | ]}                     |          S rp   r  r  s     rs   rN  z2LatexPrinter._print_Complement.<locals>.<listcomp>  r  ru   z \setminus r  r  s   `  @rs   _print_ComplementzLatexPrinter._print_Complement  C    %a((????????""8,,,ru   c                v     t          |           fd|j        D             }d                    |          S )Nc                <    g | ]}                     |          S rp   r  r  s     rs   rN  z4LatexPrinter._print_Intersection.<locals>.<listcomp>  r  ru   z \cap r  r  s   `  @rs   _print_Intersectionz LatexPrinter._print_Intersection  r  ru   c                v     t          |           fd|j        D             }d                    |          S )Nc                <    g | ]}                     |          S rp   r  r  s     rs   rN  z;LatexPrinter._print_SymmetricDifference.<locals>.<listcomp>	  r  ru   z \triangle r  r  s   `  @rs   _print_SymmetricDifferencez'LatexPrinter._print_SymmetricDifference  r  ru   c                <    t          |          t          |j                  dk    rMt          |j                  s9                     |j        d                   dt          |j                  z  z   S d                     fd|j        D                       S )Nrp  r   z^{%d}r   c              3  D   K   | ]}                     |          V  d S r  r  )r/  r  r-  r   s     rs   r1  z1LatexPrinter._print_ProductSet.<locals>.<genexpr>	  sD        <  <-0Dc4(( <  <  <  <  <  <ru   )r   r  setsr$   r  rS  )r   r  r-  s   ` @rs   _print_ProductSetzLatexPrinter._print_ProductSet	  s    %a((qv;;!K$7$7$$QVAY55#af++8MMM  <  <  <  <  <45F <  <  < < < 	<ru   c                    dS )Nz	\emptysetrp   r\  s     rs   _print_EmptySetzLatexPrinter._print_EmptySet	  s    |ru   c                    dS )Nz
\mathbb{N}rp   r   r0  s     rs   _print_NaturalszLatexPrinter._print_Naturals	  r{  ru   c                    dS )Nz\mathbb{N}_0rp   r  s     rs   _print_Naturals0zLatexPrinter._print_Naturals0	  s    ru   c                    dS Nz
\mathbb{Z}rp   r   s     rs   _print_IntegerszLatexPrinter._print_Integers	  r{  ru   c                    dS Nz
\mathbb{Q}rp   r   s     rs   _print_RationalszLatexPrinter._print_Rationals	  r{  ru   c                    dS Nz
\mathbb{R}rp   r   s     rs   _print_RealszLatexPrinter._print_Reals	  r{  ru   c                    dS Nz
\mathbb{C}rp   r   s     rs   _print_ComplexeszLatexPrinter._print_Complexes	  r{  ru   c                     |j         j        }|j         j        } fdt          ||j                  D             }d                    d |D                       }d                     |          d|dS )Nc              3  r   K   | ]1\  }}                     |                               |          fV  2d S r  rM  )r/  r0  r  r   s      rs   r1  z/LatexPrinter._print_ImageSet.<locals>.<genexpr>#	  s@      RRDAqAA/RRRRRRru   rO  c              3      K   | ]	}d |z  V  
dS )	%s \in %sNrp   )r/  xys     rs   r1  z/LatexPrinter._print_ImageSet.<locals>.<genexpr>$	  s'      ;;<",;;;;;;ru   r  \; \middle|\; r  )rX   r  	signaturerf  	base_setsrS  r	  )r   rr   r  sigxysxinyss   `     rs   _print_ImageSetzLatexPrinter._print_ImageSet 	  s~    w|gRRRRCQ[<Q<QRRR

;;s;;;;;7;{{47H7H7H7H%%%PPru   c           
     P    d                      fdt          |j                  D                       }|j        t          j        u r!d|d                     |j                  dS d|d|d                     |j                  d                     |j                  d	S )NrO  c                :    g | ]}                     |          S rp   rM  r/  r  r   s     rs   rN  z4LatexPrinter._print_ConditionSet.<locals>.<listcomp>(	  s%    IIISC 0 0IIIru   r  r3  	 \right\}r  r  )rS  r   r5  base_setr   UniversalSetr	  	conditionr   rr   
vars_prints   `  rs   _print_ConditionSetz LatexPrinter._print_ConditionSet'	  s    YYIIIIE!%LLIIIJJ
:'''T[[55557 7 (
 JJJJKK
####KK$$$$	& 	&ru   c                l    |                      |j        d                   }d                    |          S )Nr   z\mathcal{{P}}\left({}\right)r	  rB  r  )r   r  	arg_prints      rs   _print_PowerSetzLatexPrinter._print_PowerSet3	  s-    KK	!--	.55i@@@ru   c                     d                      fd|j        D                       }d                     |j                  d|d                     |j                  dS )NrO  c                :    g | ]}                     |          S rp   rM  r<  s     rs   rN  z5LatexPrinter._print_ComplexRegion.<locals>.<listcomp>8	  s%    HHHSC 0 0HHHru   r  r3  r  r=  )rS  r  r	  r  r  rA  s   `  rs   _print_ComplexRegionz!LatexPrinter._print_ComplexRegion7	  sl    YYHHHHAKHHHII

KKJJKK! 	!ru   c                J     dt           fd|j        D                       z  S )Nr1  c              3  B   K   | ]}                     |          V  d S r  rM  r  s     rs   r1  z/LatexPrinter._print_Contains.<locals>.<genexpr>?	  s-      #C#CqDKKNN#C#C#C#C#C#Cru   )r  rB  r\  s   ` rs   _print_ContainszLatexPrinter._print_Contains>	  s-    e#C#C#C#CAF#C#C#CCCCCru   c                    |j         j        t          j        u r2|j        j        t          j        u r|                     |j                  S |                     |                                          dz   S )Nz	 + \ldots)	ru  r  r   rQ  bnr	  a0rj  truncater  s     rs   _print_FourierSeriesz!LatexPrinter._print_FourierSeriesA	  sV    4<16!!adlaf&<&<;;qt$$$qzz||,,|;;ru   c                6    |                      |j                  S r  )rj  infiniter  s     rs   _print_FormalPowerSeriesz%LatexPrinter._print_FormalPowerSeriesF	  s    qz***ru   c                    d|j         z  S )Nz\mathbb{F}_{%s})modr  s     rs   _print_FiniteFieldzLatexPrinter._print_FiniteFieldI	  s    !DH,,ru   c                    dS r#  rp   r  s     rs   _print_IntegerRingzLatexPrinter._print_IntegerRingL	  r{  ru   c                    dS r&  rp   r  s     rs   _print_RationalFieldz!LatexPrinter._print_RationalFieldO	  r{  ru   c                    dS r)  rp   r  s     rs   _print_RealFieldzLatexPrinter._print_RealFieldR	  r{  ru   c                    dS r,  rp   r  s     rs   _print_ComplexFieldz LatexPrinter._print_ComplexFieldU	  r{  ru   c                    |                      |j                  }d                    t          | j         |j                            }|d|dS )NrO  r  r  r	  domainrS  rH  r|  r   r  rc  r|  s       rs   _print_PolynomialRingz"LatexPrinter._print_PolynomialRingX	  G    T[))))CT\::;;'-vvwww77ru   c                    |                      |j                  }d                    t          | j         |j                            }|d|dS )NrO  rF  rs  rb  rd  s       rs   _print_FractionFieldz!LatexPrinter._print_FractionField]	  rf  ru   c                    |                      |j                  }d                    t          | j         |j                            }d}|j        sd}||d|dS )NrO  r   zS_<^{-1}r  r  )r	  rc  rS  rH  r|  is_Poly)r   r  rc  r|  invs        rs   _print_PolynomialRingBasez&LatexPrinter._print_PolynomialRingBaseb	  s_    T[))))CT\::;;| 	C),fffggg>>ru   c           	        |j         j        }g }|                                D ]t\  }}d}t          |          D ]f\  }}|dk    r[|dk    r$||                     |j        |                   z  }5||                     t          |j        |         |                    z  }g|j        r1|rd|                     |          z  }	nz|                     |          }	nd|rM|t          j	        u r|
                    d|g           |t          j        u r|
                    d|g           |                     |          }	|s|	}
n|	dz   |z   }
|
                    d          r!|
                    d|
dd          g           ]|
                    d|
g           v|d         dv r)|                    d          }|dk    rd|d         z   |d<   d                    |          }t          t!          | j        |j                            }d	|                     |                                          z  }d
                    |g|z   |gz             }|t$          v r
d|d|d}n	d|d|d}|S )Nr   r   rp  rd  r  r3  r   )r3  r  z	domain=%srO  r    {\left(z	 \right)}r  z	}{\left( )rQ  rR  rg  rf  r	  genspowr$  r   r  extendr  r  poprS  r  rH  
get_domainr  )r   polyr  rg  monomr  s_monomr   rI  s_coeffs_termmodifierr  ro  rc  rB  r  s                    rs   _print_PolyzLatexPrinter._print_Polyj	  s   n% JJLL "	, "	,LE5G#E** G G377axx4;;ty|#<#<<4;;s49Q</E/E#F#FF| - 104;;u3E3EEGG"kk%00GG !~~c7^444 --c7^444 ++e,, 1  30  %% ,c6!"":.////c6]++++8z!!yy||H3q>axxCTY//00t{{4??+<+<===yy$$&122****/2ssDDD9CC + >ASS$$$GC
ru   c                    |j         j        }|dk    rd}|                     |j                  }|j        }|t
          v rd|||fz  S d|||fz  S )NComplexRootOfCRootOfz\%s {\left(%s, %d\right)}z'\operatorname{%s} {\left(%s, %d\right)})rQ  rR  r	  r  ra  r  )r   r;   r  r  ra  s        rs   _print_ComplexRootOfz!LatexPrinter._print_ComplexRootOf	  sq    n%/!!C{{49%%
***/3e2DDD=dAFAH H Hru   c                R   |j         j        }|                     |j                  g}|j        t
          j        ur-|                    |                     |j                             |t          v rd|dd	                    |          dS d|dd	                    |          dS )Nr   rn  rO  r.  r  z	} {\left()
rQ  rR  r	  r  funr   IdentityFunctionr<  r  rS  )r   r  r  rB  s       rs   _print_RootSumzLatexPrinter._print_RootSum	  s    n%DI&&'81---KKDH--...****/2ssDIIdOOOODD + >ASS=AYYt____N Nru   c                    dS )N\omegarp   r  s     rs   _print_OrdinalOmegaz LatexPrinter._print_OrdinalOmega	  s    yru   c                    |j         \  }}|dk    r1|dk    rd                    ||          S d                    |          S |dk    rd                    |          S dS )Nrp  z{} \omega^{{{}}}z	{} \omegaz\omega^{{{}}}r  )rB  r  )r   r  rI  muls       rs   _print_OmegaPowerzLatexPrinter._print_OmegaPower	  sk    9S!88axx*11#s;;;#**3///axx'..s333 yru   c                P     d                      fd|j        D                       S )Nrc  c                :    g | ]}                     |          S rp   rM  r  s     rs   rN  z/LatexPrinter._print_Ordinal.<locals>.<listcomp>	  s%    AAA4;;s++AAAru   )rS  rB  r  s   ` rs   _print_OrdinalzLatexPrinter._print_Ordinal	  s,    zzAAAAtyAAABBBru   c                V    | j         d         }|                    | t          d|          S )Nr   z	{%s}^{%d})r   r   r!   )r   rt  r   s      rs   _print_PolyElementzLatexPrinter._print_PolyElement	  s'    ^$67
xxj+zBBBru   c                    |j         dk    r|                     |j                  S |                     |j                  }|                     |j                   }d|d|dS )Nrp  r  r  ro   )r  r	  r  )r   r:   r  r  s       rs   _print_FracElementzLatexPrinter._print_FracElement	  s\    :??;;tz***KK
++EKK
++EE',uueee44ru   c                    t          |j                  dk    r|j        d         d fn|j        \  }}d|                     |          z  }||d|d}||d|                     |          d}|S )Nrp  r   zE_{%s}r  ro   rF  rs  r  )r   r  rI  r  r0  r  s         rs   _print_eulerzLatexPrinter._print_euler	  s    '*49~~':':	!d##	1$++a..(? #SSS)C=*-##t{{1~~~~>C
ru   c                `    d|                      |j        d                   z  }||d|d}|S )NzC_{%s}r   r  ro   r  r  s       rs   _print_catalanzLatexPrinter._print_catalan	  r  ru   c           
         d                     ||rdnd|                     |j        d                   |                     |j        d                   |                     |j        d                             S )Nz5\mathcal{{{}}}{}_{{{}}}\left[{}\right]\left({}\right)z^{-1}r   rp  r   r  r  r	  rB  )r   r  rr   inverses       rs   _print_UnifiedTransformz$LatexPrinter._print_UnifiedTransform	  s    GNNq]dRlRYRYjlnrnynyz~  {D  EF  {G  oH  oH  JN  JU  JU  VZ  V_  `a  Vb  Jc  Jc  ei  ep  ep  qu  qz  {|  q}  e~  e~      	ru   c                .    |                      |d          S )NMr  r  s     rs   _print_MellinTransformz#LatexPrinter._print_MellinTransform	      ++D#666ru   c                0    |                      |dd          S )Nr  Tr  r  s     rs   _print_InverseMellinTransformz*LatexPrinter._print_InverseMellinTransform	      ++D#t<<<ru   c                .    |                      |d          S )NLr  r  s     rs   _print_LaplaceTransformz$LatexPrinter._print_LaplaceTransform	  r  ru   c                0    |                      |dd          S )Nr  Tr  r  s     rs   _print_InverseLaplaceTransformz+LatexPrinter._print_InverseLaplaceTransform	  r  ru   c                .    |                      |d          S r  r  r  s     rs   _print_FourierTransformz$LatexPrinter._print_FourierTransform	  r  ru   c                0    |                      |dd          S )Nr  Tr  r  s     rs   _print_InverseFourierTransformz+LatexPrinter._print_InverseFourierTransform	  r  ru   c                .    |                      |d          S )NSINr  r  s     rs   _print_SineTransformz!LatexPrinter._print_SineTransform	      ++D%888ru   c                0    |                      |dd          S )Nr  Tr  r  s     rs   _print_InverseSineTransformz(LatexPrinter._print_InverseSineTransform
      ++D%>>>ru   c                .    |                      |d          S )NCOSr  r  s     rs   _print_CosineTransformz#LatexPrinter._print_CosineTransform
  r  ru   c                0    |                      |dd          S )Nr  Tr  r  s     rs   _print_InverseCosineTransformz*LatexPrinter._print_InverseCosineTransform
  r  ru   c                    	 |j         -|                     |j                             |                    S n# t          $ r Y nw xY w|                     t	          |                    S r  )ringr	  to_sympyr   reprr   r  s     rs   
_print_DMPzLatexPrinter._print_DMP
  sn    	v!{{16??1#5#5666 "  	 	 	D	{{477###s   37 
AAc                ,    |                      |          S r  )r  r  s     rs   
_print_DMFzLatexPrinter._print_DMF
  s    q!!!ru   c                P    |                      t          |j                            S r  r	  r   rT  )r   r  s     rs   _print_ObjectzLatexPrinter._print_Object
  s    {{6&+..///ru   c                   |                      |j        d                   }|d|dnd}t          |j                  dk    r
d|d|d}n7|                      |j        d                   }d	                    |||          }|S )
Nr   r  ro   r   rp  WrF  rs  zW{0}_{{{1}}}\left({2}\right))r	  rB  r  r  )r   r  rI  arg0resultarg1s         rs   _print_LambertWzLatexPrinter._print_LambertW
  s    {{49Q<((#&??###ty>>Q.1cc4448FF;;ty|,,D5<<S$MMFru   c                h    d                     |                     |j        d                             S )Nz!\operatorname{{E}}\left[{}\right]r   r  r  s     rs   _print_ExpectationzLatexPrinter._print_Expectation$
  )    3::4;;tyQR|;T;TUUUru   c                h    d                     |                     |j        d                             S )Nz#\operatorname{{Var}}\left({}\right)r   r  r  s     rs   _print_VariancezLatexPrinter._print_Variance'
  s)    5<<T[[ST=V=VWWWru   c                v     d                     d                     fd|j        D                                 S )Nz#\operatorname{{Cov}}\left({}\right)rO  c              3  B   K   | ]}                     |          V  d S r  rM  r  s     rs   r1  z1LatexPrinter._print_Covariance.<locals>.<genexpr>+
  s1      FmFm\_t{{SVGWGWFmFmFmFmFmFmru   )r  rS  rB  r  s   ` rs   _print_CovariancezLatexPrinter._print_Covariance*
  s<    5<<TYYFmFmFmFmcgclFmFmFm=m=mnnnru   c                h    d                     |                     |j        d                             S )Nz!\operatorname{{P}}\left({}\right)r   r  r  s     rs   _print_ProbabilityzLatexPrinter._print_Probability-
  r  ru   c                x    |                      |j                  }|                      |j                  }|d|S )Nr  )r	  rc  codomain)r   morphismrc  r  s       rs   _print_MorphismzLatexPrinter._print_Morphism0
  s:    X_--;;x011&,ffhh77ru   c                |    |                      |j                  |                      |j                  }}d|d|dS )Nr  r  ro   )r	  r]  den)r   r  r]  r  s       rs   _print_TransferFunctionz$LatexPrinter._print_TransferFunction5
  s<    ;;tx(($++dh*?*?S#&33,,ru   c                     t          j                  } fd}d                    t          ||                    S )Nc                L                         | t                    d          S r   )r  r   )r0  r  r   s    rs   rt   z,LatexPrinter._print_Series.<locals>.<lambda>;
  s'    4,,Q0Ft0L0L,13 3 ru   r   )r  rB  rS  rH  )r   r  rB  r"  s   ``  rs   _print_SerieszLatexPrinter._print_Series9
  sH    DI3 3 3 3 3xxFD))***ru   c                     ddl m t          j                  d d d         } fd}d                    t          ||                    S )Nr   )MIMOParallelro  c                    t          |           r$                    | t                    d          n                    |           S r   )r  r  r   r	  )r0  r  r  r   s    rs   rt   z0LatexPrinter._print_MIMOSeries.<locals>.<lambda>B
  sT    7A!\7R7Rg4,,Q0Ft0L0L-24 4 4X\XcXcdeXfXf ru   z\cdot)sympy.physics.control.ltir  r  rB  rS  rH  )r   r  rB  r"  r  s   ``  @rs   _print_MIMOSerieszLatexPrinter._print_MIMOSeries?
  sq    ::::::DIttt$g g g g g g}}S..///ru   c                \    d                     t          | j        |j                            S Nrc  rS  rH  r	  rB  r  s     rs   _print_ParallelzLatexPrinter._print_ParallelF
  "    zz#dk4955666ru   c                \    d                     t          | j        |j                            S r  r  r  s     rs   _print_MIMOParallelz LatexPrinter._print_MIMOParallelI
  r  ru   c           	     p   ddl m}m} |j         |dd|j                  }}t          ||          rt          |j                  n|g}t          |j        |          rt          |j        j                  n|j        g}|}t          ||          r t          |j        |          r |g ||R  }	nt          ||          r8t          |j        |          r#|j        |k    r || }	nt| |g ||j        R  f}	nbt          ||          r+t          |j        |          r||k    r || }	n1 ||g|R  }	n'||k    r || }	n|j        |k    r || }	n
 |g ||R  }	| 	                    |          }
| 	                    |          }| 	                    |	          }|j
        dk    rdnd}d|
d|d	|d	|d
	S )Nr   )TransferFunctionSeriesrp  ro  r  r3  r  r  r   ro   )sympy.physics.controlr  r  sys1r  r  r  rB  sys2r	  r  )r   r  r  r  r]  tfnum_arg_listden_arg_list
den_term_1
den_term_2r  denom_1denom_2_signs                 rs   _print_FeedbackzLatexPrinter._print_FeedbackL
  s?   BBBBBBBB)--aDH==R)3C)@)@KtCH~~~sety&));tDIN+++04	{ 	
c6"" 	Bz$)V'D'D 	B=====JJV$$ 	BDI?O)P)P 	ByB#V\2

!A!Aty!A!A!AA

-.. 	B:di3P3P 	Bbyy#V\2

#VC7,777

byy#V\2

b#V\2

#VA\ALAAA
C  ++j))++j))yBC).HHru   c                    ddl m} |                      ||j        |j                            }|                     |j                  }|j        dk    rdnd}d|d|d|S )	Nr   )
MIMOSeriesro  r  r3  z\left(I_{\tau} r   z\right)^{-1} \cdot )r  r  r	  r  r  r  )r   r  r  inv_matr  r  s         rs   _print_MIMOFeedbackz LatexPrinter._print_MIMOFeedbackp
  st    444444++jjDI>>??{{49%%yBC?DuugggttTTru   c                @    |                      |j                  }d|z  S )Nz%s_\tau)r	  	_expr_matr  s      rs   _print_TransferFunctionMatrixz*LatexPrinter._print_TransferFunctionMatrixw
  s     kk$.))Cru   c                L    d                     |j        j        |j                  S )Nz\text{{{}}}_{{{}}})r  rQ  rR  r0  r  s     rs   
_print_DFTzLatexPrinter._print_DFT{
  s    $++DN,CTVLLLru   c                    |                      t          |j                            }|                     |          }|d|S )Nr  )r	  r   rT  r  )r   r  pretty_namepretty_morphisms       rs   _print_NamedMorphismz!LatexPrinter._print_NamedMorphism
  sA    kk&"7"788..x88%++77ru   c                b    ddl m} |                      ||j        |j        d                    S )Nr   )NamedMorphismid)sympy.categoriesr  r  rc  r  )r   r  r  s      rs   _print_IdentityMorphismz$LatexPrinter._print_IdentityMorphism
  sF    222222((OX.*6 *6 7 7 	7ru   c                      fd|j         D             }|                                 d                    |          dz   }                     |          }||z   S )Nc                ^    g | ])}                     t          |j                            *S rp   r  )r/  	componentr   s     rs   rN  z9LatexPrinter._print_CompositeMorphism.<locals>.<listcomp>
  sE      B  B  B ) !%F9>,B,B C C  B  B  Bru   z\circ r  )r:  reverserS  r  )r   r  component_names_listcomponent_namesr   s   `    rs   _print_CompositeMorphismz%LatexPrinter._print_CompositeMorphism
  s}     B  B  B  B-5-@ B  B  B$$&&&#..)=>>D..x8800ru   c                v    d                     |                     t          |j                                      S Nr  )r  r	  r   rT  )r   r  s     rs   _print_CategoryzLatexPrinter._print_Category
  s,    &&t{{6(-3H3H'I'IJJJru   c                    |j         s|                     t          j                  S |                     |j                   }|j        r |d|                     |j                  z  z  }|S )Nz\Longrightarrow %s)premisesr	  r   EmptySetconclusions)r   diagramlatex_results      rs   _print_DiagramzLatexPrinter._print_Diagram
  sl     	+;;qz***{{7#344 	=1 KK(;<<= =L ru   c                .   dd|j         z  z  }t          |j                  D ]m}t          |j                   D ]>}|||f         r|t          |||f                   z  }|dz  }||j         dz
  k    r|dz  }?||j        dz
  k    r|dz  }|dz  }n|dz  }|S )	Nz\begin{array}{%s}
r   r   rp  & r  
z\end{array}
)widthr  heightlatex)r   gridr  r   r   s        rs   _print_DiagramGridzLatexPrinter._print_DiagramGrid
  s    -tz1ABt{## 
	! 
	!A4:&& ) )1: 6 E$q!t*$5$55L#
Q&& D(LDK!O##&D LL((ru   c                    d                     |                     |j                  |                     |j                            S )Nz{{{}}}^{{{}}})r  r	  r  rP  r   r  s     rs   _print_FreeModulezLatexPrinter._print_FreeModule
  s4    %%dkk!&&9&94;;qv;N;NOOOru   c                l     d                     d                     fd|D                                 S )N\left[ {} \right]rq  c              3  N   K   | ]}d                      |          z   dz   V   dS r   ro   NrM  r/  r0  r   s     rs   r1  z8LatexPrinter._print_FreeModuleElement.<locals>.<genexpr>
  sH       43 43+,C$++a.. 3&43 43 43 43 43 43ru   )r  rS  )r   r  s   ` rs   _print_FreeModuleElementz%LatexPrinter._print_FreeModuleElement
  sQ    #**388 43 43 43 430143 43 43 ,3 ,3 4 4 	4ru   c                      fdj         D             }d d d                    fd|D                       }d                    |          S )Nc                .    g | ]}fd |D             S )c                j    g | ]/}                     j                            |                    0S rp   )r	  r  r  )r/  r0  r  r   s     rs   rN  z<LatexPrinter._print_SubModule.<locals>.<listcomp>.<listcomp>
  s3    <<<QQV__Q//00<<<ru   rp   )r/  gr  r   s     rs   rN  z1LatexPrinter._print_SubModule.<locals>.<listcomp>
  s1    MMM<<<<<!<<<MMMru   c                    d| z   dz   S )Nr   ro   rp   rM   s    rs   rt   z/LatexPrinter._print_SubModule.<locals>.<lambda>
  s    $(T/ ru   c                    d| z   dz   S )Nz\left[ z \right]rp   r.  s    rs   rt   z/LatexPrinter._print_SubModule.<locals>.<lambda>
  s    :>K7 ru   rq  c           	   3  ~   K   | ]7}  d                      fd|D                                           V  8dS )rq  c              3  .   K   | ]} |          V  d S r  rp   )r/  r0  curlys     rs   r1  z:LatexPrinter._print_SubModule.<locals>.<genexpr>.<genexpr>
  s+      3H3HEE!HH3H3H3H3H3H3Hru   N)rS  )r/  r,  r2  squares     rs   r1  z0LatexPrinter._print_SubModule.<locals>.<genexpr>
  sX      YYqeeFF3883H3H3H3Ha3H3H3H+H+H$I$IJJYYYYYYru   \left\langle {} \right\rangle)ro  rS  r  )r   r  ro  
gens_latexr2  r3  s   ``  @@rs   _print_SubModulezLatexPrinter._print_SubModule
  sr    MMMMMafMMM))77XXYYYYYTXYYYYY
/66zBBBru   c                z     d                      fd|j        D                       }d                    |          S )Nrq  c                F    g | ]}d                      |          z   dz   S )r   ro   rM  )r/  r,  r   s     rs   rN  z9LatexPrinter._print_SubQuotientModule.<locals>.<listcomp>
  s-    JJJasT[[^^3c9JJJru   r4  )rS  ro  r  )r   r  r5  s   `  rs   _print_SubQuotientModulez%LatexPrinter._print_SubQuotientModule
  s?    XXJJJJ16JJJKK
/66zBBBru   c                     fdj         j        D             }d                     fd|D                       }d                    |          S )Nc                H    g | ]\  }j                             |          S rp   )r  r  r/  r0  r  s     rs   rN  z>LatexPrinter._print_ModuleImplementedIdeal.<locals>.<listcomp>
  s)    ===s""===ru   rq  c              3  N   K   | ]}d                      |          z   dz   V   dS r&  rM  r'  s     rs   r1  z=LatexPrinter._print_ModuleImplementedIdeal.<locals>.<genexpr>
  s7      GGQcDKKNN2S8GGGGGGru   r4  )_modulero  rS  r  )r   r  ro  r5  s   ``  rs   _print_ModuleImplementedIdealz*LatexPrinter._print_ModuleImplementedIdeal
  s[    ====ain===XXGGGG$GGGGG
/66zBBBru   c                      fd|j         D             }|d         gd t          |dd          d          D             z   }d                    |          S )Nc                V    g | ]%}                     |t          d          d          &S )r
   Tr  )r  r!   r  s     rs   rN  z2LatexPrinter._print_Quaternion.<locals>.<listcomp>
  sC     ! ! ! q*U"3DAA ! ! !ru   r   c                $    g | ]\  }}|d z   |z   S )r   rp   )r/  r   r   s      rs   rN  z2LatexPrinter._print_Quaternion.<locals>.<listcomp>
  s$    <<<$!QaeAg<<<ru   rp  ijkrc  )rB  rf  rS  )r   r  rr   r  s   `   rs   _print_QuaternionzLatexPrinter._print_Quaternion
  sn    ! ! ! !i! ! !qTF<<#aeU*;*;<<<<zz!}}ru   c                    d                     |                     |j                  |                     |j                            S Nz\frac{{{}}}{{{}}})r  r	  r  
base_ideal)r   Rs     rs   _print_QuotientRingz LatexPrinter._print_QuotientRing
  s;    #**4;;qv+>+>Q\**, , 	,ru   c                    |                      |j                            |                    }d                    ||                      |j        j                            S )N{{{}}} + {{{}}})r	  r  r  r  rG  )r   r0  x_latexs      rs   _print_QuotientRingElementz'LatexPrinter._print_QuotientRingElement
  sO    ++afooa0011!((QV.//1 1 	1ru   c                     fdj         D             }d                    d                     fd|D                                 }d                    |                     j        j                            S )Nc                N    g | ]!}j         j                            |          "S rp   )moduler  r  r<  s     rs   rN  z=LatexPrinter._print_QuotientModuleElement.<locals>.<listcomp>
  s+    :::a&&q)):::ru   r$  rq  c              3  N   K   | ]}d                      |          z   dz   V   dS r&  rM  r'  s     rs   r1  z<LatexPrinter._print_QuotientModuleElement.<locals>.<genexpr>
  sH       :6 :6+,C$++a.. 3&:6 :6 :6 :6 :6 :6ru   rK  )datar  rS  r	  rP  killed_module)r   r  rR  
data_latexs   ``  rs   _print_QuotientModuleElementz)LatexPrinter._print_QuotientModuleElement
  s    ::::16:::)00 :6 :6 :6 :604:6 :6 :6 26 26 7 7
!((QX3446 6 	6ru   c                    d                     |                     |j                  |                     |j                            S rF  )r  r	  rD  rS  r!  s     rs   _print_QuotientModulez"LatexPrinter._print_QuotientModule
  s;    #**4;;qv+>+>Q_--/ / 	/ru   c                    d                     |                     |                                          |                     |j                  |                     |j                            S )Nz{{{}}} : {{{}}} \to {{{}}})r  r	  _sympy_matrixrc  r  )r   r  s     rs   _print_MatrixHomomorphismz&LatexPrinter._print_MatrixHomomorphism
  sS    ,33DKK@Q@Q4R4RKK!!4;;qz#:#:< < 	<ru   c                &   |j         j         }d|v r|g g }}}n:t          |          \  }}}t          |          }d |D             }d |D             }d|z  }|r|dd                    |          z  z  }|r|dd                    |          z  z  }|S )Nr   c                ,    g | ]}t          |          S rp   r  r  s     rs   rN  z0LatexPrinter._print_Manifold.<locals>.<listcomp>
  r  ru   c                ,    g | ]}t          |          S rp   r  r  s     rs   rN  z0LatexPrinter._print_Manifold.<locals>.<listcomp>
  r  ru   r[  rx  r   rG  )rT  r   r  rS  )r   manifoldr  rT  r  rg  s         rs   _print_ManifoldzLatexPrinter._print_Manifold
  s    #&==!'R$&DD!0!8!8D&$T??D77777F33d333Dd" 	/Gchhv....D 	-Gchhtnn,,Dru   c                t    d|                      |j                  d|                      |j                  dS )N\text{r  ro   )r	  rT  r^  )r   patchs     rs   _print_PatchzLatexPrinter._print_Patch  s7     $(KK
$;$;$;$;T[[=X=X=X=XYYru   c                    d|                      |j                  d|                      |j        j                  d|                      |j                  dS )Nra  z	}^{\text{z}}_{ro   )r	  rT  rb  r^  )r   coordsyss     rs   _print_CoordSystemzLatexPrinter._print_CoordSystem  sV     KK&&&&HN4G(H(H(H(H$++V^VgJhJhJhJh
 	
ru   c                <    d|                      |j                  z  S )Nz\mathbb{\nabla}_{%s})r	  _wrt)r   cvds     rs   _print_CovarDerivativeOpz%LatexPrinter._print_CovarDerivativeOp
  s    &SX)>)>>>ru   c                    |j         j        |j                 j        }d                    |                     t          |                              S r  
_coord_sysr|  _indexrT  r  r	  r   r   fieldr  s      rs   _print_BaseScalarFieldz#LatexPrinter._print_BaseScalarField  s=    !)%,7<&&t{{6&>>'B'BCCCru   c                    |j         j        |j                 j        }d                    |                     t          |                              S )Nz\partial_{{{}}}rl  ro  s      rs   _print_BaseVectorFieldz#LatexPrinter._print_BaseVectorField  s=    !)%,7<!((VF^^)D)DEEEru   c                &   |j         }t          |d          rQ|j        j        |j                 j        }d                    |                     t          |                              S |                     |          }d                    |          S )Nrm  z\operatorname{{d}}{}z!\operatorname{{d}}\left({}\right))	_form_fieldr  rm  r|  rn  rT  r  r	  r   )r   diffrp  r  s       rs   _print_Differentialz LatexPrinter._print_Differential  s}     5,'' 	G%-el;@F*11$++fVnn2M2MNNN[[''F7>>vFFFru   c                l    |                      |j        d                   }d                    |          S )Nr   z"\operatorname{{tr}}\left({}\right)rE  )r   r  contentss      rs   	_print_TrzLatexPrinter._print_Tr  s-    ;;qvay))4;;HEEEru   c                    |'d|                      |j        d                   d|dS d|                      |j        d                   z  S )Nz\left(\phi\left(r   \right)\right)^{ro   z\phi\left(%s\right)r  rH  s      rs   _print_totientzLatexPrinter._print_totient#  sQ    ??TYq\****CCC1 1%DIaL(A(AAAru   c                    |'d|                      |j        d                   d|dS d|                      |j        d                   z  S )Nz\left(\lambda\left(r   r|  ro   z\lambda\left(%s\right)r  rH  s      rs   _print_reduced_totientz#LatexPrinter._print_reduced_totient)  sQ    ??TYq\****CCC1 1(4;;ty|+D+DDDru   c           	        t          |j                  dk    r>dt          t          | j        |j        d         |j        d         f                    z  }n#d|                     |j        d                   z  }|d|d|S d|z  S )	Nr  _%s\left(%s\right)rp  r   rd  z\sigma^{ro   z\sigma%sr|  r  s       rs   _print_divisor_sigmaz!LatexPrinter._print_divisor_sigma/  s    ty>>Q'%DK151ty|0L1N 1N +O +O OCC %t{{49Q<'@'@@C??'*ssCC00S  ru   c           	        t          |j                  dk    r>dt          t          | j        |j        d         |j        d         f                    z  }n#d|                     |j        d                   z  }|d|d|S d|z  S )	Nr  r  rp  r   rd  z
\sigma^*^{ro   z
\sigma^*%sr|  r  s       rs   _print_udivisor_sigmaz"LatexPrinter._print_udivisor_sigma9  s    ty>>Q'%DK151ty|0L1N 1N +O +O OCC %t{{49Q<'@'@@C??),cc22s""ru   c                    |'d|                      |j        d                   d|dS d|                      |j        d                   z  S )Nz\left(\nu\left(r   r|  ro   z\nu\left(%s\right)r  rH  s      rs   _print_primenuzLatexPrinter._print_primenuC  sQ    ??TYq\****CCC1 1$t{{49Q<'@'@@@ru   c                    |'d|                      |j        d                   d|dS d|                      |j        d                   z  S )Nz\left(\Omega\left(r   r|  ro   z\Omega\left(%s\right)r  rH  s      rs   _print_primeomegazLatexPrinter._print_primeomegaI  sQ    ??TYq\****CCC1 1'$++dil*C*CCCru   c                *    t          |j                  S r  )r   rT  r  s     rs   
_print_StrzLatexPrinter._print_StrO  s    16{{ru   c                F    |                      t          |                    S r  )r	  r   r  s     rs   _print_floatzLatexPrinter._print_floatR  s    {{5;;'''ru   c                     t          |          S r  r   r  s     rs   
_print_intzLatexPrinter._print_intU      4yyru   c                     t          |          S r  r  r  s     rs   
_print_mpzzLatexPrinter._print_mpzX  r  ru   c                     t          |          S r  r  r  s     rs   
_print_mpqzLatexPrinter._print_mpq[  r  ru   c                     t          |          S r  r  r  s     rs   _print_fmpzzLatexPrinter._print_fmpz^  r  ru   c                     t          |          S r  r  r  s     rs   _print_fmpqzLatexPrinter._print_fmpqa  r  ru   c                j    d                     t          t          |j                                      S )Nz"\operatorname{{Q}}_{{\text{{{}}}}})r  r   r   rT  r  s     rs   _print_PredicatezLatexPrinter._print_Predicated  s&    4;;LTY<X<XYYYru   c                     |j         }|j        }                     |          }d                     fd|D                       }|d|dS )NrO  c                :    g | ]}                     |          S rp   rM  r  s     rs   rN  z8LatexPrinter._print_AppliedPredicate.<locals>.<listcomp>k  s#    ===1A===ru   r   r   )r#  	argumentsr	  rS  )r   r  predrB  
pred_latex
args_latexs   `     rs   _print_AppliedPredicatez$LatexPrinter._print_AppliedPredicateg  s[    }~[[&&
YY=======>>
%::zzz22ru   c                j    t                                          |          }dt          |          z  S )Nz\mathtt{\text{%s}})superemptyPrinterr   )r   r  rr   rQ  s      rs   r  zLatexPrinter.emptyPrintern  s+    GG  &&$|A66ru   r  r  )FF)r   r  )r  r   )rW  rX  )r  r   )r  r   )r  r   r   r   )r  r,  )r  r   r   r   )r  r   r   r   r  )r5  r   r   r   r  )FN)r   )r  r   )r  r   r   r   )r  r&   )r[  r\  )F(A  rR  
__module____qualname__printmethodr   __annotations__r   r  r  r  r   r  r  r&  r=  r@  r!  r#  rJ  rV  r]  _print_BooleanTrue_print_BooleanFalser`  rj  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r%  r+  rE  rK  rN  rR  r^  rm  r}  r  r  r  r  r  propertyr  r  r  r  r  
_print_Min
_print_Maxr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  _print_gammar  r  r  r!  r%  r'  r)  r+  r1  r4  r:  r<  r@  rC  rF  rI  rK  rM  rO  rR  rT  rV  rZ  r\  ra  rf  ri  rl  rr  rx  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  _print_RandomSymbolrP  r  r  r  r  r  r
  r  r  r  r  r#  r&  r(  r1  r3  r7  r:  r<  rA  rF  rH  rL  rZ  rc  rf  rh  rl  rn  rp  rs  ru  rx  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  _print_frozensetr  r  r  r  r  r  r  r  r  r  _print_SeqPer_print_SeqAdd_print_SeqMulr  r  r  r  r  r  r  r  r  r!  r$  r'  r*  r-  r9  rC  rG  rJ  rM  rR  rU  rX  rZ  r\  r^  r`  re  rh  rl  rz  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  _print_IDFTr  r  r  r  r  r  r"  r(  r6  r9  r?  rD  rI  rM  rU  rW  rZ  r_  rc  rf  rj  rq  rs  rw  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  __classcell__)rQ  s   @rs   r   r      s        K)U)E) 	e) 	4	)
 	-) 	) 	u) 	4) 	S) 	4) 	) 	d) 	) 	) 	)  	G!)" 	##)$ %"!3) ) )    8;f ;f ;f ;fz, , , ,- - - -% % % % %  E E E EK K K K   .    >      3 3 3 3   / / /        %%        &   9 9 9BJ J J  <N N NN N NM M MM M MI I II I Iq q q qf/ / /- - -+< +< +< +<Z& & & &") ) )  &  &   <  ' ' '  @ @ @BE E E"/ "/ "/H4 4 4   @J) J) J) J) J)X0 0 0
 
 
 , , X,0 0 0
 
 
- - -     87J      	 	 	 	   + + + ++ + + +	7 	7 	7  2 2 20 0 03 3 3D D D DF F F F   ) ) ) )+ + + +                 	  	  	  	 " " " "	/ 	/ 	/ 	/[ [ [ [< < < <% % % %% % % %; ; ; ; ; (L1 1 1 1: : : :                          + + + ++ + + +   "   7 7 7 77 7 7 77 7 7 77 7 7 77 7 7 77 7 7 7= = = == = = == = = == = = =- - - - -4 4 4 4 42 2 2 22 2 2 28 8 8 88 8 8 8	 	 	 	             ! ! ! !+ + + +@ @ @ @                                 Q Q Q QG G G GG G G GS S S SS S S S' ' '' ' ' A A A A A (    ,J J J(* * *+ + +,  5 5 5
J J J( ( ($ $ $G G G7 7 7&/ / /"G G GA A A A> > >A A A> > >@ @ @! ! !> > >> > >> > ># # #5 5 5 5n   8? ? ?
F F F
 
 
  
 
 
  & & &D D D
  4 4 4 4F F F+ + +* * *' ' ': : :< < <& & &         	 	 	 	   	% 	% 	%& & &, , , "( ( (T   > > > >> > > >> > > >> > > >   > > > >M M M M
  . &M%M%MK K K$9 9 9( ( (
- - -
( ( (
- - -
< < <              Q Q Q
& 
& 
&A A A! ! !D D D< < <
+ + +- - -        8 8 8
8 8 8
? ? ?7 7 7r
H 
H 
HN N N  ! ! !C C CC C C5 5 5         7 7 7= = =7 7 7= = =7 7 7= = =9 9 9? ? ?9 9 9? ? ?$ $ $" " "0 0 0   V V VX X Xo o oV V V8 8 8
- - -+ + +0 0 07 7 77 7 7"I "I "IHU U U     M M MK8 8 8
7 7 7
	1 	1 	1K K K
 
 
  $P P P4 4 4
C C CC C CC C C
  , , ,
1 1 1
6 6 6/ / /
< < <  &Z Z Z
 
 

? ? ?D D DF F FG G GF F F
B B B BE E E E! ! ! !# # # #A A A AD D D D  ( ( (          Z Z Z3 3 37 7 7 7 7 7 7 7 7ru   r   c           
     &   t                               |           }|r|S |                                 t          v rd|                                 z   S | t          v rd| z   S t          t                                          t          d          D ]}|                                 	                    |          rZt          |           t          |          k    r:t          |         t          | dt          |                                        c S | S )a  
    Check for a modifier ending the string.  If present, convert the
    modifier to latex and translate the rest recursively.

    Given a description of a Greek letter or other special character,
    return the appropriate latex.

    Let everything else pass as given.

    >>> from sympy.printing.latex import translate
    >>> translate('alphahatdotprime')
    "{\\dot{\\hat{\\alpha}}}'"
    r   T)r2  r
  N)tex_greek_dictionaryr   r  greek_letters_setother_symbolsr  r   r  r  r	  r  )rr   r  r2  s      rs   r  r  u  s     
"
"1
%
%C
 
	
'	'	'aggii	
m		ax -,,..CFFF 	D 	DCwwyy!!#&& D3q66CHH+<+<$S))AjCyjM*B*BCCCCCru   c                F    t          |                              |           S )a%  Convert the given expression to LaTeX string representation.

    Parameters
    ==========
    full_prec: boolean, optional
        If set to True, a floating point number is printed with full precision.
    fold_frac_powers : boolean, optional
        Emit ``^{p/q}`` instead of ``^{\frac{p}{q}}`` for fractional powers.
    fold_func_brackets : boolean, optional
        Fold function brackets where applicable.
    fold_short_frac : boolean, optional
        Emit ``p / q`` instead of ``\frac{p}{q}`` when the denominator is
        simple enough (at most two terms and no powers). The default value is
        ``True`` for inline mode, ``False`` otherwise.
    inv_trig_style : string, optional
        How inverse trig functions should be displayed. Can be one of
        ``'abbreviated'``, ``'full'``, or ``'power'``. Defaults to
        ``'abbreviated'``.
    itex : boolean, optional
        Specifies if itex-specific syntax is used, including emitting
        ``$$...$$``.
    ln_notation : boolean, optional
        If set to ``True``, ``\ln`` is used instead of default ``\log``.
    long_frac_ratio : float or None, optional
        The allowed ratio of the width of the numerator to the width of the
        denominator before the printer breaks off long fractions. If ``None``
        (the default value), long fractions are not broken up.
    mat_delim : string, optional
        The delimiter to wrap around matrices. Can be one of ``'['``, ``'('``,
        or the empty string ``''``. Defaults to ``'['``.
    mat_str : string, optional
        Which matrix environment string to emit. ``'smallmatrix'``,
        ``'matrix'``, ``'array'``, etc. Defaults to ``'smallmatrix'`` for
        inline mode, ``'matrix'`` for matrices of no more than 10 columns, and
        ``'array'`` otherwise.
    mode: string, optional
        Specifies how the generated code will be delimited. ``mode`` can be one
        of ``'plain'``, ``'inline'``, ``'equation'`` or ``'equation*'``.  If
        ``mode`` is set to ``'plain'``, then the resulting code will not be
        delimited at all (this is the default). If ``mode`` is set to
        ``'inline'`` then inline LaTeX ``$...$`` will be used. If ``mode`` is
        set to ``'equation'`` or ``'equation*'``, the resulting code will be
        enclosed in the ``equation`` or ``equation*`` environment (remember to
        import ``amsmath`` for ``equation*``), unless the ``itex`` option is
        set. In the latter case, the ``$$...$$`` syntax is used.
    mul_symbol : string or None, optional
        The symbol to use for multiplication. Can be one of ``None``,
        ``'ldot'``, ``'dot'``, or ``'times'``.
    order: string, optional
        Any of the supported monomial orderings (currently ``'lex'``,
        ``'grlex'``, or ``'grevlex'``), ``'old'``, and ``'none'``. This
        parameter does nothing for `~.Mul` objects. Setting order to ``'old'``
        uses the compatibility ordering for ``~.Add`` defined in Printer. For
        very large expressions, set the ``order`` keyword to ``'none'`` if
        speed is a concern.
    symbol_names : dictionary of strings mapped to symbols, optional
        Dictionary of symbols and the custom strings they should be emitted as.
    root_notation : boolean, optional
        If set to ``False``, exponents of the form 1/n are printed in fractonal
        form. Default is ``True``, to print exponent in root form.
    mat_symbol_style : string, optional
        Can be either ``'plain'`` (default) or ``'bold'``. If set to
        ``'bold'``, a `~.MatrixSymbol` A will be printed as ``\mathbf{A}``,
        otherwise as ``A``.
    imaginary_unit : string, optional
        String to use for the imaginary unit. Defined options are ``'i'``
        (default) and ``'j'``. Adding ``r`` or ``t`` in front gives ``\mathrm``
        or ``\text``, so ``'ri'`` leads to ``\mathrm{i}`` which gives
        `\mathrm{i}`.
    gothic_re_im : boolean, optional
        If set to ``True``, `\Re` and `\Im` is used for ``re`` and ``im``, respectively.
        The default is ``False`` leading to `\operatorname{re}` and `\operatorname{im}`.
    decimal_separator : string, optional
        Specifies what separator to use to separate the whole and fractional parts of a
        floating point number as in `2.5` for the default, ``period`` or `2{,}5`
        when ``comma`` is specified. Lists, sets, and tuple are printed with semicolon
        separating the elements when ``comma`` is chosen. For example, [1; 2; 3] when
        ``comma`` is chosen and [1,2,3] for when ``period`` is chosen.
    parenthesize_super : boolean, optional
        If set to ``False``, superscripted expressions will not be parenthesized when
        powered. Default is ``True``, which parenthesizes the expression when powered.
    min: Integer or None, optional
        Sets the lower bound for the exponent to print floating point numbers in
        fixed-point format.
    max: Integer or None, optional
        Sets the upper bound for the exponent to print floating point numbers in
        fixed-point format.
    diff_operator: string, optional
        String to use for differential operator. Default is ``'d'``, to print in italic
        form. ``'rd'``, ``'td'`` are shortcuts for ``\mathrm{d}`` and ``\text{d}``.
    adjoint_style: string, optional
        String to use for the adjoint symbol. Defined options are ``'dagger'``
        (default),``'star'``, and ``'hermitian'``.

    Notes
    =====

    Not using a print statement for printing, results in double backslashes for
    latex commands since that's the way Python escapes backslashes in strings.

    >>> from sympy import latex, Rational
    >>> from sympy.abc import tau
    >>> latex((2*tau)**Rational(7,2))
    '8 \\sqrt{2} \\tau^{\\frac{7}{2}}'
    >>> print(latex((2*tau)**Rational(7,2)))
    8 \sqrt{2} \tau^{\frac{7}{2}}

    Examples
    ========

    >>> from sympy import latex, pi, sin, asin, Integral, Matrix, Rational, log
    >>> from sympy.abc import x, y, mu, r, tau

    Basic usage:

    >>> print(latex((2*tau)**Rational(7,2)))
    8 \sqrt{2} \tau^{\frac{7}{2}}

    ``mode`` and ``itex`` options:

    >>> print(latex((2*mu)**Rational(7,2), mode='plain'))
    8 \sqrt{2} \mu^{\frac{7}{2}}
    >>> print(latex((2*tau)**Rational(7,2), mode='inline'))
    $8 \sqrt{2} \tau^{7 / 2}$
    >>> print(latex((2*mu)**Rational(7,2), mode='equation*'))
    \begin{equation*}8 \sqrt{2} \mu^{\frac{7}{2}}\end{equation*}
    >>> print(latex((2*mu)**Rational(7,2), mode='equation'))
    \begin{equation}8 \sqrt{2} \mu^{\frac{7}{2}}\end{equation}
    >>> print(latex((2*mu)**Rational(7,2), mode='equation', itex=True))
    $$8 \sqrt{2} \mu^{\frac{7}{2}}$$
    >>> print(latex((2*mu)**Rational(7,2), mode='plain'))
    8 \sqrt{2} \mu^{\frac{7}{2}}
    >>> print(latex((2*tau)**Rational(7,2), mode='inline'))
    $8 \sqrt{2} \tau^{7 / 2}$
    >>> print(latex((2*mu)**Rational(7,2), mode='equation*'))
    \begin{equation*}8 \sqrt{2} \mu^{\frac{7}{2}}\end{equation*}
    >>> print(latex((2*mu)**Rational(7,2), mode='equation'))
    \begin{equation}8 \sqrt{2} \mu^{\frac{7}{2}}\end{equation}
    >>> print(latex((2*mu)**Rational(7,2), mode='equation', itex=True))
    $$8 \sqrt{2} \mu^{\frac{7}{2}}$$

    Fraction options:

    >>> print(latex((2*tau)**Rational(7,2), fold_frac_powers=True))
    8 \sqrt{2} \tau^{7/2}
    >>> print(latex((2*tau)**sin(Rational(7,2))))
    \left(2 \tau\right)^{\sin{\left(\frac{7}{2} \right)}}
    >>> print(latex((2*tau)**sin(Rational(7,2)), fold_func_brackets=True))
    \left(2 \tau\right)^{\sin {\frac{7}{2}}}
    >>> print(latex(3*x**2/y))
    \frac{3 x^{2}}{y}
    >>> print(latex(3*x**2/y, fold_short_frac=True))
    3 x^{2} / y
    >>> print(latex(Integral(r, r)/2/pi, long_frac_ratio=2))
    \frac{\int r\, dr}{2 \pi}
    >>> print(latex(Integral(r, r)/2/pi, long_frac_ratio=0))
    \frac{1}{2 \pi} \int r\, dr

    Multiplication options:

    >>> print(latex((2*tau)**sin(Rational(7,2)), mul_symbol="times"))
    \left(2 \times \tau\right)^{\sin{\left(\frac{7}{2} \right)}}

    Trig options:

    >>> print(latex(asin(Rational(7,2))))
    \operatorname{asin}{\left(\frac{7}{2} \right)}
    >>> print(latex(asin(Rational(7,2)), inv_trig_style="full"))
    \arcsin{\left(\frac{7}{2} \right)}
    >>> print(latex(asin(Rational(7,2)), inv_trig_style="power"))
    \sin^{-1}{\left(\frac{7}{2} \right)}

    Matrix options:

    >>> print(latex(Matrix(2, 1, [x, y])))
    \left[\begin{matrix}x\\y\end{matrix}\right]
    >>> print(latex(Matrix(2, 1, [x, y]), mat_str = "array"))
    \left[\begin{array}{c}x\\y\end{array}\right]
    >>> print(latex(Matrix(2, 1, [x, y]), mat_delim="("))
    \left(\begin{matrix}x\\y\end{matrix}\right)

    Custom printing of symbols:

    >>> print(latex(x**2, symbol_names={x: 'x_i'}))
    x_i^{2}

    Logarithms:

    >>> print(latex(log(10)))
    \log{\left(10 \right)}
    >>> print(latex(log(10), ln_notation=True))
    \ln{\left(10 \right)}

    ``latex()`` also supports the builtin container types :class:`list`,
    :class:`tuple`, and :class:`dict`:

    >>> print(latex([2/x, y], mode='inline'))
    $\left[ 2 / x, \  y\right]$

    Unsupported types are rendered as monospaced plaintext:

    >>> print(latex(int))
    \mathtt{\text{<class 'int'>}}
    >>> print(latex("plain % text"))
    \mathtt{\text{plain \% text}}

    See :ref:`printer_method_example` for an example of how to override
    this behavior for your own types by implementing ``_latex``.

    .. versionchanged:: 1.7.0
        Unsupported types no longer have their ``str`` representation treated as valid latex.

    )r   r  r  r   s     rs   r  r    s!    n !!))$///ru   c                :    t          t          | fi |           dS )z`Prints LaTeX representation of the given expression. Takes the same
    settings as ``latex()``.N)printr  r  s     rs   print_latexr  n  s(     
%
!
!
!
!"""""ru   rp  align*Fc           
        t          di |}|dk    rd}d}d}	d}
d}nD|dk    rd}d}d}	d	}
d}n3|d
k    rd}d}d}	d}
d}n"t          d                    |                    d}|rd}|                                }t	          |          }d}t          |          D ]}||         }d}d}d}||k    r	|rd}nd}d}||k    r||dz
  k     r||	z   dz   dz   }nd}|                                d         dk    rd|z  }d}|dk    rK|dk    rd}|d                    |                    |           |||                    |          |          z  }n.|d                    |||                    |          |          z  }|dz  }||
z  }|S )a  
    This function generates a LaTeX equation with a multiline right-hand side
    in an ``align*``, ``eqnarray`` or ``IEEEeqnarray`` environment.

    Parameters
    ==========

    lhs : Expr
        Left-hand side of equation

    rhs : Expr
        Right-hand side of equation

    terms_per_line : integer, optional
        Number of terms per line to print. Default is 1.

    environment : "string", optional
        Which LaTeX wnvironment to use for the output. Options are "align*"
        (default), "eqnarray", and "IEEEeqnarray".

    use_dots : boolean, optional
        If ``True``, ``\\dots`` is added to the end of each line. Default is ``False``.

    Examples
    ========

    >>> from sympy import multiline_latex, symbols, sin, cos, exp, log, I
    >>> x, y, alpha = symbols('x y alpha')
    >>> expr = sin(alpha*y) + exp(I*alpha) - cos(log(y))
    >>> print(multiline_latex(x, expr))
    \begin{align*}
    x = & e^{i \alpha} \\
    & + \sin{\left(\alpha y \right)} \\
    & - \cos{\left(\log{\left(y \right)} \right)}
    \end{align*}

    Using at most two terms per line:
    >>> print(multiline_latex(x, expr, 2))
    \begin{align*}
    x = & e^{i \alpha} + \sin{\left(\alpha y \right)} \\
    & - \cos{\left(\log{\left(y \right)} \right)}
    \end{align*}

    Using ``eqnarray`` and dots:
    >>> print(multiline_latex(x, expr, terms_per_line=2, environment="eqnarray", use_dots=True))
    \begin{eqnarray}
    x & = & e^{i \alpha} + \sin{\left(\alpha y \right)} \dots\nonumber\\
    & & - \cos{\left(\log{\left(y \right)} \right)}
    \end{eqnarray}

    Using ``IEEEeqnarray``:
    >>> print(multiline_latex(x, expr, environment="IEEEeqnarray"))
    \begin{IEEEeqnarray}{rCl}
    x & = & e^{i \alpha} \nonumber\\
    & & + \sin{\left(\alpha y \right)} \nonumber\\
    & & - \cos{\left(\log{\left(y \right)} \right)}
    \end{IEEEeqnarray}

    Notes
    =====

    All optional parameters from ``latex`` can also be used.

    eqnarrayz\begin{eqnarray}
z& = &z	\nonumberz
\end{eqnarray}TIEEEeqnarrayz\begin{IEEEeqnarray}{rCl}
z
\end{IEEEeqnarray}r  z\begin{align*}
z= &r   z
\end{align*}FzUnknown environment: {}z\dotsrp  r  z& & r  r  r  r   ro  r3  z{:s} {:s}{:s} {:s} {:s}z{:s}{:s} {:s} {:s}rp   )r   r   r  as_ordered_termsr  r  r  r  )r  r  terms_per_lineenvironmentuse_dotsr   r  r  
first_termnonumberend_termdoubleetr  rg  n_terms
term_countr   rh  
term_startterm_endr  s                        rs   multiline_latexr  u  s+   F 	  x  Aj  +
&		&	&4
*		 	 )
%299+FFGGGD   ""E%jjGJ7^^  Qx
&& "#

!
J''719}}(?U2T9""$$Q'2--d7DD66s{{077		#"D!))D//8E E EFF +22:t		$3 3 3Fa


hFMru   )rr   r   r   r   )rp  r  F)J__doc__
__future__r   typingr   r   r   rR  
sympy.corer   r   r	   r
   r   r   r   r   sympy.core.alphabetsr   sympy.core.containersr   sympy.core.functionr   r   r   sympy.core.operationsr   sympy.core.powerr   sympy.core.sortingr   sympy.core.sympifyr   r  r   r   r   sympy.printing.precedencer   sympy.printing.printerr   r   sympy.printing.conventionsr   r   r    r!   mpmath.libmp.libmpfr"   r#   r  sympy.utilities.iterablesr$   r%   r8   sympy.tensor.arrayr&   sympy.vector.basisdependentr'   r  r  r  r   r  	frozensetr  compiler  r   r   r  r  r  r  rp   ru   rs   <module>r     s8     # " " " " " / / / / / / / / / /     D D D D D D D D D D D D D D D D D D D D ' ' ' ' ' ' ' ' ' ' ' ' B B B B B B B B B B ) ) ) ) ) )             / / / / / / + + + + + + ? ? ? ? ? ? ? ? ? ? = < < < < < : : : : : : : : H H H H H H H H < < < < < < < < B B B B B B B B 7 7 7 7 7 7 7 7 				 ;,,,,,,::::::   %]%
M% Y% Y	%
 }% M% 
=% Y% M% ]% j% 	-% 	-% 	&% s%  }!%" 	&#% %$ 
=%%& Y'%( 
=)%* {+%, 
7-%. 
=/%0 
71%2 Y3%4 Z5%6 Z7%8 
79%: 
=;%< .=%> ?%@ jA%B YC%D jE% %F I% % % N, , ,2..2 **2 ((	2
 &&2 
$$2 ((2 ((2 ((2 ((2 ((2 
$$2 
$$2 
$$2 !!2  
!2$ ,,%2& 	
*
*'2( )(((**0099----72 2 2    < If%%  BJ~BJ'((    d+7 d+7 d+7 d+7 d+77 d+7 d+7 d+7NW   > V0 V0 V0r# # #~ ~ ~ ~ ~ ~ru   