o
    GZhׁ                     @  s   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 deZeedd Z G dd deZ!ee!dd Z"dS )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                	   @  s  e Zd ZU dZdddddddddZded< i Zd	ed
< dddZdddZdd Z	dddZ
dd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Zd>d? Z d@dA Z!dBdC Z"dDdE Z#dFdG Z$dHdI Z%dJdK Z&dLdM Z'dNdO Z(dPdQ Z)dRdS Z*dTdU Z+dVdW Z,dXdY Z-dZd[ Z.d\d] Z/d^d_ Z0d`da Z1dbdc Z2ddde Z3dfdg Z4dhdi Z5djdk Z6dldm Z7dndo Z8dpdq Z9drds Z:dtdu Z;dvdw Z<dxdy Z=dzd{ Z>d|d} Z?d~d Z@dd ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdddZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd ZaddÄ Zbddń ZcddǄ ZdddɄ Zedd˄ Zfdd̈́ Zgddτ Zhddф Ziddӄ ZjejZkejZlddՄ Zmddׄ Znddل Zoddۄ Zpdd݄ Zqdd߄ Zrdd Zsdd Ztdd Zudd Zvdd Zwdd Zxdd Zydd Zzdd Z{dd Z|dd Z}dd Z~dd Zdd Zdd Zdd Zd d Zdd Zdd Zdd Zdd	 Zd
d Zdd Zdd Zdd Zdd Zdd ZdS (  
StrPrinterZ	_sympystrNautoFT)order	full_precsympy_integersabbrevperm_cyclicminmaxdpszdict[str, Any]_default_settingszdict[str, str]_relationalsc                 C  s4   t ||k s|st ||krd| | S | |S )N(%s))r   _print)selfitemlevelstrict r(   A/var/www/auris/lib/python3.10/site-packages/sympy/printing/str.pyparenthesize#   s   
zStrPrinter.parenthesizer   c                   s   |  fdd|D S )Nc                      g | ]} | qS r(   r*   .0r%   r&   r$   r(   r)   
<listcomp>*       z(StrPrinter.stringify.<locals>.<listcomp>)join)r$   argssepr&   r(   r/   r)   	stringify)      zStrPrinter.stringifyc                 C  s(   t |tr|S t |trt|S t|S N)
isinstancestrr   reprr$   exprr(   r(   r)   emptyPrinter,   s
   

zStrPrinter.emptyPrinterc           	      C  s   | j ||d}t|}g }|D ]4}| |}|dr'|js'd}|dd  }nd}t||k s2|jr<||d| g q|||g q|d}|dkrOd}|d| S )	Nr   -r   +r"   r     )Z_as_ordered_termsr   r#   
startswithis_Addextendpopr2   )	r$   r<   r   termsprecltermtsignr(   r(   r)   
_print_Add4   s    

zStrPrinter._print_Addc                 C     dS )NTruer(   r;   r(   r(   r)   _print_BooleanTrueI      zStrPrinter._print_BooleanTruec                 C  rN   )NFalser(   r;   r(   r(   r)   _print_BooleanFalseL   rQ   zStrPrinter._print_BooleanFalsec                 C  s   d|  |jd td  S )Nz~%sr   Not)r*   r3   r   r;   r(   r(   r)   
_print_NotO   r6   zStrPrinter._print_Notc                 C  sX   t |j}t|D ]\}}t|tr"|jjtju r"|	d|
| q	| |dtd S )Nr   z & Z
BitwiseAnd)listr3   	enumerater8   r   	canonicalrhsr   NegativeInfinityinsertrF   r5   r   )r$   r<   r3   jir(   r(   r)   
_print_AndR   s   

zStrPrinter._print_Andc                 C     |  |jdtd S )Nz | Z	BitwiseOrr5   r3   r   r;   r(   r(   r)   	_print_OrZ      zStrPrinter._print_Orc                 C  r_   )Nz ^ Z
BitwiseXorr`   r;   r(   r(   r)   
_print_Xor]   rb   zStrPrinter._print_Xorc                 C  s   d|  |j| |jdf S )N%s(%s), )r#   functionr5   	argumentsr;   r(   r(   r)   _print_AppliedPredicate`   s   z"StrPrinter._print_AppliedPredicatec                   s*    fdd|j D }|jjdd|  S )Nc                      g | ]}  |qS r(   r#   )r.   or$   r(   r)   r0   e       z+StrPrinter._print_Basic.<locals>.<listcomp>r"   re   )r3   	__class____name__r2   )r$   r<   rI   r(   rl   r)   _print_Basicd   s   zStrPrinter._print_Basicc                 C  s(   |j jdkr| |j d  | |j S )N)r   r   )r   r   )blocksshaper#   )r$   Br(   r(   r)   _print_BlockMatrixh   s   zStrPrinter._print_BlockMatrixc                 C  rN   )NZCatalanr(   r;   r(   r(   r)   _print_Catalanm   rQ   zStrPrinter._print_Catalanc                 C  rN   )NZzoor(   r;   r(   r(   r)   _print_ComplexInfinityp   rQ   z!StrPrinter._print_ComplexInfinityc                   sL   t  fdd|j|jfD }|jtju rd| S | |jf7 }d| S )Nc                   ri   r(   rj   r.   r]   rl   r(   r)   r0   t   rm   z2StrPrinter._print_ConditionSet.<locals>.<listcomp>zConditionSet(%s, %s)zConditionSet(%s, %s, %s))tuplesym	conditionZbase_setr   UniversalSetr#   )r$   sr3   r(   rl   r)   _print_ConditionSets   s
   zStrPrinter._print_ConditionSetc                   s8   |j }dd |jD }dd fdd|g| D  S )Nc                 S  s$   g | ]}|d  d kr|d n|qS )r   r   r(   rw   r(   r(   r)   r0   |   s   $ z0StrPrinter._print_Derivative.<locals>.<listcomp>zDerivative(%s)re   c                 3      | ]}  |V  qd S r7   rj   r.   argrl   r(   r)   	<genexpr>}       z/StrPrinter._print_Derivative.<locals>.<genexpr>)r<   Zvariable_countr2   )r$   r<   ZdexprZdvarsr(   rl   r)   _print_Derivativez   s   "zStrPrinter._print_Derivativec                 C  sR   t | td}g }|D ]}d| || || f }|| qdd| S )Nkeyz%s: %s{%s}re   )sortedkeysr   r#   appendr2   )r$   dr   itemsr   r%   r(   r(   r)   _print_dict   s   zStrPrinter._print_dictc                 C  
   |  |S r7   )r   r;   r(   r(   r)   _print_Dict      
zStrPrinter._print_Dictc                 C  sV   t |drd| |  S t |dr#d| |j d | |j S d| |j S )N
as_booleanzDomain: setz in z
Domain on )hasattrr#   r   symbolsr   )r$   r   r(   r(   r)   _print_RandomDomain   s   


zStrPrinter._print_RandomDomainc                 C  s
   d|j  S N_namer;   r(   r(   r)   _print_Dummy   r   zStrPrinter._print_Dummyc                 C  rN   )NZ
EulerGammar(   r;   r(   r(   r)   _print_EulerGamma   rQ   zStrPrinter._print_EulerGammac                 C  rN   )NEr(   r;   r(   r(   r)   _print_Exp1   rQ   zStrPrinter._print_Exp1c                 C     d|  |j|  |jf S )Nz(%s, %s))r#   r<   Zcondr;   r(   r(   r)   _print_ExprCondPair      zStrPrinter._print_ExprCondPairc                 C     |j jd| |jd  S Nr"   re   )funcro   r5   r3   r;   r(   r(   r)   _print_Function   r6   zStrPrinter._print_Functionc                 C  rN   )NZGoldenRatior(   r;   r(   r(   r)   _print_GoldenRatio   rQ   zStrPrinter._print_GoldenRatioc                 C  r   r   )r   ro   r5   Zpargsr;   r(   r(   r)   _print_Heaviside   s   zStrPrinter._print_Heavisidec                 C  rN   )NZTribonacciConstantr(   r;   r(   r(   r)   _print_TribonacciConstant   rQ   z$StrPrinter._print_TribonacciConstantc                 C  rN   NIr(   r;   r(   r(   r)   _print_ImaginaryUnit   rQ   zStrPrinter._print_ImaginaryUnitc                 C  rN   )NZoor(   r;   r(   r(   r)   _print_Infinity   rQ   zStrPrinter._print_Infinityc                   :   fdd d  fdd|jD }d|j|f S )Nc                   :   t | dkr | d S  | d ft| dd   S Nr   r   lenr#   rx   Zxabrl   r(   r)   
_xab_tostr       z.StrPrinter._print_Integral.<locals>._xab_tostrre   c                      g | ]} |qS r(   r(   r.   rI   r   r(   r)   r0          z.StrPrinter._print_Integral.<locals>.<listcomp>zIntegral(%s, %s)r2   Zlimitsr#   rf   r$   r<   Lr(   r   r$   r)   _print_Integral      zStrPrinter._print_Integralc                 C  s   d}|j \}}}}|jr|jrd}n%|jr|sd}n|jr"|s"d}n|s)|s)d}n|r0|r0d}n|r5d}nd}|jdi |||dS )NzInterval{m}({a}, {b})rA   z.openz.Lopenz.Ropen)abmr(   )r3   is_infiniteformat)r$   r]   Zfinr   r   rI   rr   r(   r(   r)   _print_Interval   s    

zStrPrinter._print_Intervalc                 C  r   )NzAccumBounds(%s, %s))r#   r   r   )r$   r]   r(   r(   r)   _print_AccumulationBounds   s   
z$StrPrinter._print_AccumulationBoundsc                 C     d|  |jtd  S )Nz%s**(-1)r   r*   r   r   )r$   r   r(   r(   r)   _print_Inverse      zStrPrinter._print_Inversec                 C  sB   |j }|j}t|dkr|d jr|d }d| || |f S )Nr   r   zLambda(%s, %s))r<   	signaturer   Z	is_symbolr#   )r$   objr<   sigr(   r(   r)   _print_Lambda   s
   zStrPrinter._print_Lambdac                   s2   t |jtd}|jjdd fdd|D   S )Nr   r"   re   c                 3  r~   r7   rj   r   rl   r(   r)   r      r   z.StrPrinter._print_LatticeOp.<locals>.<genexpr>)r   r3   r   r   ro   r2   r$   r<   r3   r(   rl   r)   _print_LatticeOp   s   $zStrPrinter._print_LatticeOpc                 C  s*   |j \}}}}dtt| j||||f S )NzLimit(%s, %s, %s, dir='%s'))r3   rx   mapr#   )r$   r<   ezZz0dirr(   r(   r)   _print_Limit   s   zStrPrinter._print_Limitc                 C  s   d|  |d S )N[%s]re   )r5   r;   r(   r(   r)   _print_list      zStrPrinter._print_listc                 C  r   r7   )r   r;   r(   r(   r)   _print_List   r   zStrPrinter._print_Listc                 C  s
   | | S r7   )Z_format_strr;   r(   r(   r)   _print_MatrixBase   r   zStrPrinter._print_MatrixBasec                 C  s2   | j |jtd ddd| |j| |jf  S )NAtomTr'   z[%s, %s])r*   parentr   r#   r]   r\   r;   r(   r(   r)   _print_MatrixElement   s   zStrPrinter._print_MatrixElementc                   sN    fdd} j |jtd ddd ||j|jj d ||j|jj d S )	Nc                   sZ   t | } | d dkr| d= | d dkrd| d< | d |kr!d| d< d fdd| D S )N   r   r   rA   :c                 3  r~   r7   rj   r   rl   r(   r)   r      r   zBStrPrinter._print_MatrixSlice.<locals>.strslice.<locals>.<genexpr>)rV   r2   )xdimrl   r(   r)   strslice   s   z/StrPrinter._print_MatrixSlice.<locals>.strslicer   Tr   [re   ])r*   r   r   ZrowslicerowsZcolslicecols)r$   r<   r   r(   rl   r)   _print_MatrixSlice   s   	zStrPrinter._print_MatrixSlicec                 C     |j S r7   r   r;   r(   r(   r)   _print_DeferredVector     z StrPrinter._print_DeferredVectorc                   s  t | |j}|d tju stdd |dd  D rt|dd dd\}}t|D ]0\}}|jjr7|j }nt	|jj}|d  |d< t
|}|d rUt|j|d	d
n|j||< q*g }	|rs|d jss|d  rs|dg}	|	 fdd|D  }
|
sdg}
t|dkr|d  r|dg}	ng }	|	 fdd|D  }d|
}d|}t|dkrd||f S |rd||f S |S | \}}|dk rt| |}d}nd}g }g }g }jdvr| }nt
|}dd }|D ]s}|jr?t|tr?t|j d dk r?|jtjur||| qt|jd jdkr8t|jt
tfr8|| ||j q|jrf|tjurf|j dkrW|t!|j  |j"dkre|t!|j" q|| q|prtjg} fdd|D } fdd|D }|D ]}|j|v rd||#|j  ||#|j< q|s|d| S t|dkr|d| d |d  S |d| dd|  S )Nr   c                 s  s4    | ]}t |tp|jotd d |jD V  qdS )c                 s  s    | ]}|j V  qd S r7   )Z
is_Integer)r.   Zair(   r(   r)   r     s    z2StrPrinter._print_Mul.<locals>.<genexpr>.<genexpr>N)r8   r	   Zis_Powallr3   r.   r   r(   r(   r)   r     s    

z(StrPrinter._print_Mul.<locals>.<genexpr>r   c                 S  s    t | tot| j d dk S Nr   )r8   r   boolexpas_coeff_Mul)r   r(   r(   r)   <lambda>  s    z'StrPrinter._print_Mul.<locals>.<lambda>T)binaryFevaluatec                      g | ]
}j | d dqS Fr   r,   r   rH   r$   r(   r)   r0   $      z)StrPrinter._print_Mul.<locals>.<listcomp>1c                   r   r   r,   r   r   r(   r)   r0   .  r   *z%s/(%s)%s/%sr?   rA   )oldnonec                 S  sv   |   \}}tt|}|d tju r|dd  }n|d  |d< t|}t| tr4| j	||ddS | j	|ddS )Nr   r   Fr   )
Zas_base_exprV   r   	make_argsr   NegativeOne
_from_argsr8   r   r   )r]   r   r   Zeargsr(   r(   r)   apowL  s   

z#StrPrinter._print_Mul.<locals>.apowc                   r   r   r,   r.   r   r   r(   r)   r0   m      c                   r   r   r,   r  r   r(   r)   r0   n  r  r"   /z/(%s))$r   r3   r   Oneanyr   rW   r   Z	is_NumberrV   r   r   r   baserD   Zcould_extract_minus_signr#   rF   r   r2   r   r
   r   Zas_ordered_factorsr   is_commutativer8   r   r   r   is_RationalInfinitypr   qindex)r$   r<   r3   r   nr]   Zdir   dargspreZnfactorsZdfactorscrL   r   r   Z	pow_parenr   r%   Za_strZb_strr(   r   r)   
_print_Mul  s   




$





 zStrPrinter._print_Mulc                   s|      \}}d}|jr.| \}}|jr |jr t| | d}n|jr.|jr.t| | d}|d fdd jD  S )NrA   r?   r   c                      g | ]
} |t qS r(   r*   r   r   r<   r$   r(   r)   r0     r  z,StrPrinter._print_MatMul.<locals>.<listcomp>)Zas_coeff_mmulZ	is_numberZas_real_imagis_zeroZis_negativer
   r2   r3   )r$   r<   r  r   rL   reZimr(   r  r)   _print_MatMul|  s   zStrPrinter._print_MatMulc                 C  s   d |j| |jS )Nz{}.({}))r   rf   r#   r<   r;   r(   r(   r)   _print_ElementwiseApplyFunction  s   
z*StrPrinter._print_ElementwiseApplyFunctionc                 C  rN   )Nnanr(   r;   r(   r(   r)   
_print_NaN  rQ   zStrPrinter._print_NaNc                 C  rN   )Nz-oor(   r;   r(   r(   r)   _print_NegativeInfinity  rQ   z"StrPrinter._print_NegativeInfinityc                 C  sh   |j rtdd |jD r*t|j dkrd| |j S d| |jf|j  dd S d| |jdd S )Nc                 s  s    | ]}|t ju V  qd S r7   )r   ZZero)r.   r
  r(   r(   r)   r     r   z*StrPrinter._print_Order.<locals>.<genexpr>r   zO(%s)re   r   )	variablesr   pointr   r#   r<   r5   r3   r;   r(   r(   r)   _print_Order  s
   zStrPrinter._print_Orderc                 C     |  S r7   __str__r;   r(   r(   r)   _print_Ordinal     zStrPrinter._print_Ordinalc                 C  r  r7   r   r;   r(   r(   r)   _print_Cycle  r#  zStrPrinter._print_Cyclec                 C  sZ  ddl m}m} ddlm} |j}|d ur"|d| ddddd	 n| jd
d}|rf|js0dS |||jd 	 t
dd  }|d}|dks^d||d  vr^||d  |d |  }|dd}|S | }|s|jdk ryd| |j S d| |j S | |jd |d d  d| |j  }| |j }	}
t
|t
|
k r|}	d|	 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   )Zdeprecated_since_versionZactive_deprecations_target
stacklevelr   Tz()r   r&  (,rA      zPermutation(%s)zPermutation([], size=%s)z	, size=%s)Z sympy.combinatorics.permutationsr%  r&  Zsympy.utilities.exceptionsr'  Zprint_cyclic	_settingsgetsize__repr__r   rfindreplaceZsupportr#   Z
array_form)r$   r<   r%  r&  r'  r   r|   lastZtrimZusefullr(   r(   r)   _print_Permutation  s@   
"

,zStrPrinter._print_Permutationc                 C  sJ   |j \}}}t|jdkr|d }|d }d| || || |f S )Nr   r   zSubs(%s, %s, %s))r3   r   r  r#   )r$   r   r<   r   newr(   r(   r)   _print_Subs  s   zStrPrinter._print_Subsc                 C  r  r7   rj   r;   r(   r(   r)   _print_TensorIndex  r#  zStrPrinter._print_TensorIndexc                 C  r  r7   rj   r;   r(   r(   r)   _print_TensorHead  r#  zStrPrinter._print_TensorHeadc                 C  r  r7   rj   r;   r(   r(   r)   _print_Tensor  r#  zStrPrinter._print_Tensorc                   s*      \}}|d fdd|D  S )Nr   c                   r  r(   r  r   r  r(   r)   r0     r  z-StrPrinter._print_TensMul.<locals>.<listcomp>)Z!_get_args_for_traditional_printerr2   )r$   r<   rL   r3   r(   r  r)   _print_TensMul  s   zStrPrinter._print_TensMulc                 C  r  r7   rj   r;   r(   r(   r)   _print_TensAdd  r#  zStrPrinter._print_TensAddc                 C     |  |jS r7   r#   r   r;   r(   r(   r)   _print_ArraySymbol     zStrPrinter._print_ArraySymbolc                   s2   d  |jtd dd fdd|jD f S )Nz%s[%s]ZFuncTre   c                   ri   r(   rj   rw   rl   r(   r)   r0     rm   z2StrPrinter._print_ArrayElement.<locals>.<listcomp>)r*   r   r   r2   indicesr;   r(   rl   r)   _print_ArrayElement  s   *zStrPrinter._print_ArrayElementc                   s"    fdd|j D }dd| S )Nc                   s   g | ]	}d   | qS )z    %srj   r   rl   r(   r)   r0     s    z6StrPrinter._print_PermutationGroup.<locals>.<listcomp>zPermutationGroup([
%s])z,
)r3   r2   )r$   r<   r
  r(   rl   r)   _print_PermutationGroup  s   z"StrPrinter._print_PermutationGroupc                 C  rN   )Npir(   r;   r(   r(   r)   	_print_Pi  rQ   zStrPrinter._print_Pic                   4   dd  fdd|jD  |j |jf S )Nz+Polynomial ring in %s over %s with %s orderre   c                 3  r~   r7   rj   )r.   rsrl   r(   r)   r     r   z-StrPrinter._print_PolyRing.<locals>.<genexpr>r2   r   r#   domainr   )r$   ringr(   rl   r)   _print_PolyRing  
   zStrPrinter._print_PolyRingc                   rG  )Nz3Rational function field in %s over %s with %s orderre   c                 3  r~   r7   rj   )r.   fsrl   r(   r)   r     r   z.StrPrinter._print_FracField.<locals>.<genexpr>rI  r$   fieldr(   rl   r)   _print_FracField  rM  zStrPrinter._print_FracFieldc                 C  r  r7   r   )r$   elmr(   r(   r)   _print_FreeGroupElement  r#  z"StrPrinter._print_FreeGroupElementc                 C  s   d|j |jf S )Nz(%s + %s*I))r   yr$   Zpolyr(   r(   r)   _print_GaussianElement  r   z!StrPrinter._print_GaussianElementc                 C  s   | | tddS )N%s**%sr   )r9   r   rU  r(   r(   r)   _print_PolyElement
  r   zStrPrinter._print_PolyElementc                 C  sN   |j dkr| |jS | j|jtd dd}| j|j td dd}|d | S )Nr   r   Tr   r   r  )denomr#   numerr*   r   )r$   fracrZ  rY  r(   r(   r)   _print_FracElement  s
   
zStrPrinter._print_FracElementc                   sD  t d d  g  fdd|jD }}| D ]\}}g }t|D ]\}}|dkrA|dkr6|||  q"||| d|   q"d|}|jr\|rVd| d	 }	n'|}	n!|rx|tj	u rk|
d
|g q|tju rx|
d|g q|}	|s|	}
n|	d | }
|
dr|
d|
dd  g q|
d
|
g q|d dv r|d}|dkrd|d  |d< |jjd }ddlm} z
|d|  7 }W n |y   |d|  7 }Y nw |d	7 }t|D ]-\}}t|dkr|d d dkr|t|d d  d	kr|dt|d  ||< q|d|d|f S )Nr   r   c                   r+   r(   r,   )r.   r|   Z	ATOM_PRECr$   r(   r)   r0     r1   z*StrPrinter._print_Poly.<locals>.<listcomp>r   z**%dr   r*  )r@   r?   )r?   r@   z(%s, %s)PolynomialErrorz, modulus=%sz, domain='%s'r   rB   re   )r   gensrG   rW   r   r2   rD   r#   r   r  rE   r   rC   rF   rn   ro   Zsympy.polys.polyerrorsr_  Zget_modulusZ
get_domainr   )r$   r<   rG   r`  ZmonomZcoeffZs_monomr]   r   Zs_coeffZs_termmodifierr   r_  r  r%   r(   r]  r)   _print_Poly  s\   





:zStrPrinter._print_Polyc                 C  rN   )Nr{   r(   )r$   r
  r(   r(   r)   _print_UniversalSetW  rQ   zStrPrinter._print_UniversalSetc                 C  s&   |j r| |  S | | S r7   )Z
is_aliasedr#   Zas_polyZas_exprr;   r(   r(   r)   _print_AlgebraicNumberZ  s   z!StrPrinter._print_AlgebraicNumberc                   s  t |}|jtju r|sd |j S |jrI|j tju r1|s1dt fddtj|jfD  S |jtj u rId tj j	|j|ddf S  j	|j|dd} j
dkrw|jjrw|jjd	krw|d
rwd j	|j|dd|d	d f S d j	|j|dd|f 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  r~   r7   rj   r   rl   r(   r)   r     r   z(StrPrinter._print_Pow.<locals>.<genexpr>r   Fr   Z
_sympyreprr   z	(RationalrW  r-  )r   r   r   ZHalfr#   r  r  rx   r  r*   printmethodr  r  rC   )r$   r<   ZrationalPRECr   r(   rl   r)   
_print_Pow`  s   &"
"zStrPrinter._print_Powc                 C  s   |  |jd S r   r#   r3   r;   r(   r(   r)   _print_UnevaluatedExpr  r   z!StrPrinter._print_UnevaluatedExprc                 C  s0   t |}d| j|j|dd| j|j|ddf S )NrW  Fr   )r   r*   r  r   )r$   r<   rf  r(   r(   r)   _print_MatPow  s   zStrPrinter._print_MatPowc                 C  s    | j ddrd| S t|jS )Nr   FzS(%s))r.  r/  r9   r
  r;   r(   r(   r)   _print_Integer  s   
zStrPrinter._print_Integerc                 C  rN   )NZIntegersr(   r;   r(   r(   r)   _print_Integers  rQ   zStrPrinter._print_Integersc                 C  rN   )NZNaturalsr(   r;   r(   r(   r)   _print_Naturals  rQ   zStrPrinter._print_Naturalsc                 C  rN   )NZ	Naturals0r(   r;   r(   r(   r)   _print_Naturals0  rQ   zStrPrinter._print_Naturals0c                 C  rN   )NZ	Rationalsr(   r;   r(   r(   r)   _print_Rationals  rQ   zStrPrinter._print_Rationalsc                 C  rN   )NZRealsr(   r;   r(   r(   r)   _print_Reals  rQ   zStrPrinter._print_Realsc                 C  rN   )NZ	Complexesr(   r;   r(   r(   r)   _print_Complexes  rQ   zStrPrinter._print_Complexesc                 C  rN   )NZEmptySetr(   r;   r(   r(   r)   _print_EmptySet  rQ   zStrPrinter._print_EmptySetc                 C  rN   )NZEmptySequencer(   r;   r(   r(   r)   _print_EmptySequence  rQ   zStrPrinter._print_EmptySequencec                 C     t |S r7   r9   r;   r(   r(   r)   
_print_int  r#  zStrPrinter._print_intc                 C  rt  r7   ru  r;   r(   r(   r)   
_print_mpz  r#  zStrPrinter._print_mpzc                 C  sB   |j dkr
t|jS | jddrd|j|j f S d|j|j f S )Nr   r   FzS(%s)/%sr   )r  r9   r
  r.  r/  r;   r(   r(   r)   _print_Rational  s
   

zStrPrinter._print_Rationalc                 C  $   |j dkr
t|jS d|j|j f S )Nr   z%d/%d)r  r9   r
  r;   r(   r(   r)   _print_PythonRational     

z StrPrinter._print_PythonRationalc                 C  ry  Nr   r   denominatorr9   	numeratorr;   r(   r(   r)   _print_Fraction  r{  zStrPrinter._print_Fractionc                 C  ry  r|  r}  r;   r(   r(   r)   
_print_mpq  r{  zStrPrinter._print_mpqc                 C  s   |j }| jdd }|d u r|dk rdnt|j }| jd du r#d}n| jd du r-d}n| jd dkr9| jdk}d	| jv rC| jd	 nd }d
| jv rO| jd
 nd }t|j||||d}|drid|dd   }n|drvd|dd   }|d}|S )Nr   r,  r   r   TFr   r   r   r   )Zstrip_zerosZ	min_fixedZ	max_fixedz-.0z-0.   z.0z0.r   r@   )	Z_precr.  r/  r   Z_print_levelmlib_to_strZ_mpf_rC   removeprefix)r$   r<   rH   r   striplowhighrvr(   r(   r)   _print_Float  s&   



zStrPrinter._print_Floatc              	   C  s~   ddddddddd	}|j |v r"d
||j  | |j| |jf S d| |jt|| j|j p4|j | |jt|f S )NEqZNeZ
AssignmentZAddAugmentedAssignmentZSubAugmentedAssignmentZMulAugmentedAssignmentZDivAugmentedAssignmentZModAugmentedAssignment)z==z!=z:=z+=z-=z*=z/=z%=
%s(%s, %s)z%s %s %s)Zrel_opr#   lhsrY   r*   r   r!   r/  )r$   r<   charmapr(   r(   r)   _print_Relational  s"   

zStrPrinter._print_Relationalc                 C  s   d| j |jdd|jf S )NzCRootOf(%s, %d)lexr>   )rM   r<   r  r;   r(   r(   r)   _print_ComplexRootOf  s   zStrPrinter._print_ComplexRootOfc                 C  s>   | j |jddg}|jtjur|| |j dd| S )Nr  r>   zRootSum(%s)re   )rM   r<   Zfunr   ZIdentityFunctionr   r#   r2   r   r(   r(   r)   _print_RootSum  s   zStrPrinter._print_RootSumc                   s    j j} fdd jD }dd| }fdd jD }d j }d j }|g| ||g }d|d|f S )	Nc                   s   g | ]
}j | jd qS )r>   )rM   r   r   basisr$   r(   r)   r0     r  z3StrPrinter._print_GroebnerBasis.<locals>.<listcomp>r   re   c                   ri   r(   rj   )r.   genrl   r(   r)   r0     rm   zdomain='%s'z
order='%s'rd   )rn   ro   exprsr2   r`  r#   rJ  r   )r$   r  clsr  r`  rJ  r   r3   r(   r  r)   _print_GroebnerBasis  s   zStrPrinter._print_GroebnerBasisc                   s4   t |td}d fdd|D }|sdS d| S )Nr   re   c                 3  r~   r7   rj   r-   rl   r(   r)   r   )  r   z(StrPrinter._print_set.<locals>.<genexpr>zset()r   )r   r   r2   r$   r|   r   r3   r(   rl   r)   
_print_set&  s
   zStrPrinter._print_setc                   sZ   ddl m  t|td}dfdd|D }t fdd|D r(d|S d	|S )
Nr   	FiniteSetr   re   c                 3  r~   r7   rj   r-   rl   r(   r)   r   2  r   z.StrPrinter._print_FiniteSet.<locals>.<genexpr>c                 3  s    | ]}|  V  qd S r7   )hasr-   r  r(   r)   r   3  r   zFiniteSet({})z{{{}}})Zsympy.sets.setsr  r   r   r2   r  r   r  r(   )r  r$   r)   _print_FiniteSet.  s   

zStrPrinter._print_FiniteSetc                   s.   t |td}d fdd|D }d|S )Nr   re   c                 3  r~   r7   rj   r   rl   r(   r)   r   :  r   z.StrPrinter._print_Partition.<locals>.<genexpr>zPartition({}))r   r   r2   r   r  r(   rl   r)   _print_Partition7  s   
zStrPrinter._print_Partitionc                 C  s   |sdS d|  | S )Nzfrozenset()zfrozenset(%s))r  r$   r|   r(   r(   r)   _print_frozenset=  s   zStrPrinter._print_frozensetc                   r   )Nc                   r   r   r   r   rl   r(   r)   r   C  r   z)StrPrinter._print_Sum.<locals>._xab_tostrre   c                   r   r(   r(   r   r   r(   r)   r0   H  r   z)StrPrinter._print_Sum.<locals>.<listcomp>zSum(%s, %s)r   r   r(   r   r)   
_print_SumB  r   zStrPrinter._print_Sumc                 C  r   r7   r   r;   r(   r(   r)   _print_SymbolK  r   zStrPrinter._print_Symbolc                 C  rN   r   r(   r;   r(   r(   r)   _print_IdentityP  rQ   zStrPrinter._print_Identityc                 C  rN   )N0r(   r;   r(   r(   r)   _print_ZeroMatrixS  rQ   zStrPrinter._print_ZeroMatrixc                 C  rN   )Nr   r(   r;   r(   r(   r)   _print_OneMatrixV  rQ   zStrPrinter._print_OneMatrixc                 C  
   d|j  S )NzQ.%sr   r;   r(   r(   r)   _print_PredicateY  r   zStrPrinter._print_Predicatec                 C  rt  r7   ru  r;   r(   r(   r)   
_print_str\  r#  zStrPrinter._print_strc                 C  s.   t |dkrd| |d  S d| |d S )Nr   z(%s,)r   r"   re   )r   r#   r5   r;   r(   r(   r)   _print_tuple_  s   zStrPrinter._print_tuplec                 C  r   r7   )r  r;   r(   r(   r)   _print_Tuplee  r   zStrPrinter._print_Tuplec                 C  r   )Nz%s.Tr   r   )r$   Tr(   r(   r)   _print_Transposeh  r   zStrPrinter._print_Transposec                 C  r   )NzUniform(%s, %s))r#   r   r   r;   r(   r(   r)   _print_Uniformk  r   zStrPrinter._print_Uniformc                 C  s"   | j ddrd|j S d|j S )Nr   Fz%s)r.  r/  r   r   r;   r(   r(   r)   _print_Quantityn  s   

zStrPrinter._print_Quantityc                   sD    fdd|j D }|d gdd t|dd  dD  }d|S )Nc                   s    g | ]} j |td  ddqS )r   Tr   )r*   r   rw   rl   r(   r)   r0   t  s     z0StrPrinter._print_Quaternion.<locals>.<listcomp>r   c                 S  s   g | ]
\}}|d  | qS )r   r(   )r.   r]   r\   r(   r(   r)   r0   u  r  r   Zijkz + )r3   zipr2   )r$   r<   r|   r   r(   rl   r)   _print_Quaternions  s   &
zStrPrinter._print_Quaternionc                 C  rt  r7   ru  r;   r(   r(   r)   _print_Dimensionx  r#  zStrPrinter._print_Dimensionc                 C  
   |j d S r   r   r;   r(   r(   r)   _print_Wild{  r   zStrPrinter._print_Wildc                 C  r  r   r   r;   r(   r(   r)   _print_WildFunction~  r   zStrPrinter._print_WildFunctionc                 C  r   r7   r   r;   r(   r(   r)   _print_WildDot  r   zStrPrinter._print_WildDotc                 C  r   r7   r   r;   r(   r(   r)   _print_WildPlus  r   zStrPrinter._print_WildPlusc                 C  r   r7   r   r;   r(   r(   r)   _print_WildStar  r   zStrPrinter._print_WildStarc                 C  s    | j ddr	dS | tdS )Nr   FzS(0)r   )r.  r/  rk  r   r;   r(   r(   r)   _print_Zero  s   zStrPrinter._print_Zeroc                 C  s0   |j j}| | }| |j}d|||f S Nr  )rn   ro   r#   Zto_listdom)r$   r
  r  repr  r(   r(   r)   
_print_DMP  s   zStrPrinter._print_DMPc                 C  s<   |j j}| |j}| |j}| |j}d||||f S )Nz%s(%s, %s, %s))rn   ro   r#   numdenr  )r$   r<   r  r  r  r  r(   r(   r)   
_print_DMF  s
   zStrPrinter._print_DMFc                 C  r  )NzObject("%s")r   )r$   r   r(   r(   r)   _print_Object  r   zStrPrinter._print_Objectc                 C  r  )NzIdentityMorphism(%s))rJ  r$   Zmorphismr(   r(   r)   _print_IdentityMorphism  r   z"StrPrinter._print_IdentityMorphismc                 C  s   d|j |j|jf S )NzNamedMorphism(%s, %s, "%s"))rJ  Zcodomainr   r  r(   r(   r)   _print_NamedMorphism  s   zStrPrinter._print_NamedMorphismc                 C  r  )NzCategory("%s")r   )r$   categoryr(   r(   r)   _print_Category  r   zStrPrinter._print_Categoryc                 C     |j j S r7   r   )r$   Zmanifoldr(   r(   r)   _print_Manifold  r#  zStrPrinter._print_Manifoldc                 C  r  r7   r   )r$   patchr(   r(   r)   _print_Patch  r#  zStrPrinter._print_Patchc                 C  r  r7   r   )r$   Zcoordsr(   r(   r)   _print_CoordSystem  r#  zStrPrinter._print_CoordSystemc                 C  s   |j j|j jS r7   
_coord_sysr   _indexr   rO  r(   r(   r)   _print_BaseScalarField  r   z!StrPrinter._print_BaseScalarFieldc                 C  s   d|j j|j j S )Nze_%sr  rO  r(   r(   r)   _print_BaseVectorField  rb   z!StrPrinter._print_BaseVectorFieldc                 C  s2   |j }t|drd|jj|j j S d| | S )Nr  zd%szd(%s))Z_form_fieldr   r  r   r  r   r#   )r$   diffrP  r(   r(   r)   _print_Differential  s   
zStrPrinter._print_Differentialc                 C  s   dd|  |jd f S )Nrd   ZTrr   rh  r;   r(   r(   r)   	_print_Tr     zStrPrinter._print_Trc                 C  r>  r7   r?  r  r(   r(   r)   
_print_Str  rA  zStrPrinter._print_Strc                 C  s*   |j }d| || |j| |jf S r  )rf   r#   r  rY   )r$   r<   relr(   r(   r)   _print_AppliedBinaryRelation  s
   


z'StrPrinter._print_AppliedBinaryRelation)F)r   r7   )ro   
__module____qualname__re  r    __annotations__r!   r*   r5   r=   rM   rP   rS   rU   r^   ra   rc   rh   rp   rt   ru   rv   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$  r6  r8  r9  r:  r;  r<  r=  r@  rC  rD  rF  rL  rQ  rS  rV  rX  r\  rb  rc  rd  rg  ri  rj  rk  rl  rm  rn  ro  rp  rq  rr  rs  rv  rw  rx  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  Z_print_MatrixSymbolZ_print_RandomSymbolr  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      s&  
 
		v	)B=		r   c                 K     t |}|| }|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r<   settingsr
  r|   r(   r(   r)   sstr  s   
r  c                   @  s    e Zd ZdZdd Zdd ZdS )StrReprPrinterz(internal) -- see sstrreprc                 C  rt  r7   )r:   r  r(   r(   r)   r    r#  zStrReprPrinter._print_strc                 C  s   d|j j| |jf S )Nrd   )rn   ro   r#   r   r  r(   r(   r)   r    r  zStrReprPrinter._print_StrN)ro   r  r  __doc__r  r  r(   r(   r(   r)   r    s    r  c                 K  r  )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  r(   r(   r)   sstrrepr  s   

r  N)#r  
__future__r   typingr   Z
sympy.corer   r   r   r   r   r	   Zsympy.core.mulr
   Zsympy.core.numbersr   Zsympy.core.relationalr   Zsympy.core.sortingr   Zsympy.utilities.iterablesr   r   r   printerr   r   Zmpmath.libmpr   r   r  r   r  r  r  r(   r(   r(   r)   <module>   s2            B

