6 function fact int : int
7 axiom fact0 : fact 0 = 1
8 axiom factn : forall n: int. n > 0 -> fact n = n * fact (n - 1)
10 let rec lemma f (n: int) : unit variant {n}
12 ensures { fact n >= 1 }
26 let rec lemma sum_nonneg (a: array int) (l u: int) : unit
27 requires { 0 <= l <= u <= length a }
28 requires { forall i: int. 0 <= i < length a -> a[i] >= 0 }
30 ensures { sum a l u >= 0 }
32 if u > l then sum_nonneg a (l+1) u
36 (forall i: int. 0 <= i < length a -> a[i] >= 0) ->
37 sum a 0 (length a) >= 0
48 type list 'a = Nil | Cons 'a (list 'a)
50 function length (l:list 'a) : int =
53 | Cons _ r -> 1 + length r
57 let rec lemma_length_non_neg (l:list 'a) : unit
59 ensures { length l >= 0 }
63 | Cons _ r -> lemma_length_non_neg r
67 let rec toy_example(l:list 'a) : unit
68 (* variant { l } does not work (not a sub-term) *)
70 (* works if we add the "ghost lemma_length_non_neg" *)
75 | Cons x (Cons _ r) ->
76 ghost lemma_length_non_neg l;
77 toy_example (Cons x r)