U
    ;qLe                     @  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)
Relational)default_sort_key)SympifyError)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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 (  
StrPrinter	_sympystrNautoFT)order	full_precsympy_integersabbrevperm_cyclicminmaxzdict[str, Any]_default_settingszdict[str, str]_relationalsc                 C  s8   t ||k s|s*t ||kr*d| | S | |S d S )N(%s))r   _print)selfitemlevelstrict r(   i/home/p21-0144/sympy/latex2sympy2solve-back-end/sympyEq/lib/python3.8/site-packages/sympy/printing/str.pyparenthesize"   s    zStrPrinter.parenthesizer   c                   s   |  fdd|D S )Nc                   s   g | ]} | qS r(   r*   .0r%   r&   r$   r(   r)   
<listcomp>)   s     z(StrPrinter.stringify.<locals>.<listcomp>)join)r$   argssepr&   r(   r.   r)   	stringify(   s    zStrPrinter.stringifyc                 C  s,   t |tr|S t |tr t|S t|S d S N)
isinstancestrr   reprr$   exprr(   r(   r)   emptyPrinter+   s
    

zStrPrinter.emptyPrinterc           	      C  s   | j ||d}t|}g }|D ]h}| |}|drN|jsNd}|dd  }nd}t||k sd|jrx||d| g q|||g q|d}|dkrd}|d| S )	Nr   -r   +r"   r     )_as_ordered_termsr   r#   
startswithis_Addextendpopr0   )	r$   r9   r   termsprecltermtsignr(   r(   r)   
_print_Add3   s     

zStrPrinter._print_Addc                 C  s   dS )NTruer(   r8   r(   r(   r)   _print_BooleanTrueH   s    zStrPrinter._print_BooleanTruec                 C  s   dS )NFalser(   r8   r(   r(   r)   _print_BooleanFalseK   s    zStrPrinter._print_BooleanFalsec                 C  s   d|  |jd td  S )Nz~%sr   Not)r*   r1   r   r8   r(   r(   r)   
_print_NotN   s    zStrPrinter._print_Notc                 C  sX   t |j}t|D ]2\}}t|tr|jjtjkr|	d|
| q| |dtd S )Nr   z & 
BitwiseAnd)listr1   	enumerater5   r   	canonicalrhsr   NegativeInfinityinsertrD   r3   r   )r$   r9   r1   jir(   r(   r)   
_print_AndQ   s    

zStrPrinter._print_Andc                 C  s   |  |jdtd S )Nz | 	BitwiseOrr3   r1   r   r8   r(   r(   r)   	_print_OrY   s    zStrPrinter._print_Orc                 C  s   |  |jdtd S )Nz ^ 
BitwiseXorr]   r8   r(   r(   r)   
_print_Xor\   s    zStrPrinter._print_Xorc                 C  s   d|  |j| |jdf S )N%s(%s), )r#   functionr3   	argumentsr8   r(   r(   r)   _print_AppliedPredicate_   s    
 z"StrPrinter._print_AppliedPredicatec                   s*    fdd|j D }|jjdd|  S )Nc                   s   g | ]}  |qS r(   r#   )r-   or$   r(   r)   r/   d   s     z+StrPrinter._print_Basic.<locals>.<listcomp>r"   rb   )r1   	__class____name__r0   )r$   r9   rG   r(   rh   r)   _print_Basicc   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_BlockMatrixg   s    zStrPrinter._print_BlockMatrixc                 C  s   dS )NCatalanr(   r8   r(   r(   r)   _print_Catalanl   s    zStrPrinter._print_Catalanc                 C  s   dS )Nzoor(   r8   r(   r(   r)   _print_ComplexInfinityo   s    z!StrPrinter._print_ComplexInfinityc                   sL   t  fdd|j|jfD }|jtjkr2d| S | |jf7 }d| S )Nc                   s   g | ]}  |qS r(   rf   r-   rZ   rh   r(   r)   r/   s   s     z2StrPrinter._print_ConditionSet.<locals>.<listcomp>zConditionSet(%s, %s)zConditionSet(%s, %s, %s))tuplesym	conditionbase_setr   UniversalSetr#   )r$   sr1   r(   rh   r)   _print_ConditionSetr   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(   rt   r(   r(   r)   r/   {   s     z0StrPrinter._print_Derivative.<locals>.<listcomp>zDerivative(%s)rb   c                 3  s   | ]}  |V  qd S r4   rf   r-   argrh   r(   r)   	<genexpr>|   s     z/StrPrinter._print_Derivative.<locals>.<genexpr>)r9   variable_countr0   )r$   r9   ZdexprZdvarsr(   rh   r)   _print_Derivativey   s    zStrPrinter._print_Derivativec                 C  sR   t | td}g }|D ]*}d| || || f }|| qdd| S )Nkeyz%s: %s{%s}rb   )sortedkeysr   r#   appendr0   )r$   dr   itemsr   r%   r(   r(   r)   _print_dict~   s    zStrPrinter._print_dictc                 C  s
   |  |S r4   )r   r8   r(   r(   r)   _print_Dict   s    zStrPrinter._print_Dictc                 C  sZ   t |drd| |  S t |drFd| |j d | |j S d| |j S d 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_namer8   r(   r(   r)   _print_Dummy   s    zStrPrinter._print_Dummyc                 C  s   dS )N
EulerGammar(   r8   r(   r(   r)   _print_EulerGamma   s    zStrPrinter._print_EulerGammac                 C  s   dS )NEr(   r8   r(   r(   r)   _print_Exp1   s    zStrPrinter._print_Exp1c                 C  s   d|  |j|  |jf S )Nz(%s, %s))r#   r9   condr8   r(   r(   r)   _print_ExprCondPair   s    zStrPrinter._print_ExprCondPairc                 C  s   |j jd| |jd  S Nr"   rb   )funcrj   r3   r1   r8   r(   r(   r)   _print_Function   s    zStrPrinter._print_Functionc                 C  s   dS )NGoldenRatior(   r8   r(   r(   r)   _print_GoldenRatio   s    zStrPrinter._print_GoldenRatioc                 C  s   |j jd| |jd  S r   )r   rj   r3   pargsr8   r(   r(   r)   _print_Heaviside   s    zStrPrinter._print_Heavisidec                 C  s   dS )NTribonacciConstantr(   r8   r(   r(   r)   _print_TribonacciConstant   s    z$StrPrinter._print_TribonacciConstantc                 C  s   dS NIr(   r8   r(   r(   r)   _print_ImaginaryUnit   s    zStrPrinter._print_ImaginaryUnitc                 C  s   dS )Noor(   r8   r(   r(   r)   _print_Infinity   s    zStrPrinter._print_Infinityc                   s:   fdd d  fdd|jD }d|j|f S )Nc                   s>   t | dkr | d S  | d ft| dd   S d S Nr   r   lenr#   ru   xabrh   r(   r)   
_xab_tostr   s    z.StrPrinter._print_Integral.<locals>._xab_tostrrb   c                   s   g | ]} |qS r(   r(   r-   rG   r   r(   r)   r/      s     z.StrPrinter._print_Integral.<locals>.<listcomp>zIntegral(%s, %s)r0   limitsr#   rc   r$   r9   Lr(   r   r$   r)   _print_Integral   s    zStrPrinter._print_Integralc                 C  s   d}|j \}}}}|jr$|jr$d}nJ|jr4|s4d}n:|jrD|sDd}n*|sR|sRd}n|r`|r`d}n|rjd}nd}|jf |||dS )NzInterval{m}({a}, {b})r>   z.openz.Lopenz.Ropen)abm)r1   is_infiniteformat)r$   rZ   Zfinr   r   rG   rr   r(   r(   r)   _print_Interval   s     

zStrPrinter._print_Intervalc                 C  s   d|  |j|  |jf S )NzAccumBounds(%s, %s))r#   r   r   )r$   rZ   r(   r(   r)   _print_AccumulationBounds   s    
z$StrPrinter._print_AccumulationBoundsc                 C  s   d|  |jtd  S )Nz%s**(-1)r   r*   r}   r   )r$   r   r(   r(   r)   _print_Inverse   s    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))r9   	signaturer   	is_symbolr#   )r$   objr9   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"   rb   c                 3  s   | ]}  |V  qd S r4   rf   r|   rh   r(   r)   r~      s     z.StrPrinter._print_LatticeOp.<locals>.<genexpr>)r   r1   r   r   rj   r0   r$   r9   r1   r(   rh   r)   _print_LatticeOp   s    zStrPrinter._print_LatticeOpc                 C  s*   |j \}}}}dtt| j||||f S )NzLimit(%s, %s, %s, dir='%s'))r1   ru   mapr#   )r$   r9   ezz0dirr(   r(   r)   _print_Limit   s    zStrPrinter._print_Limitc                 C  s   d|  |d S )N[%s]rb   )r3   r8   r(   r(   r)   _print_list   s    zStrPrinter._print_listc                 C  s
   |  |S r4   )r   r8   r(   r(   r)   _print_List   s    zStrPrinter._print_Listc                 C  s
   | | S r4   )Z_format_strr8   r(   r(   r)   _print_MatrixBase   s    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#   rZ   rY   r8   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rBd| d< d fdd| D S )N   r   r   r>   :c                 3  s   | ]}  |V  qd S r4   rf   r|   rh   r(   r)   r~      s     zBStrPrinter._print_MatrixSlice.<locals>.strslice.<locals>.<genexpr>)rS   r0   )xdimrh   r(   r)   strslice   s    z/StrPrinter._print_MatrixSlice.<locals>.strslicer   Tr   [rb   ])r*   r   r   rowslicerowscolslicecols)r$   r9   r   r(   rh   r)   _print_MatrixSlice   s    	zStrPrinter._print_MatrixSlicec                 C  s   |j S r4   r   r8   r(   r(   r)   _print_DeferredVector  s    z StrPrinter._print_DeferredVectorc                   s  t | |j}|d tjks8tdd |dd  D rt|dd dd\}}t|D ]`\}}|jjrp|j }n$t	|jj}|d  |d< t
|}|d rt|j|d	d
n|j||< qVg }	|r|d js|d  r|dg}	|	 fdd|D  }
|
sd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kr| }n
t
|}dd }|D ]}|jrt|trt|j d dk r|jtjk	rN||| n>t|jd jdkrt|jt
tfr|| ||j nX|jr|tjk	r|j dkr|t!|j  |j"dkr|t!|j" n
|| q |ptjg} fdd|D } fdd|D }|D ]2}|j|kr$d||#|j  ||#|j< q$|sl|d| S t|dkr|d| d |d  S |d| dd|  S d S )Nr   c                 s  s2   | ]*}t |tp(|jo(td d |jD V  qdS )c                 s  s   | ]}|j V  qd S r4   )
is_Integer)r-   air(   r(   r)   r~     s     z2StrPrinter._print_Mul.<locals>.<genexpr>.<genexpr>N)r5   r	   is_Powallr1   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   )r5   r   boolexpas_coeff_Mul)r   r(   r(   r)   <lambda>  s    z'StrPrinter._print_Mul.<locals>.<lambda>T)binaryFevaluatec                   s   g | ]}j | d dqS Fr   r+   r   rF   r$   r(   r)   r/   #  s   z)StrPrinter._print_Mul.<locals>.<listcomp>1c                   s   g | ]}j | d dqS r   r+   r   r   r(   r)   r/   -  s   *z%s/(%s)%s/%sr<   r>   )oldnonec                 S  sv   |   \}}tt|}|d tjkr6|dd  }n|d  |d< t|}t| trh| j	||ddS | j	|ddS )Nr   r   Fr   )
as_base_exprS   r   	make_argsr   NegativeOne
_from_argsr5   r   r   )rZ   r   r   Zeargsr(   r(   r)   apowK  s    

z#StrPrinter._print_Mul.<locals>.apowc                   s   g | ]}j | d dqS r   r+   r-   r   r   r(   r)   r/   l  s     c                   s   g | ]}j | d dqS r   r+   r   r   r(   r)   r/   m  s     r"   /z/(%s))$r   r1   r   Oneanyr   rT   r   	is_NumberrS   r   r   r   baserB   could_extract_minus_signr#   rD   r   r0   r   r
   r   as_ordered_factorsr   is_commutativer5   r   r   r   is_RationalInfinitypr   qindex)r$   r9   r1   r   nrZ   dir   ZdargsprenfactorsZdfactorscrJ   r   r   Z	pow_parenr   r%   a_str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 )Nr>   r<   r   c                   s   g | ]} |t qS r(   r*   r   r|   r9   r$   r(   r)   r/     s     z,StrPrinter._print_MatMul.<locals>.<listcomp>)as_coeff_mmul	is_numberas_real_imagis_zerois_negativer
   r0   r1   )r$   r9   r  r   rJ   reimr(   r  r)   _print_MatMul{  s    zStrPrinter._print_MatMulc                 C  s   d |j| |jS )Nz{}.({}))r   rc   r#   r9   r8   r(   r(   r)   _print_ElementwiseApplyFunction  s    
z*StrPrinter._print_ElementwiseApplyFunctionc                 C  s   dS )Nnanr(   r8   r(   r(   r)   
_print_NaN  s    zStrPrinter._print_NaNc                 C  s   dS )Nz-oor(   r8   r(   r(   r)   _print_NegativeInfinity  s    z"StrPrinter._print_NegativeInfinityc                 C  sn   |j rtdd |jD rVt|j dkr8d| |j S d| |jf|j  dd S nd| |jdd S d S )Nc                 s  s   | ]}|t jkV  qd S r4   )r   Zero)r-   r  r(   r(   r)   r~     s     z*StrPrinter._print_Order.<locals>.<genexpr>r   zO(%s)rb   r   )	variablesr   pointr   r#   r9   r3   r1   r8   r(   r(   r)   _print_Order  s
    zStrPrinter._print_Orderc                 C  s   |  S r4   __str__r8   r(   r(   r)   _print_Ordinal  s    zStrPrinter._print_Ordinalc                 C  s   |  S r4   r$  r8   r(   r(   r)   _print_Cycle  s    zStrPrinter._print_Cyclec                 C  sb  ddl m}m} ddlm} |j}|d k	rD|d| ddddd	 n| jd
d}|r|js`dS |||jd 	 t
dd  }|d}|dksd||d  kr||d  |d |  }|dd}|S | }|s|jdk rd| |j S d| |j S | |jd |d d  d| |j  }| |j }	}
t
|t
|
k rV|}	d|	 S 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   )deprecated_since_versionactive_deprecations_target
stacklevelr   Tz()r   r)  (,r>      zPermutation(%s)zPermutation([], size=%s)z	, size=%s) sympy.combinatorics.permutationsr(  r)  sympy.utilities.exceptionsr*  print_cyclic	_settingsgetsize__repr__r   rfindreplaceZsupportr#   
array_form)r$   r9   r(  r)  r*  r   rz   lastZtrim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))r1   r   r"  r#   )r$   r   r9   r   newr(   r(   r)   _print_Subs  s      zStrPrinter._print_Subsc                 C  s   |  S r4   rf   r8   r(   r(   r)   _print_TensorIndex  s    zStrPrinter._print_TensorIndexc                 C  s   |  S r4   rf   r8   r(   r(   r)   _print_TensorHead  s    zStrPrinter._print_TensorHeadc                 C  s   |  S r4   rf   r8   r(   r(   r)   _print_Tensor  s    zStrPrinter._print_Tensorc                   s*      \}}|d fdd|D  S )Nr   c                   s   g | ]} |t qS r(   r  r|   r  r(   r)   r/     s     z-StrPrinter._print_TensMul.<locals>.<listcomp>)!_get_args_for_traditional_printerr0   )r$   r9   rJ   r1   r(   r  r)   _print_TensMul  s    zStrPrinter._print_TensMulc                 C  s   |  S r4   rf   r8   r(   r(   r)   _print_TensAdd  s    zStrPrinter._print_TensAddc                 C  s   |  |jS r4   r#   r   r8   r(   r(   r)   _print_ArraySymbol  s    zStrPrinter._print_ArraySymbolc                   s2   d  |jtd dd fdd|jD f S )Nz%s[%s]FuncTrb   c                   s   g | ]}  |qS r(   rf   rt   rh   r(   r)   r/     s     z2StrPrinter._print_ArrayElement.<locals>.<listcomp>)r*   r   r   r0   indicesr8   r(   rh   r)   _print_ArrayElement  s     zStrPrinter._print_ArrayElementc                   s"    fdd|j D }dd| S )Nc                   s   g | ]}d   | qS )z    %srf   r   rh   r(   r)   r/     s     z6StrPrinter._print_PermutationGroup.<locals>.<listcomp>zPermutationGroup([
%s])z,
)r1   r0   )r$   r9   r  r(   rh   r)   _print_PermutationGroup  s    z"StrPrinter._print_PermutationGroupc                 C  s   dS )Npir(   r8   r(   r(   r)   	_print_Pi  s    zStrPrinter._print_Pic                   s4   dd  fdd|jD  |j |jf S )Nz+Polynomial ring in %s over %s with %s orderrb   c                 3  s   | ]}  |V  qd S r4   rf   )r-   rsrh   r(   r)   r~     s     z-StrPrinter._print_PolyRing.<locals>.<genexpr>r0   r   r#   domainr   )r$   ringr(   rh   r)   _print_PolyRing  s    
 
zStrPrinter._print_PolyRingc                   s4   dd  fdd|jD  |j |jf S )Nz3Rational function field in %s over %s with %s orderrb   c                 3  s   | ]}  |V  qd S r4   rf   )r-   Zfsrh   r(   r)   r~      s     z.StrPrinter._print_FracField.<locals>.<genexpr>rR  r$   fieldr(   rh   r)   _print_FracField  s    
 
zStrPrinter._print_FracFieldc                 C  s   |  S r4   r$  )r$   elmr(   r(   r)   _print_FreeGroupElement  s    z"StrPrinter._print_FreeGroupElementc                 C  s   d|j |jf S )Nz(%s + %s*I))r   yr$   polyr(   r(   r)   _print_GaussianElement  s    z!StrPrinter._print_GaussianElementc                 C  s   | | tddS )N%s**%sr   )r6   r   r\  r(   r(   r)   _print_PolyElement	  s    zStrPrinter._print_PolyElementc                 C  sR   |j dkr| |jS | j|jtd dd}| j|j td dd}|d | S d S )Nr   r   Tr   r   r   )denomr#   numerr*   r   )r$   fracrb  ra  r(   r(   r)   _print_FracElement  s
    
zStrPrinter._print_FracElementc                   sT  t d d  g  fdd|jD  }}| D ]\}}g }t|D ]>\}}|dkrF|dkrn|||  qF||| d|   qFd|}|jr|rd| d	 }	q|}	nB|r|tj	kr|
d
|g q0|tjkr|
d|g q0|}	|s|	}
n|	d | }
|
dr8|
d|
dd  g q0|
d
|
g q0|d dkrz|d}|dkrzd|d  |d< |jjd }ddlm} z|d|  7 }W n& |k
r   |d|  7 }Y nX |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                   s   g | ]} | qS r(   r+   )r-   rz   Z	ATOM_PRECr$   r(   r)   r/     s     z*StrPrinter._print_Poly.<locals>.<listcomp>r   z**%dr   r/  )r=   r<   )r<   r=   z(%s, %s)PolynomialErrorz, modulus=%sz, domain='%s'r   r?   rb   )r   gensrE   rT   r   r0   rB   r#   r   r   rC   r   rA   rD   ri   rj   sympy.polys.polyerrorsrg  get_modulus
get_domainr   )r$   r9   rE   rh  monomcoeffZs_monomrZ   r   Zs_coeffZs_termZmodifierr   rg  r	  r%   r(   re  r)   _print_Poly  sV    





:zStrPrinter._print_Polyc                 C  s   dS )Nry   r(   )r$   r  r(   r(   r)   _print_UniversalSetV  s    zStrPrinter._print_UniversalSetc                 C  s*   |j r| |  S | | S d S r4   )
is_aliasedr#   as_polyas_exprr8   r(   r(   r)   _print_AlgebraicNumberY  s    z!StrPrinter._print_AlgebraicNumberc                   s  t |}|jtjkr(|s(d |j S |jr|j tjkrb|sbdt fddtj|jfD  S |jtj krd tj j	|j|ddf S  j	|j|dd} j
dkr|jjr|jjd	kr|d
rd 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  s   | ]}  |V  qd S r4   rf   r|   rh   r(   r)   r~     s     z(StrPrinter._print_Pow.<locals>.<genexpr>r   Fr   Z
_sympyreprr   z	(Rationalr_  r2  )r   r   r   Halfr#   r  r  ru   r   r*   printmethodr  r  rA   )r$   r9   rationalPRECr   r(   rh   r)   
_print_Pow_  s    &"
"zStrPrinter._print_Powc                 C  s   |  |jd S r   r#   r1   r8   r(   r(   r)   _print_UnevaluatedExpr  s    z!StrPrinter._print_UnevaluatedExprc                 C  s0   t |}d| j|j|dd| j|j|ddf S )Nr_  Fr   )r   r*   r  r   )r$   r9   rw  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))r6  r7  r6   r  r8   r(   r(   r)   _print_Integer  s    zStrPrinter._print_Integerc                 C  s   dS )NIntegersr(   r8   r(   r(   r)   _print_Integers  s    zStrPrinter._print_Integersc                 C  s   dS )NNaturalsr(   r8   r(   r(   r)   _print_Naturals  s    zStrPrinter._print_Naturalsc                 C  s   dS )N	Naturals0r(   r8   r(   r(   r)   _print_Naturals0  s    zStrPrinter._print_Naturals0c                 C  s   dS )N	Rationalsr(   r8   r(   r(   r)   _print_Rationals  s    zStrPrinter._print_Rationalsc                 C  s   dS )NRealsr(   r8   r(   r(   r)   _print_Reals  s    zStrPrinter._print_Realsc                 C  s   dS )N	Complexesr(   r8   r(   r(   r)   _print_Complexes  s    zStrPrinter._print_Complexesc                 C  s   dS )NEmptySetr(   r8   r(   r(   r)   _print_EmptySet  s    zStrPrinter._print_EmptySetc                 C  s   dS )NEmptySequencer(   r8   r(   r(   r)   _print_EmptySequence  s    zStrPrinter._print_EmptySequencec                 C  s   t |S r4   r6   r8   r(   r(   r)   
_print_int  s    zStrPrinter._print_intc                 C  s   t |S r4   r  r8   r(   r(   r)   
_print_mpz  s    zStrPrinter._print_mpzc                 C  sF   |j dkrt|jS | jddr2d|j|j f S d|j|j f S d S )Nr   r   FzS(%s)/%sr   )r  r6   r  r6  r7  r8   r(   r(   r)   _print_Rational  s
    

zStrPrinter._print_Rationalc                 C  s(   |j dkrt|jS d|j|j f S d S )Nr   z%d/%d)r  r6   r  r8   r(   r(   r)   _print_PythonRational  s    

z StrPrinter._print_PythonRationalc                 C  s(   |j dkrt|jS d|j|j f S d S Nr   r   denominatorr6   	numeratorr8   r(   r(   r)   _print_Fraction  s    

zStrPrinter._print_Fractionc                 C  s(   |j dkrt|jS d|j|j f S d S r  r  r8   r(   r(   r)   
_print_mpq  s    

zStrPrinter._print_mpqc                 C  s   |j }|dk rd}n
t|j }| jd dkr2d}n,| jd dkrFd}n| jd dkr^| jdk}d| jkrr| jd nd }d	| jkr| jd	 nd }t|j||||d
}|drd|dd   }n|drd|dd   }|dr|dd  }|S )Nr1  r   r   TFr   r   r   r   )strip_zeros	min_fixed	max_fixedz-.0z-0.   z.0z0.r   r=   )_precr   r6  _print_levelmlib_to_str_mpf_rA   )r$   r9   rF   dps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 |krDd
||j  | |j| |jf S d| |jt|| j|j ph|j | |jt|f S )NEqNeZ
AssignmentZAddAugmentedAssignmentZSubAugmentedAssignmentZMulAugmentedAssignmentZDivAugmentedAssignmentZModAugmentedAssignment)z==z!=z:=z+=z-=z*=z/=z%=
%s(%s, %s)z%s %s %s)rel_opr#   lhsrV   r*   r   r!   r7  )r$   r9   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;   )rK   r9   r	  r8   r(   r(   r)   _print_ComplexRootOf  s    zStrPrinter._print_ComplexRootOfc                 C  s>   | j |jddg}|jtjk	r0|| |j dd| S )Nr  r;   zRootSum(%s)rb   )rK   r9   funr   IdentityFunctionr   r#   r0   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;   )rK   r   r|   basisr$   r(   r)   r/     s     z3StrPrinter._print_GroebnerBasis.<locals>.<listcomp>r   rb   c                   s   g | ]}  |qS r(   rf   )r-   genrh   r(   r)   r/      s     zdomain='%s'z
order='%s'ra   )ri   rj   exprsr0   rh  r#   rS  r   )r$   r  clsr  rh  rS  r   r1   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   rb   c                 3  s   | ]}  |V  qd S r4   rf   r,   rh   r(   r)   r~   +  s     z(StrPrinter._print_set.<locals>.<genexpr>zset()r   )r   r   r0   r$   rz   r   r1   r(   rh   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 rPd|S d	|S )
Nr   	FiniteSetr   rb   c                 3  s   | ]}  |V  qd S r4   rf   r,   rh   r(   r)   r~   4  s     z.StrPrinter._print_FiniteSet.<locals>.<genexpr>c                 3  s   | ]}|  V  qd S r4   )hasr,   r  r(   r)   r~   5  s     zFiniteSet({})z{{{}}})sympy.sets.setsr  r   r   r0   r   r   r  r(   )r  r$   r)   _print_FiniteSet0  s    
zStrPrinter._print_FiniteSetc                   s.   t |td}d fdd|D }d|S )Nr   rb   c                 3  s   | ]}  |V  qd S r4   rf   r|   rh   r(   r)   r~   <  s     z.StrPrinter._print_Partition.<locals>.<genexpr>zPartition({}))r   r   r0   r   r  r(   rh   r)   _print_Partition9  s    zStrPrinter._print_Partitionc                 C  s   |sdS d|  | S )Nzfrozenset()zfrozenset(%s))r  r$   rz   r(   r(   r)   _print_frozenset?  s    zStrPrinter._print_frozensetc                   s:   fdd d  fdd|jD }d|j|f S )Nc                   s>   t | dkr | d S  | d ft| dd   S d S r   r   r   rh   r(   r)   r   E  s    z)StrPrinter._print_Sum.<locals>._xab_tostrrb   c                   s   g | ]} |qS r(   r(   r   r   r(   r)   r/   J  s     z)StrPrinter._print_Sum.<locals>.<listcomp>zSum(%s, %s)r   r   r(   r   r)   
_print_SumD  s    zStrPrinter._print_Sumc                 C  s   |j S r4   r   r8   r(   r(   r)   _print_SymbolM  s    zStrPrinter._print_Symbolc                 C  s   dS r   r(   r8   r(   r(   r)   _print_IdentityR  s    zStrPrinter._print_Identityc                 C  s   dS )N0r(   r8   r(   r(   r)   _print_ZeroMatrixU  s    zStrPrinter._print_ZeroMatrixc                 C  s   dS )Nr   r(   r8   r(   r(   r)   _print_OneMatrixX  s    zStrPrinter._print_OneMatrixc                 C  s
   d|j  S )NzQ.%sr   r8   r(   r(   r)   _print_Predicate[  s    zStrPrinter._print_Predicatec                 C  s   t |S r4   r  r8   r(   r(   r)   
_print_str^  s    zStrPrinter._print_strc                 C  s2   t |dkrd| |d  S d| |d S d S )Nr   z(%s,)r   r"   rb   )r   r#   r3   r8   r(   r(   r)   _print_tuplea  s    zStrPrinter._print_tuplec                 C  s
   |  |S r4   )r  r8   r(   r(   r)   _print_Tupleg  s    zStrPrinter._print_Tuplec                 C  s   d|  |jtd  S )Nz%s.Tr   r   )r$   Tr(   r(   r)   _print_Transposej  s    zStrPrinter._print_Transposec                 C  s   d|  |j|  |jf S )NzUniform(%s, %s))r#   r   r   r8   r(   r(   r)   _print_Uniformm  s    zStrPrinter._print_Uniformc                 C  s"   | j ddrd|j S d|j S )Nr   Fz%s)r6  r7  r   r   r8   r(   r(   r)   _print_Quantityp  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   rt   rh   r(   r)   r/   v  s     z0StrPrinter._print_Quaternion.<locals>.<listcomp>r   c                 S  s   g | ]\}}|d  | qS )r   r(   )r-   rZ   rY   r(   r(   r)   r/   w  s     r   Zijkz + )r1   zipr0   )r$   r9   rz   r   r(   rh   r)   _print_Quaternionu  s    &zStrPrinter._print_Quaternionc                 C  s   t |S r4   r  r8   r(   r(   r)   _print_Dimensionz  s    zStrPrinter._print_Dimensionc                 C  s
   |j d S r   r   r8   r(   r(   r)   _print_Wild}  s    zStrPrinter._print_Wildc                 C  s
   |j d S r   r   r8   r(   r(   r)   _print_WildFunction  s    zStrPrinter._print_WildFunctionc                 C  s   |j S r4   r   r8   r(   r(   r)   _print_WildDot  s    zStrPrinter._print_WildDotc                 C  s   |j S r4   r   r8   r(   r(   r)   _print_WildPlus  s    zStrPrinter._print_WildPlusc                 C  s   |j S r4   r   r8   r(   r(   r)   _print_WildStar  s    zStrPrinter._print_WildStarc                 C  s   | j ddrdS dS )Nr   FzS(0)r  )r6  r7  r8   r(   r(   r)   _print_Zero  s    zStrPrinter._print_Zeroc                 C  st   z"|j d k	r | |j |W S W n tk
r6   Y nX |jj}| |j}| |j}| |j }d||||f S )Nz%s(%s, %s, %s))rT  r#   to_sympyr   ri   rj   repdom)r$   r  r  r  r  rT  r(   r(   r)   
_print_DMP  s    
zStrPrinter._print_DMPc                 C  s
   |  |S r4   )r  r8   r(   r(   r)   
_print_DMF  s    zStrPrinter._print_DMFc                 C  s
   d|j  S )NzObject("%s")r   )r$   r   r(   r(   r)   _print_Object  s    zStrPrinter._print_Objectc                 C  s
   d|j  S )NzIdentityMorphism(%s))rS  r$   morphismr(   r(   r)   _print_IdentityMorphism  s    z"StrPrinter._print_IdentityMorphismc                 C  s   d|j |j|jf S )NzNamedMorphism(%s, %s, "%s"))rS  codomainr   r  r(   r(   r)   _print_NamedMorphism  s    zStrPrinter._print_NamedMorphismc                 C  s
   d|j  S )NzCategory("%s")r   )r$   categoryr(   r(   r)   _print_Category  s    zStrPrinter._print_Categoryc                 C  s   |j j S r4   r   )r$   manifoldr(   r(   r)   _print_Manifold  s    zStrPrinter._print_Manifoldc                 C  s   |j j S r4   r   )r$   patchr(   r(   r)   _print_Patch  s    zStrPrinter._print_Patchc                 C  s   |j j S r4   r   )r$   coordsr(   r(   r)   _print_CoordSystem  s    zStrPrinter._print_CoordSystemc                 C  s   |j j|j jS r4   
_coord_sysr   _indexr   rV  r(   r(   r)   _print_BaseScalarField  s    z!StrPrinter._print_BaseScalarFieldc                 C  s   d|j j|j j S )Nze_%sr  rV  r(   r(   r)   _print_BaseVectorField  s    z!StrPrinter._print_BaseVectorFieldc                 C  s6   |j }t|dr$d|jj|j j S d| | S d S )Nr  zd%szd(%s))_form_fieldr   r  r   r  r   r#   )r$   diffrW  r(   r(   r)   _print_Differential  s    
zStrPrinter._print_Differentialc                 C  s   dd|  |jd f S )Nra   ZTrr   ry  r8   r(   r(   r)   	_print_Tr  s    zStrPrinter._print_Trc                 C  s   |  |jS r4   rI  r  r(   r(   r)   
_print_Str  s    zStrPrinter._print_Strc                 C  s*   |j }d| || |j| |jf S )Nr  )rc   r#   r  rV   )r$   r9   relr(   r(   r)   _print_AppliedBinaryRelation  s
    


z'StrPrinter._print_AppliedBinaryRelation)F)r   )N)F)rj   
__module____qualname__ru  r    __annotations__r!   r*   r3   r:   rK   rM   rO   rQ   r[   r^   r`   re   rk   ro   rq   rs   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@  rB  rC  rD  rE  rG  rH  rJ  rM  rN  rP  rU  rX  rZ  r^  r`  rd  rn  ro  rs  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  r  r  r  r  _print_MatrixSymbol_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  s   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r9   settingsr  rz   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  s   t |S r4   )r7   r  r(   r(   r)   r    s    zStrReprPrinter._print_strc                 C  s   d|j j| |jf S )Nra   )ri   rj   r#   r   r  r(   r(   r)   r    s    zStrReprPrinter._print_StrN)rj   r  r  __doc__r  r  r(   r(   r(   r)   r    s   r  c                 K  s   t |}|| }|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  r(   r(   r)   sstrrepr  s    

r  N)#r  
__future__r   typingr   
sympy.corer   r   r   r   r   r	   sympy.core.mulr
   sympy.core.relationalr   sympy.core.sortingr   sympy.core.sympifyr   sympy.utilities.iterablesr   r   r   printerr   r   Zmpmath.libmpr   r   r  r   r   r  r  r(   r(   r(   r)   <module>   s0           G
