Let us consider algorithm 3.
Let's begin with
. After the initialization
of
, we know that
.
However, the post condition of line 2 is not as simple.
This is because there are actually two ways to get to
line 2. In the first iteration, we enter from line
1. However, in subsequent iterations, we enter from
line 3. On the other hand, no matter which way we come
from, we know that the condition
must be true if we enter
the loop.
As a result, all we say at this time is that
. Note that
.
The statement on line 3 looks familiar. It involves a
function of . In this case, the inverse function is
.
We can then derive the following:
![]() |
![]() |
![]() |
(17) |
![]() |
![]() |
(18) | |
![]() |
![]() |
(19) |
This is interesting because the same notation appears on the left and the
right hand side of the equation. The solution is to find a definition
that works in this equation. Choosing
works. This is because
simplifies to
because it includes the case of
. Furthermore,
can also simplify to just
.
In conclusion, we can define
.
How about
? In theory, we can get there
using two means. First, it is possible not to enter the loop at all.
Second, we can go through the loop at least once, then exit the loop.
Regardless of whether we get into the loop or not, one thing is for
sure:
must be false. As a result,
![]() |
![]() |
![]() |
(20) |
![]() |
![]() |
(21) | |
![]() |
![]() |
(22) | |
![]() |
![]() |
(23) |
In other words, when we exit the loop, we know that .
In its general form, a prechecking loop is as follows:
The general form of a postchecking loop is as follows: