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