In Dekker's and Brent's Method, in the initial steps, it states that $a$ and $b$ must be swapped if $|f(a)| < |f(b)|$, why is this step being done? In Dekker's and Brent's method, in the initial steps, if $|f(a)|<|f(b)|$, we swap $a$ and $b$.
Why is this?
I've searched for reasons why, but I cannot find a reason why.


*

*Cleve Moler mentions:



$b$ is the best zero so far, in the sense that $f(b)$ is the smallest value of $f(x)$ so far.



*

*Oscar Veliz (2:51) mentions that it is to keep $b$ as the "better" guess.


But I cannot find an explanation as to why this is.
 A: Because the convention, the loop invariant if you want, is that


*

*The interval between $b$ and $c$ is the root-bracketing interval and

*$b$ is the point with the current smallest function value.


This loop convention avoids additional logic inside the loop, reduces the cases to consider.
In Dekker's method, the pair of $a$ and $b$ usually contains the last two iterates of the secant method. This sequence of course gets broken if some non-secant step (midpoint or minimal step) was taken.
In a "normal" step the value at the secant root $s$ computed from $a$ and $b$ can be expected to be the new smallest value, esp. $|f(s)|<|f(b)|<|f(a)|$.


*

*If $s$ falls between $b$ and $c$


*

*if the signs at $b$ and $s$ are the same, $(a,b,c):=(b,s,c)$

*if the signs at $b$ and $s$ are different, these point form the new bracketing interval, additionally to being the last two points of the secant sequence, thus $(a,b,c)=(b,s,b)$.


*If $s$ falls outside the bracketing interval, the same logic is applied to the midpoint $m$ of $b$ and $c$.
Of course then you also need to consider the not so nice situations where the value at $s$ or $m$ is not the new smallest value.
