Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
sav08:proving_correctness_of_some_small_examples [2008/02/17 18:35] vkuncak |
sav08:proving_correctness_of_some_small_examples [2008/02/17 18:56] vkuncak |
||
---|---|---|---|
Line 3: | Line 3: | ||
In this demo we go through several examples and prove them correct using Jahob. | In this demo we go through several examples and prove them correct using Jahob. | ||
- | {{sav08:integerdemo.java.txt|Examples of Functions}} | + | ==== A Recursive Function ==== |
+ | |||
+ | Consider the following recursive function: | ||
+ | |||
+ | <code> | ||
+ | private static int f(int x, int y) | ||
+ | { | ||
+ | if (y == 0) { | ||
+ | return 0; | ||
+ | } else { | ||
+ | if (y % 2 == 0) { | ||
+ | int z = f(x, y / 2); | ||
+ | return (2 * z); | ||
+ | } else { | ||
+ | return (x + f(x, y - 1)); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | * What does 'f' compute? | ||
+ | * How can we prove it? | ||
+ | * [[Proof of first lecture01 example]] | ||
+ | |||
+ | {{sav08:integerdemo.java.txt|Examples of Functions with Specifications}} | ||
For homework, you will have more such examples. | For homework, you will have more such examples. | ||