An Inductive Proof of the Correctness of power
(define power
(lambda (b e)
(if (= e 0)
1
(* b (power b (- e 1))))))
Claim: (power b e) returns be for
non-negative integer e.
- Base Case: When e = 0, (power b e)
returns 1, which is correct by definition.
- Induction Hypothesis (IH): For k = e-1, assume that (power b k) returns
bk.
- Inductive Step:
- (power b e) returns b times the result of calling
(power b (- e 1)) [by inspection}
- (power b (- e 1)) returns be-1 [by
the IH]
- (power b e) returns b × be-1 [by 1, 2]
- (power b e) returns be
[by 3 and elementary algebra]