author | wenzelm |
Mon, 28 Dec 2015 01:26:34 +0100 | |
changeset 61944 | 5d06ecfdb472 |
parent 60758 | d8d85a8172b5 |
child 67091 | 1393c2340eec |
permissions | -rw-r--r-- |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
1 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
2 |
(* Author: Lukas Bulwahn, TU Muenchen *) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
3 |
|
60758 | 4 |
section \<open>Depth-Limited Sequences with failure element\<close> |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
5 |
|
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
6 |
theory Limited_Sequence |
50055 | 7 |
imports Lazy_Sequence |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
8 |
begin |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
9 |
|
60758 | 10 |
subsection \<open>Depth-Limited Sequence\<close> |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
11 |
|
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
51126
diff
changeset
|
12 |
type_synonym 'a dseq = "natural \<Rightarrow> bool \<Rightarrow> 'a lazy_sequence option" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
13 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
14 |
definition empty :: "'a dseq" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
15 |
where |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
16 |
"empty = (\<lambda>_ _. Some Lazy_Sequence.empty)" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
17 |
|
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
18 |
definition single :: "'a \<Rightarrow> 'a dseq" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
19 |
where |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
20 |
"single x = (\<lambda>_ _. Some (Lazy_Sequence.single x))" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
21 |
|
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
51126
diff
changeset
|
22 |
definition eval :: "'a dseq \<Rightarrow> natural \<Rightarrow> bool \<Rightarrow> 'a lazy_sequence option" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
23 |
where |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
24 |
[simp]: "eval f i pol = f i pol" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
25 |
|
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
51126
diff
changeset
|
26 |
definition yield :: "'a dseq \<Rightarrow> natural \<Rightarrow> bool \<Rightarrow> ('a \<times> 'a dseq) option" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
27 |
where |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
28 |
"yield f i pol = (case eval f i pol of |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
29 |
None \<Rightarrow> None |
55466 | 30 |
| Some s \<Rightarrow> (map_option \<circ> apsnd) (\<lambda>r _ _. Some r) (Lazy_Sequence.yield s))" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
31 |
|
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
32 |
definition map_seq :: "('a \<Rightarrow> 'b dseq) \<Rightarrow> 'a lazy_sequence \<Rightarrow> 'b dseq" |
50092 | 33 |
where |
55466 | 34 |
"map_seq f xq i pol = map_option Lazy_Sequence.flat |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
35 |
(Lazy_Sequence.those (Lazy_Sequence.map (\<lambda>x. f x i pol) xq))" |
50092 | 36 |
|
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
37 |
lemma map_seq_code [code]: |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
38 |
"map_seq f xq i pol = (case Lazy_Sequence.yield xq of |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
39 |
None \<Rightarrow> Some Lazy_Sequence.empty |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
40 |
| Some (x, xq') \<Rightarrow> (case eval (f x) i pol of |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
41 |
None \<Rightarrow> None |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
42 |
| Some yq \<Rightarrow> (case map_seq f xq' i pol of |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
43 |
None \<Rightarrow> None |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
44 |
| Some zq \<Rightarrow> Some (Lazy_Sequence.append yq zq))))" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
45 |
by (cases xq) |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
46 |
(auto simp add: map_seq_def Lazy_Sequence.those_def lazy_sequence_eq_iff split: list.splits option.splits) |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
47 |
|
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
48 |
definition bind :: "'a dseq \<Rightarrow> ('a \<Rightarrow> 'b dseq) \<Rightarrow> 'b dseq" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
49 |
where |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
50 |
"bind x f = (\<lambda>i pol. |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
51 |
if i = 0 then |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
52 |
(if pol then Some Lazy_Sequence.empty else None) |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
53 |
else |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
54 |
(case x (i - 1) pol of |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
55 |
None \<Rightarrow> None |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
56 |
| Some xq \<Rightarrow> map_seq f xq i pol))" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
57 |
|
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
58 |
definition union :: "'a dseq \<Rightarrow> 'a dseq \<Rightarrow> 'a dseq" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
59 |
where |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
60 |
"union x y = (\<lambda>i pol. case (x i pol, y i pol) of |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
61 |
(Some xq, Some yq) \<Rightarrow> Some (Lazy_Sequence.append xq yq) |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
62 |
| _ \<Rightarrow> None)" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
63 |
|
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
64 |
definition if_seq :: "bool \<Rightarrow> unit dseq" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
65 |
where |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
66 |
"if_seq b = (if b then single () else empty)" |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
67 |
|
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
68 |
definition not_seq :: "unit dseq \<Rightarrow> unit dseq" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
69 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
70 |
"not_seq x = (\<lambda>i pol. case x i (\<not> pol) of |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
71 |
None \<Rightarrow> Some Lazy_Sequence.empty |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
72 |
| Some xq \<Rightarrow> (case Lazy_Sequence.yield xq of |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
73 |
None \<Rightarrow> Some (Lazy_Sequence.single ()) |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
74 |
| Some _ \<Rightarrow> Some (Lazy_Sequence.empty)))" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
75 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
76 |
definition map :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a dseq \<Rightarrow> 'b dseq" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
77 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
78 |
"map f g = (\<lambda>i pol. case g i pol of |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
79 |
None \<Rightarrow> None |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
80 |
| Some xq \<Rightarrow> Some (Lazy_Sequence.map f xq))" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
81 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
82 |
|
60758 | 83 |
subsection \<open>Positive Depth-Limited Sequence\<close> |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
84 |
|
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
51126
diff
changeset
|
85 |
type_synonym 'a pos_dseq = "natural \<Rightarrow> 'a Lazy_Sequence.lazy_sequence" |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
86 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
87 |
definition pos_empty :: "'a pos_dseq" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
88 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
89 |
"pos_empty = (\<lambda>i. Lazy_Sequence.empty)" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
90 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
91 |
definition pos_single :: "'a \<Rightarrow> 'a pos_dseq" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
92 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
93 |
"pos_single x = (\<lambda>i. Lazy_Sequence.single x)" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
94 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
95 |
definition pos_bind :: "'a pos_dseq \<Rightarrow> ('a \<Rightarrow> 'b pos_dseq) \<Rightarrow> 'b pos_dseq" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
96 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
97 |
"pos_bind x f = (\<lambda>i. Lazy_Sequence.bind (x i) (\<lambda>a. f a i))" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
98 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
99 |
definition pos_decr_bind :: "'a pos_dseq \<Rightarrow> ('a \<Rightarrow> 'b pos_dseq) \<Rightarrow> 'b pos_dseq" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
100 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
101 |
"pos_decr_bind x f = (\<lambda>i. |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
102 |
if i = 0 then |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
103 |
Lazy_Sequence.empty |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
104 |
else |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
105 |
Lazy_Sequence.bind (x (i - 1)) (\<lambda>a. f a i))" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
106 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
107 |
definition pos_union :: "'a pos_dseq \<Rightarrow> 'a pos_dseq \<Rightarrow> 'a pos_dseq" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
108 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
109 |
"pos_union xq yq = (\<lambda>i. Lazy_Sequence.append (xq i) (yq i))" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
110 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
111 |
definition pos_if_seq :: "bool \<Rightarrow> unit pos_dseq" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
112 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
113 |
"pos_if_seq b = (if b then pos_single () else pos_empty)" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
114 |
|
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
51126
diff
changeset
|
115 |
definition pos_iterate_upto :: "(natural \<Rightarrow> 'a) \<Rightarrow> natural \<Rightarrow> natural \<Rightarrow> 'a pos_dseq" |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
116 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
117 |
"pos_iterate_upto f n m = (\<lambda>i. Lazy_Sequence.iterate_upto f n m)" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
118 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
119 |
definition pos_map :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a pos_dseq \<Rightarrow> 'b pos_dseq" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
120 |
where |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
121 |
"pos_map f xq = (\<lambda>i. Lazy_Sequence.map f (xq i))" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
122 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
123 |
|
60758 | 124 |
subsection \<open>Negative Depth-Limited Sequence\<close> |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
125 |
|
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
51126
diff
changeset
|
126 |
type_synonym 'a neg_dseq = "natural \<Rightarrow> 'a Lazy_Sequence.hit_bound_lazy_sequence" |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
127 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
128 |
definition neg_empty :: "'a neg_dseq" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
129 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
130 |
"neg_empty = (\<lambda>i. Lazy_Sequence.empty)" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
131 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
132 |
definition neg_single :: "'a \<Rightarrow> 'a neg_dseq" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
133 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
134 |
"neg_single x = (\<lambda>i. Lazy_Sequence.hb_single x)" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
135 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
136 |
definition neg_bind :: "'a neg_dseq \<Rightarrow> ('a \<Rightarrow> 'b neg_dseq) \<Rightarrow> 'b neg_dseq" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
137 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
138 |
"neg_bind x f = (\<lambda>i. hb_bind (x i) (\<lambda>a. f a i))" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
139 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
140 |
definition neg_decr_bind :: "'a neg_dseq \<Rightarrow> ('a \<Rightarrow> 'b neg_dseq) \<Rightarrow> 'b neg_dseq" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
141 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
142 |
"neg_decr_bind x f = (\<lambda>i. |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
143 |
if i = 0 then |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
144 |
Lazy_Sequence.hit_bound |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
145 |
else |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
146 |
hb_bind (x (i - 1)) (\<lambda>a. f a i))" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
147 |
|
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
148 |
definition neg_union :: "'a neg_dseq \<Rightarrow> 'a neg_dseq \<Rightarrow> 'a neg_dseq" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
149 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
150 |
"neg_union x y = (\<lambda>i. Lazy_Sequence.append (x i) (y i))" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
151 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
152 |
definition neg_if_seq :: "bool \<Rightarrow> unit neg_dseq" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
153 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
154 |
"neg_if_seq b = (if b then neg_single () else neg_empty)" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
155 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
156 |
definition neg_iterate_upto |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
157 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
158 |
"neg_iterate_upto f n m = (\<lambda>i. Lazy_Sequence.iterate_upto (\<lambda>i. Some (f i)) n m)" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
159 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
160 |
definition neg_map :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a neg_dseq \<Rightarrow> 'b neg_dseq" |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
161 |
where |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
162 |
"neg_map f xq = (\<lambda>i. Lazy_Sequence.hb_map f (xq i))" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
163 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
164 |
|
60758 | 165 |
subsection \<open>Negation\<close> |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
166 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
167 |
definition pos_not_seq :: "unit neg_dseq \<Rightarrow> unit pos_dseq" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
168 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
169 |
"pos_not_seq xq = (\<lambda>i. Lazy_Sequence.hb_not_seq (xq (3 * i)))" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
170 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
171 |
definition neg_not_seq :: "unit pos_dseq \<Rightarrow> unit neg_dseq" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
172 |
where |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
173 |
"neg_not_seq x = (\<lambda>i. case Lazy_Sequence.yield (x i) of |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
174 |
None => Lazy_Sequence.hb_single () |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
175 |
| Some ((), xq) => Lazy_Sequence.empty)" |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
176 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
177 |
|
60758 | 178 |
ML \<open> |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
179 |
signature LIMITED_SEQUENCE = |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
180 |
sig |
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
51126
diff
changeset
|
181 |
type 'a dseq = Code_Numeral.natural -> bool -> 'a Lazy_Sequence.lazy_sequence option |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
182 |
val map : ('a -> 'b) -> 'a dseq -> 'b dseq |
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
51126
diff
changeset
|
183 |
val yield : 'a dseq -> Code_Numeral.natural -> bool -> ('a * 'a dseq) option |
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
51126
diff
changeset
|
184 |
val yieldn : int -> 'a dseq -> Code_Numeral.natural -> bool -> 'a list * 'a dseq |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
185 |
end; |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
186 |
|
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
187 |
structure Limited_Sequence : LIMITED_SEQUENCE = |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
188 |
struct |
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
189 |
|
51143
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
haftmann
parents:
51126
diff
changeset
|
190 |
type 'a dseq = Code_Numeral.natural -> bool -> 'a Lazy_Sequence.lazy_sequence option |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
191 |
|
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
192 |
fun map f = @{code Limited_Sequence.map} f; |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
193 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
194 |
fun yield f = @{code Limited_Sequence.yield} f; |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
195 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
196 |
fun yieldn n f i pol = (case f i pol of |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
197 |
NONE => ([], fn _ => fn _ => NONE) |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
198 |
| SOME s => let val (xs, s') = Lazy_Sequence.yieldn n s in (xs, fn _ => fn _ => SOME s') end); |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
199 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
200 |
end; |
60758 | 201 |
\<close> |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
202 |
|
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
203 |
code_reserved Eval Limited_Sequence |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
204 |
|
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
205 |
|
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
206 |
hide_const (open) yield empty single eval map_seq bind union if_seq not_seq map |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
207 |
pos_empty pos_single pos_bind pos_decr_bind pos_union pos_if_seq pos_iterate_upto pos_not_seq pos_map |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
208 |
neg_empty neg_single neg_bind neg_decr_bind neg_union neg_if_seq neg_iterate_upto neg_not_seq neg_map |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
209 |
|
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
210 |
hide_fact (open) yield_def empty_def single_def eval_def map_seq_def bind_def union_def |
34953 | 211 |
if_seq_def not_seq_def map_def |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
212 |
pos_empty_def pos_single_def pos_bind_def pos_union_def pos_if_seq_def pos_iterate_upto_def pos_not_seq_def pos_map_def |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
50092
diff
changeset
|
213 |
neg_empty_def neg_single_def neg_bind_def neg_union_def neg_if_seq_def neg_iterate_upto_def neg_not_seq_def neg_map_def |
34948
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
214 |
|
2d5f2a9f7601
refactoring the predicate compiler; adding theories for Sequences; adding retrieval to Spec_Rules; adding timing to Quickcheck
bulwahn
parents:
diff
changeset
|
215 |
end |
50092 | 216 |