1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
use crateScalar;
use ;
use ;
/// Safeguarded Newton iteration for a scalar equation `f(x) = 0`.
///
/// Starts at the midpoint or [`with_initial_guess`](Self::with_initial_guess),
/// then proposes `x - f(x)/f'(x)`. A zero or non-finite derivative disables
/// Newton interpolation. Unsafe proposals fall back to secant interpolation
/// and then bisection. After two trials that fail to halve the bracket, the
/// next trial is a bisection.
///
/// The function must satisfy [`super::SecantRoot`]'s continuity and endpoint
/// sign contract. Derivatives must describe that function wherever they are
/// finite. An exact zero or bracket width at most
/// `absolute + relative * abs(best_endpoint)` establishes convergence; a
/// small Newton step alone does not. Each iteration evaluates one trial.
/// Limits return a clean [`RootResult`]; invalid inputs and callback failures
/// return [`RootError`]. Each solve starts with fresh history.
///
/// Separate callbacks compute derivatives only when an interpolation needs
/// them. [`solve_combined`](Self::solve_combined) computes a value and its
/// derivative together, including at endpoints, and caches the result.
/// Both interfaces preserve typed callback errors. Non-finite function values
/// are errors; non-finite derivatives trigger the safeguards instead.
///
/// # Backends
///
/// Scalar `f64` and `f32`; no linear-algebra backend or optional feature.
///
/// # Example
///
/// ```
/// use basin::NewtonRoot;
/// use std::convert::Infallible;
/// let root = NewtonRoot::new(0.0, 2.0)
/// .solve_combined(|x| Ok::<_, Infallible>((x * x - 2.0, 2.0 * x)))
/// .unwrap();
/// assert!(root.converged());
/// assert!((root.root() - 2.0_f64.sqrt()).abs() < 1e-10);
/// ```
///
/// # References
///
/// Boost.Math 1.89.0, "Root Finding With Derivatives: Newton-Raphson, Halley
/// & Schroeder." Basin adds secant fallback, a two-trial contraction safeguard,
/// and bracket-based termination.
/// <https://www.boost.org/doc/libs/1_89_0/libs/math/doc/html/math_toolkit/roots_deriv.html>