o
     ô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"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ÚReprPrinterÚ
_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   úf/var/www/html/academy/tools/voices/clone/cosy-venv/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"   )Ú_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é   )Údeprecated_since_versionÚactive_deprecations_targetÚ
stacklevelr   TzPermutation()r   r;   ú(ú,zPermutation%sé   zPermutation(%s)zPermutation([], size=%s)éÿÿÿÿz	, size=%s)Ú sympy.combinatorics.permutationsr:   r;   Úsympy.utilities.exceptionsr<   Úprint_cyclicÚ	_settingsÚgetÚsizer6   ÚlenÚrfindÚsupportr&   Ú
array_form)r   r+   r:   r;   r<   r   ÚsÚlastÚtrimÚ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                   rU   )Nr!   r"   c                   r   r   rV   rW   r   r   r   r   l   r   z0ReprPrinter._print_Heaviside.<locals>.<listcomp>)r)   rY   r   ÚpargsrZ   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$   r7   r   r   r   Ú_print_FunctionClasso   s   

z ReprPrinter._print_FunctionClassc                 C  ó   dS )NzRational(1, 2)r   r7   r   r   r   Ú_print_Halfu   ó   zReprPrinter._print_Halfc                 C  ó   t |ƒS r5   ©r&   r7   r   r   r   Ú_print_RationalConstantx   r9   z#ReprPrinter._print_RationalConstantc                 C  rd   r5   re   r7   r   r   r   Ú_print_AtomicExpr{   r9   zReprPrinter._print_AtomicExprc                 C  rd   r5   re   r7   r   r   r   Ú_print_NumberSymbol~   r9   zReprPrinter._print_NumberSymbolc                 C  ó
   d|j  S )NzInteger(%i))Úpr7   r   r   r   Ú_print_Integer�   ó   
zReprPrinter._print_Integerc                 C  ra   )NÚ	Complexesr   r7   r   r   r   Ú_print_Complexes„   rc   zReprPrinter._print_Complexesc                 C  ra   )NÚIntegersr   r7   r   r   r   Ú_print_Integers‡   rc   zReprPrinter._print_Integersc                 C  ra   )NÚNaturalsr   r7   r   r   r   Ú_print_NaturalsŠ   rc   zReprPrinter._print_Naturalsc                 C  ra   )NÚ	Naturals0r   r7   r   r   r   Ú_print_Naturals0�   rc   zReprPrinter._print_Naturals0c                 C  ra   )NÚ	Rationalsr   r7   r   r   r   Ú_print_Rationals�   rc   zReprPrinter._print_Rationalsc                 C  ra   )NÚRealsr   r7   r   r   r   Ú_print_Reals“   rc   zReprPrinter._print_Realsc                 C  ra   )NÚEmptySetr   r7   r   r   r   Ú_print_EmptySet–   rc   zReprPrinter._print_EmptySetc                 C  ra   )NÚUniversalSetr   r7   r   r   r   Ú_print_UniversalSet™   rc   zReprPrinter._print_UniversalSetc                 C  ra   )NÚEmptySequencer   r7   r   r   r   Ú_print_EmptySequenceœ   rc   z ReprPrinter._print_EmptySequencec                 C  s   d|   |d¡ S )Nz[%s]r"   ©r   r7   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()rƒ   r"   r   r7   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)rD   ú%s(%s))ÚrowsÚcolsr*   r$   r)   Úranger(   )r   r+   r,   ÚiÚjr   r   r   Ú_print_MatrixBase¬   s   

ý
ÿzReprPrinter._print_MatrixBasec                 C  ra   )NÚtruer   r7   r   r   r   Ú_print_BooleanTrueº   rc   zReprPrinter._print_BooleanTruec                 C  ra   )NÚfalser   r7   r   r   r   Ú_print_BooleanFalse½   rc   zReprPrinter._print_BooleanFalsec                 C  ra   )NÚnanr   r7   r   r   r   Ú
_print_NaNÀ   rc   zReprPrinter._print_NaNc                 C  sF   | j dvr
| ¡ }nt |¡}t| j|ƒ}t|ƒj}|dd |¡  S )N)ÚoldÚnoner!   r"   )	r   Úas_ordered_factorsr   Ú	make_argsr0   r)   r1   r$   r   r2   r   r   r   Ú
_print_MulÃ   s   



zReprPrinter._print_Mulc                 C  ó   d|   |j¡|   |j¡f S )NzRational(%s, %s))r)   rj   Úqr7   r   r   r   Ú_print_RationalÎ   ó   zReprPrinter._print_Rationalc                 C  s   d|j j|j|jf S )Nz
%s(%d, %d))r*   r$   rj   r›   r7   r   r   r   Ú_print_PythonRationalÑ   s   z!ReprPrinter._print_PythonRationalc                 C  rš   )NzFraction(%s, %s))r)   Ú	numeratorÚdenominatorr7   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_strÚ_mpf_r   Ú_precr*   r$   rZ   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Œ   rX   Úbr7   r   r   r   Ú_print_Sum2Û   s   ÿzReprPrinter._print_Sum2c                 C  s   d|j j|  |j¡f S ©Nrˆ   )r*   r$   r)   Úname)r   rO   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_indexrˆ   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"   )
Ú_assumptions_origÚis_DummyÚcopyr¬   r*   r$   r)   rª   r„   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>r‡   r"   )	Ú_assumptionsÚ	generatorr*   r$   r)   Z	coord_sysÚindexr„   r   r·   r   r   r   Ú_print_CoordinateSymbolð   s   

ý

üz#ReprPrinter._print_CoordinateSymbolc                 C  ri   )NzQ.%s)rª   r7   r   r   r   Ú_print_Predicate  rl   zReprPrinter._print_Predicatec                 C  s   |j }d|jj|  |d¡f S )Nrˆ   r"   )Ú_argsr*   r$   r   )r   r+   r   r   r   r   Ú_print_AppliedPredicate  s   z#ReprPrinter._print_AppliedPredicatec                 C  rd   r5   )Úreprr7   r   r   r   Ú
_print_str
  r9   zReprPrinter._print_strc                 C  s.   t |ƒdkrd|  |d ¡ S d|  |d¡ S )Nr   z(%s,)r   r!   r"   )rK   r)   r   r7   r   r   r   Ú_print_tuple  s   zReprPrinter._print_tuplec                 C  s   d|j j|jf S )Nz%s('%s'))r*   r$   rª   r7   r   r   r   Ú_print_WildFunction  s   zReprPrinter._print_WildFunctionc                 C  s$   d|j j|  |j¡|  | ¡ ¡f S ©Nr³   )r*   r$   r)   ÚrootÚcoeffsr7   r   r   r   Ú_print_AlgebraicNumber  s   ÿz"ReprPrinter._print_AlgebraicNumberc                 C  ó,   d|j j|  |j¡|  |j¡|  |j¡f S ©Nr‡   ©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©r�   Úreverser³   )ÚlistÚtermsÚsortrÏ   r   r*   r$   r)   )r   Ú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Ô   r‡   )
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   r0   Úgensr&   r   Ú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)   Úto_listrä   )r   rj   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_ExtensionElementr5   );r$   r#   Ú__qualname__Úprintmethodr   Ú__annotations__r   r.   r4   r8   rT   r\   r^   r`   rb   rf   rg   rh   rk   rn   rp   rr   rt   rv   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è   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   Úsympy.core.functionr   Zsympy.core.mulr   Zmpmath.libmpr   r   r¢   Úprinterr	   r
   r   rò   r   r   r   r   Ú<module>   s      @