src/HOL/Library/Multiset.thy
changeset 15867 5c63b6c2f4a5
parent 15630 cc3776f004e2
child 15869 3aca7f05cd12
equal deleted inserted replaced
15866:f011452b2815 15867:5c63b6c2f4a5
   738 
   738 
   739 lemma multiset_of_zero_iff_right[simp]: "({#} = multiset_of x) = (x = [])"
   739 lemma multiset_of_zero_iff_right[simp]: "({#} = multiset_of x) = (x = [])"
   740   by (induct_tac x, auto)
   740   by (induct_tac x, auto)
   741 
   741 
   742 lemma set_of_multiset_of[simp]: "set_of(multiset_of x) = set x"
   742 lemma set_of_multiset_of[simp]: "set_of(multiset_of x) = set x"
   743  by (induct_tac x, auto) 
   743   by (induct_tac x, auto) 
       
   744 
       
   745 lemma mem_set_multiset_eq: "x \<in> set xs = (x :# multiset_of xs)"
       
   746   by (induct xs) auto
   744 
   747 
   745 lemma multiset_of_append[simp]: 
   748 lemma multiset_of_append[simp]: 
   746   "multiset_of (xs @ ys) = multiset_of xs + multiset_of ys"
   749   "multiset_of (xs @ ys) = multiset_of xs + multiset_of ys"
   747   by (rule_tac x=ys in spec, induct_tac xs, auto simp: union_ac) 
   750   by (rule_tac x=ys in spec, induct_tac xs, auto simp: union_ac) 
   748 
   751 
   762    apply (simp_all add: set_of_multiset_of [THEN sym] del: set_of_multiset_of) 
   765    apply (simp_all add: set_of_multiset_of [THEN sym] del: set_of_multiset_of) 
   763    apply (erule_tac x=a in allE, simp, clarify)
   766    apply (erule_tac x=a in allE, simp, clarify)
   764    apply (erule_tac x=aa in allE, simp) 
   767    apply (erule_tac x=aa in allE, simp) 
   765    done
   768    done
   766 
   769 
       
   770 lemma multiset_of_eq_setD: 
       
   771   "multiset_of xs = multiset_of ys \<Longrightarrow> set xs = set ys"
       
   772   by (rule) (auto simp add:multiset_eq_conv_count_eq set_count_greater_0)
       
   773 
   767 lemma set_eq_iff_multiset_of_eq_distinct: 
   774 lemma set_eq_iff_multiset_of_eq_distinct: 
   768   "\<lbrakk>distinct x; distinct y\<rbrakk> 
   775   "\<lbrakk>distinct x; distinct y\<rbrakk> 
   769    \<Longrightarrow> (set x = set y) = (multiset_of x = multiset_of y)"
   776    \<Longrightarrow> (set x = set y) = (multiset_of x = multiset_of y)"
   770   by (auto simp: multiset_eq_conv_count_eq distinct_count_atmost_1) 
   777   by (auto simp: multiset_eq_conv_count_eq distinct_count_atmost_1) 
   771 
   778 
   780 
   787 
   781 lemma multiset_of_compl_union[simp]:
   788 lemma multiset_of_compl_union[simp]:
   782  "multiset_of [x\<in>xs. P x] + multiset_of [x\<in>xs. \<not>P x] = multiset_of xs"
   789  "multiset_of [x\<in>xs. P x] + multiset_of [x\<in>xs. \<not>P x] = multiset_of xs"
   783   by (induct xs) (auto simp: union_ac)
   790   by (induct xs) (auto simp: union_ac)
   784 
   791 
       
   792 lemma count_filter: 
       
   793   "count (multiset_of xs) x = length [y \<in> xs. y = x]"
       
   794   by (induct xs, auto)
       
   795 
       
   796 
   785 subsection {* Pointwise ordering induced by count *}
   797 subsection {* Pointwise ordering induced by count *}
   786 
   798 
   787 consts 
   799 consts 
   788   mset_le :: "['a multiset, 'a multiset] \<Rightarrow> bool"
   800   mset_le :: "['a multiset, 'a multiset] \<Rightarrow> bool"
   789 
   801