U
    ZÊ¹j -  ã                   @  sx   d 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 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.
é    )Úannotations)ÚAny)ÚAppliedUndef)ÚMul)Úrepr_dpsÚto_stré   )ÚPrinterÚprint_functionc                   @  sÐ  e Zd ZU dZdddœZded< dd„ Zd	d
„ Zdqd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!d?d@„ Z"drdAdB„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„ Z9dodp„ Z:dS )sÚReprPrinterZ
_sympyreprNT)ÚorderÚperm_cycliczdict[str, Any]Ú_default_settingsc                   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   úR/var/www/html/bwave/python/venv/lib/python3.8/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ƒrlt|jdƒrlg }|jD ]}| |  |¡¡ q@|jjdd 	|¡  S t|dƒr�t|dƒr�d|j
|jf S t|ƒS d	S )
z'
        The fallback printer.
        Ú	__srepr__r   Ú__iter__ú(%s)ú, Ú
__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  s6   | j ||d�}t| j|ƒ}t|ƒj}|dd |¡  S )N)r   r   r   )Z_as_ordered_termsÚmapr&   Útyper!   r   ©r   r(   r   r   Zclsnamer   r   r   Ú
_print_Add2   s    
zReprPrinter._print_Addc                 C  s   |  ¡ S ©N)Ú__repr__©r   r(   r   r   r   Ú_print_Cycle8   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s¼d||d … kr¼||d … |d |…  }d| S | ¡ }|sò|jdk rèd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   r5   ú(ú,zPermutation%sé   zPermutation(%s)zPermutation([], size=%s)éÿÿÿÿz	, size=%s)Z sympy.combinatorics.permutationsr4   r5   Zsympy.utilities.exceptionsr6   Zprint_cyclicZ	_settingsÚgetÚsizer1   ÚlenÚrfindZsupportr#   Z
array_form)r   r(   r4   r5   r6   r   ÚsÚlastZtrimZuseÚfullr   r   r   Ú_print_Permutation;   s>    þù
"


$zReprPrinter._print_Permutationc                   s2   ˆ   |j¡}|dd ‡ fdd„|jD ƒ¡ 7 }|S )Nr   r   c                   s   g | ]}ˆ   |¡‘qS r   ©r&   ©r   Úar   r   r   r   e   s     z/ReprPrinter._print_Function.<locals>.<listcomp>)r&   Úfuncr   r   ©r   r(   Úrr   r   r   Ú_print_Functionc   s    "zReprPrinter._print_Functionc                   s2   ˆ   |j¡}|dd ‡ fdd„|jD ƒ¡ 7 }|S )Nr   r   c                   s   g | ]}ˆ   |¡‘qS r   rE   rF   r   r   r   r   l   s     z0ReprPrinter._print_Heaviside.<locals>.<listcomp>)r&   rH   r   ZpargsrI   r   r   r   Ú_print_Heavisideh   s    "zReprPrinter._print_Heavisidec                 C  s   t |tƒrd|j S |jS d S )NzFunction(%r))Ú
issubclassr   r!   r2   r   r   r   Ú_print_FunctionClasso   s    

z ReprPrinter._print_FunctionClassc                 C  s   dS )NzRational(1, 2)r   r2   r   r   r   Ú_print_Halfu   s    zReprPrinter._print_Halfc                 C  s   t |ƒS r0   ©r#   r2   r   r   r   Ú_print_RationalConstantx   s    z#ReprPrinter._print_RationalConstantc                 C  s   t |ƒS r0   rP   r2   r   r   r   Ú_print_AtomicExpr{   s    zReprPrinter._print_AtomicExprc                 C  s   t |ƒS r0   rP   r2   r   r   r   Ú_print_NumberSymbol~   s    zReprPrinter._print_NumberSymbolc                 C  s
   d|j  S )NzInteger(%i))Úpr2   r   r   r   Ú_print_Integer�   s    zReprPrinter._print_Integerc                 C  s   dS )NZ	Complexesr   r2   r   r   r   Ú_print_Complexes„   s    zReprPrinter._print_Complexesc                 C  s   dS )NZIntegersr   r2   r   r   r   Ú_print_Integers‡   s    zReprPrinter._print_Integersc                 C  s   dS )NZNaturalsr   r2   r   r   r   Ú_print_NaturalsŠ   s    zReprPrinter._print_Naturalsc                 C  s   dS )NZ	Naturals0r   r2   r   r   r   Ú_print_Naturals0�   s    zReprPrinter._print_Naturals0c                 C  s   dS )NZ	Rationalsr   r2   r   r   r   Ú_print_Rationals�   s    zReprPrinter._print_Rationalsc                 C  s   dS )NZRealsr   r2   r   r   r   Ú_print_Reals“   s    zReprPrinter._print_Realsc                 C  s   dS )NZEmptySetr   r2   r   r   r   Ú_print_EmptySet–   s    zReprPrinter._print_EmptySetc                 C  s   dS )NZUniversalSetr   r2   r   r   r   Ú_print_UniversalSet™   s    zReprPrinter._print_UniversalSetc                 C  s   dS )NZEmptySequencer   r2   r   r   r   Ú_print_EmptySequenceœ   s    z ReprPrinter._print_EmptySequencec                 C  s   d|   |d¡ S )Nz[%s]r   ©r   r2   r   r   r   Ú_print_listŸ   s    zReprPrinter._print_listc                   s(   d}‡ fdd„|  ¡ D ƒ}d| |¡ S )Nr   c                   s(   g | ] \}}d ˆ   |¡ˆ   |¡f ‘qS )z%s: %sr   )r   ÚkeyÚvaluer   r   r   r   ¤   s     z+ReprPrinter._print_dict.<locals>.<listcomp>ú{%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()rc   r   r_   r2   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 }t|j ƒD ]4}| g ¡ t|jƒD ]}|d  |||f ¡ qdqLd|jj|  |¡f S )Nr   ú%s(%s, %s, %s)r<   ú%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   r2   r   r   r   Ú_print_BooleanTrueº   s    zReprPrinter._print_BooleanTruec                 C  s   dS )NÚfalser   r2   r   r   r   Ú_print_BooleanFalse½   s    zReprPrinter._print_BooleanFalsec                 C  s   dS )NÚnanr   r2   r   r   r   Ú
_print_NaNÀ   s    zReprPrinter._print_NaNc                 C  sF   | j dkr| ¡ }n
t |¡}t| j|ƒ}t|ƒj}|dd |¡  S )N)ÚoldÚnoner   r   )	r   Zas_ordered_factorsr   Z	make_argsr,   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&   rT   Úqr2   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!   rT   rx   r2   r   r   r   Ú_print_PythonRationalÑ   s    z!ReprPrinter._print_PythonRationalc                 C  s   d|   |j¡|   |j¡f S )NzFraction(%s, %s))r&   Ú	numeratorÚdenominatorr2   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!   rI   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&   Úfrl   rG   Úbr2   r   r   r   Ú_print_Sum2Û   s    
 
ÿzReprPrinter._print_Sum2c                 C  s   d|j j|  |j¡f S ©Nrh   )r'   r!   r&   Úname)r   rA   r   r   r   Ú
_print_Strß   s    zReprPrinter._print_Strc                 C  sl   |j }|jr|j|d< |i kr6d|jj|  |j¡f S dd„ | ¡ D ƒ}d|jj|  |j¡d |¡f S d S )NÚdummy_indexrh   c                 S  s   g | ]\}}d ||f ‘qS ©z%s=%sr   ©r   ÚkÚvr   r   r   r   ë   s     z-ReprPrinter._print_Symbol.<locals>.<listcomp>ú
%s(%s, %s)r   )	Z_assumptions_origZis_Dummyr†   r'   r!   r&   r„   rd   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 )Nr‹   c                 S  s   g | ]\}}d ||f ‘qS r‡   r   rˆ   r   r   r   r   ù   s     z7ReprPrinter._print_CoordinateSymbol.<locals>.<listcomp>rg   r   )	Z_assumptionsÚ	generatorr'   r!   r&   Z	coord_sysÚindexrd   r   rŒ   r   r   r   Ú_print_CoordinateSymbolï   s    

ý

üz#ReprPrinter._print_CoordinateSymbolc                 C  s
   d|j  S )NzQ.%s)r„   r2   r   r   r   Ú_print_Predicate  s    zReprPrinter._print_Predicatec                 C  s   |j }d|jj|  |d¡f S )Nrh   r   )Ú_argsr'   r!   r   )r   r(   r   r   r   r   Ú_print_AppliedPredicate  s    z#ReprPrinter._print_AppliedPredicatec                 C  s   t |ƒS r0   )Úreprr2   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   r   r   )r?   r&   r   r2   r   r   r   Ú_print_tuple  s    zReprPrinter._print_tuplec                 C  s   d|j j|jf S )Nz%s('%s'))r'   r!   r„   r2   r   r   r   Ú_print_WildFunction  s    zReprPrinter._print_WildFunctionc                 C  s$   d|j j|  |j¡|  | ¡ ¡f S ©Nr‹   )r'   r!   r&   ÚrootZcoeffsr2   r   r   r   Ú_print_AlgebraicNumber  s    
 ÿz"ReprPrinter._print_AlgebraicNumberc                 C  s,   d|j j|  |j¡|  |j¡|  |j¡f S ©Nrg   ©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 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©ra   Úreverser‹   )Ú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 )NTr¥   rg   )
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 rƒ   )r'   r!   r&   r£   )r   r    Úclsr£   r   r   r   Ú_print_FractionField/  s    z ReprPrinter._print_FractionFieldc                 C  sZ   |j j}|  |j¡}d t| j|jƒ¡}t|jƒ}||j	krFd| }nd}d||||f S )Nr   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_PolynomialRingBase4  s    


z%ReprPrinter._print_PolynomialRingBasec                 C  s0   |j j}|  | ¡ ¡}|  |j¡}d|||f S rš   )r'   r!   r&   Zto_listr³   )r   rT   r¯   Úrepr³   r   r   r   Ú
_print_DMP?  s    zReprPrinter._print_DMPc                 C  s   dt |jƒ S )NzFiniteExtension(%s))r#   Úmodulus)r   Úextr   r   r   Ú_print_MonogenicFiniteExtensionE  s    z+ReprPrinter._print_MonogenicFiniteExtensionc                 C  s$   |   |j¡}|   |j¡}d||f S )NzExtElem(%s, %s))r&   rµ   r¸   )r   r€   rµ   r¸   r   r   r   Ú_print_ExtensionElementJ  s    z#ReprPrinter._print_ExtensionElement)N)N);r!   r    Ú__qualname__Zprintmethodr   Ú__annotations__r   r+   r/   r3   rD   rK   rL   rN   rO   rQ   rR   rS   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r`   re   rf   rn   rp   rr   rt   rw   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      sr   
þ
(
	r   c                 K  s   t |ƒ | ¡S )zreturn expr in repr form)r   r   )r(   Úsettingsr   r   r   ÚsreprO  s    r¾   N)Ú__doc__Ú
__future__r   Útypingr   Zsympy.core.functionr   Zsympy.core.mulr   Zmpmath.libmpr   r   r~   Úprinterr	   r
   r   r¾   r   r   r   r   Ú<module>   s     ?