src/HOL/Quotient_Examples/DList.thy
changeset 63167 0909deb8059b
parent 60668 5d281c5fe712
child 66453 cc19f7ca2ed6
equal deleted inserted replaced
63166:143f58bb34f9 63167:0909deb8059b
     3 
     3 
     4 Based on typedef version "Library/Dlist" by Florian Haftmann
     4 Based on typedef version "Library/Dlist" by Florian Haftmann
     5 and theory morphism version by Maksym Bortin
     5 and theory morphism version by Maksym Bortin
     6 *)
     6 *)
     7 
     7 
     8 section {* Lists with distinct elements *}
     8 section \<open>Lists with distinct elements\<close>
     9 
     9 
    10 theory DList
    10 theory DList
    11 imports "~~/src/HOL/Library/Quotient_List"
    11 imports "~~/src/HOL/Library/Quotient_List"
    12 begin
    12 begin
    13 
    13 
    14 text {* Some facts about lists *}
    14 text \<open>Some facts about lists\<close>
    15 
    15 
    16 lemma remdups_removeAll_commute[simp]:
    16 lemma remdups_removeAll_commute[simp]:
    17   "remdups (removeAll x l) = removeAll x (remdups l)"
    17   "remdups (removeAll x l) = removeAll x (remdups l)"
    18   by (induct l) auto
    18   by (induct l) auto
    19 
    19 
    64   using assms
    64   using assms
    65   unfolding fun_eq_iff List.member_def
    65   unfolding fun_eq_iff List.member_def
    66   by (induct xa ya rule: list_induct2')
    66   by (induct xa ya rule: list_induct2')
    67      (metis remdups_nil_noteq_cons set_remdups)+
    67      (metis remdups_nil_noteq_cons set_remdups)+
    68 
    68 
    69 text {* Setting up the quotient type *}
    69 text \<open>Setting up the quotient type\<close>
    70 
    70 
    71 definition
    71 definition
    72   dlist_eq :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
    72   dlist_eq :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
    73 where
    73 where
    74   [simp]: "dlist_eq xs ys \<longleftrightarrow> remdups xs = remdups ys"
    74   [simp]: "dlist_eq xs ys \<longleftrightarrow> remdups xs = remdups ys"
    91 
    91 
    92 quotient_type
    92 quotient_type
    93   'a dlist = "'a list" / "dlist_eq"
    93   'a dlist = "'a list" / "dlist_eq"
    94   by (rule dlist_eq_equivp)
    94   by (rule dlist_eq_equivp)
    95 
    95 
    96 text {* respectfulness and constant definitions *}
    96 text \<open>respectfulness and constant definitions\<close>
    97 
    97 
    98 definition [simp]: "card_remdups = length \<circ> remdups"
    98 definition [simp]: "card_remdups = length \<circ> remdups"
    99 definition [simp]: "foldr_remdups f xs e = foldr f (remdups xs) e"
    99 definition [simp]: "foldr_remdups f xs e = foldr f (remdups xs) e"
   100 
   100 
   101 quotient_definition empty where "empty :: 'a dlist"
   101 quotient_definition empty where "empty :: 'a dlist"
   123   is "List.filter" by (metis dlist_eq_def remdups_filter)
   123   is "List.filter" by (metis dlist_eq_def remdups_filter)
   124 
   124 
   125 quotient_definition "list_of_dlist :: 'a dlist \<Rightarrow> 'a list"
   125 quotient_definition "list_of_dlist :: 'a dlist \<Rightarrow> 'a list"
   126   is "remdups" by simp
   126   is "remdups" by simp
   127 
   127 
   128 text {* lifted theorems *}
   128 text \<open>lifted theorems\<close>
   129 
   129 
   130 lemma dlist_member_insert:
   130 lemma dlist_member_insert:
   131   "member dl x \<Longrightarrow> insert x dl = dl"
   131   "member dl x \<Longrightarrow> insert x dl = dl"
   132   by descending (simp add: List.member_def)
   132   by descending (simp add: List.member_def)
   133 
   133