src/HOL/Library/List_Cset.thy
author huffman
Fri Mar 30 12:32:35 2012 +0200 (2012-03-30)
changeset 47220 52426c62b5d0
parent 46305 8ea02e499d53
child 47232 e2f0176149d0
permissions -rw-r--r--
replace lemmas eval_nat_numeral with a simpler reformulation
bulwahn@43241
     1
bulwahn@43241
     2
(* Author: Florian Haftmann, TU Muenchen *)
bulwahn@43241
     3
bulwahn@43241
     4
header {* implementation of Cset.sets based on lists *}
bulwahn@43241
     5
bulwahn@43241
     6
theory List_Cset
bulwahn@43241
     7
imports Cset
bulwahn@43241
     8
begin
bulwahn@43241
     9
haftmann@44558
    10
code_datatype Cset.set Cset.coset
bulwahn@43241
    11
bulwahn@43241
    12
lemma member_code [code]:
Andreas@43971
    13
  "member (Cset.set xs) = List.member xs"
haftmann@44558
    14
  "member (Cset.coset xs) = Not \<circ> List.member xs"
haftmann@44558
    15
  by (simp_all add: fun_eq_iff List.member_def)
bulwahn@43241
    16
bulwahn@43241
    17
definition (in term_syntax)
bulwahn@46305
    18
  csetify :: "'a\<Colon>typerep list \<times> (unit \<Rightarrow> Code_Evaluation.term)
bulwahn@43241
    19
    \<Rightarrow> 'a Cset.set \<times> (unit \<Rightarrow> Code_Evaluation.term)" where
bulwahn@46305
    20
  [code_unfold]: "csetify xs = Code_Evaluation.valtermify Cset.set {\<cdot>} xs"
bulwahn@43241
    21
bulwahn@43241
    22
notation fcomp (infixl "\<circ>>" 60)
bulwahn@43241
    23
notation scomp (infixl "\<circ>\<rightarrow>" 60)
bulwahn@43241
    24
bulwahn@43241
    25
instantiation Cset.set :: (random) random
bulwahn@43241
    26
begin
bulwahn@43241
    27
bulwahn@43241
    28
definition
bulwahn@46305
    29
  "Quickcheck.random i = Quickcheck.random i \<circ>\<rightarrow> (\<lambda>xs. Pair (csetify xs))"
bulwahn@43241
    30
bulwahn@43241
    31
instance ..
bulwahn@43241
    32
bulwahn@43241
    33
end
bulwahn@43241
    34
bulwahn@43241
    35
no_notation fcomp (infixl "\<circ>>" 60)
bulwahn@43241
    36
no_notation scomp (infixl "\<circ>\<rightarrow>" 60)
bulwahn@43241
    37
bulwahn@43241
    38
subsection {* Basic operations *}
bulwahn@43241
    39
bulwahn@43241
    40
lemma is_empty_set [code]:
Andreas@43971
    41
  "Cset.is_empty (Cset.set xs) \<longleftrightarrow> List.null xs"
bulwahn@43241
    42
  by (simp add: is_empty_set null_def)
bulwahn@43241
    43
hide_fact (open) is_empty_set
bulwahn@43241
    44
bulwahn@43241
    45
lemma empty_set [code]:
Andreas@43971
    46
  "Cset.empty = Cset.set []"
haftmann@44558
    47
  by simp
bulwahn@43241
    48
hide_fact (open) empty_set
bulwahn@43241
    49
bulwahn@43241
    50
lemma UNIV_set [code]:
haftmann@44558
    51
  "top = Cset.coset []"
haftmann@44558
    52
  by (simp add: Cset.coset_def)
bulwahn@43241
    53
hide_fact (open) UNIV_set
bulwahn@43241
    54
bulwahn@43241
    55
lemma remove_set [code]:
Andreas@43971
    56
  "Cset.remove x (Cset.set xs) = Cset.set (removeAll x xs)"
haftmann@44558
    57
  "Cset.remove x (Cset.coset xs) = Cset.coset (List.insert x xs)"
haftmann@44558
    58
  by (simp_all add: Cset.set_def Cset.coset_def Compl_insert)
bulwahn@43241
    59
bulwahn@43241
    60
lemma insert_set [code]:
Andreas@43971
    61
  "Cset.insert x (Cset.set xs) = Cset.set (List.insert x xs)"
haftmann@44558
    62
  "Cset.insert x (Cset.coset xs) = Cset.coset (removeAll x xs)"
haftmann@44558
    63
  by (simp_all add: Cset.set_def Cset.coset_def)
haftmann@44558
    64
haftmann@44558
    65
declare compl_set [code]
haftmann@44558
    66
declare compl_coset [code]
haftmann@44560
    67
declare subtract_remove [code]
bulwahn@43241
    68
bulwahn@43241
    69
lemma map_set [code]:
Andreas@43971
    70
  "Cset.map f (Cset.set xs) = Cset.set (remdups (List.map f xs))"
Andreas@43971
    71
  by (simp add: Cset.set_def)
bulwahn@43241
    72
  
bulwahn@43241
    73
lemma filter_set [code]:
Andreas@43971
    74
  "Cset.filter P (Cset.set xs) = Cset.set (List.filter P xs)"
haftmann@46147
    75
  by (simp add: Cset.set_def)
bulwahn@43241
    76
bulwahn@43241
    77
lemma forall_set [code]:
Andreas@43971
    78
  "Cset.forall P (Cset.set xs) \<longleftrightarrow> list_all P xs"
Andreas@43971
    79
  by (simp add: Cset.set_def list_all_iff)
bulwahn@43241
    80
bulwahn@43241
    81
lemma exists_set [code]:
Andreas@43971
    82
  "Cset.exists P (Cset.set xs) \<longleftrightarrow> list_ex P xs"
Andreas@43971
    83
  by (simp add: Cset.set_def list_ex_iff)
bulwahn@43241
    84
bulwahn@43241
    85
lemma card_set [code]:
Andreas@43971
    86
  "Cset.card (Cset.set xs) = length (remdups xs)"
bulwahn@43241
    87
proof -
bulwahn@43241
    88
  have "Finite_Set.card (set (remdups xs)) = length (remdups xs)"
bulwahn@43241
    89
    by (rule distinct_card) simp
Andreas@43971
    90
  then show ?thesis by (simp add: Cset.set_def)
bulwahn@43241
    91
qed
bulwahn@43241
    92
bulwahn@43241
    93
context complete_lattice
bulwahn@43241
    94
begin
bulwahn@43241
    95
haftmann@44558
    96
declare Infimum_inf [code]
haftmann@44558
    97
declare Supremum_sup [code]
bulwahn@43241
    98
bulwahn@43241
    99
end
bulwahn@43241
   100
Andreas@43979
   101
declare Cset.single_code [code del]
Andreas@43971
   102
lemma single_set [code]:
Andreas@43971
   103
  "Cset.single a = Cset.set [a]"
Andreas@43971
   104
by(simp add: Cset.single_code)
Andreas@43971
   105
hide_fact (open) single_set
Andreas@43971
   106
haftmann@44558
   107
declare Cset.bind_set [code]
haftmann@44558
   108
declare Cset.pred_of_cset_set [code]
bulwahn@43241
   109
haftmann@44556
   110
bulwahn@43241
   111
subsection {* Derived operations *}
bulwahn@43241
   112
bulwahn@43241
   113
lemma subset_eq_forall [code]:
bulwahn@43241
   114
  "A \<le> B \<longleftrightarrow> Cset.forall (member B) A"
haftmann@44556
   115
  by (simp add: subset_eq member_def)
bulwahn@43241
   116
bulwahn@43241
   117
lemma subset_subset_eq [code]:
bulwahn@43241
   118
  "A < B \<longleftrightarrow> A \<le> B \<and> \<not> B \<le> (A :: 'a Cset.set)"
bulwahn@43241
   119
  by (fact less_le_not_le)
bulwahn@43241
   120
bulwahn@43241
   121
instantiation Cset.set :: (type) equal
bulwahn@43241
   122
begin
bulwahn@43241
   123
bulwahn@43241
   124
definition [code]:
bulwahn@43241
   125
  "HOL.equal A B \<longleftrightarrow> A \<le> B \<and> B \<le> (A :: 'a Cset.set)"
bulwahn@43241
   126
bulwahn@43241
   127
instance proof
haftmann@45969
   128
qed (auto simp add: equal_set_def Cset.set_eq_iff Cset.member_def fun_eq_iff)
bulwahn@43241
   129
bulwahn@43241
   130
end
bulwahn@43241
   131
bulwahn@43241
   132
lemma [code nbe]:
bulwahn@43241
   133
  "HOL.equal (A :: 'a Cset.set) A \<longleftrightarrow> True"
bulwahn@43241
   134
  by (fact equal_refl)
bulwahn@43241
   135
bulwahn@43241
   136
bulwahn@43241
   137
subsection {* Functorial operations *}
bulwahn@43241
   138
haftmann@44558
   139
declare inter_project [code]
haftmann@44558
   140
declare union_insert [code]
bulwahn@43307
   141
haftmann@44556
   142
end