src/HOL/Library/Executable_Set.thy
author haftmann
Wed Sep 16 13:43:05 2009 +0200 (2009-09-16)
changeset 32587 caa5ada96a00
parent 32139 e271a64f03ff
child 32606 b5c3a8a75772
permissions -rw-r--r--
Inter and Union are mere abbreviations for Inf and Sup
haftmann@23854
     1
(*  Title:      HOL/Library/Executable_Set.thy
haftmann@23854
     2
    Author:     Stefan Berghofer, TU Muenchen
haftmann@23854
     3
*)
haftmann@23854
     4
haftmann@23854
     5
header {* Implementation of finite sets by lists *}
haftmann@23854
     6
haftmann@23854
     7
theory Executable_Set
haftmann@31850
     8
imports Main Fset
haftmann@23854
     9
begin
haftmann@23854
    10
haftmann@32587
    11
subsection {* Preprocessor setup *}
haftmann@31847
    12
haftmann@31847
    13
declare member [code] 
haftmann@23854
    14
haftmann@28522
    15
definition subset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
haftmann@28522
    16
  "subset = op \<le>"
haftmann@28522
    17
haftmann@31998
    18
declare subset_def [symmetric, code_unfold]
haftmann@28522
    19
haftmann@31847
    20
lemma [code]:
haftmann@31847
    21
  "subset A B \<longleftrightarrow> (\<forall>x\<in>A. x \<in> B)"
haftmann@31847
    22
  by (simp add: subset_def subset_eq)
haftmann@28522
    23
haftmann@28522
    24
definition eq_set :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
haftmann@28522
    25
  [code del]: "eq_set = op ="
haftmann@28522
    26
haftmann@32587
    27
(*declare eq_set_def [symmetric, code_unfold]*)
nipkow@29107
    28
haftmann@23854
    29
lemma [code]:
haftmann@31847
    30
  "eq_set A B \<longleftrightarrow> A \<subseteq> B \<and> B \<subseteq> A"
haftmann@31847
    31
  by (simp add: eq_set_def set_eq)
haftmann@23854
    32
haftmann@31847
    33
declare inter [code]
haftmann@23854
    34
haftmann@31847
    35
declare Inter_image_eq [symmetric, code]
haftmann@31847
    36
declare Union_image_eq [symmetric, code]
haftmann@23854
    37
haftmann@31998
    38
declare List_Set.project_def [symmetric, code_unfold]
haftmann@23854
    39
haftmann@32587
    40
definition Inter :: "'a set set \<Rightarrow> 'a set" where
haftmann@32587
    41
  "Inter = Complete_Lattice.Inter"
haftmann@23854
    42
haftmann@32587
    43
declare Inter_def [symmetric, code_unfold]
haftmann@32587
    44
haftmann@32587
    45
definition Union :: "'a set set \<Rightarrow> 'a set" where
haftmann@32587
    46
  "Union = Complete_Lattice.Union"
haftmann@32587
    47
haftmann@32587
    48
declare Union_def [symmetric, code_unfold]
haftmann@32587
    49
haftmann@32587
    50
haftmann@32587
    51
subsection {* Code generator setup *}
haftmann@23854
    52
haftmann@23854
    53
ML {*
haftmann@23854
    54
nonfix inter;
haftmann@23854
    55
nonfix union;
haftmann@23854
    56
nonfix subset;
haftmann@23854
    57
*}
haftmann@23854
    58
haftmann@31847
    59
definition flip :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'c" where
haftmann@31847
    60
  "flip f a b = f b a"
haftmann@23854
    61
haftmann@31850
    62
types_code
haftmann@31850
    63
  fset ("(_/ \<module>fset)")
haftmann@31850
    64
attach {*
haftmann@31850
    65
datatype 'a fset = Set of 'a list;
haftmann@31850
    66
*}
haftmann@31850
    67
haftmann@23854
    68
consts_code
haftmann@31850
    69
  Set ("\<module>Set")
haftmann@31850
    70
haftmann@31850
    71
consts_code
haftmann@31850
    72
  "Set.empty"         ("{*Fset.empty*}")
haftmann@31850
    73
  "List_Set.is_empty" ("{*Fset.is_empty*}")
haftmann@31850
    74
  "Set.insert"        ("{*Fset.insert*}")
haftmann@31850
    75
  "List_Set.remove"   ("{*Fset.remove*}")
haftmann@31850
    76
  "Set.image"         ("{*Fset.map*}")
haftmann@31850
    77
  "List_Set.project"  ("{*Fset.filter*}")
haftmann@31850
    78
  "Ball"              ("{*flip Fset.forall*}")
haftmann@31850
    79
  "Bex"               ("{*flip Fset.exists*}")
haftmann@31850
    80
  "op \<union>"              ("{*Fset.union*}")
haftmann@31850
    81
  "op \<inter>"              ("{*Fset.inter*}")
haftmann@31850
    82
  "op - \<Colon> 'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" ("{*flip Fset.subtract*}")
haftmann@32587
    83
  "Union"             ("{*Fset.Union*}")
haftmann@32587
    84
  "Inter"             ("{*Fset.Inter*}")
haftmann@31850
    85
  card                ("{*Fset.card*}")
haftmann@31847
    86
  fold                ("{*foldl o flip*}")
haftmann@23854
    87
haftmann@31847
    88
end