src/HOL/Library/List_Cset.thy
author Andreas Lochbihler
Tue, 26 Jul 2011 14:05:28 +0200
changeset 43979 9f27d2bf4087
parent 43971 892030194015
child 44556 c0fd385a41f4
permissions -rw-r--r--
fixed code generator setup in List_Cset
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
     1
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
     2
(* Author: Florian Haftmann, TU Muenchen *)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
     3
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
     4
header {* implementation of Cset.sets based on lists *}
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
     5
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
     6
theory List_Cset
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
     7
imports Cset
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
     8
begin
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
     9
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    10
declare mem_def [simp]
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
    11
declare Cset.set_code [code del]
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    12
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    13
definition coset :: "'a list \<Rightarrow> 'a Cset.set" where
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    14
  "coset xs = Set (- set xs)"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    15
hide_const (open) coset
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    16
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    17
lemma member_coset [simp]:
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    18
  "member (List_Cset.coset xs) = - set xs"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    19
  by (simp add: coset_def)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    20
hide_fact (open) member_coset
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    21
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
    22
code_datatype Cset.set List_Cset.coset
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    23
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    24
lemma member_code [code]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
    25
  "member (Cset.set xs) = List.member xs"
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    26
  "member (List_Cset.coset xs) = Not \<circ> List.member xs"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    27
  by (simp_all add: fun_eq_iff member_def fun_Compl_def bool_Compl_def)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    28
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    29
lemma member_image_UNIV [simp]:
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    30
  "member ` UNIV = UNIV"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    31
proof -
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    32
  have "\<And>A \<Colon> 'a set. \<exists>B \<Colon> 'a Cset.set. A = member B"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    33
  proof
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    34
    fix A :: "'a set"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    35
    show "A = member (Set A)" by simp
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    36
  qed
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    37
  then show ?thesis by (simp add: image_def)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    38
qed
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    39
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    40
definition (in term_syntax)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    41
  setify :: "'a\<Colon>typerep list \<times> (unit \<Rightarrow> Code_Evaluation.term)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    42
    \<Rightarrow> 'a Cset.set \<times> (unit \<Rightarrow> Code_Evaluation.term)" where
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
    43
  [code_unfold]: "setify xs = Code_Evaluation.valtermify Cset.set {\<cdot>} xs"
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    44
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    45
notation fcomp (infixl "\<circ>>" 60)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    46
notation scomp (infixl "\<circ>\<rightarrow>" 60)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    47
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    48
instantiation Cset.set :: (random) random
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    49
begin
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    50
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    51
definition
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    52
  "Quickcheck.random i = Quickcheck.random i \<circ>\<rightarrow> (\<lambda>xs. Pair (setify xs))"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    53
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    54
instance ..
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    55
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    56
end
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    57
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    58
no_notation fcomp (infixl "\<circ>>" 60)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    59
no_notation scomp (infixl "\<circ>\<rightarrow>" 60)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    60
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    61
subsection {* Basic operations *}
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    62
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    63
lemma is_empty_set [code]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
    64
  "Cset.is_empty (Cset.set xs) \<longleftrightarrow> List.null xs"
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    65
  by (simp add: is_empty_set null_def)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    66
hide_fact (open) is_empty_set
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    67
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    68
lemma empty_set [code]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
    69
  "Cset.empty = Cset.set []"
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    70
  by (simp add: set_def)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    71
hide_fact (open) empty_set
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    72
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    73
lemma UNIV_set [code]:
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    74
  "top = List_Cset.coset []"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    75
  by (simp add: coset_def)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    76
hide_fact (open) UNIV_set
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    77
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    78
lemma remove_set [code]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
    79
  "Cset.remove x (Cset.set xs) = Cset.set (removeAll x xs)"
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    80
  "Cset.remove x (List_Cset.coset xs) = List_Cset.coset (List.insert x xs)"
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
    81
by (simp_all add: Cset.set_def coset_def)
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    82
  (metis List.set_insert More_Set.remove_def remove_set_compl)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    83
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    84
lemma insert_set [code]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
    85
  "Cset.insert x (Cset.set xs) = Cset.set (List.insert x xs)"
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    86
  "Cset.insert x (List_Cset.coset xs) = List_Cset.coset (removeAll x xs)"
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
    87
  by (simp_all add: Cset.set_def coset_def)
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    88
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    89
lemma map_set [code]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
    90
  "Cset.map f (Cset.set xs) = Cset.set (remdups (List.map f xs))"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
    91
  by (simp add: Cset.set_def)
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    92
  
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    93
lemma filter_set [code]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
    94
  "Cset.filter P (Cset.set xs) = Cset.set (List.filter P xs)"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
    95
  by (simp add: Cset.set_def project_set)
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    96
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
    97
lemma forall_set [code]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
    98
  "Cset.forall P (Cset.set xs) \<longleftrightarrow> list_all P xs"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
    99
  by (simp add: Cset.set_def list_all_iff)
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   100
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   101
lemma exists_set [code]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   102
  "Cset.exists P (Cset.set xs) \<longleftrightarrow> list_ex P xs"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   103
  by (simp add: Cset.set_def list_ex_iff)
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   104
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   105
lemma card_set [code]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   106
  "Cset.card (Cset.set xs) = length (remdups xs)"
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   107
proof -
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   108
  have "Finite_Set.card (set (remdups xs)) = length (remdups xs)"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   109
    by (rule distinct_card) simp
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   110
  then show ?thesis by (simp add: Cset.set_def)
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   111
qed
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   112
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   113
lemma compl_set [simp, code]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   114
  "- Cset.set xs = List_Cset.coset xs"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   115
  by (simp add: Cset.set_def coset_def)
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   116
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   117
lemma compl_coset [simp, code]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   118
  "- List_Cset.coset xs = Cset.set xs"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   119
  by (simp add: Cset.set_def coset_def)
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   120
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   121
context complete_lattice
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   122
begin
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   123
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   124
lemma Infimum_inf [code]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   125
  "Infimum (Cset.set As) = foldr inf As top"
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   126
  "Infimum (List_Cset.coset []) = bot"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   127
  by (simp_all add: Inf_set_foldr Inf_UNIV)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   128
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   129
lemma Supremum_sup [code]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   130
  "Supremum (Cset.set As) = foldr sup As bot"
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   131
  "Supremum (List_Cset.coset []) = top"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   132
  by (simp_all add: Sup_set_foldr Sup_UNIV)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   133
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   134
end
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   135
43979
9f27d2bf4087 fixed code generator setup in List_Cset
Andreas Lochbihler
parents: 43971
diff changeset
   136
declare Cset.single_code [code del]
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   137
lemma single_set [code]:
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   138
  "Cset.single a = Cset.set [a]"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   139
by(simp add: Cset.single_code)
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   140
hide_fact (open) single_set
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   141
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   142
lemma bind_set [code]:
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   143
  "Cset.bind (Cset.set xs) f = foldl (\<lambda>A x. sup A (f x)) (Cset.set []) xs"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   144
proof(rule sym)
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   145
  show "foldl (\<lambda>A x. sup A (f x)) (Cset.set []) xs = Cset.bind (Cset.set xs) f"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   146
    by(induct xs rule: rev_induct)(auto simp add: Cset.bind_def Cset.set_def)
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   147
qed
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   148
hide_fact (open) bind_set
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   149
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   150
lemma pred_of_cset_set [code]:
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   151
  "pred_of_cset (Cset.set xs) = foldr sup (map Predicate.single xs) bot"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   152
proof -
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   153
  have "pred_of_cset (Cset.set xs) = Predicate.Pred (\<lambda>x. x \<in> set xs)"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   154
    by(auto simp add: Cset.pred_of_cset_def mem_def)
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   155
  moreover have "foldr sup (map Predicate.single xs) bot = \<dots>"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   156
    by(induct xs)(auto simp add: bot_pred_def simp del: mem_def intro: pred_eqI, simp)
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   157
  ultimately show ?thesis by(simp)
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   158
qed
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   159
hide_fact (open) pred_of_cset_set
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   160
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   161
subsection {* Derived operations *}
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   162
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   163
lemma subset_eq_forall [code]:
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   164
  "A \<le> B \<longleftrightarrow> Cset.forall (member B) A"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   165
  by (simp add: subset_eq)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   166
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   167
lemma subset_subset_eq [code]:
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   168
  "A < B \<longleftrightarrow> A \<le> B \<and> \<not> B \<le> (A :: 'a Cset.set)"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   169
  by (fact less_le_not_le)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   170
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   171
instantiation Cset.set :: (type) equal
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   172
begin
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   173
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   174
definition [code]:
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   175
  "HOL.equal A B \<longleftrightarrow> A \<le> B \<and> B \<le> (A :: 'a Cset.set)"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   176
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   177
instance proof
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   178
qed (simp add: equal_set_def set_eq [symmetric] Cset.set_eq_iff)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   179
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   180
end
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   181
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   182
lemma [code nbe]:
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   183
  "HOL.equal (A :: 'a Cset.set) A \<longleftrightarrow> True"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   184
  by (fact equal_refl)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   185
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   186
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   187
subsection {* Functorial operations *}
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   188
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   189
lemma inter_project [code]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   190
  "inf A (Cset.set xs) = Cset.set (List.filter (Cset.member A) xs)"
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   191
  "inf A (List_Cset.coset xs) = foldr Cset.remove xs A"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   192
proof -
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   193
  show "inf A (Cset.set xs) = Cset.set (List.filter (member A) xs)"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   194
    by (simp add: inter project_def Cset.set_def)
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   195
  have *: "\<And>x::'a. Cset.remove = (\<lambda>x. Set \<circ> More_Set.remove x \<circ> member)"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   196
    by (simp add: fun_eq_iff More_Set.remove_def)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   197
  have "member \<circ> fold (\<lambda>x. Set \<circ> More_Set.remove x \<circ> member) xs =
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   198
    fold More_Set.remove xs \<circ> member"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   199
    by (rule fold_commute) (simp add: fun_eq_iff)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   200
  then have "fold More_Set.remove xs (member A) = 
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   201
    member (fold (\<lambda>x. Set \<circ> More_Set.remove x \<circ> member) xs A)"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   202
    by (simp add: fun_eq_iff)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   203
  then have "inf A (List_Cset.coset xs) = fold Cset.remove xs A"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   204
    by (simp add: Diff_eq [symmetric] minus_set *)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   205
  moreover have "\<And>x y :: 'a. Cset.remove y \<circ> Cset.remove x = Cset.remove x \<circ> Cset.remove y"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   206
    by (auto simp add: More_Set.remove_def * intro: ext)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   207
  ultimately show "inf A (List_Cset.coset xs) = foldr Cset.remove xs A"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   208
    by (simp add: foldr_fold)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   209
qed
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   210
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   211
lemma subtract_remove [code]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   212
  "A - Cset.set xs = foldr Cset.remove xs A"
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   213
  "A - List_Cset.coset xs = Cset.set (List.filter (member A) xs)"
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   214
  by (simp_all only: diff_eq compl_set compl_coset inter_project)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   215
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   216
lemma union_insert [code]:
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   217
  "sup (Cset.set xs) A = foldr Cset.insert xs A"
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   218
  "sup (List_Cset.coset xs) A = List_Cset.coset (List.filter (Not \<circ> member A) xs)"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   219
proof -
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   220
  have *: "\<And>x::'a. Cset.insert = (\<lambda>x. Set \<circ> Set.insert x \<circ> member)"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   221
    by (simp add: fun_eq_iff)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   222
  have "member \<circ> fold (\<lambda>x. Set \<circ> Set.insert x \<circ> member) xs =
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   223
    fold Set.insert xs \<circ> member"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   224
    by (rule fold_commute) (simp add: fun_eq_iff)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   225
  then have "fold Set.insert xs (member A) =
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   226
    member (fold (\<lambda>x. Set \<circ> Set.insert x \<circ> member) xs A)"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   227
    by (simp add: fun_eq_iff)
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   228
  then have "sup (Cset.set xs) A = fold Cset.insert xs A"
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   229
    by (simp add: union_set *)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   230
  moreover have "\<And>x y :: 'a. Cset.insert y \<circ> Cset.insert x = Cset.insert x \<circ> Cset.insert y"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   231
    by (auto simp add: * intro: ext)
43971
892030194015 added operations to Cset with code equations in backing implementations
Andreas Lochbihler
parents: 43307
diff changeset
   232
  ultimately show "sup (Cset.set xs) A = foldr Cset.insert xs A"
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   233
    by (simp add: foldr_fold)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   234
  show "sup (List_Cset.coset xs) A = List_Cset.coset (List.filter (Not \<circ> member A) xs)"
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   235
    by (auto simp add: coset_def)
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   236
qed
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   237
43307
1a32a953cef1 local simp rule in List_Cset
bulwahn
parents: 43241
diff changeset
   238
declare mem_def[simp del]
1a32a953cef1 local simp rule in List_Cset
bulwahn
parents: 43241
diff changeset
   239
43241
93b1183e43e5 splitting Cset into Cset and List_Cset
bulwahn
parents:
diff changeset
   240
end