src/HOL/Algebra/Divisibility.thy
changeset 60495 d7ff0a1df90a
parent 60397 f8a513fedb31
child 60515 484559628038
equal deleted inserted replaced
60492:db0f4f4c17c7 60495:d7ff0a1df90a
  2023 
  2023 
  2024 
  2024 
  2025 subsubsection {* Interpreting multisets as factorizations *}
  2025 subsubsection {* Interpreting multisets as factorizations *}
  2026 
  2026 
  2027 lemma (in monoid) mset_fmsetEx:
  2027 lemma (in monoid) mset_fmsetEx:
  2028   assumes elems: "\<And>X. X \<in> set_of Cs \<Longrightarrow> \<exists>x. P x \<and> X = assocs G x"
  2028   assumes elems: "\<And>X. X \<in> set_mset Cs \<Longrightarrow> \<exists>x. P x \<and> X = assocs G x"
  2029   shows "\<exists>cs. (\<forall>c \<in> set cs. P c) \<and> fmset G cs = Cs"
  2029   shows "\<exists>cs. (\<forall>c \<in> set cs. P c) \<and> fmset G cs = Cs"
  2030 proof -
  2030 proof -
  2031   have "\<exists>Cs'. Cs = multiset_of Cs'"
  2031   have "\<exists>Cs'. Cs = multiset_of Cs'"
  2032       by (rule surjE[OF surj_multiset_of], fast)
  2032       by (rule surjE[OF surj_multiset_of], fast)
  2033   from this obtain Cs'
  2033   from this obtain Cs'
  2060   qed
  2060   qed
  2061   thus ?thesis by (simp add: fmset_def)
  2061   thus ?thesis by (simp add: fmset_def)
  2062 qed
  2062 qed
  2063 
  2063 
  2064 lemma (in monoid) mset_wfactorsEx:
  2064 lemma (in monoid) mset_wfactorsEx:
  2065   assumes elems: "\<And>X. X \<in> set_of Cs 
  2065   assumes elems: "\<And>X. X \<in> set_mset Cs 
  2066                       \<Longrightarrow> \<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x"
  2066                       \<Longrightarrow> \<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x"
  2067   shows "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> fmset G cs = Cs"
  2067   shows "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> fmset G cs = Cs"
  2068 proof -
  2068 proof -
  2069   have "\<exists>cs. (\<forall>c\<in>set cs. c \<in> carrier G \<and> irreducible G c) \<and> fmset G cs = Cs"
  2069   have "\<exists>cs. (\<forall>c\<in>set cs. c \<in> carrier G \<and> irreducible G c) \<and> fmset G cs = Cs"
  2070       by (intro mset_fmsetEx, rule elems)
  2070       by (intro mset_fmsetEx, rule elems)
  2169   have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> fmset G cs = fmset G bs - fmset G as"
  2169   have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> fmset G cs = fmset G bs - fmset G as"
  2170   proof (intro mset_wfactorsEx, simp)
  2170   proof (intro mset_wfactorsEx, simp)
  2171     fix X
  2171     fix X
  2172     assume "count (fmset G as) X < count (fmset G bs) X"
  2172     assume "count (fmset G as) X < count (fmset G bs) X"
  2173     hence "0 < count (fmset G bs) X" by simp
  2173     hence "0 < count (fmset G bs) X" by simp
  2174     hence "X \<in> set_of (fmset G bs)" by simp
  2174     hence "X \<in> set_mset (fmset G bs)" by simp
  2175     hence "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def)
  2175     hence "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def)
  2176     hence "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct bs) auto
  2176     hence "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct bs) auto
  2177     from this obtain x
  2177     from this obtain x
  2178         where xbs: "x \<in> set bs"
  2178         where xbs: "x \<in> set bs"
  2179         and X: "X = assocs G x"
  2179         and X: "X = assocs G x"
  2593 
  2593 
  2594   have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> 
  2594   have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> 
  2595                fmset G cs = fmset G as #\<inter> fmset G bs"
  2595                fmset G cs = fmset G as #\<inter> fmset G bs"
  2596   proof (intro mset_wfactorsEx)
  2596   proof (intro mset_wfactorsEx)
  2597     fix X
  2597     fix X
  2598     assume "X \<in> set_of (fmset G as #\<inter> fmset G bs)"
  2598     assume "X \<in> set_mset (fmset G as #\<inter> fmset G bs)"
  2599     hence "X \<in> set_of (fmset G as)" by (simp add: multiset_inter_def)
  2599     hence "X \<in> set_mset (fmset G as)" by (simp add: multiset_inter_def)
  2600     hence "X \<in> set (map (assocs G) as)" by (simp add: fmset_def)
  2600     hence "X \<in> set (map (assocs G) as)" by (simp add: fmset_def)
  2601     hence "\<exists>x. X = assocs G x \<and> x \<in> set as" by (induct as) auto
  2601     hence "\<exists>x. X = assocs G x \<and> x \<in> set as" by (induct as) auto
  2602     from this obtain x
  2602     from this obtain x
  2603         where X: "X = assocs G x"
  2603         where X: "X = assocs G x"
  2604         and xas: "x \<in> set as"
  2604         and xas: "x \<in> set as"
  2671 
  2671 
  2672   have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> 
  2672   have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> 
  2673                fmset G cs = (fmset G as - fmset G bs) + fmset G bs"
  2673                fmset G cs = (fmset G as - fmset G bs) + fmset G bs"
  2674   proof (intro mset_wfactorsEx)
  2674   proof (intro mset_wfactorsEx)
  2675     fix X
  2675     fix X
  2676     assume "X \<in> set_of ((fmset G as - fmset G bs) + fmset G bs)"
  2676     assume "X \<in> set_mset ((fmset G as - fmset G bs) + fmset G bs)"
  2677     hence "X \<in> set_of (fmset G as) \<or> X \<in> set_of (fmset G bs)"
  2677     hence "X \<in> set_mset (fmset G as) \<or> X \<in> set_mset (fmset G bs)"
  2678        by (cases "X :# fmset G bs", simp, simp)
  2678        by (cases "X :# fmset G bs", simp, simp)
  2679     moreover
  2679     moreover
  2680     {
  2680     {
  2681       assume "X \<in> set_of (fmset G as)"
  2681       assume "X \<in> set_mset (fmset G as)"
  2682       hence "X \<in> set (map (assocs G) as)" by (simp add: fmset_def)
  2682       hence "X \<in> set (map (assocs G) as)" by (simp add: fmset_def)
  2683       hence "\<exists>x. x \<in> set as \<and> X = assocs G x" by (induct as) auto
  2683       hence "\<exists>x. x \<in> set as \<and> X = assocs G x" by (induct as) auto
  2684       from this obtain x
  2684       from this obtain x
  2685           where xas: "x \<in> set as"
  2685           where xas: "x \<in> set as"
  2686           and X: "X = assocs G x" by auto
  2686           and X: "X = assocs G x" by auto
  2691       from xcarr and xirr and X
  2691       from xcarr and xirr and X
  2692           have "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" by fast
  2692           have "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" by fast
  2693     }
  2693     }
  2694     moreover
  2694     moreover
  2695     {
  2695     {
  2696       assume "X \<in> set_of (fmset G bs)"
  2696       assume "X \<in> set_mset (fmset G bs)"
  2697       hence "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def)
  2697       hence "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def)
  2698       hence "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct as) auto
  2698       hence "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct as) auto
  2699       from this obtain x
  2699       from this obtain x
  2700           where xbs: "x \<in> set bs"
  2700           where xbs: "x \<in> set bs"
  2701           and X: "X = assocs G x" by auto
  2701           and X: "X = assocs G x" by auto