+
    LV-j§O  ã                   ó†   € R t ^ RIt^RIHt ^RIHt R.t. ROt	 ! R R4      t
RR ltR tR	 tR
 tR tR tR tR tR tR# )z•
Unified interfaces to root finding algorithms for real or complex
scalar functions.

Functions
---------
- root : find a root of a scalar function.
N)Ú	_zeros_py©Úapprox_derivativeÚroot_scalarc                   óB   a € ] tR t^t o RtR tR tR tR tR t	Rt
V tR# )	Ú
MemoizeDera€  Decorator that caches the value and derivative(s) of function each
time it is called.

This is a simplistic memoizer that calls and caches a single value
of ``f(x, *args)``.
It assumes that `args` does not change between invocations.
It supports the use case of a root-finder where `args` is fixed,
`x` changes, and only rarely, if at all, does x assume the same value
more than once.c                ó<   € Wn         R V n        R V n        ^ V n        R # ©N)ÚfunÚvalsÚxÚn_calls)Úselfr
   s   &&Úl/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/scipy/optimize/_root_scalar.pyÚ__init__ÚMemoizeDer.__init__   s   € ØŒØˆŒ	ØˆŒØˆŽó    c                óæ   € V P                   e   WP                  8w  dB   V P                  ! V.VO5!  pWn        V ;P                  ^,          un        VR,          V n         V P                   ^ ,          # )z,Calculate f or use cached value if available:NNN)r   r   r
   r   )r   r   ÚargsÚfgs   &&* r   Ú__call__ÚMemoizeDer.__call__$   sU   € ð �9‰9Ò §V¡V¤Ø—’˜!Ð#˜dÓ#ˆBØŒFØ�LŠL˜AÕ�LØ˜1�ˆDŒIØ�y‰y˜�|Ðr   c                óx   € V P                   e   WP                  8w  d   V ! V.VO5!   V P                   ^,          # )z/Calculate f' or use a cached value if available©r   r   ©r   r   r   s   &&*r   ÚfprimeÚMemoizeDer.fprime.   ó-   € à�9‰9Ò §V¡V¤Ù�ˆN�TŒNØ�y‰y˜�|Ðr   c                óx   € V P                   e   WP                  8w  d   V ! V.VO5!   V P                   ^,          # )z0Calculate f'' or use a cached value if availabler   r   s   &&*r   Úfprime2ÚMemoizeDer.fprime24   r   r   c                ó   € V P                   # r	   )r   )r   s   &r   ÚncallsÚMemoizeDer.ncalls:   s   € Ø�|‰|Ðr   )r
   r   r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   r   r"   Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r   r   r      s(   ø‡ € ñòòòò÷ð r   r   c                óŠ  a € \        V\        4      '       g   V3pVf   / pRpVeK   \        V4      '       g:   \        V4      '       d'   \	        S 4      o RpS P
                  pS P                  pMRpVe?   \        V4      '       g.   \        V4      '       d   \	        S 4      o RpS P                  pMRp/ pR F&  p\        4       P                  V4      pVf   K"  WýV&   K(  	  V'       d   VP                  V4       VP                  RRR7       V'       g+   Ve   RpM#Ve    V'       d   V'       d   RpMRpM	Ve   R	pMRpV'       g   \        R
4      hVP                  4       pRRR	R/p \        \        VP                  VV4      4      pTR9   dd   \        T\        \        ,          \         P"                  ,          4      '       g   \        RT 24      hTR,          w  pp T! S TT3RT/TB w  ppEM"TR9   dD   Tf   \        RT 24      hRT9   d   TP1                  R4      TR&   T! S T3RTRRRRRT/TB w  ppMØTR9   dP   Tf   \        RT 24      hT'       g   T 3R lpRT9   d   TP1                  R4      TR&   T! S T3RTRTRR/TB w  ppM‚TR9   dn   Tf   \        RT 24      hT'       g   \        RT 24      hT'       g   \        RT 24      hRT9   d   TP1                  R4      TR&   T! S T3RTRTRT/TB w  ppM\        RT 24      hT'       d   S P2                  pTTn        T#   \         d   p\        RT 24      ThRp?ii ; i  \         dd   p\%        TR4      '       dL   \        P&                  ! TP(                  \         P*                  TP,                  \/        T4      TR7      p Rp?L§h Rp?ii ; i)a  
Find a root of a scalar function.

Parameters
----------
f : callable
    A function to find a root of.

    Suppose the callable has signature ``f0(x, *my_args, **my_kwargs)``, where
    ``my_args`` and ``my_kwargs`` are required positional and keyword arguments.
    Rather than passing ``f0`` as the callable, wrap it to accept
    only ``x``; e.g., pass ``fun=lambda x: f0(x, *my_args, **my_kwargs)`` as the
    callable, where ``my_args`` (tuple) and ``my_kwargs`` (dict) have been
    gathered before invoking this function.
args : tuple, optional
    Extra arguments passed to the objective function and its derivative(s).
method : str, optional
    Type of solver.  Should be one of

    - 'bisect'    :ref:`(see here) <optimize.root_scalar-bisect>`
    - 'brentq'    :ref:`(see here) <optimize.root_scalar-brentq>`
    - 'brenth'    :ref:`(see here) <optimize.root_scalar-brenth>`
    - 'ridder'    :ref:`(see here) <optimize.root_scalar-ridder>`
    - 'toms748'    :ref:`(see here) <optimize.root_scalar-toms748>`
    - 'newton'    :ref:`(see here) <optimize.root_scalar-newton>`
    - 'secant'    :ref:`(see here) <optimize.root_scalar-secant>`
    - 'halley'    :ref:`(see here) <optimize.root_scalar-halley>`

bracket: A sequence of 2 floats, optional
    An interval bracketing a root.  ``f(x, *args)`` must have different
    signs at the two endpoints.
x0 : float, optional
    Initial guess.
x1 : float, optional
    A second guess.
fprime : bool or callable, optional
    If `fprime` is a boolean and is True, `f` is assumed to return the
    value of the objective function and of the derivative.
    `fprime` can also be a callable returning the derivative of `f`. In
    this case, it must accept the same arguments as `f`.
fprime2 : bool or callable, optional
    If `fprime2` is a boolean and is True, `f` is assumed to return the
    value of the objective function and of the
    first and second derivatives.
    `fprime2` can also be a callable returning the second derivative of `f`.
    In this case, it must accept the same arguments as `f`.
xtol : float, optional
    Tolerance (absolute) for termination.
rtol : float, optional
    Tolerance (relative) for termination.
maxiter : int, optional
    Maximum number of iterations.
options : dict, optional
    A dictionary of solver options. E.g., ``k``, see
    :obj:`show_options()` for details.

Returns
-------
sol : RootResults
    The solution represented as a ``RootResults`` object.
    Important attributes are: ``root`` the solution , ``converged`` a
    boolean flag indicating if the algorithm exited successfully and
    ``flag`` which describes the cause of the termination. See
    `RootResults` for a description of other attributes.

See also
--------
show_options : Additional options accepted by the solvers
root : Find a root of a vector function.

Notes
-----
This section describes the available solvers that can be selected by the
'method' parameter.

The default is to use the best method available for the situation
presented.
If a bracket is provided, it may use one of the bracketing methods.
If a derivative and an initial value are specified, it may
select one of the derivative-based methods.
If no method is judged applicable, it will raise an Exception.

Arguments for each method are as follows (x=required, o=optional).

+-----------------------------------------------+---+------+---------+----+----+--------+---------+------+------+---------+---------+
|                    method                     | f | args | bracket | x0 | x1 | fprime | fprime2 | xtol | rtol | maxiter | options |
+===============================================+===+======+=========+====+====+========+=========+======+======+=========+=========+
| :ref:`bisect <optimize.root_scalar-bisect>`   | x |  o   |    x    |    |    |        |         |  o   |  o   |    o    |   o     |
+-----------------------------------------------+---+------+---------+----+----+--------+---------+------+------+---------+---------+
| :ref:`brentq <optimize.root_scalar-brentq>`   | x |  o   |    x    |    |    |        |         |  o   |  o   |    o    |   o     |
+-----------------------------------------------+---+------+---------+----+----+--------+---------+------+------+---------+---------+
| :ref:`brenth <optimize.root_scalar-brenth>`   | x |  o   |    x    |    |    |        |         |  o   |  o   |    o    |   o     |
+-----------------------------------------------+---+------+---------+----+----+--------+---------+------+------+---------+---------+
| :ref:`ridder <optimize.root_scalar-ridder>`   | x |  o   |    x    |    |    |        |         |  o   |  o   |    o    |   o     |
+-----------------------------------------------+---+------+---------+----+----+--------+---------+------+------+---------+---------+
| :ref:`toms748 <optimize.root_scalar-toms748>` | x |  o   |    x    |    |    |        |         |  o   |  o   |    o    |   o     |
+-----------------------------------------------+---+------+---------+----+----+--------+---------+------+------+---------+---------+
| :ref:`secant <optimize.root_scalar-secant>`   | x |  o   |         | x  | o  |        |         |  o   |  o   |    o    |   o     |
+-----------------------------------------------+---+------+---------+----+----+--------+---------+------+------+---------+---------+
| :ref:`newton <optimize.root_scalar-newton>`   | x |  o   |         | x  |    |   o    |         |  o   |  o   |    o    |   o     |
+-----------------------------------------------+---+------+---------+----+----+--------+---------+------+------+---------+---------+
| :ref:`halley <optimize.root_scalar-halley>`   | x |  o   |         | x  |    |   x    |    x    |  o   |  o   |    o    |   o     |
+-----------------------------------------------+---+------+---------+----+----+--------+---------+------+------+---------+---------+

Examples
--------

Find the root of a simple cubic

>>> from scipy import optimize
>>> def f(x):
...     return (x**3 - 1)  # only one real root at x = 1

>>> def fprime(x):
...     return 3*x**2

The `brentq` method takes as input a bracket

>>> sol = optimize.root_scalar(f, bracket=[0, 3], method='brentq')
>>> sol.root, sol.iterations, sol.function_calls
(1.0, 10, 11)

The `newton` method takes as input a single point and uses the
derivative(s).

>>> sol = optimize.root_scalar(f, x0=0.2, fprime=fprime, method='newton')
>>> sol.root, sol.iterations, sol.function_calls
(1.0, 11, 22)

The function can provide the value and derivative(s) in a single call.

>>> def f_p_pp(x):
...     return (x**3 - 1), 3*x**2, 6*x

>>> sol = optimize.root_scalar(
...     f_p_pp, x0=0.2, fprime=True, method='newton'
... )
>>> sol.root, sol.iterations, sol.function_calls
(1.0, 11, 11)

>>> sol = optimize.root_scalar(
...     f_p_pp, x0=0.2, fprime=True, fprime2=True, method='halley'
... )
>>> sol.root, sol.iterations, sol.function_calls
(1.0, 7, 8)


NFTÚxtol)Úfull_outputÚdispÚbrentqÚhalleyÚnewtonÚsecantzIUnable to select a solver as neither bracket nor starting point provided.zUnknown solver zBracket needed for :Né   Nr   Ú_x)ÚrootÚ
iterationsÚfunction_callsÚflagÚmethodzx0 must not be None for Útolr   r   Úx1c                 ó:   <€ V3R  lp\        W RVR7      ^ ,          # )c                 ó&   <€ S! V ^ ,          .VO5!  # )é    © )r   r   Úfs   &*€r   Ú	f_wrappedÚ.root_scalar.<locals>.fprime.<locals>.f_wrappedA  s   ø€ Ù˜Q˜q�T˜> D›>Ð)r   z2-point)r:   r   r   )r   r   rB   rA   s   &* €r   r   Úroot_scalar.<locals>.fprime9  s   ø€ õ*ä(¨¸iÈdÔSÐTUÕVÐVr   zfprime must be specified for zfprime2 must be specified for )r-   ÚrtolÚmaxiter)ÚbisectÚridderr0   ÚbrenthÚtoms748)r3   )r2   )r1   )Ú
isinstanceÚtupleÚcallableÚboolr   r   r   ÚlocalsÚgetÚupdateÚ
ValueErrorÚlowerÚgetattrÚoptzerosÚAttributeErrorÚlistÚnpÚndarrayÚhasattrÚRootResultsr5   ÚnanÚ_function_callsÚstrÚpopr   r8   )rA   r   r:   Úbracketr   r   Úx0r<   r-   rE   rF   ÚoptionsÚis_memoizedÚkwargsÚkÚvÚmethÚmap2underlyingÚmethodcÚeÚaÚbÚrÚsolr   s   f&&&&&&&&&&&             r   r   r   >   sï  ø€ ôr �dœE×"Ò"Øˆwˆà‚Øˆð €KØÒ¤8¨G×#4Ò#4Ü��=Š=Ü˜1“ˆAØˆKØ—i‘iˆGØ—X‘X‰FàˆGØÒ¤(¨6×"2Ò"2Ü��<Š<Ü˜1“ˆAØˆKØ—X‘X‰FàˆFð €FÛ(ˆÜ‹H�L‰L˜‹OˆØŒ=Ø�1‹Iñ )÷ Ø�‰�gÔð ‡M�M˜d¨€MÔ/÷ ØÒØ‰FØŠ^ßßØ%‘Fà%‘FØ’Ø!‘à!�ßÜð 8ó 9ð 	9ð �<‰<‹>€DØ ¨(°HÐ=€Nð:Üœ( N×$6Ñ$6°t¸TÓ$BÓCˆð ÐBÔBÜ˜'¤4¬%¥<´"·*±*Õ#<×=Ò=ÜÐ2°6°(Ð;Ó<Ð<à�r�{‰ˆˆ1ð	Ù˜Q  1Ñ:¨4Ð:°6Ñ:‰FˆAŠsð 
�Ô	ØŠ:ÜÐ7¸°xÐ@ÓAÐAØ�VÔØ"ŸJ™J vÓ.ˆF�5‰MÙ˜˜Bñ * Tð *°$ð *Àð *Øð*Ø"(ñ*‰ˆ‰3à	�Ô	ØŠ:ÜÐ7¸°xÐ@ÓAÐAßõ
Wð �VÔØ"ŸJ™J vÓ.ˆF�5‰MÙ˜˜Bñ # Tð #°&ð #À$ð #Ø!ñ#‰ˆ‰3à	�Ô	ØŠ:ÜÐ7¸°xÐ@ÓAÐAßÜÐ<¸V¸HÐEÓFÐFßÜÐ=¸f¸XÐFÓGÐGØ�VÔØ"ŸJ™J vÓ.ˆF�5‰MÙ˜˜BÑT TÐT°&ÐTÀ'ÐTÈVÑT‰ˆ‰3ä˜?¨6¨(Ð3Ó4Ð4çð —)‘)ˆØ$ˆÔà€JøôO ô :Ü˜?¨4¨&Ð1Ó2¸Ð9ûð:ûô ô 	ô
 �q˜$×ÒÜ×*Ò*°·±Ü68·f±fØ:;×:KÑ:KÜ03°A³¸vôG•ð
 ûð	ús7   Å) L2 Ç!M Ì2MÌ=MÍMÍOÍAN=Î<N=Î=Oc                 ó   € R# )a  
Options
-------
args : tuple, optional
    Extra arguments passed to the objective function.
bracket: A sequence of 2 floats, optional
    An interval bracketing a root.  ``f(x, *args)`` must have different
    signs at the two endpoints.
xtol : float, optional
    Tolerance (absolute) for termination.
rtol : float, optional
    Tolerance (relative) for termination.
maxiter : int, optional
    Maximum number of iterations.
options: dict, optional
    Specifies any method-specific options not covered above

Nr@   r@   r   r   Ú_root_scalar_brentq_docrp   _  ó   € ñ& 	r   c                 ó   € R# ©a  
Options
-------
args : tuple, optional
    Extra arguments passed to the objective function.
bracket: A sequence of 2 floats, optional
    An interval bracketing a root.  ``f(x, *args)`` must have different
    signs at the two endpoints.
xtol : float, optional
    Tolerance (absolute) for termination.
rtol : float, optional
    Tolerance (relative) for termination.
maxiter : int, optional
    Maximum number of iterations.
options: dict, optional
    Specifies any method-specific options not covered above.

Nr@   r@   r   r   Ú_root_scalar_brenth_docrt   u  rq   r   c                 ó   € R# rs   r@   r@   r   r   Ú_root_scalar_toms748_docrv   Š  rq   r   c                 ó   € R# )a  
Options
-------
args : tuple, optional
    Extra arguments passed to the objective function.
xtol : float, optional
    Tolerance (absolute) for termination.
rtol : float, optional
    Tolerance (relative) for termination.
maxiter : int, optional
    Maximum number of iterations.
x0 : float, required
    Initial guess.
x1 : float, optional
    A second guess. Must be different from `x0`. If not specified,
    a value near `x0` will be chosen.
options: dict, optional
    Specifies any method-specific options not covered above.

Nr@   r@   r   r   Ú_root_scalar_secant_docrx      s   € ñ* 	r   c                 ó   € R# )aÒ  
Options
-------
args : tuple, optional
    Extra arguments passed to the objective function and its derivative.
xtol : float, optional
    Tolerance (absolute) for termination.
rtol : float, optional
    Tolerance (relative) for termination.
maxiter : int, optional
    Maximum number of iterations.
x0 : float, required
    Initial guess.
fprime : bool or callable, optional
    If `fprime` is a boolean and is True, `f` is assumed to return the
    value of derivative along with the objective function.
    `fprime` can also be a callable returning the derivative of `f`. In
    this case, it must accept the same arguments as `f`.
options: dict, optional
    Specifies any method-specific options not covered above.

Nr@   r@   r   r   Ú_root_scalar_newton_docrz   ¸  s   € ñ. 	r   c                 ó   € R# )a  
Options
-------
args : tuple, optional
    Extra arguments passed to the objective function and its derivatives.
xtol : float, optional
    Tolerance (absolute) for termination.
rtol : float, optional
    Tolerance (relative) for termination.
maxiter : int, optional
    Maximum number of iterations.
x0 : float, required
    Initial guess.
fprime : bool or callable, required
    If `fprime` is a boolean and is True, `f` is assumed to return the
    value of derivative along with the objective function.
    `fprime` can also be a callable returning the derivative of `f`. In
    this case, it must accept the same arguments as `f`.
fprime2 : bool or callable, required
    If `fprime2` is a boolean and is True, `f` is assumed to return the
    value of 1st and 2nd derivatives along with the objective function.
    `fprime2` can also be a callable returning the 2nd derivative of `f`.
    In this case, it must accept the same arguments as `f`.
options: dict, optional
    Specifies any method-specific options not covered above.

Nr@   r@   r   r   Ú_root_scalar_halley_docr|   Ò  s   € ñ8 	r   c                 ó   € R# rs   r@   r@   r   r   Ú_root_scalar_ridder_docr~   ñ  rq   r   c                 ó   € R# rs   r@   r@   r   r   Ú_root_scalar_bisect_docr€     rq   r   )rG   r0   rI   rH   rJ   r2   r3   r1   )r@   NNNNNNNNNN)r(   ÚnumpyrX   Ú r   rU   Ú_numdiffr   Ú__all__ÚROOT_SCALAR_METHODSr   r   rp   rt   rv   rx   rz   r|   r~   r€   r@   r   r   Ú<module>r†      s^   ðñó å #Ý 'àˆ/€ò5Ð ÷'ñ 'ôT^òB		ò,	ò*	ò,	ò0	ò4	ò>	ô,	r   