U
    9%e                     @  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 (  
StrPrinterZ	_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'   Q/var/www/html/Darija-Ai-API/env/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     )Z_as_ordered_termsr   r"   
startswithis_Addextendpopr/   )	r#   r8   r   termsprecltermtsignr'   r'   r(   
_print_Add3   s     

zStrPrinter._print_Addc                 C  s   dS )NTruer'   r7   r'   r'   r(   _print_BooleanTrueH   s    zStrPrinter._print_BooleanTruec                 C  s   dS )NFalser'   r7   r'   r'   r(   _print_BooleanFalseK   s    zStrPrinter._print_BooleanFalsec                 C  s   d|  |jd td  S )Nz~%sr   Not)r)   r0   r   r7   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 & Z
BitwiseAnd)listr0   	enumerater4   r   	canonicalrhsr   NegativeInfinityinsertrB   r2   r   )r#   r8   r0   jir'   r'   r(   
_print_AndQ   s    

zStrPrinter._print_Andc                 C  s   |  |jdtd S )Nz | Z	BitwiseOrr2   r0   r   r7   r'   r'   r(   	_print_OrY   s    zStrPrinter._print_Orc                 C  s   |  |jdtd S )Nz ^ Z
BitwiseXorrY   r7   r'   r'   r(   
_print_Xor\   s    zStrPrinter._print_Xorc                 C  s   d|  |j| |jdf S )N%s(%s), )r"   functionr2   	argumentsr7   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!   r]   )r0   	__class____name__r/   )r#   r8   rE   r'   rc   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 )NZCatalanr'   r7   r'   r'   r(   _print_Catalanl   s    zStrPrinter._print_Catalanc                 C  s   dS )NZzoor'   r7   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'   ra   r,   rW   rc   r'   r(   r.   s   s     z2StrPrinter._print_ConditionSet.<locals>.<listcomp>zConditionSet(%s, %s)zConditionSet(%s, %s, %s))tuplesym	conditionZbase_setr   UniversalSetr"   )r#   sr0   r'   rc   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'   rm   r'   r'   r(   r.   {   s     z0StrPrinter._print_Derivative.<locals>.<listcomp>zDerivative(%s)r]   c                 3  s   | ]}  |V  qd S r3   ra   r,   argrc   r'   r(   	<genexpr>|   s     z/StrPrinter._print_Derivative.<locals>.<genexpr>)r8   Zvariable_countr/   )r#   r8   ZdexprZdvarsr'   rc   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}r]   )sortedkeysr   r"   appendr/   )r#   dr|   itemsry   r$   r'   r'   r(   _print_dict~   s    zStrPrinter._print_dictc                 C  s
   |  |S r3   )r   r7   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_namer7   r'   r'   r(   _print_Dummy   s    zStrPrinter._print_Dummyc                 C  s   dS )NZ
EulerGammar'   r7   r'   r'   r(   _print_EulerGamma   s    zStrPrinter._print_EulerGammac                 C  s   dS )NEr'   r7   r'   r'   r(   _print_Exp1   s    zStrPrinter._print_Exp1c                 C  s   d|  |j|  |jf S )Nz(%s, %s))r"   r8   Zcondr7   r'   r'   r(   _print_ExprCondPair   s    zStrPrinter._print_ExprCondPairc                 C  s   |j jd| |jd  S Nr!   r]   )funcre   r2   r0   r7   r'   r'   r(   _print_Function   s    zStrPrinter._print_Functionc                 C  s   dS )NZGoldenRatior'   r7   r'   r'   r(   _print_GoldenRatio   s    zStrPrinter._print_GoldenRatioc                 C  s   |j jd| |jd  S r   )r   re   r2   Zpargsr7   r'   r'   r(   _print_Heaviside   s    zStrPrinter._print_Heavisidec                 C  s   dS )NZTribonacciConstantr'   r7   r'   r'   r(   _print_TribonacciConstant   s    z$StrPrinter._print_TribonacciConstantc                 C  s   dS NIr'   r7   r'   r'   r(   _print_ImaginaryUnit   s    zStrPrinter._print_ImaginaryUnitc                 C  s   dS )NZoor'   r7   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"   rn   Zxabrc   r'   r(   
_xab_tostr   s    z.StrPrinter._print_Integral.<locals>._xab_tostrr]   c                   s   g | ]} |qS r'   r'   r,   rE   r   r'   r(   r.      s     z.StrPrinter._print_Integral.<locals>.<listcomp>zIntegral(%s, %s)r/   Zlimitsr"   r^   r#   r8   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)r0   is_infiniteformat)r#   rW   Zfinr   r   rE   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#   rW   r'   r'   r(   _print_AccumulationBounds   s    
z$StrPrinter._print_AccumulationBoundsc                 C  s   d|  |jtd  S )Nz%s**(-1)r   r)   ru   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))r8   	signaturer   Z	is_symbolr"   )r#   objr8   sigr'   r'   r(   _print_Lambda   s
    zStrPrinter._print_Lambdac                   s2   t |jtd}|jjdd fdd|D   S )Nrx   r!   r]   c                 3  s   | ]}  |V  qd S r3   ra   rt   rc   r'   r(   rv      s     z.StrPrinter._print_LatticeOp.<locals>.<genexpr>)r{   r0   r   r   re   r/   r#   r8   r0   r'   rc   r(   _print_LatticeOp   s    zStrPrinter._print_LatticeOpc                 C  s*   |j \}}}}dtt| j||||f S )NzLimit(%s, %s, %s, dir='%s'))r0   rn   mapr"   )r#   r8   ezZz0dirr'   r'   r(   _print_Limit   s    zStrPrinter._print_Limitc                 C  s   d|  |d S )N[%s]r]   )r2   r7   r'   r'   r(   _print_list   s    zStrPrinter._print_listc                 C  s
   |  |S r3   )r   r7   r'   r'   r(   _print_List   s    zStrPrinter._print_Listc                 C  s
   | | S r3   )Z_format_strr7   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"   rW   rV   r7   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 r3   ra   rt   rc   r'   r(   rv      s     zBStrPrinter._print_MatrixSlice.<locals>.strslice.<locals>.<genexpr>)rP   r/   )xdimrc   r'   r(   strslice   s    z/StrPrinter._print_MatrixSlice.<locals>.strslicer   Tr   [r]   ])r)   r   r   ZrowslicerowsZcolslicecols)r#   r8   r   r'   rc   r(   _print_MatrixSlice   s    	zStrPrinter._print_MatrixSlicec                 C  s   |j S r3   r   r7   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 r3   )Z
is_Integer)r,   Zair'   r'   r(   rv     s     z2StrPrinter._print_Mul.<locals>.<genexpr>.<genexpr>N)r4   r	   Zis_Powallr0   r,   r   r'   r'   r(   rv     s   
z(StrPrinter._print_Mul.<locals>.<genexpr>r   c                 S  s    t | tot| j d dk S Nr   )r4   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   rD   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   )
Zas_base_exprP   r   	make_argsr   NegativeOne
_from_argsr4   r   r   )rW   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   r0   r   Oneanyr   rQ   r   Z	is_NumberrP   r   r   r   baser@   Zcould_extract_minus_signr"   rB   r   r/   r   r
   r   Zas_ordered_factorsr   is_commutativer4   r   r   r}   is_RationalInfinitypr   qindex)r#   r8   r0   r~   nrW   Zdir   dargspreZnfactorsZdfactorscrH   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 )Nr=   r;   r   c                   s   g | ]} |t qS r'   r)   r   rt   r8   r#   r'   r(   r.     s     z,StrPrinter._print_MatMul.<locals>.<listcomp>)Zas_coeff_mmulZ	is_numberZas_real_imagis_zeroZis_negativer
   r/   r0   )r#   r8   r   r   rH   reZimr'   r   r(   _print_MatMul{  s    zStrPrinter._print_MatMulc                 C  s   d |j| |jS )Nz{}.({}))r   r^   r"   r8   r7   r'   r'   r(   _print_ElementwiseApplyFunction  s    
z*StrPrinter._print_ElementwiseApplyFunctionc                 C  s   dS )Nnanr'   r7   r'   r'   r(   
_print_NaN  s    zStrPrinter._print_NaNc                 C  s   dS )Nz-oor'   r7   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 r3   )r   ZZero)r,   r   r'   r'   r(   rv     s     z*StrPrinter._print_Order.<locals>.<genexpr>r   zO(%s)r]   r   )	variablesr   pointr   r"   r8   r2   r0   r7   r'   r'   r(   _print_Order  s
    zStrPrinter._print_Orderc                 C  s   |  S r3   __str__r7   r'   r'   r(   _print_Ordinal  s    zStrPrinter._print_Ordinalc                 C  s   |  S r3   r   r7   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   )Zdeprecated_since_versionZactive_deprecations_target
stacklevelr   Tz()r   r  (,r=      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#   r8   r  r  r  r   rr   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))r0   r   r   r"   )r#   r   r8   r   newr'   r'   r(   _print_Subs  s      zStrPrinter._print_Subsc                 C  s   |  S r3   ra   r7   r'   r'   r(   _print_TensorIndex  s    zStrPrinter._print_TensorIndexc                 C  s   |  S r3   ra   r7   r'   r'   r(   _print_TensorHead  s    zStrPrinter._print_TensorHeadc                 C  s   |  S r3   ra   r7   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   rt   r   r'   r(   r.     s     z-StrPrinter._print_TensMul.<locals>.<listcomp>)Z!_get_args_for_traditional_printerr/   )r#   r8   rH   r0   r'   r   r(   _print_TensMul  s    zStrPrinter._print_TensMulc                 C  s   |  S r3   ra   r7   r'   r'   r(   _print_TensAdd  s    zStrPrinter._print_TensAddc                 C  s   |  |jS r3   r"   r   r7   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]ZFuncTr]   c                   s   g | ]}  |qS r'   ra   rm   rc   r'   r(   r.     s     z2StrPrinter._print_ArrayElement.<locals>.<listcomp>)r)   r   r   r/   indicesr7   r'   rc   r(   _print_ArrayElement  s     zStrPrinter._print_ArrayElementc                   s"    fdd|j D }dd| S )Nc                   s   g | ]}d   | qS )z    %sra   r   rc   r'   r(   r.     s     z6StrPrinter._print_PermutationGroup.<locals>.<listcomp>zPermutationGroup([
%s])z,
)r0   r/   )r#   r8   r   r'   rc   r(   _print_PermutationGroup  s    z"StrPrinter._print_PermutationGroupc                 C  s   dS )Npir'   r7   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 orderr]   c                 3  s   | ]}  |V  qd S r3   ra   )r,   rsrc   r'   r(   rv     s     z-StrPrinter._print_PolyRing.<locals>.<genexpr>r/   r   r"   domainr   )r#   ringr'   rc   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 orderr]   c                 3  s   | ]}  |V  qd S r3   ra   )r,   fsrc   r'   r(   rv      s     z.StrPrinter._print_FracField.<locals>.<genexpr>r$  r#   fieldr'   rc   r(   _print_FracField  s    
 
zStrPrinter._print_FracFieldc                 C  s   |  S r3   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#   Zpolyr'   r'   r(   _print_GaussianElement  s    z!StrPrinter._print_GaussianElementc                 C  s   | | tddS )N%s**%sr   )r5   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#   fracr4  r3  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,   rr   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>   r]   )r   gensrC   rQ   r}   r/   r@   r"   r   r   rA   r   r?   rB   rd   re   Zsympy.polys.polyerrorsr9  Zget_modulusZ
get_domainr   )r#   r8   rC   r:  ZmonomZcoeffZs_monomrW   r   Zs_coeffZs_termmodifierr   r9  r   r$   r'   r7  r(   _print_Poly  sV    





:zStrPrinter._print_Polyc                 C  s   dS )Nrq   r'   )r#   r   r'   r'   r(   _print_UniversalSetV  s    zStrPrinter._print_UniversalSetc                 C  s*   |j r| |  S | | S d S r3   )Z
is_aliasedr"   Zas_polyZas_exprr7   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 r3   ra   rt   rc   r'   r(   rv     s     z(StrPrinter._print_Pow.<locals>.<genexpr>r   Fr   Z
_sympyreprr   z	(Rationalr1  r  )r   r   r   ZHalfr"   r   r   rn   r   r)   printmethodr   r   r?   )r#   r8   ZrationalPRECr   r'   rc   r(   
_print_Pow_  s    &"
"zStrPrinter._print_Powc                 C  s   |  |jd S r   r"   r0   r7   r'   r'   r(   _print_UnevaluatedExpr  s    z!StrPrinter._print_UnevaluatedExprc                 C  s0   t |}d| j|j|dd| j|j|ddf S )Nr1  Fr   )r   r)   r   r   )r#   r8   r@  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  r5   r   r7   r'   r'   r(   _print_Integer  s    zStrPrinter._print_Integerc                 C  s   dS )NZIntegersr'   r7   r'   r'   r(   _print_Integers  s    zStrPrinter._print_Integersc                 C  s   dS )NZNaturalsr'   r7   r'   r'   r(   _print_Naturals  s    zStrPrinter._print_Naturalsc                 C  s   dS )NZ	Naturals0r'   r7   r'   r'   r(   _print_Naturals0  s    zStrPrinter._print_Naturals0c                 C  s   dS )NZ	Rationalsr'   r7   r'   r'   r(   _print_Rationals  s    zStrPrinter._print_Rationalsc                 C  s   dS )NZRealsr'   r7   r'   r'   r(   _print_Reals  s    zStrPrinter._print_Realsc                 C  s   dS )NZ	Complexesr'   r7   r'   r'   r(   _print_Complexes  s    zStrPrinter._print_Complexesc                 C  s   dS )NZEmptySetr'   r7   r'   r'   r(   _print_EmptySet  s    zStrPrinter._print_EmptySetc                 C  s   dS )NZEmptySequencer'   r7   r'   r'   r(   _print_EmptySequence  s    zStrPrinter._print_EmptySequencec                 C  s   t |S r3   r5   r7   r'   r'   r(   
_print_int  s    zStrPrinter._print_intc                 C  s   t |S r3   rN  r7   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   r5   r   r  r  r7   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   r5   r   r7   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   denominatorr5   	numeratorr7   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 rS  rT  r7   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 )Nr
  r   r   TFr   r   r   r   )Zstrip_zerosZ	min_fixedZ	max_fixedz-.0z-0.   z.0z0.r   r<   )Z_precr   r  Z_print_levelmlib_to_strZ_mpf_r?   )r#   r8   rD   Z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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"   lhsrS   r)   r   r    r  )r#   r8   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:   )rI   r8   r   r7   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 )Nre  r:   zRootSum(%s)r]   )rI   r8   Zfunr   ZIdentityFunctionr}   r"   r/   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:   )rI   r   rt   basisr#   r'   r(   r.     s     z3StrPrinter._print_GroebnerBasis.<locals>.<listcomp>r   r]   c                   s   g | ]}  |qS r'   ra   )r,   genrc   r'   r(   r.      s     zdomain='%s'z
order='%s'r\   )rd   re   exprsr/   r:  r"   r%  r   )r#   ri  clsrk  r:  r%  r   r0   r'   rh  r(   _print_GroebnerBasis  s    zStrPrinter._print_GroebnerBasisc                   s4   t |td}d fdd|D }|s,dS d| S )Nrx   r]   c                 3  s   | ]}  |V  qd S r3   ra   r+   rc   r'   r(   rv   +  s     z(StrPrinter._print_set.<locals>.<genexpr>zset()rz   )r{   r   r/   r#   rr   r   r0   r'   rc   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   	FiniteSetrx   r]   c                 3  s   | ]}  |V  qd S r3   ra   r+   rc   r'   r(   rv   4  s     z.StrPrinter._print_FiniteSet.<locals>.<genexpr>c                 3  s   | ]}|  V  qd S r3   )hasr+   rp  r'   r(   rv   5  s     zFiniteSet({})z{{{}}})Zsympy.sets.setsrq  r{   r   r/   r   r   rn  r'   )rq  r#   r(   _print_FiniteSet0  s    
zStrPrinter._print_FiniteSetc                   s.   t |td}d fdd|D }d|S )Nrx   r]   c                 3  s   | ]}  |V  qd S r3   ra   rt   rc   r'   r(   rv   <  s     z.StrPrinter._print_Partition.<locals>.<genexpr>zPartition({}))r{   r   r/   r   rn  r'   rc   r(   _print_Partition9  s    zStrPrinter._print_Partitionc                 C  s   |sdS d|  | S )Nzfrozenset()zfrozenset(%s))ro  r#   rr   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   rc   r'   r(   r   E  s    z)StrPrinter._print_Sum.<locals>._xab_tostrr]   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 r3   r   r7   r'   r'   r(   _print_SymbolM  s    zStrPrinter._print_Symbolc                 C  s   dS r   r'   r7   r'   r'   r(   _print_IdentityR  s    zStrPrinter._print_Identityc                 C  s   dS )N0r'   r7   r'   r'   r(   _print_ZeroMatrixU  s    zStrPrinter._print_ZeroMatrixc                 C  s   dS )Nr   r'   r7   r'   r'   r(   _print_OneMatrixX  s    zStrPrinter._print_OneMatrixc                 C  s
   d|j  S )NzQ.%sr   r7   r'   r'   r(   _print_Predicate[  s    zStrPrinter._print_Predicatec                 C  s   t |S r3   rN  r7   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!   r]   )r   r"   r2   r7   r'   r'   r(   _print_tuplea  s    zStrPrinter._print_tuplec                 C  s
   |  |S r3   )r  r7   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   r7   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)r  r  r   r   r7   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   rm   rc   r'   r(   r.   v  s     z0StrPrinter._print_Quaternion.<locals>.<listcomp>r   c                 S  s   g | ]\}}|d  | qS )r   r'   )r,   rW   rV   r'   r'   r(   r.   w  s     r   Zijkz + )r0   zipr/   )r#   r8   rr   r   r'   rc   r(   _print_Quaternionu  s    &zStrPrinter._print_Quaternionc                 C  s   t |S r3   rN  r7   r'   r'   r(   _print_Dimensionz  s    zStrPrinter._print_Dimensionc                 C  s
   |j d S r   r   r7   r'   r'   r(   _print_Wild}  s    zStrPrinter._print_Wildc                 C  s
   |j d S r   r   r7   r'   r'   r(   _print_WildFunction  s    zStrPrinter._print_WildFunctionc                 C  s   |j S r3   r   r7   r'   r'   r(   _print_WildDot  s    zStrPrinter._print_WildDotc                 C  s   |j S r3   r   r7   r'   r'   r(   _print_WildPlus  s    zStrPrinter._print_WildPlusc                 C  s   |j S r3   r   r7   r'   r'   r(   _print_WildStar  s    zStrPrinter._print_WildStarc                 C  s   | j ddrdS dS )Nr   FzS(0)rz  )r  r  r7   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))r&  r"   Zto_sympyr   rd   re   repdom)r#   r   rl  r  r  r&  r'   r'   r(   
_print_DMP  s    
zStrPrinter._print_DMPc                 C  s
   |  |S r3   )r  r7   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))r%  r#   Zmorphismr'   r'   r(   _print_IdentityMorphism  s    z"StrPrinter._print_IdentityMorphismc                 C  s   d|j |j|jf S )NzNamedMorphism(%s, %s, "%s"))r%  Z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 r3   r   )r#   Zmanifoldr'   r'   r(   _print_Manifold  s    zStrPrinter._print_Manifoldc                 C  s   |j j S r3   r   )r#   patchr'   r'   r(   _print_Patch  s    zStrPrinter._print_Patchc                 C  s   |j j S r3   r   )r#   Zcoordsr'   r'   r(   _print_CoordSystem  s    zStrPrinter._print_CoordSystemc                 C  s   |j j|j jS r3   
_coord_sysr   _indexr   r)  r'   r'   r(   _print_BaseScalarField  s    z!StrPrinter._print_BaseScalarFieldc                 C  s   d|j j|j j S )Nze_%sr  r)  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))Z_form_fieldr   r  r   r  r   r"   )r#   diffr*  r'   r'   r(   _print_Differential  s    
zStrPrinter._print_Differentialc                 C  s   dd|  |jd f S )Nr\   ZTrr   rB  r7   r'   r'   r(   	_print_Tr  s    zStrPrinter._print_Trc                 C  s   |  |jS r3   r  ru  r'   r'   r(   
_print_Str  s    zStrPrinter._print_Strc                 C  s*   |j }d| || |j| |jf S )Nra  )r^   r"   rb  rS   )r#   r8   relr'   r'   r(   _print_AppliedBinaryRelation  s
    


z'StrPrinter._print_AppliedBinaryRelation)F)r   )N)F)re   
__module____qualname__r?  r   __annotations__r    r)   r2   r9   rI   rK   rM   rO   rX   rZ   r[   r`   rf   rj   rk   rl   rs   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   r   r  r  r  r  r  r  r  r  r  r  r  r   r"  r'  r+  r-  r0  r2  r6  r<  r=  r>  rA  rC  rD  rE  rF  rG  rH  rI  rJ  rK  rL  rM  rO  rP  rQ  rR  rW  rX  r_  rd  rf  rg  rm  ro  rs  rt  rv  rw  rx  Z_print_MatrixSymbolZ_print_RandomSymbolry  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r8   settingsr   rr   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 r3   )r6   ru  r'   r'   r(   r~    s    zStrReprPrinter._print_strc                 C  s   d|j j| |jf S )Nr\   )rd   re   r"   r   ru  r'   r'   r(   r    s    zStrReprPrinter._print_StrN)re   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   Z
sympy.corer   r   r   r   r   r	   Zsympy.core.mulr
   Zsympy.core.relationalr   Zsympy.core.sortingr   Zsympy.core.sympifyr   Zsympy.utilities.iterablesr   r   r   printerr   r   Zmpmath.libmpr   r   rZ  r   r  r  r  r'   r'   r'   r(   <module>   s0           G
