author | wenzelm |
Fri, 01 Apr 2016 18:56:31 +0200 | |
changeset 62804 | 7b9c5416f30e |
parent 62020 | 5d208fd2507d |
child 69593 | 3dda49e08b9d |
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 |
|
62020 | 5 |
section \<open>List examples\<close> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
6 |
|
62020 | 7 |
ML_command \<open> |
52260
e7c47fe56fbd
toplevel invocation via implicit ML compilation context;
wenzelm
parents:
52255
diff
changeset
|
8 |
check_property "ALL xs. rev xs = xs"; |
62020 | 9 |
\<close> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
10 |
|
62020 | 11 |
ML_command \<open> |
52260
e7c47fe56fbd
toplevel invocation via implicit ML compilation context;
wenzelm
parents:
52255
diff
changeset
|
12 |
check_property "ALL xs. rev (rev xs) = xs"; |
62020 | 13 |
\<close> |
52248
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 |
|
62020 | 16 |
section \<open>AList Specification\<close> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
17 |
|
62020 | 18 |
ML_command \<open> |
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 *) |
52260
e7c47fe56fbd
toplevel invocation via implicit ML compilation context;
wenzelm
parents:
52255
diff
changeset
|
20 |
check_property "ALL k f xs. AList.lookup (op =) (AList.map_entry (op =) k f xs) k = Option.map f (AList.lookup (op =) xs k)"; |
62020 | 21 |
\<close> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
22 |
|
62020 | 23 |
ML_command \<open> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
24 |
(* update always results in an entry *) |
52260
e7c47fe56fbd
toplevel invocation via implicit ML compilation context;
wenzelm
parents:
52255
diff
changeset
|
25 |
check_property "ALL k v xs. AList.defined (op =) (AList.update (op =) (k, v) xs) k"; |
62020 | 26 |
\<close> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
27 |
|
62020 | 28 |
ML_command \<open> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
29 |
(* update always writes the value *) |
52260
e7c47fe56fbd
toplevel invocation via implicit ML compilation context;
wenzelm
parents:
52255
diff
changeset
|
30 |
check_property "ALL k v xs. AList.lookup (op =) (AList.update (op =) (k, v) xs) k = SOME v"; |
62020 | 31 |
\<close> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
32 |
|
62020 | 33 |
ML_command \<open> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
34 |
(* default always results in an entry *) |
52260
e7c47fe56fbd
toplevel invocation via implicit ML compilation context;
wenzelm
parents:
52255
diff
changeset
|
35 |
check_property "ALL k v xs. AList.defined (op =) (AList.default (op =) (k, v) xs) k"; |
62020 | 36 |
\<close> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
37 |
|
62020 | 38 |
ML_command \<open> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
39 |
(* delete always removes the entry *) |
52260
e7c47fe56fbd
toplevel invocation via implicit ML compilation context;
wenzelm
parents:
52255
diff
changeset
|
40 |
check_property "ALL k xs. not (AList.defined (op =) (AList.delete (op =) k xs) k)"; |
62020 | 41 |
\<close> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
42 |
|
62020 | 43 |
ML_command \<open> |
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 *) |
52260
e7c47fe56fbd
toplevel invocation via implicit ML compilation context;
wenzelm
parents:
52255
diff
changeset
|
45 |
check_property "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))"; |
62020 | 46 |
\<close> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
47 |
|
62020 | 48 |
section \<open>Examples on Types and Terms\<close> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
49 |
|
62020 | 50 |
ML_command \<open> |
52260
e7c47fe56fbd
toplevel invocation via implicit ML compilation context;
wenzelm
parents:
52255
diff
changeset
|
51 |
check_property "ALL f g t. map_types (g o f) t = (map_types f o map_types g) t"; |
62020 | 52 |
\<close> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
53 |
|
62020 | 54 |
ML_command \<open> |
52260
e7c47fe56fbd
toplevel invocation via implicit ML compilation context;
wenzelm
parents:
52255
diff
changeset
|
55 |
check_property "ALL f g t. map_types (f o g) t = (map_types f o map_types g) t"; |
62020 | 56 |
\<close> |
52248
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 |
|
62020 | 59 |
text \<open>One would think this holds:\<close> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
60 |
|
62020 | 61 |
ML_command \<open> |
52260
e7c47fe56fbd
toplevel invocation via implicit ML compilation context;
wenzelm
parents:
52255
diff
changeset
|
62 |
check_property "ALL t ts. strip_comb (list_comb (t, ts)) = (t, ts)" |
62020 | 63 |
\<close> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
64 |
|
62020 | 65 |
text \<open>But it only holds with this precondition:\<close> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
66 |
|
62020 | 67 |
ML_command \<open> |
52260
e7c47fe56fbd
toplevel invocation via implicit ML compilation context;
wenzelm
parents:
52255
diff
changeset
|
68 |
check_property "ALL t ts. case t of _ $ _ => true | _ => strip_comb (list_comb (t, ts)) = (t, ts)" |
62020 | 69 |
\<close> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
70 |
|
62020 | 71 |
section \<open>Some surprises\<close> |
52248
2c893e0c1def
added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff
changeset
|
72 |
|
62020 | 73 |
ML_command \<open> |
52260
e7c47fe56fbd
toplevel invocation via implicit ML compilation context;
wenzelm
parents:
52255
diff
changeset
|
74 |
check_property "ALL Ts t. type_of1 (Ts, t) = fastype_of1 (Ts, t)" |
62020 | 75 |
\<close> |
52248
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 |
|
62020 | 78 |
ML_command \<open> |
52262
f22d227a090c
tuned -- dynamic ML context is updated incrementally (see also e7c47fe56fbd);
wenzelm
parents:
52260
diff
changeset
|
79 |
val thy = @{theory}; |
52260
e7c47fe56fbd
toplevel invocation via implicit ML compilation context;
wenzelm
parents:
52255
diff
changeset
|
80 |
check_property "ALL t u. if Pattern.matches thy (t, u) then Term.could_unify (t, u) else true" |
62020 | 81 |
\<close> |
52248
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 |