author | wenzelm |
Mon, 03 Mar 2014 13:54:47 +0100 | |
changeset 55885 | c871a2e751ec |
parent 55543 | f0ef75c6c0d8 |
child 58823 | 513268cb2178 |
permissions | -rw-r--r-- |
33265 | 1 |
(* Title: HOL/Predicate_Compile.thy |
2 |
Author: Stefan Berghofer, Lukas Bulwahn, Florian Haftmann, TU Muenchen |
|
3 |
*) |
|
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
diff
changeset
|
4 |
|
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
diff
changeset
|
5 |
header {* A compiler for predicates defined by introduction rules *} |
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
diff
changeset
|
6 |
|
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
diff
changeset
|
7 |
theory Predicate_Compile |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50055
diff
changeset
|
8 |
imports Random_Sequence Quickcheck_Exhaustive |
46950
d0181abdbdac
declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents:
46664
diff
changeset
|
9 |
keywords "code_pred" :: thy_goal and "values" :: diag |
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
diff
changeset
|
10 |
begin |
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
diff
changeset
|
11 |
|
48891 | 12 |
ML_file "Tools/Predicate_Compile/predicate_compile_aux.ML" |
13 |
ML_file "Tools/Predicate_Compile/predicate_compile_compilations.ML" |
|
14 |
ML_file "Tools/Predicate_Compile/core_data.ML" |
|
15 |
ML_file "Tools/Predicate_Compile/mode_inference.ML" |
|
16 |
ML_file "Tools/Predicate_Compile/predicate_compile_proof.ML" |
|
17 |
ML_file "Tools/Predicate_Compile/predicate_compile_core.ML" |
|
18 |
ML_file "Tools/Predicate_Compile/predicate_compile_data.ML" |
|
19 |
ML_file "Tools/Predicate_Compile/predicate_compile_fun.ML" |
|
20 |
ML_file "Tools/Predicate_Compile/predicate_compile_pred.ML" |
|
21 |
ML_file "Tools/Predicate_Compile/predicate_compile_specialisation.ML" |
|
22 |
ML_file "Tools/Predicate_Compile/predicate_compile.ML" |
|
23 |
||
33265 | 24 |
setup Predicate_Compile.setup |
33250
5c2af18a3237
including the predicate compiler in HOL-Main; added RandomPredicate monad to Quickcheck
bulwahn
parents:
diff
changeset
|
25 |
|
52023
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
26 |
subsection {* Set membership as a generator predicate *} |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
27 |
|
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
28 |
text {* |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
29 |
Introduce a new constant for membership to allow |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
30 |
fine-grained control in code equations. |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
31 |
*} |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
32 |
|
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
33 |
definition contains :: "'a set => 'a => bool" |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
34 |
where "contains A x \<longleftrightarrow> x : A" |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
35 |
|
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
36 |
definition contains_pred :: "'a set => 'a => unit Predicate.pred" |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
37 |
where "contains_pred A x = (if x : A then Predicate.single () else bot)" |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
38 |
|
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
39 |
lemma pred_of_setE: |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
40 |
assumes "Predicate.eval (pred_of_set A) x" |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
41 |
obtains "contains A x" |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
42 |
using assms by(simp add: contains_def) |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
43 |
|
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
44 |
lemma pred_of_setI: "contains A x ==> Predicate.eval (pred_of_set A) x" |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
45 |
by(simp add: contains_def) |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
46 |
|
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
47 |
lemma pred_of_set_eq: "pred_of_set \<equiv> \<lambda>A. Predicate.Pred (contains A)" |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
48 |
by(simp add: contains_def[abs_def] pred_of_set_def o_def) |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
49 |
|
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
50 |
lemma containsI: "x \<in> A ==> contains A x" |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
51 |
by(simp add: contains_def) |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
52 |
|
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
53 |
lemma containsE: assumes "contains A x" |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
54 |
obtains A' x' where "A = A'" "x = x'" "x : A" |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
55 |
using assms by(simp add: contains_def) |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
56 |
|
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
57 |
lemma contains_predI: "contains A x ==> Predicate.eval (contains_pred A x) ()" |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
58 |
by(simp add: contains_pred_def contains_def) |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
59 |
|
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
60 |
lemma contains_predE: |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
61 |
assumes "Predicate.eval (contains_pred A x) y" |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
62 |
obtains "contains A x" |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
63 |
using assms by(simp add: contains_pred_def contains_def split: split_if_asm) |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
64 |
|
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
65 |
lemma contains_pred_eq: "contains_pred \<equiv> \<lambda>A x. Predicate.Pred (\<lambda>y. contains A x)" |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
66 |
by(rule eq_reflection)(auto simp add: contains_pred_def fun_eq_iff contains_def intro: pred_eqI) |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
67 |
|
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
68 |
lemma contains_pred_notI: |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
69 |
"\<not> contains A x ==> Predicate.eval (Predicate.not_pred (contains_pred A x)) ()" |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
70 |
by(simp add: contains_pred_def contains_def not_pred_eq) |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
71 |
|
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
72 |
setup {* |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
73 |
let |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
74 |
val Fun = Predicate_Compile_Aux.Fun |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
75 |
val Input = Predicate_Compile_Aux.Input |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
76 |
val Output = Predicate_Compile_Aux.Output |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
77 |
val Bool = Predicate_Compile_Aux.Bool |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
78 |
val io = Fun (Input, Fun (Output, Bool)) |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
79 |
val ii = Fun (Input, Fun (Input, Bool)) |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
80 |
in |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
81 |
Core_Data.PredData.map (Graph.new_node |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
82 |
(@{const_name contains}, |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
83 |
Core_Data.PredData { |
55543 | 84 |
pos = Position.thread_data (), |
52023
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
85 |
intros = [(NONE, @{thm containsI})], |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
86 |
elim = SOME @{thm containsE}, |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
87 |
preprocessed = true, |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
88 |
function_names = [(Predicate_Compile_Aux.Pred, |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
89 |
[(io, @{const_name pred_of_set}), (ii, @{const_name contains_pred})])], |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
90 |
predfun_data = [ |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
91 |
(io, Core_Data.PredfunData { |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
92 |
elim = @{thm pred_of_setE}, intro = @{thm pred_of_setI}, |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
93 |
neg_intro = NONE, definition = @{thm pred_of_set_eq} |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
94 |
}), |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
95 |
(ii, Core_Data.PredfunData { |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
96 |
elim = @{thm contains_predE}, intro = @{thm contains_predI}, |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
97 |
neg_intro = SOME @{thm contains_pred_notI}, definition = @{thm contains_pred_eq} |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
98 |
})], |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
99 |
needs_random = []})) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
33265
diff
changeset
|
100 |
end |
52023
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
101 |
*} |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
102 |
|
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
103 |
hide_const (open) contains contains_pred |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
104 |
hide_fact (open) pred_of_setE pred_of_setI pred_of_set_eq |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
105 |
containsI containsE contains_predI contains_predE contains_pred_eq contains_pred_notI |
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
106 |
|
b477be38a7bb
setup for set membership as a predicate for code_pred
Andreas Lochbihler
parents:
51126
diff
changeset
|
107 |
end |