B
    [l                 @   s   d Z ddlmZmZ ddl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mZ ddlmZ dd	lmZ dd
lmZ G dd deZdd ZG dd deZdd ZdS )zI
A Printer for generating readable representation of most sympy classes.
    )print_functiondivision)SRationalPowBasicMul)_keep_coeff   )Printer)
precedence
PRECEDENCEN)prec_to_dps)default_sort_keyc               @   s$  e Zd ZdZdddddZe ZdddZdd	d
Zdd Z	dd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d/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Z d;d< Z!d=d> Z"d?d@ Z#dAdB Z$dCdD Z%dEdF Z&dGdH Z'dIdJ Z(dKdL Z)dMdN Z*dOdP Z+dQdR Z,dSdT Z-e- Z. Z/ Z0 Z1 Z2 Z3 Z4Z5dUdV Z6dWdX Z7dYdZ Z8d[d\ Z9d]d^ Z:d_d` Z;dadb Z<dcdd Z=dedf Z>dgdh Z?didj Z@dkdl ZAdmdn ZBdodp ZCdqdr ZDdsdt ZEdudv ZFdwdx ZGdydz ZHd{d| ZId}d~ ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSddd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 Zjdd Zkdd Z.ddĄ ZlddƄ ZmemZnemZoddȄ 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 Zdd Zdd Zdd Zdd Zdd ZdS )
StrPrinterZ	_sympystrNautoF)order	full_precsympy_integersabbrevc             C   s8   t ||k s|s*t ||kr*d| | S | |S d S )Nz(%s))r   _print)selfitemlevelstrict r   1lib/python3.7/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   r   	stringify#   s    zStrPrinter.stringifyc             C   s:   t |tr|S t |tr.t|dr*t|S  nt|S d S )Nr!   )
isinstancestrr   hasattrrepr)r   exprr   r   r   emptyPrinter&   s    


zStrPrinter.emptyPrinterc       	      C   s   | j dkrt|j}n| j||d}t|}g }xd|D ]\}| |}|dr`d}|dd  }nd}t||k r||d| g q6|||g q6W |d}|dkrd}|d		| S )
Nnone)r   -r
   +z(%s)r     )
r   listr!   Z_as_ordered_termsr   r   
startswithextendpopr    )	r   r(   r   termsPREClZtermtsignr   r   r   
_print_Add1   s$    




zStrPrinter._print_Addc             C   s   dS )NTruer   )r   r(   r   r   r   _print_BooleanTrueI   s    zStrPrinter._print_BooleanTruec             C   s   dS )NFalser   )r   r(   r   r   r   _print_BooleanFalseL   s    zStrPrinter._print_BooleanFalsec             C   s   d|  |jd td  S )Nz~%sr   ZNot)r   r!   r   )r   r(   r   r   r   
_print_NotO   s    zStrPrinter._print_Notc             C   s   |  |jdtd S )Nz & Z
BitwiseAnd)r#   r!   r   )r   r(   r   r   r   
_print_AndR   s    zStrPrinter._print_Andc             C   s   |  |jdtd S )Nz | Z	BitwiseOr)r#   r!   r   )r   r(   r   r   r   	_print_OrU   s    zStrPrinter._print_Orc             C   s   d|  |j|  |jf S )Nz%s(%s))r   funcarg)r   r(   r   r   r   _print_AppliedPredicateX   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   \   s    z+StrPrinter._print_Basic.<locals>.<listcomp>z(%s)z, )r!   	__class____name__r    )r   r(   r5   r   )r   r   _print_Basic[   s    zStrPrinter._print_Basicc             C   s(   |j jdkr| |j d  | |j S )N)r
   r
   )r   r   )Zblocksshaper   )r   Br   r   r   _print_BlockMatrix_   s    zStrPrinter._print_BlockMatrixc             C   s   dS )NZCatalanr   )r   r(   r   r   r   _print_Cataland   s    zStrPrinter._print_Catalanc             C   s   dS )NZzoor   )r   r(   r   r   r   _print_ComplexInfinityg   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   )r   )r   i)r   r   r   r   k   s    z2StrPrinter._print_ConditionSet.<locals>.<listcomp>zConditionSet(%s, %s)zConditionSet(%s, %s, %s))tupleZsymZ	conditionZbase_setr   ZUniversalSetr   )r   sr!   r   )r   r   _print_ConditionSetj   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   )r   rL   r   r   r   r   s   s    z0StrPrinter._print_Derivative.<locals>.<listcomp>zDerivative(%s)z, c                s
     | S )N)r   )rA   )r   r   r   <lambda>t   s    z.StrPrinter._print_Derivative.<locals>.<lambda>)r(   Zvariable_countr    map)r   r(   ZdexprZdvarsr   )r   r   _print_Derivativeq   s    zStrPrinter._print_Derivativec             C   sV   t | td}g }x2|D ]*}d| || || f }|| qW dd| S )N)keyz%s: %sz{%s}z, )sortedkeysr   r   appendr    )r   drU   itemsrS   r   r   r   r   _print_dictv   s    
zStrPrinter._print_dictc             C   s
   |  |S )N)rY   )r   r(   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 )r&   r   r[   symbolsr\   )r   rW   r   r   r   _print_RandomDomain   s    

zStrPrinter._print_RandomDomainc             C   s
   d|j  S )N_)name)r   r(   r   r   r   _print_Dummy   s    zStrPrinter._print_Dummyc             C   s   dS )NZ
EulerGammar   )r   r(   r   r   r   _print_EulerGamma   s    zStrPrinter._print_EulerGammac             C   s   dS )NEr   )r   r(   r   r   r   _print_Exp1   s    zStrPrinter._print_Exp1c             C   s   d|  |j|  |jf S )Nz(%s, %s))r   r(   Zcond)r   r(   r   r   r   _print_ExprCondPair   s    zStrPrinter._print_ExprCondPairc                s\   t |td}t|dkr8|d d dg |dd   }n|}dd fdd	|D  d
 S )N)rS   
      z...{z, c             3   s   | ]}  |V  qd S )N)r   )r   Zel)r   r   r   	<genexpr>   s    z.StrPrinter._print_FiniteSet.<locals>.<genexpr>})rT   r   lenr    )r   rN   Zprintsetr   )r   r   _print_FiniteSet   s
     zStrPrinter._print_FiniteSetc             C   s   |j jd| |jd  S )Nz(%s)z, )r@   rE   r#   r!   )r   r(   r   r   r   _print_Function   s    zStrPrinter._print_Functionc             C   s   t |S )N)r%   )r   r(   r   r   r   _print_GeometryEntity   s    z StrPrinter._print_GeometryEntityc             C   s   dS )NZGoldenRatior   )r   r(   r   r   r   _print_GoldenRatio   s    zStrPrinter._print_GoldenRatioc             C   s   dS )NZTribonacciConstantr   )r   r(   r   r   r   _print_TribonacciConstant   s    z$StrPrinter._print_TribonacciConstantc             C   s   dS )NIr   )r   r(   r   r   r   _print_ImaginaryUnit   s    zStrPrinter._print_ImaginaryUnitc             C   s   dS )NZoor   )r   r(   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   )rl   r   rM   )xab)r   r   r   
_xab_tostr   s    z.StrPrinter._print_Integral.<locals>._xab_tostrz, c                s   g | ]} |qS r   r   )r   r5   )rv   r   r   r      s    z.StrPrinter._print_Integral.<locals>.<listcomp>zIntegral(%s, %s))r    limitsr   function)r   r(   Lr   )rv   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)r!   Zis_infiniteformat)r   rL   Zfinr{   r|   r5   rr}   r   r   r   _print_Interval   s     

zStrPrinter._print_Intervalc             C   s   d|  |j|  |jf S )NzAccumBounds(%s, %s))r   minmax)r   rL   r   r   r   _print_AccumulationBounds   s    z$StrPrinter._print_AccumulationBoundsc             C   s   d|  |jtd  S )Nz%s^-1r   )r   rA   r   )r   rr   r   r   r   _print_Inverse   s    zStrPrinter._print_Inversec                sb   |j \}}t|dkr4d |j d  |f S d fdd|D }d| |f S d S )Nr
   zLambda(%s, %s)r   z, c             3   s   | ]}  |V  qd S )N)r   )r   rA   )r   r   r   rj      s    z+StrPrinter._print_Lambda.<locals>.<genexpr>zLambda((%s), %s))r!   rl   r   r    )r   objr!   r(   Z
arg_stringr   )r   r   _print_Lambda   s
    
zStrPrinter._print_Lambdac                s2   t |jtd}|jjdd fdd|D   S )N)rS   z(%s)z, c             3   s   | ]}  |V  qd S )N)r   )r   rA   )r   r   r   rj      s    z.StrPrinter._print_LatticeOp.<locals>.<genexpr>)rT   r!   r   r@   rE   r    )r   r(   r!   r   )r   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'))r!   r%   rM   rQ   r   )r   r(   ezZz0dirr   r   r   _print_Limit   s
    
zStrPrinter._print_Limitc             C   s   d|  |d S )Nz[%s]z, )r#   )r   r(   r   r   r   _print_list   s    zStrPrinter._print_listc             C   s
   | | S )N)Z_format_str)r   r(   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   rL   j)r   r(   r   r   r   _print_MatrixElement   s    zStrPrinter._print_MatrixElementc                s8    fdd}  |jd ||j d ||j d S )Nc                s`   t | } | d dkr| d= | d | d d kr4| d= | d dkrHd| d< dt fdd| S )N   r
   r   r-   :c                s
     | S )N)r   )rA   )r   r   r   rP     s    zAStrPrinter._print_MatrixSlice.<locals>.strslice.<locals>.<lambda>)r/   r    rQ   )x)r   r   r   strslice   s    z/StrPrinter._print_MatrixSlice.<locals>.strslice[z, ])r   r   ZrowsliceZcolslice)r   r(   r   r   )r   r   _print_MatrixSlice   s    zStrPrinter._print_MatrixSlicec             C   s   |j S )N)r`   )r   r(   r   r   r   _print_DeferredVector  s    z StrPrinter._print_DeferredVectorc                s  t | | \}}|dk r.t| |}d}nd}g }g }g }jdkrR| }n
t|}x|D ]}	|	jr|	jr|	j	j
r|	j	jr|	j	dkr|t|	j|	j	 dd n@t|	jd jdkrt|	jtr||	 |t|	j|	j	  qb|	j
r8|	tjk	r8|	jdkr|t|	j |	jdkrB|t|	j qb||	 qbW |pRtjg} fd	d
|D }
 fdd
|D }x:|D ]2}	|	j|krd|||	j  |||	j< qW t|dkr|d|
 S t|dkr|d|
 d |d  S |d|
 dd|  S d S )Nr   r+   r-   )oldr*   F)Zevaluater
   c                s   g | ]}j | d dqS )F)r   )r   )r   r   )precr   r   r   r   7  s    z)StrPrinter._print_Mul.<locals>.<listcomp>c                s   g | ]}j | d dqS )F)r   )r   )r   r   )r   r   r   r   r   8  s    z(%s)*/z/(%s))r   Zas_coeff_Mulr	   r   Zas_ordered_factorsr   Z	make_argsis_commutativeZis_Powexpis_RationalZis_negativerV   r   baserl   r!   r$   r   ZInfinitypr   qOneindexr    )r   r(   cr   r7   r{   r|   Z	pow_parenr!   r   Za_strZb_strr   )r   r   r   
_print_Mul  sH    




 

&zStrPrinter._print_Mulc                sP      \}}|jr,|dk r,t| | d}nd}|d fdd jD  S )Nr   r+   r-   r   c                s   g | ]} |t qS r   )r   r   )r   rA   )r(   r   r   r   r   O  s    z,StrPrinter._print_MatMul.<locals>.<listcomp>)Zas_coeff_mmulZ	is_numberr	   r    r!   )r   r(   r   r}   r7   r   )r(   r   r   _print_MatMulF  s    zStrPrinter._print_MatMulc                s   d  fdd jD S )Nz.*c                s   g | ]} |t qS r   )r   r   )r   rA   )r(   r   r   r   r   S  s   z5StrPrinter._print_HadamardProduct.<locals>.<listcomp>)r    r!   )r   r(   r   )r(   r   r   _print_HadamardProductR  s    z!StrPrinter._print_HadamardProductc                sz    fdd j D }g }x:|D ]2}|dr@d}|dd  }nd}|||g q W |d}|dkrld}|d| S )	Nc                s   g | ]} |t qS r   )r   r   )r   rA   )r(   r   r   r   r   W  s   z,StrPrinter._print_MatAdd.<locals>.<listcomp>r+   r
   r,   r   r-   r.   )r!   r0   r1   r2   r    )r   r(   r3   r5   r6   r7   r   )r(   r   r   _print_MatAddV  s    



zStrPrinter._print_MatAddc             C   s   dS )Nnanr   )r   r(   r   r   r   
_print_NaNf  s    zStrPrinter._print_NaNc             C   s   dS )Nz-oor   )r   r(   r   r   r   _print_NegativeInfinityi  s    z"StrPrinter._print_NegativeInfinityc             C   s   d|  |j|  |jf S )NzNormal(%s, %s))r   ZmuZsigma)r   r(   r   r   r   _print_Normall  s    zStrPrinter._print_Normalc             C   sr   t dd |jD st|jsZt|jdkr<d| |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 )N)r   ZZero)r   r   r   r   r   rj   p  s    z*StrPrinter._print_Order.<locals>.<genexpr>r
   zO(%s)z, r   )allZpointrl   Z	variablesr   r(   r#   r!   )r   r(   r   r   r   _print_Ordero  s
    zStrPrinter._print_Orderc             C   s   |  S )N)__str__)r   r(   r   r   r   _print_Ordinalx  s    zStrPrinter._print_Ordinalc             C   s   |  S )N)r   )r   r(   r   r   r   _print_Cycle{  s    zStrPrinter._print_Cyclec       	      C   s   ddl m}m} |jr|js dS |||jd  tdd  }|d}|dks|d||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 r|}d
| S d S )Nr   )PermutationCyclez()r
   r   (,r-      zPermutation(%s)zPermutation([], size=%s)r   z	, size=%s)Z sympy.combinatorics.permutationsr   r   Zprint_cyclicsize__repr__rl   rfindreplaceZsupportr   Z
array_form)	r   r(   r   r   rN   ZlastZtrimZuseZfullr   r   r   _print_Permutation~  s(    "

,zStrPrinter._print_Permutationc             C   s   |  S )N)r   )r   r(   r   r   r   _print_TensorIndex  s    zStrPrinter._print_TensorIndexc             C   s   |  S )N)r   )r   r(   r   r   r   _print_TensorHead  s    zStrPrinter._print_TensorHeadc             C   s   |  S )N)r   )r   r(   r   r   r   _print_Tensor  s    zStrPrinter._print_Tensorc             C   s   |  S )N)r   )r   r(   r   r   r   _print_TensMul  s    zStrPrinter._print_TensMulc             C   s   |  S )N)r   )r   r(   r   r   r   _print_TensAdd  s    zStrPrinter._print_TensAddc                s"    fdd|j D }dd| S )Nc                s   g | ]}d   | qS )z    %s)r   )r   r{   )r   r   r   r     s    z6StrPrinter._print_PermutationGroup.<locals>.<listcomp>zPermutationGroup([
%s])z,
)r!   r    )r   r(   r   r   )r   r   _print_PermutationGroup  s    z"StrPrinter._print_PermutationGroupc             C   sD   d|  |jjd |  |jjd |  |jd |  |jd f S )NzPDF(%s, (%s, %s, %s))r
   r   )r   Zpdfr!   domain)r   r(   r   r   r   
_print_PDF  s     zStrPrinter._print_PDFc             C   s   dS )NZpir   )r   r(   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 orderz, c                s
     | S )N)r   )Zrs)r   r   r   rP     s    z,StrPrinter._print_PolyRing.<locals>.<lambda>)r    rQ   r]   r   r   r   )r   ringr   )r   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 orderz, c                s
     | S )N)r   )Zfs)r   r   r   rP     s    z-StrPrinter._print_FracField.<locals>.<lambda>)r    rQ   r]   r   r   r   )r   fieldr   )r   r   _print_FracField  s    zStrPrinter._print_FracFieldc             C   s   |  S )N)r   )r   Zelmr   r   r   _print_FreeGroupElement  s    z"StrPrinter._print_FreeGroupElementc             C   s   | | tddS )Nz%s**%sr   )r%   r   )r   Zpolyr   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   T)r   r   r   )denomr   numerr   r   )r   Zfracr   r   r   r   r   _print_FracElement  s
    
zStrPrinter._print_FracElementc                sb  t d d  g  fdd|jD  }}x&| D ]\}}g }xJt|D ]>\}}|dkrL|dkrt|||  qL||| d|   qLW d|}|jr|rd| d	 }	n
|}	nB|r|tj	kr|
d
|g q4|tjkr|
d|g q4|}	|s|	}
n|	d | }
|
dr@|
d|
dd  g q4|
d
|
g q4W |d dkr|d}|dkrd|d  |d< |jjd }ddlm} y|d|  7 }W n& |k
r   |d|  7 }Y nX |d	7 }xht|D ]\\}}t|dkr|d d dkr|t|d d  d	kr|dt|d  ||< qW |d|d|f S )Nr   r
   c                s   g | ]} | qS r   )r   )r   rN   )	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.   z, )r   gensr3   	enumeraterV   r    Zis_Addr   r   r   r1   ZNegativeOner0   r2   rD   rE   Zsympy.polys.polyerrorsr   Zget_modulusZ
get_domainrl   )r   r(   r3   r   ZmonomZcoeffZs_monomrL   r   Zs_coeffZs_termZmodifierr~   r   r   r   r   )r   r   r   _print_Poly  sV    





:zStrPrinter._print_Polyc                s   d  fdd|jD S )Nz x c             3   s   | ]}  |V  qd S )N)r   )r   r\   )r   r   r   rj     s    z/StrPrinter._print_ProductSet.<locals>.<genexpr>)r    Zsets)r   r   r   )r   r   _print_ProductSet  s    zStrPrinter._print_ProductSetc             C   s*   |j r| |  S | | S d S )N)Z
is_aliasedr   Zas_polyZas_expr)r   r(   r   r   r   _print_AlgebraicNumber  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t fddtj	|jf 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 )Nzsqrt(%s)z%s/sqrt(%s)c                s
     | S )N)r   )rA   )r   r   r   rP     s    z'StrPrinter._print_Pow.<locals>.<lambda>z%s/%sF)r   Z
_sympyreprr
   z	(Rationalz%s**%sr   )r   r   r   ZHalfr   r   r   rM   rQ   r   r   printmethodr   r   r0   )r   r(   Zrationalr4   r   r   )r   r   
_print_Pow  s    "
"zStrPrinter._print_Powc             C   s   |  |jd S )Nr   )r   r!   )r   r(   r   r   r   _print_UnevaluatedExpr-  s    z!StrPrinter._print_UnevaluatedExprc             C   s0   t |}d| j|j|dd| j|j|ddf S )Nz%s**%sF)r   )r   r   r   r   )r   r(   r4   r   r   r   _print_MatPow0  s    zStrPrinter._print_MatPowc             C   s   t |S )N)r%   )r   r(   r   r   r   _print_ImmutableDenseNDimArray5  s    z)StrPrinter._print_ImmutableDenseNDimArrayc             C   s   t |S )N)r%   )r   r(   r   r   r   _print_ImmutableSparseNDimArray8  s    z*StrPrinter._print_ImmutableSparseNDimArrayc             C   s    | j ddrd| S t|jS )Nr   FzS(%s))	_settingsgetr%   r   )r   r(   r   r   r   _print_Integer;  s    zStrPrinter._print_Integerc             C   s   dS )NZIntegersr   )r   r(   r   r   r   _print_Integers@  s    zStrPrinter._print_Integersc             C   s   dS )NZNaturalsr   )r   r(   r   r   r   _print_NaturalsC  s    zStrPrinter._print_Naturalsc             C   s   dS )NZ	Naturals0r   )r   r(   r   r   r   _print_Naturals0F  s    zStrPrinter._print_Naturals0c             C   s   dS )NZRealsr   )r   r(   r   r   r   _print_RealsI  s    zStrPrinter._print_Realsc             C   s   t |S )N)r%   )r   r(   r   r   r   
_print_intL  s    zStrPrinter._print_intc             C   s   t |S )N)r%   )r   r(   r   r   r   
_print_mpzO  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)/%sz%s/%s)r   r%   r   r   r   )r   r(   r   r   r   _print_RationalR  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   r%   r   )r   r(   r   r   r   _print_PythonRationalZ  s    

z StrPrinter._print_PythonRationalc             C   s(   |j dkrt|jS d|j|j f S d S )Nr
   z%s/%s)denominatorr%   	numerator)r   r(   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 )Nr
   z%s/%s)r   r%   r   )r   r(   r   r   r   
_print_mpqf  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}tj|j||d}|d	rd
|dd   }n|drd|dd   }|dr|dd  }|S )Nr   r   r   TFr   r
   )Zstrip_zerosz-.0z-0.rg   z.0z0.r   r,   )Z_precr   r   Z_print_levelmlibZto_strZ_mpf_r0   )r   r(   r   Zdpsstriprvr   r   r   _print_Floatl  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 )NZEqZNeZ
AssignmentZAddAugmentedAssignmentZSubAugmentedAssignmentZMulAugmentedAssignmentZDivAugmentedAssignmentZModAugmentedAssignment)z==z!=z:=z+=z-=z*=z/=z%=z
%s(%s, %s)z%s %s %s)Zrel_opr   ZlhsZrhsr   r   _relationalsr   )r   r(   charmapr   r   r   _print_Relational  s    
zStrPrinter._print_Relationalc             C   s   d| j |jdd|jf S )NzCRootOf(%s, %d)lex)r   )r8   r(   r   )r   r(   r   r   r   _print_ComplexRootOf  s    zStrPrinter._print_ComplexRootOfc             C   s>   | j |jddg}|jtjk	r0|| |j dd| S )Nr   )r   zRootSum(%s)z, )r8   r(   Zfunr   ZIdentityFunctionrV   r   r    )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   )r8   r   )r   rA   )basisr   r   r   r     s    z3StrPrinter._print_GroebnerBasis.<locals>.<listcomp>z[%s]z, c                s   g | ]}  |qS r   )r   )r   gen)r   r   r   r     s    zdomain='%s'z
order='%s'z%s(%s))rD   rE   exprsr    r   r   r   r   )r   r   clsr   r   r   r   r!   r   )r   r   r   _print_GroebnerBasis  s    zStrPrinter._print_GroebnerBasisc             C   s   d|  |dd S )NzSample([%s])z, r   )r#   )r   r(   r   r   r   _print_Sample  s    zStrPrinter._print_Samplec                s4   t |td}d fdd|D }|s,dS d| S )N)rS   z, c             3   s   | ]}  |V  qd S )N)r   )r   r   )r   r   r   rj     s    z(StrPrinter._print_set.<locals>.<genexpr>zset()z{%s})rT   r   r    )r   rN   rX   r!   r   )r   r   
_print_set  s
    zStrPrinter._print_setc             C   s   |sdS d|  | S )Nzfrozenset()zfrozenset(%s))r   )r   rN   r   r   r   _print_frozenset  s    zStrPrinter._print_frozensetc             C   s   ddl m} | ||S )Nr   )Matrix)Zsympy.matricesr   r   )r   r(   r   r   r   r   _print_SparseMatrix  s    zStrPrinter._print_SparseMatrixc                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   )rl   r   rM   )ru   )r   r   r   rv     s    z)StrPrinter._print_Sum.<locals>._xab_tostrz, c                s   g | ]} |qS r   r   )r   r5   )rv   r   r   r     s    z)StrPrinter._print_Sum.<locals>.<listcomp>zSum(%s, %s))r    rw   r   rx   )r   r(   ry   r   )rv   r   r   
_print_Sum  s    zStrPrinter._print_Sumc             C   s   |j S )N)r`   )r   r(   r   r   r   _print_Symbol  s    zStrPrinter._print_Symbolc             C   s   dS )Nrr   r   )r   r(   r   r   r   _print_Identity  s    zStrPrinter._print_Identityc             C   s   dS )N0r   )r   r(   r   r   r   _print_ZeroMatrix  s    zStrPrinter._print_ZeroMatrixc             C   s
   d|j  S )NzQ.%s)r`   )r   r(   r   r   r   _print_Predicate  s    zStrPrinter._print_Predicatec             C   s   t |S )N)r%   )r   r(   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   z(%s)z, )rl   r   r#   )r   r(   r   r   r   _print_tuple  s    zStrPrinter._print_tuplec             C   s
   |  |S )N)r	  )r   r(   r   r   r   _print_Tuple  s    zStrPrinter._print_Tuplec             C   s   d|  |jtd  S )Nz%s.Tr   )r   rA   r   )r   Tr   r   r   _print_Transpose  s    zStrPrinter._print_Transposec             C   s   d|  |j|  |jf S )NzUniform(%s, %s))r   r{   r|   )r   r(   r   r   r   _print_Uniform  s    zStrPrinter._print_Uniformc                s   dd  fdd|jD  S )Nz	Union(%s)z, c                s   g | ]}  |qS r   )r   )r   r{   )r   r   r   r     s    z+StrPrinter._print_Union.<locals>.<listcomp>)r    r!   )r   r(   r   )r   r   _print_Union  s    zStrPrinter._print_Unionc                s   d  fdd|jD S )Nz \ c             3   s   | ]}  |V  qd S )N)r   )r   Zset_)r   r   r   rj     s    z/StrPrinter._print_Complement.<locals>.<genexpr>)r    r!   )r   r(   r   )r   r   _print_Complement  s    zStrPrinter._print_Complementc             C   s"   | j ddrd|j S d|j S )Nr   Fz%s)r   r   r   r`   )r   r(   r   r   r   _print_Quantity  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   T)r   )r   r   )r   rL   )r   r   r   r     s    z0StrPrinter._print_Quaternion.<locals>.<listcomp>r   c             S   s   g | ]\}}|d  | qS )r   r   )r   rL   r   r   r   r   r     s    r
   Zijkz + )r!   zipr    )r   r(   rN   r{   r   )r   r   _print_Quaternion  s    &zStrPrinter._print_Quaternionc             C   s   t |S )N)r%   )r   r(   r   r   r   _print_Dimension  s    zStrPrinter._print_Dimensionc             C   s
   |j d S )Nr_   )r`   )r   r(   r   r   r   _print_Wild  s    zStrPrinter._print_Wildc             C   s
   |j d S )Nr_   )r`   )r   r(   r   r   r   _print_WildFunction  s    zStrPrinter._print_WildFunctionc             C   s   | j ddrdS dS )Nr   FzS(0)r  )r   r   )r   r(   r   r   r   _print_Zero  s    zStrPrinter._print_Zeroc             C   s~   ddl m} y |jd k	r*| |j|S W n |k
r@   Y nX |jj}| |j}| |j}| |j}d||||f S )Nr   )SympifyErrorz%s(%s, %s, %s))	Zsympy.core.sympifyr  r   r   Zto_sympyrD   rE   repdom)r   r   r  r   r  r  r   r   r   r   
_print_DMP  s    
zStrPrinter._print_DMPc             C   s
   |  |S )N)r  )r   r(   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   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   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|j S )N)
_coord_sys_names_index)r   r   r   r   r   _print_BaseScalarField,  s    z!StrPrinter._print_BaseScalarFieldc             C   s   d|j j|j  S )Nze_%s)r"  r#  r$  )r   r   r   r   r   _print_BaseVectorField/  s    z!StrPrinter._print_BaseVectorFieldc             C   s4   |j }t|dr"d|jj|j  S d| | S d S )Nr"  zd%szd(%s))Z_form_fieldr&   r"  r#  r$  r   )r   Zdiffr   r   r   r   _print_Differential2  s    
zStrPrinter._print_Differentialc             C   s   dd|  |jd f S )Nz%s(%s)ZTrr   )r   r!   )r   r(   r   r   r   	_print_Tr9  s    zStrPrinter._print_Tr)F)r   )N)F)rE   
__module____qualname__r   Z_default_settingsdictr   r   r#   r)   r8   r:   r<   r=   r>   r?   rB   rF   rI   rJ   rK   rO   rR   rY   rZ   r^   ra   rb   rd   re   rm   rn   ro   rp   rq   rs   rt   rz   r   r   r   r   r   r   r   r   r  Z_print_MutableSparseMatrixZ_print_ImmutableSparseMatrixZ_print_MatrixZ_print_DenseMatrixZ_print_MutableDenseMatrixZ_print_ImmutableMatrixZ_print_ImmutableDenseMatrixr   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   r   r   r   r   r  r  Z_print_MatrixSymbolZ_print_RandomSymbolr  r  r  r  r	  r
  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r%  r&  r'  r(  r   r   r   r   r      s  



		
 8	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)r(   settingsr   rN   r   r   r   sstr>  s    
r.  c               @   s   e Zd ZdZdd ZdS )StrReprPrinterz(internal) -- see sstrreprc             C   s   t |S )N)r'   )r   rN   r   r   r   r  W  s    zStrReprPrinter._print_strN)rE   r)  r*  __doc__r  r   r   r   r   r/  T  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   rN   r   r   r   sstrrepr[  s    	
r1  )r0  Z
__future__r   r   Z
sympy.corer   r   r   r   r   Zsympy.core.mulr	   Zprinterr   Zsympy.printing.precedencer   r   Zmpmath.libmpZlibmpr   r   Zsympy.utilitiesr   r   r.  r/  r1  r   r   r   r   <module>   s$         2