src/HOL/Library/Cset.thy
author haftmann
Mon Dec 26 22:17:10 2011 +0100 (2011-12-26)
changeset 45990 b7b905b23b2a
parent 45986 c9e50153e5ae
child 46133 d9fe85d3d2cd
permissions -rw-r--r--
incorporated More_Set and More_List into the Main body -- to be consolidated later
haftmann@31807
     1
haftmann@31807
     2
(* Author: Florian Haftmann, TU Muenchen *)
haftmann@31807
     3
haftmann@40672
     4
header {* A dedicated set type which is executable on its finite part *}
haftmann@31807
     5
haftmann@40672
     6
theory Cset
haftmann@45990
     7
imports Main
haftmann@31807
     8
begin
haftmann@31807
     9
haftmann@31807
    10
subsection {* Lifting *}
haftmann@31807
    11
haftmann@40672
    12
typedef (open) 'a set = "UNIV :: 'a set set"
haftmann@44555
    13
  morphisms set_of Set by rule+
haftmann@40672
    14
hide_type (open) set
haftmann@31807
    15
haftmann@44555
    16
lemma set_of_Set [simp]:
haftmann@44555
    17
  "set_of (Set A) = A"
haftmann@44555
    18
  by (rule Set_inverse) rule
haftmann@44555
    19
haftmann@44555
    20
lemma Set_set_of [simp]:
haftmann@44555
    21
  "Set (set_of A) = A"
haftmann@44555
    22
  by (fact set_of_inverse)
haftmann@44555
    23
haftmann@44555
    24
definition member :: "'a Cset.set \<Rightarrow> 'a \<Rightarrow> bool" where
haftmann@44555
    25
  "member A x \<longleftrightarrow> x \<in> set_of A"
haftmann@44555
    26
haftmann@40672
    27
lemma member_Set [simp]:
haftmann@44555
    28
  "member (Set A) x \<longleftrightarrow> x \<in> A"
haftmann@44555
    29
  by (simp add: member_def)
haftmann@37468
    30
haftmann@40672
    31
lemma Set_inject [simp]:
haftmann@40672
    32
  "Set A = Set B \<longleftrightarrow> A = B"
haftmann@40672
    33
  by (simp add: Set_inject)
haftmann@37468
    34
haftmann@40672
    35
lemma set_eq_iff:
haftmann@39380
    36
  "A = B \<longleftrightarrow> member A = member B"
haftmann@45970
    37
  by (auto simp add: fun_eq_iff set_of_inject [symmetric] member_def)
haftmann@40672
    38
hide_fact (open) set_eq_iff
haftmann@39380
    39
haftmann@40672
    40
lemma set_eqI:
haftmann@37473
    41
  "member A = member B \<Longrightarrow> A = B"
haftmann@40672
    42
  by (simp add: Cset.set_eq_iff)
haftmann@40672
    43
hide_fact (open) set_eqI
haftmann@37473
    44
haftmann@34048
    45
subsection {* Lattice instantiation *}
haftmann@34048
    46
haftmann@40672
    47
instantiation Cset.set :: (type) boolean_algebra
haftmann@34048
    48
begin
haftmann@34048
    49
haftmann@40672
    50
definition less_eq_set :: "'a Cset.set \<Rightarrow> 'a Cset.set \<Rightarrow> bool" where
haftmann@44555
    51
  [simp]: "A \<le> B \<longleftrightarrow> set_of A \<subseteq> set_of B"
haftmann@34048
    52
haftmann@40672
    53
definition less_set :: "'a Cset.set \<Rightarrow> 'a Cset.set \<Rightarrow> bool" where
haftmann@44555
    54
  [simp]: "A < B \<longleftrightarrow> set_of A \<subset> set_of B"
haftmann@34048
    55
haftmann@40672
    56
definition inf_set :: "'a Cset.set \<Rightarrow> 'a Cset.set \<Rightarrow> 'a Cset.set" where
haftmann@44555
    57
  [simp]: "inf A B = Set (set_of A \<inter> set_of B)"
haftmann@34048
    58
haftmann@40672
    59
definition sup_set :: "'a Cset.set \<Rightarrow> 'a Cset.set \<Rightarrow> 'a Cset.set" where
haftmann@44555
    60
  [simp]: "sup A B = Set (set_of A \<union> set_of B)"
haftmann@34048
    61
haftmann@40672
    62
definition bot_set :: "'a Cset.set" where
haftmann@40672
    63
  [simp]: "bot = Set {}"
haftmann@34048
    64
haftmann@40672
    65
definition top_set :: "'a Cset.set" where
haftmann@40672
    66
  [simp]: "top = Set UNIV"
haftmann@34048
    67
haftmann@40672
    68
definition uminus_set :: "'a Cset.set \<Rightarrow> 'a Cset.set" where
haftmann@44555
    69
  [simp]: "- A = Set (- (set_of A))"
haftmann@34048
    70
haftmann@40672
    71
definition minus_set :: "'a Cset.set \<Rightarrow> 'a Cset.set \<Rightarrow> 'a Cset.set" where
haftmann@44555
    72
  [simp]: "A - B = Set (set_of A - set_of B)"
haftmann@34048
    73
haftmann@34048
    74
instance proof
haftmann@45970
    75
qed (auto intro!: Cset.set_eqI simp add: member_def)
haftmann@34048
    76
haftmann@34048
    77
end
haftmann@34048
    78
haftmann@40672
    79
instantiation Cset.set :: (type) complete_lattice
haftmann@34048
    80
begin
haftmann@34048
    81
haftmann@40672
    82
definition Inf_set :: "'a Cset.set set \<Rightarrow> 'a Cset.set" where
haftmann@44555
    83
  [simp]: "Inf_set As = Set (Inf (image set_of As))"
haftmann@34048
    84
haftmann@40672
    85
definition Sup_set :: "'a Cset.set set \<Rightarrow> 'a Cset.set" where
haftmann@44555
    86
  [simp]: "Sup_set As = Set (Sup (image set_of As))"
haftmann@34048
    87
haftmann@34048
    88
instance proof
haftmann@44555
    89
qed (auto simp add: le_fun_def)
haftmann@34048
    90
haftmann@34048
    91
end
haftmann@34048
    92
haftmann@44555
    93
instance Cset.set :: (type) complete_boolean_algebra proof
haftmann@44555
    94
qed (unfold INF_def SUP_def, auto)
haftmann@44555
    95
haftmann@37023
    96
haftmann@31807
    97
subsection {* Basic operations *}
haftmann@31807
    98
Andreas@43971
    99
abbreviation empty :: "'a Cset.set" where "empty \<equiv> bot"
Andreas@43971
   100
hide_const (open) empty
Andreas@43971
   101
Andreas@43971
   102
abbreviation UNIV :: "'a Cset.set" where "UNIV \<equiv> top"
Andreas@43971
   103
hide_const (open) UNIV
Andreas@43971
   104
haftmann@40672
   105
definition is_empty :: "'a Cset.set \<Rightarrow> bool" where
haftmann@45986
   106
  [simp]: "is_empty A \<longleftrightarrow> Set.is_empty (set_of A)"
haftmann@31807
   107
haftmann@40672
   108
definition insert :: "'a \<Rightarrow> 'a Cset.set \<Rightarrow> 'a Cset.set" where
haftmann@44555
   109
  [simp]: "insert x A = Set (Set.insert x (set_of A))"
haftmann@31807
   110
haftmann@40672
   111
definition remove :: "'a \<Rightarrow> 'a Cset.set \<Rightarrow> 'a Cset.set" where
haftmann@45986
   112
  [simp]: "remove x A = Set (Set.remove x (set_of A))"
haftmann@31807
   113
haftmann@40672
   114
definition map :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a Cset.set \<Rightarrow> 'b Cset.set" where
haftmann@44555
   115
  [simp]: "map f A = Set (image f (set_of A))"
haftmann@31807
   116
haftmann@41505
   117
enriched_type map: map
haftmann@41372
   118
  by (simp_all add: fun_eq_iff image_compose)
haftmann@40604
   119
haftmann@40672
   120
definition filter :: "('a \<Rightarrow> bool) \<Rightarrow> 'a Cset.set \<Rightarrow> 'a Cset.set" where
haftmann@45986
   121
  [simp]: "filter P A = Set (Set.project P (set_of A))"
haftmann@31807
   122
haftmann@40672
   123
definition forall :: "('a \<Rightarrow> bool) \<Rightarrow> 'a Cset.set \<Rightarrow> bool" where
haftmann@44555
   124
  [simp]: "forall P A \<longleftrightarrow> Ball (set_of A) P"
haftmann@31807
   125
haftmann@40672
   126
definition exists :: "('a \<Rightarrow> bool) \<Rightarrow> 'a Cset.set \<Rightarrow> bool" where
haftmann@44555
   127
  [simp]: "exists P A \<longleftrightarrow> Bex (set_of A) P"
haftmann@31807
   128
haftmann@40672
   129
definition card :: "'a Cset.set \<Rightarrow> nat" where
haftmann@44555
   130
  [simp]: "card A = Finite_Set.card (set_of A)"
bulwahn@43241
   131
  
haftmann@34048
   132
context complete_lattice
haftmann@34048
   133
begin
haftmann@31807
   134
haftmann@40672
   135
definition Infimum :: "'a Cset.set \<Rightarrow> 'a" where
haftmann@44555
   136
  [simp]: "Infimum A = Inf (set_of A)"
haftmann@31807
   137
haftmann@40672
   138
definition Supremum :: "'a Cset.set \<Rightarrow> 'a" where
haftmann@44555
   139
  [simp]: "Supremum A = Sup (set_of A)"
haftmann@34048
   140
haftmann@34048
   141
end
haftmann@31807
   142
Andreas@43971
   143
subsection {* More operations *}
Andreas@43971
   144
Andreas@43971
   145
text {* conversion from @{typ "'a list"} *}
Andreas@43971
   146
Andreas@43971
   147
definition set :: "'a list \<Rightarrow> 'a Cset.set" where
Andreas@43971
   148
  "set xs = Set (List.set xs)"
Andreas@43971
   149
hide_const (open) set
Andreas@43971
   150
haftmann@44558
   151
definition coset :: "'a list \<Rightarrow> 'a Cset.set" where
haftmann@44558
   152
  "coset xs = Set (- List.set xs)"
haftmann@44558
   153
hide_const (open) coset
haftmann@44558
   154
Andreas@43971
   155
text {* conversion from @{typ "'a Predicate.pred"} *}
Andreas@43971
   156
haftmann@44555
   157
definition pred_of_cset :: "'a Cset.set \<Rightarrow> 'a Predicate.pred" where
haftmann@44555
   158
  [code del]: "pred_of_cset = Predicate.Pred \<circ> Cset.member"
Andreas@43971
   159
haftmann@44555
   160
definition of_pred :: "'a Predicate.pred \<Rightarrow> 'a Cset.set" where
haftmann@44555
   161
  "of_pred = Cset.Set \<circ> Collect \<circ> Predicate.eval"
Andreas@43971
   162
haftmann@44555
   163
definition of_seq :: "'a Predicate.seq \<Rightarrow> 'a Cset.set" where 
haftmann@44555
   164
  "of_seq = of_pred \<circ> Predicate.pred_of_seq"
Andreas@43971
   165
Andreas@43971
   166
text {* monad operations *}
Andreas@43971
   167
Andreas@43971
   168
definition single :: "'a \<Rightarrow> 'a Cset.set" where
Andreas@43971
   169
  "single a = Set {a}"
Andreas@43971
   170
haftmann@44555
   171
definition bind :: "'a Cset.set \<Rightarrow> ('a \<Rightarrow> 'b Cset.set) \<Rightarrow> 'b Cset.set" (infixl "\<guillemotright>=" 70) where
haftmann@44555
   172
  "A \<guillemotright>= f = (SUP x : set_of A. f x)"
haftmann@44555
   173
haftmann@31807
   174
haftmann@31846
   175
subsection {* Simplified simprules *}
haftmann@31846
   176
haftmann@44555
   177
lemma empty_simp [simp]: "member Cset.empty = bot"
haftmann@44555
   178
  by (simp add: fun_eq_iff bot_apply)
Andreas@43971
   179
haftmann@44555
   180
lemma UNIV_simp [simp]: "member Cset.UNIV = top"
haftmann@44555
   181
  by (simp add: fun_eq_iff top_apply)
Andreas@43971
   182
haftmann@31846
   183
lemma is_empty_simp [simp]:
haftmann@44555
   184
  "is_empty A \<longleftrightarrow> set_of A = {}"
haftmann@45986
   185
  by (simp add: Set.is_empty_def)
haftmann@31846
   186
declare is_empty_def [simp del]
haftmann@31846
   187
haftmann@31846
   188
lemma remove_simp [simp]:
haftmann@44555
   189
  "remove x A = Set (set_of A - {x})"
haftmann@45986
   190
  by (simp add: Set.remove_def)
haftmann@31846
   191
declare remove_def [simp del]
haftmann@31846
   192
haftmann@31847
   193
lemma filter_simp [simp]:
haftmann@44555
   194
  "filter P A = Set {x \<in> set_of A. P x}"
haftmann@45986
   195
  by (simp add: Set.project_def)
haftmann@31847
   196
declare filter_def [simp del]
haftmann@31846
   197
haftmann@44555
   198
lemma set_of_set [simp]:
haftmann@44555
   199
  "set_of (Cset.set xs) = set xs"
Andreas@43971
   200
  by (simp add: set_def)
haftmann@44555
   201
hide_fact (open) set_def
Andreas@43971
   202
haftmann@44558
   203
lemma member_set [simp]:
haftmann@44558
   204
  "member (Cset.set xs) = (\<lambda>x. x \<in> set xs)"
haftmann@44558
   205
  by (simp add: fun_eq_iff member_def)
haftmann@44558
   206
hide_fact (open) member_set
haftmann@44558
   207
haftmann@44558
   208
lemma set_of_coset [simp]:
haftmann@44558
   209
  "set_of (Cset.coset xs) = - set xs"
haftmann@44558
   210
  by (simp add: coset_def)
haftmann@44558
   211
hide_fact (open) coset_def
haftmann@44558
   212
haftmann@44558
   213
lemma member_coset [simp]:
haftmann@44558
   214
  "member (Cset.coset xs) = (\<lambda>x. x \<in> - set xs)"
haftmann@44558
   215
  by (simp add: fun_eq_iff member_def)
haftmann@44558
   216
hide_fact (open) member_coset
haftmann@44558
   217
Andreas@43971
   218
lemma set_simps [simp]:
Andreas@43971
   219
  "Cset.set [] = Cset.empty"
Andreas@43971
   220
  "Cset.set (x # xs) = insert x (Cset.set xs)"
Andreas@43971
   221
by(simp_all add: Cset.set_def)
Andreas@43971
   222
haftmann@44555
   223
lemma member_SUP [simp]:
Andreas@43971
   224
  "member (SUPR A f) = SUPR A (member \<circ> f)"
haftmann@44555
   225
  by (auto simp add: fun_eq_iff SUP_apply member_def, unfold SUP_def, auto)
Andreas@43971
   226
Andreas@43971
   227
lemma member_bind [simp]:
haftmann@44555
   228
  "member (P \<guillemotright>= f) = SUPR (set_of P) (member \<circ> f)"
haftmann@44555
   229
  by (simp add: bind_def Cset.set_eq_iff)
Andreas@43971
   230
Andreas@43971
   231
lemma member_single [simp]:
haftmann@44555
   232
  "member (single a) = (\<lambda>x. x \<in> {a})"
haftmann@44555
   233
  by (simp add: single_def fun_eq_iff)
Andreas@43971
   234
Andreas@43971
   235
lemma single_sup_simps [simp]:
Andreas@43971
   236
  shows single_sup: "sup (single a) A = insert a A"
Andreas@43971
   237
  and sup_single: "sup A (single a) = insert a A"
haftmann@44555
   238
  by (auto simp add: Cset.set_eq_iff single_def)
Andreas@43971
   239
Andreas@43971
   240
lemma single_bind [simp]:
Andreas@43971
   241
  "single a \<guillemotright>= B = B a"
haftmann@44555
   242
  by (simp add: Cset.set_eq_iff SUP_insert single_def)
Andreas@43971
   243
Andreas@43971
   244
lemma bind_bind:
Andreas@43971
   245
  "(A \<guillemotright>= B) \<guillemotright>= C = A \<guillemotright>= (\<lambda>x. B x \<guillemotright>= C)"
haftmann@44555
   246
  by (simp add: bind_def, simp only: SUP_def image_image, simp)
haftmann@44555
   247
 
Andreas@43971
   248
lemma bind_single [simp]:
Andreas@43971
   249
  "A \<guillemotright>= single = A"
haftmann@44555
   250
  by (simp add: Cset.set_eq_iff SUP_apply fun_eq_iff single_def member_def)
Andreas@43971
   251
Andreas@43971
   252
lemma bind_const: "A \<guillemotright>= (\<lambda>_. B) = (if Cset.is_empty A then Cset.empty else B)"
haftmann@44555
   253
  by (auto simp add: Cset.set_eq_iff fun_eq_iff)
Andreas@43971
   254
Andreas@43971
   255
lemma empty_bind [simp]:
Andreas@43971
   256
  "Cset.empty \<guillemotright>= f = Cset.empty"
haftmann@44555
   257
  by (simp add: Cset.set_eq_iff fun_eq_iff bot_apply)
Andreas@43971
   258
Andreas@43971
   259
lemma member_of_pred [simp]:
haftmann@44555
   260
  "member (of_pred P) = (\<lambda>x. x \<in> {x. Predicate.eval P x})"
haftmann@44555
   261
  by (simp add: of_pred_def fun_eq_iff)
Andreas@43971
   262
Andreas@43971
   263
lemma member_of_seq [simp]:
haftmann@44555
   264
  "member (of_seq xq) = (\<lambda>x. x \<in> {x. Predicate.member xq x})"
haftmann@44555
   265
  by (simp add: of_seq_def eval_member)
Andreas@43971
   266
Andreas@43971
   267
lemma eval_pred_of_cset [simp]: 
Andreas@43971
   268
  "Predicate.eval (pred_of_cset A) = Cset.member A"
haftmann@44555
   269
  by (simp add: pred_of_cset_def)
Andreas@43971
   270
Andreas@43971
   271
subsection {* Default implementations *}
Andreas@43971
   272
Andreas@43971
   273
lemma set_code [code]:
haftmann@44555
   274
  "Cset.set = (\<lambda>xs. fold insert xs Cset.empty)"
haftmann@44555
   275
proof (rule ext, rule Cset.set_eqI)
haftmann@44555
   276
  fix xs :: "'a list"
haftmann@44555
   277
  show "member (Cset.set xs) = member (fold insert xs Cset.empty)"
haftmann@44555
   278
    by (simp add: fold_commute_apply [symmetric, where ?h = Set and ?g = Set.insert]
haftmann@44555
   279
      fun_eq_iff Cset.set_def union_set [symmetric])
Andreas@43971
   280
qed
Andreas@43971
   281
Andreas@43971
   282
lemma single_code [code]:
Andreas@43971
   283
  "single a = insert a Cset.empty"
haftmann@44555
   284
  by (simp add: Cset.single_def)
Andreas@43971
   285
haftmann@44558
   286
lemma compl_set [simp]:
haftmann@44558
   287
  "- Cset.set xs = Cset.coset xs"
haftmann@44558
   288
  by (simp add: Cset.set_def Cset.coset_def)
haftmann@44558
   289
haftmann@44558
   290
lemma compl_coset [simp]:
haftmann@44558
   291
  "- Cset.coset xs = Cset.set xs"
haftmann@44558
   292
  by (simp add: Cset.set_def Cset.coset_def)
haftmann@44558
   293
haftmann@44558
   294
lemma inter_project:
haftmann@44558
   295
  "inf A (Cset.set xs) = Cset.set (List.filter (Cset.member A) xs)"
haftmann@44558
   296
  "inf A (Cset.coset xs) = foldr Cset.remove xs A"
haftmann@44558
   297
proof -
haftmann@44558
   298
  show "inf A (Cset.set xs) = Cset.set (List.filter (member A) xs)"
haftmann@44558
   299
    by (simp add: inter project_def Cset.set_def member_def)
haftmann@45986
   300
  have *: "\<And>x::'a. Cset.remove = (\<lambda>x. Set \<circ> Set.remove x \<circ> set_of)"
haftmann@45986
   301
    by (simp add: fun_eq_iff Set.remove_def)
haftmann@45986
   302
  have "set_of \<circ> fold (\<lambda>x. Set \<circ> Set.remove x \<circ> set_of) xs =
haftmann@45986
   303
    fold Set.remove xs \<circ> set_of"
haftmann@44563
   304
    by (rule fold_commute) (simp add: fun_eq_iff)
haftmann@45986
   305
  then have "fold Set.remove xs (set_of A) = 
haftmann@45986
   306
    set_of (fold (\<lambda>x. Set \<circ> Set.remove x \<circ> set_of) xs A)"
haftmann@44558
   307
    by (simp add: fun_eq_iff)
haftmann@44558
   308
  then have "inf A (Cset.coset xs) = fold Cset.remove xs A"
haftmann@44563
   309
    by (simp add: Diff_eq [symmetric] minus_set *)
haftmann@44558
   310
  moreover have "\<And>x y :: 'a. Cset.remove y \<circ> Cset.remove x = Cset.remove x \<circ> Cset.remove y"
haftmann@45986
   311
    by (auto simp add: Set.remove_def *)
haftmann@44558
   312
  ultimately show "inf A (Cset.coset xs) = foldr Cset.remove xs A"
haftmann@44558
   313
    by (simp add: foldr_fold)
haftmann@44558
   314
qed
haftmann@44558
   315
haftmann@44563
   316
lemma union_insert:
haftmann@44563
   317
  "sup (Cset.set xs) A = foldr Cset.insert xs A"
haftmann@44563
   318
  "sup (Cset.coset xs) A = Cset.coset (List.filter (Not \<circ> member A) xs)"
haftmann@44563
   319
proof -
haftmann@44563
   320
  have *: "\<And>x::'a. Cset.insert = (\<lambda>x. Set \<circ> Set.insert x \<circ> set_of)"
haftmann@44563
   321
    by (simp add: fun_eq_iff)
haftmann@44563
   322
  have "set_of \<circ> fold (\<lambda>x. Set \<circ> Set.insert x \<circ> set_of) xs =
haftmann@44563
   323
    fold Set.insert xs \<circ> set_of"
haftmann@44563
   324
    by (rule fold_commute) (simp add: fun_eq_iff)
haftmann@44563
   325
  then have "fold Set.insert xs (set_of A) =
haftmann@44563
   326
    set_of (fold (\<lambda>x. Set \<circ> Set.insert x \<circ> set_of) xs A)"
haftmann@44563
   327
    by (simp add: fun_eq_iff)
haftmann@44563
   328
  then have "sup (Cset.set xs) A = fold Cset.insert xs A"
haftmann@44563
   329
    by (simp add: union_set *)
haftmann@44563
   330
  moreover have "\<And>x y :: 'a. Cset.insert y \<circ> Cset.insert x = Cset.insert x \<circ> Cset.insert y"
haftmann@44563
   331
    by (auto simp add: *)
haftmann@44563
   332
  ultimately show "sup (Cset.set xs) A = foldr Cset.insert xs A"
haftmann@44563
   333
    by (simp add: foldr_fold)
haftmann@44563
   334
  show "sup (Cset.coset xs) A = Cset.coset (List.filter (Not \<circ> member A) xs)"
haftmann@44563
   335
    by (auto simp add: Cset.coset_def Cset.member_def)
haftmann@44563
   336
qed
haftmann@44563
   337
haftmann@44558
   338
lemma subtract_remove:
haftmann@44558
   339
  "A - Cset.set xs = foldr Cset.remove xs A"
haftmann@44558
   340
  "A - Cset.coset xs = Cset.set (List.filter (member A) xs)"
haftmann@44558
   341
  by (simp_all only: diff_eq compl_set compl_coset inter_project)
haftmann@44558
   342
haftmann@44558
   343
context complete_lattice
haftmann@44558
   344
begin
haftmann@44558
   345
haftmann@44558
   346
lemma Infimum_inf:
haftmann@44558
   347
  "Infimum (Cset.set As) = foldr inf As top"
haftmann@44558
   348
  "Infimum (Cset.coset []) = bot"
haftmann@44558
   349
  by (simp_all add: Inf_set_foldr)
haftmann@44558
   350
haftmann@44558
   351
lemma Supremum_sup:
haftmann@44558
   352
  "Supremum (Cset.set As) = foldr sup As bot"
haftmann@44558
   353
  "Supremum (Cset.coset []) = top"
haftmann@44558
   354
  by (simp_all add: Sup_set_foldr)
haftmann@44558
   355
haftmann@44558
   356
end
haftmann@44558
   357
Andreas@43971
   358
lemma of_pred_code [code]:
Andreas@43971
   359
  "of_pred (Predicate.Seq f) = (case f () of
Andreas@43971
   360
     Predicate.Empty \<Rightarrow> Cset.empty
Andreas@43971
   361
   | Predicate.Insert x P \<Rightarrow> Cset.insert x (of_pred P)
Andreas@43971
   362
   | Predicate.Join P xq \<Rightarrow> sup (of_pred P) (of_seq xq))"
haftmann@45970
   363
  by (auto split: seq.split simp add: Predicate.Seq_def of_pred_def Cset.set_eq_iff sup_apply eval_member [symmetric] member_def [symmetric])
Andreas@43971
   364
Andreas@43971
   365
lemma of_seq_code [code]:
Andreas@43971
   366
  "of_seq Predicate.Empty = Cset.empty"
Andreas@43971
   367
  "of_seq (Predicate.Insert x P) = Cset.insert x (of_pred P)"
Andreas@43971
   368
  "of_seq (Predicate.Join P xq) = sup (of_pred P) (of_seq xq)"
haftmann@45970
   369
  by (auto simp add: of_seq_def of_pred_def Cset.set_eq_iff)
haftmann@31846
   370
haftmann@44558
   371
lemma bind_set:
haftmann@44558
   372
  "Cset.bind (Cset.set xs) f = fold (sup \<circ> f) xs (Cset.set [])"
haftmann@44558
   373
  by (simp add: Cset.bind_def SUPR_set_fold)
haftmann@44558
   374
hide_fact (open) bind_set
haftmann@44558
   375
haftmann@44558
   376
lemma pred_of_cset_set:
haftmann@44558
   377
  "pred_of_cset (Cset.set xs) = foldr sup (List.map Predicate.single xs) bot"
haftmann@44558
   378
proof -
haftmann@44558
   379
  have "pred_of_cset (Cset.set xs) = Predicate.Pred (\<lambda>x. x \<in> set xs)"
haftmann@45970
   380
    by (simp add: Cset.pred_of_cset_def)
haftmann@44558
   381
  moreover have "foldr sup (List.map Predicate.single xs) bot = \<dots>"
haftmann@45970
   382
    by (induct xs) (auto simp add: bot_pred_def intro: pred_eqI)
haftmann@44558
   383
  ultimately show ?thesis by simp
haftmann@44558
   384
qed
haftmann@44558
   385
hide_fact (open) pred_of_cset_set
haftmann@44558
   386
Andreas@43971
   387
no_notation bind (infixl "\<guillemotright>=" 70)
haftmann@31849
   388
bulwahn@43241
   389
hide_const (open) is_empty insert remove map filter forall exists card
Andreas@43971
   390
  Inter Union bind single of_pred of_seq
Andreas@43971
   391
Andreas@43971
   392
hide_fact (open) set_def pred_of_cset_def of_pred_def of_seq_def single_def 
haftmann@44555
   393
  bind_def empty_simp UNIV_simp set_simps member_bind 
Andreas@43971
   394
  member_single single_sup_simps single_sup sup_single single_bind
Andreas@43971
   395
  bind_bind bind_single bind_const empty_bind member_of_pred member_of_seq
Andreas@43971
   396
  eval_pred_of_cset set_code single_code of_pred_code of_seq_code
haftmann@31849
   397
haftmann@31807
   398
end