
    Ed{-                         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	e          Z ee          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                   ^   e Zd ZdZdd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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-d. Z.d/ Z/d0 Z0d1 Z1d2 Z2d3 Z3d4 Z4d5 Z5d6 Z6d7 Z7d8 Z8d9 Z9dS );ReprPrinter
_sympyreprNT)orderperm_cyclicc                 F     |                      fd|D                       S )zG
        Prints each item in `args` and joins them with `sep`.
        c                 :    g | ]}                     |          S  doprint).0itemselfs     3lib/python3.11/site-packages/sympy/printing/repr.py
<listcomp>z'ReprPrinter.reprify.<locals>.<listcomp>   s%    ===d++===    )join)r   argsseps   `  r   reprifyzReprPrinter.reprify   s,     xx=======>>>r   c                    t          |t                    r|S t          |d          r|                                S t          |d          rnt          |j        d          rYg }|j        D ]*}|                    |                     |                     +|j        j        dd	                    |          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"" 	wty*'E'E 	AY ) )Q((((>*Vdiill-BBBT<(( 	WT:-F-F 	 	"&///4===AAt99r   c                     |                      ||          }t          | j        |          }t          |          j        }|dd                    |          z  z   S )N)r   r#   r$   )_as_ordered_termsmapr,   typer&   r   r   r.   r   r   clsnames        r   
_print_AddzReprPrinter._print_Add1   sS    %%d%%884;%%t**%$))D//111r   c                 *    |                                 S N)__repr__r   r.   s     r   _print_CyclezReprPrinter._print_Cycle7   s    }}r   c                 
   ddl m}m} ddlm} |j        }| |d| dddd	           n| j                            d
d          }|r|j        sdS   ||          |j        dz
            	                                t          d          d          }|                    d          }|dk    s!d||d          vr||d          |d |         z   }d|z  S |                                }|s,|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.exceptionsrA   print_cyclic	_settingsgetsizer;   lenrfindsupportr)   
array_form)r   r.   r?   r@   rA   r   slasttrimusefulls              r   _print_PermutationzReprPrinter._print_Permutation:   s   GGGGGGGGHHHHHH!. 	B%%+6   */+P     .,,]DAAK 	+9 '& dDIM**3355c'llmmDA773<<D19 (AdeeH!4 (deeHq$x'"A%%A >9q= D,s4?/C/CCC1DI==tz"	z233kDI6MMDT_---C$4yy3t99$ $s**r   c                                            |j                  }|dd                     fd|j        D                       z  z  }|S )Nr#   r$   c                 :    g | ]}                     |          S r   r,   r   ar   s     r   r   z/ReprPrinter._print_Function.<locals>.<listcomp>d   s#     C C CAQ C C Cr   )r,   funcr   r   r   r.   rs   `  r   _print_FunctionzReprPrinter._print_Functionb   sM    KK	""	Vdii C C C C C C CDDDDr   c                                            |j                  }|dd                     fd|j        D                       z  z  }|S )Nr#   r$   c                 :    g | ]}                     |          S r   r\   r]   s     r   r   z0ReprPrinter._print_Heaviside.<locals>.<listcomp>k   s#     D D DAQ D D Dr   )r,   r_   r   pargsr`   s   `  r   _print_HeavisidezReprPrinter._print_Heavisideg   sO     KK	""	Vdii D D D D D D DEEEEr   c                 N    t          |t                    r
d|j        z  S |j        S )NzFunction(%r))
issubclassr   r&   r<   s     r   _print_FunctionClassz ReprPrinter._print_FunctionClassn   s)    dL)) 	!!T]33= r   c                     dS )NzRational(1, 2)r   r<   s     r   _print_HalfzReprPrinter._print_Halft   s    r   c                      t          |          S r:   r)   r<   s     r   _print_RationalConstantz#ReprPrinter._print_RationalConstantw       4yyr   c                      t          |          S r:   rm   r<   s     r   _print_AtomicExprzReprPrinter._print_AtomicExprz   ro   r   c                      t          |          S r:   rm   r<   s     r   _print_NumberSymbolzReprPrinter._print_NumberSymbol}   ro   r   c                     d|j         z  S )NzInteger(%i))pr<   s     r   _print_IntegerzReprPrinter._print_Integer   s    tv%%r   c                     dS )N	Complexesr   r<   s     r   _print_ComplexeszReprPrinter._print_Complexes       {r   c                     dS )NIntegersr   r<   s     r   _print_IntegerszReprPrinter._print_Integers       zr   c                     dS )NNaturalsr   r<   s     r   _print_NaturalszReprPrinter._print_Naturals   r~   r   c                     dS )N	Naturals0r   r<   s     r   _print_Naturals0zReprPrinter._print_Naturals0   rz   r   c                     dS )N	Rationalsr   r<   s     r   _print_RationalszReprPrinter._print_Rationals   rz   r   c                     dS )NRealsr   r<   s     r   _print_RealszReprPrinter._print_Reals       wr   c                     dS )NEmptySetr   r<   s     r   _print_EmptySetzReprPrinter._print_EmptySet   r~   r   c                     dS )NUniversalSetr   r<   s     r   _print_UniversalSetzReprPrinter._print_UniversalSet   s    ~r   c                     dS )NEmptySequencer   r<   s     r   _print_EmptySequencez ReprPrinter._print_EmptySequence   s    r   c                 4    d|                      |d          z  S )Nz[%s]r$   r   r<   s     r   _print_listzReprPrinter._print_list   s    T40000r   c                 x     d} fd|                                 D             }d|                    |          z  S )Nr$   c                 p    g | ]2\  }}                     |          d                      |          3S )z: r   )r   keyvaluer   s      r   r   z+ReprPrinter._print_dict.<locals>.<listcomp>   sD    gggJCQVS 1 1 1 14<<3F3F3FGgggr   {%s})itemsr   )r   r.   r   dict_kvss   `   r   _print_dictzReprPrinter._print_dict   sE    ggggZ^ZdZdZfZfggg****r   c                 <    |sdS d|                      |d          z  S )Nzset()r   r$   r   r<   s     r   
_print_setzReprPrinter._print_set   s(     	7T40000r   c           	          |j         dk    |j        dk    z  r[|j        j        d|                     |j                   d|                     |j                  d|                     g           dS g }t          |j                   D ]Q}|                    g            t          |j                  D ]%}|d                             |||f                    &R|j        j        d|                     |          dS )Nr   rF   r$   )rI   )rowscolsr-   r&   r,   ranger+   )r   r.   r/   ijs        r   _print_MatrixBasezReprPrinter._print_MatrixBase   s   INtyA~. 	8'+~'>'>'>'+{{49'='='='='+{{49'='='='='+{{28 8 ty!! 	) 	)AHHRLLL49%% ) )"T!Q$Z(((()>222DKKNNNNCCr   c                     dS )Ntruer   r<   s     r   _print_BooleanTruezReprPrinter._print_BooleanTrue   s    vr   c                     dS )Nfalser   r<   s     r   _print_BooleanFalsezReprPrinter._print_BooleanFalse   r   r   c                     dS )Nnanr   r<   s     r   
_print_NaNzReprPrinter._print_NaN   s    ur   c                     | j         dvr|                                }nt          j        |          }t	          | j        |          }t          |          j        }|dd                    |          z  z   S )N)oldnoner#   r$   )	r   as_ordered_factorsr   	make_argsr4   r,   r5   r&   r   r6   s        r   
_print_MulzReprPrinter._print_Mul   sn    :_, 	'**,,DD =&&D4;%%t**%$))D//111r   c                 t    d|                      |j                  d|                      |j                  dS )Nz	Rational(r$   r   )r,   ru   qr<   s     r   _print_RationalzReprPrinter._print_Rational   s7     %)[[%8%8%8%8$++df:M:M:M:MNNr   c                 :    d|j         j        |j        |j        fz  S )Nz
%s(%d, %d))r-   r&   ru   r   r<   s     r   _print_PythonRationalz!ReprPrinter._print_PythonRational   s    t~6GGGr   c                 t    d|                      |j                  d|                      |j                  dS )Nz	Fraction(r$   r   )r,   	numeratordenominatorr<   s     r   _print_FractionzReprPrinter._print_Fraction   s8     %)[[%@%@%@%@$++dN^B_B_B_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`   s      r   _print_FloatzReprPrinter._print_Float   s6    
HTZ$8$899'4>+BAtz*RRRr   c           
          d|                      |j                  d|                      |j                  d|                      |j                  d|                      |j                  d	S )NzSum2(z, (r$   z)))r,   fr   r^   br<   s     r   _print_Sum2zReprPrinter._print_Sum2   sj     +/;;tv+>+>+>+>DF@S@S@S@S+/;;tv+>+>+>+>DF@S@S@S@SU 	Ur   c                 V    |j         j        d|                     |j                  dS NrF   r   )r-   r&   r,   name)r   rT   s     r   
_print_StrzReprPrinter._print_Str   s,    ;///QV1D1D1D1DEEr   c                 X   |j         j        }|j        r
|j        |d<   |i k    r*|j        j        d|                     |j                  dS d |                                D             }|j        j        d|                     |j                  dd	                    |          dS )Ndummy_indexrF   r   c                 "    g | ]\  }}|d |S =r   r   kvs      r   r   z-ReprPrinter._print_Symbol.<locals>.<listcomp>   '    ;;;Aqqq!!$;;;r   r$   )
_assumptions	generatoris_Dummyr   r-   r&   r,   r   r   r   r   r.   dattrs       r   _print_SymbolzReprPrinter._print_Symbol   s    '= 	0#/Am7 	L#~666DI8N8N8N8NOO;;;;;D#'>#:#:#:#';;ty#9#9#9#9499T????L Lr   c           	         |j         j        }|i k    rE|j        j        d|                     |j                  d|                     |j                  dS d |                                D             }|j        j        d|                     |j                  d|                     |j                  dd                    |          dS )NrF   r$   r   c                 "    g | ]\  }}|d |S r   r   r   s      r   r   z7ReprPrinter._print_CoordinateSymbol.<locals>.<listcomp>   r   r   )	r   r   r-   r&   r,   	coord_sysindexr   r   r   s       r   _print_CoordinateSymbolz#ReprPrinter._print_CoordinateSymbol   s    '7 	'''DN++++DJ''''  <;;;;D'''DN++++DJ''''		$	 r   c                     d|j         z  S )NzQ.%s)r   r<   s     r   _print_PredicatezReprPrinter._print_Predicate   s    	!!r   c                 \    |j         }|j        j        d|                     |d          dS NrF   r$   r   )_argsr-   r&   r   )r   r.   r   s      r   _print_AppliedPredicatez#ReprPrinter._print_AppliedPredicate  s3    z>222DLLt4L4L4L4LMMr   c                      t          |          S r:   )reprr<   s     r   
_print_strzReprPrinter._print_str  s    Dzzr   c                     t          |          dk    rd|                     |d                   z  S d|                     |d          z  S )Nr	   z(%s,)r   r#   r$   )rP   r,   r   r<   s     r   _print_tuplezReprPrinter._print_tuple  sH    t99> 	5T[[a1111DLLt4444r   c                 0    |j         j        d|j        dS )Nz('z'))r-   r&   r   r<   s     r   _print_WildFunctionzReprPrinter._print_WildFunction  s    !^444diii@@r   c                     |j         j        d|                     |j                  d|                     |                                          dS r   )r-   r&   r,   rootcoeffsr<   s     r   _print_AlgebraicNumberz"ReprPrinter._print_AlgebraicNumber  sO    #~666KK	""""DKK$>$>$>$>@ 	@r   c           	          |j         j        d|                     |j                  d|                     |j                  d|                     |j                  dS r   r-   r&   r,   symbolsdomainr   )r   rings     r   _print_PolyRingzReprPrinter._print_PolyRing  s_    #'>#:#:#:KK%%%%t{{4;'?'?'?'?TZAXAXAXAXZ 	Zr   c           	          |j         j        d|                     |j                  d|                     |j                  d|                     |j                  dS r   r   )r   fields     r   _print_FracFieldzReprPrinter._print_FracField  s_    #(?#;#;#;KK&&&&EL(A(A(A(A4;;u{C[C[C[C[] 	]r   c                    t          |                                          }|                    |j        j        d           |j        j        d|                     |j                  d|                     |          dS NT)r   reverserF   r$   r   )listtermssortr   r   r-   r&   r,   )r   polyr  s      r   _print_PolyElementzReprPrinter._print_PolyElement   ss    TZZ\\""

ty
555#~666DI8N8N8N8NPTP[P[\aPbPbPbPbccr   c                    t          |j                                                  }|                    |j        j        d           t          |j                                                  }|                    |j        j        d           |                     |          }|                     |          }|j        j	        d|                     |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:++--..TZ-t<<<4:++--..TZ-t<<<K((K((#'>#:#:#:DKK
<S<S<S<SUZUZUZ\a\a\abbr   c                 ^    |j         j        }|                     |j                  }|d|dS r   )r-   r&   r,   r   )r   r   clsr   s       r   _print_FractionFieldz ReprPrinter._print_FractionField.  s3    'FL))33&&r   c                    |j         j        }|                     |j                  }d                    t          | j        |j                            }t          |j                  }||j	        k    rd|z   }nd}|d|d||dS )Nr$   z, order= rF   r   )
r-   r&   r,   r   r   r4   gensr)   r   default_order)r   r   r  domr  r   orderstrs          r   _print_PolynomialRingBasez%ReprPrinter._print_PolynomialRingBase3  s    n%kk$+&&yyT[$)4455DJD&& 	!E)HHH!$ccc44::r   c                     |j         j        }|                     |j                  }|                     |j                  }|j        d|                     |j                  z   }nd}|d|d||dS )Nz, ring=r  rF   r$   r   )r-   r&   r,   repr  r   )r   ru   r  r  r  ringstrs         r   
_print_DMPzReprPrinter._print_DMP>  sx    k"kk!%  kk!%  6 	$++af"5"55GGG!$ccc3388r   c                 0    dt          |j                  z  S )NzFiniteExtension(%s))r)   modulus)r   exts     r   _print_MonogenicFiniteExtensionz+ReprPrinter._print_MonogenicFiniteExtensionH  s     %s3;'7'777r   c                 |    |                      |j                  }|                      |j                  }d|d|dS )NzExtElem(r$   r   )r,   r  r  )r   r   r  r  s       r   _print_ExtensionElementz#ReprPrinter._print_ExtensionElementM  s=    kk!%  kk!%  $'CC--r   r:   ):r&   r%   __qualname__printmethod_default_settingsr   r1   r8   r=   rY   rb   rf   ri   rk   rn   rq   rs   rv   ry   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  r   r   r   r   r   r      s       K  
? ? ?  $2 2 2 2  &+ &+ &+P  
  ! ! !           & & &                  1 1 1+ + +
1 1 1
D D D      	2 	2 	2 	2O O OH H Ha a aS S SU U UF F FL L L  $" " "N N N
  5 5 5A A A@ @ @Z Z Z] ] ]d d d
c c c' ' '
	; 	; 	;9 9 98 8 8
. . . . .r   r   c                 F    t          |                              |           S )zreturn expr in repr form)r   r   )r.   settingss     r   sreprr&  R  s      x  ((...r   N)__doc__typingr   r   tDictsympy.core.functionr   sympy.core.mulr   mpmath.libmpr   r   r   printerr
   r   r   r&  r   r   r   <module>r.     s     & % % % % % % % , , , , , ,       8 8 8 8 8 8 8 8 , , , , , , , ,. . . . .' . . .B
 / / / / /r   