
    \h                    "   % S r SSKJr  SSKJrJrJrJrJr  SSK	r	SSK
Jr  SSKJrJrJrJrJrJrJrJrJr  SSKJr  SSK
JrJrJrJrJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J8r8  SSK
J9r:  SS	K;J<r<  SS
K=J>r>  SSK?J@r@JArA  SSKBJBrB  SSKCJDrD  SSKEJFrF  SSKGJHrH  SSKIJJrJ  SSKKJLrL  \(       a^  SSKMJNrN  SSKOJPrP  SSKQJRrR  SSKSJTrT  SSKUJVrV  SSKWJXrX  SSKYJZrZ  SSK[J\r\  SSK]J^r^J_r_  SSK`JaraJbrbJcrc  SSKdJereJfrf  SSKgJhrh  SSKiJjrjJkrkJlrlJmrmJnrn  \	R                  " S 5      rp\5rqS! r9\r" \5      rs\r" \* 5      rtS"ru " S# S$\v5      rw \x\y\y\y\y4   rz \r{\|\}\4   r~SVS% jrSWSXS& jjr\x\\y   \y\y\y4   r\SYSZS' jj5       r\SYS[S( jj5       rSY S\S) jjrSWS]S* jjrS^S+ jrS_S, jrS`S- jrSaS. jrSbS/ jrScS0 jrSdS1 jrSeS2 jrSfS3 jrSW SgS4 jjrShS5 jrSiS6 jrSjS7 jrSkS8 jrSlS9 jr  SmS: jrSnS; jrSoS< jrSpS= jrSqS> jrSrS? jrSsS@ jrStSA jrSuSB jrS_SC jrSvSD jrSwSE jrSxSF jrSxSG jrSySH jrSzSI jrS{SJ jrS|SK jrS}SL jr0 qSM\SN'   SO rS}SP jrS~SQ jr " SR SS5      rSST jr   S     SSU jjrg)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Number
   c                <    [        [        [        U 5      5      5      $ )z8Return smallest integer, b, such that |n|/2**b < 1.
    )mpmath_bitcountabsint)ns    H/var/www/auris/envauris/lib/python3.13/site-packages/sympy/core/evalf.pyr4   r4   2   s     3s1v;''    iM  c                      \ rS rSrSrg)PrecisionExhaustedA    N)__name__
__module____qualname____firstlineno____static_attributes__rh   rd   rc   rf   rf   A   s    rd   rf   c                F    U (       a
  U [         :X  a  [        $ U S   U S   -   $ )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)xs    rc   fastlogrs   r   s%    > U
Q4!A$;rd   c                    U R                  5       u  p#U(       a*  UR                  5       u  pEU[        R                  L a  X$4$  gU(       a  U[        R                  4$ g)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_Mulr;   ImaginaryUnitZero)vor_realhtcis         rc   pure_complexr      sV    ( >>DA~~4K    
!&&yrd   c                    g Nrh   magsigns     rc   scaled_zeror          rd   c                    g r   rh   r   s     rc   r   r      r   rd   c                8   [        U [        5      (       a-  [        U 5      S:X  a  [        U SS9(       a  U S   S   4U SS -   $ [        U [        5      (       a9  US;  a  [        S5      e[        [        U 5      S	p2US:X  a  SOSnU/4USS -   nX#4$ [        S
5      e)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scaledr   r9   N)r9   zsign must be +/-1r   z-scaled zero expects int or scaled_zero tuple.)
isinstancetupleleniszeror<   
ValueErrorr,   r   )r   r   rvpss        rc   r   r      s    4 #u#c(a-F3t4LAq	|c!"g%%	C	$	$w011$$bAAcVbf_uHIIrd   c                    U(       d)  U (       + =(       d    U S   (       + =(       a
    U S   (       + $ U =(       a5    [        U S   [        5      =(       a    U S   U S   s=:H  =(       a    S:H  $ s  $ )Nr9   r   r   )r   list)r   r   s     rc   r   r      sY    w4c!f*4SW4F:c!fd+FA#b'0F0FQ0FF0FFrd   c                    U [         R                  L a  [        $ U u  pp4U(       d  U(       d  [        $ U$ U(       d  U$ [        U5      n[        U5      n[	        XS-
  Xd-
  5      nU[	        XV5      -
  nU* $ )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.
)r;   ComplexInfinityINFrs   max)	resultrR   rS   re_accim_accre_sizeim_sizeabsolute_errorrelative_errors	            rc   complex_accuracyr      st     """
#BFJbkGbkG)7+;<N#c'&;;N?rd   c           	        [        XS-   U5      nU[        R                  L a
  [        S US 4$ Uu  pEpgU(       d  XWXF4u  pFpWU(       ap  U R                  (       a.  [        [        [        XS-   5      5      US-   U5      u  ppUS U
S 4$ SU;   a  [        R                  " XE4U5      S US 4$ [        U 5      S US 4$ U(       a  [        U5      S US 4$ g)Nro   subsNNNN)
evalfr;   r   r   	is_numberr`   Nlibmpmpc_absr   )exprprecoptionsr   rR   rS   r   r   abs_expr_accs              rc   get_absr   	  s    47+F"""T4%%#BF!#R!7B	>>"'Ad1H,=(>(,q'#;HT3,, }}bXt4dFDHHt9dD$..	r{D&$..%rd   c                    UnSn [        XU5      nU[        R                  L a
  [        SUS4$ XaSS2   u  pxU(       a  X:  d
  US   * U:  a  USUS4$ U[	        SSU-  5      -  nUS-  nMg  )z/no = 0 for real part, no = 1 for imaginary partr   r9   Nro      )r   r;   r   r   r   )	r   nor   r   r   r~   resvalueaccuracys	            rc   get_complex_partr     s    H	A
DG,!###tT))e!e*(*uQxi$.>$$..CAqDM!	Q rd   c                4    [        U R                  S   X5      $ Nr   )r   argsr   r   r   s      rc   	evalf_absr   /  s    499Q<//rd   c                6    [        U R                  S   SX5      $ r   r   r   r   s      rc   evalf_rer   3      DIIaL!T;;rd   c                6    [        U R                  S   SX5      $ Nr   r9   r   r   s      rc   evalf_imr   7  r   rd   c                   U [         :X  a  U[         :X  a  [        S5      eU [         :X  a  S US U4$ U[         :X  a  U S US 4$ [        U 5      n[        U5      nX4:  a  UnU[        X4-
  * S5      -   nOUnU[        XC-
  * S5      -   nXXV4$ )Nz&got complex zero with unknown accuracyr   )r   r   rs   min)rR   rS   r   size_resize_imr   r   s          rc   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!!rd   c                ~   U [         R                  L a  U $ U u  p#pEU(       a!  U[        ;  a  [        U5      U* S-   :  a  Su  p$U(       a!  U[        ;  a  [        U5      U* S-   :  a  Su  p5U(       aI  U(       aB  [        U5      [        U5      -
  nUS:  a  Xd-
  U* S-   ::  a  Su  p$US:  a  Xe-
  US-
  :  a  Su  p5X#XE4$ )z&
Chop off tiny real or complex parts.
r   NNro   )r;   r   r6   rs   )r   r   rR   rS   r   r   deltas          rc   
chop_partsr   N  s     !!!"BF	b	!wr{dUQY'>
	b	!wr{dUQY'>
	bgbk)A:5>dUQY6#JBA:5>TAX5#JB6!!rd   c                @    [        U5      nX2:  a  [        SU -  5      eg )NzFailed to distinguish the expression: 

%s

from zero. Try simplifying the input, using chop=True, or providing a higher maxn for evalf)r   rf   )r   r   r   as       rc   check_targetr   d  s0     Ax  "&)-"/ 0 	0 rd   c                  ^^^ SSK JnJn  Sn[        XT5      nU[        R
                  L a  [        S5      eUu  ppU(       a,  U	(       a%  [        [        U5      U
-
  [        U	5      U-
  5      nO5U(       a  [        U5      U
-
  nOU	(       a  [        U	5      U-
  nO	U(       a  ggSnX* :  a  X-   U-   m[        U TT5      u  ppOUmSUUU4S jjnSu  nnnnUb  U[        :w  a  U" U" U S	S
9U5      u  nnU	b  U	[        :w  a  U" U" U S	S
9U	5      u  nnU(       aB  [        [        U=(       d    [        5      5      [        [        U=(       d    [        5      5      4$ UUUU4$ )z
With no = 1, computes ceiling(expr)
With no = -1, computes floor(expr)

Note: this function either gives the exact result or signals failure.
r   rR   rS   r   z+Cannot get integer part of Complex Infinityr   r   r   r]   c                6  >^ SSK Jn  Uu    p4nUS:H  n[        [        U[        5      5      nU(       an  [        X-
  ST5      u  pxpU(       a   e[        U5      * S-   nUT:  a  [        XT5      u  pxpU(       a   eUn[        [        U[        5      5      nUu    p<nUS:H  nU(       d  TR                  SS5      nU(       a<  S m[        U4S	 jUR                  5        5       5      (       a  U R                  U5      n U" X* SS
9n [        U ST5      u  pp [        XS US 4S5        U[        T[        U=(       d    [        [        5      T:H  -  5      -  n[!        U5      nU["        4$ ! [         a%    U R                  S5      (       d  [        e[        n Npf = f)Nr9   rA   r   r]   ro   r   Fc           	          [        U SS9  g! [         aC     U R                  5        Vs/ s H  n[        USS9PM     Os  snf   n g! [         a      gf = ff = f)z)Check for integer or integer + I*integer.F)strictT)r?   r   as_real_imag)rr   r~   s     rc   is_int_reim8get_integer_part.<locals>.calc_part.<locals>.is_int_reim  s_    )q/#% ))>?nn>NO>NVAe4>NO#') )#()	)s/   
 
AA?A
AAAAc              3  4   >#    U  H  nT" U5      v   M     g 7fr   rh   ).0ry   r   s     rc   	<genexpr>6get_integer_part.<locals>.calc_part.<locals>.<genexpr>  s     :z!{1~~zs   evaluaterp   )addrB   ra   r1   rndr   rs   getallvaluesr   r   rf   equalsr   r!   r   r   )re_imnexprrB   r   exponentis_intnintireiimire_acciim_accsizenew_expr   rr   x_accr   r   r   r   s                   @rc   	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
) :qxxz:::!JJqMEuu5E"5"g6NA%UeT$:A>
 CGAJ6"<=>>D~Sy & ||A,,s   E) ),FFFr   )r   r@   r   MPF_TUP)$sympy.functions.elementary.complexesrR   rS   r   r;   r   r   r   rs   r   ra   r1   )r   r   r   return_intsrR   rS   assumed_sizer   r   r   r   r   gapmarginr   re_im_r   r   r   s    ``                @rc   get_integer_partr   l  s_    <L4w/F"""FGG!'Cg s'#,('#,*@A	clW$	clW$ )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##rd   c                6    [        U R                  S   SU5      $ r   r   r   r   s      rc   evalf_ceilingr     s    DIIaL!W55rd   c                6    [        U R                  S   SU5      $ )Nr   r   r   r   s      rc   evalf_floorr    s    DIIaL"g66rd   c                "    U R                   S US 4$ r   )_mpf_r   s      rc   evalf_floatr    s    ::tT4''rd   c                L    [        U R                  U R                  U5      S US 4$ r   )r   r   qr   s      rc   evalf_rationalr    s"    .dD@@rd   c                6    [        U R                  U5      S US 4$ r   )r   r   r   s      rc   evalf_integerr	    s    DFFD!4t33rd   c                   U  Vs/ s H  n[        US   5      (       a  M  UPM     n nU (       d  g[        U 5      S:X  a  U S   $ / nSSKJn  U  HP  nUR                  " US   S5      nU[
        R                  L d  UR                  (       d  M?  UR                  U5        MR     U(       a#  SSK	J
n  [        U" U6 US-   0 5      nUS   US   4$ SU-  n	Su  p/ nU  H  u  pUu  nnnnU(       a  U* nUR                  UU-   U-
  5        UU-
  nUU:  a8  UU	:  a(  U
(       a  U[        [        U
5      5      -
  U	:  a  Un
UnMf  U
UU-  -  n
Mp  U* nUU-
  U	:  a  U
(       d  UUpM  M  U
U-  U-   n
UnM     [        U5      nU
(       d  [        U5      $ U
S:  a  SnU
* n
OSn[        U
5      nUU-   U-
  n[!        UXUU["        5      U4nU$ s  snf )	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
r   r   r9   rX   rA   r   ro   r   )r   r   numbersrX   _newr;   NaNis_infiniteappendr   rB   r   r4   r`   r   r   r/   r   )termsr   target_precr|   specialrX   argrB   r   working_precsum_mansum_expabsolute_errrr   r   r   manrO   bcr   r   sum_signsum_bcsum_accuracyrs                            rc   	add_termsr    s   0 21VAaD\QE2	UqQx Gjj1q!!%%<3???NN3  3=$(B/!ube|T6LG 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
   GGc           	        [        U 5      nU(       a&  Uu  pE[        XAU5      u  pgp[        XQU5      u  ppXiX4$ UR                  S[        5      nSnUn [	        USU-  5      US'   U R
                   Vs/ s H  n[        XS-   U5      PM     nnUR                  [        R                  5      nUS:  a
  [        S US 4$ [        U Vs/ s H.  n[        U[        5      (       d  M  US   (       d  M&  USS S2   PM0     snX5      u  ph[        U Vs/ s H.  n[        U[        5      (       d  M  US   (       d  M&  USS S2   PM0     snX5      u  pUS:X  aD  U[        [        [        4;   d  U	[        [        [        4;   a
  [        S US 4$ [        R                  $ [        XiX45      nUU:  a%  UR                  S5      (       a  [!        SUSX5        ONX-
  US   :  a  OBU[#        SSU-  -   UU-
  5      -   nUS-  nUR                  S5      (       a  [!        S	U5        GM  XS'   [%        US
S9(       a  ['        U5      n[%        U	S
S9(       a  ['        U	5      n	XiX4$ s  snf s  snf s  snf )Nmaxprecr   r9   ro   r]   verbosezADD: wantedaccurate bits, gotzADD: restarting with precTr   )r   r   r   DEFAULT_MAXPRECr   r   countr;   r   r   r  r   r   r   r   r   printr   r   r   )ry   r   r   r   r{   r}   rR   r   r   rS   r   
oldmaxprecr~   r  r  r  rb   r   r   s                      rc   	evalf_addr(  K  sW   
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!WQqt!tWeEtZ
#Eez!U';W!WQqt!tWeEtZ
6dE4((B42E,ET4--$$$78+{{9%%m[2FW"gi&88#b1a4is):;;DFA{{9%%1487 : $Ib_b_6!!? C
 FEs*   4II$I0II$,I$8I$c           
        [        U 5      nU(       a  Uu  pE[        XQU5      u  pdptS US U4$ [        U R                  5      nSn	/ n
SSKJn  U H  n[        XU5      nU[        R                  L a  U
R                  U5        M5  US   c
  US   c  Sn	ME  UR                  " US   S5      nU[        R                  L a  [        S US 4s  $ UR                  (       d  M  U
R                  U5        M     U
(       a*  U	(       a
  [        S US 4$ SSKJn  [        U" U
6 US-   0 5      $ U	(       a  gUnU[        U5      -   S	-   n[!        S5      SS4=nu  nnn[        U5      nSnUR                  [        R"                  5        / n[%        U5       H  u  nnUU:w  a+  [        U5      (       a  US
   U-  R'                  5       US
'   M7  UU:X  a  U[        R"                  L a  MR  [        UUU5      u  nnnnU(       a  U(       a  UR                  UUUU45        M  U(       a  UUsu  nnnnn OU(       a  Xgsu  nnnnn US-  nO  gUSU-  -  nUU-  nUU-  nUU-  nUSU-  :  a  UU-  nUU-  nUU-  nUSU-  :  a  M  [)        UU 5      nM     US-  S-	  n!U(       d3  [+        U!UU[-        U5      U[.        5      n US-  (       a  S U S U4$ U S US 4$ UUU4U:w  a!  U!UU[-        U5      4S[!        S5      SS4nnSn"O)US   u  n#n$n%n&[)        U[1        U#U$U%U&45      5      nU#nU$nSn"UU"S   Hz  u  n#n$n%n&[)        U[1        U#U$U%U&45      5      nUn'[3        UU#U'5      n([3        [5        U5      U$U'5      n)[3        UU$U'5      n*[3        UU#U'5      n+[7        U(U)U'5      n[7        U*U+U'5      nM|     UR9                  S5      (       a  [;        SUSU5        US-  (       a  [5        U5      UnnUUUU4$ )NFr9   r  r   TrC   r   r      r   ro   rp   r"  zMUL: wantedr#  )r   r   r   r   r  rX   r;   r   r  r  r  r   r  mulrD   r   r5   One	enumerateexpandr   r/   r4   r   r   r'   r(   r   r   r&  ),ry   r   r   r   r   r{   rS   r   r   has_zeror  rX   r  r   numrD   r   r  startr  rO   r  last	directioncomplex_factorsr~   rR   r   r   mebw_accr   i0wrewimwre_accwim_accuse_precABCDs,                                               rc   	evalf_mulrC  |  sM   
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 1\>! #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rd   c                z   UnU R                   u  pEUR                  (       Ga;  UR                  nU(       d
  [        S US 4$ U[	        [
        R                  " [        U5      5      5      -  n[        XAS-   U5      nU[        R                  L a	  US:  a  gU$ Uu  ppU(       a  U	(       d  [        XU5      S US 4$ U	(       aZ  U(       dS  [        XU5      nUS-  nUS:X  a  US US 4$ US:X  a  S US U4$ US:X  a  [        U5      S US 4$ US:X  a  S [        U5      S U4$ U(       d  US:  a  [        R                  $ g[        R                  " X4Xa5      u  p[        XU5      $ [        XAS-   U5      nU[        R                  L a   UR                   (       a	  US:  a  gU$ ["        eU[        R$                  L a  Uu  p  nU(       a4  [        R&                  " U=(       d    [(        U4U5      u  p[        XU5      $ U(       d  g[+        U[(        5      (       a  S [-        [        U5      U5      S U4$ [-        X5      S US 4$ US-  n[        XQU5      nU[        R                  L a
  [.        S US 4$ Uu  nn  nU(       d  U(       d
  [        S US 4$ [1        U5      nUS:  a  UU-  n[        XQU5      u  nn  nU[        R2                  L aK  U(       a4  [        R4                  " U=(       d    [(        U4U5      u  p[        XU5      $ [7        UU5      S US 4$ [        XAS-   U5      u  p  nU(       d2  U(       d+  U(       a
  [.        S US 4$ US   S:X  a  [        R                  $ gU(       aQ  [        R8                  " U=(       d    [(        U=(       d    [(        4U=(       d    [(        U4U5      u  p[        XU5      $ U(       a5  [        R:                  " U=(       d    [(        U4UU5      u  p[        XU5      $ [+        U[(        5      (       a,  [        R:                  " U[(        4UU5      u  p[        XU5      $ [=        UUU5      S US 4$ )	Nr*  r   r   r   r9   ro   rp   r]   )r   
is_Integerr   r   ra   mathlog2r`   r   r;   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*   )ry   r   r   r  baserO   r   r   rR   rS   r   r   zcasexreximr   yreyimysizes                       rc   	evalf_powrY    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~]]CL5##6=FB#BK88sK($TAA473NCa3tT))q6Q;$$$% \E3<%(3<%*=  44
""CL5##6[I44	U		""C<kB44 sC-t[$FFrd   c                b    SSK Jn  [        U" [        R                  U R
                  SS9X5      $ )Nr9   rE   Fr   )powerrF   rY  r;   rM  rO   )r   r   r   rF   s       rc   	evalf_expr\  |  s#    SE:DJJrd   c                   SSK JnJnJn  [	        X5      (       a  [
        nO4[	        X5      (       a  [        nO[	        X5      (       a  [        nO[        eU R                  S   nUS-   n[        XxU5      u  ppU
(       a5  SU;   a  U R                  US   5      n [        U R                  U5      X5      $ U	(       dB  [	        X5      (       a
  [        SUS4$ [	        X5      (       a  g[	        X5      (       a  g[        e[        U	5      nUS:  a  U" X[        5      SUS4$ US:  a  X-   n[        XxU5      u  pp U" X[        5      n[        U5      nU* nX-
  U-
  nUU:  ap  UR!                  S	5      (       a%  [#        S
USUSU5        [#        [%        US5      5        XR!                  S[&        5      :  a  USUS4$ UU-  n[        XxU5      u  ppM  USUS4$ )z@
This function handles sin , cos and tan of complex arguments.

r   )cossintan   r   Nr   r9   r]   r"  zSIN/COS/TANwantedr   r!  )(sympy.functions.elementary.trigonometricr^  r_  r`  r   r"   r-   r3   rJ  r   r   r   _eval_evalfr   rs   r   r   r&  r2   r$  )ry   r   r   r^  r_  r`  funcr  xprecrR   rS   r   r   xsizeyrX  r   r   s                     rc   
evalf_trigri    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$&&rd   c           	     2   [        U R                  5      S:  a  U R                  5       n [        XU5      $ U R                  S   nUS-   n[        X4U5      nU[        R
                  L a  U$ Uu  pgpXgs=L a  c	  O  O[        nU(       aF  SSKJn
  SSK	J
n  [        U" U
" USS9SS9X5      n[        Xv=(       d    [        U5      nUS   XS   U4$ [        U[        5      S:  n[        [        U5      U[         5      n[#        U5      nX-
  U:  am  U[        :w  ac  SS	KJn  U" [        R(                  USS9n[+        UX5      u  pg  n	U[#        U5      -
  n[        [        [-        U[.        U5      5      U[         5      nUnU(       a  U[1        U5      UU4$ US US 4$ )
Nr9   r   r]   )rQ   )rP   Fr   ro   rA   )r   r   doitr   r;   r   r   r   rQ   &sympy.functions.elementary.exponentialrP   	evalf_logr    r!   r%   r   r   rs   r   rB   NegativeOner(  r   r   r)   )r   r   r   r  r   r   rT  rU  xaccr   rQ   rP   rR   rS   imaginary_termr   rB   r   prec2r   s                       rc   rm  rm    s   
499~ayy{T))
))A,CbyH3'*F"""Cd  
<> C%(594JsL5$/!ubQ%%%c5)A-N	tS	)B2;D{X"+!--u5"36!Q73<'WWS$67sCF6$<--4%%rd   c                    U R                   S   n[        X1S-   U5      u  pEpgXEs=L a  c   g  U(       a  [        e[        XA[        5      S US 4$ )Nr   r*  r   )r   r   rJ  r   r   )ry   r   r   r  rT  rU  reaccimaccs           rc   
evalf_atanru    sQ    
&&)C"3q':Ce
 
!!Cs#T455rd   c                    0 nUR                  5        H6  u  p4[        U5      nUR                  (       a  UR                  U 5      nXBU'   M8     U$ )z;Change all Float entries in `subs` to have precision prec. )itemsr;   is_Floatrd  )r   r   newsubsr   r7  s        rc   
evalf_subsrz     sE    G

aD::d#A
	 
 Nrd   c                `   SSK JnJn  SU;   a  U R                  [	        XS   5      5      n UR                  5       nUS	 [        U S5      (       a  [        XU5      $ [        U [        5      (       a  [        U" U 5      X5      $ [        U [        5      (       a  [        U" U 5      X5      $ [        e)Nr9   )rX   rZ   r   re  )r  rX   rZ   r   rz  copyhasattrr   r   floatra   rJ  )r   r   r   rX   rZ   newoptss         rc   evalf_piecewiser    s    'yyD&/:;,,.FO4  W--dE""td44dC  66 rd   c                6    [        U R                  5       X5      $ r   )r   to_root)r   r   r   s      rc   evalf_alg_numr    s    d,,rd   c                   SSK JnJnJn  [	        U 5      n [        X5      (       d  U S:X  a  [        S5      $ [        X5      (       a  [        S5      $ [        X5      (       a  [        S5      $ [        XU5      n[        U5      $ )Nr9   )InfinityNegativeInfinityrx   g        r   r   z-inf)	r  r  r  rx   r:   r   r   r   quad_to_mpmath)rr   r   r   r  r  rx   r   s          rc   	as_mpmathr  &  sl    99
A!a3h1v!5z!&&6{1G$F&!!rd   c           	       ^^^^^ U R                   S   mU R                   S   u  mp4X4:X  a  S=p4OFTTR                  ;  a6  UR                  UR                  -  (       a  XC-
  nUR                  (       a  SUpCUR                  S[        5      n[        USU-  5      US'   [        US-   5         [        X1S-   U5      n[        XAS-   U5      nSSKJ	nJ
n  SSKJn	  S	S	/m[        m[        mSUUUUU4S
 jjn
UR                  S5      S:X  a  U	" ST/S9nU	" ST/S9nU	" S5      nTR                  U" UT-  U-   5      U-  5      nU(       d   TR                  U" UT-  U-   5      U-  5      nU(       d  [        S5      e[        S[         R"                  -  X   -  US-   U5      n[%        XU/US9n[        nO$['        XU/SS9u  nn[)        UR*                  5      nS S S 5        XbS'   TS   (       au  WR,                  R*                  nU[.        :X  a/  [1        [3        [5        UTW5      * 5      5      u  nn[1        U5      nO+[3        [5        T[)        U5      -
  U-
  W5      * 5      nOSu  nnTS   (       au  WR6                  R*                  nU[.        :X  a/  [1        [3        [5        UTW5      * 5      5      u  nn[1        U5      nO+[3        [5        T[)        U5      -
  U-
  W5      * 5      nOSu  nnUUUU4nU$ ! , (       d  f       GN#= f)Nr   r9   r!  ro   r*     )r^  r_  )WildFc                P  > [        T[        R                  ST	U 005      u  pp4U=(       d    TS   TS'   U=(       d    TS   TS'   [        T[	        U5      5      m[        T[	        U5      5      mU(       a  [        U=(       d    [        U5      $ [        U=(       d    [        5      $ )Nr   r   r9   )r   r   r   r   rs   r   r   r   )
r|   rR   rS   r   r   re  	have_partmax_imag_termmax_real_termrr   s
        rc   fdo_integral.<locals>.fW  s    %*46Aq6:J%K"BF-1IaL-1IaLwr{;Mwr{;M2;++r{U##rd   quadoscr?  )excluder@  rB  zbAn integrand of the form sin(A*x+B)*f(x) or cos(A*x+B)*f(x) is required for oscillatory quadrature)period)errorr   )r|   r@   return	mpc | mpf)r   free_symbolsr   r   r$  r   r   r  rc  r^  r_  symbolr  rq   matchr   r;   Pir   r   rs   r  realr   r   ra   r   imag)r   r   r   xlowxhighdiffr'  r^  r_  r  r  r?  r@  rB  r5  r  r   quadrature_errorquadrature_errrR   re_sr   rS   im_sr   re  r  r  r  rr   s                            @@@@@rc   do_integralr  4  s   99Q<DYYq\NAt}u	
$##	#
  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
F|#[[..;&sCmEU,V+V'WXLD&T"B#mgbk9D@BRSSTF
FVV#FMU 
	s   ,D,K44
Lc                L   U R                   n[        U5      S:w  d  [        US   5      S:w  a  [        eUnSnUR                  S[        5      n [        XU5      n[        U5      nX:  a   U$ XF:  a   U$ US:X  a  US-  nOU[        USU-  5      -  n[        XF5      nUS-  nMW  )Nr9   r   rp   r!  r   ro   )	limitsr   rJ  r   r   r  r   r   r   )	r   r   r   r  r   r~   r!  r   r   s	            rc   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 rd   c                   SSK Jn  U" X5      nU" X5      nUR                  5       nUR                  5       nXv-
  nU(       a  USS4$ UR                  5       UR                  5       -  n	SSKJn
  U
" [        U	5      S5      (       d  XS4$ UR                  5       UR                  5       s=:X  a  S:X  a  O  OXS4$ UR                  5       S   nUR                  5       S   nXX-
  UR                  5       -  4$ )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)

r   )PolyNr9   )equal_valued)sympy.polys.polytoolsr  degreeLCr  r  r`   
all_coeffs)numerdenomrb   r  npoldpolr   r  rateconstantr  pcqcs                rc   check_convergencer    s    . +>D>DAA5DT4wwy4779$H%Hq))t##{{}**q  		1	B		1	BBGTWWY...rd   c                  ^^^ SSK JnJn  SSKJn  U[        S5      :X  a  [        S5      eU(       a  U R                  XU-   5      n U" X5      nUc  [        S5      eUR                  5       u  p[        X5      m[        X5      m[        XU5      u  pnU
S:  a  [        S	U
* -  5      eU R                  US5      nUR                  (       d  [        S
5      eUnU
S:  d  U
S:X  a  [        U5      S:  a  [        UR                  5      U-  UR                   -  nUnSn[        U5      S:  aH  U[        T" US-
  5      5      -  nU[        T" US-
  5      5      -  nX-  nUS-  n[        U5      S:  a  MH  [#        X* 5      $ US:  n[        U5      S:  a  [        S[        SU-  5      -  5      eUS:  d  U" US5      (       a  U(       d  [        SU* -  5      eSn[%        U5      n SU-  m[        UR                  5      T-  UR                   -  nU/4UUU4S jjn['        U5         [)        US[*        /SS9nSSS5        U" WU5      nUb  UU:X  a   UR,                  $ X3-  nUnM  ! , (       d  f       N5= f)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.
r9   )rX   r  r   )	hypersimpr   zdoes not support inf precNz#a hypergeometric series is requiredzSum diverges like (n!)^%iz3Non rational term functionality is not implemented.r*  zSum diverges like (%i)^nzSum diverges like n^%ir   c           	        > U (       aI  [        U 5      n US==   [        T" U S-
  5      5      -  ss'   US==   [        T" U S-
  5      5      -  ss'   [        [        US   T* 5      5      $ r   )ra   r5   r
   r   )k_termfunc1func2rq  s     rc   summandhypsum.<locals>.summand  s]    AA!HE!a%L 11H!HU1q5\!22HU1Xv >??rd   
richardson)method)r  rX   r  sympy.simplify.simplifyr  r~  rJ  r   as_numer_denomr>   r  r   rI  r`   r5   r   r  r   r8   r   r   
mpmath_infr  )r   rb   r1  r   rX   r  r  hsr0  denr{   gr   etermtermr   r  altvoldndigterm0r  ry   vfr  r  rq  s                           @@@rc   hypsumr    sk    -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	 $i!m
 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   'I((
I6c                    [        S U R                   5       5      (       a  [        U R                  5       XS9nU$ SSKJn  [        U R                  U5      XS9nU$ )Nc              3  J   #    U  H  oS    US   -
  R                   v   M     g7f)r9   ro   N)rE  )r   ls     rc   r   evalf_prod.<locals>.<genexpr>'  s      
9[aD1Q4K##[s   !#)r   r   r   rJ   )r   r  r   rk  sympy.concrete.summationsrK   rewrite)r   r   r   r   rK   s        rc   
evalf_prodr  &  sO    

9T[[
999tyy{? M 	2t||C(tEMrd   c           	        SSK Jn  SU;   a  U R                  US   5      n U R                  nU R                  n[        U5      S:w  d  [        US   5      S:w  a  [        eUR                  (       a  S S US 4$ US-   n US   u  pxn	U	[        R                  Ld"  U[        R                  L d  U[        U5      :w  a  [        e[        XG[        U5      U5      n
U[        U
5      -
  n[        U
5      S:  a  [        XG[        U5      U5      n
U
S [        X5      S 4$ ! [         a    U" S5      U* -  n[        SS	5       HQ  nS
U-  U-  =pU R!                  XUSS9u  nnUR#                  5       nU[        R$                  L a  [        eUU::  d  MQ    O   [        [#        ['        W5      SU5      S   5      n[#        WXb5      u  nnnnUc  U* nUc  U* nUUUU4s $ f = f)Nr9   r  r   r   rp   r]   ig       @r*  ro   F)r5  rb   epseval_integralra  )r  rX   r   functionr  r   rJ  is_zeror;   r  r  ra   r  rs   r   rangeeuler_maclaurinr   r  r`   )r   r   r   rX   re  r  rq  rb   r   r7  ry   r   r  r~   r5  r   errrR   rS   r   r   s                        rc   	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D A/GA	GGc                   US   U    n[        U[        5      (       a  U(       d  gUR                  S US 4$ SU;  a  0 US'   US   nUR                  U S [        45      u  pVXa:  a  U$ [        [        U5      X5      nXq4X@'   U$ )Nr   r   _cache)r   r   r  r   rq   r   r:   )rr   r   r   valcachecachedcached_precry   s           rc   evalf_symbolr  _  s    
&/!
C#s)yy$d**7" "GH!#iiD)+<=M'#,.9rd   z:dict[Type[Expr], Callable[[Expr, int, OPT_DICT], TMP_RES]]evalf_tablec                    SSK Jn   SSKJn  SSKJn  SSKJn  SSKJ	nJ
nJnJnJnJn	Jn
JnJnJnJnJnJn  SSKJn  SS	KJnJn  SS
KJnJnJn  SSKJ nJ!n  SSK"J#nJ$n  SSK%J&n  SSK'J(nJ)nJ*nJ+n  SSK,J-n   0 U[\        _U[\        _U[^        _U[`        _U[b        _US _US _US _US _US _US _U
S _US _U	S _U[d        _U[f        _U[f        _0 U[f        _U[h        _U[j        _U[l        _U[n        _U[p        _U[r        _U[t        _U[v        _U[x        _U[z        _U [|        _U[~        _U [        _U[        _U[        _EqCg )Nr   rL   rJ   r9   rA   rC   )rM  rX   rK  rw   rZ   r  rn  r,  r  rY   rx   r   r[   rE   )DummyrG   )rQ   rS   rR   rN   rT   )	Piecewise)rW   r^  r_  r`  rH   c                    S S US 4$ r   rh   rr   r   r   s      rc   <lambda>%_create_evalf_table.<locals>.<lambda>  s    dD$'?rd   c                    [         S US 4$ r   r   r  s      rc   r  r        tT4&>rd   c                    [         S US 4$ r   )r   r  s      rc   r  r    s    tT4'@rd   c                     [        U5      S US 4$ r   )r)   r  s      rc   r  r    s    fTlD$%Erd   c                     [        U5      S US 4$ r   )r#   r  s      rc   r  r    s    dT4'Frd   c                    S [         S U4$ r   r  r  s      rc   r  r    s    tT40Hrd   c                    [         S US 4$ r   )r   r  s      rc   r  r    s    udD$.Grd   c                "    [         R                  $ r   )r;   r   r  s      rc   r  r    s
    !2C2Crd   c                    [         S US 4$ r   )r   r  s      rc   r  r    r  rd   )Dsympy.concrete.productsrM   r  rK   r   rB   r+  rD   r  rM  rX   rK  rw   rZ   r  rn  r,  r  rY   rx   r   r[   r[  rF   r  r  rG   r   rQ   rS   rR   rl  rO   rP   #sympy.functions.elementary.integersrU   rV   $sympy.functions.elementary.piecewiser  rc  rW   r^  r_  r`  sympy.integrals.integralsrI   r  r  r  r	  r\  ri  r(  rC  rY  rm  ru  r   r   r   r  r   r  r  r  r  r  r  )!rM   rK   rB   rD   rM  rX   rK  rw   rZ   r  rn  r,  r  rY   rx   r   r[   rF   r  rG   rQ   rS   rR   rO   rP   rU   rV   r  rW   r^  r_  r`  rI   s!                                    rc   _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)Krd   c                   SSK JnJn   [        [	        U 5         nU" XU5      nUR                  S5      (       a_  [!        S	U 5        [!        S
[#        U[$        5      (       a  ['        US   =(       d    [(        S5      OU5        [!        SU5        [!        5         UR                  SS5      nU(       aL  USL a  UnO9[+        [-        S[.        R0                  " U5      -  S-   5      5      nUS:X  a  US-  n[3        Xn5      nUR                  S5      (       a  [5        XU5        U$ ! [
         Ga    SU;   a  U R                  [        XS   5      5      n U R                  U5      nUc  [        e[        USS5      nUc  [        eU" 5       u  pU	R                  " U5      (       d  U
R                  " U5      (       a  [        eU	(       d  Sn	SnO5U	R                  (       a  U	R                  " USS9R                  n	UnO[        eU
(       d  Sn
SnO5U
R                  (       a  U
R                  " USS9R                  n
UnO[        eXX4n GN"f = f)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   r   Nr   F)
allow_intsr"  z	### inputz
### output2   z### rawchopTg rh
g      @rp   r9   r   )r   rR   rS   r  typeKeyErrorr   rz  rd  rJ  getattrhasr   
_to_mpmathr  r   r&  r   r   r2   r   ra   roundrF  log10r   r   )rr   r   r   r   r   rfr  xer   rR   rS   reprecimprecr  	chop_precs                  rc   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";#s   D# #D!IIc                   Uc  [         OUR                   nUc  [        OUR                  nU [        R                  L a  [        eU u  pE  nU(       a  U(       d  [
        nU" XE45      $ U(       a  U" U5      $ U" [
        5      $ )z@Turn the quad returned by ``evalf`` into an ``mpf`` or ``mpc``. )r	   r
   r;   r   rJ  r   )r  ctxr   r   rR   rS   r   s          rc   r  r    sl    k(s||Ck(s||CA!!LBAq	BB8}	2w5zrd   c                  T    \ rS rSr% SrSrS\S'   SS jr\rSS jr	SS	 jr
SS
 jrSrg)
EvalfMixini  z$Mixin class adding evalf capability.rh   ztuple[str, ...]	__slots__Nc           	        SSK JnJn	  Ub  UOSnU(       a  [        U5      (       a  [	        S5      eUS:X  aH  [        X	5      (       a8  SSKJn
  U R                  SX#XEXg5      nU
" U5      nUR                  SU-
  5      nU$ [        (       d
  [        5         [        U5      n[        U[        U[        -  5      5      UXWS.nUb  X.S'   Ub  XnS	'    [        XS
-   U5      nU[*        R,                  L a  U$ Uu  nnnnU[*        R.                  L d  U[*        R.                  L a  [*        R.                  $ U(       a*  [        [1        UU5      S5      nUR2                  " UU5      nO[*        R4                  nU(       a?  [        [1        UU5      S5      nUR2                  " UU5      nUU[*        R6                  -  -   $ U$ ! [          a    [#        U S5      (       a$  Ub!  U R%                  U5      R'                  U5      nOU R'                  U5      nUc  U s $ UR(                  (       d  Us $  [        UX5      n GNW! [          a    Us s $ f = ff = f)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
r9   )rX   r\   r  z"subs must be given as a dictionary)_magro   )r!  r  r   r"  r   r  r   )r  rX   r\   r=   	TypeErrorr   r   r  r   r
  r  r   r7   r   ra   LG10rJ  r}  r   rd  r   r;   r   r  r   r  rx   rw   )selfrb   r   maxnr  r   r  r"  rX   r\   r  r   r5  r   r   r   ry   rR   rS   r   r   r   s                         rc   r   EvalfMixin.evalf  s   B 	+ABK%%@AA 6j.."At4GBRA!a%BI{!1~!$DI7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& 	s1   F9 9AI
I
&H55II
II
c                2    U R                  U5      nUc  U nU$ )z@Helper for evalf. Does the same thing but takes binary precision)rd  )r  r   r  s      rc   _evalfEvalfMixin._evalf  s!    T"9Ard   c                    g r   rh   )r  r   s     rc   rd  EvalfMixin._eval_evalf  s    rd   c                   SnU(       a  U R                   (       a  U R                  $ [        U S5      (       a  [        U R	                  U5      5      $  [        X0 5      n[        U5      $ ! [         Ga    U R                  U5      nUc  [        U5      eUR                  (       a  [        UR                  5      s $ UR                  5       u  pgU(       a'  UR                   (       a  [        UR                  5      nO)UR                  (       a  UR                  nO[        U5      eU(       a'  UR                   (       a  [        UR                  5      nO)UR                  (       a  UR                  nO[        U5      e[        Xg45      s $ f = f)Nzcannot convert to mpmath number_as_mpf_val)rE  r   r}  r
   r#  r   r  rJ  rd  r   rx  r  r   r   r	   )r  r   r  errmsgr   ry   rR   rS   s           rc   r	  EvalfMixin._to_mpmath  s   2$//66M4''D,,T233	&4r*F!&))" 	&  &Ay ((zz((^^%FBbmmbdd^XX ((bmmbdd^XX ((RH%%)	&s   A* *AF<CF
F)r  Nd   FFNF)r   ra   r  r@   )r   ra   r  Expr | None)T)ri   rj   rk   rl   __doc__r  __annotations__r   rb   r  rd  r	  rm   rh   rd   rc   r  r    s,    .!#I#yv 	A&rd   r  c                8    [        U SS9R                  " U40 UD6$ )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)r:   r   )rr   rb   r   s      rc   r   r     s!    . 1t$**1888rd   c                f   UbS  UR                   (       d  UR                  (       a  US:  d  [        S5      e[        SU-  S0 5      u  n    n[	        U5      n[        U S0 5      u  pg  n[	        U5      [	        U5      p[        X5      S-   n
[        SX*-   S-   5      nU=(       d    0 n[        XU5      $ )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

r   zeps must be positiver9   )rI  rx  r   r   rs   r   )rr   r  r5  r   r  r   r}   dnrnirb   r   s               rc   _evalf_with_bounded_errorr0    s    : 3<<a3441S5!R(
1aAJq!RJA!Q QZBaA 	AquqyAmGwrd   )rr   zMPF_TUP | Noner  	int | Any)F)ry   r@   r  ztuple[Number, Number] | None)r9   )r   SCALED_ZERO_TUPr  r   )r   ra   r  ztuple[SCALED_ZERO_TUP, int])r   zSCALED_ZERO_TUP | intr  z%MPF_TUP | tuple[SCALED_ZERO_TUP, int])r   z MPF_TUP | SCALED_ZERO_TUP | Noner  zbool | None)r   TMP_RESr  r1  )r   r@   r   ra   r   OPT_DICTr  r3  )
r   r@   r   ra   r   ra   r   r4  r  r3  )r   z'Abs'r   ra   r   r4  r  r3  )r   z're'r   ra   r   r4  r  r3  )r   z'im'r   ra   r   r4  r  r3  )rR   r   rS   r   r   ra   r  r3  )r   r3  r   ra   r  r3  )r   r@   r   r3  r   ra   )r   r@   r   ra   r   r4  r  zTMP_RES | tuple[int, int])r   z	'ceiling'r   ra   r   r4  r  r3  )r   z'floor'r   ra   r   r4  r  r3  )r   z'Float'r   ra   r   r4  r  r3  )r   z
'Rational'r   ra   r   r4  r  r3  )r   z	'Integer'r   ra   r   r4  r  r3  )r  r   r   ra   r  ra   r  z3tuple[MPF_TUP | SCALED_ZERO_TUP | None, int | None])ry   z'Add'r   ra   r   r4  r  r3  )ry   z'Mul'r   ra   r   r4  r  r3  )ry   z'Pow'r   ra   r  r3  )r   z'exp'r   ra   r   r4  r  r3  )ry   r@   r   ra   r   r4  r  r3  )r   z'log'r   ra   r   r4  r  r3  )ry   z'atan'r   ra   r   r4  r  r3  )r   ra   r   dictr  r5  )r   z'AlgebraicNumber'r   ra   r   r4  r  r3  )rr   r   r   ra   r   r4  r  r  )r   z
'Integral'r   ra   r   r4  r  r3  )r  r@   r  r@   rb   rG   r  ztuple[int, Any, Any])
r   r@   rb   rG   r1  ra   r   ra   r  r   )r   z	'Product'r   ra   r   r4  r  r3  )r   z'Sum'r   ra   r   r4  r  r3  )rr   r@   r   ra   r   r4  r  r3  r   )r  )Nr   N)
rr   r@   r  r'  r5  ra   r   zOPT_DICT | Noner  r3  )r(  
__future__r   typingr   r   r   r   r   rF  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/   r0   r1   r2   r3   r4   r_   mpmath.libmp.backendr5   mpmath.libmp.libmpcr6   mpmath.libmp.libmpfr7   r8   r:   	singletonr;   sympy.external.gmpyr<   sympy.utilities.iterablesr=   sympy.utilities.lambdifyr>   sympy.utilities.miscr?   sympy.core.exprr@   sympy.core.addrB   sympy.core.mulrD   sympy.core.powerrF   sympy.core.symbolrG   r  rI   r  rK   r  rM   rl  rO   rP   r   rQ   rR   rS   r  rU   rV   rc  rW   r  rX   rY   rZ   r[   r\   rG  r  r   r~  r   rq   r$  ArithmeticErrorrf   r   ra   r   r3  r5  strr4  rs   r   r   r2  r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r	  r  r(  rC  rY  r\  ri  rm  ru  rz  r  r  r  r  r  r  r  r  r  r  r  r)  r   r   r  r  r   r0  rh   rd   rc   <module>rI     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-$JNG:&, 0<<"&",0l$!l$^67(A4S;Sl."b{ |xGDK
='@2&j6"-"\~4'/TL^'&`" KMG L9xUp"j& j&Z94 ;?'(9=1 !$1 '61 BI1 rd   