2 (** Various ways of proving
6 forall n: int. 0 <= n -> p n -> p (n+2)
7 ---------------------------------------
8 forall n: int. 0 <= n -> p n
10 by induction using theories int.SimpleInduction or
11 int.Induction or lemma functions.
22 axiom H2: forall n: int. 0 <= n -> p n -> p (n + 2)
26 (** {2 With a simple induction} *)
31 predicate pr (k: int) = p k && p (k+1)
32 clone int.SimpleInduction
33 with predicate p = pr, lemma base, lemma induction_step
35 goal G: forall n: int. 0 <= n -> p n
39 (** {2 With a strong induction} *)
45 with predicate p = p, constant bound = zero
47 goal G: forall n: int. 0 <= n -> p n
51 (** {2 With a recursive lemma function} *)
56 let rec lemma ind (n: int) requires { 0 <= n} ensures { p n }
58 = if n >= 2 then ind (n-2)
60 (** no need to write the following goal, that's just a check this is
62 goal G: forall n: int. 0 <= n -> p n
66 (** {2 With a while loop} *)
72 let lemma ind (n: int) requires { 0 <= n} ensures { p n }
76 invariant { 0 <= !k && (p !k -> p n) } variant { !k }
80 goal G: forall n: int. 0 <= n -> p n
84 (** {2 With an ascending while loop} *)
90 let lemma ind (n: int) requires { 0 <= n} ensures { p n }
94 invariant { 0 <= !k <= n && p !k && p (!k + 1) } variant { n - !k }
98 goal G: forall n: int. 0 <= n -> p n