src/HOL/Quotient_Examples/List_Cset.thy
author krauss
Wed, 20 Jul 2011 13:24:49 +0200
changeset 43926 3264fbfd87d6
parent 43800 9959c8732edf
child 44293 83c4f8ba0aa3
permissions -rw-r--r--
added UNION
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43800
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
     1
(*  Title:      HOL/Quotient_Examples/List_Cset.thy
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
     2
    Author:     Florian Haftmann, Alexander Krauss, TU Muenchen
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
     3
*)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
     4
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
     5
header {* Implementation of type Cset.set based on lists. Code equations obtained via quotient lifting. *}
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
     6
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
     7
theory List_Cset
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
     8
imports Cset
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
     9
begin
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    10
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    11
lemma [quot_respect]: "((op = ===> set_eq ===> set_eq) ===> op = ===> set_eq ===> set_eq)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    12
  foldr foldr"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    13
by (simp add: fun_rel_eq)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    14
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    15
lemma [quot_preserve]: "((id ---> abs_set ---> rep_set) ---> id ---> rep_set ---> abs_set) foldr = foldr"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    16
apply (rule ext)+
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    17
by (induct_tac xa) (auto simp: Quotient_abs_rep[OF Quotient_set])
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    18
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    19
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    20
subsection {* Relationship to lists *}
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    21
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    22
(*FIXME: maybe define on sets first and then lift -> more canonical*)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    23
definition coset :: "'a list \<Rightarrow> 'a Cset.set" where
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    24
  "coset xs = Cset.uminus (Cset.set xs)"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    25
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    26
code_datatype Cset.set List_Cset.coset
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    27
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    28
lemma member_code [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    29
  "member x (Cset.set xs) \<longleftrightarrow> List.member xs x"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    30
  "member x (coset xs) \<longleftrightarrow> \<not> List.member xs x"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    31
unfolding coset_def
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    32
apply (lifting in_set_member)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    33
by descending (simp add: in_set_member)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    34
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    35
definition (in term_syntax)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    36
  setify :: "'a\<Colon>typerep list \<times> (unit \<Rightarrow> Code_Evaluation.term)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    37
    \<Rightarrow> 'a Cset.set \<times> (unit \<Rightarrow> Code_Evaluation.term)" where
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    38
  [code_unfold]: "setify xs = Code_Evaluation.valtermify Cset.set {\<cdot>} xs"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    39
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    40
notation fcomp (infixl "\<circ>>" 60)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    41
notation scomp (infixl "\<circ>\<rightarrow>" 60)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    42
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    43
instantiation Cset.set :: (random) random
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    44
begin
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    45
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    46
definition
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    47
  "Quickcheck.random i = Quickcheck.random i \<circ>\<rightarrow> (\<lambda>xs. Pair (setify xs))"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    48
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    49
instance ..
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    50
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    51
end
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    52
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    53
no_notation fcomp (infixl "\<circ>>" 60)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    54
no_notation scomp (infixl "\<circ>\<rightarrow>" 60)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    55
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    56
subsection {* Basic operations *}
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    57
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    58
lemma is_empty_set [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    59
  "Cset.is_empty (Cset.set xs) \<longleftrightarrow> List.null xs"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    60
  by (lifting is_empty_set)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    61
hide_fact (open) is_empty_set
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    62
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    63
lemma empty_set [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    64
  "Cset.empty = Cset.set []"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    65
  by (lifting set.simps(1)[symmetric])
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    66
hide_fact (open) empty_set
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    67
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    68
lemma UNIV_set [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    69
  "Cset.UNIV = coset []"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    70
  unfolding coset_def by descending simp
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    71
hide_fact (open) UNIV_set
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    72
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    73
lemma remove_set [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    74
  "Cset.remove x (Cset.set xs) = Cset.set (removeAll x xs)"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    75
  "Cset.remove x (coset xs) = coset (List.insert x xs)"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    76
unfolding coset_def
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    77
apply descending
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    78
apply (simp add: More_Set.remove_def)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    79
apply descending
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    80
by (simp add: remove_set_compl)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    81
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    82
lemma insert_set [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    83
  "Cset.insert x (Cset.set xs) = Cset.set (List.insert x xs)"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    84
  "Cset.insert x (coset xs) = coset (removeAll x xs)"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    85
unfolding coset_def
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    86
apply (lifting set_insert[symmetric])
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    87
by descending simp
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    88
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    89
lemma map_set [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    90
  "Cset.map f (Cset.set xs) = Cset.set (remdups (List.map f xs))"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    91
by descending simp
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    92
  
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    93
lemma filter_set [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    94
  "Cset.filter P (Cset.set xs) = Cset.set (List.filter P xs)"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    95
by descending (simp add: project_set)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    96
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    97
lemma forall_set [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    98
  "Cset.forall (Cset.set xs) P \<longleftrightarrow> list_all P xs"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
    99
(* FIXME: why does (lifting Ball_set_list_all) fail? *)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   100
by descending (fact Ball_set_list_all)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   101
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   102
lemma exists_set [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   103
  "Cset.exists (Cset.set xs) P \<longleftrightarrow> list_ex P xs"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   104
by descending (fact Bex_set_list_ex)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   105
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   106
lemma card_set [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   107
  "Cset.card (Cset.set xs) = length (remdups xs)"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   108
by (lifting length_remdups_card_conv[symmetric])
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   109
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   110
lemma compl_set [simp, code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   111
  "Cset.uminus (Cset.set xs) = coset xs"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   112
unfolding coset_def by descending simp
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   113
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   114
lemma compl_coset [simp, code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   115
  "Cset.uminus (coset xs) = Cset.set xs"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   116
unfolding coset_def by descending simp
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   117
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   118
context complete_lattice
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   119
begin
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   120
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   121
(* FIXME: automated lifting fails, since @{term inf} and @{term top}
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   122
  are variables (???) *)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   123
lemma Infimum_inf [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   124
  "Infimum (Cset.set As) = foldr inf As top"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   125
  "Infimum (coset []) = bot"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   126
unfolding Infimum_def member_code List.member_def
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   127
apply (simp add: mem_def Inf_set_foldr)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   128
apply (simp add: Inf_UNIV[unfolded UNIV_def Collect_def])
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   129
done
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   130
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   131
lemma Supremum_sup [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   132
  "Supremum (Cset.set As) = foldr sup As bot"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   133
  "Supremum (coset []) = top"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   134
unfolding Supremum_def member_code List.member_def
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   135
apply (simp add: mem_def Sup_set_foldr)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   136
apply (simp add: Sup_UNIV[unfolded UNIV_def Collect_def])
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   137
done
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   138
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   139
end
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   140
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   141
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   142
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   143
subsection {* Derived operations *}
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   144
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   145
lemma subset_eq_forall [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   146
  "Cset.subset A B \<longleftrightarrow> Cset.forall A (\<lambda>x. member x B)"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   147
by descending blast
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   148
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   149
lemma subset_subset_eq [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   150
  "Cset.psubset A B \<longleftrightarrow> Cset.subset A B \<and> \<not> Cset.subset B A"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   151
by descending blast
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   152
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   153
instantiation Cset.set :: (type) equal
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   154
begin
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   155
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   156
definition [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   157
  "HOL.equal A B \<longleftrightarrow> Cset.subset A B \<and> Cset.subset B A"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   158
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   159
instance
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   160
apply intro_classes
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   161
unfolding equal_set_def
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   162
by descending auto
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   163
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   164
end
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   165
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   166
lemma [code nbe]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   167
  "HOL.equal (A :: 'a Cset.set) A \<longleftrightarrow> True"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   168
  by (fact equal_refl)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   169
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   170
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   171
subsection {* Functorial operations *}
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   172
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   173
lemma inter_project [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   174
  "Cset.inter A (Cset.set xs) = Cset.set (List.filter (\<lambda>x. Cset.member x A) xs)"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   175
  "Cset.inter A (coset xs) = foldr Cset.remove xs A"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   176
apply descending
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   177
apply auto
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   178
unfolding coset_def
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   179
apply descending
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   180
apply simp
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   181
by (metis diff_eq minus_set_foldr)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   182
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   183
lemma subtract_remove [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   184
  "Cset.minus A (Cset.set xs) = foldr Cset.remove xs A"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   185
  "Cset.minus A (coset xs) = Cset.set (List.filter (\<lambda>x. member x A) xs)"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   186
unfolding coset_def
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   187
apply (lifting minus_set_foldr)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   188
by descending auto
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   189
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   190
lemma union_insert [code]:
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   191
  "Cset.union (Cset.set xs) A = foldr Cset.insert xs A"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   192
  "Cset.union (coset xs) A = coset (List.filter (\<lambda>x. \<not> member x A) xs)"
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   193
unfolding coset_def
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   194
apply (lifting union_set_foldr)
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   195
by descending auto
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   196
43926
3264fbfd87d6 added UNION
krauss
parents: 43800
diff changeset
   197
lemma UNION_code [code]:
3264fbfd87d6 added UNION
krauss
parents: 43800
diff changeset
   198
  "Cset.UNION (Cset.set []) f = Cset.set []"
3264fbfd87d6 added UNION
krauss
parents: 43800
diff changeset
   199
  "Cset.UNION (Cset.set (x#xs)) f =
3264fbfd87d6 added UNION
krauss
parents: 43800
diff changeset
   200
     Cset.union (f x) (Cset.UNION (Cset.set xs) f)"
3264fbfd87d6 added UNION
krauss
parents: 43800
diff changeset
   201
  by (descending, simp)+
3264fbfd87d6 added UNION
krauss
parents: 43800
diff changeset
   202
3264fbfd87d6 added UNION
krauss
parents: 43800
diff changeset
   203
43800
9959c8732edf experimental variants of Library/Cset.thy and Library/Dlist_Cset.thy defined via quotient package
krauss
parents:
diff changeset
   204
end