
    wg -                        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
e      Z ee      d        Zy)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                  h   e Zd ZU dZdddZded<   d Zd Zd<d	Zd
 Z	d Z
d Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd  Zd! Z d" Z!d# Z"d<d$Z#d% Z$d& Z%d' Z&d( Z'd) Z(d* Z)d+ Z*d, Z+d- Z,d. Z-d/ Z.d0 Z/d1 Z0d2 Z1d3 Z2d4 Z3d5 Z4d6 Z5d7 Z6d8 Z7d9 Z8d: Z9d; Z:y)=ReprPrinter
_sympyreprNT)orderperm_cycliczdict[str, Any]_default_settingsc                h    |j                  |D cg c]  }| j                  |       c}      S c c}w )zG
        Prints each item in `args` and joins them with `sep`.
        )joindoprint)selfargssepitems       X/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/printing/repr.pyreprifyzReprPrinter.reprify   s*     xx=d+=>>=s   /c                   t        |t              r|S t        |d      r|j                         S t        |d      rtt        |j                  d      r^g }|j                  D ]"  }|j                  | j                  |             $ |j                  j                  ddj                  |      z  z   S t        |d      r)t        |d      rd|j                  d	|j                  d
S t        |      S )z'
        The fallback printer.
        	__srepr__r   __iter__(%s), 
__module____name__z<'.z'>)
isinstancestrhasattrr   r   append_print	__class__r!   r   r    )r   exprlos       r   emptyPrinterzReprPrinter.emptyPrinter    s     dC KT;'>>##T6"wtyy*'EAYY )Q()>>**Vdiil-BBBT<(WT:-F"&//4==AAt9    c                    | j                  ||      }t        | j                  |      }t        |      j                  }|ddj                  |      z  z   S )N)r   r   r   )_as_ordered_termsmapr'   typer!   r   r   r)   r   r   clsnames        r   
_print_AddzReprPrinter._print_Add2   sN    %%d%%84;;%t*%%$))D/111r-   c                "    |j                         S N)__repr__r   r)   s     r   _print_CyclezReprPrinter._print_Cycle8   s    }}r-   c                   ddl m}m} ddlm} |j
                  }| |d| dddd	       n| j                  j                  d
d      }|ro|j                  sy  ||      |j                  dz
        j                         t        d      d  }|j                  d      }|dk(  sd||d  vr||d  |d | z   }d|z  S |j                         }|s6|j                  dk  rdt        |j                        z  S d|j                  z  S t        |j                  d |d   dz          d|j                  z  z   }t        |j                        x}	}
t        |      t        |
      k  r|}	d|	z  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sizer7   lenrfindsupportr$   
array_form)r   r)   r;   r<   r=   r   slasttrimusefulls              r   _print_PermutationzReprPrinter._print_Permutation;   so   GH!.."%++6- 8 */+P ..,,]DAK99& dDIIM*335c'lmDA773<D19AdeH!4deHq$x'"A%%A99q=,s4??/CCC1DII==tz"	23kDII6MMDT__--C$4y3t9$$s**r-   c           
         | j                  |j                        }|ddj                  |j                  D cg c]  }| j                  |       c}      z  z  }|S c c}w Nr   r   )r'   funcr   r   r   r)   ras       r   _print_FunctionzReprPrinter._print_Functionc   sN    KK		"	Vdii CAQ CDDD !D   Ac           
         | j                  |j                        }|ddj                  |j                  D cg c]  }| j                  |       c}      z  z  }|S c c}w rW   )r'   rX   r   pargsrY   s       r   _print_HeavisidezReprPrinter._print_Heavisideh   sP     KK		"	Vdii DAQ DEEE !Er]   c                X    t        |t              rd|j                  z  S |j                  S )NzFunction(%r))
issubclassr   r!   r8   s     r   _print_FunctionClassz ReprPrinter._print_FunctionClasso   s%    dL)!T]]33== r-   c                     y)NzRational(1, 2) r8   s     r   _print_HalfzReprPrinter._print_Halfu   s    r-   c                    t        |      S r6   r$   r8   s     r   _print_RationalConstantz#ReprPrinter._print_RationalConstantx       4yr-   c                    t        |      S r6   rh   r8   s     r   _print_AtomicExprzReprPrinter._print_AtomicExpr{   rj   r-   c                    t        |      S r6   rh   r8   s     r   _print_NumberSymbolzReprPrinter._print_NumberSymbol~   rj   r-   c                     d|j                   z  S )NzInteger(%i))pr8   s     r   _print_IntegerzReprPrinter._print_Integer   s    tvv%%r-   c                     y)N	Complexesre   r8   s     r   _print_ComplexeszReprPrinter._print_Complexes       r-   c                     y)NIntegersre   r8   s     r   _print_IntegerszReprPrinter._print_Integers       r-   c                     y)NNaturalsre   r8   s     r   _print_NaturalszReprPrinter._print_Naturals   ry   r-   c                     y)N	Naturals0re   r8   s     r   _print_Naturals0zReprPrinter._print_Naturals0   ru   r-   c                     y)N	Rationalsre   r8   s     r   _print_RationalszReprPrinter._print_Rationals   ru   r-   c                     y)NRealsre   r8   s     r   _print_RealszReprPrinter._print_Reals       r-   c                     y)NEmptySetre   r8   s     r   _print_EmptySetzReprPrinter._print_EmptySet   ry   r-   c                     y)NUniversalSetre   r8   s     r   _print_UniversalSetzReprPrinter._print_UniversalSet   s    r-   c                     y)NEmptySequencere   r8   s     r   _print_EmptySequencez ReprPrinter._print_EmptySequence   s    r-   c                ,    d| j                  |d      z  S )Nz[%s]r   r   r8   s     r   _print_listzReprPrinter._print_list   s    T4000r-   c           	         d}|j                         D cg c]*  \  }}| j                  |      d| j                  |      , }}}d|j                  |      z  S c c}}w )Nr   z: {%s})itemsr   r   )r   r)   r   keyvaluedict_kvss         r   _print_dictzReprPrinter._print_dict   sY    Z^ZdZdZfgJCQVS 14<<3FGgg*** hs   /Ac                2    |syd| j                  |d      z  S )Nzset()r   r   r   r8   s     r   
_print_setzReprPrinter._print_set   s    T4000r-   c           	        |j                   dk(  |j                  dk(  z  rc|j                  j                  d| j	                  |j                         d| j	                  |j                        d| j	                  g       dS g }t        |j                         D ]F  }|j                  g        t        |j                        D ]  }|d   j                  |||f           H |j                  j                  d| j	                  |      dS )Nr   rB   r   )rE   )rowscolsr(   r!   r'   ranger&   )r   r)   r*   ijs        r   _print_MatrixBasezReprPrinter._print_MatrixBase   s    IINtyyA~.'+~~'>'>'+{{499'='+{{499'='+{{28 8 tyy! 	)AHHRL499% )"T!Q$Z()	)  >>22DKKNCCr-   c                     y)Ntruere   r8   s     r   _print_BooleanTruezReprPrinter._print_BooleanTrue   s    r-   c                     y)Nfalsere   r8   s     r   _print_BooleanFalsezReprPrinter._print_BooleanFalse   r   r-   c                     y)Nnanre   r8   s     r   
_print_NaNzReprPrinter._print_NaN   s    r-   c                    | j                   dvr|j                         }nt        j                  |      }t	        | j
                  |      }t        |      j                  }|ddj                  |      z  z   S )N)oldnoner   r   )	r   as_ordered_factorsr   	make_argsr0   r'   r1   r!   r   r2   s        r   
_print_MulzReprPrinter._print_Mul   sc    ::_,**,D ==&D4;;%t*%%$))D/111r-   c                x    d| j                  |j                        d| j                  |j                        dS )Nz	Rational(r   r   )r'   rp   qr8   s     r   _print_RationalzReprPrinter._print_Rational   s'    %)[[%8$++dff:MNNr-   c                b    d|j                   j                  |j                  |j                  fz  S )Nz
%s(%d, %d))r(   r!   rp   r   r8   s     r   _print_PythonRationalz!ReprPrinter._print_PythonRational   s&    t~~66GGGr-   c                x    d| j                  |j                        d| j                  |j                        dS )Nz	Fraction(r   r   )r'   	numeratordenominatorr8   s     r   _print_FractionzReprPrinter._print_Fraction   s)    %)[[%@$++dN^N^B_``r-   c                    t        |j                  t        |j                              }d|j                  j
                  ||j                  fz  S )Nz%s('%s', precision=%i))mlib_to_str_mpf_r   _precr(   r!   )r   r)   rZ   s      r   _print_FloatzReprPrinter._print_Float   s;    

HTZZ$89'4>>+B+BAtzz*RRRr-   c           
         d| j                  |j                        d| j                  |j                        d| j                  |j                        d| j                  |j                        d	S )NzSum2(z, (r   z)))r'   fr   r[   br8   s     r   _print_Sum2zReprPrinter._print_Sum2   sL    +/;;tvv+>DFF@S+/;;tvv+>DFF@SU 	Ur-   c                l    |j                   j                  d| j                  |j                        dS NrB   r   )r(   r!   r'   name)r   rP   s     r   
_print_StrzReprPrinter._print_Str   s$    ;;//QVV1DEEr-   c                   |j                   }|j                  r|j                  |d<   |i k(  r5|j                  j                  d| j                  |j                        dS |j                         D cg c]  \  }}|d| }}}|j                  j                  d| j                  |j                        ddj                  |      dS c c}}w )Ndummy_indexrB   r   =r   )	_assumptions_origis_Dummyr   r(   r!   r'   r   r   r   r   r)   dkvattrs         r   _print_SymbolzReprPrinter._print_Symbol   s    ""==#//Am7#~~66DII8NOO12;Aq!$;D;#'>>#:#:#';;tyy#9499T?L L <s   5Cc           	        |j                   j                  }|i k(  rQ|j                  j                  d| j	                  |j
                        d| j	                  |j                        dS |j                         D cg c]  \  }}|d| }}}|j                  j                  d| j	                  |j
                        d| j	                  |j                        ddj                  |      dS c c}}w )NrB   r   r   r   )	_assumptions	generatorr(   r!   r'   	coord_sysindexr   r   r   s         r   _print_CoordinateSymbolz#ReprPrinter._print_CoordinateSymbol   s    ''7''DNN+DJJ'  23;Aq!$;D;''DNN+DJJ'		$	  <s    C7c                     d|j                   z  S )NzQ.%s)r   r8   s     r   _print_PredicatezReprPrinter._print_Predicate  s    		!!r-   c                r    |j                   }|j                  j                  d| j                  |d      dS NrB   r   r   )_argsr(   r!   r   )r   r)   r   s      r   _print_AppliedPredicatez#ReprPrinter._print_AppliedPredicate  s+    zz>>22DLLt4LMMr-   c                    t        |      S r6   )reprr8   s     r   
_print_strzReprPrinter._print_str	  s    Dzr-   c                v    t        |      dk(  rd| j                  |d         z  S d| j                  |d      z  S )Nr	   z(%s,)r   r   r   )rL   r'   r   r8   s     r   _print_tuplezReprPrinter._print_tuple  s;    t9>T[[a111DLLt444r-   c                N    |j                   j                  d|j                  dS )Nz('z'))r(   r!   r   r8   s     r   _print_WildFunctionzReprPrinter._print_WildFunction  s    !^^44dii@@r-   c                    |j                   j                  d| j                  |j                        d| j                  |j	                               dS r   )r(   r!   r'   rootcoeffsr8   s     r   _print_AlgebraicNumberz"ReprPrinter._print_AlgebraicNumber  s<    #~~66KK		"DKK$>@ 	@r-   c           	         |j                   j                  d| j                  |j                        d| j                  |j                        d| j                  |j
                        dS r   r(   r!   r'   symbolsdomainr   )r   rings     r   _print_PolyRingzReprPrinter._print_PolyRing  sI    #'>>#:#:KK%t{{4;;'?TZZAXZ 	Zr-   c           	         |j                   j                  d| j                  |j                        d| j                  |j                        d| j                  |j
                        dS r   r   )r   fields     r   _print_FracFieldzReprPrinter._print_FracField  sI    #(??#;#;KK&ELL(A4;;u{{C[] 	]r-   c                   t        |j                               }|j                  |j                  j                  d       |j
                  j                  d| j                  |j                        d| j                  |      dS NT)r   reverserB   r   r   )listtermssortr   r   r(   r!   r'   )r   polyr   s      r   _print_PolyElementzReprPrinter._print_PolyElement!  s[    TZZ\"

tyy
5#~~66DII8NPTP[P[\aPbccr-   c                   t        |j                  j                               }|j                  |j                  j
                  d       t        |j                  j                               }|j                  |j                  j
                  d       | j                  |      }| j                  |      }|j                  j                  d| j                  |j                        d|d|dS r   )
r   numerr   r   r   r   denomr'   r(   r!   )r   fracnumer_termsdenom_termsr   r   s         r   _print_FracElementzReprPrinter._print_FracElement&  s    4::++-.TZZ--t<4::++-.TZZ--t<K(K(#'>>#:#:DKK

<SUZ\abbr-   c                t    |j                   j                  }| j                  |j                        }|d|dS r   )r(   r!   r'   r   )r   r   clsr   s       r   _print_FractionFieldz ReprPrinter._print_FractionField/  s0    ''FLL)&&r-   c                4   |j                   j                  }| j                  |j                        }dj	                  t        | j                  |j                              }t        |j                        }||j                  k7  rd|z   }nd}|d|d||dS )Nr   z, order= rB   r   )
r(   r!   r'   r   r   r0   gensr$   r   default_order)r   r   r  domr  r   orderstrs          r   _print_PolynomialRingBasez%ReprPrinter._print_PolynomialRingBase4  sy    nn%%kk$++&yyT[[$))45DJJD&&&!E)HH!$c4::r-   c                    |j                   j                  }| j                  |j                               }| j                  |j                        }|d|d|dS r   )r(   r!   r'   to_listr
  )r   rp   r  repr
  s        r   
_print_DMPzReprPrinter._print_DMP?  sD    kk""kk!))+&kk!%% "C--r-   c                2    dt        |j                        z  S )NzFiniteExtension(%s))r$   modulus)r   exts     r   _print_MonogenicFiniteExtensionz+ReprPrinter._print_MonogenicFiniteExtensionE  s     %s3;;'777r-   c                    | j                  |j                        }| j                  |j                        }d|d|dS )NzExtElem(r   r   )r'   r  r  )r   r   r  r  s       r   _print_ExtensionElementz#ReprPrinter._print_ExtensionElementJ  s1    kk!%% kk!%% $'--r-   r6   );r!   r    __qualname__printmethodr   __annotations__r   r,   r4   r9   rU   r\   r`   rc   rf   ri   rl   rn   rq   rt   rx   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  re   r-   r   r   r      s7   K )~ 
?$2&+P
! &1+
1
D	2OHaSUFL$"N
5A@Z]d
c'
	;.8
.r-   r   c                6    t        |      j                  |       S )zreturn expr in repr form)r   r   )r)   settingss     r   sreprr  O  s     x ((..r-   N)__doc__
__future__r   typingr   sympy.core.functionr   sympy.core.mulr   mpmath.libmpr   r   r   printerr
   r   r   r  re   r-   r   <module>r$     sF    #  ,  8 ,{.' {.z	 / /r-   