a
    RG5d                     @   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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Add)_keep_coeff)
Relational)default_sort_key)SympifyError)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i 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[ Z/d\d] Z0d^d_ Z1d`da Z2dbdc Z3ddde Z4dfdg Z5dhdi Z6djdk Z7dldm Z8dndo Z9dpdq Z:drds Z;dtdu Z<dvdw Z=dxdy Z>dzd{ Z?d|d} Z@d~d ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdddZMdd 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τ ZieiZjeiZkddф Zlddӄ 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 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maxc                 C   s8   t ||k s|s*t ||kr*d| | S | |S d S )N(%s))r   _print)selfitemlevelstrict r'   N/var/www/html/django/DPS/env/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 ]f}| |}|drHd}|dd  }nd}t||k sbt|trv||d| g q|||g q|d}|dkrd}|d| S )	Nr   -r   +r!   r     )	_as_ordered_termsr   r"   
startswithr5   r
   extendpopr0   )	r#   r9   r   termsPRECltermtsignr'   r'   r(   
_print_Add2   s     


zStrPrinter._print_Addc                 C   s   dS )NTruer'   r8   r'   r'   r(   _print_BooleanTrueG   s    zStrPrinter._print_BooleanTruec                 C   s   dS )NFalser'   r8   r'   r'   r(   _print_BooleanFalseJ   s    zStrPrinter._print_BooleanFalsec                 C   s   d|  |jd td  S )Nz~%sr   Not)r)   r1   r   r8   r'   r'   r(   
_print_NotM   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 & 
BitwiseAnd)listr1   	enumerater5   r   	canonicalrhsr   NegativeInfinityinsertrC   r3   r   )r#   r9   r1   jir'   r'   r(   
_print_AndP   s    

zStrPrinter._print_Andc                 C   s   |  |jdtd S )Nz | 	BitwiseOrr3   r1   r   r8   r'   r'   r(   	_print_OrX   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.   c   r/   z+StrPrinter._print_Basic.<locals>.<listcomp>r!   ra   )r1   	__class____name__r0   )r#   r9   rF   r'   rg   r(   _print_Basicb   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_BlockMatrixf   s    zStrPrinter._print_BlockMatrixc                 C   s   dS )NCatalanr'   r8   r'   r'   r(   _print_Catalank   s    zStrPrinter._print_Catalanc                 C   s   dS )Nzoor'   r8   r'   r'   r(   _print_ComplexInfinityn   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'   re   r,   rY   rg   r'   r(   r.   r   r/   z2StrPrinter._print_ConditionSet.<locals>.<listcomp>zConditionSet(%s, %s)zConditionSet(%s, %s, %s))tuplesym	conditionbase_setr   UniversalSetr"   )r#   sr1   r'   rg   r(   _print_ConditionSetq   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'   rs   r'   r'   r(   r.   z   r/   z0StrPrinter._print_Derivative.<locals>.<listcomp>zDerivative(%s)ra   c                    s
     | S r4   re   argrg   r'   r(   <lambda>{   r/   z.StrPrinter._print_Derivative.<locals>.<lambda>)r9   variable_countr0   map)r#   r9   ZdexprZdvarsr'   rg   r(   _print_Derivativex   s    zStrPrinter._print_Derivativec                 C   sR   t | td}g }|D ]*}d| || || f }|| qdd| S )Nkeyz%s: %s{%s}ra   )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!   ra   )funcri   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   ri   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"   rt   xabrg   r'   r(   
_xab_tostr   s    z.StrPrinter._print_Integral.<locals>._xab_tostrra   c                    s   g | ]} |qS r'   r'   r,   rF   r   r'   r(   r.      r/   z.StrPrinter._print_Integral.<locals>.<listcomp>zIntegral(%s, %s)r0   limitsr"   rb   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 i |||dS )NzInterval{m}({a}, {b})r>   z.openz.Lopenz.Ropen)abm)r1   is_infiniteformat)r#   rY   Zfinr   r   rF   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#   rY   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!   ra   c                 3   s   | ]}  |V  qd S r4   re   r,   r|   rg   r'   r(   	<genexpr>   r/   z.StrPrinter._print_LatticeOp.<locals>.<genexpr>)r   r1   r   r   ri   r0   r#   r9   r1   r'   rg   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'))r1   r6   rt   r   r"   )r#   r9   ezz0dirr'   r'   r(   _print_Limit   s    

zStrPrinter._print_Limitc                 C   s   d|  |d S )N[%s]ra   )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"   rY   rX   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t fdd| S )N   r   r   r>   :c                    s
     | S r4   re   r{   rg   r'   r(   r}      r/   zAStrPrinter._print_MatrixSlice.<locals>.strslice.<locals>.<lambda>)rR   r0   r   )xdimrg   r'   r(   strslice   s    z/StrPrinter._print_MatrixSlice.<locals>.strslicer   Tr   [ra   ])r)   r   r   rowslicerowscolslicecols)r#   r9   r   r'   rg   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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 r4   )
is_Integer)r,   air'   r'   r(   r     r/   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(   r}     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.   /  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   )
as_base_exprR   r   	make_argsr   NegativeOne
_from_argsr5   r   r   )rY   r   r   Zeargsr'   r'   r(   apowM  s    

z#StrPrinter._print_Mul.<locals>.apowc                    s   g | ]}j | d dqS r   r*   r,   r   r   r'   r(   r.   n  r/   c                    s   g | ]}j | d dqS r   r*   r   r   r'   r(   r.   o  r/   r!   /z/(%s))#r   r1   r   Oneanyr   rS   r   	is_NumberrR   r   r   r   basecould_extract_minus_signr6   rC   r   r0   r   r   r   as_ordered_factorsr   is_commutativer5   r   r   r   is_RationalInfinitypr   qindex)r#   r9   r1   r   nrY   dir   ZdargsprenfactorsZdfactorscrI   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.     r/   z,StrPrinter._print_MatMul.<locals>.<listcomp>)as_coeff_mmul	is_numberas_real_imagis_zerois_negativer   r0   r1   )r#   r9   r  r   rI   reimr'   r  r(   _print_MatMul}  s    zStrPrinter._print_MatMulc                 C   s   d |j| |jS )Nz{}.({}))r   rb   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u V  qd S r4   )r   Zero)r,   r  r'   r'   r(   r     r/   z*StrPrinter._print_Order.<locals>.<genexpr>r   zO(%s)ra   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 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   )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replacesupportr"   
array_form)r#   r9   r)  r*  r+  r   ry   last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   re   r8   r'   r'   r(   _print_TensorIndex  s    zStrPrinter._print_TensorIndexc                 C   s   |  S r4   re   r8   r'   r'   r(   _print_TensorHead  s    zStrPrinter._print_TensorHeadc                 C   s   |  S r4   re   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.     r/   z-StrPrinter._print_TensMul.<locals>.<listcomp>)!_get_args_for_traditional_printerr0   )r#   r9   rI   r1   r'   r  r(   _print_TensMul  s    zStrPrinter._print_TensMulc                 C   s   |  S r4   re   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]FuncTra   c                    s   g | ]}  |qS r'   re   rs   rg   r'   r(   r.     r/   z2StrPrinter._print_ArrayElement.<locals>.<listcomp>)r)   r   r   r0   indicesr8   r'   rg   r(   _print_ArrayElement  s    *zStrPrinter._print_ArrayElementc                    s"    fdd|j D }dd| S )Nc                    s   g | ]}d   | qS )z    %sre   r   rg   r'   r(   r.     r/   z6StrPrinter._print_PermutationGroup.<locals>.<listcomp>zPermutationGroup([
%s])z,
)r1   r0   )r#   r9   r  r'   rg   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 t fdd|j |j |jf S )Nz+Polynomial ring in %s over %s with %s orderra   c                    s
     | S r4   re   )rsrg   r'   r(   r}     r/   z,StrPrinter._print_PolyRing.<locals>.<lambda>r0   r   r   r"   domainr   )r#   ringr'   rg   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 orderra   c                    s
     | S r4   re   )fsrg   r'   r(   r}     r/   z-StrPrinter._print_FracField.<locals>.<lambda>rU  r#   fieldr'   rg   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#   fracrf  re  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,   ry   Z	ATOM_PRECr#   r'   r(   r.     r/   z*StrPrinter._print_Poly.<locals>.<listcomp>r   z**%dr   r0  )r=   r<   )r<   r=   z(%s, %s)PolynomialErrorz, modulus=%sz, domain='%s'r   r?   ra   )r   gensrD   rS   r   r0   is_Addr"   r   r   rB   r   rA   rC   rh   ri   sympy.polys.polyerrorsrk  get_modulus
get_domainr   )r#   r9   rD   rl  monomcoeffZs_monomrY   r   Zs_coeffZs_termmodifierr   rk  r
  r$   r'   ri  r(   _print_Poly  sV    





:zStrPrinter._print_Polyc                 C   s   dS )Nrx   r'   )r#   r  r'   r'   r(   _print_UniversalSetX  s    zStrPrinter._print_UniversalSetc                 C   s*   |j r| |  S | | S d S r4   )
is_aliasedr"   as_polyas_exprr8   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 r4   re   r{   rg   r'   r(   r}     r/   z'StrPrinter._print_Pow.<locals>.<lambda>r   Fr   Z
_sympyreprr   z	(Rationalrc  r3  )r   r   r   Halfr"   r  r  rt   r   r   r)   printmethodr  r	  rA   )r#   r9   rationalrE   r   r'   rg   r(   
_print_Powa  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 )Nrc  Fr   )r   r)   r  r   )r#   r9   rE   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))r7  r8  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  r7  r8  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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 )Nr2  r   r   TFr   r   r   r    )strip_zeros	min_fixed	max_fixedz-.0z-0.   z.0z0.r   r=   )_precr   r7  _print_levelmlib_to_str_mpf_rA   )r#   r9   r   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EqNe
AssignmentZAddAugmentedAssignmentZSubAugmentedAssignmentZMulAugmentedAssignmentZDivAugmentedAssignmentZModAugmentedAssignment)z==z!=z:=z+=z-=z*=z/=z%=
%s(%s, %s)z%s %s %s)rel_opr"   lhsrU   r)   r   _relationalsr8  )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;   )rJ   r9   r
  r8   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 )Nr  r;   zRootSum(%s)ra   )rJ   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;   )rJ   r   r   basisr#   r'   r(   r.     r/   z3StrPrinter._print_GroebnerBasis.<locals>.<listcomp>r   ra   c                    s   g | ]}  |qS r'   re   )r,   genrg   r'   r(   r.   "  r/   zdomain='%s'z
order='%s'r`   )rh   ri   exprsr0   rl  r"   rV  r   )r#   r  clsr  rl  rV  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   ra   c                 3   s   | ]}  |V  qd S r4   re   r+   rg   r'   r(   r   -  r/   z(StrPrinter._print_set.<locals>.<genexpr>zset()r   )r   r   r0   r#   ry   r   r1   r'   rg   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   ra   c                 3   s   | ]}  |V  qd S r4   re   r+   rg   r'   r(   r   6  r/   z.StrPrinter._print_FiniteSet.<locals>.<genexpr>c                 3   s   | ]}|  V  qd S r4   )hasr+   r  r'   r(   r   7  r/   zFiniteSet({})z{{{}}})sympy.sets.setsr  r   r   r0   r   r   r  r'   )r  r#   r(   _print_FiniteSet2  s    
zStrPrinter._print_FiniteSetc                    s.   t |td}d fdd|D }d|S )Nr   ra   c                 3   s   | ]}  |V  qd S r4   re   r   rg   r'   r(   r   >  r/   z.StrPrinter._print_Partition.<locals>.<genexpr>zPartition({}))r   r   r0   r   r  r'   rg   r(   _print_Partition;  s    zStrPrinter._print_Partitionc                 C   s   |sdS d|  | S )Nzfrozenset()zfrozenset(%s))r  r#   ry   r'   r'   r(   _print_frozensetA  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   rg   r'   r(   r   G  s    z)StrPrinter._print_Sum.<locals>._xab_tostrra   c                    s   g | ]} |qS r'   r'   r   r   r'   r(   r.   L  r/   z)StrPrinter._print_Sum.<locals>.<listcomp>zSum(%s, %s)r   r   r'   r   r(   
_print_SumF  s    zStrPrinter._print_Sumc                 C   s   |j S r4   r   r8   r'   r'   r(   _print_SymbolO  s    zStrPrinter._print_Symbolc                 C   s   dS r   r'   r8   r'   r'   r(   _print_IdentityT  s    zStrPrinter._print_Identityc                 C   s   dS )N0r'   r8   r'   r'   r(   _print_ZeroMatrixW  s    zStrPrinter._print_ZeroMatrixc                 C   s   dS )Nr   r'   r8   r'   r'   r(   _print_OneMatrixZ  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!   ra   )r   r"   r3   r8   r'   r'   r(   _print_tuplec  s    zStrPrinter._print_tuplec                 C   s
   |  |S r4   )r  r8   r'   r'   r(   _print_Tuplei  s    zStrPrinter._print_Tuplec                 C   s   d|  |jtd  S )Nz%s.Tr   r   )r#   Tr'   r'   r(   _print_Transposel  s    zStrPrinter._print_Transposec                 C   s   d|  |j|  |jf S )NzUniform(%s, %s))r"   r   r   r8   r'   r'   r(   _print_Uniformo  s    zStrPrinter._print_Uniformc                 C   s"   | j ddrd|j S d|j S )Nr   Fz%s)r7  r8  r   r   r8   r'   r'   r(   _print_Quantityr  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   rs   rg   r'   r(   r.   x  r/   z0StrPrinter._print_Quaternion.<locals>.<listcomp>r   c                 S   s   g | ]\}}|d  | qS )r   r'   )r,   rY   rX   r'   r'   r(   r.   y  r/   r   Zijkz + )r1   zipr0   )r#   r9   ry   r   r'   rg   r(   _print_Quaternionw  s    &zStrPrinter._print_Quaternionc                 C   s   t |S r4   r  r8   r'   r'   r(   _print_Dimension|  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  )r7  r8  r8   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))rW  r"   to_sympyr   rh   ri   repdom)r#   r  r  r  r  rW  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))rV  r#   morphismr'   r'   r(   _print_IdentityMorphism  s    z"StrPrinter._print_IdentityMorphismc                 C   s   d|j |j|jf S )NzNamedMorphism(%s, %s, "%s"))rV  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   rZ  r'   r'   r(   _print_BaseScalarField  s    z!StrPrinter._print_BaseScalarFieldc                 C   s   d|j j|j j S )Nze_%sr  rZ  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#   diffr[  r'   r'   r(   _print_Differential  s    
zStrPrinter._print_Differentialc                 C   s   dd|  |jd f S )Nr`   ZTrr   r~  r8   r'   r'   r(   	_print_Tr  s    zStrPrinter._print_Trc                 C   s   |  |jS r4   rL  r  r'   r'   r(   
_print_Str  s    zStrPrinter._print_Strc                 C   s*   |j }d| || |j| |jf S )Nr  )rb   r"   r  rU   )r#   r9   relr'   r'   r(   _print_AppliedBinaryRelation  s
    


z'StrPrinter._print_AppliedBinaryRelation)F)r   )N)F)ri   
__module____qualname__r{  _default_settingsr  r)   r3   r:   rJ   rL   rN   rP   rZ   r]   r_   rd   rj   rn   rp   rr   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$  r'  r(  rC  rE  rF  rG  rH  rJ  rK  rM  rP  rQ  rS  rX  r\  r^  rb  rd  rh  rt  ru  ry  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  _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  ry   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 )Nr`   )rh   ri   r"   r   r  r'   r'   r(   r    s    zStrReprPrinter._print_StrN)ri   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	  typingr   r   tDict
sympy.corer   r   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>   s.   $       J
