2 (** {1 Nistonacci numbers}
4 The simple "Nistonacci numbers" example, originally designed by
5 K. Rustan M. Leino for the SSAS workshop (Sound Static Analysis
6 for Security, NIST, Gaithersburg, MD, USA, June 27-28, 2018) *)
13 new in Why3 1.0: (pure) program function that goes into the logic
14 (no need for axioms anymore to define such a function)
17 let rec ghost function nist(n:int) : int
20 = if n < 2 then n else nist (n-2) + 2 * nist (n-1)
22 (** {2 Implementation} *)
26 let rec nistonacci (n:int) : int
29 ensures { result = nist n }
33 invariant { !x = nist i }
34 invariant { !y = nist (i+1) }
41 (** {2 A general lemma on Nistonacci numbers}
43 That lemma function is used to prove the lemma `forall n. nist(n) >=
44 n` by induction on `n`
48 (*** (new in Why3 1.0: markdown in comments !) *)
50 let rec lemma nist_ge_n (n:int)
53 ensures { nist(n) >= n }
54 = if n >= 2 then begin
55 (** recursive call on `n-1`, acts as using the induction
56 hypothesis on `n-1` *)
58 (** let's also use induction hypothesis on `n-2` *)
63 (** test: this can be proved by instantiating the previous lemma *)
65 goal test : nist 42 >= 17