Let us consider algorithm 2.
Note that the first two statements of algorithm 2
are the same as the first two statements of algorithm 1.
Let's start with the first statement that is different. We know that
. What is the
?
Let us examine what we are doing on line 3. In this
assignment statement, we first evaluate the right hand side.
at this point, so
. Then, we take the value of 3, and use that
to update
. In other words,
after the statement.
In the analysis of post conditions, we have a more obsure way to come to the same conclusion.
First, let us define a ``function''
. This is really just a
notation so that
,
and etc. When some functions,
we can also define an ``inverse function''. In this case, the
inverse function is
. What this really means is simply
that
. In other words,
undoes whatever
does.
Next, let us define a substitution operation.
means that
in condition
, replace all occurances of
with
. For example,
.
With these new tools, we can get back to work. Let us keep the definition
that
and
. Then we have the following
derivation:
![]() |
![]() |
![]() |
(7) |
![]() |
![]() |
(8) | |
![]() |
![]() |
(9) | |
![]() |
![]() |
(10) |
Of course, this doesn't really come as a surprise. However, we now know why it is the case!
On to the last statement, we define
. The inverse function
is
so that
. Given this, we can
finish the derivation:
![]() |
![]() |
![]() |
(11) |
![]() |
![]() |
(12) | |
![]() |
![]() |
(13) | |
![]() |
![]() |
(14) |
This is yet another earth-breaking discovery (not!). Although it may seem that we could have used intuition (sometimes called ``eyeball proof'') to come to the same conclusion, the tools that we have used in this section are very general and can be applied to much more difficult problems.
We can now derive the general case as follows:
Assume that is a function of
that has an inverse function
, then
.
Copyright © 2012-02-07 by Tak Auyeung