B
    ed.                 @   sp   d Z ddl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mZ G dd	 d	eZeed
d ZdS )z
A Printer for generating executable code.

The most important function here is srepr that returns a string so that the
relation eval(srepr(expr))=expr holds in an appropriate environment.
    )AnyDict)AppliedUndef)Mul)repr_dpsto_str   )Printerprint_functionc               @   s  e Zd ZdZdddZdd Zdd Zdod	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+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!dpd?d@Z"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOdP Z*dQdR Z+dSdT Z,dUdV Z-dWdX Z.dYdZ Z/d[d\ Z0d]d^ Z1d_d` Z2dadb Z3dcdd Z4dedf Z5dgdh Z6didj Z7dkdl Z8dmdn Z9dS )qReprPrinterZ
_sympyreprNT)orderperm_cyclicc                s   |  fdd|D S )zG
        Prints each item in `args` and joins them with `sep`.
        c                s   g | ]}  |qS  )doprint).0item)selfr   `/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/sympy/printing/repr.py
<listcomp>   s    z'ReprPrinter.reprify.<locals>.<listcomp>)join)r   argssepr   )r   r   reprify   s    zReprPrinter.reprifyc             C   s   t |tr|S t|dr | S t|drpt|jdrpg }x|jD ]}|| | qBW |jjdd	|  S t|drt|drd|j
|jf S t|S d	S )
z'
        The fallback printer.
        	__srepr__r   __iter__z(%s)z, 
__module____name__z	<'%s.%s'>N)
isinstancestrhasattrr   r   append_print	__class__r   r   r   )r   exprlor   r   r   emptyPrinter   s    

zReprPrinter.emptyPrinterc             C   sX   | j ||d}t|}t| j|}t|j}|dkrF|dd|  S |dd|  S )N)r      z(*[%s])z, z(%s))Z_as_ordered_termslenmapr!   typer   r   )r   r#   r   r   nargsclsnamer   r   r   
_print_Add1   s    
zReprPrinter._print_Addc             C   s   |  S )N)__repr__)r   r#   r   r   r   _print_Cycle:   s    zReprPrinter._print_Cyclec             C   sF  ddl m}m} ddlm} |j}|d k	rD|d| ddddd	 n| jd
d}|r|js`dS |||jd 	 t
dd  }|d}|dksd||d  kr||d  |d |  }d| S | }|s|jdk rdt|j S d|j S t|jd |d d  d|j  }t|j }	}
t
|t
|
k r:|}	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Permutation()r   r1   (,zPermutation%s   zPermutation(%s)zPermutation([], size=%s)z	, size=%s)Z sympy.combinatorics.permutationsr0   r1   Zsympy.utilities.exceptionsr2   Zprint_cyclicZ	_settingsgetsizer.   r(   rfindZsupportr   Z
array_form)r   r#   r0   r1   r2   r   slastZtrimZusefullr   r   r   _print_Permutation=   s8    

"


$zReprPrinter._print_Permutationc                s2     |j}|dd fdd|jD  7 }|S )Nz(%s)z, c                s   g | ]}  |qS r   )r!   )r   a)r   r   r   r   g   s    z/ReprPrinter._print_Function.<locals>.<listcomp>)r!   funcr   r   )r   r#   rr   )r   r   _print_Functione   s    "zReprPrinter._print_Functionc                s2     |j}|dd fdd|jD  7 }|S )Nz(%s)z, c                s   g | ]}  |qS r   )r!   )r   r@   )r   r   r   r   n   s    z0ReprPrinter._print_Heaviside.<locals>.<listcomp>)r!   rA   r   Zpargs)r   r#   rB   r   )r   r   _print_Heavisidej   s    "zReprPrinter._print_Heavisidec             C   s   t |trd|j S |jS d S )NzFunction(%r))
issubclassr   r   )r   r#   r   r   r   _print_FunctionClassq   s    

z ReprPrinter._print_FunctionClassc             C   s   dS )NzRational(1, 2)r   )r   r#   r   r   r   _print_Halfw   s    zReprPrinter._print_Halfc             C   s   t |S )N)r   )r   r#   r   r   r   _print_RationalConstantz   s    z#ReprPrinter._print_RationalConstantc             C   s   t |S )N)r   )r   r#   r   r   r   _print_AtomicExpr}   s    zReprPrinter._print_AtomicExprc             C   s   t |S )N)r   )r   r#   r   r   r   _print_NumberSymbol   s    zReprPrinter._print_NumberSymbolc             C   s
   d|j  S )NzInteger(%i))p)r   r#   r   r   r   _print_Integer   s    zReprPrinter._print_Integerc             C   s   dS )NZ	Complexesr   )r   r#   r   r   r   _print_Complexes   s    zReprPrinter._print_Complexesc             C   s   dS )NZIntegersr   )r   r#   r   r   r   _print_Integers   s    zReprPrinter._print_Integersc             C   s   dS )NZNaturalsr   )r   r#   r   r   r   _print_Naturals   s    zReprPrinter._print_Naturalsc             C   s   dS )NZ	Naturals0r   )r   r#   r   r   r   _print_Naturals0   s    zReprPrinter._print_Naturals0c             C   s   dS )NZ	Rationalsr   )r   r#   r   r   r   _print_Rationals   s    zReprPrinter._print_Rationalsc             C   s   dS )NZRealsr   )r   r#   r   r   r   _print_Reals   s    zReprPrinter._print_Realsc             C   s   dS )NZEmptySetr   )r   r#   r   r   r   _print_EmptySet   s    zReprPrinter._print_EmptySetc             C   s   dS )NZUniversalSetr   )r   r#   r   r   r   _print_UniversalSet   s    zReprPrinter._print_UniversalSetc             C   s   dS )NZEmptySequencer   )r   r#   r   r   r   _print_EmptySequence   s    z ReprPrinter._print_EmptySequencec             C   s   d|  |d S )Nz[%s]z, )r   )r   r#   r   r   r   _print_list   s    zReprPrinter._print_listc                s(   d} fdd|  D }d|| S )Nz, c                s(   g | ] \}}d   |  |f qS )z%s: %s)r   )r   keyvalue)r   r   r   r      s    z+ReprPrinter._print_dict.<locals>.<listcomp>z{%s})itemsr   )r   r#   r   Zdict_kvsr   )r   r   _print_dict   s    zReprPrinter._print_dictc             C   s   |sdS d|  |d S )Nzset()z{%s}z, )r   )r   r#   r   r   r   
_print_set   s    zReprPrinter._print_setc             C   s   |j dk|jdkA r>d|jj| |j | |j| g f S g }xFt|j D ]8}|g  x(t|jD ]}|d |||f  qhW qNW d|jj| |f S )Nr   z%s(%s, %s, %s)r8   z%s(%s))rowscolsr"   r   r!   ranger    )r   r#   r$   ijr   r   r   _print_MatrixBase   s    


zReprPrinter._print_MatrixBasec             C   s   dS )Ntruer   )r   r#   r   r   r   _print_BooleanTrue   s    zReprPrinter._print_BooleanTruec             C   s   dS )Nfalser   )r   r#   r   r   r   _print_BooleanFalse   s    zReprPrinter._print_BooleanFalsec             C   s   dS )Nnanr   )r   r#   r   r   r   
_print_NaN   s    zReprPrinter._print_NaNc             C   sh   | j dkr| }n
t|}t|}t| j|}t|j}|dkrV|dd	|  S |dd	|  S )N)oldnoner'   z(*[%s])z, z(%s))
r   Zas_ordered_factorsr   Z	make_argsr(   r)   r!   r*   r   r   )r   r#   r   r   r+   r,   r   r   r   
_print_Mul   s    



zReprPrinter._print_Mulc             C   s   d|  |j|  |jf S )NzRational(%s, %s))r!   rK   q)r   r#   r   r   r   _print_Rational   s    zReprPrinter._print_Rationalc             C   s   d|j j|j|jf S )Nz
%s(%d, %d))r"   r   rK   rk   )r   r#   r   r   r   _print_PythonRational   s    z!ReprPrinter._print_PythonRationalc             C   s   d|  |j|  |jf S )NzFraction(%s, %s))r!   	numeratordenominator)r   r#   r   r   r   _print_Fraction   s    zReprPrinter._print_Fractionc             C   s&   t |jt|j}d|jj||jf S )Nz%s('%s', precision=%i))mlib_to_strZ_mpf_r   Z_precr"   r   )r   r#   rB   r   r   r   _print_Float   s    zReprPrinter._print_Floatc             C   s0   d|  |j|  |j|  |j|  |jf S )NzSum2(%s, (%s, %s, %s)))r!   fr_   r@   b)r   r#   r   r   r   _print_Sum2   s    zReprPrinter._print_Sum2c             C   s   d|j j| |jf S )Nz%s(%s))r"   r   r!   name)r   r<   r   r   r   
_print_Str   s    zReprPrinter._print_Strc             C   sn   |j j}|jr|j|d< |i kr8d|jj| |jf S dd | D }d|jj| |jd	|f S d S )Ndummy_indexz%s(%s)c             S   s   g | ]\}}d ||f qS )z%s=%sr   )r   kvr   r   r   r      s    z-ReprPrinter._print_Symbol.<locals>.<listcomp>z
%s(%s, %s)z, )
_assumptions	generatorZis_Dummyrx   r"   r   r!   rv   rY   r   )r   r#   dattrr   r   r   _print_Symbol   s    
zReprPrinter._print_Symbolc             C   sr   |j j}|i kr2d|jj| |j| |jf S dd | D }d|jj| |j| |jd|f S d S )Nz
%s(%s, %s)c             S   s   g | ]\}}d ||f qS )z%s=%sr   )r   ry   rz   r   r   r   r      s    z7ReprPrinter._print_CoordinateSymbol.<locals>.<listcomp>z%s(%s, %s, %s)z, )	r{   r|   r"   r   r!   Z	coord_sysindexrY   r   )r   r#   r}   r~   r   r   r   _print_CoordinateSymbol   s    


z#ReprPrinter._print_CoordinateSymbolc             C   s
   d|j  S )NzQ.%s)rv   )r   r#   r   r   r   _print_Predicate  s    zReprPrinter._print_Predicatec             C   s   |j }d|jj| |df S )Nz%s(%s)z, )_argsr"   r   r   )r   r#   r   r   r   r   _print_AppliedPredicate	  s    z#ReprPrinter._print_AppliedPredicatec             C   s   t |S )N)repr)r   r#   r   r   r   
_print_str  s    zReprPrinter._print_strc             C   s2   t |dkrd| |d  S d| |d S d S )Nr   z(%s,)r   z(%s)z, )r(   r!   r   )r   r#   r   r   r   _print_tuple  s    zReprPrinter._print_tuplec             C   s   d|j j|jf S )Nz%s('%s'))r"   r   rv   )r   r#   r   r   r   _print_WildFunction  s    zReprPrinter._print_WildFunctionc             C   s$   d|j j| |j| | f S )Nz
%s(%s, %s))r"   r   r!   rootZcoeffs)r   r#   r   r   r   _print_AlgebraicNumber  s    z"ReprPrinter._print_AlgebraicNumberc             C   s,   d|j j| |j| |j| |jf S )Nz%s(%s, %s, %s))r"   r   r!   symbolsdomainr   )r   ringr   r   r   _print_PolyRing  s    zReprPrinter._print_PolyRingc             C   s,   d|j j| |j| |j| |jf S )Nz%s(%s, %s, %s))r"   r   r!   r   r   r   )r   fieldr   r   r   _print_FracField"  s    zReprPrinter._print_FracFieldc             C   s>   t | }|j|jjdd d|jj| |j| |f S )NT)rW   reversez
%s(%s, %s))listtermssortr   r   r"   r   r!   )r   Zpolyr   r   r   r   _print_PolyElement&  s    zReprPrinter._print_PolyElementc             C   sp   t |j }|j|jjdd t |j }|j|jjdd | |}| |}d|jj	| |j||f S )NT)rW   r   z%s(%s, %s, %s))
r   numerr   r   r   r   denomr!   r"   r   )r   fracZnumer_termsZdenom_termsr   r   r   r   r   _print_FracElement+  s    

zReprPrinter._print_FracElementc             C   s    |j j}| |j}d||f S )Nz%s(%s))r"   r   r!   r   )r   r   clsr   r   r   r   _print_FractionField4  s    z ReprPrinter._print_FractionFieldc             C   sZ   |j j}| |j}dt| j|j}t|j}||j	krFd| }nd}d||||f S )Nz, z, order= z%s(%s, %s%s))
r"   r   r!   r   r   r)   gensr   r   Zdefault_order)r   r   r   domr   r   Zorderstrr   r   r   _print_PolynomialRingBase9  s    


z%ReprPrinter._print_PolynomialRingBasec             C   sP   |j j}| |j}| |j}|jd k	r<d| |j }nd}d||||f S )Nz, ring=r   z%s(%s, %s%s))r"   r   r!   repr   r   )r   rK   r   r   r   Zringstrr   r   r   
_print_DMPD  s    
zReprPrinter._print_DMPc             C   s   dt |j S )NzFiniteExtension(%s))r   modulus)r   extr   r   r   _print_MonogenicFiniteExtensionN  s    z+ReprPrinter._print_MonogenicFiniteExtensionc             C   s$   |  |j}|  |j}d||f S )NzExtElem(%s, %s))r!   r   r   )r   rs   r   r   r   r   r   _print_ExtensionElementS  s    z#ReprPrinter._print_ExtensionElement)N)N):r   r   __qualname__ZprintmethodZ_default_settingsr   r&   r-   r/   r?   rC   rD   rF   rG   rH   rI   rJ   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rZ   r[   ra   rc   re   rg   rj   rl   rm   rp   rr   ru   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      sp   
	(
	
r   c             K   s   t || S )zreturn expr in repr form)r   r   )r#   settingsr   r   r   sreprX  s    r   N)__doc__typingr   r   ZtDictZsympy.core.functionr   Zsympy.core.mulr   Zmpmath.libmpr   r   rq   printerr	   r
   r   r   r   r   r   r   <module>   s     I