author | wenzelm |
Thu, 30 May 2013 21:37:00 +0200 | |
changeset 52255 | 85f732610740 |
parent 52248 | 2c893e0c1def |
child 52260 | e7c47fe56fbd |
permissions | -rw-r--r-- |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
1 |
theory Examples |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
2 |
imports Spec_Check |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
3 |
begin |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
4 |
|
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
5 |
section {* List examples *} |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
6 |
|
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
7 |
ML_command {* |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
8 |
check_property @{context} "ALL xs. rev xs = xs"; |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
9 |
*} |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
10 |
|
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
11 |
ML_command {* |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
12 |
check_property @{context} "ALL xs. rev (rev xs) = xs"; |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
13 |
*} |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
14 |
|
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
15 |
|
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
16 |
section {* AList Specification *} |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
17 |
|
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
18 |
ML_command {* |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
19 |
(* map_entry applies the function to the element *) |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
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)"; |
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
21 |
*} |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
22 |
|
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
23 |
ML_command {* |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
24 |
(* update always results in an entry *) |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
25 |
check_property @{context} "ALL k v xs. AList.defined (op =) (AList.update (op =) (k, v) xs) k"; |
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
26 |
*} |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
27 |
|
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
28 |
ML_command {* |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
29 |
(* update always writes the value *) |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
30 |
check_property @{context} "ALL k v xs. AList.lookup (op =) (AList.update (op =) (k, v) xs) k = SOME v"; |
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
31 |
*} |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
32 |
|
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
33 |
ML_command {* |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
34 |
(* default always results in an entry *) |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
35 |
check_property @{context} "ALL k v xs. AList.defined (op =) (AList.default (op =) (k, v) xs) k"; |
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
36 |
*} |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
37 |
|
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
38 |
ML_command {* |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
39 |
(* delete always removes the entry *) |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
40 |
check_property @{context} "ALL k xs. not (AList.defined (op =) (AList.delete (op =) k xs) k)"; |
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
41 |
*} |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
42 |
|
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
43 |
ML_command {* |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
44 |
(* default writes the entry iff it didn't exist *) |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
45 |
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))"; |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
46 |
*} |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
47 |
|
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
48 |
section {* Examples on Types and Terms *} |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
49 |
|
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
50 |
ML_command {* |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
51 |
check_property @{context} "ALL f g t. map_types (g o f) t = (map_types f o map_types g) t"; |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
52 |
*} |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
53 |
|
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
54 |
ML_command {* |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
55 |
check_property @{context} "ALL f g t. map_types (f o g) t = (map_types f o map_types g) t"; |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
56 |
*} |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
57 |
|
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
58 |
|
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
59 |
text {* One would think this holds: *} |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
60 |
|
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
61 |
ML_command {* |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
62 |
check_property @{context} "ALL t ts. strip_comb (list_comb (t, ts)) = (t, ts)" |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
63 |
*} |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
64 |
|
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
65 |
text {* But it only holds with this precondition: *} |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
66 |
|
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
67 |
ML_command {* |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
68 |
check_property @{context} "ALL t ts. case t of _ $ _ => true | _ => strip_comb (list_comb (t, ts)) = (t, ts)" |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
69 |
*} |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
70 |
|
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
71 |
section {* Some surprises *} |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
72 |
|
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
73 |
ML_command {* |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
74 |
check_property @{context} "ALL Ts t. type_of1 (Ts, t) = fastype_of1 (Ts, t)" |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
75 |
*} |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
76 |
|
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
77 |
|
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
78 |
ML {* val thy = @{theory}; *} |
52255
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
79 |
ML_command {* |
85f732610740
prefer separate 'ML_command' for parallel evaluation;
wenzelm
parents:
52248
diff
changeset
|
80 |
check_property @{context} "ALL t u. if Pattern.matches thy (t, u) then Term.could_unify (t, u) else true" |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
81 |
*} |
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
82 |
|
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
83 |
end |