a
    <bo                     @   s   d Z ddlmZ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 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.
    )AnyDict)SRationalPowBasicMulNumber)_keep_coeff)
Relational)default_sort_key)SympifyError)	FiniteSet)sift   )
precedence
PRECEDENCE)Printerprint_function)prec_to_dpsto_strc                   @   s  e Zd ZdZddddddddZe Z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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[ Z0d\d] Z1d^d_ Z2d`da Z3dbdc Z4ddde Z5dfdg Z6dhdi Z7djdk Z8dldm Z9dndo Z:dpdq Z;drds Z<dtdu Z=dvdw Z>dxdy Z?dzd{ Z@d|d} ZAd~d 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 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 ZdS (  
StrPrinterZ	_sympystrNautoFT)order	full_precsympy_integersabbrevperm_cyclicminmaxc                 C   s8   t ||k s|s*t ||kr*d| | S | |S d S )N(%s))r   _print)selfitemlevelstrict r&   b/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/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>*       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 ]\}| |}|drHd}|dd  }nd}t||k rl||d| g q|||g q|d}|dkrd}|d| S )	Nr   -r   +r    r     )Z_as_ordered_termsr   r!   
startswithextendpopr/   )	r"   r8   r   termsPREClZtermtsignr&   r&   r'   
_print_Add4   s     


zStrPrinter._print_Addc                 C   s   dS )NTruer&   r7   r&   r&   r'   _print_BooleanTrueI   s    zStrPrinter._print_BooleanTruec                 C   s   dS )NFalser&   r7   r&   r&   r'   _print_BooleanFalseL   s    zStrPrinter._print_BooleanFalsec                 C   s   d|  |jd td  S )Nz~%sr   Not)r(   r0   r   r7   r&   r&   r'   
_print_NotO   s    zStrPrinter._print_Notc                 C   sX   t |j}t|D ]2\}}t|tr|jjtju r|	d|
| q| |dtd S )Nr   z & Z
BitwiseAnd)listr0   	enumerater4   r   	canonicalrhsr   NegativeInfinityinsertrA   r2   r   )r"   r8   r0   jir&   r&   r'   
_print_AndR   s    

zStrPrinter._print_Andc                 C   s   |  |jdtd S )Nz | Z	BitwiseOrr2   r0   r   r7   r&   r&   r'   	_print_OrZ   s    zStrPrinter._print_Orc                 C   s   |  |jdtd S )Nz ^ Z
BitwiseXorrW   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-   e   r.   z+StrPrinter._print_Basic.<locals>.<listcomp>r    r[   )r0   	__class____name__r/   )r"   r8   rD   r&   ra   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   s   dS )NZCatalanr&   r7   r&   r&   r'   _print_Catalanm   s    zStrPrinter._print_Catalanc                 C   s   dS )NZzoor&   r7   r&   r&   r'   _print_ComplexInfinityp   s    z!StrPrinter._print_ComplexInfinityc                    sL   t  fdd|j|jfD }|jtju r2d| S | |jf7 }d| S )Nc                    s   g | ]}  |qS r&   r_   r+   rU   ra   r&   r'   r-   t   r.   z2StrPrinter._print_ConditionSet.<locals>.<listcomp>zConditionSet(%s, %s)zConditionSet(%s, %s, %s))tuplesym	conditionZbase_setr   UniversalSetr!   )r"   sr0   r&   ra   r'   _print_ConditionSets   s
    zStrPrinter._print_ConditionSetc                    s8   |j }dd |jD }ddt fdd|g|  S )Nc                 S   s$   g | ]}|d  d kr|d n|qS )r   r   r&   rk   r&   r&   r'   r-   |   r.   z0StrPrinter._print_Derivative.<locals>.<listcomp>zDerivative(%s)r[   c                    s
     | S r3   r_   argra   r&   r'   <lambda>}   r.   z.StrPrinter._print_Derivative.<locals>.<lambda>)r8   Zvariable_countr/   map)r"   r8   ZdexprZdvarsr&   ra   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}r[   )sortedkeysr   r!   appendr/   )r"   dr{   itemsrx   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[   )funcrc   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   rc   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!   rl   Zxabra   r&   r'   
_xab_tostr   s    z.StrPrinter._print_Integral.<locals>._xab_tostrr[   c                    s   g | ]} |qS r&   r&   r+   rD   r   r&   r'   r-      r.   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 i |||dS )NzInterval{m}({a}, {b})r=   z.openz.Lopenz.Ropen)abm)r0   is_infiniteformat)r"   rU   Zfinr   r   rD   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"   rU   r&   r&   r'   _print_AccumulationBounds   s    
z$StrPrinter._print_AccumulationBoundsc                 C   s   d|  |jtd  S )Nz%s**(-1)r   r(   rs   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 )Nrw   r    r[   c                 3   s   | ]}  |V  qd S r3   r_   r+   rs   ra   r&   r'   	<genexpr>   r.   z.StrPrinter._print_LatticeOp.<locals>.<genexpr>)rz   r0   r   r   rc   r/   r"   r8   r0   r&   ra   r'   _print_LatticeOp   s    zStrPrinter._print_LatticeOpc                 C   sT   |j \}}}}t|dkr4dtt| j|||f S dtt| j||||f S d S )Nr<   zLimit(%s, %s, %s)zLimit(%s, %s, %s, dir='%s'))r0   r5   rl   ru   r!   )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!   rU   rT   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t fdd| S )N   r   r   r=   :c                    s
     | S r3   r_   rr   ra   r&   r'   rt     r.   zAStrPrinter._print_MatrixSlice.<locals>.strslice.<locals>.<lambda>)rN   r/   ru   )xZdimra   r&   r'   strslice   s    z/StrPrinter._print_MatrixSlice.<locals>.strslicer   Tr   [r[   ])r(   r   r   ZrowslicerowsZcolslicecols)r"   r8   r   r&   ra   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u 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  rt|dg}	|	 fdd|D  }
|
sdg}
t|dkr,|d  r,t|dg}	ng }	|	 fdd|D  }d|
}d|}t|dkrvd||f S |rd||f S |S | \}}|dk rt| |}d}nd}g }g }g }jdvr| }n
t
|}dd }|D ]}|jr~t|tr~t|j d dk r~|jtjur>||| n>t|jd jdkrpt|jt
tfrp|| ||j nX|jr|tju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|v rd||"|j  ||"|j< q|s\|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'   r     r.   z2StrPrinter._print_Mul.<locals>.<genexpr>.<genexpr>N)r4   r	   Zis_Powallr0   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   )r4   r   boolexpas_coeff_Mul)r   r&   r&   r'   rt     s    z'StrPrinter._print_Mul.<locals>.<lambda>T)binaryFevaluatec                    s   g | ]}j | d dqS Fr   r)   r   precr"   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-   1  s   *z%s/(%s)%s/%sr;   r=   )oldnonec                 S   sv   |   \}}tt|}|d tju r6|dd  }n|d  |d< t|}t| trh| j	||ddS | j	|ddS )Nr   r   Fr   )
Zas_base_exprN   r   	make_argsr   NegativeOne
_from_argsr4   r   r   )rU   r   r   Zeargsr&   r&   r'   apowO  s    

z#StrPrinter._print_Mul.<locals>.apowc                    s   g | ]}j | d dqS r   r)   r+   r   r   r&   r'   r-   p  r.   c                    s   g | ]}j | d dqS r   r)   r   r   r&   r'   r-   q  r.   r    /z/(%s))#r   r0   r   Oneanyr   rO   r   Z	is_NumberrN   r   r   r   baseZcould_extract_minus_signr5   rA   r   r/   r   r
   r   Zas_ordered_factorsr   is_commutativer4   r   r   r|   is_RationalInfinitypr   qindex)r"   r8   r0   r}   nrU   Zdir   dargspreZnfactorsZdfactorscrF   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   r   r8   r"   r&   r'   r-     r.   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   rF   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u V  qd S r3   )r   ZZero)r+   r   r&   r&   r'   r     r.   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 u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  v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   rp   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   r_   r7   r&   r&   r'   _print_TensorIndex  s    zStrPrinter._print_TensorIndexc                 C   s   |  S r3   r_   r7   r&   r&   r'   _print_TensorHead  s    zStrPrinter._print_TensorHeadc                 C   s   |  S r3   r_   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   r   r   r&   r'   r-     r.   z-StrPrinter._print_TensMul.<locals>.<listcomp>)Z!_get_args_for_traditional_printerr/   )r"   r8   rF   r0   r&   r   r'   _print_TensMul  s    zStrPrinter._print_TensMulc                 C   s   |  S r3   r_   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&   r_   rk   ra   r&   r'   r-     r.   z2StrPrinter._print_ArrayElement.<locals>.<listcomp>)r(   r   r   r/   indicesr7   r&   ra   r'   _print_ArrayElement  s    *zStrPrinter._print_ArrayElementc                    s"    fdd|j D }dd| S )Nc                    s   g | ]}d   | qS )z    %sr_   r   ra   r&   r'   r-     r.   z6StrPrinter._print_PermutationGroup.<locals>.<listcomp>zPermutationGroup([
%s])z,
)r0   r/   )r"   r8   r   r&   ra   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 t fdd|j |j |jf S )Nz+Polynomial ring in %s over %s with %s orderr[   c                    s
     | S r3   r_   )rsra   r&   r'   rt     r.   z,StrPrinter._print_PolyRing.<locals>.<lambda>r/   ru   r   r!   domainr   )r"   ringr&   ra   r'   _print_PolyRing  s
    zStrPrinter._print_PolyRingc                    s4   dd t fdd|j |j |jf S )Nz3Rational function field in %s over %s with %s orderr[   c                    s
     | S r3   r_   )fsra   r&   r'   rt     r.   z-StrPrinter._print_FracField.<locals>.<lambda>r#  r"   fieldr&   ra   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"   fracr3  r2  r&   r&   r'   _print_FracElement  s
    
zStrPrinter._print_FracElementc                    sR  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	u r|
d
|g q0|tju r|
d|g q0|}	|s|	}
n|	d | }
|
dr8|
d|
dd  g q0|
d
|
g q0|d dv rz|d}|dkrzd|d  |d< |jjd }ddlm} z|d|  7 }W n$ |y   |d|  7 }Y n0 |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+   rp   Z	ATOM_PRECr"   r&   r'   r-     r.   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   gensrB   rO   r|   r/   Zis_Addr!   r   r   r@   r   r?   rA   rb   rc   Zsympy.polys.polyerrorsr8  Zget_modulusZ
get_domainr   )r"   r8   rB   r9  ZmonomZcoeffZs_monomrU   r   Zs_coeffZs_termmodifierr   r8  r   r#   r&   r6  r'   _print_Poly  sV    





:zStrPrinter._print_Polyc                 C   s   dS )Nro   r&   )r"   r   r&   r&   r'   _print_UniversalSetZ  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_AlgebraicNumber]  s    z!StrPrinter._print_AlgebraicNumberc                    s  t |}|jtju r(|s(d |j S |jr|j tju rb|sbdtt fddtj	|jf S |jtj	 u 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                    s
     | S r3   r_   rr   ra   r&   r'   rt     r.   z'StrPrinter._print_Pow.<locals>.<lambda>r   Fr   Z
_sympyreprr   z	(Rationalr0  r
  )r   r   r   ZHalfr!   r   r   rl   ru   r   r(   printmethodr   r   r?   )r"   r8   ZrationalrC   r   r&   ra   r'   
_print_Powc  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 )Nr0  Fr   )r   r(   r   r   )r"   r8   rC   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   rL  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 rQ  rR  r7   r&   r&   r'   
_print_mpq  s    

zStrPrinter._print_mpqc                 C   s   |j }|dk rd}n
t|j }| jd du r2d}n,| jd du rFd}n| jd dkr^| jdk}d| jv rr| jd nd }d	| jv 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   r   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 |v 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!   lhsrQ   r(   r   _relationalsr  )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:   )rG   r8   r   r7   r&   r&   r'   _print_ComplexRootOf  s    zStrPrinter._print_ComplexRootOfc                 C   s>   | j |jddg}|jtjur0|| |j dd| S )Nrd  r:   zRootSum(%s)r[   )rG   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:   )rG   r   r   basisr"   r&   r'   r-   !  r.   z3StrPrinter._print_GroebnerBasis.<locals>.<listcomp>r   r[   c                    s   g | ]}  |qS r&   r_   )r+   genra   r&   r'   r-   $  r.   zdomain='%s'z
order='%s'rZ   )rb   rc   exprsr/   r9  r!   r$  r   )r"   rh  clsrj  r9  r$  r   r0   r&   rg  r'   _print_GroebnerBasis  s    zStrPrinter._print_GroebnerBasisc                    s4   t |td}d fdd|D }|s,dS d| S )Nrw   r[   c                 3   s   | ]}  |V  qd S r3   r_   r*   ra   r&   r'   r   /  r.   z(StrPrinter._print_set.<locals>.<genexpr>zset()ry   )rz   r   r/   r"   rp   r~   r0   r&   ra   r'   
_print_set,  s
    zStrPrinter._print_setc                    sJ   t |td}d fdd|D }tdd |D r@d|S d|S )Nrw   r[   c                 3   s   | ]}  |V  qd S r3   r_   r*   ra   r&   r'   r   7  r.   z.StrPrinter._print_FiniteSet.<locals>.<genexpr>c                 s   s   | ]}| tV  qd S r3   )Zhasr   r*   r&   r&   r'   r   8  r.   zFiniteSet({})z{{{}}})rz   r   r/   r   r   rm  r&   ra   r'   _print_FiniteSet4  s
    
zStrPrinter._print_FiniteSetc                    s.   t |td}d fdd|D }d|S )Nrw   r[   c                 3   s   | ]}  |V  qd S r3   r_   r   ra   r&   r'   r   ?  r.   z.StrPrinter._print_Partition.<locals>.<genexpr>zPartition({}))rz   r   r/   r   rm  r&   ra   r'   _print_Partition<  s    zStrPrinter._print_Partitionc                 C   s   |sdS d|  | S )Nzfrozenset()zfrozenset(%s))rn  r"   rp   r&   r&   r'   _print_frozensetB  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   ra   r&   r'   r   H  s    z)StrPrinter._print_Sum.<locals>._xab_tostrr[   c                    s   g | ]} |qS r&   r&   r   r   r&   r'   r-   M  r.   z)StrPrinter._print_Sum.<locals>.<listcomp>zSum(%s, %s)r   r   r&   r   r'   
_print_SumG  s    zStrPrinter._print_Sumc                 C   s   |j S r3   r   r7   r&   r&   r'   _print_SymbolP  s    zStrPrinter._print_Symbolc                 C   s   dS r   r&   r7   r&   r&   r'   _print_IdentityU  s    zStrPrinter._print_Identityc                 C   s   dS )N0r&   r7   r&   r&   r'   _print_ZeroMatrixX  s    zStrPrinter._print_ZeroMatrixc                 C   s   dS )Nr   r&   r7   r&   r&   r'   _print_OneMatrix[  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   rL  r7   r&   r&   r'   
_print_stra  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_tupled  s    zStrPrinter._print_tuplec                 C   s
   |  |S r3   )r{  r7   r&   r&   r'   _print_Tuplej  s    zStrPrinter._print_Tuplec                 C   s   d|  |jtd  S )Nz%s.Tr   r   )r"   Tr&   r&   r'   _print_Transposem  s    zStrPrinter._print_Transposec                 C   s   d|  |j|  |jf S )NzUniform(%s, %s))r!   r   r   r7   r&   r&   r'   _print_Uniformp  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_Quantitys  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   rk   ra   r&   r'   r-   y  r.   z0StrPrinter._print_Quaternion.<locals>.<listcomp>r   c                 S   s   g | ]\}}|d  | qS )r   r&   )r+   rU   rT   r&   r&   r'   r-   z  r.   r   Zijkz + )r0   zipr/   )r"   r8   rp   r   r&   ra   r'   _print_Quaternionx  s    &zStrPrinter._print_Quaternionc                 C   s   t |S r3   rL  r7   r&   r&   r'   _print_Dimension}  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)rv  )r  r  r7   r&   r&   r'   _print_Zero  s    zStrPrinter._print_Zeroc                 C   sr   z"|j d ur | |j |W S W n ty4   Y n0 |jj}| |j}| |j}| |j }d||||f S )Nz%s(%s, %s, %s))r%  r!   Zto_sympyr   rb   rc   repdom)r"   r   rk  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 )NrZ   ZTrr   r@  r7   r&   r&   r'   	_print_Tr  s    zStrPrinter._print_Trc                 C   s   |  |jS r3   r  rq  r&   r&   r'   
_print_Str  s    zStrPrinter._print_Strc                 C   s*   |j }d| || |j| |jf S )Nr_  )r\   r!   r`  rQ   )r"   r8   relr&   r&   r'   _print_AppliedBinaryRelation  s
    


z'StrPrinter._print_AppliedBinaryRelation)F)r   )N)F)rc   
__module____qualname__r>  Z_default_settingsdictra  r(   r2   r9   rG   rI   rK   rM   rV   rX   rY   r^   rd   rh   ri   rj   rq   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  r  r  r  r  r  r  r  r  r!  r&  r*  r,  r/  r1  r5  r;  r<  r=  r?  rA  rB  rC  rD  rE  rF  rG  rH  rI  rJ  rK  rM  rN  rO  rP  rU  rV  r]  rc  re  rf  rl  rn  ro  rp  rr  rs  rt  Z_print_MatrixSymbolZ_print_RandomSymbolru  rw  rx  ry  rz  r{  r|  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r&   r&   r&   r'   r      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   rp   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   rq  r&   r&   r'   rz    s    zStrReprPrinter._print_strc                 C   s   d|j j| |jf S )NrZ   )rb   rc   r!   r   rq  r&   r&   r'   r    s    zStrReprPrinter._print_StrN)rc   r  r  __doc__rz  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  typingr   r   ZtDictZ
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.sets.setsr   Zsympy.utilities.iterablesr   r   r   printerr   r   Zmpmath.libmpr   r   rX  r   r  r  r  r&   r&   r&   r'   <module>   s0           I
