2 (* EWD 650: A Theorem About Odd Powers of Odd Integers *)
9 use number.Divisibility
12 let theorem (p: int) (k: int) (r: int)
13 requires { p >= 1 /\ odd p /\ k >= 1 /\ 1 <= r < power 2 k /\ odd r }
14 ensures { 1 <= result < power 2 k }
15 ensures { divides (power 2 k) (power result p - r) }
16 ensures { odd result }
20 invariant { !d = power 2 i /\ 1 <= !x < !d }
21 invariant { divides !d (power !x p - r) /\ odd !x }
22 if not (divides (2 * !d) (power !x p - r)) then x := !x + !d;