src/HOL/Library/Crude_Executable_Set.thy
author haftmann
Fri, 04 Dec 2009 11:03:54 +0100
changeset 33947 2d0d08b5b048
child 34008 1ce58e8c02ee
permissions -rw-r--r--
added Crude_Executable_Set
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33947
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
     1
(*  Title:      HOL/Library/Crude_Executable_Set.thy
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
     2
    Author:     Florian Haftmann, TU Muenchen
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
     3
*)
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
     4
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
     5
header {* A crude implementation of finite sets by lists -- avoid using this at any cost! *}
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
     6
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
     7
theory Crude_Executable_Set
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
     8
imports List_Set
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
     9
begin
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    10
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    11
declare mem_def [code del]
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    12
declare Collect_def [code del]
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    13
declare insert_code [code del]
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    14
declare vimage_code [code del]
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    15
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    16
subsection {* Set representation *}
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    17
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    18
setup {*
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    19
  Code.add_type_cmd "set"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    20
*}
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    21
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    22
definition Set :: "'a list \<Rightarrow> 'a set" where
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    23
  [simp]: "Set = set"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    24
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    25
definition Coset :: "'a list \<Rightarrow> 'a set" where
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    26
  [simp]: "Coset xs = - set xs"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    27
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    28
setup {*
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    29
  Code.add_signature_cmd ("Set", "'a list \<Rightarrow> 'a set")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    30
  #> Code.add_signature_cmd ("Coset", "'a list \<Rightarrow> 'a set")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    31
  #> Code.add_signature_cmd ("set", "'a list \<Rightarrow> 'a set")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    32
  #> Code.add_signature_cmd ("op \<in>", "'a \<Rightarrow> 'a set \<Rightarrow> bool")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    33
*}
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    34
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    35
code_datatype Set Coset
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    36
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    37
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    38
subsection {* Basic operations *}
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    39
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    40
lemma [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    41
  "set xs = Set (remdups xs)"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    42
  by simp
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    43
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    44
lemma [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    45
  "x \<in> Set xs \<longleftrightarrow> member x xs"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    46
  "x \<in> Coset xs \<longleftrightarrow> \<not> member x xs"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    47
  by (simp_all add: mem_iff)
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    48
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    49
definition is_empty :: "'a set \<Rightarrow> bool" where
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    50
  [simp]: "is_empty A \<longleftrightarrow> A = {}"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    51
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    52
lemma [code_inline]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    53
  "A = {} \<longleftrightarrow> is_empty A"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    54
  by simp
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    55
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    56
definition empty :: "'a set" where
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    57
  [simp]: "empty = {}"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    58
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    59
lemma [code_inline]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    60
  "{} = empty"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    61
  by simp
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    62
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    63
setup {*
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    64
  Code.add_signature_cmd ("is_empty", "'a set \<Rightarrow> bool")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    65
  #> Code.add_signature_cmd ("empty", "'a set")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    66
  #> Code.add_signature_cmd ("insert", "'a \<Rightarrow> 'a set \<Rightarrow> 'a set")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    67
  #> Code.add_signature_cmd ("List_Set.remove", "'a \<Rightarrow> 'a set \<Rightarrow> 'a set")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    68
  #> Code.add_signature_cmd ("image", "('a \<Rightarrow> 'b) \<Rightarrow> 'a set \<Rightarrow> 'b set")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    69
  #> Code.add_signature_cmd ("List_Set.project", "('a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> 'a set")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    70
  #> Code.add_signature_cmd ("Ball", "'a set \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    71
  #> Code.add_signature_cmd ("Bex", "'a set \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    72
  #> Code.add_signature_cmd ("card", "'a set \<Rightarrow> nat")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    73
*}
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    74
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    75
lemma is_empty_Set [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    76
  "is_empty (Set xs) \<longleftrightarrow> null xs"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    77
  by (simp add: empty_null)
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    78
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    79
lemma empty_Set [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    80
  "empty = Set []"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    81
  by simp
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    82
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    83
lemma insert_Set [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    84
  "insert x (Set xs) = Set (List_Set.insert x xs)"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    85
  "insert x (Coset xs) = Coset (remove_all x xs)"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    86
  by (simp_all add: insert_set insert_set_compl)
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    87
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    88
lemma remove_Set [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    89
  "remove x (Set xs) = Set (remove_all x xs)"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    90
  "remove x (Coset xs) = Coset (List_Set.insert x xs)"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    91
  by (simp_all add:remove_set remove_set_compl)
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    92
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    93
lemma image_Set [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    94
  "image f (Set xs) = Set (remdups (map f xs))"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    95
  by simp
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    96
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    97
lemma project_Set [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    98
  "project P (Set xs) = Set (filter P xs)"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
    99
  by (simp add: project_set)
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   100
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   101
lemma Ball_Set [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   102
  "Ball (Set xs) P \<longleftrightarrow> list_all P xs"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   103
  by (simp add: ball_set)
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   104
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   105
lemma Bex_Set [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   106
  "Bex (Set xs) P \<longleftrightarrow> list_ex P xs"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   107
  by (simp add: bex_set)
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   108
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   109
lemma card_Set [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   110
  "card (Set xs) = length (remdups xs)"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   111
proof -
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   112
  have "card (set (remdups xs)) = length (remdups xs)"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   113
    by (rule distinct_card) simp
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   114
  then show ?thesis by simp
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   115
qed
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   116
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   117
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   118
subsection {* Derived operations *}
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   119
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   120
definition set_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   121
  [simp]: "set_eq = op ="
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   122
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   123
lemma [code_inline]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   124
  "op = = set_eq"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   125
  by simp
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   126
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   127
definition subset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   128
  [simp]: "subset_eq = op \<subseteq>"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   129
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   130
lemma [code_inline]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   131
  "op \<subseteq> = subset_eq"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   132
  by simp
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   133
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   134
definition subset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   135
  [simp]: "subset = op \<subset>"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   136
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   137
lemma [code_inline]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   138
  "op \<subset> = subset"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   139
  by simp
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   140
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   141
setup {*
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   142
  Code.add_signature_cmd ("set_eq", "'a set \<Rightarrow> 'a set \<Rightarrow> bool")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   143
  #> Code.add_signature_cmd ("subset_eq", "'a set \<Rightarrow> 'a set \<Rightarrow> bool")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   144
  #> Code.add_signature_cmd ("subset", "'a set \<Rightarrow> 'a set \<Rightarrow> bool")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   145
*}
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   146
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   147
lemma set_eq_subset_eq [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   148
  "set_eq A B \<longleftrightarrow> subset_eq A B \<and> subset_eq B A"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   149
  by auto
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   150
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   151
lemma subset_eq_forall [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   152
  "subset_eq A B \<longleftrightarrow> (\<forall>x\<in>A. x \<in> B)"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   153
  by (simp add: subset_eq)
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   154
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   155
lemma subset_subset_eq [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   156
  "subset A B \<longleftrightarrow> subset_eq A B \<and> \<not> subset_eq B A"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   157
  by (simp add: subset)
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   158
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   159
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   160
subsection {* Functorial operations *}
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   161
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   162
definition inter :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" where
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   163
  [simp]: "inter = op \<inter>"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   164
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   165
lemma [code_inline]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   166
  "op \<inter> = inter"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   167
  by simp
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   168
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   169
definition subtract :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" where
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   170
  [simp]: "subtract A B = B - A"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   171
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   172
lemma [code_inline]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   173
  "B - A = subtract A B"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   174
  by simp
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   175
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   176
definition union :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" where
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   177
  [simp]: "union = op \<union>"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   178
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   179
lemma [code_inline]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   180
  "op \<union> = union"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   181
  by simp
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   182
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   183
definition Inf :: "'a::complete_lattice set \<Rightarrow> 'a" where
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   184
  [simp]: "Inf = Complete_Lattice.Inf"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   185
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   186
lemma [code_inline]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   187
  "Complete_Lattice.Inf = Inf"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   188
  by simp
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   189
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   190
definition Sup :: "'a::complete_lattice set \<Rightarrow> 'a" where
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   191
  [simp]: "Sup = Complete_Lattice.Sup"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   192
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   193
lemma [code_inline]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   194
  "Complete_Lattice.Sup = Sup"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   195
  by simp
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   196
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   197
definition Inter :: "'a set set \<Rightarrow> 'a set" where
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   198
  [simp]: "Inter = Inf"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   199
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   200
lemma [code_inline]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   201
  "Inf = Inter"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   202
  by simp
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   203
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   204
definition Union :: "'a set set \<Rightarrow> 'a set" where
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   205
  [simp]: "Union = Sup"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   206
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   207
lemma [code_inline]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   208
  "Sup = Union"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   209
  by simp
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   210
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   211
setup {*
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   212
  Code.add_signature_cmd ("inter", "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   213
  #> Code.add_signature_cmd ("subtract", "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   214
  #> Code.add_signature_cmd ("union", "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   215
  #> Code.add_signature_cmd ("Inf", "'a set \<Rightarrow> 'a")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   216
  #> Code.add_signature_cmd ("Sup", "'a set \<Rightarrow> 'a")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   217
  #> Code.add_signature_cmd ("Inter", "'a set set \<Rightarrow> 'a set")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   218
  #> Code.add_signature_cmd ("Union", "'a set set \<Rightarrow> 'a set")
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   219
*}
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   220
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   221
lemma inter_project [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   222
  "inter A (Set xs) = Set (List.filter (\<lambda>x. x \<in> A) xs)"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   223
  "inter A (Coset xs) = foldl (\<lambda>A x. remove x A) A xs"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   224
  by (simp add: inter project_def, simp add: Diff_eq [symmetric] minus_set)
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   225
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   226
lemma subtract_remove [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   227
  "subtract (Set xs) A = foldl (\<lambda>A x. remove x A) A xs"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   228
  "subtract (Coset xs) A = Set (List.filter (\<lambda>x. x \<in> A) xs)"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   229
  by (auto simp add: minus_set)
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   230
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   231
lemma union_insert [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   232
  "union (Set xs) A = foldl (\<lambda>A x. insert x A) A xs"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   233
  "union (Coset xs) A = Coset (List.filter (\<lambda>x. x \<notin> A) xs)"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   234
  by (auto simp add: union_set)
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   235
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   236
lemma Inf_inf [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   237
  "Inf (Set xs) = foldl inf (top :: 'a::complete_lattice) xs"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   238
  "Inf (Coset []) = (bot :: 'a::complete_lattice)"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   239
  by (simp_all add: Inf_Univ bot_def [symmetric] Inf_set_fold)
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   240
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   241
lemma Sup_sup [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   242
  "Sup (Set xs) = foldl sup (bot :: 'a::complete_lattice) xs"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   243
  "Sup (Coset []) = (top :: 'a::complete_lattice)"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   244
  by (simp_all add: Sup_Univ top_def [symmetric] Sup_set_fold)
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   245
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   246
lemma Inter_inter [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   247
  "Inter (Set xs) = foldl inter (Coset []) xs"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   248
  "Inter (Coset []) = empty"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   249
  unfolding Inter_def Inf_inf by simp_all
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   250
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   251
lemma Union_union [code]:
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   252
  "Union (Set xs) = foldl union empty xs"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   253
  "Union (Coset []) = Coset []"
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   254
  unfolding Union_def Sup_sup by simp_all
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   255
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   256
hide (open) const is_empty empty remove
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   257
  set_eq subset_eq subset inter union subtract Inf Sup Inter Union
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   258
2d0d08b5b048 added Crude_Executable_Set
haftmann
parents:
diff changeset
   259
end