1052 by (induct xs) (simp_all add: ac_simps) |
1052 by (induct xs) (simp_all add: ac_simps) |
1053 |
1053 |
1054 lemma mset_map: "mset (map f xs) = image_mset f (mset xs)" |
1054 lemma mset_map: "mset (map f xs) = image_mset f (mset xs)" |
1055 by (induct xs) simp_all |
1055 by (induct xs) simp_all |
1056 |
1056 |
1057 definition mset_set :: "'a set \<Rightarrow> 'a multiset" |
1057 permanent_interpretation mset_set: folding "\<lambda>x M. {#x#} + M" "{#}" |
1058 where |
1058 defines mset_set = "folding.F (\<lambda>x M. {#x#} + M) {#}" |
1059 "mset_set = folding.F (\<lambda>x M. {#x#} + M) {#}" |
1059 by standard (simp add: fun_eq_iff ac_simps) |
1060 |
|
1061 interpretation mset_set: folding "\<lambda>x M. {#x#} + M" "{#}" |
|
1062 rewrites |
|
1063 "folding.F (\<lambda>x M. {#x#} + M) {#} = mset_set" |
|
1064 proof - |
|
1065 interpret comp_fun_commute "\<lambda>x M. {#x#} + M" |
|
1066 by standard (simp add: fun_eq_iff ac_simps) |
|
1067 show "folding (\<lambda>x M. {#x#} + M)" |
|
1068 by standard (fact comp_fun_commute) |
|
1069 from mset_set_def show "folding.F (\<lambda>x M. {#x#} + M) {#} = mset_set" .. |
|
1070 qed |
|
1071 |
1060 |
1072 lemma count_mset_set [simp]: |
1061 lemma count_mset_set [simp]: |
1073 "finite A \<Longrightarrow> x \<in> A \<Longrightarrow> count (mset_set A) x = 1" (is "PROP ?P") |
1062 "finite A \<Longrightarrow> x \<in> A \<Longrightarrow> count (mset_set A) x = 1" (is "PROP ?P") |
1074 "\<not> finite A \<Longrightarrow> count (mset_set A) x = 0" (is "PROP ?Q") |
1063 "\<not> finite A \<Longrightarrow> count (mset_set A) x = 0" (is "PROP ?Q") |
1075 "x \<notin> A \<Longrightarrow> count (mset_set A) x = 0" (is "PROP ?R") |
1064 "x \<notin> A \<Longrightarrow> count (mset_set A) x = 0" (is "PROP ?R") |
1216 notation Groups.one ("1") |
1205 notation Groups.one ("1") |
1217 |
1206 |
1218 context comm_monoid_add |
1207 context comm_monoid_add |
1219 begin |
1208 begin |
1220 |
1209 |
1221 definition msetsum :: "'a multiset \<Rightarrow> 'a" |
|
1222 where "msetsum = comm_monoid_mset.F plus 0" |
|
1223 |
|
1224 sublocale msetsum: comm_monoid_mset plus 0 |
1210 sublocale msetsum: comm_monoid_mset plus 0 |
1225 rewrites "comm_monoid_mset.F plus 0 = msetsum" |
1211 defines msetsum = msetsum.F .. |
1226 proof - |
|
1227 show "comm_monoid_mset plus 0" .. |
|
1228 from msetsum_def show "comm_monoid_mset.F plus 0 = msetsum" .. |
|
1229 qed |
|
1230 |
1212 |
1231 lemma (in semiring_1) msetsum_replicate_mset [simp]: |
1213 lemma (in semiring_1) msetsum_replicate_mset [simp]: |
1232 "msetsum (replicate_mset n a) = of_nat n * a" |
1214 "msetsum (replicate_mset n a) = of_nat n * a" |
1233 by (induct n) (simp_all add: algebra_simps) |
1215 by (induct n) (simp_all add: algebra_simps) |
1234 |
1216 |
1274 "SUM i :# A. b" == "CONST msetsum (CONST image_mset (\<lambda>i. b) A)" |
1256 "SUM i :# A. b" == "CONST msetsum (CONST image_mset (\<lambda>i. b) A)" |
1275 |
1257 |
1276 context comm_monoid_mult |
1258 context comm_monoid_mult |
1277 begin |
1259 begin |
1278 |
1260 |
1279 definition msetprod :: "'a multiset \<Rightarrow> 'a" |
|
1280 where "msetprod = comm_monoid_mset.F times 1" |
|
1281 |
|
1282 sublocale msetprod: comm_monoid_mset times 1 |
1261 sublocale msetprod: comm_monoid_mset times 1 |
1283 rewrites "comm_monoid_mset.F times 1 = msetprod" |
1262 defines msetprod = msetprod.F .. |
1284 proof - |
|
1285 show "comm_monoid_mset times 1" .. |
|
1286 show "comm_monoid_mset.F times 1 = msetprod" using msetprod_def .. |
|
1287 qed |
|
1288 |
1263 |
1289 lemma msetprod_empty: |
1264 lemma msetprod_empty: |
1290 "msetprod {#} = 1" |
1265 "msetprod {#} = 1" |
1291 by (fact msetprod.empty) |
1266 by (fact msetprod.empty) |
1292 |
1267 |