
    wg                       d Z ddlmZ ddlmZ ddl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 ddl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  G d de      Z ee      d        Z  G d de      Z! ee!      d        Z"y)zI
A Printer for generating readable representation of most SymPy classes.
    )annotations)Any)SRationalPowBasicMulNumber)_keep_coeff)Integer)
Relational)default_sort_key)sift   )
precedence
PRECEDENCE)Printerprint_function)prec_to_dpsto_strc                  l   e Zd ZU dZddddddddZded<   i Zd	ed
<   ddZddZd Z	ddZ
d Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd  Z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+d0 Z,d1 Z-d2 Z.d3 Z/d4 Z0d5 Z1d6 Z2d7 Z3d8 Z4d9 Z5d: Z6d; Z7d< Z8d= Z9d> Z:d? Z;d@ Z<dA Z=dB Z>dC Z?dD Z@dE ZAdF ZBdG ZCdH ZDdI ZEdJ ZFdK ZGdL ZHdM ZIdN ZJdO ZKdP ZLdQ ZMddRZNdS ZOdT ZPdU ZQdV ZRdW ZSdX ZTdY ZUdZ ZVd[ ZWd\ ZXd] ZYd^ ZZd_ Z[d` Z\da Z]db Z^dc Z_dd Z`de Zadf Zbdg Zcdh Zddi Zedj Zfdk Zgdl Zhdm Zidn ZjejZkejZldo Zmdp Zndq Zodr Zpds Zqdt Zrdu Zsdv Ztdw Zudx Zvdy Zwdz Zxd{ Zyd| Zzd} Z{d~ Z|d Z}d Z~d Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)
StrPrinter	_sympystrNautoFT)order	full_precsympy_integersabbrevperm_cyclicminmaxzdict[str, Any]_default_settingszdict[str, str]_relationalsc                    t        |      |k  s|s"t        |      |k  rd| j                  |      z  S | j                  |      S )N(%s))r   _print)selfitemlevelstricts       W/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/printing/str.pyparenthesizezStrPrinter.parenthesize"   s@    tu$v:d;Ku;TDKK---;;t$$    c           	     j    |j                  |D cg c]  }| j                  ||       c}      S c c}w N)joinr,   )r'   argssepr)   r(   s        r+   	stringifyzStrPrinter.stringify(   s,    xxDID**47IJJIs   0c                r    t        |t              r|S t        |t              rt        |      S t        |      S r/   )
isinstancestrr   reprr'   exprs     r+   emptyPrinterzStrPrinter.emptyPrinter+   s/    dC Ke$:t9r-   c                   | j                  ||      }t        |      }g }|D ]~  }| j                  |      }|j                  d      r|j                  sd}|dd  }nd}t        |      |k  s|j                  r|j                  |d|z  g       l|j                  ||g        |j                  d      }|dk(  rd}|dj                  |      z   S )	Nr   -r   +r%   r     )_as_ordered_termsr   r&   
startswithis_Addextendpopr0   )	r'   r9   r   termsprecltermtsigns	            r+   
_print_AddzStrPrinter._print_Add3   s    &&t5&9$ 
	$DD!A||C abE$$&$++$
+,$#
	$ uuQx3;Dchhqk!!r-   c                     y)NTrue r8   s     r+   _print_BooleanTruezStrPrinter._print_BooleanTrueH   s    r-   c                     y)NFalserO   r8   s     r+   _print_BooleanFalsezStrPrinter._print_BooleanFalseK       r-   c                T    d| j                  |j                  d   t        d         z  S )Nz~%sr   Not)r,   r1   r   r8   s     r+   
_print_NotzStrPrinter._print_NotN   s'    t((1j6GHIIr-   c                8   t        |j                        }t        |      D ]^  \  }}t        |t              s|j
                  j                  t        j                  u s>|j                  d|j                  |             ` | j                  |dt        d         S )Nr   z & 
BitwiseAnd)listr1   	enumerater5   r   	canonicalrhsr   NegativeInfinityinsertrE   r3   r   )r'   r9   r1   jis        r+   
_print_AndzStrPrinter._print_AndQ   sv    DIIdO 	,DAq!Z(KKOOq'9'99Atxx{+	, ~~dE:l+CDDr-   c                J    | j                  |j                  dt        d         S )Nz | 	BitwiseOrr3   r1   r   r8   s     r+   	_print_OrzStrPrinter._print_OrY   s    ~~dii
;0GHHr-   c                J    | j                  |j                  dt        d         S )Nz ^ 
BitwiseXorre   r8   s     r+   
_print_XorzStrPrinter._print_Xor\   s    ~~dii
<0HIIr-   c                x    | j                  |j                        d| j                  |j                  d      dS N(, ))r&   functionr3   	argumentsr8   s     r+   _print_AppliedPredicatez"StrPrinter._print_AppliedPredicate_   s/    KK&t~~t(LN 	Nr-   c                    |j                   D cg c]  }| j                  |       }}|j                  j                  ddj	                  |      z  z   S c c}w Nr%   rm   )r1   r&   	__class____name__r0   )r'   r9   orH   s       r+   _print_BasiczStrPrinter._print_Basicc   sH    %)YY/T[[^//~~&&$))A,)>>> 0s   Ac                    |j                   j                  dk(  r| j                  |j                   d          | j                  |j                         S )N)r   r   )r   r   )blocksshaper&   )r'   Bs     r+   _print_BlockMatrixzStrPrinter._print_BlockMatrixg   s9    88>>V#KK'{{188$$r-   c                     y)NCatalanrO   r8   s     r+   _print_CatalanzStrPrinter._print_Catalanl   s    r-   c                     y)NzoorO   r8   s     r+   _print_ComplexInfinityz!StrPrinter._print_ComplexInfinityo       r-   c                   t        |j                  |j                  fD cg c]  }| j                  |       c}      }|j                  t
        j                  u rd|z  S || j                  |j                        fz  }d|z  S c c}w )NzConditionSet(%s, %s)zConditionSet(%s, %s, %s))tuplesym	conditionr&   base_setr   UniversalSet)r'   sra   r1   s       r+   _print_ConditionSetzStrPrinter._print_ConditionSetr   sr    quuakk.BCdkk!nCD::')D00QZZ(**)D00	 Ds   Bc                     |j                   }|j                  D cg c]  }|d   dk(  r|d   n| }}ddj                   fd|g|z   D              z  S c c}w )Nr   r   zDerivative(%s)rm   c              3  @   K   | ]  }j                  |        y wr/   r&   .0argr'   s     r+   	<genexpr>z/StrPrinter._print_Derivative.<locals>.<genexpr>|   s     ,Y#T[[-=,Y   )r9   variable_countr0   )r'   r9   dexprra   dvarss   `    r+   _print_DerivativezStrPrinter._print_Derivativey   s_    		373F3FGa11)GG$)),Y%SX,Y"ZZZ Hs   Ac                    t        |j                         t              }g }|D ];  }| j                  |      d| j                  ||         }|j	                  |       = ddj                  |      z  S )Nkeyz: {%s}rm   )sortedkeysr   r&   appendr0   )r'   dr   itemsr   r(   s         r+   _print_dictzStrPrinter._print_dict~   sk    affh$45 	C#{{3/QsV1DEDLL	 		%(((r-   c                $    | j                  |      S r/   )r   r8   s     r+   _print_DictzStrPrinter._print_Dict       %%r-   c                ,   t        |d      r"d| j                  |j                               z   S t        |d      r=d| j                  |j                        z   dz   | j                  |j                        z   S d| j                  |j                        z   S )N
as_booleanzDomain: setz in z
Domain on )hasattrr&   r   symbolsr   )r'   r   s     r+   _print_RandomDomainzStrPrinter._print_RandomDomain   s~    1l#ALLN ;;;QQYY!77&@KK&' (  $++aii"888r-   c                     d|j                   z   S N_namer8   s     r+   _print_DummyzStrPrinter._print_Dummy   s    TYYr-   c                     y)N
EulerGammarO   r8   s     r+   _print_EulerGammazStrPrinter._print_EulerGamma   s    r-   c                     y)NErO   r8   s     r+   _print_Exp1zStrPrinter._print_Exp1       r-   c                x    d| j                  |j                        d| j                  |j                        dS rk   )r&   r9   condr8   s     r+   _print_ExprCondPairzStrPrinter._print_ExprCondPair   s'    ![[3T[[5KLLr-   c                n    |j                   j                  d| j                  |j                  d      z  z   S rs   )funcru   r3   r1   r8   s     r+   _print_FunctionzStrPrinter._print_Function   s+    yy!!FT^^DIIt-L$LLLr-   c                     y)NGoldenRatiorO   r8   s     r+   _print_GoldenRatiozStrPrinter._print_GoldenRatio   s    r-   c                n    |j                   j                  d| j                  |j                  d      z  z   S rs   )r   ru   r3   pargsr8   s     r+   _print_HeavisidezStrPrinter._print_Heaviside   s-     yy!!FT^^DJJ-M$MMMr-   c                     y)NTribonacciConstantrO   r8   s     r+   _print_TribonacciConstantz$StrPrinter._print_TribonacciConstant   s    #r-   c                     yNIrO   r8   s     r+   _print_ImaginaryUnitzStrPrinter._print_ImaginaryUnit   r   r-   c                     y)NoorO   r8   s     r+   _print_InfinityzStrPrinter._print_Infinity       r-   c                      fd}dj                  |j                  D cg c]
  } ||       c}      }d j                  |j                        d|dS c c}w )Nc                    t        |       dk(  rj                  | d         S j                  | d   ft        | dd        z         S Nr   r   lenr&   r   xabr'   s    r+   
_xab_tostrz.StrPrinter._print_Integral.<locals>._xab_tostr   E    3x1}{{3q6**{{CF9uSW~#=>>r-   rm   z	Integral(rn   r0   limitsr&   ro   r'   r9   r   rH   Ls   `    r+   _print_IntegralzStrPrinter._print_Integral   sH    	?
 IIdkk:z!}:;%)[[%?CC ;   Ac                    d}|j                   \  }}}}|j                  r|j                  rd}n7|j                  r|sd}n&|j                  r|sd}n|s|sd}n|r|rd}n|rd}nd} |j                  di |||dS )NzInterval{m}({a}, {b})r?   z.openz.Lopenz.Ropen)abmrO   )r1   is_infiniteformat)r'   ra   finr   r   rH   rr   s           r+   _print_IntervalzStrPrinter._print_Interval   s    &VV
1a==Q]]A]]1A]]1A1A1AAAszz5!!!455r-   c                x    d| j                  |j                        d| j                  |j                        dS )NzAccumBounds(rm   rn   )r&   r    r!   )r'   ra   s     r+   _print_AccumulationBoundsz$StrPrinter._print_AccumulationBounds   s,    (,AEE(:(,AEE(:< 	<r-   c                N    d| j                  |j                  t        d         z  S )Nz%s**(-1)r   r,   r   r   )r'   r   s     r+   _print_InversezStrPrinter._print_Inverse   s#    D--aeeZ5FGGGr-   c                    |j                   }|j                  }t        |      dk(  r|d   j                  r|d   }d| j	                  |      d| j	                  |      dS )Nr   r   zLambda(rm   rn   )r9   	signaturer   	is_symbolr&   )r'   objr9   sigs       r+   _print_LambdazStrPrinter._print_Lambda   sR    xxmms8q=SV--a&C#';;s#3T[[5FGGr-   c                     t        |j                  t              }|j                  j                  ddj                   fd|D              z  z   S )Nr   r%   rm   c              3  @   K   | ]  }j                  |        y wr/   r   r   s     r+   r   z.StrPrinter._print_LatticeOp.<locals>.<genexpr>   s     6XCt{{37G6Xr   )r   r1   r   r   ru   r0   r'   r9   r1   s   `  r+   _print_LatticeOpzStrPrinter._print_LatticeOp   s>    dii%56yy!!FTYY6XSW6X-X$XXXr-   c           
     p    |j                   \  }}}}dt        t        | j                  ||||f            z  S )NzLimit(%s, %s, %s, dir='%s'))r1   r   mapr&   )r'   r9   ezz0dirs         r+   _print_LimitzStrPrinter._print_Limit   s7    		1b#,uSq!RQTo5V/WWWr-   c                ,    d| j                  |d      z  S )N[%s]rm   )r3   r8   s     r+   _print_listzStrPrinter._print_list   s    tT222r-   c                $    | j                  |      S r/   )r   r8   s     r+   _print_ListzStrPrinter._print_List   r   r-   c                $    |j                  |       S r/   )_format_strr8   s     r+   _print_MatrixBasezStrPrinter._print_MatrixBase   r   r-   c                    | j                  |j                  t        d   d      d| j                  |j                        d| j                  |j
                        dz   S )NAtomTr*   [rm   ])r,   parentr   r&   ra   r`   r8   s     r+   _print_MatrixElementzStrPrinter._print_MatrixElement   sN      j.@ N KK/TVV1DEF 	Fr-   c                
     fd} j                  |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j                  fd| D              S )N   r   r   r?   :c              3  @   K   | ]  }j                  |        y wr/   r   r   s     r+   r   zBStrPrinter._print_MatrixSlice.<locals>.strslice.<locals>.<genexpr>   s     ;#T[[-;r   )rZ   r0   )xdimr'   s     r+   strslicez/StrPrinter._print_MatrixSlice.<locals>.strslice   s[    QAtqyaDtqy!ts{!88;;<<r-   r  Tr  r  rm   r	  )r,   r
  r   rowslicerowscolslicecols)r'   r9   r  s   `  r+   _print_MatrixSlicezStrPrinter._print_MatrixSlice   s    	= !!$++z&/A$!ORUU(8(89:<@A(8(89:<?@ 	Ar-   c                    |j                   S r/   r   r8   s     r+   _print_DeferredVectorz StrPrinter._print_DeferredVector      yyr-   c           	     ^
   t        |      }|j                  }|d   t        j                  u st	        d |dd  D              rt        |d d      \  }}t        |      D ]  \  }}|j                  j                  r|j                   }n=t        |j                  j                        }	|	d    |	d<   t        j                  |	      }|dz
  rt        |j                  |d      n|j                  ||<    g }
|rC|d   j                  s4|d   j                         r!| j!                  |j#                  d            g}
|
|D cg c]  }| j%                  ||d	       c}z   }|sd
g}t'        |      dkD  r5|d   j                         r"| j!                  |j#                  d            g}
ng }
|
|D cg c]  }| j%                  ||d	       c}z   }dj)                  |      }dj)                  |      }t'        |      dkD  r|d|dS |r|d|S |S |j+                         \  }}|dk  rt-        | |      }d}nd}g }g }g }| j.                  dvr|j1                         }nt        j2                  |      }d }|D ]  }|j4                  rt7        |t              rt9        |j                  j+                         d   dk        r|j                  t        j:                  ur|j=                   ||             }t'        |j                  d   j                        dk7  r1t7        |j                  t        t        f      r|j=                  |       |j=                  |j                         |j>                  r||t        j@                  urj|jB                  dk7  r$|j=                  tE        |jB                               |jF                  dk7  sQ|j=                  tE        |jF                               w|j=                  |        |xs t        j                  g}|D cg c]  }| j%                  ||d	       }}|D cg c]  }| j%                  ||d	       }}|D ]N  }|j                  |v sd||jI                  |j                           z  ||jI                  |j                        <   P |s|dj)                  |      z   S t'        |      dk(  r|dj)                  |      z   dz   |d   z   S |dj)                  |      z   ddj)                  |      z  z   S c c}w c c}w c c}w c c}w )Nr   c              3     K   | ]@  }t        |t              xs* |j                  xr t        d  |j                  D               B yw)c              3  4   K   | ]  }|j                     y wr/   )
is_Integer)r   ais     r+   r   z2StrPrinter._print_Mul.<locals>.<genexpr>.<genexpr>  s      @2 @s   N)r5   r
   is_Powallr1   )r   r   s     r+   r   z(StrPrinter._print_Mul.<locals>.<genexpr>  sH      ##  1f% A@S @ @@A##s   AAr   c                x    t        | t              xr) t        | j                  j	                         d   dk        S Nr   )r5   r   boolexpas_coeff_Mul)r  s    r+   <lambda>z'StrPrinter._print_Mul.<locals>.<lambda>  s2    1c"HtAEE,>,>,@,Ca,G'H r-   T)binaryFevaluater  1*z/(rn   /r=   r?   )oldnonec                D   | j                         \  }}t        t        j                  |            }|d   t        j
                  u r|dd  }n	|d    |d<   t        j                  |      }t        | t              r| j                  ||d      S | j                  |d      S )Nr   r   Fr*  )
as_base_exprZ   r	   	make_argsr   NegativeOne
_from_argsr5   r   r   )ra   r   r   eargss       r+   apowz#StrPrinter._print_Mul.<locals>.apowK  s    ==?DAqq)*EQx1==(ab	!!H9au%A!S!vvaUv3366!e6,,r-   r%   z/(%s))%r   r1   r   Oneanyr   r[   r&  	is_NumberrZ   r	   r5  r   baserC   could_extract_minus_signr&   rE   r,   r   r0   r'  r   r   as_ordered_factorsr3  is_commutativer5   r%  r4  r   is_RationalInfinitypr   qindex)r'   r9   rG   r1   r   nra   dir   dargsprer   nfactorsdfactorscrK   r   	pow_parenr7  r(   r  a_strb_strs                          r+   
_print_MulzStrPrinter._print_Mul  s   $ yy7aees ## ab##  #  IDAq #1 M266##A -E %ayE!Hu-A:;a%s277A6RWW!M C11)F)F)H{{1558,- #//4/F  H5 1vzad;;={{1558,- #//4/F  H "A"A8}q $%q))"#Q''H  "1q5r1%DDD	::_,**,D ==&D
	-  	D##tS)..03a78881==0HHT$Z(DIIaL--.!3&tyy3*=!((.HHTYY'!!d!**&<66Q;HHXdff-.66Q;HHXdff-.%	( L!%%CDEa""1d5"9EECDEa""1d5"9EE  	ODyyA~,2U177499;M5N,Naggdii()	O #((5/))Vq[#((5/)C/%(::#((5/)Gchhuo,EEEm~ FEs   T0T  T%T*c                   |j                         \  }}d}|j                  rb|j                         \  }}|j                  r|j                  rt        | |      }d}n'|j                  r|j                  rt        | |      }d}|dj                  |j                  D cg c]  }| j                  |t        |             c}      z   S c c}w )Nr?   r=   r-  )
as_coeff_mmul	is_numberas_real_imagis_zerois_negativer   r0   r1   r,   r   )r'   r9   rJ  r   rK   reimr   s           r+   _print_MatMulzStrPrinter._print_MatMul{  s    !!#1;;^^%FBzzbnn"A2q)"A2q)chhAEK#TsJt$45K
 
 	
Ks   "C	
c                l    dj                  |j                  | j                  |j                              S )Nz{}.({}))r   ro   r&   r9   r8   s     r+   _print_ElementwiseApplyFunctionz*StrPrinter._print_ElementwiseApplyFunction  s,    MMKK		"
 	
r-   c                     y)NnanrO   r8   s     r+   
_print_NaNzStrPrinter._print_NaN  r   r-   c                     y)Nz-oorO   r8   s     r+   _print_NegativeInfinityz"StrPrinter._print_NegativeInfinity  r   r-   c                Z   |j                   rt        d |j                  D              rdt        |j                         dk  rd| j	                  |j
                        z  S d| j                  |j
                  f|j                   z   dd      z  S d| j                  |j                  dd      z  S )Nc              3  @   K   | ]  }|t         j                  u   y wr/   )r   Zero)r   rA  s     r+   r   z*StrPrinter._print_Order.<locals>.<genexpr>  s     $EQQ!&&[$Es   r   zO(%s)rm   r   )	variablesr"  pointr   r&   r9   r3   r1   r8   s     r+   _print_OrderzStrPrinter._print_Order  s    ~~$E$**$E!E4>>"a'TYY!777t~~0MtUV!WWWT^^DIItQ???r-   c                "    |j                         S r/   __str__r8   s     r+   _print_OrdinalzStrPrinter._print_Ordinal      ||~r-   c                "    |j                         S r/   rf  r8   s     r+   _print_CyclezStrPrinter._print_Cycle  ri  r-   c                J   ddl m}m} ddlm} |j
                  }| |d| dddd	       n| j                  j                  d
d      }|r~|j                  sy  ||      |j                  dz
        j                         t        d      d  }|j                  d      }|dk(  sd||d  vr||d  |d | z   }|j                  dd      }|S |j                         }|sK|j                  dk  rd| j                  |j                        z  S d| j                  |j                        z  S | j                  |j                  d |d   dz          d| j                  |j                        z  z   }| j                  |j                        x}	}
t        |      t        |
      k  r|}	d|	z  S )Nr   )PermutationCycle)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   Tz()r   rn  rl   ,r?      zPermutation(%s)zPermutation([], size=%s)z	, size=%s) sympy.combinatorics.permutationsrm  rn  sympy.utilities.exceptionsro  print_cyclic	_settingsgetsize__repr__r   rfindreplacesupportr&   
array_form)r'   r9   rm  rn  ro  r   r   lasttrimusefulls              r+   _print_PermutationzStrPrinter._print_Permutation  s   GH!.."%++6- 8 */+P ..,,]DAK99 dDIIM*335c'lmDA773<D19AdeH!4deHq$x'		#r"AHA99q=,t{{4??/KKK1DKK		4JJJ;;tz"	:;kDKKX\XaXaLb>bbDT__55C$4y3t9$$s**r-   c                    |j                   \  }}}t        |j                        dk(  r
|d   }|d   }d| j                  |      d| j                  |      d| j                  |      dS )Nr   r   zSubs(rm   rn   )r1   r   rc  r&   )r'   r   r9   r/  news        r+   _print_SubszStrPrinter._print_Subs  sb    c3syy>Qa&Ca&CKKt{{3/S1AC 	Cr-   c                "    |j                         S r/   r   r8   s     r+   _print_TensorIndexzStrPrinter._print_TensorIndex      {{}r-   c                "    |j                         S r/   r   r8   s     r+   _print_TensorHeadzStrPrinter._print_TensorHead  r  r-   c                "    |j                         S r/   r   r8   s     r+   _print_TensorzStrPrinter._print_Tensor  r  r-   c                    |j                         \  }}|dj                  |D cg c]  }| j                  |t        |             c}      z   S c c}w )Nr-  )!_get_args_for_traditional_printerr0   r,   r   )r'   r9   rK   r1   r   s        r+   _print_TensMulzStrPrinter._print_TensMul  sO    ;;=
dchhAEF#TsJt$45F
 
 	
Fs   "A
c                "    |j                         S r/   r   r8   s     r+   _print_TensAddzStrPrinter._print_TensAdd  r  r-   c                8    | j                  |j                        S r/   r&   r   r8   s     r+   _print_ArraySymbolzStrPrinter._print_ArraySymbol  s    {{499%%r-   c           
         | j                  |j                  t        d   d      ddj                  |j                  D cg c]  }| j                  |       c}      dS c c}w )NFuncTr  rm   r	  )r,   r   r   r0   indicesr&   )r'   r9   ra   s      r+   _print_ArrayElementzStrPrinter._print_ArrayElement  sS    diiF);TBDIIgkgsgsNtbct{{[\~NtDuw 	wNts   A!c                    |j                   D cg c]  }d| j                  |      z   }}ddj                  |      z  S c c}w )Nz    %szPermutationGroup([
%s])z,
)r1   r&   r0   )r'   r9   r   rA  s       r+   _print_PermutationGroupz"StrPrinter._print_PermutationGroup  s>    04		:1XA&::)EJJqM99 ;s   A c                     y)NpirO   r8   s     r+   	_print_PizStrPrinter._print_Pi  r   r-   c                     ddj                   fd|j                  D              d j                  |j                        d j                  |j                        dS )NzPolynomial ring in rm   c              3  @   K   | ]  }j                  |        y wr/   r   )r   rsr'   s     r+   r   z-StrPrinter._print_PolyRing.<locals>.<genexpr>  s     ?BB?r    over  with  orderr0   r   r&   domainr   )r'   rings   ` r+   _print_PolyRingzStrPrinter._print_PolyRing  sB    YY?$,,?@KK$dkk$**&=? 	?r-   c                     ddj                   fd|j                  D              d j                  |j                        d j                  |j                        dS )NzRational function field in rm   c              3  @   K   | ]  }j                  |        y wr/   r   )r   fsr'   s     r+   r   z.StrPrinter._print_FracField.<locals>.<genexpr>   s     @BB@r   r  r  r  r  r'   fields   ` r+   _print_FracFieldzStrPrinter._print_FracField  sD    YY@%--@AKK%t{{5;;'?A 	Ar-   c                "    |j                         S r/   rf  )r'   elms     r+   _print_FreeGroupElementz"StrPrinter._print_FreeGroupElement  s    {{}r-   c                <    d|j                   d|j                  dS )Nrl    + z*I))r  yr'   polys     r+   _print_GaussianElementz!StrPrinter._print_GaussianElement  s     $//r-   c                2    |j                  | t        dd      S )Nz%s**%sr-  )r6   r   r  s     r+   _print_PolyElementzStrPrinter._print_PolyElement	  s    xxj(C88r-   c                    |j                   dk(  r| j                  |j                        S | j                  |j                  t        d   d      }| j                  |j                   t        d   d      }|dz   |z   S )Nr   r	   Tr  r  r.  )denomr&   numerr,   r   )r'   fracr  r  s       r+   _print_FracElementzStrPrinter._print_FracElement  so    ::?;;tzz**%%djj*U2CD%QE%%djj*V2DT%RE3;&&r-   c                (   t         d   dz
  }g |j                  D cg c]  }| j                  ||       }}}|j                         D ]F  \  }}g }t	        |      D ]?  \  }	}
|
dkD  s|
dk(  r|j                  ||	          &|j                  ||	   d|
z  z          A dj                  |      }|j                  r,|rd| j                  |      z   dz   }nq| j                  |      }n_|rL|t        j                  u r|j                  d|g       |t        j                  u r|j                  d	|g       | j                  |      }|s|}n|dz   |z   }|j                  d	      r|j                  d	|dd  g       4|j                  d|g       I |d   d
v r!|j                  d      }|d	k(  rd	|d   z   |d<   |j                  j                   dz   }ddlm} 	 |d|j'                         z  z  }|dz  }t	        |      D ]F  \  }}t+        |      dkD  s|d d dk(  s|t+        |      dz
  d  dk(  s3|dt+        |      dz
   ||<   H |dj                  |      dj                  |      fz  S c c}w # |$ r |d|j)                         z  z  }Y w xY w)Nr  r   r   z**%dr-  rl   rn   r>   r=   )r=   r>   z(%s, %s)PolynomialErrorz, modulus=%sz, domain='%s'r  r@   rm   )r   gensr,   rF   r[   r   r0   rC   r&   r   r8  rD   r4  rB   rE   rt   ru   sympy.polys.polyerrorsr  get_modulus
get_domainr   )r'   r9   	ATOM_PRECr   rF   r  monomcoeffs_monomra   r   s_coeffs_termmodifierr   r  rC  r(   s                     r+   _print_PolyzStrPrinter._print_Poly  s   v&*	TYYPD--a;PtP JJL %	,LE5G!%( =1q5AvtAw/tAw!';<= hhw'G||!DKK$66<G"kk%0G~c7^4 -c7^4 ++e,  30  %c6!":./c6]+K%	,N 8z!yy|H3q>a((94:	:nt'7'7'999F 	#$T? 	4KE44y1}$r(c/d3t9q=>6Jc6Q"1SY]3U	4 %$))D/:::} Qj  	:o(999F	:s   I.I3 3JJc                     y)Nr   rO   )r'   rA  s     r+   _print_UniversalSetzStrPrinter._print_UniversalSetV  s    r-   c                    |j                   r-| j                  |j                         j                               S | j                  |j                               S r/   )
is_aliasedr&   as_polyas_exprr8   s     r+   _print_AlgebraicNumberz!StrPrinter._print_AlgebraicNumberY  s<    ??;;t||~55788;;t||~..r-   c                p    t        |      }|j                  t        j                  u r |sd j	                  |j
                        z  S |j                  r|j                   t        j                  u r3|s1dt         fdt        j                  |j
                  fD              z  S |j                  t        j                   u r@ j	                  t        j                        d j                  |j
                  |d      S  j                  |j                  |d      } j                  dk(  rf|j                  j                  rP|j                  j                  dk7  r7|j                  d	      r& j                  |j
                  |d      d
|dd S  j                  |j
                  |d      d
|S )a$  Printing helper function for ``Pow``

        Parameters
        ==========

        rational : bool, optional
            If ``True``, it will not attempt printing ``sqrt(x)`` or
            ``x**S.Half`` as ``sqrt``, and will use ``x**(1/2)``
            instead.

            See examples for additional details

        Examples
        ========

        >>> from sympy import sqrt, StrPrinter
        >>> from sympy.abc import x

        How ``rational`` keyword works with ``sqrt``:

        >>> printer = StrPrinter()
        >>> printer._print_Pow(sqrt(x), rational=True)
        'x**(1/2)'
        >>> printer._print_Pow(sqrt(x), rational=False)
        'sqrt(x)'
        >>> printer._print_Pow(1/sqrt(x), rational=True)
        'x**(-1/2)'
        >>> printer._print_Pow(1/sqrt(x), rational=False)
        '1/sqrt(x)'

        Notes
        =====

        ``sqrt(x)`` is canonicalized as ``Pow(x, S.Half)`` in SymPy,
        so there is no need of defining a separate printer for ``sqrt``.
        Instead, it should be handled here as well.
        zsqrt(%s)z%s/sqrt(%s)c              3  @   K   | ]  }j                  |        y wr/   r   r   s     r+   r   z(StrPrinter._print_Pow.<locals>.<genexpr>  s     -]3dkk#.>-]r   r.  Fr  
_sympyreprr   z	(Rational**rv  )r   r&  r   Halfr&   r;  r>  r   r8  r,   printmethodr?  rB  rB   )r'   r9   rationalPRECr   s   `    r+   
_print_PowzStrPrinter._print_Pow_  sf   L $88qvvhDII 666yAFF"8 %u-]155RVR[R[J\-]'^^^xxAEE6!"&++aee"4"&"3"3DIItE"3"RT T dhhU;|+0D0DWX ||K(#'#4#4TYYU#4#SUVWXY[U\]],,TYYU,KQOOr-   c                >    | j                  |j                  d         S r$  r&   r1   r8   s     r+   _print_UnevaluatedExprz!StrPrinter._print_UnevaluatedExpr  s    {{499Q<((r-   c                    t        |      }| j                  |j                  |d      d| j                  |j                  |d      S )NFr  r  )r   r,   r;  r&  )r'   r9   r  s      r+   _print_MatPowzStrPrinter._print_MatPow  sJ    $,,TYYU,K**488T%*HJ 	Jr-   c                n    | j                   j                  dd      rd|z  S t        |j                        S )Nr   FzS(%s))rz  r{  r6   rA  r8   s     r+   _print_IntegerzStrPrinter._print_Integer  s0    >>.6d##466{r-   c                     y)NIntegersrO   r8   s     r+   _print_IntegerszStrPrinter._print_Integers      r-   c                     y)NNaturalsrO   r8   s     r+   _print_NaturalszStrPrinter._print_Naturals  r  r-   c                     y)N	Naturals0rO   r8   s     r+   _print_Naturals0zStrPrinter._print_Naturals0      r-   c                     y)N	RationalsrO   r8   s     r+   _print_RationalszStrPrinter._print_Rationals  r  r-   c                     y)NRealsrO   r8   s     r+   _print_RealszStrPrinter._print_Reals  rT   r-   c                     y)N	ComplexesrO   r8   s     r+   _print_ComplexeszStrPrinter._print_Complexes  r  r-   c                     y)NEmptySetrO   r8   s     r+   _print_EmptySetzStrPrinter._print_EmptySet  r  r-   c                     y)NEmptySequencerO   r8   s     r+   _print_EmptySequencezStrPrinter._print_EmptySequence  s    r-   c                    t        |      S r/   r6   r8   s     r+   
_print_intzStrPrinter._print_int      4yr-   c                    t        |      S r/   r  r8   s     r+   
_print_mpzzStrPrinter._print_mpz  r  r-   c                    |j                   dk(  rt        |j                        S | j                  j	                  dd      rd|j                  d|j                   S |j                  d|j                   S )Nr   r   FzS(z)/r.  )rB  r6   rA  rz  r{  r8   s     r+   _print_RationalzStrPrinter._print_Rational  sV    66Q;tvv;~~!!"2E:%)VVTVV44"ffdff--r-   c                    |j                   dk(  rt        |j                        S d|j                  |j                   fz  S )Nr   z%d/%d)rB  r6   rA  r8   s     r+   _print_PythonRationalz StrPrinter._print_PythonRational  s3    66Q;tvv;dffdff---r-   c                    |j                   dk(  rt        |j                        S |j                  d|j                   S Nr   r.  denominatorr6   	numeratorr8   s     r+   _print_FractionzStrPrinter._print_Fraction  4    q t~~&&"nnd.>.>??r-   c                    |j                   dk(  rt        |j                        S |j                  d|j                   S r  r  r8   s     r+   
_print_mpqzStrPrinter._print_mpq  r  r-   c                ,   |j                   }|dk  rd}nt        |j                         }| j                  d   du rd}n5| j                  d   du rd}n!| j                  d   dk(  r| j                  dkD  }d| j                  v r| j                  d   nd }d	| j                  v r| j                  d	   nd }t	        |j
                  |||
      }|j                  d      r	d|dd  z   }n|j                  d      rd|dd  z   }|j                  d      r|dd  }|S )Nru  r   r   TFr   r   r    r!   )strip_zeros	min_fixed	max_fixedz-.0z-0.   z.0z0.r  r>   )_precr   rz  _print_levelmlib_to_str_mpf_rB   )r'   r9   rG   dpsstriplowhighrvs           r+   _print_FloatzStrPrinter._print_Float  s   zz!8Cdjj)C>>+&$.E^^K(E1E^^K(F2%%)E','>dnnU#D(-(?t~~e$TSesVZ[==ABB]]4 12B==ABB	r-   c           
        ddddddddd	}|j                   |v rJ||j                      d
| j                  |j                        d| j                  |j                        dS | j	                  |j                  t        |            d| j                  j                  |j                         xs |j                   d| j	                  |j                  t        |            S )NEqNe
AssignmentAddAugmentedAssignmentSubAugmentedAssignmentMulAugmentedAssignmentDivAugmentedAssignmentModAugmentedAssignment)z==z!=z:=z+=z-=z*=z/=z%=rl   rm   rn   r@   )rel_opr&   lhsr]   r,   r   r#   r{  )r'   r9   charmaps      r+   _print_RelationalzStrPrinter._print_Relational  s     *****	
 ;;'!#*4;;#7TXX9N#';;txx#8: : "..txxD9IJ,,00=LL,,TXXz$7GHJ 	Jr-   c                Z    d| j                  |j                  d      |j                  fz  S )NzCRootOf(%s, %d)lexr<   )rL   r9   rC  r8   s     r+   _print_ComplexRootOfzStrPrinter._print_ComplexRootOf  s.     DOODIIeO$L$(JJ$0 0 	0r-   c                    | j                  |j                  d      g}|j                  t        j                  ur*|j                  | j                  |j                               ddj                  |      z  S )Nr1  r<   zRootSum(%s)rm   )rL   r9   funr   IdentityFunctionr   r&   r0   r   s      r+   _print_RootSumzStrPrinter._print_RootSum  sY    		78881---KKDHH-.tyy..r-   c                   |j                   j                  }|j                  D cg c]  }| j                  ||j                        ! }}ddj                  |      z  }|j                  D cg c]  }| j                  |       }}d| j                  |j                        z  }d| j                  |j                        z  }|g|z   ||gz   }	|ddj                  |	      dS c c}w c c}w )Nr<   r   rm   zdomain='%s'z
order='%s'rl   rn   )	rt   ru   exprsrL   r   r0   r  r&   r  )
r'   basisclsr   r8  genr  r  r   r1   s
             r+   _print_GroebnerBasiszStrPrinter._print_GroebnerBasis  s    oo&&DIKKPSEKK8PP5))-2ZZ9cS!99U\\!::t{{5;;77w~/		$00 Q :s   $C%-C*c                j     t        |t              }dj                   fd|D              }|syd|z  S )Nr   rm   c              3  @   K   | ]  }j                  |        y wr/   r   r   r(   r'   s     r+   r   z(StrPrinter._print_set.<locals>.<genexpr>+       =tT*=r   zset()r   )r   r   r0   r'   r   r   r1   s   `   r+   
_print_setzStrPrinter._print_set(  s4    q./yy=u==}r-   c                     ddl m t        |t              }dj	                   fd|D              }t        fd|D              rdj                  |      S dj                  |      S )	Nr   )	FiniteSetr   rm   c              3  @   K   | ]  }j                  |        y wr/   r   r?  s     r+   r   z.StrPrinter._print_FiniteSet.<locals>.<genexpr>4  r@  r   c              3  @   K   | ]  }|j                          y wr/   )has)r   r(   rD  s     r+   r   z.StrPrinter._print_FiniteSet.<locals>.<genexpr>5  s     5ttxx	"5r   zFiniteSet({})z{{{}}})sympy.sets.setsrD  r   r   r0   r9  r   )r'   r   r   r1   rD  s   `   @r+   _print_FiniteSetzStrPrinter._print_FiniteSet0  sU    -q./yy=u==5u55"))$//t$$r-   c                |     t        |t              }dj                   fd|D              }dj                  |      S )Nr   rm   c              3  @   K   | ]  }j                  |        y wr/   r   r   s     r+   r   z.StrPrinter._print_Partition.<locals>.<genexpr><  s     ;cS);r   zPartition({}))r   r   r0   r   rA  s   `   r+   _print_PartitionzStrPrinter._print_Partition9  s5    q./yy;U;;%%d++r-   c                0    |syd| j                  |      z  S )Nzfrozenset()zfrozenset(%s))rB  r'   r   s     r+   _print_frozensetzStrPrinter._print_frozenset?  s     !333r-   c                      fd}dj                  |j                  D cg c]
  } ||       c}      }d j                  |j                        d|dS c c}w )Nc                    t        |       dk(  rj                  | d         S j                  | d   ft        | dd        z         S r   r   r   s    r+   r   z)StrPrinter._print_Sum.<locals>._xab_tostrE  r   r-   rm   zSum(rn   r   r   s   `    r+   
_print_SumzStrPrinter._print_SumD  sH    	?
 IIdkk:z!}:; $DMM :A>> ;r   c                    |j                   S r/   r   r8   s     r+   _print_SymbolzStrPrinter._print_SymbolM  r  r-   c                     yr   rO   r8   s     r+   _print_IdentityzStrPrinter._print_IdentityR  r   r-   c                     y)N0rO   r8   s     r+   _print_ZeroMatrixzStrPrinter._print_ZeroMatrixU  r   r-   c                     y)Nr,  rO   r8   s     r+   _print_OneMatrixzStrPrinter._print_OneMatrixX  r   r-   c                     d|j                   z  S )NzQ.%sr   r8   s     r+   _print_PredicatezStrPrinter._print_Predicate[  s    		!!r-   c                    t        |      S r/   r  r8   s     r+   
_print_strzStrPrinter._print_str^  r  r-   c                v    t        |      dk(  rd| j                  |d         z  S d| j                  |d      z  S )Nr   z(%s,)r   r%   rm   )r   r&   r3   r8   s     r+   _print_tuplezStrPrinter._print_tuplea  s;    t9>T[[a111DNN4666r-   c                $    | j                  |      S r/   )ra  r8   s     r+   _print_TuplezStrPrinter._print_Tupleg  s      &&r-   c                N    d| j                  |j                  t        d         z  S )Nz%s.Tr   r   )r'   Ts     r+   _print_TransposezStrPrinter._print_Transposej  s#    ))!%%E1BCCCr-   c                x    d| j                  |j                        d| j                  |j                        dS )NzUniform(rm   rn   )r&   r   r   r8   s     r+   _print_UniformzStrPrinter._print_Uniformm  s'    $(KK$7TVV9LMMr-   c                v    | j                   j                  dd      rd|j                  z  S d|j                  z  S )Nr   Fz%s)rz  r{  r   r   r8   s     r+   _print_QuantityzStrPrinter._print_Quantityp  s4    >>h.$++%%diir-   c                    |j                   D cg c]  }| j                  |t        d   d       }}|d   gt        |dd  d      D cg c]  \  }}|dz   |z    c}}z   }dj	                  |      S c c}w c c}}w )	Nr	   Tr  r   r   ijkr-  r  )r1   r,   r   zipr0   )r'   r9   ra   r   r`   r   s         r+   _print_QuaternionzStrPrinter._print_Quaternionu  s{    KO99UaTq*U"3DAUUqTF#aeU*;<$!QaeAg<<zz!} V<s   "A3
A8c                    t        |      S r/   r  r8   s     r+   _print_DimensionzStrPrinter._print_Dimensionz  r  r-   c                     |j                   dz   S r   r   r8   s     r+   _print_WildzStrPrinter._print_Wild}      yy3r-   c                     |j                   dz   S r   r   r8   s     r+   _print_WildFunctionzStrPrinter._print_WildFunction  rs  r-   c                    |j                   S r/   r   r8   s     r+   _print_WildDotzStrPrinter._print_WildDot  r  r-   c                    |j                   S r/   r   r8   s     r+   _print_WildPluszStrPrinter._print_WildPlus  r  r-   c                    |j                   S r/   r   r8   s     r+   _print_WildStarzStrPrinter._print_WildStar  r  r-   c                p    | j                   j                  dd      ry| j                  t        d            S )Nr   FzS(0)r   )rz  r{  r  r   r8   s     r+   _print_ZerozStrPrinter._print_Zero  s/    >>.6""71:..r-   c                    |j                   j                  }| j                  |j                               }| j                  |j                        }|d|d|dS rk   )rt   ru   r&   to_listdom)r'   rA  r:  repr  s        r+   
_print_DMPzStrPrinter._print_DMP  sD    kk""kk!))+&kk!%% "C--r-   c                    |j                   j                  }| j                  |j                        }| j                  |j                        }| j                  |j
                        }|d|d|d|dS rk   )rt   ru   r&   numdenr  )r'   r9   r:  r  r  r  s         r+   
_print_DMFzStrPrinter._print_DMF  sV    nn%%kk$((#kk$((#kk$((##&S#66r-   c                     d|j                   z  S )NzObject("%s")r   )r'   r   s     r+   _print_ObjectzStrPrinter._print_Object  s    ((r-   c                     d|j                   z  S )NzIdentityMorphism(%s))r  r'   morphisms     r+   _print_IdentityMorphismz"StrPrinter._print_IdentityMorphism  s    %77r-   c                V    d|j                   d|j                  d|j                  dS )NzNamedMorphism(rm   z, "z"))r  codomainr   r  s     r+   _print_NamedMorphismzStrPrinter._print_NamedMorphism  s#    !2!2HMMC 	Cr-   c                     d|j                   z  S )NzCategory("%s")r   )r'   categorys     r+   _print_CategoryzStrPrinter._print_Category  s    (--//r-   c                .    |j                   j                   S r/   r   )r'   manifolds     r+   _print_ManifoldzStrPrinter._print_Manifold  s    }}!!!r-   c                .    |j                   j                   S r/   r   )r'   patchs     r+   _print_PatchzStrPrinter._print_Patch  s    zzr-   c                .    |j                   j                   S r/   r   )r'   coordss     r+   _print_CoordSystemzStrPrinter._print_CoordSystem  s    {{r-   c                \    |j                   j                  |j                     j                  S r/   
_coord_sysr   _indexr   r  s     r+   _print_BaseScalarFieldz!StrPrinter._print_BaseScalarField  s#    ''5:::r-   c                b    d|j                   j                  |j                     j                  z  S )Nze_%sr  r  s     r+   _print_BaseVectorFieldz!StrPrinter._print_BaseVectorField  s(    ((00>CCCCr-   c                    |j                   }t        |d      r0d|j                  j                  |j                     j
                  z  S d| j                  |      z  S )Nr  zd%szd(%s))_form_fieldr   r  r   r  r   r&   )r'   diffr  s      r+   _print_DifferentialzStrPrinter._print_Differential  sQ      5,'5++33ELLAFFFFT[[///r-   c                J    dd| j                  |j                  d         dS )NTrrl   r   rn   r  r8   s     r+   	_print_TrzStrPrinter._print_Tr  s    TYYq\!:;;r-   c                8    | j                  |j                        S r/   r  rN  s     r+   
_print_StrzStrPrinter._print_Str  s    {{166""r-   c                    |j                   }| j                  |      d| j                  |j                        d| j                  |j                        dS rk   )ro   r&   r-  r]   )r'   r9   rels      r+   _print_AppliedBinaryRelationz'StrPrinter._print_AppliedBinaryRelation  sA    mm#{{3/#{{4884#{{48846 	6r-   )F)r   r/   )ru   
__module____qualname__r  r"   __annotations__r#   r,   r3   r:   rL   rP   rS   rW   rb   rf   ri   rq   rw   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  rN  rW  rY  r\  r^  rd  rh  rk  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r
  r  r  r"  r/  r2  r6  r<  rB  rI  rL  rO  rR  rT  _print_MatrixSymbol_print_RandomSymbolrV  rY  r[  r]  r_  ra  rc  rf  rh  rj  rn  rp  rr  ru  rw  ry  r{  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rO   r-   r+   r   r      s   K)~  $&L.%%K"*JEIJN?%
1[
)&9MMN
$D6&<HHYX
3&&FAtFl
"
@'+RC
&w:?
A
09'@;D/;Pz)J

..@@0J*0/1%,4
?''"7'DN 

/
.7)8C0" ;D0<#6r-   r   c                >    t        |      }|j                  |       }|S )ab  Returns the expression as a string.

    For large expressions where speed is a concern, use the setting
    order='none'. If abbrev=True setting is used then units are printed in
    abbreviated form.

    Examples
    ========

    >>> from sympy import symbols, Eq, sstr
    >>> a, b = symbols('a b')
    >>> sstr(Eq(a + b, 0))
    'Eq(a + b, 0)'
    )r   doprintr9   settingsrA  r   s       r+   sstrr    s     " 	8A			$AHr-   c                      e Zd ZdZd Zd Zy)StrReprPrinterz(internal) -- see sstrreprc                    t        |      S r/   )r7   rN  s     r+   r_  zStrReprPrinter._print_str  s    Awr-   c                l    |j                   j                  d| j                  |j                        dS )Nrl   rn   )rt   ru   r&   r   rN  s     r+   r  zStrReprPrinter._print_Str  s$    ;;//QVV1DEEr-   N)ru   r  r  __doc__r_  r  rO   r-   r+   r  r    s    $Fr-   r  c                >    t        |      }|j                  |       }|S )zreturn expr in mixed str/repr form

       i.e. strings are returned in repr form with quotes, and everything else
       is returned in str form.

       This function could be useful for hooking into sys.displayhook
    )r  r  r  s       r+   sstrreprr    s      	x A			$AHr-   N)#r  
__future__r   typingr   
sympy.corer   r   r   r   r	   r
   sympy.core.mulr   sympy.core.numbersr   sympy.core.relationalr   sympy.core.sortingr   sympy.utilities.iterablesr   r   r   printerr   r   mpmath.libmpr   r   r  r   r  r  r  rO   r-   r+   <module>r     s    #  ; ; & & , / * . , ;z6 z6z 
 ,FZ F   r-   