
    (ph              	           S SK r S SKrS SKJr  S SKJs  Jr  S SK	J
r
  S SKJrJrJrJrJr  S/rSSSSSSSSS	.S
 jrS rSrS rS rS rS rS rS rS rS rS rSSS\" S5      SS.S jrSS jr S r!g)    N)special)_RichResult)array_namespacexp_copyxp_ravelxp_realxp_take_along_axisnsum F   )argslogmaxlevelminlevelatolrtolpreserve_shapecallbackc                z	  ^^^^^0^1^2^3 Sn[        XUTXTTTX9U
5      u  pnmpmmmp9n
m3[        R                  " SSSS9   T3R                  [	        U5      [	        U5      -   S-  UR
                  5      nT3R                  U5      T3R                  U5      pX-   S-
  X'   X   S-   X'   SXU-  '   [        R                  " X4USU	T3S9nSSS5        Wu  n nnnnnm3[	        T3R                  T3R                  UU5      U5      5      n[	        T3R                  T3R                  UU5      U5      5      n[        XT35      u  pnm2nnnS	u  nnT(       a  T3R                  * OS
nT3R                  T3R                  US9S   nUT-
  S-   nT3R                  U5      R                   nTc%  T(       a  S["        R$                  " U5      -  OUS-  m[	        T3R'                  UUUS95      m0T3R(                  T0T3R+                  U5      T3R+                  U5      -  T3R+                  US
   5      -  '   T3R                  T3R-                  T05      S5      SS2S
S
24   n[	        T3R'                  UT3R(                  US95      n[	        T3R'                  U[        R.                  T3R0                  S95      n [3        UT35      m1[5        T15      m1[	        T3R'                  UT3R                  * US95      n![	        T3R'                  UT3R(                  US95      n"[	        T3R7                  UUS95      n#[	        T3R'                  UT3R                  US95      n$[	        T3R'                  UT3R(                  US95      n%[	        T3R7                  UUS95      n&[	        T3R7                  UUS95      n'[9        S0 ST0_SU_SU_ST1_ST_SU_SU_SU_ST3R                  US5      _ST3R                  US5      _ST_SU_SU_SU _SU!_SU"_S U#_S!U$_S"U%_S#U&_S$U'_S%U_S&U_S'U_S(T3R                  US5      _S)[9        SSS
/SS*9_6n(/ S+Qn)U1UU34S, jn*UU34S- jn+U0UUUU34S. jn,U34S/ jn-UUU2U34S0 jn.[        R                  " SSSS9   [        R:                  " U(U
UUXUU*U+U,U-U.U)T3U	5      n/SSS5        U/$ ! , (       d  f       GN= f! , (       d  f       W/$ = f)1uV1  Evaluate a convergent integral numerically using tanh-sinh quadrature.

In practice, tanh-sinh quadrature achieves quadratic convergence for
many integrands: the number of accurate *digits* scales roughly linearly
with the number of function evaluations [1]_.

Either or both of the limits of integration may be infinite, and
singularities at the endpoints are acceptable. Divergent integrals and
integrands with non-finite derivatives or singularities within an interval
are out of scope, but the latter may be evaluated be calling `tanhsinh` on
each sub-interval separately.

Parameters
----------
f : callable
    The function to be integrated. The signature must be::

        f(xi: ndarray, *argsi) -> ndarray

    where each element of ``xi`` is a finite real number and ``argsi`` is a tuple,
    which may contain an arbitrary number of arrays that are broadcastable
    with ``xi``. `f` must be an elementwise function: see documentation of parameter
    `preserve_shape` for details. It must not mutate the array ``xi`` or the arrays
    in ``argsi``.
    If ``f`` returns a value with complex dtype when evaluated at
    either endpoint, subsequent arguments ``x`` will have complex dtype
    (but zero imaginary part).
a, b : float array_like
    Real lower and upper limits of integration. Must be broadcastable with one
    another and with arrays in `args`. Elements may be infinite.
args : tuple of array_like, optional
    Additional positional array arguments to be passed to `f`. Arrays
    must be broadcastable with one another and the arrays of `a` and `b`.
    If the callable for which the root is desired requires arguments that are
    not broadcastable with `x`, wrap that callable with `f` such that `f`
    accepts only `x` and broadcastable ``*args``.
log : bool, default: False
    Setting to True indicates that `f` returns the log of the integrand
    and that `atol` and `rtol` are expressed as the logs of the absolute
    and relative errors. In this case, the result object will contain the
    log of the integral and error. This is useful for integrands for which
    numerical underflow or overflow would lead to inaccuracies.
    When ``log=True``, the integrand (the exponential of `f`) must be real,
    but it may be negative, in which case the log of the integrand is a
    complex number with an imaginary part that is an odd multiple of π.
maxlevel : int, default: 10
    The maximum refinement level of the algorithm.

    At the zeroth level, `f` is called once, performing 16 function
    evaluations. At each subsequent level, `f` is called once more,
    approximately doubling the number of function evaluations that have
    been performed. Accordingly, for many integrands, each successive level
    will double the number of accurate digits in the result (up to the
    limits of floating point precision).

    The algorithm will terminate after completing level `maxlevel` or after
    another termination condition is satisfied, whichever comes first.
minlevel : int, default: 2
    The level at which to begin iteration (default: 2). This does not
    change the total number of function evaluations or the abscissae at
    which the function is evaluated; it changes only the *number of times*
    `f` is called. If ``minlevel=k``, then the integrand is evaluated at
    all abscissae from levels ``0`` through ``k`` in a single call.
    Note that if `minlevel` exceeds `maxlevel`, the provided `minlevel` is
    ignored, and `minlevel` is set equal to `maxlevel`.
atol, rtol : float, optional
    Absolute termination tolerance (default: 0) and relative termination
    tolerance (default: ``eps**0.75``, where ``eps`` is the precision of
    the result dtype), respectively.  Iteration will stop when
    ``res.error < atol`` or  ``res.error < res.integral * rtol``. The error
    estimate is as described in [1]_ Section 5 but with a lower bound of
    ``eps * res.integral``. While not theoretically rigorous or
    conservative, it is said to work well in practice. Must be non-negative
    and finite if `log` is False, and must be expressed as the log of a
    non-negative and finite number if `log` is True.
preserve_shape : bool, default: False
    In the following, "arguments of `f`" refers to the array ``xi`` and
    any arrays within ``argsi``. Let ``shape`` be the broadcasted shape
    of `a`, `b`, and all elements of `args` (which is conceptually
    distinct from ``xi` and ``argsi`` passed into `f`).

    - When ``preserve_shape=False`` (default), `f` must accept arguments
      of *any* broadcastable shapes.

    - When ``preserve_shape=True``, `f` must accept arguments of shape
      ``shape`` *or* ``shape + (n,)``, where ``(n,)`` is the number of
      abscissae at which the function is being evaluated.

    In either case, for each scalar element ``xi[j]`` within ``xi``, the array
    returned by `f` must include the scalar ``f(xi[j])`` at the same index.
    Consequently, the shape of the output is always the shape of the input
    ``xi``.

    See Examples.

callback : callable, optional
    An optional user-supplied function to be called before the first
    iteration and after each iteration.
    Called as ``callback(res)``, where ``res`` is a ``_RichResult``
    similar to that returned by `_differentiate` (but containing the
    current iterate's values of all variables). If `callback` raises a
    ``StopIteration``, the algorithm will terminate immediately and
    `tanhsinh` will return a result object. `callback` must not mutate
    `res` or its attributes.

Returns
-------
res : _RichResult
    An object similar to an instance of `scipy.optimize.OptimizeResult` with the
    following attributes. (The descriptions are written as though the values will
    be scalars; however, if `f` returns an array, the outputs will be
    arrays of the same shape.)

    success : bool array
        ``True`` when the algorithm terminated successfully (status ``0``).
        ``False`` otherwise.
    status : int array
        An integer representing the exit status of the algorithm.

        ``0`` : The algorithm converged to the specified tolerances.
        ``-1`` : (unused)
        ``-2`` : The maximum number of iterations was reached.
        ``-3`` : A non-finite value was encountered.
        ``-4`` : Iteration was terminated by `callback`.
        ``1`` : The algorithm is proceeding normally (in `callback` only).

    integral : float array
        An estimate of the integral.
    error : float array
        An estimate of the error. Only available if level two or higher
        has been completed; otherwise NaN.
    maxlevel : int array
        The maximum refinement level used.
    nfev : int array
        The number of points at which `f` was evaluated.

See Also
--------
quad

Notes
-----
Implements the algorithm as described in [1]_ with minor adaptations for
finite-precision arithmetic, including some described by [2]_ and [3]_. The
tanh-sinh scheme was originally introduced in [4]_.

Due to floating-point error in the abscissae, the function may be evaluated
at the endpoints of the interval during iterations, but the values returned by
the function at the endpoints will be ignored.

References
----------
.. [1] Bailey, David H., Karthik Jeyabalan, and Xiaoye S. Li. "A comparison of
       three high-precision quadrature schemes." Experimental Mathematics 14.3
       (2005): 317-329.
.. [2] Vanherck, Joren, Bart Sorée, and Wim Magnus. "Tanh-sinh quadrature for
       single and multiple integration using floating-point arithmetic."
       arXiv preprint arXiv:2007.15057 (2020).
.. [3] van Engelen, Robert A.  "Improving the Double Exponential Quadrature
       Tanh-Sinh, Sinh-Sinh and Exp-Sinh Formulas."
       https://www.genivia.com/files/qthsh.pdf
.. [4] Takahasi, Hidetosi, and Masatake Mori. "Double exponential formulas for
       numerical integration." Publications of the Research Institute for
       Mathematical Sciences 9.3 (1974): 721-741.

Examples
--------
Evaluate the Gaussian integral:

>>> import numpy as np
>>> from scipy.integrate import tanhsinh
>>> def f(x):
...     return np.exp(-x**2)
>>> res = tanhsinh(f, -np.inf, np.inf)
>>> res.integral  # true value is np.sqrt(np.pi), 1.7724538509055159
1.7724538509055159
>>> res.error  # actual error is 0
4.0007963937534104e-16

The value of the Gaussian function (bell curve) is nearly zero for
arguments sufficiently far from zero, so the value of the integral
over a finite interval is nearly the same.

>>> tanhsinh(f, -20, 20).integral
1.772453850905518

However, with unfavorable integration limits, the integration scheme
may not be able to find the important region.

>>> tanhsinh(f, -np.inf, 1000).integral
4.500490856616431

In such cases, or when there are singularities within the interval,
break the integral into parts with endpoints at the important points.

>>> tanhsinh(f, -np.inf, 0).integral + tanhsinh(f, 0, 1000).integral
1.772453850905404

For integration involving very large or very small magnitudes, use
log-integration. (For illustrative purposes, the following example shows a
case in which both regular and log-integration work, but for more extreme
limits of integration, log-integration would avoid the underflow
experienced when evaluating the integral normally.)

>>> res = tanhsinh(f, 20, 30, rtol=1e-10)
>>> res.integral, res.error
(4.7819613911309014e-176, 4.670364401645202e-187)
>>> def log_f(x):
...     return -x**2
>>> res = tanhsinh(log_f, 20, 30, log=True, rtol=np.log(1e-10))
>>> np.exp(res.integral), np.exp(res.error)
(4.7819613911306924e-176, 4.670364401645093e-187)

The limits of integration and elements of `args` may be broadcastable
arrays, and integration is performed elementwise.

>>> from scipy import stats
>>> dist = stats.gausshyper(13.8, 3.12, 2.51, 5.18)
>>> a, b = dist.support()
>>> x = np.linspace(a, b, 100)
>>> res = tanhsinh(dist.pdf, a, x)
>>> ref = dist.cdf(x)
>>> np.allclose(res.integral, ref)
True

By default, `preserve_shape` is False, and therefore the callable
`f` may be called with arrays of any broadcastable shapes.
For example:

>>> shapes = []
>>> def f(x, c):
...    shape = np.broadcast_shapes(x.shape, c.shape)
...    shapes.append(shape)
...    return np.sin(c*x)
>>>
>>> c = [1, 10, 30, 100]
>>> res = tanhsinh(f, 0, 1, args=(c,), minlevel=1)
>>> shapes
[(4,), (4, 34), (4, 32), (3, 64), (2, 128), (1, 256)]

To understand where these shapes are coming from - and to better
understand how `tanhsinh` computes accurate results - note that
higher values of ``c`` correspond with higher frequency sinusoids.
The higher frequency sinusoids make the integrand more complicated,
so more function evaluations are required to achieve the target
accuracy:

>>> res.nfev
array([ 67, 131, 259, 515], dtype=int32)

The initial ``shape``, ``(4,)``, corresponds with evaluating the
integrand at a single abscissa and all four frequencies; this is used
for input validation and to determine the size and dtype of the arrays
that store results. The next shape corresponds with evaluating the
integrand at an initial grid of abscissae and all four frequencies.
Successive calls to the function double the total number of abscissae at
which the function has been evaluated. However, in later function
evaluations, the integrand is evaluated at fewer frequencies because
the corresponding integral has already converged to the required
tolerance. This saves function evaluations to improve performance, but
it requires the function to accept arguments of any shape.

"Vector-valued" integrands, such as those written for use with
`scipy.integrate.quad_vec`, are unlikely to satisfy this requirement.
For example, consider

>>> def f(x):
...    return [x, np.sin(10*x), np.cos(30*x), x*np.sin(100*x)**2]

This integrand is not compatible with `tanhsinh` as written; for instance,
the shape of the output will not be the same as the shape of ``x``. Such a
function *could* be converted to a compatible form with the introduction of
additional parameters, but this would be inconvenient. In such cases,
a simpler solution would be to use `preserve_shape`.

>>> shapes = []
>>> def f(x):
...     shapes.append(x.shape)
...     x0, x1, x2, x3 = x
...     return [x0, np.sin(10*x1), np.cos(30*x2), x3*np.sin(100*x3)]
>>>
>>> a = np.zeros(4)
>>> res = tanhsinh(f, a, 1, preserve_shape=True)
>>> shapes
[(4,), (4, 66), (4, 64), (4, 128), (4, 256)]

Here, the broadcasted shape of `a` and `b` is ``(4,)``. With
``preserve_shape=True``, the function may be called with argument
``x`` of shape ``(4,)`` or ``(4, n)``, and this is what we observe.

Nignore)overinvaliddivider   g      ?        T)
complex_okr   xpr      r   dtyper   r   g      ?r   SnSkaerrhr   r    piepsabnnitnfevstatusxr0fr0wr0xl0fl0wl0d4ainfbinfabinfa0
pair_cache)xjcwjindicesh0))r.   r.   )integralr#   )errorr%   )r,   r,   )r-   r-   c           	      0  > TSU R                   -  -  U l        [        U R                   TU R                  U R                   T:H  TU S9u  p[	        XU R
                  U R                  T5      u  U l        U l        [        U R                  5      nX0R                     S[        X0R                     5      S-  -
  -  X0R                  '   SX0R                     -  S-
  U R                  U R                     -   X0R                  '   X0R                  ==   S-  ss'   U$ )Nr   )r    	inclusiver   workr   r"   )r+   r&   
_get_pairsr    _transform_to_limitsr)   r*   xjr<   r   r8   r   r7   r9   r6   )rC   r;   r<   rF   r>   r   r   s       L/var/www/html/venv/lib/python3.13/site-packages/scipy/integrate/_tanhsinh.pypre_func_evaltanhsinh.<locals>.pre_func_eval  s    aiTVVRtzz(,((:O/L TWWJJ1wr**~/F/I+IJ::"YY-!+dggdii.@@99
99	    c           
        > UR                   (       a  XR                  ==   TR                  SUR                  UR                     S-  -   5      STR                  SUR                  UR                     S-  -
  5      -  -
  -  ss'   XR                  ==   STR                  UR                  UR                     5      -  -  ss'   OXR                  ==   SUR                  UR                     S-  -   SUR                  UR                     S-  -
  S-  -  -  ss'   XR                  ==   UR                  UR                     S-  -  ss'   [	        XT5      u  p4UR
                  R                  S   (       a_  UR
                  S S 2S4   nT(       a=  [        R                  " TR                  U[        R                   " S5      -
  U/5      SS9OUS-  U-   nX2l        XBl        g )Nr   r   g       r"   r   axis)r   r8   rF   r7   _euler_maclaurin_sumr$   shaper   	logsumexpstackmathfjwjr#   )xfjrC   rS   r#   Snm1r   r   s         rG   post_func_eval tanhsinh.<locals>.post_func_eval  s   88zzNrvva$''$***=q*@&@A!"266!dggdjj.A1.D*D#E!E F GNyyMQ		(:!;;;MzzNDGGDJJ$7$: : !DGGDJJ$7$: :Q> ? @NyyMTWWTYY/44M ("577==771b5>DSV'##BHHdTXXa[.@"-E$FQOax"}  	rJ   c                 R  > TR                  U R                  R                  [        S9nU R                  S:X  a  [        U R                  U R                  :H  5      nTR                  T
(       a  TR                  * OS5      nTR                  U R                  R                  UTR                  S9nTR                  UTR                  T5      '   X2   U R                  U'   X2   U R                  U'   [        R                   U R"                  U'   SX'   O~[%        U T5      u  pEUT:  UT	:  -  nTR'                  TR)                  XPR                  5      U R                  R                  5      U l        [        R                   U R"                  U'   SX'   T
(       aO  [+        U R                  5      nTR-                  U5      US:  -  nUTR                  U R                  5      -  U) -  nO TR/                  U R                  5      ) U) -  n[        R0                  U R"                  U'   SX'   U$ )z>Terminate due to convergence or encountering non-finite valuesr   r   r   T)zerosr#   rO   boolr,   r   r)   r*   asarrayinffullr    nanisnanr%   eim_ECONVERGEDr.   _estimate_errorreshapeastyper   isinfisfinite
_EVALUEERR)rC   stopizerorerrr%   Sn_real
Sn_pos_infr#   r   r   r   r   s           rG   check_termination#tanhsinh.<locals>.check_termination  s   xxTx2 88q=466)*A::rvvg"5D77477==$bhh7?D!#D"DGGAJ7DIIaL __DKKNDG )r2JD-ABIIdJJ$?ODI __DKKNDG dgg&G'*gk:Jbhhtww//D58ATWW%%-AArJ   c                    > U =R                   S-  sl         TR                  U R                  U R                  S S 2TR                  4   4SS9U l        g )Nr   r"   rL   )r+   concatr$   r#   newaxis)rC   r   s    rG   post_termination_check(tanhsinh.<locals>.post_termination_check  sA    !))TWWdggam&<=B)GrJ   c                 V  > T(       aq  TR                  T5      (       a[  U S   R                  nTR                  TR                  US9S   nTR                  STR                  S9S   nU S   TU-  U-  -   U S'   OU S   T==   S-  ss'   TU S   -   S-
  U S'   SU S   U S   S	:H  '   U S	 U$ )
Nr?   r   r                 ?r"   r,   r   r   r   )anyr    r\   r'   	complex64)	resrO   r    r'   jr   r   negativer   s	        rG   customize_result"tanhsinh.<locals>.customize_result  s     266(##
O))EBEE/3B

2R\\
226A!*oA=C
O
OH%+% #SZ/!3J+-JE
a(JrJ   )_tanhsinh_ivnperrstaterd   r   rO   rf   ra   _initializere   broadcast_to_transform_integralsr]   r\   r'   finfor(   rR   r   r^   r_   r`   
empty_like_EINPROGRESSint32_get_base_stepr   rZ   r   _loop)4fr)   r*   r   r   r   r   r   r   r   r   maxfuncinf_ainf_btempxsfsrO   r    r9   r8   r6   r7   r,   r-   rk   r'   maxiterr(   r$   r%   r.   r/   r0   r1   r2   r3   r4   r5   rC   res_work_pairsrH   rW   ro   rt   r}   rz   r#   r>   r|   r   s4       ` ```                                       @@@@rG   tanhsinhr      s!   J	 F7C	af$dH8.5Q1c6X	4x 
(HX	FJJhqk114agg>xx{BHHQKu8b=8b=%-q$.<E 
G )-%Ar2tUE22??1e4e<=A2??1e4e<=A -Ar,J)A"htT ICBFF7qD	BEE	'	+B!A%G
((5/

C|%(tDHHSM!c4i	"''%U'3	4B68ffBrxx{RXXa[ 288BqE?23	BMM"%w	/1Q3	7BBGGE266G78DbggeS%5%5RXXgFGF	r	"B	B
 2775266'77
8C
2775"&&76
7C
288E8/
0C
2775"&&76
7C
2775"&&76
7C
288E8/
0C	"((5(.	/B IIII#%I+.I6;I@BIHKI
**Q
 I$&JJq'$:I I I #'I 06I 	I 	I "	I (+	I 14	I :=	I BD	I
 I
 I
 %*I
 /1jjW.EI 4D1#$GIDKN*   D
 ( 
(HX	Fiihw&(9;Q(."nN 
G J 
G	Fv 
G	F Js   BR+$R+
R(+
R:c                     SUR                  U 5      R                  -  n[        R                  " [        R                  " SU-  S-
  5      UR
                  -  5      nU[        -  nUR                  X@S9S   $ )N   r   r   r   r   )r   smallest_normalrR   asinhr   r'   _N_BASE_STEPSr\   )r    r   fmintmaxr>   s        rG   r   r     sf     RXXe_,,,D::dhhqvz*RUU23D 
	B::b:&r**rJ      c                    USU -  -  n[         SU -  -  nU S:X  a  UR                  US-   5      OUR                  SUS-   S5      nXS-  nUR                  S-  nXrR                  U5      -  nXrR	                  U5      -  n	XR                  U	5      S-  -  n
SUR                  U	5      UR                  U	5      -  -  nU S:X  a  U
S   S-  OU
S   U
S'   X4$ Nr   r   r   )r   aranger'   coshsinhexp)kr>   r   r&   maxr{   jhpi_2u1u2r<   r;   s               rG   _compute_pairr     s     	QT	A
!Q$
C F		#a%		!SUA(>A	
B 5519D	ggbk	B	ggbk	B 
ggbk1n	B
rvvbzBGGBK'
(C aBqEAIRUBqE7NrJ   c                    [        U[        UR                  R                  5      5      (       a  XR                  R                  :w  aR  UR	                  S5      UR                  l        UR	                  S5      UR                  l        S/UR                  l        UR                  R
                  /nUR                  R                  /n[        [        UR                  R                  5      S-
  U S-   5       H  n[        XaU5      u  pxUR                  U5        UR                  U5        UR                  R                  R                  UR                  R                  S   UR                  S   -   5        M     UR                  U5      UR                  l        UR                  U5      UR                  l        XR                  l        g )Nr   r   r"   )
isinstancetyper:   r>   emptyr;   r<   r=   rangelenr   appendrO   rr   )	r   r>   r   rC   xjcswjsrj   r;   r<   s	            rG   _pair_cacher   0  s?   
 b$t11233r__=O=O7O hhqkXXa[#$#OO D??
C3t../11q59r*C

2&&t'>'>r'BSYYq\'QR	 : ))D/DOO3DOOOOrJ   c                    [        UR                  R                  5      U S-   ::  dG  [        U[	        UR                  R
                  5      5      (       a  XR                  R
                  :w  a  [        XXE5        UR                  R                  nUR                  R                  nUR                  R                  nU(       a  SOX   n	XS-      n
UR                  XiU
 U5      UR                  XyU
 U5      4$ r   )
r   r:   r=   r   r   r>   r   r;   r<   re   )r   r>   rB   r    r   rC   r;   r<   r=   startends              rG   rD   rD   H  s     	DOO##$!+2tDOO$6$6788###r(
//

C			Boo%%GA
E
A#,C99Ss^U+RYYr}e-LLLrJ   c                     X2-
  S-  nUR                  U* U -  U-   XP-  U-   4SS9nX-  nUR                  X4SS9n[        U5      [        U5      [        U5      pnXx:*  Xy:  -  n
SX'   Xa4$ )Nr   r"   rL   r   )rr   r   )r;   r<   r)   r*   r   alpharF   xj_reala_realb_realr   s              rG   rE   rE   Z  s    
 UaKE	UFSL1$ekAo6R	@B	B	B8"	%B &bk71:wqzVG W%67GBK6MrJ   c                    UR                   UR                  UR                  pTnUR                  UR                  UR
                  pnUR                  R                  U R                  UR                  R                  pn	U	R                  u  p[        UR                  U	SUS-  U45      5      u  pUR                  U SUS-  U45      u  nnUR                  U
SUS-  U45      u  nnUR                  U5      ) US:H  -  nUR                  U5      ) US:H  -  nUR                  * UU'   UR                  [        U5      SSS9n[!        UUSS9S   n[!        UUSS9S   n[!        UUSS9S   n[        U5      [        U5      :  nUU   UU'   UU   UU'   UU   UU'   UR                  UU'   UR#                  [        U5      SSS9n[!        UUSS9S   n[!        UUSS9S   n[!        UUSS9S   n[        U5      [        U5      :  nUU   UU'   UU   UU'   UU   UU'   U R                  n UR$                  (       a  XrR%                  U5      -   OXx-  nUR$                  (       a  XBR%                  U5      -   OXE-  nUR$                  (       a  [        OUR&                  n UR)                  U " U5      U " U5      5      Ul        UR-                  XBR.                  S S 24   UR                  5      n!UR-                  XrR.                  S S 24   UR                  5      n"U!U   UU'   U"U   UU'   UR$                  (       a  XR%                  UR                  5      -   OXR                  -  n#UR$                  (       a1  [0        R2                  " U#UR%                  UR4                  5      -   SS9OUR7                  U#SS9UR4                  -  n$X4UsUl         Ul        Ul        XgUsUl        Ul        Ul        U#U$4$ )Nr   r   TrM   keepdimsrL   r"   )r/   r0   r1   r2   r3   r4   rF   Tr<   rO   r   rd   rg   r]   argmaxr   r	   argminr   absmaximumr5   r   rs   r   rP   r&   sum)%rU   rC   r   r/   r0   r1   r2   r3   r4   rF   r<   n_xn_activexrxlfrflwrwl	invalid_r	invalid_lirxr_maxfr_maxwr_maxr{   ilxl_minfl_minwl_minflwl0frwr0	magnitudefr0bfl0brS   r#   s%                                        rG   rN   rN   p  s    HHdhhcCHHdhhcC BDD$''))BBHHMC RZZQq($;<=FBZZQq(34FBZZQq(34FBR B!G,IR B!G,I VVGByM	72;Q	6B  BQ/2FBQ/2FBQ/2F 	'#,&AAYCFAYCFAYCF FFByM	72;Q	6BBQ/2FBQ/2FBQ/2F 	'#,&AAYCFAYCFAYCF	B "&C&&+syE!%C&&+syE88Ijj5)9U+;<DG ??3zz1}-rxx8D??3zz1}-rxx8DOByMOByM $(882twwggD @Dxx'

D266$&&>1
;vvdv$tvv-  $'S DHdh#&S DHdh8OrJ   c           
      
   U R                   S:X  d  U R                  S:X  a)  UR                  U R                  UR                  5      nX"4$ U R
                  R                  nU R                  R                  S   n[        SSS9nU R                  R                  S   S:X  a  SU R                  -  nX0R                      nUR                  U R                  USS45      nUR                  US S 2S S 2S U24   USU-  45      n	U R                  (       a)  [        R                  " U	40 UD6UR                  U5      -   OUR                   " U	40 UD6U-  n
UR#                  XR                  4SS9U l	        U R                   S:X  a)  UR                  U R                  UR                  5      nX"4$ U R                  R                  S   S:  a  SU R                  -  nX0R                   S-
     nUR                  U R                  U R                  R                  S   SS45      nUR                  US	S U24   USU-  45      n	U R                  (       a)  [        R                  " U	40 UD6UR                  U5      -   OUR                   " U	40 UD6U-  nUR#                  XR                  4SS9U l	        U R                  S
   nU R                  S   n
UR%                  U R&                  5      S   nU R                  (       Gak  UR                  U5      n[)        [        R                  " UR+                  U R                  XR,                  S-  -   /5      SS95      n[)        [        R                  " UR+                  U R                  XR,                  S-  -   /5      SS95      nXR/                  [)        U R                  5      SS9-   nU R0                  nXR3                  U R                  5      -   nUR5                  XR6                  * :  US-  U-  UR6                  * 5      nUR+                  USU-  UUU/5      nUR/                  USS9nUUR3                  U R                  5      -
  nUU4$ UR9                  U R                  U
-
  5      nUR9                  U R                  U-
  5      nXR/                  UR9                  U R                  5      SS9-  nU R0                  nXR9                  U R                  5      -  nUR5                  US:  XR                  U5      UR                  U5      -  -  S5      nUR+                  UUS-  UUU/5      nUR/                  USS9nUUR9                  U R                  5      -  nUU4$ )Nr   r"   Tr   r   rL   r   r   .).).r"   r   rw   )r+   r,   	full_liker#   r_   r:   r=   rO   dictr$   r&   rd   rS   r   r   rP   r   rr   r\   r(   r   rQ   r'   r   r5   realwherer]   r   )rC   r   r_   r=   r   axis_kwargsr&   r   fjwj_rlrS   rV   Snm2e1log_e1d1d2d3r5   d5r   dsr%   rl   s                          rG   rc   rc     s    vv{dhh!m ll477BFF+xoo%%Gww}}QHB.K ww}}RAJffo **TYY1b(9:zz'!Q*-!C%/@AFJhh!!$6+6BVVD0K014 	))T77O")5vv{ll477BFF+x
 ww}}R1JffQh **TYYq)91b(ABzz'#tt),x3.?@FJhh!!$6+6BVVD0K014 	))T77O")5777D777D	DHH	b	!Bxxx
 W&&rxx$:K0L'MTUVWW&&rxx$:K0L'MTUVWffWTYY/bf99WWggdgg&&xxffWbAglRVVG<XXtQVRR01vvbqv!bggdgg&& : VVDGGdN#VVDGGdN#&&		*&44WW&&/!xxQVVBZr
%: ;Q?XXtRUBB/0vvbqv!BFF477O#:rJ   c                 R   X:H  nSu  X'   X'   [        U5      [        U 5      :  nX   X   sX'   X'   UR                  U 5      UR                  U5      -  nSu  X'   X'   UR                  U 5      nX   * X   * sX'   X'   UR                  U5      n[        U 5      nSu  X'   X'   XXXVU4$ )N)r   r   r!   r   )r   rf   r   )	r)   r*   r   ab_samer|   r8   r6   r7   r9   s	            rG   r   r     s     vG!AJ
 qzGAJ&H {AKAKHHQK"((1+%EAHah88A;Dx!'AGQW88A;D	BAGQWuD00rJ   c                 $  ^ [        X5      mSn[        U 5      (       d  [        U5      eSnTR                  U5      TR                  U5      p!TR	                  X5      u  pTR                  UR                  S5      (       d!  TR                  UR                  S5      (       a  [        U5      eSnUS;  a  [        U5      e[        U5      nUc  U(       a  TR                  * OSnUb  UOSn[        R                  " X}S/5      nSn[        R                  " UR                  [        R                  5      (       d  [        U5      eU(       a=  S	n[        R                  " [        R                  " U5      5      (       a  [        U5      eOZS
n[        R                  " US:  5      (       d/  [        R                  " [        R                  " U5      5      (       a  [        U5      eUS   nUc  UOUS   n[        S5      nUc  Uc  SnUc  UOUnUc  UOUnSn[        R                  " XEU/5      n[        R                  " UR                  [        R                   5      (       aj  [        R"                  " [        R$                  " U5      5      (       a;  [        R"                  " UR'                  [        R(                  5      U:H  5      (       d  [        U5      eSn[        R                  " US:  5      (       a  [        U5      eUR'                  [        R(                  5      u  pEn[+        Xe5      n[        R,                  " U	5      (       d  U	4n	U4S jU	 5       n	SnU
S;  a  [        U5      eUb  [        U5      (       d  [        S5      eXX#XEUXxXUT4$ )N`f` must be callable.z1All elements of `a` and `b` must be real numbers.complex floating`log` must be True or False.   FTr   r   '`atol` and `rtol` must be real numbers.z/`atol` and `rtol` may not be positive infinity.z2`atol` and `rtol` must be non-negative and finite.r   l            
   z6`maxfun`, `maxlevel`, and `minlevel` must be integers.z:`maxfun`, `maxlevel`, and `minlevel` must be non-negative.c              3   F   >#    U  H  nTR                  U5      v   M     g 7fN)r\   ).0argr   s     rG   	<genexpr>_tanhsinh_iv.<locals>.<genexpr>x  s     ,tBJJsOOts   !z'`preserve_shape` must be True or False.z`callback` must be callable.)r   callable
ValueErrorr\   broadcast_arraysisdtyper    r[   r]   r   
issubdtypefloatingrx   isposinfrf   floatnumberallisrealre   int64miniterable)r   r)   r*   r   r   r   r   r   r   r   r   r   message	rtol_tempparamsBIGINTr   s                   @rG   r   r   7  s    
	B%GA;;!!AG::a="**Q-qq$DA


177.//zz!''#566!!,G
-!!
s)C|w1(bI ZZ"-.F7G==r{{33!!
C66"++f%&&W%% ' G66&1*(8!9!9W%%!9D<4VAYD5\F~(*~V6F!)vxHFGZZ845FMM&,,		22ryy())v}}RXX.&899!!JG	vvfqj!!!'rxx!8Fh8&H;;tw,t,D7G]*!!HX$6$6788!&Hh< <rJ   c                 N   [        X5      nSn	[        U 5      (       d  [        U	5      eSn	UR                  UR	                  U5      UR	                  U5      UR	                  U5      5      u  pnUR                  UR                  UR                  UR                  5      n
UR                  U
S5      (       a  UR                  U
S5      (       a  [        U	5      eX!:  nUR                  U5      US:  -  nX-  nSn	US;  a  [        U	5      eUc  0 OUnUR                  SS 5      nUc  U(       a  UR                  * OSnUR                  S	S 5      nUb  UOS
n[        R                  " UUS
/5      nSn	[        R                  " UR                  [        R                  5      (       d  [        U	5      eU(       aT  Sn	[        R                  " [        R                  " U5      [        R                   " U5      -  5      (       a  [        U	5      eOCSn	[        R                  " US:  [        R                  " U5      ) -  5      (       a  [        U	5      eUS   nUc  UOUS   n[#        U5      nUU:w  d  US:  a  Sn	[        U	5      e[        R$                  " U5      (       d  U4nXX#XUUXU4$ )Nr   z:All elements of `a`, `b`, and `step` must be real numbers.numericr   r   r   r   r   r   r   r   z3`atol`, `rtol` may not be positive infinity or NaN.z3`atol`, and `rtol` must be non-negative and finite.r   z*`maxterms` must be a non-negative integer.)r   r   r   r   r\   result_typer    r   rg   getr]   r   r   r  rx   r  r`   intr	  )r   r)   r*   stepr   r   maxterms
tolerancesr   r
  r    valid_b
valid_stepvalid_abstepr   r   r  r  maxterms_ints                      rG   _nsum_ivr    sQ    
	B%GA;;!!JG$$RZZ]BJJqM2::dCSTJA$NN177AGGTZZ8E::eY''2::e=O+P+P!!fGT"dQh/J'L,G
-!!!)zJ>>&$'D|w1>>&$'D(bI ZZy"-.F7G==r{{33!!
G66"++f%(8899W%% : H666A:2;;v#6"6788W%%!9D<4VAYDx=Lx8a<>!!;;tw,c<ROOrJ   r   i   )r  r   r   r  r  c                	  ^ ^" [        T XX4XVU5      nUu  m pp9pEpjnm"[        R                  " T U4UST"S9nUu  m ppNnm"US   nT"R                  [	        T"R                  X.5      5      U5      nT"R                  [	        T"R                  X>5      5      U5      n[	        T"R                  X5      5      n	T"R                  X!-
  U-  5      nT"R                  U5      nUU   UU   UU   -  -   UU'   T"R                  U5      R                  nT"R                  U(       a  T"R                  * OSUS9S   nUc%  U(       a  S[        R                  " U5      -  OUS-  nXUUXU4nT"R                  U5      nT"R                  U5      nT"R                  [!        U5      T"R"                  S9nT"R%                  [!        U5      T"R"                  S9nU	) nUS-   U:*  U) -  nT"R                  U5      U) -  U) -  nT"R                  U5      U) -  U) -  U) -  nU) U) -  U) -  U) -  nT"R'                  U5      (       a$  T"R(                  T"R(                  sUU'   UU'   S	UU'   T"R'                  U5      (       a  U Vs/ s H  nUU   PM
     nn[+        T UU   UU   UU   UUT"5      nUSS	 u  UU'   UU'   UU==   US	   -  ss'   S
T"R                  T"R                  UU   5      ) T"R"                  S9-  UU'   T"R'                  U5      (       aQ  U Vs/ s H  nUU   PM
     n n[-        T UU   UU   UU   U UT"5      nUSS	 u  UU'   UU'   UU'   UU==   US	   -  ss'   T"R'                  U5      (       aY  U Vs/ s H  nUU   PM
     n nU 4S jn![-        U!UU   * UU   * UU   U UT"5      nUSS	 u  UU'   UU'   UU'   UU==   US	   -  ss'   T"R'                  U5      (       a{  U Vs/ s H  nUU   PM
     n nU(       a  U U"4S jn!OU U"4S jn!T"R/                  UU   5      n[-        U!UUU   UU   U UT"5      nUSS	 u  UU'   UU'   UU'   UU==   SUS	   -  -  ss'   UR1                  U5      S   UR1                  U5      S   nnUR1                  U5      S   UR1                  U5      S   nn[3        UUUUS:H  US9$ s  snf s  snf s  snf s  snf )a  Evaluate a convergent finite or infinite series.

For finite `a` and `b`, this evaluates::

    f(a + np.arange(n)*step).sum()

where ``n = int((b - a) / step) + 1``, where `f` is smooth, positive, and
unimodal. The number of terms in the sum may be very large or infinite,
in which case a partial sum is evaluated directly and the remainder is
approximated using integration.

Parameters
----------
f : callable
    The function that evaluates terms to be summed. The signature must be::

        f(x: ndarray, *args) -> ndarray

    where each element of ``x`` is a finite real and ``args`` is a tuple,
    which may contain an arbitrary number of arrays that are broadcastable
    with ``x``.

    `f` must be an elementwise function: each element ``f(x)[i]``
    must equal ``f(x[i])`` for all indices ``i``. It must not mutate the
    array ``x`` or the arrays in ``args``, and it must return NaN where
    the argument is NaN.

    `f` must represent a smooth, positive, unimodal function of `x` defined at
    *all reals* between `a` and `b`.
a, b : float array_like
    Real lower and upper limits of summed terms. Must be broadcastable.
    Each element of `a` must be less than the corresponding element in `b`.
step : float array_like
    Finite, positive, real step between summed terms. Must be broadcastable
    with `a` and `b`. Note that the number of terms included in the sum will
    be ``floor((b - a) / step)`` + 1; adjust `b` accordingly to ensure
    that ``f(b)`` is included if intended.
args : tuple of array_like, optional
    Additional positional arguments to be passed to `f`. Must be arrays
    broadcastable with `a`, `b`, and `step`. If the callable to be summed
    requires arguments that are not broadcastable with `a`, `b`, and `step`,
    wrap that callable with `f` such that `f` accepts only `x` and
    broadcastable ``*args``. See Examples.
log : bool, default: False
    Setting to True indicates that `f` returns the log of the terms
    and that `atol` and `rtol` are expressed as the logs of the absolute
    and relative errors. In this case, the result object will contain the
    log of the sum and error. This is useful for summands for which
    numerical underflow or overflow would lead to inaccuracies.
maxterms : int, default: 2**20
    The maximum number of terms to evaluate for direct summation.
    Additional function evaluations may be performed for input
    validation and integral evaluation.
atol, rtol : float, optional
    Absolute termination tolerance (default: 0) and relative termination
    tolerance (default: ``eps**0.5``, where ``eps`` is the precision of
    the result dtype), respectively. Must be non-negative
    and finite if `log` is False, and must be expressed as the log of a
    non-negative and finite number if `log` is True.

Returns
-------
res : _RichResult
    An object similar to an instance of `scipy.optimize.OptimizeResult` with the
    following attributes. (The descriptions are written as though the values will
    be scalars; however, if `f` returns an array, the outputs will be
    arrays of the same shape.)

    success : bool
        ``True`` when the algorithm terminated successfully (status ``0``);
        ``False`` otherwise.
    status : int array
        An integer representing the exit status of the algorithm.

        - ``0`` : The algorithm converged to the specified tolerances.
        - ``-1`` : Element(s) of `a`, `b`, or `step` are invalid
        - ``-2`` : Numerical integration reached its iteration limit;
          the sum may be divergent.
        - ``-3`` : A non-finite value was encountered.
        - ``-4`` : The magnitude of the last term of the partial sum exceeds
          the tolerances, so the error estimate exceeds the tolerances.
          Consider increasing `maxterms` or loosening `tolerances`.
          Alternatively, the callable may not be unimodal, or the limits of
          summation may be too far from the function maximum. Consider
          increasing `maxterms` or breaking the sum into pieces.

    sum : float array
        An estimate of the sum.
    error : float array
        An estimate of the absolute error, assuming all terms are non-negative,
        the function is computed exactly, and direct summation is accurate to
        the precision of the result dtype.
    nfev : int array
        The number of points at which `f` was evaluated.

See Also
--------
mpmath.nsum

Notes
-----
The method implemented for infinite summation is related to the integral
test for convergence of an infinite series: assuming `step` size 1 for
simplicity of exposition, the sum of a monotone decreasing function is bounded by

.. math::

    \int_u^\infty f(x) dx \leq \sum_{k=u}^\infty f(k) \leq \int_u^\infty f(x) dx + f(u)

Let :math:`a` represent  `a`, :math:`n` represent `maxterms`, :math:`\epsilon_a`
represent `atol`, and :math:`\epsilon_r` represent `rtol`.
The implementation first evaluates the integral :math:`S_l=\int_a^\infty f(x) dx`
as a lower bound of the infinite sum. Then, it seeks a value :math:`c > a` such
that :math:`f(c) < \epsilon_a + S_l \epsilon_r`, if it exists; otherwise,
let :math:`c = a + n`. Then the infinite sum is approximated as

.. math::

    \sum_{k=a}^{c-1} f(k) + \int_c^\infty f(x) dx + f(c)/2

and the reported error is :math:`f(c)/2` plus the error estimate of
numerical integration. Note that the integral approximations may require
evaluation of the function at points besides those that appear in the sum,
so `f` must be a continuous and monotonically decreasing function defined
for all reals within the integration interval. However, due to the nature
of the integral approximation, the shape of the function between points
that appear in the sum has little effect. If there is not a natural
extension of the function to all reals, consider using linear interpolation,
which is easy to evaluate and preserves monotonicity.

The approach described above is generalized for non-unit
`step` and finite `b` that is too large for direct evaluation of the sum,
i.e. ``b - a + 1 > maxterms``. It is further generalized to unimodal
functions by directly summing terms surrounding the maximum.
This strategy may fail:

- If the left limit is finite and the maximum is far from it.
- If the right limit is finite and the maximum is far from it.
- If both limits are finite and the maximum is far from the origin.

In these cases, accuracy may be poor, and `nsum` may return status code ``4``.

Although the callable `f` must be non-negative and unimodal,
`nsum` can be used to evaluate more general forms of series. For instance, to
evaluate an alternating series, pass a callable that returns the difference
between pairs of adjacent terms, and adjust `step` accordingly. See Examples.

References
----------
.. [1] Wikipedia. "Integral test for convergence."
       https://en.wikipedia.org/wiki/Integral_test_for_convergence

Examples
--------
Compute the infinite sum of the reciprocals of squared integers.

>>> import numpy as np
>>> from scipy.integrate import nsum
>>> res = nsum(lambda k: 1/k**2, 1, np.inf)
>>> ref = np.pi**2/6  # true value
>>> res.error  # estimated error
np.float64(7.448762306416137e-09)
>>> (res.sum - ref)/ref  # true error
np.float64(-1.839871898894426e-13)
>>> res.nfev  # number of points at which callable was evaluated
np.int32(8561)

Compute the infinite sums of the reciprocals of integers raised to powers ``p``,
where ``p`` is an array.

>>> from scipy import special
>>> p = np.arange(3, 10)
>>> res = nsum(lambda k, p: 1/k**p, 1, np.inf, maxterms=1e3, args=(p,))
>>> ref = special.zeta(p, 1)
>>> np.allclose(res.sum, ref)
True

Evaluate the alternating harmonic series.

>>> res = nsum(lambda x: 1/x - 1/(x+1), 1, np.inf, step=2)
>>> res.sum, res.sum - np.log(2)  # result, difference vs analytical sum
(np.float64(0.6931471805598691), np.float64(-7.616129948928574e-14))

F)r   r   r   r   r   N      ?r   r"   c                    > T" U * /UQ76 $ r   r   )rT   r   r   s     rG   _fnsum.<locals>._f  s    A2-rJ   c                    > TR                  U S:H  [        R                  " S5      S5      nTR                  T" U /UQ76 T" U * /UQ76 /SS9n[        R
                  " USS9U-   $ )Nr   r  rL   )r   rR   r   rQ   r   rP   )rT   r   
log_factoroutr   r   s       rG   r  r     sb    XXadDHHSM1=
hh!dQr\D\:hC((15
BBrJ   c                 ^   > TR                  U S:H  SS5      nT" U /UQ76 T" U * /UQ76 -   U-  $ )Nr   r  r   )r   )rT   r   factorr   r   s      rG   r  r     s;    !Q$Q/!dalTl2f<<rJ   r   )r   r@   r.   successr-   )r  ra   r   re   r   r   floorrg   r   r(   r\   r]   rR   r   r   rZ   r   r   onesrx   r_   _direct_integral_bound
zeros_likerd   r   )#r   r)   r*   r  r   r   r  r  tmpr  r   r   r   r   rO   r    ntermsfinite_termsr(   rk   	constantsSEr.   r-   i0i1i2i3i4r   args_directargs_indirectr  r   s#   `                                 @rG   r
   r
     s   D 1aDz
BCGJDAqTHD" //!aT4Eb
AC(+%ArtE2 	1A
		(2??145u=A99Xbood:;UCDBOOL@ALXXqun%F;;v&Lo|(<T,=O(OOAlO ((5/

C::rvvg!5:9"=D|$'s488C= S#XS$H=I 	aA
aAXXc!fBHHX-F773q67*D B
1*
 RC	'B	Q2#		#B	Q2#		#rc	)B
sbSB3	B	vvbzzvvrvv"qur
	vvbzz*./$3s2w$/a2"tBxiL3Bx"quRCG"**bkk!B%&8%8*IIr
	vvbzz,01DSRD1a2"tBx+Y<#&s8 "qufRjRCG	vvbzz,01DSRD1-b1R5&1R5&$r(+Y<#&s8 "qufRjRCG	vvbzz,01DSRD1 C= }}QrU#b$"tBx	SUV#&s8 "qufRjRAc"gI 99UB5!1"!5qA>>%(,dll5.A".EDF1Affk " "k 0 2 2 2s   ,R/R4)R9R>c                    Uu  pp    n[        U5      nUR                  X!-
  U-  5      U-   n[        UR                  U5      5      nUS S 2UR                  4   US S 2UR                  4   US S 2UR                  4   nnnU Vs/ s H  nUS S 2UR                  4   PM     nnUUR	                  XS9U-  -   nUUUU-  S-  -   :  nUR
                  UU'   U " U/UQ76 nUUU'   UUR                  SS9-
  nU	(       a  [        R                  " USS9OUR                  USS9nU	(       a"  [        U5      [        R                  " U
5      -   OU
[        U5      -  nUUU4$ s  snf )Nr   r   r"   rL   )r  roundr   rs   r   r_   r   r   rP   r   rR   r   r   )r   r)   r*   r  r   r/  r   rB   r    r   r(   rk   _inclusive_adjustmentsteps	max_stepsa2b2step2r   args2ksi_nanr   r-   r0  r1  s                              rG   r)  r)    sg    &/"E1a y>HHaet^$';;EBFF5M"I am$a2::&6Q

]8KEB+/04CSBJJ4E0	bii	i/%7	7B2,U21445EBuI	
2B
 BuIuyyby))D*-"2&266"263FA&)
TXXc]"sSV|Aa: 1s   Ec                    Uu  px  ppUR                  [        R                  " S5      US9n[        XX$XUS9nUR	                  UR                  U5      UR
                  R                  5      nU(       a3  [        R                  " UR                  XUR
                  -   45      SS9nOXUR
                  -  -   nUR                  S:  nUR                  UU'   UR                  nUSUR                  4   nUSUR                  4   nU Vs/ s H  nUSUR                  4   PM     nnU(       a*  [        R                  " [        R                  " U5      5      OSnUR                  SUR!                  SU5      -  UR                  U/5      45      nUR#                  UU5      n[%        U5      S-  nUUU-  -   nU " U/UQ76 nU " UU-   /UQ76 nUUS S 2UR                  4   :  UU:  -  nUR'                  USS9nUR)                  UUR                  UR                  S   S-
  5      5      nUU   nUUS-  :H  nUUU-  -   n [+        XU X4XVS	S
9u  n!n"n#UR-                  U!5      U!S:  -  n$UU$-  nSUU$'   UR                  U U'   [        U U X$XUS9n%UUR!                  [%        U5      5      U4   n&U(       a  UR/                  U&UR0                  * 5      OUR3                  U&5      n'UR5                  U5      n(UR7                  U(5      (       a#  U " UU(   /U Vs/ s H  nUU(   PM
     snQ76 U'U('   UUR                  U(U#R8                  S9-   nU(       a  UR                  U5      n)U!U%R
                  U)-
  U&U-
  U'U-
  4n*[        R                  " UR                  U*5      SS9n+U"U%R:                  U)-
  U&U-
  U'U-
  UR<                  S-  -   4n,[?        [        R                  " UR                  U,5      SS95      n-O<U!U%R
                  U-  -   U&S-  -   U'S-  -   n+U"U%R:                  U-  -   U&S-  -   U'S-  -
  n-U%R                  U)    UU) '   SUUS:H  U-  '   U+U-UU#U%R@                  -   U-   UR@                  -   4$ s  snf s  snf )Nr   r   )r   r   r   r   r   rL   .r"   r   F)rB   r  rw   )!r\   rR   r   r   r   r?   rO   r   rP   rQ   r.   r_   rs   r'  log2rr   r   re   r   r   minimumr)  rf   r   r]   r+  rg   rx   r    r@   r'   r   r-   ).r   r)   r*   r  r   r/  r   r    r   r;  r   r   r  rG  lbtoli_skipr.   r?  rA  r   rB  log2maxtermsn_stepsr-   rC  fksfksp1fk_insufficientn_fk_insufficientnti_fk_insufficientr   left
left_error	left_nfevleft_is_pos_infrightfkfbrj   log_stepS_termsr0  E_termsr1  s.                                                 rG   r*  r*    sf   -6*E1D::dhhqk:/D 
!4	DB
//"**T*BKK,=,=
>C
#bkk/A)B C!L$$YY]F&&CKYYF
 
3

?	Bbjj!E-12TcSbjj!TE2 7?4::dii12ALiiBIIa66

H:8NOPGii'Gw<!D	go	B
B--Cb5j!5!ESBJJ//ECK@OR8	%rzz'--2CA2E'F	GBbkG +dAg5 	
GdNA")!4*35#JD*ihhtnq1O
oF F?AfI Q1d3GE 
RYYs3x "$	%B '*b266'	"r}}R/@B
AA	vvayy!A$2D1DS#a&D121"**Qioo*66D
66$<(2BIrDyIbhhw/a8u{{X5r$w4b@PQG%%bhhw&7a@A5>>$&&A-14T))BqD02a47llF7+FF7O02FFaK,,-aUZZ/$6@@@} 3^ 2s   Q0Q5
)T)"rR   numpyr   scipyr   (scipy._lib._elementwise_iterative_method_lib_elementwise_iterative_methodra   scipy._lib._utilr   scipy._lib._array_apir   r   r   r   r	   __all__r   r   r   r   r   rD   rE   rN   rc   r   r   r  r  r
   r)  r*  r   rJ   rG   <module>rf     s       6 6 (@ @ (& !edQT%$Rj+, !H0M$,UpQh16K<\9Px "%#e*QU a"H	-`SArJ   