|
1 theory Examples |
|
2 imports Spec_Check |
|
3 begin |
|
4 |
|
5 section {* List examples *} |
|
6 |
|
7 ML {* |
|
8 check_property @{context} "ALL xs. rev xs = xs"; |
|
9 *} |
|
10 |
|
11 ML {* |
|
12 check_property @{context} "ALL xs. rev (rev xs) = xs"; |
|
13 *} |
|
14 |
|
15 |
|
16 section {* AList Specification *} |
|
17 |
|
18 ML {* |
|
19 (* map_entry applies the function to the element *) |
|
20 check_property @{context} "ALL k f xs. AList.lookup (op =) (AList.map_entry (op =) k f xs) k = Option.map f (AList.lookup (op =) xs k)"; |
|
21 |
|
22 (* update always results in an entry *) |
|
23 check_property @{context} "ALL k v xs. AList.defined (op =) (AList.update (op =) (k, v) xs) k"; |
|
24 |
|
25 (* update always writes the value *) |
|
26 check_property @{context} "ALL k v xs. AList.lookup (op =) (AList.update (op =) (k, v) xs) k = SOME v"; |
|
27 |
|
28 (* default always results in an entry *) |
|
29 check_property @{context} "ALL k v xs. AList.defined (op =) (AList.default (op =) (k, v) xs) k"; |
|
30 |
|
31 (* delete always removes the entry *) |
|
32 check_property @{context} "ALL k xs. not (AList.defined (op =) (AList.delete (op =) k xs) k)"; |
|
33 |
|
34 (* default writes the entry iff it didn't exist *) |
|
35 check_property @{context} "ALL k v xs. (AList.lookup (op =) (AList.default (op =) (k, v) xs) k = (if AList.defined (op =) xs k then AList.lookup (op =) xs k else SOME v))"; |
|
36 *} |
|
37 |
|
38 section {* Examples on Types and Terms *} |
|
39 |
|
40 ML {* |
|
41 check_property @{context} "ALL f g t. map_types (g o f) t = (map_types f o map_types g) t"; |
|
42 *} |
|
43 |
|
44 ML {* |
|
45 check_property @{context} "ALL f g t. map_types (f o g) t = (map_types f o map_types g) t"; |
|
46 *} |
|
47 |
|
48 text {* One would think this holds: *} |
|
49 |
|
50 ML {* |
|
51 check_property @{context} "ALL t ts. strip_comb (list_comb (t, ts)) = (t, ts)" |
|
52 *} |
|
53 |
|
54 text {* But it only holds with this precondition: *} |
|
55 |
|
56 ML {* |
|
57 check_property @{context} "ALL t ts. case t of _ $ _ => true | _ => strip_comb (list_comb (t, ts)) = (t, ts)" |
|
58 *} |
|
59 |
|
60 section {* Some surprises *} |
|
61 |
|
62 ML {* |
|
63 check_property @{context} "ALL Ts t. type_of1 (Ts, t) = fastype_of1 (Ts, t)" |
|
64 *} |
|
65 |
|
66 |
|
67 |
|
68 ML {* val thy = @{theory}; *} |
|
69 ML {* |
|
70 check_property @{context} "ALL t u. if Pattern.matches thy (t, u) then Term.could_unify (t, u) else true" |
|
71 *} |
|
72 |
|
73 end |