src/HOL/Library/Multiset.thy
changeset 57512 cc97b347b301
parent 57492 74bf65a1910a
child 57514 bdc2c6b40bf2
equal deleted inserted replaced
57511:de51a86fc903 57512:cc97b347b301
   223 lemma add_eq_conv_diff:
   223 lemma add_eq_conv_diff:
   224   "M + {#a#} = N + {#b#} \<longleftrightarrow> M = N \<and> a = b \<or> M = N - {#a#} + {#b#} \<and> N = M - {#b#} + {#a#}"  (is "?lhs = ?rhs")
   224   "M + {#a#} = N + {#b#} \<longleftrightarrow> M = N \<and> a = b \<or> M = N - {#a#} + {#b#} \<and> N = M - {#b#} + {#a#}"  (is "?lhs = ?rhs")
   225 (* shorter: by (simp add: multiset_eq_iff) fastforce *)
   225 (* shorter: by (simp add: multiset_eq_iff) fastforce *)
   226 proof
   226 proof
   227   assume ?rhs then show ?lhs
   227   assume ?rhs then show ?lhs
   228   by (auto simp add: add_assoc add_commute [of "{#b#}"])
   228   by (auto simp add: add.assoc add.commute [of "{#b#}"])
   229     (drule sym, simp add: add_assoc [symmetric])
   229     (drule sym, simp add: add.assoc [symmetric])
   230 next
   230 next
   231   assume ?lhs
   231   assume ?lhs
   232   show ?rhs
   232   show ?rhs
   233   proof (cases "a = b")
   233   proof (cases "a = b")
   234     case True with `?lhs` show ?thesis by simp
   234     case True with `?lhs` show ?thesis by simp
  1492     case 0 then show ?thesis by simp
  1492     case 0 then show ?thesis by simp
  1493   next
  1493   next
  1494     case (Suc i')
  1494     case (Suc i')
  1495     with Cons show ?thesis
  1495     with Cons show ?thesis
  1496       apply simp
  1496       apply simp
  1497       apply (subst add_assoc)
  1497       apply (subst add.assoc)
  1498       apply (subst add_commute [of "{#v#}" "{#x#}"])
  1498       apply (subst add.commute [of "{#v#}" "{#x#}"])
  1499       apply (subst add_assoc [symmetric])
  1499       apply (subst add.assoc [symmetric])
  1500       apply simp
  1500       apply simp
  1501       apply (rule mset_le_multiset_union_diff_commute)
  1501       apply (rule mset_le_multiset_union_diff_commute)
  1502       apply (simp add: mset_le_single nth_mem_multiset_of)
  1502       apply (simp add: mset_le_single nth_mem_multiset_of)
  1503       done
  1503       done
  1504   qed
  1504   qed
  1595           case (add K x)
  1595           case (add K x)
  1596           from add.prems have "(x, a) \<in> r" by simp
  1596           from add.prems have "(x, a) \<in> r" by simp
  1597           with wf_hyp have "\<forall>M \<in> ?W. M + {#x#} \<in> ?W" by blast
  1597           with wf_hyp have "\<forall>M \<in> ?W. M + {#x#} \<in> ?W" by blast
  1598           moreover from add have "M0 + K \<in> ?W" by simp
  1598           moreover from add have "M0 + K \<in> ?W" by simp
  1599           ultimately have "(M0 + K) + {#x#} \<in> ?W" ..
  1599           ultimately have "(M0 + K) + {#x#} \<in> ?W" ..
  1600           then show "M0 + (K + {#x#}) \<in> ?W" by (simp only: add_assoc)
  1600           then show "M0 + (K + {#x#}) \<in> ?W" by (simp only: add.assoc)
  1601         qed
  1601         qed
  1602         then show "N \<in> ?W" by (simp only: N)
  1602         then show "N \<in> ?W" by (simp only: N)
  1603       qed
  1603       qed
  1604     qed
  1604     qed
  1605   } note tedious_reasoning = this
  1605   } note tedious_reasoning = this
  1650  apply (rule_tac x = M0 in exI, simp, clarify)
  1650  apply (rule_tac x = M0 in exI, simp, clarify)
  1651 apply (case_tac "a :# K")
  1651 apply (case_tac "a :# K")
  1652  apply (rule_tac x = I in exI)
  1652  apply (rule_tac x = I in exI)
  1653  apply (simp (no_asm))
  1653  apply (simp (no_asm))
  1654  apply (rule_tac x = "(K - {#a#}) + Ka" in exI)
  1654  apply (rule_tac x = "(K - {#a#}) + Ka" in exI)
  1655  apply (simp (no_asm_simp) add: add_assoc [symmetric])
  1655  apply (simp (no_asm_simp) add: add.assoc [symmetric])
  1656  apply (drule_tac f = "\<lambda>M. M - {#a#}" and x="?S + ?T" in arg_cong)
  1656  apply (drule_tac f = "\<lambda>M. M - {#a#}" and x="?S + ?T" in arg_cong)
  1657  apply (simp add: diff_union_single_conv)
  1657  apply (simp add: diff_union_single_conv)
  1658  apply (simp (no_asm_use) add: trans_def)
  1658  apply (simp (no_asm_use) add: trans_def)
  1659  apply blast
  1659  apply blast
  1660 apply (subgoal_tac "a :# I")
  1660 apply (subgoal_tac "a :# I")
  1693 apply (subgoal_tac
  1693 apply (subgoal_tac
  1694   "((I + {# x :# K. (x, a) \<in> r #}) + {# x :# K. (x, a) \<notin> r #},
  1694   "((I + {# x :# K. (x, a) \<in> r #}) + {# x :# K. (x, a) \<notin> r #},
  1695     (I + {# x :# K. (x, a) \<in> r #}) + J') \<in> mult r")
  1695     (I + {# x :# K. (x, a) \<in> r #}) + J') \<in> mult r")
  1696  prefer 2
  1696  prefer 2
  1697  apply force
  1697  apply force
  1698 apply (simp (no_asm_use) add: add_assoc [symmetric] mult_def)
  1698 apply (simp (no_asm_use) add: add.assoc [symmetric] mult_def)
  1699 apply (erule trancl_trans)
  1699 apply (erule trancl_trans)
  1700 apply (rule r_into_trancl)
  1700 apply (rule r_into_trancl)
  1701 apply (simp add: mult1_def set_of_def)
  1701 apply (simp add: mult1_def set_of_def)
  1702 apply (rule_tac x = a in exI)
  1702 apply (rule_tac x = a in exI)
  1703 apply (rule_tac x = "I + J'" in exI)
  1703 apply (rule_tac x = "I + J'" in exI)
  1758 lemma mult1_union: "(B, D) \<in> mult1 r ==> (C + B, C + D) \<in> mult1 r"
  1758 lemma mult1_union: "(B, D) \<in> mult1 r ==> (C + B, C + D) \<in> mult1 r"
  1759 apply (unfold mult1_def)
  1759 apply (unfold mult1_def)
  1760 apply auto
  1760 apply auto
  1761 apply (rule_tac x = a in exI)
  1761 apply (rule_tac x = a in exI)
  1762 apply (rule_tac x = "C + M0" in exI)
  1762 apply (rule_tac x = "C + M0" in exI)
  1763 apply (simp add: add_assoc)
  1763 apply (simp add: add.assoc)
  1764 done
  1764 done
  1765 
  1765 
  1766 lemma union_less_mono2: "B \<subset># D ==> C + B \<subset># C + (D::'a::order multiset)"
  1766 lemma union_less_mono2: "B \<subset># D ==> C + B \<subset># C + (D::'a::order multiset)"
  1767 apply (unfold less_multiset_def mult_def)
  1767 apply (unfold less_multiset_def mult_def)
  1768 apply (erule trancl_induct)
  1768 apply (erule trancl_induct)
  1769  apply (blast intro: mult1_union)
  1769  apply (blast intro: mult1_union)
  1770 apply (blast intro: mult1_union trancl_trans)
  1770 apply (blast intro: mult1_union trancl_trans)
  1771 done
  1771 done
  1772 
  1772 
  1773 lemma union_less_mono1: "B \<subset># D ==> B + C \<subset># D + (C::'a::order multiset)"
  1773 lemma union_less_mono1: "B \<subset># D ==> B + C \<subset># D + (C::'a::order multiset)"
  1774 apply (subst add_commute [of B C])
  1774 apply (subst add.commute [of B C])
  1775 apply (subst add_commute [of D C])
  1775 apply (subst add.commute [of D C])
  1776 apply (erule union_less_mono2)
  1776 apply (erule union_less_mono2)
  1777 done
  1777 done
  1778 
  1778 
  1779 lemma union_less_mono:
  1779 lemma union_less_mono:
  1780   "A \<subset># C ==> B \<subset># D ==> A + B \<subset># C + (D::'a::order multiset)"
  1780   "A \<subset># C ==> B \<subset># D ==> A + B \<subset># C + (D::'a::order multiset)"
  1939 subsection {* Legacy theorem bindings *}
  1939 subsection {* Legacy theorem bindings *}
  1940 
  1940 
  1941 lemmas multi_count_eq = multiset_eq_iff [symmetric]
  1941 lemmas multi_count_eq = multiset_eq_iff [symmetric]
  1942 
  1942 
  1943 lemma union_commute: "M + N = N + (M::'a multiset)"
  1943 lemma union_commute: "M + N = N + (M::'a multiset)"
  1944   by (fact add_commute)
  1944   by (fact add.commute)
  1945 
  1945 
  1946 lemma union_assoc: "(M + N) + K = M + (N + (K::'a multiset))"
  1946 lemma union_assoc: "(M + N) + K = M + (N + (K::'a multiset))"
  1947   by (fact add_assoc)
  1947   by (fact add.assoc)
  1948 
  1948 
  1949 lemma union_lcomm: "M + (N + K) = N + (M + (K::'a multiset))"
  1949 lemma union_lcomm: "M + (N + K) = N + (M + (K::'a multiset))"
  1950   by (fact add_left_commute)
  1950   by (fact add.left_commute)
  1951 
  1951 
  1952 lemmas union_ac = union_assoc union_commute union_lcomm
  1952 lemmas union_ac = union_assoc union_commute union_lcomm
  1953 
  1953 
  1954 lemma union_right_cancel: "M + K = N + K \<longleftrightarrow> M = (N::'a multiset)"
  1954 lemma union_right_cancel: "M + K = N + K \<longleftrightarrow> M = (N::'a multiset)"
  1955   by (fact add_right_cancel)
  1955   by (fact add_right_cancel)