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