On 26/01/2021 15:46, Shriramana Sharma via Boost-users wrote:
Namaste.
This is wrt the TOMS748 math root finding implementation:
Given that `if(fa == 0)` is handled at:
https://github.com/boostorg/math/blob/develop/include/boost/math/tools/toms7...
… and the function returns in case of the above condition, it is not clear to me what the need is for the `if (fa != 0)` at:
https://github.com/boostorg/math/blob/develop/include/boost/math/tools/toms7...
You're quite right - it's superfluous, will fix.
Now I also note similar checks at:
https://github.com/boostorg/math/blob/develop/include/boost/math/tools/toms7... https://github.com/boostorg/math/blob/develop/include/boost/math/tools/toms7...
… but regarding those lines, while I can understand the need for checking there after more bracketing work is done, it is not clear to me why `(fa == 0)` is alone checked for, and not `(fb == 0)` as well. I would have thought the algorithm is not biased towards a or b.
When bracket() is called, it updates either fa or fb with the next value (fc), and when fc is zero then fa is always set to zero, and the result is always a. So checking fb == 0 is unnecessary after a bracket() call.
Indeed, in the last steps from:
https://github.com/boostorg/math/blob/develop/include/boost/math/tools/toms7...,
… both the conditions are checked for,
Somewhat different situation - at this point the loop has terminated, and we're just tightening up our interval in the case that one of a or b is right on the root. This is a nicety not required by the algorithm as such, and indeed the fb == 0 branch *may* be superfluous, but I would want to think very carefully indeed before changing it ;) Best, John Maddock. -- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus