+
    i                      a  0 t $ R t^ RIHt ^ RIHtHtHtHtH	t	 ^ RI
t
^ RIHt ^ RIHtHtHtHtHtHtHtHtHt ^ RIHt ^ RIHtHtHtHtHtHtHtH t H!t!H"t"H#t#H$t$H%t%H&t&H't'H(t(H)t)H*t*H+t+H,t,H-t-H.t.H/t/H0t0H1t1H2t2H3t3H4t4H5t5H6t6H7t7H8t8H9t9 ^ RIH:t; ^ RI<H=t= ^ R	I>H?t? ^ R
I@HAtAHBtB ^RICHCtC ^RIDHEtE ^ RIFHGtG ^ RIHHItI ^ RIJHKtK ^ RILHMtM ]'       d_   ^ RINHOtO ^ RIPHQtQ ^ RIRHStS ^ RITHUtU ^ RIVHWtW ^ RIXHYtY ^ RIZH[t[ ^ RI\H]t] ^ RI^H_t_H`t` ^ RIaHbtbHctcHdtd ^ RIeHftfHgtg ^ RIhHiti ^RIjHktkHltlHmtmHntnHoto ]
P                  ! ^
4      tq]6trR t:]s! ]4      tt]s! ]) 4      tuRtv ! R  R!]w4      tx ]y]z]z]z]z3,          t{ ]t|]}]~]3,          tR" R# ltR}R$ R% llt]y]]z,          ]z]z]z3,          t]R~R& R' ll4       t]R~R( R) ll4       tR~R* R+ lltR}R, R- lltR. R/ ltR0 R1 ltR2 R3 ltR4 R5 ltR6 R7 ltR8 R9 ltR: R; ltR< R= ltR> R? ltR}R@ RA lltRB RC ltRD RE ltRF RG ltRH RI ltRJ RK ltRL RM ltRN RO ltRP RQ ltRR RS ltRT RU ltRV RW ltRX RY ltRZ R[ ltR\ R] ltR^ R_ ltR` Ra ltRb Rc ltRd Re ltRf Rg ltRh Ri ltRj Rk ltRl Rm ltRn Ro ltRp Rq lt/ sRr]Rs&   Rt tRu Rv ltRRw lt ! Rx Ry4      tRRz ltRR{ R| lltR# )z^
Adaptive numerical evaluation of SymPy expressions, using mpmath
for mathematical functions.
)annotations)CallableTYPE_CHECKINGAnyoverloadTypeN)	make_mpcmake_mpfmpmpcmpfnsumquadtsquadoscworkprec)inf)!from_intfrom_man_expfrom_rationalfhalffnanfinffninffnonefonefzerompf_absmpf_addmpf_atan	mpf_atan2mpf_cmpmpf_cosmpf_empf_expmpf_logmpf_ltmpf_mulmpf_negmpf_pimpf_powmpf_pow_int	mpf_shiftmpf_sinmpf_sqrt	normalizeround_nearestto_intto_strmpf_tan)bitcount)MPZ)	_infs_nan)dps_to_precprec_to_dps)sympify)S)
SYMPY_INTS)is_sequence)lambdify)as_int)ExprAddMulPow)SymbolIntegralSumProductexplog)Absreimceilingfloor)atan)FloatRationalIntegerAlgebraicNumberNumberc                <    \        \        \        V 4      4      4      # )z8Return smallest integer, b, such that |n|/2**b < 1.
    )mpmath_bitcountabsint)ns   &N/var/www/html/photoedit/myenv/lib/python3.14/site-packages/sympy/core/evalf.pyr3   r3   2   s     3s1v;''    iM  c                      ] tR t^AtRtR# )PrecisionExhausted N)__name__
__module____qualname____firstlineno____static_attributes__rd   ra   r`   rc   rc   A   s    ra   rc   c                    V ^8  d   QhRRRR/# )   xzMPF_TUP | Nonereturn	int | Anyrd   )formats   "r`   __annotate__rp   r   s     ! !~ !) !ra   c                b    V '       d   V \         8X  d   \        # V ^,          V ^,          ,           # )a  Fast approximation of log2(x) for an mpf value tuple x.

Explanation
===========

Calculated as exponent + width of mantissa. This is an
approximation for two reasons: 1) it gives the ceil(log2(abs(x)))
value and 2) it is too high by 1 in the case that x is an exact
power of 2. Although this is easy to remedy by testing to see if
the odd mpf mantissa is 1 (indicating that one was dealing with
an exact power of 2) that would decrease the speed and is not
necessary as this is only being used as an approximation for the
number of bits in x. The correct return value could be written as
"x[2] + (x[3] if x[1] != 1 else 0)".
    Since mpf tuples always have an odd mantissa, no check is done
to see if the mantissa is a multiple of 2 (in which case the
result would be too large by 1).

Examples
========

>>> from sympy import log
>>> from sympy.core.evalf import fastlog, bitcount
>>> s, m, e = 0, 5, 1
>>> bc = bitcount(m)
>>> n = [1, -1][s]*m*2**e
>>> n, (log(n)/log(2)).evalf(2), fastlog((s, m, e, bc))
(10, 3.3, 4)
)r   	MINUS_INF)rl   s   &r`   fastlogrs   r   s%    > U
Q4!A$;ra   c                    V ^8  d   QhRRRR/# )rk   vr>   rm   ztuple[Number, Number] | Nonerd   )ro   s   "r`   rp   rp      s      D ,H ra   c                    V P                  4       w  r#V'       d-   VP                  4       w  rEV\        P                  J d   W$3#  R# V'       d   V\        P                  3# R# )a  Return a and b if v matches a + I*b where b is not zero and
a and b are Numbers, else None. If `or_real` is True then 0 will
be returned for `b` if `v` is a real number.

Examples
========

>>> from sympy.core.evalf import pure_complex
>>> from sympy import sqrt, I, S
>>> a, b, surd = S(2), S(3), sqrt(2)
>>> pure_complex(a)
>>> pure_complex(a, or_real=True)
(2, 0)
>>> pure_complex(surd)
>>> pure_complex(a + b*I)
(2, 3)
>>> pure_complex(I)
(0, 1)
N)as_coeff_Addas_coeff_Mulr9   ImaginaryUnitZero)ru   or_realhtcis   &&    r`   pure_complexr      sV    ( >>DA~~4K    
!&&yra   c                    V ^8  d   QhRRRR/# )rk   magSCALED_ZERO_TUPrm   MPF_TUPrd   )ro   s   "r`   rp   rp      s      _  ra   c                    R # Nrd   r   signs   &&r`   scaled_zeror          ra   c                    V ^8  d   QhRRRR/# )rk   r   r^   rm   ztuple[SCALED_ZERO_TUP, int]rd   )ro   s   "r`   rp   rp      s      S %@ ra   c                    R # r   rd   r   s   &&r`   r   r      r   ra   c                    V ^8  d   QhRRRR/# )rk   r   zSCALED_ZERO_TUP | intrm   z%MPF_TUP | tuple[SCALED_ZERO_TUP, int]rd   )ro   s   "r`   rp   rp      s      $J $J* $J-$Jra   c                z   \        V \        4      '       dC   \        V 4      ^8X  d3   \        V RR7      '       d    V ^ ,          ^ ,          3V R,          ,           # \        V \        4      '       dD   VR9  d   \        R4      h\        \        V 4      Rr2V^8X  d   ^ M^pV.3VR,          ,           pW#3# \        R4      h)a  Return an mpf representing a power of two with magnitude ``mag``
and -1 for precision. Or, if ``mag`` is a scaled_zero tuple, then just
remove the sign from within the list that it was initially wrapped
in.

Examples
========

>>> from sympy.core.evalf import scaled_zero
>>> from sympy import Float
>>> z, p = scaled_zero(100)
>>> z, p
(([0], 1, 100, 1), -1)
>>> ok = scaled_zero(z)
>>> ok
(0, 1, 100, 1)
>>> Float(ok)
1.26765060022823e+30
>>> Float(ok, p)
0.e+30
>>> ok, p = scaled_zero(100, -1)
>>> Float(scaled_zero(ok), p)
-0.e+30
Tscaled:   NNzsign must be +/-1z-scaled zero expects int or scaled_zero tuple.)r   r   )
isinstancetupleleniszeror:   
ValueErrorr+   r   )r   r   rvpss   &&   r`   r   r      s    4 #u#c(a-F3t4L4LAq	|c"g%%	C	$	$w011$$bAAcVbf_uHIIra   c                    V ^8  d   QhRRRR/# )rk   r   z MPF_TUP | SCALED_ZERO_TUP | Nonerm   zbool | Nonerd   )ro   s   "r`   rp   rp      s     G G0 G; Gra   c                   V'       g4   V '       * ;'       g%    V ^,          '       * ;'       d    V R,          '       * # T ;'       dD    \        V ^ ,          \        4      ;'       d%    V ^,          V R,          u;8H  ;'       d    ^8H  # u # )r   r   )r   list)r   r   s   &&r`   r   r      se    w44c!f*44SW4FF:c!fd+FFA#b'0F0FQ0FF0FFra   c                    V ^8  d   QhRRRR/# )rk   resultTMP_RESrm   rn   rd   )ro   s   "r`   rp   rp      s      W  ra   c                
   V \         P                  J d   \        # V w  rr4V'       g   V'       g   \        # V# V'       g   V# \        V4      p\        V4      p\	        WS,
          Wd,
          4      pV\	        WV4      ,
          pV) # )a  
Returns relative accuracy of a complex number with given accuracies
for the real and imaginary parts. The relative accuracy is defined
in the complex norm sense as ||z|+|error|| / |z| where error
is equal to (real absolute error) + (imag absolute error)*i.

The full expression for the (logarithmic) error can be approximated
easily by using the max norm to approximate the complex norm.

In the worst case (re and im equal), this is wrong by a factor
sqrt(2), or by log2(sqrt(2)) = 0.5 bit.
)r9   ComplexInfinityINFrs   max)	r   rP   rQ   re_accim_accre_sizeim_sizeabsolute_errorrelative_errors	   &        r`   complex_accuracyr      st     """
#BFJbkGbkG)7+;<N#c'&;;N?ra   c               (    V ^8  d   QhRRRRRRRR/# 	rk   exprr>   precr^   optionsOPT_DICTrm   r   rd   )ro   s   "r`   rp   rp   	  s(     & &$ &c &H & &ra   c           	        \        W^,           V4      pV\        P                  J d   \        RVR3# Vw  rErgV'       g   WWWF3w  rFrWV'       d{   V P                  '       d7   \        \        \        W^,           4      4      V^,           V4      w  rrVRV
R3# RV9   d   \        P                  ! WE3V4      RVR3# \        V 4      RVR3# V'       d   \        V4      RVR3# R# )rk   NsubsNNNN)
evalfr9   r   r   	is_numberr]   Nlibmpmpc_absr   )r   r   r   r   rP   rQ   r   r   abs_expr_accs   &&&        r`   get_absr   	  s    47+F"""T4%%#BF!#R!7B	>>>"'Ad1H,=(>(,q'#;HT3,, }}bXt4dFDHHt9dD$..	r{D&$..%%ra   c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
rk   r   r>   nor^   r   r   r   rm   r   rd   )ro   s   "r`   rp   rp     s/      4 S  h 7 ra   c                
   Tp^ p \        WV4      pV\        P                  J d   \        RVR3# WaR^1,          w  rxV'       d   W8  g   V^,          ) V8  d   VRVR3# V\	        ^^V,          4      ,          pV^,          pK  )z/no = 0 for real part, no = 1 for imaginary partN)r   r9   r   r   r   )	r   r   r   r   r   r   resvalueaccuracys	   &&&&     r`   get_complex_partr     s    H	A
DG,!###tT))e!e*(*uQxi$.>$$..CAqDM!	Qra   c               (    V ^8  d   QhRRRRRRRR/# )	rk   r   z'Abs'r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp   /  s(     0 0E 0 0x 0G 0ra   c                <    \        V P                  ^ ,          W4      #     )r   argsr   r   r   s   &&&r`   	evalf_absr   /  s    499Q<//ra   c               (    V ^8  d   QhRRRRRRRR/# )	rk   r   z're'r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp   3  (     < <4 <s <X <' <ra   c                >    \        V P                  ^ ,          ^ W4      # r   r   r   r   s   &&&r`   evalf_rer   3      DIIaL!T;;ra   c               (    V ^8  d   QhRRRRRRRR/# )	rk   r   z'im'r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp   7  r   ra   c                >    \        V P                  ^ ,          ^W4      # r   r   r   s   &&&r`   evalf_imr   7  r   ra   c               (    V ^8  d   QhRRRRRRRR/# )rk   rP   r   rQ   r   r^   rm   r   rd   )ro   s   "r`   rp   rp   ;  s(     " " "g "S "W "ra   c                :   V \         8X  d   V\         8X  d   \        R 4      hV \         8X  d   RVRV3# V\         8X  d   V RVR3# \        V 4      p\        V4      pW48  d   TpV\        W4,
          ) ^ 4      ,           pMTpV\        WC,
          ) ^ 4      ,           pWWV3# )z&got complex zero with unknown accuracyN)r   r   rs   min)rP   rQ   r   size_resize_imr   r   s   &&&    r`   finalize_complexr   ;  s    	U{rU{ABB	uRt##	u4t##bkGbkGg/0!44g/0!446!!ra   c               $    V ^8  d   QhRRRRRR/# )rk   r   r   r   r^   rm   rd   )ro   s   "r`   rp   rp   N  s!     " "g "S "W "ra   c                   V \         P                  J d   V # V w  r#rEV'       d'   V\        9  d   \        V4      V) ^,           8  d   RRrBV'       d'   V\        9  d   \        V4      V) ^,           8  d   RRrSV'       da   V'       dY   \        V4      \        V4      ,
          pV^8  d   Wd,
          V) ^,           8:  d   RRrBV^8  d   We,
          V^,
          8  d   RRrSW#WE3# )z&
Chop off tiny real or complex parts.
N)r9   r   r5   rs   )r   r   rP   rQ   r   r   deltas   &&     r`   
chop_partsr   N  s     !!!"BF	b	!wr{dUQY'>4F	b	!wr{dUQY'>4F	bgbk)A:5>dUQY6tA:5>TAX5t6!!ra   c               $    V ^8  d   QhRRRRRR/# )rk   r   r>   r   r   r   r^   rd   )ro   s   "r`   rp   rp   d  s!     0 0t 0W 0C 0ra   c                L    \        V4      pW28  d   \        R V ,          4      hR# )zFailed to distinguish the expression: 

%s

from zero. Try simplifying the input, using chop=True, or providing a higher maxn for evalfN)r   rc   )r   r   r   as   &&& r`   check_targetr   d  s0     Ax  "&)-"/ 0 	0 ra   c               (    V ^8  d   QhRRRRRRRR/# )	rk   r   r>   r   r^   r   r   rm   zTMP_RES | tuple[int, int]rd   )ro   s   "r`   rp   rp   l  s/     l$ l$4 l$S l$8 l$!l$ra   c                $  aaa ^ RI HpHp ^p\        WS4      pV\        P
                  J d   \        R4      hVw  rrV'       d6   V	'       d.   \        \        V4      V
,
          \        V	4      V,
          4      pMBV'       d   \        V4      V
,
          pM'V	'       d   \        V	4      V,
          pMV'       d   R# R# ^
pW) 8  d!   W,           V,           o\        V SS4      w  rrMVoR VVV3R llpRw  ppppVe    V\        8w  d   V! V! V RR7      V4      w  ppV	e    V	\        8w  d   V! V! V RR7      V	4      w  ppV'       dE   \        \        T;'       g    \        4      4      \        \        T;'       g    \        4      4      3# VVVV3# )	z
With no = 1, computes ceiling(expr)
With no = -1, computes floor(expr)

Note: this function either gives the exact result or signals failure.
rP   rQ   z+Cannot get integer part of Complex Infinityc                    V ^8  d   QhRRRR/# )rk   re_imr>   nexprr   rd   )ro   s   "r`   rp   &get_integer_part.<locals>.__annotate__  s     6 6 6g 6ra   c                  <a ^RI Hp Vw   r4pV^ 8H  p\        \        V\        4      4      pV'       dz   \        W,
          ^
S4      w  rxrV'       d   Q h\        V4      ) ^,           pVS8  d   \        WS4      w  rxrV'       d   Q hTp\        \        V\        4      4      pVw   r<pV^ 8H  pV'       g   SP                  RR4      pV'       dq   R o\        ;QJ d-    V3R lVP                  4        4       F  '       d   K   RM"	  RM! V3R lVP                  4        4       4      '       d   V P                  V4      p V! W) RR7      p \        V ^
S4      w  rr \        WRVR3^4       T\        S\        T;'       g    \        \        4      S8H  ,          4      ,          p\!        V4      pV\"        3#   \         d'    T P                  ^ 4      '       g   \        h\        p L{i ; i)	r   r?   r   Fc           	          \        V RR7       R#   \         dI     T P                  4        Uu. uF  p\        TRR7      NK  	  Mu upi  p R#   \         d      R# i ; ii ; i)z)Check for integer or integer + I*integer.F)strictT)r=   r   as_real_imag)rl   r   s   & r`   is_int_reim8get_integer_part.<locals>.calc_part.<locals>.is_int_reim  s_    )q/#% ))>?nn>NO>NVAe4>NO#') )#()	)s1    A$AAAA A$A  A$c              3  4   <"   T F  pS! V4      x  K  	  R # 5ir   rd   ).0ru   r   s   & r`   	<genexpr>6get_integer_part.<locals>.calc_part.<locals>.<genexpr>  s     :z!{1~~zs   TevaluateN)addr@   r^   r0   rndr   rs   getallvaluesr   r   rc   equalsr   r    r   r   )r   r   r@   r   exponentis_intnintireiimire_acciim_accsizenew_expr   rl   x_accr   r   r   r   s   &&              @r`   	calc_part#get_integer_part.<locals>.calc_part  s   !1Q6%%& */b'*+&CgN7CL=1$Dd{-2.**'wveS)*D"Aq1\F FE*A
) 3:qxxz:333:qxxz:::!JJqMEuu5E"5"g6NA%UeT$:A>
 CGAJJ6"<=>>D~Sy & ||A,,s   F7 7!G(G('G(Fr   )r   r   r   )$sympy.functions.elementary.complexesrP   rQ   r   r9   r   r   r   rs   r   r^   r0   )r   r   r   return_intsrP   rQ   assumed_sizer   r   r   r  r  gapmarginr  re_im_r   r   r   s   &ff&               @r`   get_integer_partr  l  sh    <L4w/F"""FGG!'Cg s'#,('#,*@A	clW$	clW$ K))F
g~$s*%*$&!"'7 
6 6p  6Cff
3%<4% 8#>V
3%<4% 8#>V6#,,'(#fS\\E.B*CCCVV##ra   c               (    V ^8  d   QhRRRRRRRR/# )	rk   r   z	'ceiling'r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp     s(     6 6	 6 6x 6G 6ra   c                >    \        V P                  ^ ,          ^V4      # r   r  r   r   s   &&&r`   evalf_ceilingr    s    DIIaL!W55ra   c               (    V ^8  d   QhRRRRRRRR/# )	rk   r   z'floor'r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp     s(     7 7g 7S 78 7 7ra   c                >    \        V P                  ^ ,          RV4      # )r   r   r  r   s   &&&r`   evalf_floorr    s    DIIaL"g66ra   c               (    V ^8  d   QhRRRRRRRR/# )	rk   r   z'Float'r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp     s(     ( (g (S (8 ( (ra   c                "    V P                   R VR 3# r   )_mpf_r   s   &&&r`   evalf_floatr    s    ::tT4''ra   c               (    V ^8  d   QhRRRRRRRR/# )	rk   r   z
'Rational'r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp     s.     A A A3 A Ag Ara   c                L    \        V P                  V P                  V4      R VR 3# r   )r   r   qr   s   &&&r`   evalf_rationalr    s"    .dD@@ra   c               (    V ^8  d   QhRRRRRRRR/# )	rk   r   z	'Integer'r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp     s(     4 4	 4 4x 4G 4ra   c                6    \        V P                  V4      R VR 3# r   )r   r   r   s   &&&r`   evalf_integerr!    s    DFFD!4t33ra   c               (    V ^8  d   QhRRRRRRRR/# )rk   termsr   r   r^   target_precrm   z3tuple[MPF_TUP | SCALED_ZERO_TUP | None, int | None]rd   )ro   s   "r`   rp   rp     s/     S ST S S3 S;Sra   c                D   V  Uu. uF  p\        V^ ,          4      '       d   K  VNK!  	  p pV '       g   R# \        V 4      ^8X  d
   V ^ ,          # . p^RIHp V  FV  pVP                  ! V^ ,          ^4      pV\
        P                  J g   VP                  '       g   KE  VP                  V4       KX  	  V'       d1   ^RI	H
p \        V! V!  V^,           / 4      pV^ ,          V^,          3# ^V,          p	^ ^ r. pV  F  w  rVw  ppppV'       d   V) pVP                  VV,           V,
          4       VV,
          pVV8  dH   VV	8  d/   V
'       d!   V\        \        V
4      4      ,
          V	8  d   Tp
TpK{  V
VV,          ,          p
K  V) pVV,
          V	8  d   V
'       g   TTrK  K  V
V,          V,           p
TpK  	  \        V4      pV
'       g   \        V4      # V
^ 8  d   ^pV
) p
M^ p\        V
4      pVV,           V,
          p\!        VWVV\"        4      V3pV# u upi )a  
Helper for evalf_add. Adds a list of (mpfval, accuracy) terms.

Returns
=======

- None, None if there are no non-zero terms;
- terms[0] if there is only 1 term;
- scaled_zero if the sum of the terms produces a zero by cancellation
  e.g. mpfs representing 1 and -1 would produce a scaled zero which need
  special handling since they are not actually zero and they are purposely
  malformed to ensure that they cannot be used in anything but accuracy
  calculations;
- a tuple that is scaled to target_prec that corresponds to the
  sum of the terms.

The returned mpf tuple will be normalized to target_prec; the input
prec is used to define the working precision.

XXX explain why this is needed and why one cannot just loop using mpf_add
rV   r?   )NN)r   r   numbersrV   _newr9   NaNis_infiniteappendr   r@   r   r3   r]   r   r   r.   r   )r#  r   r$  r}   specialrV   argr@   r   working_precsum_mansum_expabsolute_errrl   r   r   manrM   bcr   r   sum_signsum_bcsum_accuracyrs   &&&                      r`   	add_termsr8    s   0 21VAaD\QQE2	UqQx Gjj1q!!%%<3???NN3  3=$(B/!ube|T6L!W Lc3$CBHx/0g'> %#g,//,>C5L)FErzL('*CW  #e+s21 2 &N>**{(gFV#n4L(Gfk		AHw 3s
   HHc               (    V ^8  d   QhRRRRRRRR/# )	rk   ru   z'Add'r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp   K  s(     ." ." ."c ."H ." ."ra   c           	     X   \        V 4      pV'       d'   Vw  rE\        WAV4      w  rgr\        WQV4      w  rrWiW3# VP                  R \        4      p^ pTp \	        V^V,          4      VR &   V P
                   Uu. uF  p\        W^
,           V4      NK  	  ppVP                  \        P                  4      pV^8  d   \        RVR3# \        V Uu. uF5  p\        V\        4      '       g   K  V^ ,          '       g   K,  VR,          NK7  	  upW4      w  rh\        V Uu. uF5  p\        V\        4      '       g   K  V^,          '       g   K,  VR,          NK7  	  upW4      w  rV^8X  dG   V\        \        \        39   g   V	\        \        \        39   d   \        RVR3# \        P                  # \        WiW34      pVV8  d'   VP                  R4      '       d   \!        RVRW4       MoW,
          VR ,          8  d   MZV\#        ^
^V,          ,           VV,
          4      ,           pV^,          pVP                  R4      '       g   EK  \!        RV4       EK  WR &   \%        VRR	7      '       d   \'        V4      p\%        V	RR	7      '       d   \'        V	4      p	WiW3# u upi u upi u upi )
maxprecN:r   Nrk   :r   Nrk   verbosezADD: wantedaccurate bits, gotzADD: restarting with precTr   )r   r   r   DEFAULT_MAXPRECr   r   countr9   r   r   r8  r   r   r   r   r   printr   r   r   )ru   r   r   r   r|   r~   rP   r   r   rQ   r   
oldmaxprecr   r$  r-  r#  r_   r   r   s   &&&                r`   	evalf_addrB  K  sR   
q/C
 '2v '2vv%%Y8J	AK
 QtV4	;<66B6Cs2Iw/6BKK))*6tT))#Eez!U';W!WQtWWeEtZ
#Eez!U';W!WQtWWeEtZ
6dE4((B42E,ET4--$$$78+{{9%%m[2FW"gi&88#b1a4is):;;DFA{{9%%148#Ib_b_6!!? C
 FEs*   9JJ"-J">J"J';J'J'c               (    V ^8  d   QhRRRRRRRR/# )	rk   ru   z'Mul'r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp   |  s.     {  {  { c { H {  { ra   c           
        \        V 4      pV'       d   Vw  rE\        WQV4      w  rdrtR VR V3# \        V P                  4      pRp	. p
^RIHp V F  p\        WV4      pV\        P                  J d   V
P                  V4       K6  V^ ,          f   V^,          f   Rp	KP  VP                  ! V^ ,          ^4      pV\        P                  J d   \        R VR 3u # VP                  '       g   K  V
P                  V4       K  	  V
'       d1   V	'       d   \        R VR 3# ^RIHp \        V! V
!  V^,           / 4      # V	'       d   R# TpV\        V4      ,           ^,           p\!        ^4      ^ ^3;pw  ppp\        V4      p^ pVP                  \        P"                  4       . p\%        V4       EF,  w  ppVV8w  d5   \        V4      '       d$   VR	,          V,          P'                  4       VR	&   KB  VV8X  d   V\        P"                  J d   K_  \        VVV4      w  ppppV'       d    V'       d   VP                  VVVV34       K  V'       d   VTuw  ppppp MV'       d   Yguw  ppppp V^,          pMRu # V^V,          ,          pVV,          pVV,          pVV,          pV^V,          8  d   VV,          pVV,          pVV,          pK+  \)        VV 4      pEK/  	  V^,          ^,	          p!V'       g9   \+        V!VV\-        V4      V\.        4      p V^,          '       d   R V R V3# V R VR 3# VVV3V8w  d"   V!VV\-        V4      3^ \!        ^ 4      ^ ^ 3pp^ p"M-V^ ,          w  p#p$p%p&\)        V\1        V#V$V%V&34      4      pT#pT$p^p"VV"R   Fz  w  p#p$p%p&\)        V\1        V#V$V%V&34      4      pTp'\3        VV#V'4      p(\3        \5        V4      V$V'4      p)\3        VV$V'4      p*\3        VV#V'4      p+\7        V(V)V'4      p\7        V*V+V'4      pK|  	  VP9                  R4      '       d   \;        RVRV4       V^,          '       d   \5        V4      TppVVVV3# )
NFr&  TrA   r<  zMUL: wantedr=  r   r   )r   r   r   r   r'  rV   r9   r   r+  r(  r)  r   r*  mulrB   r   r4   One	enumerateexpandr   r.   r3   r   r   r&   r'   r   r   r@  ),ru   r   r   r   r   r|   rQ   r   r   has_zeror,  rV   r-  r   numrB   r   r.  startr2  rM   r3  last	directioncomplex_factorsr   rP   r   r   mebw_accr   i0wrewimwre_accwim_accuse_precABCDs,   &&&                                         r`   	evalf_mulr]  |  sG   
q/C
 '2vRv%%<D HGs'*Q&&&NN6"!9ay jjA&!%%<tT))???NN3  tT))S']D1Hb11%% C #d)#a'L q61a<'ELCb t9DIKKOD/39c**R,,.DH$Y3!%%<!&sL'!BB"""BFF#;<"$fLQ1a%"$LQ1a%NI))QqS	qq
a1\>!L C<C,B#uo3 "4 MaDdChsmT3?q==D#%%dC%% b>U"Chsm4q#a&!Q6GBB *9);&Cgwc&S'7'CDFCBBB*9"#*>&Cgw c&S'7'CDFC $HC*AS(3AC*AC*AAx(BAx(B +? ;;y!!-';SAq==R["B2sCra   c               $    V ^8  d   QhRRRRRR/# )rk   ru   z'Pow'r   r^   rm   r   rd   )ro   s   "r`   rp   rp     s+     xG xG xGc xGw xGra   c                	   TpV P                   w  rEVP                  '       EdW   VP                  pV'       g   \        R VR 3# V\	        \
        P                  ! \        V4      4      4      ,          p\        WA^,           V4      pV\        P                  J d   V^ 8  d   R# V# Vw  rrV'       d   V	'       g   \        WV4      R VR 3# V	'       dd   V'       g\   \        WV4      pV^,          pV^ 8X  d   VR VR 3# V^8X  d   R VR V3# V^8X  d   \        V4      R VR 3# V^8X  d   R \        V4      R V3# V'       g   V^ 8  d   \        P                  # R# \        P                  ! W3Wa4      w  r\        WV4      # \        WA^,           V4      pV\        P                  J d$   VP                   '       d   V^ 8  d   R# V# \"        hV\        P$                  J d   Vw  r pV'       d6   \        P&                  ! T;'       g    \(        V3V4      w  r\        WV4      # V'       g   R# \+        V\(        4      '       d   R \-        \        V4      V4      R V3# \-        W4      R VR 3# V^
,          p\        WQV4      pV\        P                  J d   \.        R VR 3# Vw  pp pV'       g   V'       g   \        R VR 3# \1        V4      pV^8  d   VV,          p\        WQV4      w  pp pV\        P2                  J dN   V'       d6   \        P4                  ! T;'       g    \(        V3V4      w  r\        WV4      # \7        VV4      R VR 3# \        WA^,           V4      w  r pV'       g;   V'       g3   V'       d   \.        R VR 3# V^ ,          ^8X  d   \        P                  # R# V'       dU   \        P8                  ! T;'       g    \(        T;'       g    \(        3T;'       g    \(        V3V4      w  r\        WV4      # V'       d7   \        P:                  ! T;'       g    \(        V3VV4      w  r\        WV4      # \+        V\(        4      '       d-   \        P:                  ! V\(        3VV4      w  r\        WV4      # \=        VVV4      R VR 3# )Nr   )r   
is_Integerr   r   r^   mathlog2r]   r   r9   r   r*   r'   r   mpc_pow_intr   is_RationalNotImplementedErrorHalfmpc_sqrtr   r%   r-   r   rs   Exp1mpc_expr#   mpc_powmpc_pow_mpfr)   )ru   r   r   r$  baserM   r   r   rP   rQ   r   r   zcasexreximr   yreyimysizes   &&&                 r`   	evalf_powrt    s   KID
 ~~~tT)) 	DIIc!f%&&tAXw/Q&&&1u--M!'brk2D+tKKbB;/Aq5Dqy$T11qyQk11qyqz4d::qyWQZ{::1u((())""B8Q54447+F"""???Qw--M!! aff}!Q^^S\\E3$7>FB#BD11))#u'#,5tTAA"D$44 	BJD3g&F"""T4%%NCa3T4%%CLE qys'2S!Q qvv~]]CLL5##6=FB#BK88sK($TAA473NCa3tT))q6Q;$$$%% \\E3<<%(3<<%*=  44
""CLL5##6[I44	U		""C<kB44 sC-t[$FFra   c               (    V ^8  d   QhRRRRRRRR/# )	rk   r   z'exp'r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp   |  s.     K KE K Kx KG Kra   c                h    ^RI Hp \        V! \        P                  V P
                  RR7      W4      # )r   rC   Fr   )powerrD   rt  r9   rh  rM   )r   r   r   rD   s   &&& r`   	evalf_exprx  |  s#    SE:DJJra   c               (    V ^8  d   QhRRRRRRRR/# )	rk   ru   r>   r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp     s(     =' ='$ ='c ='H =' ='ra   c                   ^ RI HpHpHp \	        W4      '       d   \
        pM6\	        W4      '       d   \        pM\	        W4      '       d   \        pM\        hV P                  ^ ,          pV^,           p\        WxV4      w  rrV
'       d;   RV9   d   V P                  VR,          4      p \        V P                  V4      W4      # V	'       gH   \	        W4      '       d   \        RVR3# \	        W4      '       d   R	# \	        W4      '       d   R	# \        h\        V	4      pV^8  d   V! W\        4      RVR3# V^
8  d   W,           p\        WxV4      w  rr V! W\        4      p\        V4      pV) pW,
          V,
          pVV8  dw   VP!                  R4      '       d&   \#        RVRVRV4       \#        \%        V^
4      4       WP!                  R\&        4      8  d   VRVR3# VV,          p\        WxV4      w  rrK  VRVR3# )
z@
This function handles sin , cos and tan of complex arguments.

)cossintanr   Nr<  zSIN/COS/TANwantedr  r;  r   )(sympy.functions.elementary.trigonometricr{  r|  r}  r   r!   r,   r2   re  r   r   r   _eval_evalfr   rs   r   r   r@  r1   r>  )ru   r   r   r{  r|  r}  funcr-  xprecrP   rQ   r   r   xsizeyrs  r  r   s   &&&               r`   
evalf_trigr    s   
 GF!	A			A		!!
&&)C 2IE"3w7BF	Wwv'AQ]]4($88atT))))))%% BKE qyBc"D$44{!&s7!; 3
fMS(d?{{9%%mXxucJfQm${{9o>>$$..SLE%*3w%?"BFdD$&&ra   c               (    V ^8  d   QhRRRRRRRR/# )	rk   r   z'log'r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp     s(     2& 2&E 2& 2&x 2&G 2&ra   c           	        \        V P                  4      ^8  d   V P                  4       p \        WV4      # V P                  ^ ,          pV^
,           p\        W4V4      pV\        P
                  J d   V# Vw  rgrYgu;J d   f
   M M\        pV'       dV   ^ RIHp
 ^ RI	H
p \        V! V
! VRR7      RR7      W4      p\        Yv;'       g    \        V4      pV^ ,          W^,          V3# \        V\        4      ^ 8  p\        \        V4      V\         4      p\#        V4      pW,
          V8  dv   V\        8w  dk   ^RIHp V! \        P(                  VRR7      p\+        VW4      w  rg p	V\#        V4      ,
          p\        \        \-        V\.        V4      4      V\         4      pTpV'       d   V\1        V4      VV3# VRVR3# )r   N)rO   )rN   Fr   r?   )r   r   doitr   r9   r   r   r  rO   &sympy.functions.elementary.exponentialrN   	evalf_logr   r    r$   r   r   rs   r   r@   NegativeOnerB  r   r   r(   )r   r   r   r-  r   r   ro  rp  xaccr   rO   rN   rP   rQ   imaginary_termr  r@   r   prec2r   s   &&&                 r`   r  r    s   
499~ayy{T))
))A,CbyH3'*F"""Cd  
<> C%(594JsLL5$/!ubQ%%%c5)A-N	tS	)B2;D{X"+!--u5"36!Q73<'WWS$67sCF6$<--4%%ra   c               (    V ^8  d   QhRRRRRRRR/# )	rk   ru   z'atan'r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp     s(     6 6& 6 6h 67 6ra   c                    V P                   ^ ,          p\        W1^,           V4      w  rErgYEu;J d   f   M MR# V'       d   \        h\        WA\        4      RVR3# )r   Nr   )r   r   re  r   r   )ru   r   r   r-  ro  rp  reaccimaccs   &&&     r`   
evalf_atanr    sR    
&&)C"3q':Ce

!!Cs#T455ra   c               $    V ^8  d   QhRRRRRR/# )rk   r   r^   r   dictrm   rd   )ro   s   "r`   rp   rp      s!      S   ra   c                    / pVP                  4        F7  w  r4\        V4      pVP                  '       d   VP                  V 4      pWBV&   K9  	  V# )z;Change all Float entries in `subs` to have precision prec. )itemsr9   is_Floatr  )r   r   newsubsr   rQ  s   &&   r`   
evalf_subsr     sG    G

aD:::d#A
	 
 Nra   c               (    V ^8  d   QhRRRRRRRR/# r   rd   )ro   s   "r`   rp   rp     s(      $ c H  ra   c                p   ^RI HpHp RV9   d   V P                  \	        WR,          4      4      p VP                  4       pVR \        V R4      '       d   \        WV4      # \        V \        4      '       d   \        V! V 4      W4      # \        V \        4      '       d   \        V! V 4      W4      # \        h)r   )rV   rX   r   r  )r'  rV   rX   r   r  copyhasattrr   r   floatr^   re  )r   r   r   rV   rX   newoptss   &&&   r`   evalf_piecewiser    s    'yyD&/:;,,.FO4  W--dE""td44dC  66 ra   c               (    V ^8  d   QhRRRRRRRR/# )	rk   r   z'AlgebraicNumber'r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp     s)     - -& -c -H - -ra   c                6    \        V P                  4       W4      # r   )r   to_root)r   r   r   s   &&&r`   evalf_alg_numr    s    d,,ra   c               (    V ^8  d   QhRRRRRRRR/# )	rk   rl   r   r   r^   r   r   rm   	mpc | mpfrd   )ro   s   "r`   rp   rp   &  s(     " " "C "( "y "ra   c                   ^RI HpHpHp \	        V 4      p \        W4      '       g   V R8X  d   \        ^ 4      # \        W4      '       d   \        R4      # \        W4      '       d   \        R4      # \        WV4      p\        V4      # )r   )InfinityNegativeInfinityrz   g        r   z-inf)	r'  r  r  rz   r8   r   r   r   quad_to_mpmath)rl   r   r   r  r  rz   r   s   &&&    r`   	as_mpmathr  &  sl    99
A!a3h1v!5z!&&6{1G$F&!!ra   c               (    V ^8  d   QhRRRRRRRR/# 	rk   r   z
'Integral'r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp   4  s.     \ \j \ \h \7 \ra   c           	       aaaaa V P                   ^ ,          oV P                   ^,          w  or4W48X  d   ^ ;r4MQSSP                  9  dA   VP                  VP                  ,          '       d   WC,
          pVP                  '       d   ^ TrCTP                  R\        4      p\        V^V,          4      VR&   \        V^,           4      ;_uu_ 4        \        W1^,           V4      p\        WA^,           V4      p^ RIH	pH
p ^RIHp	 RR.o\        o\        oR VVVVV3R llp
VP                  R4      R8X  d   V	! R	S.R
7      pV	! RS.R
7      pV	! R4      pSP                  V! VS,          V,           4      V,          4      pV'       g-   SP                  V! VS,          V,           4      V,          4      pV'       g   \        R4      h\        ^\         P"                  ,          W,          ,          V^,           V4      p\%        WV.VR7      p\        pM'\'        WV.^R7      w  pp\)        VP*                  4      pRRR4       WbR&   S^ ,          '       d   XP,                  P*                  pV\.        8X  d0   \1        \3        \5        VSX4      ) 4      4      w  pp\1        V4      pM2\3        \5        S\)        V4      ,
          V,
          X4      ) 4      pMRRppS^,          '       d   XP6                  P*                  pV\.        8X  d0   \1        \3        \5        VSX4      ) 4      4      w  pp\1        V4      pM2\3        \5        S\)        V4      ,
          V,
          X4      ) 4      pMRRppVVVV3pV#   + '       g   i     EL?; i)r   r;  )r{  r|  )WildFc                    V ^8  d   QhRRRR/# )rk   r}   r>   rm   r  rd   )ro   s   "r`   rp   !do_integral.<locals>.__annotate__W  s     	$ 	$ 	$) 	$ra   c                j  < \        S\        P                  R S	V //4      w  rr4T;'       g
    S^ ,          S^ &   T;'       g
    S^,          S^&   \        S\	        V4      4      o\        S\	        V4      4      oV'       d   \        T;'       g    \        V4      # \        T;'       g    \        4      # )r   )r   r
   r   r   rs   r   r   r   )
r}   rP   rQ   r   r   r  	have_partmax_imag_termmax_real_termrl   s
   &    r`   fdo_integral.<locals>.fW  s    %*46Aq6:J%K"BF--1IaL--1IaLwr{;Mwr{;M2;;++r{{U##ra   quadoscrY  )excluderZ  r\  zbAn integrand of the form sin(A*x+B)*f(x) or cos(A*x+B)*f(x) is required for oscillatory quadrature)period)errorN)r   free_symbolsr   r   r>  r   r   r  r  r{  r|  symbolr  rr   matchr   r9   Pir   r   rs   r  realr   r   r^   r   imag)r   r   r   xlowxhighdiffrA  r{  r|  r  r  rY  rZ  r\  rO  r  r   quadrature_errorquadrature_errrP   re_sr   rQ   im_sr   r  r  r  r  rl   s   &&&                      @@@@@r`   do_integralr  4  s   99Q<DYYq\NAt}u	
$##	#
  1 111<D~~~eY8JZ40GI	$(		by'2%G4 	F EN	%.%.	$ 	$ ;;v%'S1#&AS1#&AS	A

3qsQw<>*AJJs1Q37|A~.  "N O Oqvad{D2Iw?FQuf=F(%+Ae}A%F"FN&~';';<_ 
b $I||#[[..;&sCmEU,V+V'WXLD&T"B#mgbk9D@BRSSTF4F||#[[..;&sCmEU,V+V'WXLD&T"B#mgbk9D@BRSSTF4FVV#FMU 
		s   B9M2
3M2>A>M22N	c               (    V ^8  d   QhRRRRRRRR/# r  rd   )ro   s   "r`   rp   rp     s(       3  g ra   c                ~   V P                   p\        V4      ^8w  g   \        V^ ,          4      ^8w  d   \        hTp^ pVP                  R\        4      p \        WV4      p\        V4      pW8  d    V# WF8  d    V# VR8X  d   V^,          pMV\        V^V,          4      ,          p\        WF4      pV^,          pKk  )r   r;  r   )	limitsr   re  r   r   r  r   r   r   )	r   r   r   r  r   r   r;  r   r   s	   &&&      r`   evalf_integralr    s    [[F
6{a3vay>Q.!!H	Akk)S)G
TW5#F+ M  M r> MHD!Q$'Hx)	Qra   c               (    V ^8  d   QhRRRRRRRR/# )rk   numerr>   denomr_   rE   rm   ztuple[int, Any, Any]rd   )ro   s   "r`   rp   rp     s)     '/ '/T '/$ '/6 '/>R '/ra   c                $   ^ RI Hp V! W4      pV! W4      pVP                  4       pVP                  4       pWv,
          pV'       d   VRR3# TP                  4       VP                  4       ,          p	^RIHp
 V
! \        V	4      ^4      '       g   WR3# VP                  4       VP                  4       u;8X  d   ^ 8X  d   M MW^ 3# VP                  4       ^,          pVP                  4       ^,          pWW,
          VP                  4       ,          3# )a	  
Returns
=======

(h, g, p) where
-- h is:
    > 0 for convergence of rate 1/factorial(n)**h
    < 0 for divergence of rate factorial(n)**(-h)
    = 0 for geometric or polynomial convergence or divergence

-- abs(g) is:
    > 1 for geometric convergence of rate 1/h**n
    < 1 for geometric divergence of rate h**n
    = 1 for polynomial convergence or divergence

    (g < 0 indicates an alternating series)

-- p is:
    > 1 for polynomial convergence of rate 1/n**h
    <= 1 for polynomial divergence of rate n**(-h)

)PolyN)equal_valued)sympy.polys.polytoolsr  degreeLCr'  r  r]   
all_coeffs)r  r  r_   r  npoldpolr   r  rateconstantr  pcqcs   &&&          r`   check_convergencer    s    . +>D>DAA5DT4wwy4779$H%Hq))t##{{}**q  		1	B		1	BBGTWWY...ra   c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
rk   r   r>   r_   rE   rK  r^   r   rm   r   rd   )ro   s   "r`   rp   rp     s6     L L L& L LC LC Lra   c                  aaa ^RI HpHp ^ RIHp V\        R4      8X  d   \        R4      hV'       d   V P                  WV,           4      p V! W4      pVf   \        R4      hVP                  4       w  r\        W4      o\        W4      o\        WV4      w  rpV
^ 8  d   \        RV
) ,          4      hV P                  V^ 4      pVP                  '       g   \        R4      hTpV
^ 8  g   V
^ 8X  d   \        V4      ^8  d   \        VP                  4      V,          VP                   ,          pTp^p\        V4      ^8  dR   V\        S! V^,
          4      4      ,          pV\        S! V^,
          4      4      ,          pW,          pV^,          pKa  \#        W) 4      # V^ 8  p\        V4      ^8  d#   \        R	\        ^V,          4      ,          4      hV^8  g   V! V^4      '       d   V'       g   \        R
V) ,          4      hRp\%        V4      p ^V,          o\        VP                  4      S,          VP                   ,          pV.3VVV3R llp\'        V4      ;_uu_ 4        \)        V^ \*        .RR7      pRRR4       V! XV4      pVe   VV8X  d    VP,                  # W3,          pTpK    + '       g   i     L=; i)z
Sum a rapidly convergent infinite hypergeometric series with
given general term, e.g. e = hypsum(1/factorial(n), n). The
quotient between successive terms must be a quotient of integer
polynomials.
)rV   r  )	hypersimpr   zdoes not support inf precNz#a hypergeometric series is requiredzSum diverges like (n!)^%iz3Non rational term functionality is not implemented.zSum diverges like (%i)^nzSum diverges like n^%ic           	       < V '       db   \        V 4      p V^ ;;,          \        S! V ^,
          4      4      ,          uu&   V^ ;;,          \        S! V ^,
          4      4      ,          uu&   \        \        V^ ,          S) 4      4      # r   )r^   r4   r	   r   )k_termfunc1func2r  s   &&r`   summandhypsum.<locals>.summand  s]    AA!HE!a%L 11H!HU1q5\!22HU1Xv >??ra   
richardson)method)r'  rV   r  sympy.simplify.simplifyr  r  re  r   as_numer_denomr<   r  r   rd  r]   r4   r   r  r   r7   r   r   
mpmath_infr  )r   r_   rK  r   rV   r  r  hsrJ  denr|   gr   etermtermr   r  altvoldndigterm0r  ru   vfr  r  r  s   &&&&                    @@@r`   hypsumr    s\    -1uU|!"=>>yyI&	4	B	z!"GHH  "HCQEQE!,GA!1u4;<<IIaOE!"WXXD 	1uaCFQJDFFt#.$i!mCa!e%%DSq1u&&DIAFAAu%%!eq6A:7#ac(BCCq5\!Q''5!<==4  dFE[E)dff4E"' @ @ $1j/,G  q$BDBJ ww LDD  s   -J77K	c               (    V ^8  d   QhRRRRRRRR/# )	rk   r   z	'Product'r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp   &  s(      Y c H  ra   c                    \         ;QJ d&    R  V P                   4       F  '       d   K   RM	  RM! R  V P                   4       4      '       d   \        V P                  4       WR7      pV# ^ RIHp \        V P                  V4      WR7      pV# )c              3  b   "   T F%  q^,          V^,          ,
          P                   x  K'  	  R# 5i)r   N)r`  )r   ls   & r`   r   evalf_prod.<locals>.<genexpr>'  s      
9[aD1Q4K##[s   -/FT)r   r   rH   )r   r  r   r  sympy.concrete.summationsrI   rewrite)r   r   r   r   rI   s   &&&  r`   
evalf_prodr  &  sc    
s
9T[[
9sss
9T[[
999tyy{? M 	2t||C(tEMra   c               (    V ^8  d   QhRRRRRRRR/# )	rk   r   z'Sum'r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp   /  s(     '& '&E '& '&x '&G '&ra   c           	        ^RI Hp RV9   d   V P                  VR,          4      p V P                  pV P                  p\        V4      ^8w  g   \        V^ ,          4      ^8w  d   \        hVP                  '       d   RRVR3# V^
,           p V^ ,          w  rxp	V	\        P                  Jg%   V\        P                  J g   V\        V4      8w  d   \        h\        WG\        V4      V4      p
V\        V
4      ,
          p\        V
4      R8  d   \        WG\        V4      V4      p
V
R\        W4      R3#   \         d    T! R4      T) ,          p\        ^^4       F^  p^T,          T,          ;rT P!                  YTRR7      w  ppTP#                  4       pT\        P$                  J d   \        hTT8:  g   K^   M	  \        \#        \'        X4      ^T4      ^ ,          4      p\#        XYb4      w  ppppTf   T) pTf   T) pTTTT3u # i ; i)r   r&  r   Ng       @F)rO  r_   epseval_integrali)r'  rV   r   functionr  r   re  is_zeror9   r  r  r^   r  rs   r   rangeeuler_maclaurinr   r)  r]   )r   r   r   rV   r  r  r  r_   r   rQ  ru   r   r  r   rO  r   errrP   rQ   r   r   s   &&&                  r`   	evalf_sumr  /  s   yy)==D[[F
6{a3vay>Q.!!|||T4%%2IE&)aAJJ!q'9'9"9Q#a&[%%4CFE*wqz!1:tA.A$D($.. &CjD5!q!AqD4KA))A# * %FAs))+Caee|))cz  eCHb'2156!&q%!9B>TF>TF2vv%%%&s   B&D4 4B H9AH
Hc               (    V ^8  d   QhRRRRRRRR/# 	rk   rl   r>   r   r^   r   r   rm   r   rd   )ro   s   "r`   rp   rp   _  s(      D  h 7 ra   c                (   VR ,          V ,          p\        V\        4      '       d   V'       g   R# VP                  RVR3# RV9  d   / VR&   VR,          pVP                  V R\        34      w  rVWa8  d   V# \        \        V4      W4      pWq3W@&   V# )r   N_cacher   )r   r   r  r   rr   r   r8   )rl   r   r   valcachecachedcached_precru   s   &&&     r`   evalf_symbolr  _  s    
&/!
C#s))yy$d**7" "GH!#iiD)+<=M'#,.9ra   z:dict[Type[Expr], Callable[[Expr, int, OPT_DICT], TMP_RES]]evalf_tablec                    ^ RI Hp  ^ RIHp ^RIHp ^RIHp ^RIH	pH
pHpHpHpHp	Hp
HpHpHpHpHpHp ^RIHp ^RIHpHp ^ RIHpHpHp ^ R	IH pH!p ^ R
I"H#pH$p ^ RI%H&p ^ RI'H(pH)pH*pH+p ^ RI,H-p  / V\\        bV\\        bV\^        bV\`        bV\b        bVR bVR bVR bVR bVR bVR bV
R bVR bV	R bV\d        bV\f        bV\f        b/ V\f        bV\h        bV\j        bV\l        bV\n        bV\p        bV\r        bV\t        bV\v        bV\x        bV\z        bV \|        bV\~        bV \        bV\        bV\        bCsCR# )r   rJ   rH   r?   rA   )rh  rV   rf  ry   rX   r)  r  rF  r  rW   rz   r   rY   rC   )DummyrE   )rO   rQ   rP   rL   rR   )	Piecewise)rU   r{  r|  r}  rF   c                    R R VR 3# r   rd   rl   r   r   s   &&&r`   <lambda>%_create_evalf_table.<locals>.<lambda>  s    dD$'?ra   c                    \         R VR 3# r   r   r  s   &&&r`   r  r        tT4&>ra   c                    \         R VR 3# r   )r   r  s   &&&r`   r  r    s    tT4'@ra   c                     \        V4      R VR 3# r   )r(   r  s   &&&r`   r  r    s    fTlD$%Era   c                     \        V4      R VR 3# r   )r"   r  s   &&&r`   r  r    s    dT4'Fra   c                    R \         R V3# r   r  r  s   &&&r`   r  r    s    tT40Hra   c                    \         R VR 3# r   )r   r  s   &&&r`   r  r    s    udD$.Gra   c                "    \         P                  # r   )r9   r   r  s   &&&r`   r  r    s
    !2C2Cra   c                    \         R VR 3# r   )r   r  s   &&&r`   r  r    r   ra   N)Dsympy.concrete.productsrK   r   rI   r   r@   rE  rB   r'  rh  rV   rf  ry   rX   r)  r  rF  r  rW   rz   r   rY   rw  rD   r  r  rE   r  rO   rQ   rP   r  rM   rN   #sympy.functions.elementary.integersrS   rT   $sympy.functions.elementary.piecewiser  r  rU   r{  r|  r}  sympy.integrals.integralsrG   r  r  r  r!  rx  r  rB  r]  rt  r  r  r   r   r   r  r  r  r  r  r  r  r  )!rK   rI   r@   rB   rh  rV   rf  ry   rX   r)  r  rF  r  rW   rz   r   rY   rD   r  rE   rO   rQ   rP   rM   rN   rS   rT   r  rU   r{  r|  r}  rG   s!                                    r`   _create_evalf_tabler,  s  s   /-/ / / /%@@?B>LL2))|) 	{) 	.	)
 	) 	?) 	>) 	@) 	E) 	F) 	H) 	G) 	C) 	>)  	Y!)$ 	Z%)& 	Z')( 	Z)), 	Y-). 	Y/)0 	Y1)4 	Y5)6 	j7)8 	Y9)< 	H=)> 	H?)@ 	{A)B 	C)F 	.G)H 	YI)J 	K)L 	?M)P 	Q)Kra   c               (    V ^8  d   QhRRRRRRRR/# r  rd   )ro   s   "r`   rp   rp     s.     U UT U Ux UG Ura   c                   ^ RI HpHp  \        \	        V 4      ,          pV! WV4      pVP                  R4      '       df   \!        RV 4       \!        R	\#        V\$        4      '       d"   \'        V^ ,          ;'       g    \(        ^24      MT4       \!        R
V4       \!        4        VP                  RR4      pV'       d[   VRJ d   TpMF\+        \-        R\.        P0                  ! V4      ,          R,           4      4      pV^8X  d
   V^,          p\3        Wn4      pVP                  R4      '       d   \5        WV4       V#   \
         Ed.    RT9   d"   T P                  \        YR,          4      4      p T P                  T4      pTf   \        h\        TRR4      pTf   \        hT! 4       w  rT	P                  ! T4      '       g   T
P                  ! T4      '       d   \        hT	'       g   Rp	RpM9T	P                  '       d"   T	P                  ! TRR7      P                  p	TpM\        hT
'       g   Rp
RpM9T
P                  '       d"   T
P                  ! TRR7      P                  p
TpM\        hYY3p ELMi ; i)a&  
Evaluate the ``Expr`` instance, ``x``
to a binary precision of ``prec``. This
function is supposed to be used internally.

Parameters
==========

x : Expr
    The formula to evaluate to a float.
prec : int
    The binary precision that the output should have.
options : dict
    A dictionary with the same entries as
    ``EvalfMixin.evalf`` and in addition,
    ``maxprec`` which is the maximum working precision.

Returns
=======

An optional tuple, ``(re, im, re_acc, im_acc)``
which are the real, imaginary, real accuracy
and imaginary accuracy respectively. ``re`` is
an mpf value tuple and so is ``im``. ``re_acc``
and ``im_acc`` are ints.

NB: all these return values can be ``None``.
If all values are ``None``, then that represents 0.
Note that 0 is also represented as ``fzero = (0, 0, 0, 0)``.
r   r   Nr   F)
allow_intsr<  z	### inputz
### outputz### rawchopTg      @r   g rh
)r  rP   rQ   r  typeKeyErrorr   r  r  re  getattrhasr   
_to_mpmathr  r   r@  r   r   r1   r   r^   roundra  log10r   r   )rl   r   r   r  r  rfr7  xer   rP   rQ   reprecimprecr0  	chop_precs   &&&            r`   r   r     s   > J #a!q @ {{9k1lAu9M9MF1Q4==5"5STUi;;vu%D4<I
 E&D)9"9C"?@AIA~Q	q${{8Q4 He  #Wz$89A]]4 :%%r>48%%66#;;"&&++%%BF\\\t6<<BF%%BF\\\t6<<BF%%F";#s0   D> >BI7I7+I7.I71I7+I76I7c                   Vf   \         MVP                   pVf   \        MVP                  pV \        P                  J d   \        hV w  rE pV'       d   V'       g   \
        pV! WE34      # V'       d	   V! V4      # V! \
        4      # )z@Turn the quad returned by ``evalf`` into an ``mpf`` or ``mpc``. )r   r	   r9   r   re  r   )r  ctxr   r   rP   rQ   r   s   &&     r`   r  r    sl    k(s||Ck(s||CA!!LBAq	BB8}	2w5zra   c                  Z    ] tR tRt$ RtRtR]R&   RR lt]tR R lt	R	 R
 lt
RR ltRtR# )
EvalfMixini  z$Mixin class adding evalf capability.ztuple[str, ...]	__slots__Nc           	        ^RI HpHp	 Ve   TM^pV'       d   \        V4      '       d   \	        R4      hV^8X  dN   \        W	4      '       d=   ^RIHp
 V P                  ^W#WEWg4      pV
! V4      pVP                  ^V,
          4      pV# \        '       g   \        4        \        V4      pR\        V\        V\        ,          4      4      RVRVRV/pVe   W.R&   Ve   WnR	&    \        W^,           V4      pT\*        P,                  J d   T# Tw  ppppT\*        P.                  J g   T\*        P.                  J d   \*        P.                  # T'       d+   \        \1        TT4      ^4      pTP2                  ! TT4      pM\*        P4                  pT'       dH   \        \1        TT4      ^4      pTP2                  ! TT4      pTT\*        P6                  ,          ,           # T#   \          d    \#        T R4      '       d&   Te"   T P%                  T4      P'                  T4      pMT P'                  T4      pTf   T u # TP(                  '       g   Tu #  \        TY4      p ELi  \          d    Tu u # i ; ii ; i)
a  
Evaluate the given formula to an accuracy of *n* digits.

Parameters
==========

subs : dict, optional
    Substitute numerical values for symbols, e.g.
    ``subs={x:3, y:1+pi}``. The substitutions must be given as a
    dictionary.

maxn : int, optional
    Allow a maximum temporary working precision of maxn digits.

chop : bool or number, optional
    Specifies how to replace tiny real or imaginary parts in
    subresults by exact zeros.

    When ``True`` the chop value defaults to standard precision.

    Otherwise the chop value is used to determine the
    magnitude of "small" for purposes of chopping.

    >>> from sympy import N
    >>> x = 1e-4
    >>> N(x, chop=True)
    0.000100000000000000
    >>> N(x, chop=1e-5)
    0.000100000000000000
    >>> N(x, chop=1e-4)
    0

strict : bool, optional
    Raise ``PrecisionExhausted`` if any subresult fails to
    evaluate to full accuracy, given the available maxprec.

quad : str, optional
    Choose algorithm for numerical quadrature. By default,
    tanh-sinh quadrature is used. For oscillatory
    integrals on an infinite interval, try ``quad='osc'``.

verbose : bool, optional
    Print debug information.

Notes
=====

When Floats are naively substituted into an expression,
precision errors may adversely affect the result. For example,
adding 1e16 (a Float) to 1 will truncate to 1e16; if 1e16 is
then subtracted, the result will be 0.
That is exactly what happens in the following:

>>> from sympy.abc import x, y, z
>>> values = {x: 1e16, y: 1, z: 1e16}
>>> (x + y - z).subs(values)
0

Using the subs argument for evalf is the accurate way to
evaluate such an expression:

>>> (x + y - z).evalf(subs=values)
1.00000000000000
)rV   rZ   z"subs must be given as a dictionary)_magr;  r0  r   r<  r   r  )r'  rV   rZ   r;   	TypeErrorr   r   rC  r   r6  r  r,  r6   r   r^   LG10re  r  r   r  r   r9   r   r)  r   r(  rz   ry   )selfr_   r   maxnr0  r   r  r<  rV   rZ   rC  r   rO  r   r   r   ru   rP   rQ   r   r   r   s   &&&&&&&&              r`   r   EvalfMixin.evalf  s   B 	+ABK%%@AA 6j.."At4GBRA!a%BI{!1~c$DI7G5"FO"FO	473F" Q&&&M!'B;"+55LCf%q)AB"BBCf%q)AB"B1??***I? # 	tV$$)9IIdO//5$$T*y[[[q$0& 	s7   #G AI59I5I5II1,I50I11I5c                    V ^8  d   QhRRRR/# )rk   r   r^   rm   r>   rd   )ro   s   "r`   rp   EvalfMixin.__annotate__  s      3 4 ra   c                4    V P                  V4      pVf   T pV# )z@Helper for evalf. Does the same thing but takes binary precision)r  )rF  r   r7  s   && r`   _evalfEvalfMixin._evalf  s!    T"9Ara   c                    V ^8  d   QhRRRR/# )rk   r   r^   rm   Expr | Nonerd   )ro   s   "r`   rp   rJ    s        ra   c                	    R # r   rd   )rF  r   s   &&r`   r  EvalfMixin._eval_evalf  s    ra   c                	4   R pV'       d   V P                   '       d   V P                  # \        V R4      '       d   \        V P	                  V4      4      #  \        W/ 4      p\        V4      #   \         Ed    T P                  T4      pTf   \        T4      hTP                  '       d   \        TP                  4      u # TP                  4       w  rgT'       d)   TP                   '       d   \        TP                  4      pM*TP                  '       d   TP                  pM\        T4      hT'       d)   TP                   '       d   \        TP                  4      pM*TP                  '       d   TP                  pM\        T4      h\        Yg34      u # i ; i)zcannot convert to mpmath number_as_mpf_val)r`  r   r  r	   rS  r   r  re  r  r   r  r  r   r   r   )rF  r   r/  errmsgr   ru   rP   rQ   s   &&&     r`   r5  EvalfMixin._to_mpmath  s&   2$///66M4''D,,T233	&4r*F!&))" 	&  &Ay ((zzz((^^%FBbmmmbdd^XX ((bmmmbdd^XX ((RH%%)	&s<   A- -=F+F+F.'FF6F'F0$FFrd   )   Nd   FFNF)T)re   rf   rg   rh   __doc__rA  __annotations__r   r_   rL  r  r5  ri   rd   ra   r`   r@  r@    s1    .!#I#yv 	A& &ra   r@  c                >    \        V RR7      P                  ! V3/ VB # )ah  
Calls x.evalf(n, \*\*options).

Explanations
============

Both .n() and N() are equivalent to .evalf(); use the one that you like better.
See also the docstring of .evalf() for information on the options.

Examples
========

>>> from sympy import Sum, oo, N
>>> from sympy.abc import k
>>> Sum(1/k**k, (k, 1, oo))
Sum(k**(-k), (k, 1, oo))
>>> N(_, 4)
1.291

T)rational)r8   r   )rl   r_   r   s   &&,r`   r   r     s!    . 1t$**1888ra   c          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )rk   rl   r>   r  rO  rO  r^   r   zOPT_DICT | Nonerm   r   rd   )ro   s   "r`   rp   rp     s2     1  1  1 K 1 !$1 '61 BI1 ra   c                   Ve[   VP                   '       g   VP                  '       d   V^ 8  g   \        R4      h\        ^V,          ^/ 4      w  p  p\	        V4      p\        V ^/ 4      w  rg p\	        V4      \	        V4      r\        W4      ^,           p
\        ^W*,           ^,           4      pT;'       g    / p\        WV4      # )a  
Evaluate *x* to within a bounded absolute error.

Parameters
==========

x : Expr
    The quantity to be evaluated.
eps : Expr, None, optional (default=None)
    Positive real upper bound on the acceptable error.
m : int, optional (default=0)
    If *eps* is None, then use 2**(-m) as the upper bound on the error.
options: OPT_DICT
    As in the ``evalf`` function.

Returns
=======

A tuple ``(re, im, re_acc, im_acc)``, as returned by ``evalf``.

See Also
========

evalf

zeps must be positive)rd  r  r   r   rs   r   )rl   r  rO  r   r7  r   r~   dnrnir_   r   s   &&&&        r`   _evalf_with_bounded_errorra    s    : 3<<<a3441S5!R(
1aAJq!RJA!Q QZBaA 	AquqyAmmGwra   )F)r   r   )rV  )Nr   N)__conditional_annotations__rX  
__future__r   typingr   r   r   r   r   ra  mpmath.libmpr   mpmathr   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/   r0   r1   r2   r3   r\   mpmath.libmp.backendr4   mpmath.libmp.libmpcr5   mpmath.libmp.libmpfr6   r7   r8   	singletonr9   sympy.external.gmpyr:   sympy.utilities.iterablesr;   sympy.utilities.lambdifyr<   sympy.utilities.miscr=   sympy.core.exprr>   sympy.core.addr@   sympy.core.mulrB   sympy.core.powerrD   sympy.core.symbolrE   r+  rG   r   rI   r(  rK   r  rM   rN   r  rO   rP   rQ   r)  rS   rT   r  rU   r'  rV   rW   rX   rY   rZ   rb  rE  r   r  r   rr   r>  ArithmeticErrorrc   r   r^   r   r   r  strr   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r!  r8  rB  r]  rt  rx  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rY  r,  r   r  r@  r   ra  )rb  s   @r`   <module>rv     s   # ? ?  G G G $W W W W W W W W W
 5 $ ) 8   * 1 - '$""$(2-/?@@B=JJyy}( J:+	 	 	 S#s"
#&  S>!H> S	3S01 
 
	 
$JNG:&, 0<<"&",0l$^67(A4Sl."b{ |xGDK
='@2&j6"-"\~4'/TL^'&`" KMG L9xUp"j& j&Z941  1 ra   