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