src/HOL/Library/Dlist_Cset.thy
author kuncar
Fri Dec 09 18:07:04 2011 +0100 (2011-12-09)
changeset 45802 b16f976db515
parent 44563 01b2732cf4ad
child 47232 e2f0176149d0
permissions -rw-r--r--
Quotient_Info stores only relation maps
     1 (* Author: Florian Haftmann, TU Muenchen *)
     2 
     3 header {* Canonical implementation of sets by distinct lists *}
     4 
     5 theory Dlist_Cset
     6 imports Dlist Cset
     7 begin
     8 
     9 definition Set :: "'a dlist \<Rightarrow> 'a Cset.set" where
    10   "Set dxs = Cset.set (list_of_dlist dxs)"
    11 
    12 definition Coset :: "'a dlist \<Rightarrow> 'a Cset.set" where
    13   "Coset dxs = Cset.coset (list_of_dlist dxs)"
    14 
    15 code_datatype Set Coset
    16 
    17 lemma Set_Dlist [simp]:
    18   "Set (Dlist xs) = Cset.set xs"
    19   by (rule Cset.set_eqI) (simp add: Set_def)
    20 
    21 lemma Coset_Dlist [simp]:
    22   "Coset (Dlist xs) = Cset.coset xs"
    23   by (rule Cset.set_eqI) (simp add: Coset_def)
    24 
    25 lemma member_Set [simp]:
    26   "Cset.member (Set dxs) = List.member (list_of_dlist dxs)"
    27   by (simp add: Set_def fun_eq_iff List.member_def)
    28 
    29 lemma member_Coset [simp]:
    30   "Cset.member (Coset dxs) = Not \<circ> List.member (list_of_dlist dxs)"
    31   by (simp add: Coset_def fun_eq_iff List.member_def)
    32 
    33 lemma Set_dlist_of_list [code]:
    34   "Cset.set xs = Set (dlist_of_list xs)"
    35   by (rule Cset.set_eqI) simp
    36 
    37 lemma Coset_dlist_of_list [code]:
    38   "Cset.coset xs = Coset (dlist_of_list xs)"
    39   by (rule Cset.set_eqI) simp
    40 
    41 lemma is_empty_Set [code]:
    42   "Cset.is_empty (Set dxs) \<longleftrightarrow> Dlist.null dxs"
    43   by (simp add: Dlist.null_def List.null_def Set_def)
    44 
    45 lemma bot_code [code]:
    46   "bot = Set Dlist.empty"
    47   by (simp add: empty_def)
    48 
    49 lemma top_code [code]:
    50   "top = Coset Dlist.empty"
    51   by (simp add: empty_def Cset.coset_def)
    52 
    53 lemma insert_code [code]:
    54   "Cset.insert x (Set dxs) = Set (Dlist.insert x dxs)"
    55   "Cset.insert x (Coset dxs) = Coset (Dlist.remove x dxs)"
    56   by (simp_all add: Dlist.insert_def Dlist.remove_def Cset.set_def Cset.coset_def Set_def Coset_def)
    57 
    58 lemma remove_code [code]:
    59   "Cset.remove x (Set dxs) = Set (Dlist.remove x dxs)"
    60   "Cset.remove x (Coset dxs) = Coset (Dlist.insert x dxs)"
    61   by (simp_all add: Dlist.insert_def Dlist.remove_def Cset.set_def Cset.coset_def Set_def Coset_def Compl_insert)
    62 
    63 lemma member_code [code]:
    64   "Cset.member (Set dxs) = Dlist.member dxs"
    65   "Cset.member (Coset dxs) = Not \<circ> Dlist.member dxs"
    66   by (simp_all add: List.member_def member_def fun_eq_iff Dlist.member_def)
    67 
    68 lemma compl_code [code]:
    69   "- Set dxs = Coset dxs"
    70   "- Coset dxs = Set dxs"
    71   by (rule Cset.set_eqI, simp add: fun_eq_iff List.member_def Set_def Coset_def)+
    72 
    73 lemma map_code [code]:
    74   "Cset.map f (Set dxs) = Set (Dlist.map f dxs)"
    75   by (rule Cset.set_eqI) (simp add: fun_eq_iff List.member_def Set_def)
    76   
    77 lemma filter_code [code]:
    78   "Cset.filter f (Set dxs) = Set (Dlist.filter f dxs)"
    79   by (rule Cset.set_eqI) (simp add: fun_eq_iff List.member_def Set_def)
    80 
    81 lemma forall_Set [code]:
    82   "Cset.forall P (Set xs) \<longleftrightarrow> list_all P (list_of_dlist xs)"
    83   by (simp add: Set_def list_all_iff)
    84 
    85 lemma exists_Set [code]:
    86   "Cset.exists P (Set xs) \<longleftrightarrow> list_ex P (list_of_dlist xs)"
    87   by (simp add: Set_def list_ex_iff)
    88 
    89 lemma card_code [code]:
    90   "Cset.card (Set dxs) = Dlist.length dxs"
    91   by (simp add: length_def Set_def distinct_card)
    92 
    93 lemma inter_code [code]:
    94   "inf A (Set xs) = Set (Dlist.filter (Cset.member A) xs)"
    95   "inf A (Coset xs) = Dlist.foldr Cset.remove xs A"
    96   by (simp_all only: Set_def Coset_def foldr_def inter_project list_of_dlist_filter)
    97 
    98 lemma subtract_code [code]:
    99   "A - Set xs = Dlist.foldr Cset.remove xs A"
   100   "A - Coset xs = Set (Dlist.filter (Cset.member A) xs)"
   101   by (simp_all only: Set_def Coset_def foldr_def subtract_remove list_of_dlist_filter)
   102 
   103 lemma union_code [code]:
   104   "sup (Set xs) A = Dlist.foldr Cset.insert xs A"
   105   "sup (Coset xs) A = Coset (Dlist.filter (Not \<circ> Cset.member A) xs)"
   106   by (simp_all only: Set_def Coset_def foldr_def union_insert list_of_dlist_filter)
   107 
   108 context complete_lattice
   109 begin
   110 
   111 lemma Infimum_code [code]:
   112   "Infimum (Set As) = Dlist.foldr inf As top"
   113   by (simp only: Set_def Infimum_inf foldr_def inf.commute)
   114 
   115 lemma Supremum_code [code]:
   116   "Supremum (Set As) = Dlist.foldr sup As bot"
   117   by (simp only: Set_def Supremum_sup foldr_def sup.commute)
   118 
   119 end
   120 
   121 declare Cset.single_code [code]
   122 
   123 lemma bind_set [code]:
   124   "Cset.bind (Dlist_Cset.Set xs) f = fold (sup \<circ> f) (list_of_dlist xs) Cset.empty"
   125   by (simp add: Cset.bind_set Set_def)
   126 hide_fact (open) bind_set
   127 
   128 lemma pred_of_cset_set [code]:
   129   "pred_of_cset (Dlist_Cset.Set xs) = foldr sup (map Predicate.single (list_of_dlist xs)) bot"
   130   by (simp add: Cset.pred_of_cset_set Dlist_Cset.Set_def)
   131 hide_fact (open) pred_of_cset_set
   132 
   133 end