2 (** Benchmarks goals for proof by induction
3 From http://dream.inf.ed.ac.uk/projects/isaplanner/
8 type nat = Zero | Suc nat
10 function (+) (x y: nat) : nat = match x with
12 | Suc xs -> Suc (xs + y)
15 function ( * ) (x y: nat) : nat = match y with
17 | Suc ys -> x + x * ys
20 function (-) (x y: nat) : nat = match x with
22 | Suc xs -> match y with
28 predicate ( < ) (x y: nat) = match y with
30 | Suc ys -> match x with
32 | Suc xs -> xs < ys end
35 predicate ( <= ) (x y: nat) = match x with
37 | Suc xs -> match y with
43 function max (x y: nat) : nat = match x with
45 | Suc xs -> match y with
47 | Suc ys -> Suc (max xs ys) end end
49 function min (x y: nat) : nat = match x with
51 | Suc xs -> match y with
53 | Suc ys -> Suc (min xs ys) end end
60 type list 'a = Nil | Cons 'a (list 'a)
62 function len (l : list 'a) : nat = match l with
64 | Cons _ s -> Suc (len s)
67 predicate mem (x: 'a) (l: list 'a) = match l with
69 | Cons y ys -> if x = y then true else mem x ys
72 function (++) (l r : list 'a) : list 'a = match l with
74 | Cons x ls -> Cons x (ls ++ r)
77 function rev (l: list 'a) : list 'a = match l with
79 | Cons x xs -> rev xs ++ Cons x Nil
82 function insert (x : 'a) (l : list 'a) : list 'a = match l with
84 | Cons h t -> if x = h then Cons x t else Cons h (insert x t)
87 function delete (x: 'a) (l : list 'a) : list 'a = match l with
89 | Cons h t -> if x = h then delete x t else Cons h (delete x t)
92 function take (n: nat) (l : list 'a) : list 'a = match l with
94 | Cons h t -> match n with
96 | Suc m -> Cons h (take m t)
100 function drop (n: nat) (l : list 'a) : list 'a = match l with
102 | Cons h t -> match n with
108 function last (l : list 'a) : 'a
110 forall x: 'a. last (Cons x Nil) = x
112 forall x: 'a, l : list 'a. l <> Nil -> last (Cons x l) = last l
114 function butlast (l : list 'a) : list 'a = match l with
117 | Cons x xs -> Cons x (butlast xs)
120 function zip (l r : list 'a) : list ('a, 'a) = match r with
122 | Cons y rs -> match l with
124 | Cons x ls -> Cons (x,y) (zip ls rs)
128 function count (x: 'a) (l: list 'a) : nat = match l with
130 | Cons y ys -> if x = y then Suc (count x ys) else count x ys
133 function map (f: 'a -> 'b) (l: list 'a) : list 'b = match l with
135 | Cons x xs -> Cons (f x) (map f xs)
138 function filter (p: 'a -> bool) (l : list 'a) : list 'a = match l with
140 | Cons x xs -> if p x then Cons x (filter p xs) else filter p xs
143 function takeWhile (p: 'a -> bool) (l : list 'a) : list 'a = match l with
145 | Cons x xs -> if p x then Cons x (takeWhile p xs) else Nil
148 function dropWhile (p: 'a -> bool) (l : list 'a) : list 'a = match l with
150 | Cons x xs -> if p x then (dropWhile p xs) else (Cons x xs)
153 predicate pfalse (_x: 'a) = false
155 function dropWhile_False (l : list 'a) : list 'a = match l with
157 | Cons x xs -> if pfalse x then (dropWhile_False xs) else (Cons x xs)
160 predicate ptrue (_x: 'a) = true
162 function takeWhile_True (l : list 'a) : list 'a = match l with
164 | Cons x xs -> if ptrue x then Cons x (takeWhile_True xs) else Nil
167 (******************** INSERTION SORT WITH NAT LIST ***************)
169 predicate sorted (l : list nat) = match l with
171 | Cons x xs -> match xs with
173 | Cons y _ -> x <= y && sorted xs
177 function insert_nat (n : nat) (l : list nat) : list nat = match l with
179 | Cons h t -> if n < h then Cons n (Cons h t) else Cons h (insert_nat n t)
182 function insertion_sort_aux (x : nat) (l : list nat) : list nat =
186 if x <= y then Cons x (Cons y ys) else Cons y (insertion_sort_aux x ys)
189 function insertion_sort (l : list nat) : list nat = match l with
191 | Cons x xs -> insertion_sort_aux x (insertion_sort xs)
202 | Node (tree 'a) 'a (tree 'a)
204 function mirror (t: tree 'a) : tree 'a = match t with
206 | Node l x r -> Node (mirror r) x (mirror l)
209 function nodes (t: tree 'a) : nat = match t with
211 | Node l _ r-> (Suc Zero) + nodes l + nodes r
214 function height (t: tree 'a) : nat = match t with
216 | Node l _ r -> Suc (max (height l) (height r))
221 (******************************************************************************)
222 (************************** ISAPLANNER THEOREMS *******************************)
223 (******************************************************************************)
225 (*Pas d'induction(13): 4, 5, 11, 13, 16, 17, 35, 39, 40, 42, 44, 45, 46 *)
226 (*Induction sur une variable(22): 2, 3, 6, 7, 8, 10, 12, 14, 15, 18, 19,
227 21, 26, 27, 28, 29, 30, 32, 36, 37, 38, 43 *)
228 (*Induction sur plusieurs variables à cause de raisonnement par cas (9):
229 1, 9, 22, 23, 24, 25, 31, 33, 34, *)
230 (*Problème résolu avec un lemme supplémentaire (2): 20(15), 47(23) *)
231 (******************************************************************************)
232 theory IsaPlanner_all
238 goal P1: forall l: list 'a, n : nat.
239 take n l ++ drop n l = l
241 goal P2: forall l m: list 'a, x: 'a.
242 count x l + count x m = count x (l ++ m)
244 goal P3: forall l m: list 'a, x: 'a.
245 count x l <= count x (l ++ m)
247 goal P4: forall l: list 'a, x: 'a.
248 Suc Zero + count x l = count x (Cons x l)
250 goal P5: forall l: list 'a, x y : 'a.
251 x = y -> Suc Zero + count x l = count x (Cons y l)
253 goal P6: forall n m: nat.
256 goal P7: forall n m: nat.
259 goal P8: forall k [@induction] n m: nat.
260 (k + m) - (k + n) = (m - n)
262 goal P9: forall i j k: nat.
263 (i - j) - k = i - (j + k)
265 goal P10: forall m: nat.
268 goal P11: forall l: list 'a.
271 goal P12: forall f: 'a -> 'b, l, n.
272 drop n (map f l) = map f (drop n l)
274 goal P13: forall n: nat, x: 'a, ls: list 'a.
275 drop (Suc n) (Cons x ls) = drop n ls
277 goal P14: forall p, xs ys: list 'a.
278 filter p (xs ++ ys) = filter p xs ++ filter p ys
280 goal P15: forall l: list nat, n: nat.
281 len (insertion_sort_aux n l) = Suc (len l)
283 goal P16: forall l: list 'a, x: 'a.
284 l = Nil -> last (Cons x l) = x
286 goal P17: forall n: nat.
287 (n <= Zero) <-> (n = Zero)
289 goal P18: forall i m: nat.
292 goal P19: forall l: list 'a, n: nat.
293 len (drop n l) = (len l) - n
295 (* requires the lemma
296 forall l: list nat, n: nat. len (insertion_sort_aux n l) = Suc (len l) *)
297 goal P20: forall l: list nat.
298 len (insertion_sort l) = len l
300 goal P21: forall n m: nat.
303 goal P22: forall a [@induction] b [@induction] c [@induction]: nat .
304 max (max a b) c = max a (max b c)
306 goal P23: forall a b: nat.
309 goal P24: forall a b: nat.
310 (max a b = a) <-> b <= a
312 goal P25: forall a b: nat.
313 (max a b = b) <-> a <= b
315 goal P26: forall l t: list 'a, x: 'a.
316 mem x l -> mem x (l ++ t)
318 goal P27: forall l t: list 'a, x: 'a.
319 mem x t -> mem x (l ++ t)
321 goal P28: forall l: list 'a, x: 'a.
322 mem x (l ++ Cons x Nil)
324 goal P29: forall l : list nat, x : nat.
325 mem x (insert_nat x l)
327 goal P30: forall l: list 'a, x: 'a.
330 goal P31: forall a [@induction] b [@induction] c [@induction]: nat.
331 min (min a b) c = min a (min b c)
333 goal P32: forall a b: nat.
336 goal P33: forall a b: nat.
337 (min a b = a) <-> a <= b
339 goal P34: forall a b: nat.
340 (min a b = b) <-> b <= a
342 goal P35: forall xs : list 'a.
343 dropWhile_False xs = xs
345 goal P36: forall xs: list 'a.
346 takeWhile_True xs = xs
348 goal P37: forall l: list 'a, x: 'a.
349 not mem x (delete x l)
351 goal P38: forall l: list 'a, n: 'a.
352 count n (l ++ Cons n Nil) = Suc (count n l)
354 goal P39: forall t: list 'a, n h: 'a.
355 count n (Cons h Nil) + count n t = count n (Cons h t)
357 goal P40: forall xs: list 'a.
360 goal P41: forall f, xs : list 'a, n: nat.
361 take n (map f xs : list 'b) = map f (take n xs)
363 goal P42: forall xs: list 'a, n: nat, x: 'a.
364 take (Suc n) (Cons x xs) = Cons x (take n xs)
366 goal P43: forall p, xs : list 'a.
367 takeWhile p xs ++ dropWhile p xs = xs
369 goal P44: forall xs ys: list 'a, x: 'a.
373 | Cons y ys -> Cons (x,y) (zip xs ys)
376 goal P45: forall xs ys: list 'a, x y: 'a .
377 zip (Cons x xs) (Cons y ys) = Cons (x, y) (zip xs ys)
379 goal P46: forall ys: list 'a.
382 (* requires P23: forall a b: nat. max a b = max b a *)
383 goal P47: forall a : tree 'a.
384 height (mirror a) = height a
388 theory IsaPlanner_beyond
394 goal P48: forall xs : list 'a.
395 xs <> Nil -> butlast xs ++ (Cons (last xs) Nil) = xs
397 goal P49: forall xs ys: list 'a .
398 butlast (xs ++ ys) = (if ys = Nil then butlast xs else xs ++ butlast ys)
400 goal P50: forall xs : list 'a.
401 butlast xs = take ((len xs) - (Suc Zero)) xs
403 goal P51: forall xs : list 'a, x: 'a.
404 butlast (xs ++ Cons x Nil) = xs
406 goal P52: forall l : list 'a, n: 'a.
407 count n l = count n (rev l)
409 goal P53: forall l : list nat, x : nat.
410 count x l = count x (insertion_sort l)
412 goal P54: forall m n: nat.
415 goal P55: forall i [@induction] k [@induction] j [@induction] : nat.
416 (i - j) - k = i - (k - j)
418 goal P56: forall xs ys: list 'a, n: nat.
419 drop n (xs ++ ys) = drop n xs ++ drop (n - (len xs)) ys
421 goal P57: forall n [@induction] m [@induction]: nat,
422 xs [@induction]: list nat.
423 drop n (drop m xs) = drop (n + m) xs
425 goal P58: forall xs [@induction]: list 'a,
426 m [@induction] n [@induction]: nat.
427 drop n (take m xs) = take (m - n) (drop n xs)