src/HOL/Library/Multiset.thy
changeset 42871 1c0b99f950d9
parent 42809 5b45125b15ba
child 44339 eda6aef75939
equal deleted inserted replaced
42869:43b0f61f56d0 42871:1c0b99f950d9
  1455 done
  1455 done
  1456 
  1456 
  1457 lemma fold_mset_empty[simp]: "fold_mset f z {#} = z"
  1457 lemma fold_mset_empty[simp]: "fold_mset f z {#} = z"
  1458 unfolding fold_mset_def by blast
  1458 unfolding fold_mset_def by blast
  1459 
  1459 
  1460 context fun_left_comm
  1460 context comp_fun_commute
  1461 begin
  1461 begin
  1462 
  1462 
  1463 lemma fold_msetG_determ:
  1463 lemma fold_msetG_determ:
  1464   "fold_msetG f z A x \<Longrightarrow> fold_msetG f z A y \<Longrightarrow> y = x"
  1464   "fold_msetG f z A x \<Longrightarrow> fold_msetG f z A y \<Longrightarrow> y = x"
  1465 proof (induct arbitrary: x y z rule: full_multiset_induct)
  1465 proof (induct arbitrary: x y z rule: full_multiset_induct)
  1561     by (simp add: fold_mset_commute[of x,symmetric] add fold_mset_insert)
  1561     by (simp add: fold_mset_commute[of x,symmetric] add fold_mset_insert)
  1562   finally show ?case .
  1562   finally show ?case .
  1563 qed
  1563 qed
  1564 
  1564 
  1565 lemma fold_mset_fusion:
  1565 lemma fold_mset_fusion:
  1566   assumes "fun_left_comm g"
  1566   assumes "comp_fun_commute g"
  1567   shows "(\<And>x y. h (g x y) = f x (h y)) \<Longrightarrow> h (fold_mset g w A) = fold_mset f (h w) A" (is "PROP ?P")
  1567   shows "(\<And>x y. h (g x y) = f x (h y)) \<Longrightarrow> h (fold_mset g w A) = fold_mset f (h w) A" (is "PROP ?P")
  1568 proof -
  1568 proof -
  1569   interpret fun_left_comm g by (fact assms)
  1569   interpret comp_fun_commute g by (fact assms)
  1570   show "PROP ?P" by (induct A) auto
  1570   show "PROP ?P" by (induct A) auto
  1571 qed
  1571 qed
  1572 
  1572 
  1573 lemma fold_mset_rec:
  1573 lemma fold_mset_rec:
  1574   assumes "a \<in># A" 
  1574   assumes "a \<in># A" 
  1596 subsection {* Image *}
  1596 subsection {* Image *}
  1597 
  1597 
  1598 definition image_mset :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a multiset \<Rightarrow> 'b multiset" where
  1598 definition image_mset :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a multiset \<Rightarrow> 'b multiset" where
  1599   "image_mset f = fold_mset (op + o single o f) {#}"
  1599   "image_mset f = fold_mset (op + o single o f) {#}"
  1600 
  1600 
  1601 interpretation image_left_comm: fun_left_comm "op + o single o f"
  1601 interpretation image_fun_commute: comp_fun_commute "op + o single o f"
  1602 proof qed (simp add: add_ac fun_eq_iff)
  1602 proof qed (simp add: add_ac fun_eq_iff)
  1603 
  1603 
  1604 lemma image_mset_empty [simp]: "image_mset f {#} = {#}"
  1604 lemma image_mset_empty [simp]: "image_mset f {#} = {#}"
  1605 by (simp add: image_mset_def)
  1605 by (simp add: image_mset_def)
  1606 
  1606