triqs.utility.dichotomy.dichotomy
- triqs.utility.dichotomy.dichotomy(function, x_init, y_value, precision_on_y, delta_x, max_loops=1000, x_name='', y_name='', verbosity=1)[source]
Find \(x\) such that \(f(x) = y_{\mathrm{value}}\).
Starting from
x_init(treated as either the lower or the upper bound depending on the local sign of \(f - y\)), the second bracketing bound is found by stepping bydelta_xuntil the sign of \(f(x) - y_{\mathrm{value}}\) changes. The root is then refined by linear interpolation between the current bounds untilabs(f(x) - y_value) < precision_on_yormax_loopsis reached.- Parameters:
- functioncallable
Real-valued function \(f(x)\) of one real argument.
- x_initfloat
Initial guess for \(x\), used as one end of the initial bracket.
- y_valuefloat
Target value \(y_{\mathrm{value}}\) to be matched.
- precision_on_yfloat
Convergence tolerance: the iteration stops when
abs(f(x) - y_value) < precision_on_y.- delta_xfloat
\(\Delta x\) added to or subtracted from
x_inituntil the second bracketing bound is found.- max_loopsint, optional
Maximum number of bracketing + bisection iterations. Default 1000.
- x_namestr, optional
Display name for \(x\), used in the textual report. Default
"".- y_namestr, optional
Display name for \(y\), used in the textual report. Default
"".- verbosityint, optional
Verbosity of the textual report emitted through
triqs.utility.mpi.0suppresses per-iteration output;>= 1prints the final answer;>= 3prints every intermediate \(x\)/\(y\) pair. Default 1.
- Returns:
- xfloat or None
Solution of \(f(x) = y_{\mathrm{value}}\), or
Noneif the iteration did not converge withinmax_loopssteps.- yfloat or None
Function value \(f(x)\) at the returned solution, or
Noneon failure.
Notes
On failure the function returns
(None, None)rather than raising; callers are expected to check the result.The progress messages are printed via
triqs.utility.mpi.report(), which suppresses output on non-master MPI ranks.