o
    GZh-                     @  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"dqdAdB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 )r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                      g | ]}  |qS  doprint).0itemselfr   B/var/www/auris/lib/python3.10/site-packages/sympy/printing/repr.py
<listcomp>       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r6t|jdr6g }|jD ]
}|| | q |jjdd	|  S t|drHt|drHd|j
|jf S t|S )	z'
        The fallback printer.
        	__srepr__r   __iter__(%s), 
__module____name__z	<'%s.%s'>)
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   clsnamer   r   r   
_print_Add2   s   
zReprPrinter._print_Addc                 C  s   |  S N)__repr__r   r*   r   r   r   _print_Cycle8      zReprPrinter._print_Cyclec                 C  s@  ddl m}m} ddlm} |j}|d ur"|d| ddddd	 n| jd
d}|rb|js0dS |||jd 	 t
dd  }|d}|dks^d||d  vr^||d  |d |  }d| S | }|sy|jdk rtdt|j S d|j S t|jd |d d  d|j  }t|j }	}
t
|t
|
k r|}	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   r9   (,zPermutation%s   zPermutation(%s)zPermutation([], size=%s)z	, size=%s)Z sympy.combinatorics.permutationsr8   r9   Zsympy.utilities.exceptionsr:   Zprint_cyclicZ	_settingsgetsizer4   lenrfindZsupportr%   Z
array_form)r   r*   r8   r9   r:   r   slastZtrimZusefullr   r   r   _print_Permutation;   s>   
"


$zReprPrinter._print_Permutationc                   2     |j}|dd fdd|jD  7 }|S )Nr    r!   c                   r   r   r(   r   ar   r   r   r   e   r   z/ReprPrinter._print_Function.<locals>.<listcomp>)r(   funcr   r   r   r*   rr   r   r   _print_Functionc   s   "zReprPrinter._print_Functionc                   rI   )Nr    r!   c                   r   r   rJ   rK   r   r   r   r   l   r   z0ReprPrinter._print_Heaviside.<locals>.<listcomp>)r(   rM   r   ZpargsrN   r   r   r   _print_Heavisideh   s   "zReprPrinter._print_Heavisidec                 C  s   t |tr
d|j S |jS )NzFunction(%r))
issubclassr   r#   r5   r   r   r   _print_FunctionClasso   s   

z ReprPrinter._print_FunctionClassc                 C     dS )NzRational(1, 2)r   r5   r   r   r   _print_Halfu      zReprPrinter._print_Halfc                 C     t |S r3   r%   r5   r   r   r   _print_RationalConstantx   r7   z#ReprPrinter._print_RationalConstantc                 C  rW   r3   rX   r5   r   r   r   _print_AtomicExpr{   r7   zReprPrinter._print_AtomicExprc                 C  rW   r3   rX   r5   r   r   r   _print_NumberSymbol~   r7   zReprPrinter._print_NumberSymbolc                 C  
   d|j  S )NzInteger(%i))pr5   r   r   r   _print_Integer      
zReprPrinter._print_Integerc                 C  rT   )NZ	Complexesr   r5   r   r   r   _print_Complexes   rV   zReprPrinter._print_Complexesc                 C  rT   )NZIntegersr   r5   r   r   r   _print_Integers   rV   zReprPrinter._print_Integersc                 C  rT   )NZNaturalsr   r5   r   r   r   _print_Naturals   rV   zReprPrinter._print_Naturalsc                 C  rT   )NZ	Naturals0r   r5   r   r   r   _print_Naturals0   rV   zReprPrinter._print_Naturals0c                 C  rT   )NZ	Rationalsr   r5   r   r   r   _print_Rationals   rV   zReprPrinter._print_Rationalsc                 C  rT   )NZRealsr   r5   r   r   r   _print_Reals   rV   zReprPrinter._print_Realsc                 C  rT   )NZEmptySetr   r5   r   r   r   _print_EmptySet   rV   zReprPrinter._print_EmptySetc                 C  rT   )NZUniversalSetr   r5   r   r   r   _print_UniversalSet   rV   zReprPrinter._print_UniversalSetc                 C  rT   )NZEmptySequencer   r5   r   r   r   _print_EmptySequence   rV   z ReprPrinter._print_EmptySequencec                 C  s   d|  |d S )Nz[%s]r!   r   r5   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()rm   r!   ri   r5   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 ]}|g  t|jD ]}|d |||f  q2q&d|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  rT   )Ntruer   r5   r   r   r   _print_BooleanTrue   rV   zReprPrinter._print_BooleanTruec                 C  rT   )Nfalser   r5   r   r   r   _print_BooleanFalse   rV   zReprPrinter._print_BooleanFalsec                 C  rT   )Nnanr   r5   r   r   r   
_print_NaN   rV   zReprPrinter._print_NaNc                 C  sF   | j dv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   r0   r   r   r   
_print_Mul   s   



zReprPrinter._print_Mulc                 C     d|  |j|  |jf S )NzRational(%s, %s))r(   r]   qr5   r   r   r   _print_Rational      zReprPrinter._print_Rationalc                 C  s   d|j j|j|jf S )Nz
%s(%d, %d))r)   r#   r]   r   r5   r   r   r   _print_PythonRational   s   z!ReprPrinter._print_PythonRationalc                 C  r   )NzFraction(%s, %s))r(   	numeratordenominatorr5   r   r   r   _print_Fraction   r   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#   rN   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(   frv   rL   br5   r   r   r   _print_Sum2   s   zReprPrinter._print_Sum2c                 C  s   d|j j| |jf S Nrr   )r)   r#   r(   name)r   rE   r   r   r   
_print_Str   s   zReprPrinter._print_Strc                 C  sp   |j }|jr| }|j|d< |i krd|jj| |jf S dd | D }d|jj| |jd	|f S )Ndummy_indexrr   c                 S     g | ]
\}}d ||f qS z%s=%sr   r   kvr   r   r   r          z-ReprPrinter._print_Symbol.<locals>.<listcomp>
%s(%s, %s)r!   )
Z_assumptions_origZis_Dummycopyr   r)   r#   r(   r   rn   r   r   r*   dattrr   r   r   _print_Symbol   s   
zReprPrinter._print_Symbolc                 C  sn   |j j}|i krd|jj| |j| |jf S dd | D }d|jj| |j| |jd|f S )Nr   c                 S  r   r   r   r   r   r   r   r      r   z7ReprPrinter._print_CoordinateSymbol.<locals>.<listcomp>rq   r!   )	Z_assumptions	generatorr)   r#   r(   Z	coord_sysindexrn   r   r   r   r   r   _print_CoordinateSymbol   s   



z#ReprPrinter._print_CoordinateSymbolc                 C  r\   )NzQ.%s)r   r5   r   r   r   _print_Predicate  r_   zReprPrinter._print_Predicatec                 C  s   |j }d|jj| |df S )Nrr   r!   )_argsr)   r#   r   )r   r*   r   r   r   r   _print_AppliedPredicate  s   z#ReprPrinter._print_AppliedPredicatec                 C  rW   r3   )reprr5   r   r   r   
_print_str
  r7   zReprPrinter._print_strc                 C  s.   t |dkrd| |d  S d| |d S )Nr   z(%s,)r   r    r!   )rC   r(   r   r5   r   r   r   _print_tuple  s   zReprPrinter._print_tuplec                 C  s   d|j j|jf S )Nz%s('%s'))r)   r#   r   r5   r   r   r   _print_WildFunction  s   zReprPrinter._print_WildFunctionc                 C  s$   d|j j| |j| | f S Nr   )r)   r#   r(   rootZcoeffsr5   r   r   r   _print_AlgebraicNumber  s   z"ReprPrinter._print_AlgebraicNumberc                 C  ,   d|j j| |j| |j| |jf S Nrq   r)   r#   r(   symbolsdomainr   )r   ringr   r   r   _print_PolyRing     zReprPrinter._print_PolyRingc                 C  r   r   r   )r   fieldr   r   r   _print_FracField  r   zReprPrinter._print_FracFieldc                 C  s>   t | }|j|jjdd d|jj| |j| |f S )NTrk   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   rq   )
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_FractionField0  s   z ReprPrinter._print_FractionFieldc                 C  sZ   |j j}| |j}dt| j|j}t|j}||j	kr#d| }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_PolynomialRingBase5  s   


z%ReprPrinter._print_PolynomialRingBasec                 C  s0   |j j}| | }| |j}d|||f S r   )r)   r#   r(   Zto_listr   )r   r]   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_MonogenicFiniteExtensionF     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_ExtensionElementK  s   z#ReprPrinter._print_ExtensionElementr3   );r#   r"   __qualname__Zprintmethodr   __annotations__r   r-   r2   r6   rH   rP   rQ   rS   rU   rY   rZ   r[   r^   r`   ra   rb   rc   rd   re   rf   rg   rh   rj   ro   rp   rx   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      st   
 
(
	r   c                 K  s   t || S )zreturn expr in repr form)r   r   )r*   settingsr   r   r   sreprP  r   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      @