author | haftmann |
Sun, 19 Feb 2012 15:30:35 +0100 | |
changeset 46553 | 50a7e97fe653 |
parent 46191 | a88546428c2a |
child 46557 | ae926869a311 |
permissions | -rw-r--r-- |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
1 |
(* Title: HOL/Predicate.thy |
30328 | 2 |
Author: Stefan Berghofer and Lukas Bulwahn and Florian Haftmann, TU Muenchen |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
3 |
*) |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
4 |
|
30328 | 5 |
header {* Predicates as relations and enumerations *} |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
6 |
|
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
7 |
theory Predicate |
23708 | 8 |
imports Inductive Relation |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
9 |
begin |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
10 |
|
30328 | 11 |
notation |
41082 | 12 |
bot ("\<bottom>") and |
13 |
top ("\<top>") and |
|
30328 | 14 |
inf (infixl "\<sqinter>" 70) and |
15 |
sup (infixl "\<squnion>" 65) and |
|
16 |
Inf ("\<Sqinter>_" [900] 900) and |
|
41082 | 17 |
Sup ("\<Squnion>_" [900] 900) |
30328 | 18 |
|
41080 | 19 |
syntax (xsymbols) |
41082 | 20 |
"_INF1" :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Sqinter>_./ _)" [0, 10] 10) |
21 |
"_INF" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Sqinter>_\<in>_./ _)" [0, 0, 10] 10) |
|
41080 | 22 |
"_SUP1" :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Squnion>_./ _)" [0, 10] 10) |
23 |
"_SUP" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Squnion>_\<in>_./ _)" [0, 0, 10] 10) |
|
24 |
||
30328 | 25 |
|
26 |
subsection {* Predicates as (complete) lattices *} |
|
27 |
||
32779 | 28 |
subsubsection {* Equality *} |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
29 |
|
46175
48c534b22040
Declared pred_equals/subset_eq, sup_Un_eq and SUP_UN_eq(2) as pred_set_conv rules
berghofe
parents:
46038
diff
changeset
|
30 |
lemma pred_equals_eq [pred_set_conv]: "((\<lambda>x. x \<in> R) = (\<lambda>x. x \<in> S)) \<longleftrightarrow> (R = S)" |
45970
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
haftmann
parents:
45630
diff
changeset
|
31 |
by (simp add: set_eq_iff fun_eq_iff) |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
32 |
|
44415 | 33 |
lemma pred_equals_eq2 [pred_set_conv]: "((\<lambda>x y. (x, y) \<in> R) = (\<lambda>x y. (x, y) \<in> S)) \<longleftrightarrow> (R = S)" |
45970
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
haftmann
parents:
45630
diff
changeset
|
34 |
by (simp add: set_eq_iff fun_eq_iff) |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
35 |
|
32779 | 36 |
|
37 |
subsubsection {* Order relation *} |
|
38 |
||
46175
48c534b22040
Declared pred_equals/subset_eq, sup_Un_eq and SUP_UN_eq(2) as pred_set_conv rules
berghofe
parents:
46038
diff
changeset
|
39 |
lemma pred_subset_eq [pred_set_conv]: "((\<lambda>x. x \<in> R) \<le> (\<lambda>x. x \<in> S)) \<longleftrightarrow> (R \<subseteq> S)" |
45970
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
haftmann
parents:
45630
diff
changeset
|
40 |
by (simp add: subset_iff le_fun_def) |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
41 |
|
44415 | 42 |
lemma pred_subset_eq2 [pred_set_conv]: "((\<lambda>x y. (x, y) \<in> R) \<le> (\<lambda>x y. (x, y) \<in> S)) \<longleftrightarrow> (R \<subseteq> S)" |
45970
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
haftmann
parents:
45630
diff
changeset
|
43 |
by (simp add: subset_iff le_fun_def) |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
44 |
|
23741
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
45 |
|
30328 | 46 |
subsubsection {* Top and bottom elements *} |
23741
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
47 |
|
44414 | 48 |
lemma bot_empty_eq: "\<bottom> = (\<lambda>x. x \<in> {})" |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
49 |
by (auto simp add: fun_eq_iff) |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
50 |
|
44414 | 51 |
lemma bot_empty_eq2: "\<bottom> = (\<lambda>x y. (x, y) \<in> {})" |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
52 |
by (auto simp add: fun_eq_iff) |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
53 |
|
41082 | 54 |
|
55 |
subsubsection {* Binary intersection *} |
|
56 |
||
46191
a88546428c2a
Added inf_Int_eq to pred_set_conv database as well
berghofe
parents:
46175
diff
changeset
|
57 |
lemma inf_Int_eq [pred_set_conv]: "(\<lambda>x. x \<in> R) \<sqinter> (\<lambda>x. x \<in> S) = (\<lambda>x. x \<in> R \<inter> S)" |
45970
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
haftmann
parents:
45630
diff
changeset
|
58 |
by (simp add: inf_fun_def) |
41082 | 59 |
|
44414 | 60 |
lemma inf_Int_eq2 [pred_set_conv]: "(\<lambda>x y. (x, y) \<in> R) \<sqinter> (\<lambda>x y. (x, y) \<in> S) = (\<lambda>x y. (x, y) \<in> R \<inter> S)" |
45970
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
haftmann
parents:
45630
diff
changeset
|
61 |
by (simp add: inf_fun_def) |
41082 | 62 |
|
23741
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
63 |
|
30328 | 64 |
subsubsection {* Binary union *} |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
65 |
|
46175
48c534b22040
Declared pred_equals/subset_eq, sup_Un_eq and SUP_UN_eq(2) as pred_set_conv rules
berghofe
parents:
46038
diff
changeset
|
66 |
lemma sup_Un_eq [pred_set_conv]: "(\<lambda>x. x \<in> R) \<squnion> (\<lambda>x. x \<in> S) = (\<lambda>x. x \<in> R \<union> S)" |
45970
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
haftmann
parents:
45630
diff
changeset
|
67 |
by (simp add: sup_fun_def) |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
68 |
|
44414 | 69 |
lemma sup_Un_eq2 [pred_set_conv]: "(\<lambda>x y. (x, y) \<in> R) \<squnion> (\<lambda>x y. (x, y) \<in> S) = (\<lambda>x y. (x, y) \<in> R \<union> S)" |
45970
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
haftmann
parents:
45630
diff
changeset
|
70 |
by (simp add: sup_fun_def) |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
71 |
|
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
72 |
|
30328 | 73 |
subsubsection {* Intersections of families *} |
22430
6a56bf1b3a64
Generalized version of SUP and INF (with index set).
berghofe
parents:
22422
diff
changeset
|
74 |
|
46553
50a7e97fe653
distributed lattice properties of predicates to places of instantiation
haftmann
parents:
46191
diff
changeset
|
75 |
lemma INF_INT_eq: "(\<Sqinter>i. (\<lambda>x. x \<in> r i)) = (\<lambda>x. x \<in> (\<Inter>i. r i))" |
44928
7ef6505bde7f
renamed Complete_Lattices lemmas, removed legacy names
hoelzl
parents:
44415
diff
changeset
|
76 |
by (simp add: INF_apply fun_eq_iff) |
23741
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
77 |
|
46553
50a7e97fe653
distributed lattice properties of predicates to places of instantiation
haftmann
parents:
46191
diff
changeset
|
78 |
lemma INF_INT_eq2: "(\<Sqinter>i. (\<lambda>x y. (x, y) \<in> r i)) = (\<lambda>x y. (x, y) \<in> (\<Inter>i. r i))" |
44928
7ef6505bde7f
renamed Complete_Lattices lemmas, removed legacy names
hoelzl
parents:
44415
diff
changeset
|
79 |
by (simp add: INF_apply fun_eq_iff) |
23741
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
80 |
|
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
81 |
|
41082 | 82 |
subsubsection {* Unions of families *} |
83 |
||
46175
48c534b22040
Declared pred_equals/subset_eq, sup_Un_eq and SUP_UN_eq(2) as pred_set_conv rules
berghofe
parents:
46038
diff
changeset
|
84 |
lemma SUP_UN_eq [pred_set_conv]: "(\<Squnion>i. (\<lambda>x. x \<in> r i)) = (\<lambda>x. x \<in> (\<Union>i. r i))" |
44928
7ef6505bde7f
renamed Complete_Lattices lemmas, removed legacy names
hoelzl
parents:
44415
diff
changeset
|
85 |
by (simp add: SUP_apply fun_eq_iff) |
41082 | 86 |
|
46175
48c534b22040
Declared pred_equals/subset_eq, sup_Un_eq and SUP_UN_eq(2) as pred_set_conv rules
berghofe
parents:
46038
diff
changeset
|
87 |
lemma SUP_UN_eq2 [pred_set_conv]: "(\<Squnion>i. (\<lambda>x y. (x, y) \<in> r i)) = (\<lambda>x y. (x, y) \<in> (\<Union>i. r i))" |
44928
7ef6505bde7f
renamed Complete_Lattices lemmas, removed legacy names
hoelzl
parents:
44415
diff
changeset
|
88 |
by (simp add: SUP_apply fun_eq_iff) |
41082 | 89 |
|
90 |
||
30328 | 91 |
subsection {* Predicates as relations *} |
92 |
||
93 |
subsubsection {* Composition *} |
|
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
94 |
|
44414 | 95 |
inductive pred_comp :: "['a \<Rightarrow> 'b \<Rightarrow> bool, 'b \<Rightarrow> 'c \<Rightarrow> bool] \<Rightarrow> 'a \<Rightarrow> 'c \<Rightarrow> bool" (infixr "OO" 75) |
96 |
for r :: "'a \<Rightarrow> 'b \<Rightarrow> bool" and s :: "'b \<Rightarrow> 'c \<Rightarrow> bool" where |
|
97 |
pred_compI [intro]: "r a b \<Longrightarrow> s b c \<Longrightarrow> (r OO s) a c" |
|
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
98 |
|
23741
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
99 |
inductive_cases pred_compE [elim!]: "(r OO s) a c" |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
100 |
|
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
101 |
lemma pred_comp_rel_comp_eq [pred_set_conv]: |
23741
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
102 |
"((\<lambda>x y. (x, y) \<in> r) OO (\<lambda>x y. (x, y) \<in> s)) = (\<lambda>x y. (x, y) \<in> r O s)" |
41550 | 103 |
by (auto simp add: fun_eq_iff) |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
104 |
|
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
105 |
|
30328 | 106 |
subsubsection {* Converse *} |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
107 |
|
44414 | 108 |
inductive conversep :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> bool" ("(_^--1)" [1000] 1000) |
109 |
for r :: "'a \<Rightarrow> 'b \<Rightarrow> bool" where |
|
110 |
conversepI: "r a b \<Longrightarrow> r^--1 b a" |
|
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
111 |
|
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
112 |
notation (xsymbols) |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
113 |
conversep ("(_\<inverse>\<inverse>)" [1000] 1000) |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
114 |
|
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
115 |
lemma conversepD: |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
116 |
assumes ab: "r^--1 a b" |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
117 |
shows "r b a" using ab |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
118 |
by cases simp |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
119 |
|
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
120 |
lemma conversep_iff [iff]: "r^--1 a b = r b a" |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
121 |
by (iprover intro: conversepI dest: conversepD) |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
122 |
|
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
123 |
lemma conversep_converse_eq [pred_set_conv]: |
23741
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
124 |
"(\<lambda>x y. (x, y) \<in> r)^--1 = (\<lambda>x y. (x, y) \<in> r^-1)" |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
125 |
by (auto simp add: fun_eq_iff) |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
126 |
|
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
127 |
lemma conversep_conversep [simp]: "(r^--1)^--1 = r" |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
128 |
by (iprover intro: order_antisym conversepI dest: conversepD) |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
129 |
|
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
130 |
lemma converse_pred_comp: "(r OO s)^--1 = s^--1 OO r^--1" |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
131 |
by (iprover intro: order_antisym conversepI pred_compI |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
132 |
elim: pred_compE dest: conversepD) |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
133 |
|
44414 | 134 |
lemma converse_meet: "(r \<sqinter> s)^--1 = r^--1 \<sqinter> s^--1" |
41550 | 135 |
by (simp add: inf_fun_def) (iprover intro: conversepI ext dest: conversepD) |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
136 |
|
44414 | 137 |
lemma converse_join: "(r \<squnion> s)^--1 = r^--1 \<squnion> s^--1" |
41550 | 138 |
by (simp add: sup_fun_def) (iprover intro: conversepI ext dest: conversepD) |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
139 |
|
44414 | 140 |
lemma conversep_noteq [simp]: "(op \<noteq>)^--1 = op \<noteq>" |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
141 |
by (auto simp add: fun_eq_iff) |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
142 |
|
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
143 |
lemma conversep_eq [simp]: "(op =)^--1 = op =" |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
144 |
by (auto simp add: fun_eq_iff) |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
145 |
|
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
146 |
|
30328 | 147 |
subsubsection {* Domain *} |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
148 |
|
44414 | 149 |
inductive DomainP :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> bool" |
150 |
for r :: "'a \<Rightarrow> 'b \<Rightarrow> bool" where |
|
151 |
DomainPI [intro]: "r a b \<Longrightarrow> DomainP r a" |
|
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
152 |
|
23741
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
153 |
inductive_cases DomainPE [elim!]: "DomainP r a" |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
154 |
|
23741
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
155 |
lemma DomainP_Domain_eq [pred_set_conv]: "DomainP (\<lambda>x y. (x, y) \<in> r) = (\<lambda>x. x \<in> Domain r)" |
26797
a6cb51c314f2
- Added mem_def and predicate1I in some of the proofs
berghofe
parents:
24345
diff
changeset
|
156 |
by (blast intro!: Orderings.order_antisym predicate1I) |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
157 |
|
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
158 |
|
30328 | 159 |
subsubsection {* Range *} |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
160 |
|
44414 | 161 |
inductive RangeP :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'b \<Rightarrow> bool" |
162 |
for r :: "'a \<Rightarrow> 'b \<Rightarrow> bool" where |
|
163 |
RangePI [intro]: "r a b \<Longrightarrow> RangeP r b" |
|
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
164 |
|
23741
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
165 |
inductive_cases RangePE [elim!]: "RangeP r b" |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
166 |
|
23741
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
167 |
lemma RangeP_Range_eq [pred_set_conv]: "RangeP (\<lambda>x y. (x, y) \<in> r) = (\<lambda>x. x \<in> Range r)" |
26797
a6cb51c314f2
- Added mem_def and predicate1I in some of the proofs
berghofe
parents:
24345
diff
changeset
|
168 |
by (blast intro!: Orderings.order_antisym predicate1I) |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
169 |
|
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
170 |
|
30328 | 171 |
subsubsection {* Inverse image *} |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
172 |
|
44414 | 173 |
definition inv_imagep :: "('b \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" where |
174 |
"inv_imagep r f = (\<lambda>x y. r (f x) (f y))" |
|
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
175 |
|
23741
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
176 |
lemma [pred_set_conv]: "inv_imagep (\<lambda>x y. (x, y) \<in> r) f = (\<lambda>x y. (x, y) \<in> inv_image r f)" |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
177 |
by (simp add: inv_image_def inv_imagep_def) |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
178 |
|
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
179 |
lemma in_inv_imagep [simp]: "inv_imagep r f x y = r (f x) (f y)" |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
180 |
by (simp add: inv_imagep_def) |
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
181 |
|
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
182 |
|
30328 | 183 |
subsubsection {* Powerset *} |
23741
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
184 |
|
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
185 |
definition Powp :: "('a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> bool" where |
44414 | 186 |
"Powp A = (\<lambda>B. \<forall>x \<in> B. A x)" |
23741
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
187 |
|
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
188 |
lemma Powp_Pow_eq [pred_set_conv]: "Powp (\<lambda>x. x \<in> A) = (\<lambda>x. x \<in> Pow A)" |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
189 |
by (auto simp add: Powp_def fun_eq_iff) |
23741
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
190 |
|
46175
48c534b22040
Declared pred_equals/subset_eq, sup_Un_eq and SUP_UN_eq(2) as pred_set_conv rules
berghofe
parents:
46038
diff
changeset
|
191 |
lemmas Powp_mono [mono] = Pow_mono [to_pred] |
26797
a6cb51c314f2
- Added mem_def and predicate1I in some of the proofs
berghofe
parents:
24345
diff
changeset
|
192 |
|
23741
1801a921df13
- Moved infrastructure for converting between sets and predicates
berghofe
parents:
23708
diff
changeset
|
193 |
|
30328 | 194 |
subsubsection {* Properties of relations *} |
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
195 |
|
44414 | 196 |
abbreviation antisymP :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where |
197 |
"antisymP r \<equiv> antisym {(x, y). r x y}" |
|
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
198 |
|
44414 | 199 |
abbreviation transP :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where |
200 |
"transP r \<equiv> trans {(x, y). r x y}" |
|
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
201 |
|
44414 | 202 |
abbreviation single_valuedP :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> bool" where |
203 |
"single_valuedP r \<equiv> single_valued {(x, y). r x y}" |
|
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
204 |
|
40813
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
205 |
(*FIXME inconsistencies: abbreviations vs. definitions, suffix `P` vs. suffix `p`*) |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
206 |
|
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
207 |
definition reflp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
208 |
"reflp r \<longleftrightarrow> refl {(x, y). r x y}" |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
209 |
|
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
210 |
definition symp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
211 |
"symp r \<longleftrightarrow> sym {(x, y). r x y}" |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
212 |
|
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
213 |
definition transp :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool" where |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
214 |
"transp r \<longleftrightarrow> trans {(x, y). r x y}" |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
215 |
|
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
216 |
lemma reflpI: |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
217 |
"(\<And>x. r x x) \<Longrightarrow> reflp r" |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
218 |
by (auto intro: refl_onI simp add: reflp_def) |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
219 |
|
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
220 |
lemma reflpE: |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
221 |
assumes "reflp r" |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
222 |
obtains "r x x" |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
223 |
using assms by (auto dest: refl_onD simp add: reflp_def) |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
224 |
|
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
225 |
lemma sympI: |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
226 |
"(\<And>x y. r x y \<Longrightarrow> r y x) \<Longrightarrow> symp r" |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
227 |
by (auto intro: symI simp add: symp_def) |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
228 |
|
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
229 |
lemma sympE: |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
230 |
assumes "symp r" and "r x y" |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
231 |
obtains "r y x" |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
232 |
using assms by (auto dest: symD simp add: symp_def) |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
233 |
|
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
234 |
lemma transpI: |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
235 |
"(\<And>x y z. r x y \<Longrightarrow> r y z \<Longrightarrow> r x z) \<Longrightarrow> transp r" |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
236 |
by (auto intro: transI simp add: transp_def) |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
237 |
|
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
238 |
lemma transpE: |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
239 |
assumes "transp r" and "r x y" and "r y z" |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
240 |
obtains "r x z" |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
241 |
using assms by (auto dest: transD simp add: transp_def) |
f1fc2a1547eb
moved generic definitions about relations from Quotient.thy to Predicate;
haftmann
parents:
40674
diff
changeset
|
242 |
|
30328 | 243 |
|
244 |
subsection {* Predicates as enumerations *} |
|
245 |
||
246 |
subsubsection {* The type of predicate enumerations (a monad) *} |
|
247 |
||
248 |
datatype 'a pred = Pred "'a \<Rightarrow> bool" |
|
249 |
||
250 |
primrec eval :: "'a pred \<Rightarrow> 'a \<Rightarrow> bool" where |
|
251 |
eval_pred: "eval (Pred f) = f" |
|
252 |
||
253 |
lemma Pred_eval [simp]: |
|
254 |
"Pred (eval x) = x" |
|
255 |
by (cases x) simp |
|
256 |
||
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
257 |
lemma pred_eqI: |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
258 |
"(\<And>w. eval P w \<longleftrightarrow> eval Q w) \<Longrightarrow> P = Q" |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
259 |
by (cases P, cases Q) (auto simp add: fun_eq_iff) |
30328 | 260 |
|
46038
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
261 |
lemma pred_eq_iff: |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
262 |
"P = Q \<Longrightarrow> (\<And>w. eval P w \<longleftrightarrow> eval Q w)" |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
263 |
by (simp add: pred_eqI) |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
264 |
|
44033 | 265 |
instantiation pred :: (type) complete_lattice |
30328 | 266 |
begin |
267 |
||
268 |
definition |
|
269 |
"P \<le> Q \<longleftrightarrow> eval P \<le> eval Q" |
|
270 |
||
271 |
definition |
|
272 |
"P < Q \<longleftrightarrow> eval P < eval Q" |
|
273 |
||
274 |
definition |
|
275 |
"\<bottom> = Pred \<bottom>" |
|
276 |
||
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
277 |
lemma eval_bot [simp]: |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
278 |
"eval \<bottom> = \<bottom>" |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
279 |
by (simp add: bot_pred_def) |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
280 |
|
30328 | 281 |
definition |
282 |
"\<top> = Pred \<top>" |
|
283 |
||
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
284 |
lemma eval_top [simp]: |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
285 |
"eval \<top> = \<top>" |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
286 |
by (simp add: top_pred_def) |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
287 |
|
30328 | 288 |
definition |
289 |
"P \<sqinter> Q = Pred (eval P \<sqinter> eval Q)" |
|
290 |
||
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
291 |
lemma eval_inf [simp]: |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
292 |
"eval (P \<sqinter> Q) = eval P \<sqinter> eval Q" |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
293 |
by (simp add: inf_pred_def) |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
294 |
|
30328 | 295 |
definition |
296 |
"P \<squnion> Q = Pred (eval P \<squnion> eval Q)" |
|
297 |
||
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
298 |
lemma eval_sup [simp]: |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
299 |
"eval (P \<squnion> Q) = eval P \<squnion> eval Q" |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
300 |
by (simp add: sup_pred_def) |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
301 |
|
30328 | 302 |
definition |
37767 | 303 |
"\<Sqinter>A = Pred (INFI A eval)" |
30328 | 304 |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
305 |
lemma eval_Inf [simp]: |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
306 |
"eval (\<Sqinter>A) = INFI A eval" |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
307 |
by (simp add: Inf_pred_def) |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
308 |
|
30328 | 309 |
definition |
37767 | 310 |
"\<Squnion>A = Pred (SUPR A eval)" |
30328 | 311 |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
312 |
lemma eval_Sup [simp]: |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
313 |
"eval (\<Squnion>A) = SUPR A eval" |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
314 |
by (simp add: Sup_pred_def) |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
315 |
|
44033 | 316 |
instance proof |
44415 | 317 |
qed (auto intro!: pred_eqI simp add: less_eq_pred_def less_pred_def le_fun_def less_fun_def) |
44033 | 318 |
|
319 |
end |
|
320 |
||
321 |
lemma eval_INFI [simp]: |
|
322 |
"eval (INFI A f) = INFI A (eval \<circ> f)" |
|
44928
7ef6505bde7f
renamed Complete_Lattices lemmas, removed legacy names
hoelzl
parents:
44415
diff
changeset
|
323 |
by (simp only: INF_def eval_Inf image_compose) |
44033 | 324 |
|
325 |
lemma eval_SUPR [simp]: |
|
326 |
"eval (SUPR A f) = SUPR A (eval \<circ> f)" |
|
44928
7ef6505bde7f
renamed Complete_Lattices lemmas, removed legacy names
hoelzl
parents:
44415
diff
changeset
|
327 |
by (simp only: SUP_def eval_Sup image_compose) |
44033 | 328 |
|
329 |
instantiation pred :: (type) complete_boolean_algebra |
|
330 |
begin |
|
331 |
||
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
332 |
definition |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
333 |
"- P = Pred (- eval P)" |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
334 |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
335 |
lemma eval_compl [simp]: |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
336 |
"eval (- P) = - eval P" |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
337 |
by (simp add: uminus_pred_def) |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
338 |
|
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
339 |
definition |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
340 |
"P - Q = Pred (eval P - eval Q)" |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
341 |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
342 |
lemma eval_minus [simp]: |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
343 |
"eval (P - Q) = eval P - eval Q" |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
344 |
by (simp add: minus_pred_def) |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
345 |
|
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
346 |
instance proof |
44415 | 347 |
qed (auto intro!: pred_eqI simp add: uminus_apply minus_apply INF_apply SUP_apply) |
30328 | 348 |
|
22259
476604be7d88
New theory for converting between predicates and sets.
berghofe
parents:
diff
changeset
|
349 |
end |
30328 | 350 |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
351 |
definition single :: "'a \<Rightarrow> 'a pred" where |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
352 |
"single x = Pred ((op =) x)" |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
353 |
|
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
354 |
lemma eval_single [simp]: |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
355 |
"eval (single x) = (op =) x" |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
356 |
by (simp add: single_def) |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
357 |
|
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
358 |
definition bind :: "'a pred \<Rightarrow> ('a \<Rightarrow> 'b pred) \<Rightarrow> 'b pred" (infixl "\<guillemotright>=" 70) where |
41080 | 359 |
"P \<guillemotright>= f = (SUPR {x. eval P x} f)" |
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
360 |
|
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
361 |
lemma eval_bind [simp]: |
41080 | 362 |
"eval (P \<guillemotright>= f) = eval (SUPR {x. eval P x} f)" |
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
363 |
by (simp add: bind_def) |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
364 |
|
30328 | 365 |
lemma bind_bind: |
366 |
"(P \<guillemotright>= Q) \<guillemotright>= R = P \<guillemotright>= (\<lambda>x. Q x \<guillemotright>= R)" |
|
44415 | 367 |
by (rule pred_eqI) (auto simp add: SUP_apply) |
30328 | 368 |
|
369 |
lemma bind_single: |
|
370 |
"P \<guillemotright>= single = P" |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
371 |
by (rule pred_eqI) auto |
30328 | 372 |
|
373 |
lemma single_bind: |
|
374 |
"single x \<guillemotright>= P = P x" |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
375 |
by (rule pred_eqI) auto |
30328 | 376 |
|
377 |
lemma bottom_bind: |
|
378 |
"\<bottom> \<guillemotright>= P = \<bottom>" |
|
40674
54dbe6a1c349
adhere established Collect/mem convention more closely
haftmann
parents:
40616
diff
changeset
|
379 |
by (rule pred_eqI) auto |
30328 | 380 |
|
381 |
lemma sup_bind: |
|
382 |
"(P \<squnion> Q) \<guillemotright>= R = P \<guillemotright>= R \<squnion> Q \<guillemotright>= R" |
|
40674
54dbe6a1c349
adhere established Collect/mem convention more closely
haftmann
parents:
40616
diff
changeset
|
383 |
by (rule pred_eqI) auto |
30328 | 384 |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
385 |
lemma Sup_bind: |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
386 |
"(\<Squnion>A \<guillemotright>= f) = \<Squnion>((\<lambda>x. x \<guillemotright>= f) ` A)" |
44415 | 387 |
by (rule pred_eqI) (auto simp add: SUP_apply) |
30328 | 388 |
|
389 |
lemma pred_iffI: |
|
390 |
assumes "\<And>x. eval A x \<Longrightarrow> eval B x" |
|
391 |
and "\<And>x. eval B x \<Longrightarrow> eval A x" |
|
392 |
shows "A = B" |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
393 |
using assms by (auto intro: pred_eqI) |
30328 | 394 |
|
395 |
lemma singleI: "eval (single x) x" |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
396 |
by simp |
30328 | 397 |
|
398 |
lemma singleI_unit: "eval (single ()) x" |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
399 |
by simp |
30328 | 400 |
|
401 |
lemma singleE: "eval (single x) y \<Longrightarrow> (y = x \<Longrightarrow> P) \<Longrightarrow> P" |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
402 |
by simp |
30328 | 403 |
|
404 |
lemma singleE': "eval (single x) y \<Longrightarrow> (x = y \<Longrightarrow> P) \<Longrightarrow> P" |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
405 |
by simp |
30328 | 406 |
|
407 |
lemma bindI: "eval P x \<Longrightarrow> eval (Q x) y \<Longrightarrow> eval (P \<guillemotright>= Q) y" |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
408 |
by auto |
30328 | 409 |
|
410 |
lemma bindE: "eval (R \<guillemotright>= Q) y \<Longrightarrow> (\<And>x. eval R x \<Longrightarrow> eval (Q x) y \<Longrightarrow> P) \<Longrightarrow> P" |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
411 |
by auto |
30328 | 412 |
|
413 |
lemma botE: "eval \<bottom> x \<Longrightarrow> P" |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
414 |
by auto |
30328 | 415 |
|
416 |
lemma supI1: "eval A x \<Longrightarrow> eval (A \<squnion> B) x" |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
417 |
by auto |
30328 | 418 |
|
419 |
lemma supI2: "eval B x \<Longrightarrow> eval (A \<squnion> B) x" |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
420 |
by auto |
30328 | 421 |
|
422 |
lemma supE: "eval (A \<squnion> B) x \<Longrightarrow> (eval A x \<Longrightarrow> P) \<Longrightarrow> (eval B x \<Longrightarrow> P) \<Longrightarrow> P" |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
423 |
by auto |
30328 | 424 |
|
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
425 |
lemma single_not_bot [simp]: |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
426 |
"single x \<noteq> \<bottom>" |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
427 |
by (auto simp add: single_def bot_pred_def fun_eq_iff) |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
428 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
429 |
lemma not_bot: |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
430 |
assumes "A \<noteq> \<bottom>" |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
431 |
obtains x where "eval A x" |
45970
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
haftmann
parents:
45630
diff
changeset
|
432 |
using assms by (cases A) (auto simp add: bot_pred_def) |
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
haftmann
parents:
45630
diff
changeset
|
433 |
|
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
434 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
435 |
subsubsection {* Emptiness check and definite choice *} |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
436 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
437 |
definition is_empty :: "'a pred \<Rightarrow> bool" where |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
438 |
"is_empty A \<longleftrightarrow> A = \<bottom>" |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
439 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
440 |
lemma is_empty_bot: |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
441 |
"is_empty \<bottom>" |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
442 |
by (simp add: is_empty_def) |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
443 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
444 |
lemma not_is_empty_single: |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
445 |
"\<not> is_empty (single x)" |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
446 |
by (auto simp add: is_empty_def single_def bot_pred_def fun_eq_iff) |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
447 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
448 |
lemma is_empty_sup: |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
449 |
"is_empty (A \<squnion> B) \<longleftrightarrow> is_empty A \<and> is_empty B" |
36008 | 450 |
by (auto simp add: is_empty_def) |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
451 |
|
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
452 |
definition singleton :: "(unit \<Rightarrow> 'a) \<Rightarrow> 'a pred \<Rightarrow> 'a" where |
33111 | 453 |
"singleton dfault A = (if \<exists>!x. eval A x then THE x. eval A x else dfault ())" |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
454 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
455 |
lemma singleton_eqI: |
33110 | 456 |
"\<exists>!x. eval A x \<Longrightarrow> eval A x \<Longrightarrow> singleton dfault A = x" |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
457 |
by (auto simp add: singleton_def) |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
458 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
459 |
lemma eval_singletonI: |
33110 | 460 |
"\<exists>!x. eval A x \<Longrightarrow> eval A (singleton dfault A)" |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
461 |
proof - |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
462 |
assume assm: "\<exists>!x. eval A x" |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
463 |
then obtain x where "eval A x" .. |
33110 | 464 |
moreover with assm have "singleton dfault A = x" by (rule singleton_eqI) |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
465 |
ultimately show ?thesis by simp |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
466 |
qed |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
467 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
468 |
lemma single_singleton: |
33110 | 469 |
"\<exists>!x. eval A x \<Longrightarrow> single (singleton dfault A) = A" |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
470 |
proof - |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
471 |
assume assm: "\<exists>!x. eval A x" |
33110 | 472 |
then have "eval A (singleton dfault A)" |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
473 |
by (rule eval_singletonI) |
33110 | 474 |
moreover from assm have "\<And>x. eval A x \<Longrightarrow> singleton dfault A = x" |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
475 |
by (rule singleton_eqI) |
33110 | 476 |
ultimately have "eval (single (singleton dfault A)) = eval A" |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
477 |
by (simp (no_asm_use) add: single_def fun_eq_iff) blast |
40616
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
478 |
then have "\<And>x. eval (single (singleton dfault A)) x = eval A x" |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
479 |
by simp |
c5ee1e06d795
eval simp rules for predicate type, simplify primitive proofs
haftmann
parents:
39302
diff
changeset
|
480 |
then show ?thesis by (rule pred_eqI) |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
481 |
qed |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
482 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
483 |
lemma singleton_undefinedI: |
33111 | 484 |
"\<not> (\<exists>!x. eval A x) \<Longrightarrow> singleton dfault A = dfault ()" |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
485 |
by (simp add: singleton_def) |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
486 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
487 |
lemma singleton_bot: |
33111 | 488 |
"singleton dfault \<bottom> = dfault ()" |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
489 |
by (auto simp add: bot_pred_def intro: singleton_undefinedI) |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
490 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
491 |
lemma singleton_single: |
33110 | 492 |
"singleton dfault (single x) = x" |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
493 |
by (auto simp add: intro: singleton_eqI singleI elim: singleE) |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
494 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
495 |
lemma singleton_sup_single_single: |
33111 | 496 |
"singleton dfault (single x \<squnion> single y) = (if x = y then x else dfault ())" |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
497 |
proof (cases "x = y") |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
498 |
case True then show ?thesis by (simp add: singleton_single) |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
499 |
next |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
500 |
case False |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
501 |
have "eval (single x \<squnion> single y) x" |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
502 |
and "eval (single x \<squnion> single y) y" |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
503 |
by (auto intro: supI1 supI2 singleI) |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
504 |
with False have "\<not> (\<exists>!z. eval (single x \<squnion> single y) z)" |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
505 |
by blast |
33111 | 506 |
then have "singleton dfault (single x \<squnion> single y) = dfault ()" |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
507 |
by (rule singleton_undefinedI) |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
508 |
with False show ?thesis by simp |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
509 |
qed |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
510 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
511 |
lemma singleton_sup_aux: |
33110 | 512 |
"singleton dfault (A \<squnion> B) = (if A = \<bottom> then singleton dfault B |
513 |
else if B = \<bottom> then singleton dfault A |
|
514 |
else singleton dfault |
|
515 |
(single (singleton dfault A) \<squnion> single (singleton dfault B)))" |
|
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
516 |
proof (cases "(\<exists>!x. eval A x) \<and> (\<exists>!y. eval B y)") |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
517 |
case True then show ?thesis by (simp add: single_singleton) |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
518 |
next |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
519 |
case False |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
520 |
from False have A_or_B: |
33111 | 521 |
"singleton dfault A = dfault () \<or> singleton dfault B = dfault ()" |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
522 |
by (auto intro!: singleton_undefinedI) |
33110 | 523 |
then have rhs: "singleton dfault |
33111 | 524 |
(single (singleton dfault A) \<squnion> single (singleton dfault B)) = dfault ()" |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
525 |
by (auto simp add: singleton_sup_single_single singleton_single) |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
526 |
from False have not_unique: |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
527 |
"\<not> (\<exists>!x. eval A x) \<or> \<not> (\<exists>!y. eval B y)" by simp |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
528 |
show ?thesis proof (cases "A \<noteq> \<bottom> \<and> B \<noteq> \<bottom>") |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
529 |
case True |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
530 |
then obtain a b where a: "eval A a" and b: "eval B b" |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
531 |
by (blast elim: not_bot) |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
532 |
with True not_unique have "\<not> (\<exists>!x. eval (A \<squnion> B) x)" |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
533 |
by (auto simp add: sup_pred_def bot_pred_def) |
33111 | 534 |
then have "singleton dfault (A \<squnion> B) = dfault ()" by (rule singleton_undefinedI) |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
535 |
with True rhs show ?thesis by simp |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
536 |
next |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
537 |
case False then show ?thesis by auto |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
538 |
qed |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
539 |
qed |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
540 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
541 |
lemma singleton_sup: |
33110 | 542 |
"singleton dfault (A \<squnion> B) = (if A = \<bottom> then singleton dfault B |
543 |
else if B = \<bottom> then singleton dfault A |
|
33111 | 544 |
else if singleton dfault A = singleton dfault B then singleton dfault A else dfault ())" |
33110 | 545 |
using singleton_sup_aux [of dfault A B] by (simp only: singleton_sup_single_single) |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
546 |
|
30328 | 547 |
|
548 |
subsubsection {* Derived operations *} |
|
549 |
||
550 |
definition if_pred :: "bool \<Rightarrow> unit pred" where |
|
551 |
if_pred_eq: "if_pred b = (if b then single () else \<bottom>)" |
|
552 |
||
33754
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
553 |
definition holds :: "unit pred \<Rightarrow> bool" where |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
554 |
holds_eq: "holds P = eval P ()" |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
555 |
|
30328 | 556 |
definition not_pred :: "unit pred \<Rightarrow> unit pred" where |
557 |
not_pred_eq: "not_pred P = (if eval P () then \<bottom> else single ())" |
|
558 |
||
559 |
lemma if_predI: "P \<Longrightarrow> eval (if_pred P) ()" |
|
560 |
unfolding if_pred_eq by (auto intro: singleI) |
|
561 |
||
562 |
lemma if_predE: "eval (if_pred b) x \<Longrightarrow> (b \<Longrightarrow> x = () \<Longrightarrow> P) \<Longrightarrow> P" |
|
563 |
unfolding if_pred_eq by (cases b) (auto elim: botE) |
|
564 |
||
565 |
lemma not_predI: "\<not> P \<Longrightarrow> eval (not_pred (Pred (\<lambda>u. P))) ()" |
|
566 |
unfolding not_pred_eq eval_pred by (auto intro: singleI) |
|
567 |
||
568 |
lemma not_predI': "\<not> eval P () \<Longrightarrow> eval (not_pred P) ()" |
|
569 |
unfolding not_pred_eq by (auto intro: singleI) |
|
570 |
||
571 |
lemma not_predE: "eval (not_pred (Pred (\<lambda>u. P))) x \<Longrightarrow> (\<not> P \<Longrightarrow> thesis) \<Longrightarrow> thesis" |
|
572 |
unfolding not_pred_eq |
|
573 |
by (auto split: split_if_asm elim: botE) |
|
574 |
||
575 |
lemma not_predE': "eval (not_pred P) x \<Longrightarrow> (\<not> eval P x \<Longrightarrow> thesis) \<Longrightarrow> thesis" |
|
576 |
unfolding not_pred_eq |
|
577 |
by (auto split: split_if_asm elim: botE) |
|
33754
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
578 |
lemma "f () = False \<or> f () = True" |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
579 |
by simp |
30328 | 580 |
|
37549 | 581 |
lemma closure_of_bool_cases [no_atp]: |
44007 | 582 |
fixes f :: "unit \<Rightarrow> bool" |
583 |
assumes "f = (\<lambda>u. False) \<Longrightarrow> P f" |
|
584 |
assumes "f = (\<lambda>u. True) \<Longrightarrow> P f" |
|
585 |
shows "P f" |
|
33754
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
586 |
proof - |
44007 | 587 |
have "f = (\<lambda>u. False) \<or> f = (\<lambda>u. True)" |
33754
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
588 |
apply (cases "f ()") |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
589 |
apply (rule disjI2) |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
590 |
apply (rule ext) |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
591 |
apply (simp add: unit_eq) |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
592 |
apply (rule disjI1) |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
593 |
apply (rule ext) |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
594 |
apply (simp add: unit_eq) |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
595 |
done |
41550 | 596 |
from this assms show ?thesis by blast |
33754
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
597 |
qed |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
598 |
|
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
599 |
lemma unit_pred_cases: |
44007 | 600 |
assumes "P \<bottom>" |
601 |
assumes "P (single ())" |
|
602 |
shows "P Q" |
|
44415 | 603 |
using assms unfolding bot_pred_def bot_fun_def bot_bool_def empty_def single_def proof (cases Q) |
44007 | 604 |
fix f |
605 |
assume "P (Pred (\<lambda>u. False))" "P (Pred (\<lambda>u. () = u))" |
|
606 |
then have "P (Pred f)" |
|
607 |
by (cases _ f rule: closure_of_bool_cases) simp_all |
|
608 |
moreover assume "Q = Pred f" |
|
609 |
ultimately show "P Q" by simp |
|
610 |
qed |
|
611 |
||
33754
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
612 |
lemma holds_if_pred: |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
613 |
"holds (if_pred b) = b" |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
614 |
unfolding if_pred_eq holds_eq |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
615 |
by (cases b) (auto intro: singleI elim: botE) |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
616 |
|
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
617 |
lemma if_pred_holds: |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
618 |
"if_pred (holds P) = P" |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
619 |
unfolding if_pred_eq holds_eq |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
620 |
by (rule unit_pred_cases) (auto intro: singleI elim: botE) |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
621 |
|
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
622 |
lemma is_empty_holds: |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
623 |
"is_empty P \<longleftrightarrow> \<not> holds P" |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
624 |
unfolding is_empty_def holds_eq |
f2957bd46faf
adding derived constant Predicate.holds to Predicate theory; adopting the predicate compiler
bulwahn
parents:
33622
diff
changeset
|
625 |
by (rule unit_pred_cases) (auto elim: botE intro: singleI) |
30328 | 626 |
|
41311 | 627 |
definition map :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a pred \<Rightarrow> 'b pred" where |
628 |
"map f P = P \<guillemotright>= (single o f)" |
|
629 |
||
630 |
lemma eval_map [simp]: |
|
44363 | 631 |
"eval (map f P) = (\<Squnion>x\<in>{x. eval P x}. (\<lambda>y. f x = y))" |
44415 | 632 |
by (auto simp add: map_def comp_def) |
41311 | 633 |
|
41505
6d19301074cf
"enriched_type" replaces less specific "type_lifting"
haftmann
parents:
41372
diff
changeset
|
634 |
enriched_type map: map |
44363 | 635 |
by (rule ext, rule pred_eqI, auto)+ |
41311 | 636 |
|
637 |
||
30328 | 638 |
subsubsection {* Implementation *} |
639 |
||
640 |
datatype 'a seq = Empty | Insert "'a" "'a pred" | Join "'a pred" "'a seq" |
|
641 |
||
642 |
primrec pred_of_seq :: "'a seq \<Rightarrow> 'a pred" where |
|
44414 | 643 |
"pred_of_seq Empty = \<bottom>" |
644 |
| "pred_of_seq (Insert x P) = single x \<squnion> P" |
|
645 |
| "pred_of_seq (Join P xq) = P \<squnion> pred_of_seq xq" |
|
30328 | 646 |
|
647 |
definition Seq :: "(unit \<Rightarrow> 'a seq) \<Rightarrow> 'a pred" where |
|
648 |
"Seq f = pred_of_seq (f ())" |
|
649 |
||
650 |
code_datatype Seq |
|
651 |
||
652 |
primrec member :: "'a seq \<Rightarrow> 'a \<Rightarrow> bool" where |
|
653 |
"member Empty x \<longleftrightarrow> False" |
|
44414 | 654 |
| "member (Insert y P) x \<longleftrightarrow> x = y \<or> eval P x" |
655 |
| "member (Join P xq) x \<longleftrightarrow> eval P x \<or> member xq x" |
|
30328 | 656 |
|
657 |
lemma eval_member: |
|
658 |
"member xq = eval (pred_of_seq xq)" |
|
659 |
proof (induct xq) |
|
660 |
case Empty show ?case |
|
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
661 |
by (auto simp add: fun_eq_iff elim: botE) |
30328 | 662 |
next |
663 |
case Insert show ?case |
|
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
664 |
by (auto simp add: fun_eq_iff elim: supE singleE intro: supI1 supI2 singleI) |
30328 | 665 |
next |
666 |
case Join then show ?case |
|
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
667 |
by (auto simp add: fun_eq_iff elim: supE intro: supI1 supI2) |
30328 | 668 |
qed |
669 |
||
46038
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
670 |
lemma eval_code [(* FIXME declare simp *)code]: "eval (Seq f) = member (f ())" |
30328 | 671 |
unfolding Seq_def by (rule sym, rule eval_member) |
672 |
||
673 |
lemma single_code [code]: |
|
674 |
"single x = Seq (\<lambda>u. Insert x \<bottom>)" |
|
675 |
unfolding Seq_def by simp |
|
676 |
||
41080 | 677 |
primrec "apply" :: "('a \<Rightarrow> 'b pred) \<Rightarrow> 'a seq \<Rightarrow> 'b seq" where |
44415 | 678 |
"apply f Empty = Empty" |
679 |
| "apply f (Insert x P) = Join (f x) (Join (P \<guillemotright>= f) Empty)" |
|
680 |
| "apply f (Join P xq) = Join (P \<guillemotright>= f) (apply f xq)" |
|
30328 | 681 |
|
682 |
lemma apply_bind: |
|
683 |
"pred_of_seq (apply f xq) = pred_of_seq xq \<guillemotright>= f" |
|
684 |
proof (induct xq) |
|
685 |
case Empty show ?case |
|
686 |
by (simp add: bottom_bind) |
|
687 |
next |
|
688 |
case Insert show ?case |
|
689 |
by (simp add: single_bind sup_bind) |
|
690 |
next |
|
691 |
case Join then show ?case |
|
692 |
by (simp add: sup_bind) |
|
693 |
qed |
|
694 |
||
695 |
lemma bind_code [code]: |
|
696 |
"Seq g \<guillemotright>= f = Seq (\<lambda>u. apply f (g ()))" |
|
697 |
unfolding Seq_def by (rule sym, rule apply_bind) |
|
698 |
||
699 |
lemma bot_set_code [code]: |
|
700 |
"\<bottom> = Seq (\<lambda>u. Empty)" |
|
701 |
unfolding Seq_def by simp |
|
702 |
||
30376 | 703 |
primrec adjunct :: "'a pred \<Rightarrow> 'a seq \<Rightarrow> 'a seq" where |
44415 | 704 |
"adjunct P Empty = Join P Empty" |
705 |
| "adjunct P (Insert x Q) = Insert x (Q \<squnion> P)" |
|
706 |
| "adjunct P (Join Q xq) = Join Q (adjunct P xq)" |
|
30376 | 707 |
|
708 |
lemma adjunct_sup: |
|
709 |
"pred_of_seq (adjunct P xq) = P \<squnion> pred_of_seq xq" |
|
710 |
by (induct xq) (simp_all add: sup_assoc sup_commute sup_left_commute) |
|
711 |
||
30328 | 712 |
lemma sup_code [code]: |
713 |
"Seq f \<squnion> Seq g = Seq (\<lambda>u. case f () |
|
714 |
of Empty \<Rightarrow> g () |
|
715 |
| Insert x P \<Rightarrow> Insert x (P \<squnion> Seq g) |
|
30376 | 716 |
| Join P xq \<Rightarrow> adjunct (Seq g) (Join P xq))" |
30328 | 717 |
proof (cases "f ()") |
718 |
case Empty |
|
719 |
thus ?thesis |
|
34007
aea892559fc5
tuned lattices theory fragements; generlized some lemmas from sets to lattices
haftmann
parents:
33988
diff
changeset
|
720 |
unfolding Seq_def by (simp add: sup_commute [of "\<bottom>"]) |
30328 | 721 |
next |
722 |
case Insert |
|
723 |
thus ?thesis |
|
724 |
unfolding Seq_def by (simp add: sup_assoc) |
|
725 |
next |
|
726 |
case Join |
|
727 |
thus ?thesis |
|
30376 | 728 |
unfolding Seq_def |
729 |
by (simp add: adjunct_sup sup_assoc sup_commute sup_left_commute) |
|
30328 | 730 |
qed |
731 |
||
30430
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
732 |
primrec contained :: "'a seq \<Rightarrow> 'a pred \<Rightarrow> bool" where |
44415 | 733 |
"contained Empty Q \<longleftrightarrow> True" |
734 |
| "contained (Insert x P) Q \<longleftrightarrow> eval Q x \<and> P \<le> Q" |
|
735 |
| "contained (Join P xq) Q \<longleftrightarrow> P \<le> Q \<and> contained xq Q" |
|
30430
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
736 |
|
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
737 |
lemma single_less_eq_eval: |
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
738 |
"single x \<le> P \<longleftrightarrow> eval P x" |
44415 | 739 |
by (auto simp add: less_eq_pred_def le_fun_def) |
30430
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
740 |
|
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
741 |
lemma contained_less_eq: |
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
742 |
"contained xq Q \<longleftrightarrow> pred_of_seq xq \<le> Q" |
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
743 |
by (induct xq) (simp_all add: single_less_eq_eval) |
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
744 |
|
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
745 |
lemma less_eq_pred_code [code]: |
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
746 |
"Seq f \<le> Q = (case f () |
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
747 |
of Empty \<Rightarrow> True |
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
748 |
| Insert x P \<Rightarrow> eval Q x \<and> P \<le> Q |
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
749 |
| Join P xq \<Rightarrow> P \<le> Q \<and> contained xq Q)" |
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
750 |
by (cases "f ()") |
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
751 |
(simp_all add: Seq_def single_less_eq_eval contained_less_eq) |
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
752 |
|
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
753 |
lemma eq_pred_code [code]: |
31133 | 754 |
fixes P Q :: "'a pred" |
38857
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38651
diff
changeset
|
755 |
shows "HOL.equal P Q \<longleftrightarrow> P \<le> Q \<and> Q \<le> P" |
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38651
diff
changeset
|
756 |
by (auto simp add: equal) |
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38651
diff
changeset
|
757 |
|
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38651
diff
changeset
|
758 |
lemma [code nbe]: |
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38651
diff
changeset
|
759 |
"HOL.equal (x :: 'a pred) x \<longleftrightarrow> True" |
97775f3e8722
renamed class/constant eq to equal; tuned some instantiations
haftmann
parents:
38651
diff
changeset
|
760 |
by (fact equal_refl) |
30430
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
761 |
|
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
762 |
lemma [code]: |
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
763 |
"pred_case f P = f (eval P)" |
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
764 |
by (cases P) simp |
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
765 |
|
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
766 |
lemma [code]: |
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
767 |
"pred_rec f P = f (eval P)" |
42ea5d85edcc
explicit code equations for some rarely used pred operations
haftmann
parents:
30378
diff
changeset
|
768 |
by (cases P) simp |
30328 | 769 |
|
31105
95f66b234086
added general preprocessing of equality in predicates for code generation
bulwahn
parents:
30430
diff
changeset
|
770 |
inductive eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool" where "eq x x" |
95f66b234086
added general preprocessing of equality in predicates for code generation
bulwahn
parents:
30430
diff
changeset
|
771 |
|
95f66b234086
added general preprocessing of equality in predicates for code generation
bulwahn
parents:
30430
diff
changeset
|
772 |
lemma eq_is_eq: "eq x y \<equiv> (x = y)" |
31108 | 773 |
by (rule eq_reflection) (auto intro: eq.intros elim: eq.cases) |
30948 | 774 |
|
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
775 |
primrec null :: "'a seq \<Rightarrow> bool" where |
44415 | 776 |
"null Empty \<longleftrightarrow> True" |
777 |
| "null (Insert x P) \<longleftrightarrow> False" |
|
778 |
| "null (Join P xq) \<longleftrightarrow> is_empty P \<and> null xq" |
|
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
779 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
780 |
lemma null_is_empty: |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
781 |
"null xq \<longleftrightarrow> is_empty (pred_of_seq xq)" |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
782 |
by (induct xq) (simp_all add: is_empty_bot not_is_empty_single is_empty_sup) |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
783 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
784 |
lemma is_empty_code [code]: |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
785 |
"is_empty (Seq f) \<longleftrightarrow> null (f ())" |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
786 |
by (simp add: null_is_empty Seq_def) |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
787 |
|
33111 | 788 |
primrec the_only :: "(unit \<Rightarrow> 'a) \<Rightarrow> 'a seq \<Rightarrow> 'a" where |
789 |
[code del]: "the_only dfault Empty = dfault ()" |
|
44415 | 790 |
| "the_only dfault (Insert x P) = (if is_empty P then x else let y = singleton dfault P in if x = y then x else dfault ())" |
791 |
| "the_only dfault (Join P xq) = (if is_empty P then the_only dfault xq else if null xq then singleton dfault P |
|
33110 | 792 |
else let x = singleton dfault P; y = the_only dfault xq in |
33111 | 793 |
if x = y then x else dfault ())" |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
794 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
795 |
lemma the_only_singleton: |
33110 | 796 |
"the_only dfault xq = singleton dfault (pred_of_seq xq)" |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
797 |
by (induct xq) |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
798 |
(auto simp add: singleton_bot singleton_single is_empty_def |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
799 |
null_is_empty Let_def singleton_sup) |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
800 |
|
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
801 |
lemma singleton_code [code]: |
33110 | 802 |
"singleton dfault (Seq f) = (case f () |
33111 | 803 |
of Empty \<Rightarrow> dfault () |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
804 |
| Insert x P \<Rightarrow> if is_empty P then x |
33110 | 805 |
else let y = singleton dfault P in |
33111 | 806 |
if x = y then x else dfault () |
33110 | 807 |
| Join P xq \<Rightarrow> if is_empty P then the_only dfault xq |
808 |
else if null xq then singleton dfault P |
|
809 |
else let x = singleton dfault P; y = the_only dfault xq in |
|
33111 | 810 |
if x = y then x else dfault ())" |
32578
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
811 |
by (cases "f ()") |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
812 |
(auto simp add: Seq_def the_only_singleton is_empty_def |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
813 |
null_is_empty singleton_bot singleton_single singleton_sup Let_def) |
22117a76f943
added emptiness check predicate and singleton projection
haftmann
parents:
32372
diff
changeset
|
814 |
|
44414 | 815 |
definition the :: "'a pred \<Rightarrow> 'a" where |
37767 | 816 |
"the A = (THE x. eval A x)" |
33111 | 817 |
|
40674
54dbe6a1c349
adhere established Collect/mem convention more closely
haftmann
parents:
40616
diff
changeset
|
818 |
lemma the_eqI: |
41080 | 819 |
"(THE x. eval P x) = x \<Longrightarrow> the P = x" |
40674
54dbe6a1c349
adhere established Collect/mem convention more closely
haftmann
parents:
40616
diff
changeset
|
820 |
by (simp add: the_def) |
54dbe6a1c349
adhere established Collect/mem convention more closely
haftmann
parents:
40616
diff
changeset
|
821 |
|
44414 | 822 |
definition not_unique :: "'a pred \<Rightarrow> 'a" where |
823 |
[code del]: "not_unique A = (THE x. eval A x)" |
|
824 |
||
825 |
code_abort not_unique |
|
826 |
||
40674
54dbe6a1c349
adhere established Collect/mem convention more closely
haftmann
parents:
40616
diff
changeset
|
827 |
lemma the_eq [code]: "the A = singleton (\<lambda>x. not_unique A) A" |
54dbe6a1c349
adhere established Collect/mem convention more closely
haftmann
parents:
40616
diff
changeset
|
828 |
by (rule the_eqI) (simp add: singleton_def not_unique_def) |
33110 | 829 |
|
36531
19f6e3b0d9b6
code_reflect: specify module name directly after keyword
haftmann
parents:
36513
diff
changeset
|
830 |
code_reflect Predicate |
36513 | 831 |
datatypes pred = Seq and seq = Empty | Insert | Join |
832 |
functions map |
|
833 |
||
30948 | 834 |
ML {* |
835 |
signature PREDICATE = |
|
836 |
sig |
|
837 |
datatype 'a pred = Seq of (unit -> 'a seq) |
|
838 |
and 'a seq = Empty | Insert of 'a * 'a pred | Join of 'a pred * 'a seq |
|
30959
458e55fd0a33
fixed compilation of predicate types in ML environment
haftmann
parents:
30948
diff
changeset
|
839 |
val yield: 'a pred -> ('a * 'a pred) option |
458e55fd0a33
fixed compilation of predicate types in ML environment
haftmann
parents:
30948
diff
changeset
|
840 |
val yieldn: int -> 'a pred -> 'a list * 'a pred |
31222 | 841 |
val map: ('a -> 'b) -> 'a pred -> 'b pred |
30948 | 842 |
end; |
843 |
||
844 |
structure Predicate : PREDICATE = |
|
845 |
struct |
|
846 |
||
36513 | 847 |
datatype pred = datatype Predicate.pred |
848 |
datatype seq = datatype Predicate.seq |
|
849 |
||
850 |
fun map f = Predicate.map f; |
|
30959
458e55fd0a33
fixed compilation of predicate types in ML environment
haftmann
parents:
30948
diff
changeset
|
851 |
|
36513 | 852 |
fun yield (Seq f) = next (f ()) |
853 |
and next Empty = NONE |
|
854 |
| next (Insert (x, P)) = SOME (x, P) |
|
855 |
| next (Join (P, xq)) = (case yield P |
|
30959
458e55fd0a33
fixed compilation of predicate types in ML environment
haftmann
parents:
30948
diff
changeset
|
856 |
of NONE => next xq |
36513 | 857 |
| SOME (x, Q) => SOME (x, Seq (fn _ => Join (Q, xq)))); |
30959
458e55fd0a33
fixed compilation of predicate types in ML environment
haftmann
parents:
30948
diff
changeset
|
858 |
|
458e55fd0a33
fixed compilation of predicate types in ML environment
haftmann
parents:
30948
diff
changeset
|
859 |
fun anamorph f k x = (if k = 0 then ([], x) |
458e55fd0a33
fixed compilation of predicate types in ML environment
haftmann
parents:
30948
diff
changeset
|
860 |
else case f x |
458e55fd0a33
fixed compilation of predicate types in ML environment
haftmann
parents:
30948
diff
changeset
|
861 |
of NONE => ([], x) |
458e55fd0a33
fixed compilation of predicate types in ML environment
haftmann
parents:
30948
diff
changeset
|
862 |
| SOME (v, y) => let |
458e55fd0a33
fixed compilation of predicate types in ML environment
haftmann
parents:
30948
diff
changeset
|
863 |
val (vs, z) = anamorph f (k - 1) y |
33607 | 864 |
in (v :: vs, z) end); |
30959
458e55fd0a33
fixed compilation of predicate types in ML environment
haftmann
parents:
30948
diff
changeset
|
865 |
|
458e55fd0a33
fixed compilation of predicate types in ML environment
haftmann
parents:
30948
diff
changeset
|
866 |
fun yieldn P = anamorph yield P; |
30948 | 867 |
|
868 |
end; |
|
869 |
*} |
|
870 |
||
46038
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
871 |
text {* Conversion from and to sets *} |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
872 |
|
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
873 |
definition pred_of_set :: "'a set \<Rightarrow> 'a pred" where |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
874 |
"pred_of_set = Pred \<circ> (\<lambda>A x. x \<in> A)" |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
875 |
|
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
876 |
lemma eval_pred_of_set [simp]: |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
877 |
"eval (pred_of_set A) x \<longleftrightarrow> x \<in>A" |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
878 |
by (simp add: pred_of_set_def) |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
879 |
|
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
880 |
definition set_of_pred :: "'a pred \<Rightarrow> 'a set" where |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
881 |
"set_of_pred = Collect \<circ> eval" |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
882 |
|
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
883 |
lemma member_set_of_pred [simp]: |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
884 |
"x \<in> set_of_pred P \<longleftrightarrow> Predicate.eval P x" |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
885 |
by (simp add: set_of_pred_def) |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
886 |
|
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
887 |
definition set_of_seq :: "'a seq \<Rightarrow> 'a set" where |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
888 |
"set_of_seq = set_of_pred \<circ> pred_of_seq" |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
889 |
|
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
890 |
lemma member_set_of_seq [simp]: |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
891 |
"x \<in> set_of_seq xq = Predicate.member xq x" |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
892 |
by (simp add: set_of_seq_def eval_member) |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
893 |
|
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
894 |
lemma of_pred_code [code]: |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
895 |
"set_of_pred (Predicate.Seq f) = (case f () of |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
896 |
Predicate.Empty \<Rightarrow> {} |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
897 |
| Predicate.Insert x P \<Rightarrow> insert x (set_of_pred P) |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
898 |
| Predicate.Join P xq \<Rightarrow> set_of_pred P \<union> set_of_seq xq)" |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
899 |
by (auto split: seq.split simp add: eval_code) |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
900 |
|
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
901 |
lemma of_seq_code [code]: |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
902 |
"set_of_seq Predicate.Empty = {}" |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
903 |
"set_of_seq (Predicate.Insert x P) = insert x (set_of_pred P)" |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
904 |
"set_of_seq (Predicate.Join P xq) = set_of_pred P \<union> set_of_seq xq" |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
905 |
by auto |
bb2f7488a0f1
conversions from sets to predicates and vice versa; extensionality on predicates
haftmann
parents:
45970
diff
changeset
|
906 |
|
30328 | 907 |
no_notation |
41082 | 908 |
bot ("\<bottom>") and |
909 |
top ("\<top>") and |
|
30328 | 910 |
inf (infixl "\<sqinter>" 70) and |
911 |
sup (infixl "\<squnion>" 65) and |
|
912 |
Inf ("\<Sqinter>_" [900] 900) and |
|
913 |
Sup ("\<Squnion>_" [900] 900) and |
|
914 |
bind (infixl "\<guillemotright>=" 70) |
|
915 |
||
41080 | 916 |
no_syntax (xsymbols) |
41082 | 917 |
"_INF1" :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Sqinter>_./ _)" [0, 10] 10) |
918 |
"_INF" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Sqinter>_\<in>_./ _)" [0, 0, 10] 10) |
|
41080 | 919 |
"_SUP1" :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Squnion>_./ _)" [0, 10] 10) |
920 |
"_SUP" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Squnion>_\<in>_./ _)" [0, 0, 10] 10) |
|
921 |
||
36176
3fe7e97ccca8
replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact' -- frees some popular keywords;
wenzelm
parents:
36008
diff
changeset
|
922 |
hide_type (open) pred seq |
3fe7e97ccca8
replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact' -- frees some popular keywords;
wenzelm
parents:
36008
diff
changeset
|
923 |
hide_const (open) Pred eval single bind is_empty singleton if_pred not_pred holds |
33111 | 924 |
Empty Insert Join Seq member pred_of_seq "apply" adjunct null the_only eq map not_unique the |
30328 | 925 |
|
926 |
end |