src/Tools/Spec_Check/Examples.thy
author wenzelm
Mon, 25 Mar 2019 17:21:26 +0100
changeset 69981 3dced198b9ec
parent 69593 3dda49e08b9d
permissions -rw-r--r--
more strict AFP properties;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
     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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
     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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
     9
\<close>
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    10
62020
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    21
\<close>
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    22
62020
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    26
\<close>
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    27
62020
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    31
\<close>
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    32
62020
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    36
\<close>
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    37
62020
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    41
\<close>
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    42
62020
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    46
\<close>
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    47
62020
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    52
\<close>
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    53
62020
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    63
\<close>
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    64
62020
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    69
\<close>
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    70
62020
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    78
ML_command \<open>
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 62020
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
5d208fd2507d isabelle update_cartouches -c -t;
wenzelm
parents: 53164
diff changeset
    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