[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master a259cb6 05/23: Calculate maximum possible num
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master a259cb6 05/23: Calculate maximum possible number of iterations |
Date: |
Tue, 27 Jul 2021 21:59:51 -0400 (EDT) |
branch: master
commit a259cb67c781a3e750447fbdaa953ad32979266d
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Calculate maximum possible number of iterations
---
zero_test.cpp | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/zero_test.cpp b/zero_test.cpp
index 6afd8e0..73d7bab 100644
--- a/zero_test.cpp
+++ b/zero_test.cpp
@@ -59,6 +59,14 @@ double max_err(double zeta, double tol)
///
/// static_cast<int> is exact for any number of iterations that
/// can be counted by an 'int'.
+///
+/// The greatest possible number of bisection steps (where [x] is
+/// the greatest integer function) is:
+/// log2(DBL_MAX - -DBL_MAX) / DBL_TRUE_MIN
+/// = 1 + 1024 + 1074 = 2099
+/// Yet an IEEE 754 binary64 entity can have no more than 2^64
+/// distinct values; with an appropriate definition of "bisection",
+/// about 64 steps should suffice.
int max_n_iter_bolzano(double a, double b, double tol, double zeta)
{
@@ -68,6 +76,8 @@ int max_n_iter_bolzano(double a, double b, double tol, double
zeta)
}
/// AfMWD eq. 3.3: maximum number of iterations for Brent's method.
+///
+/// The greatest possible number of steps is 2099^2 = 4405801.
int max_n_iter_brent(double a, double b, double tol, double zeta)
{
@@ -337,6 +347,23 @@ void test_fundamentals()
r = decimal_root(e, 0.1, 1.0, bias_none, 9);
LMI_TEST(root_not_bracketed == r.validity);
+
+ // Calculate maximum possible number of iterations according to
+ // the documentation for max_n_iter_bolzano(). This calculation
+ // would overflow in double precision.
+ //
+ // log2(DBL_MAX) is 1024, so log2(DBL_MAX - -DBL_MAX) is 1025;
+ // and log2(DBL_TRUE_MIN) is 1074; so the maximum number of
+ // iterations is
+ // log2(DBL_MAX - -DBL_MAX) / DBL_TRUE_MIN
+ // = 1 + 1024 + 1074 = 2099
+ // for bisection, and 2099^2 = 4405801 for Brent's method with
+ // IEEE 754 binary64.
+ long double max = DBL_MAX;
+ long double min = DBL_TRUE_MIN;
+ int max_iter = static_cast<int>(std::ceil(std::log2((max - -max) / min)));
+ LMI_TEST_EQUAL(1 + 1024 + 1074, max_iter);
+ LMI_TEST_EQUAL(2099, max_iter);
}
/// A function whose value almost everywhere in (-1.0e100, 1.0e100)
- [lmi-commits] [lmi] master eea9469 02/23: Ignore an immaterial i686 deviation, (continued)
- [lmi-commits] [lmi] master eea9469 02/23: Ignore an immaterial i686 deviation, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master a041329 08/23: Consider bounds not to bracket a root if value at either is NaN, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master c9c50dc 07/23: Add a specialized midpoint function for root finding, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master f576a4b 11/23: Augment unit test, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master dc63e62 16/23: Cache evaluations for rounded decimal solves, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master cecc91f 21/23: Avoid a unit-test false negative, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 4b26bf8 01/23: Add a parenthetical comment to a unit test, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 86ae65d 18/23: Revert "Demonstration, for immediate reversion", Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master e59df26 14/23: Refactor, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 8f2f355 19/23: Augment unit tests; record some observations, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master a259cb6 05/23: Calculate maximum possible number of iterations,
Greg Chicares <=
- [lmi-commits] [lmi] master d0a65c2 04/23: Demonstrate that Brent's δ can be almost arbitrarily small, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 548f9ab 06/23: Document known shortcomings of a unit-testing helper, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 19a4a3a 03/23: For now at least, trace solves in regression test, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 04c58eb 09/23: Count iterations and evaluations separately, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master bbf2517 10/23: Use signum() where a signum function is wanted, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master e08be34 12/23: Improve a unit test, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 02dde17 13/23: Avoid catastrophic cancellation, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master d2dcbf8 15/23: Reduce complexity, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master e93ca8f 17/23: Demonstration, for immediate reversion, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 4500338 22/23: Simplify, Greg Chicares, 2021/07/27