src/HOL/Library/Multiset.thy
changeset 60606 e5cb9271e339
parent 60515 484559628038
child 60607 d440af2e584f
     1.1 --- a/src/HOL/Library/Multiset.thy	Mon Jun 29 13:49:21 2015 +0200
     1.2 +++ b/src/HOL/Library/Multiset.thy	Mon Jun 29 15:36:29 2015 +0200
     1.3 @@ -14,9 +14,9 @@
     1.4  
     1.5  subsection \<open>The type of multisets\<close>
     1.6  
     1.7 -definition "multiset = {f :: 'a => nat. finite {x. f x > 0}}"
     1.8 -
     1.9 -typedef 'a multiset = "multiset :: ('a => nat) set"
    1.10 +definition "multiset = {f :: 'a \<Rightarrow> nat. finite {x. f x > 0}}"
    1.11 +
    1.12 +typedef 'a multiset = "multiset :: ('a \<Rightarrow> nat) set"
    1.13    morphisms count Abs_multiset
    1.14    unfolding multiset_def
    1.15  proof
    1.16 @@ -25,34 +25,27 @@
    1.17  
    1.18  setup_lifting type_definition_multiset
    1.19  
    1.20 -abbreviation Melem :: "'a => 'a multiset => bool"  ("(_/ :# _)" [50, 51] 50) where
    1.21 +abbreviation Melem :: "'a \<Rightarrow> 'a multiset \<Rightarrow> bool"  ("(_/ :# _)" [50, 51] 50) where
    1.22    "a :# M == 0 < count M a"
    1.23  
    1.24  notation (xsymbols)
    1.25    Melem (infix "\<in>#" 50)
    1.26  
    1.27 -lemma multiset_eq_iff:
    1.28 -  "M = N \<longleftrightarrow> (\<forall>a. count M a = count N a)"
    1.29 +lemma multiset_eq_iff: "M = N \<longleftrightarrow> (\<forall>a. count M a = count N a)"
    1.30    by (simp only: count_inject [symmetric] fun_eq_iff)
    1.31  
    1.32 -lemma multiset_eqI:
    1.33 -  "(\<And>x. count A x = count B x) \<Longrightarrow> A = B"
    1.34 +lemma multiset_eqI: "(\<And>x. count A x = count B x) \<Longrightarrow> A = B"
    1.35    using multiset_eq_iff by auto
    1.36  
    1.37 -text \<open>
    1.38 - \medskip Preservation of the representing set @{term multiset}.
    1.39 -\<close>
    1.40 -
    1.41 -lemma const0_in_multiset:
    1.42 -  "(\<lambda>a. 0) \<in> multiset"
    1.43 +text \<open>Preservation of the representing set @{term multiset}.\<close>
    1.44 +
    1.45 +lemma const0_in_multiset: "(\<lambda>a. 0) \<in> multiset"
    1.46    by (simp add: multiset_def)
    1.47  
    1.48 -lemma only1_in_multiset:
    1.49 -  "(\<lambda>b. if b = a then n else 0) \<in> multiset"
    1.50 +lemma only1_in_multiset: "(\<lambda>b. if b = a then n else 0) \<in> multiset"
    1.51    by (simp add: multiset_def)
    1.52  
    1.53 -lemma union_preserves_multiset:
    1.54 -  "M \<in> multiset \<Longrightarrow> N \<in> multiset \<Longrightarrow> (\<lambda>a. M a + N a) \<in> multiset"
    1.55 +lemma union_preserves_multiset: "M \<in> multiset \<Longrightarrow> N \<in> multiset \<Longrightarrow> (\<lambda>a. M a + N a) \<in> multiset"
    1.56    by (simp add: multiset_def)
    1.57  
    1.58  lemma diff_preserves_multiset:
    1.59 @@ -92,10 +85,10 @@
    1.60  abbreviation Mempty :: "'a multiset" ("{#}") where
    1.61    "Mempty \<equiv> 0"
    1.62  
    1.63 -lift_definition plus_multiset :: "'a multiset => 'a multiset => 'a multiset" is "\<lambda>M N. (\<lambda>a. M a + N a)"
    1.64 +lift_definition plus_multiset :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> 'a multiset" is "\<lambda>M N. (\<lambda>a. M a + N a)"
    1.65  by (rule union_preserves_multiset)
    1.66  
    1.67 -lift_definition minus_multiset :: "'a multiset => 'a multiset => 'a multiset" is "\<lambda> M N. \<lambda>a. M a - N a"
    1.68 +lift_definition minus_multiset :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> 'a multiset" is "\<lambda> M N. \<lambda>a. M a - N a"
    1.69  by (rule diff_preserves_multiset)
    1.70  
    1.71  instance
    1.72 @@ -103,11 +96,11 @@
    1.73  
    1.74  end
    1.75  
    1.76 -lift_definition single :: "'a => 'a multiset" is "\<lambda>a b. if b = a then 1 else 0"
    1.77 +lift_definition single :: "'a \<Rightarrow> 'a multiset" is "\<lambda>a b. if b = a then 1 else 0"
    1.78  by (rule only1_in_multiset)
    1.79  
    1.80  syntax
    1.81 -  "_multiset" :: "args => 'a multiset"    ("{#(_)#}")
    1.82 +  "_multiset" :: "args \<Rightarrow> 'a multiset"    ("{#(_)#}")
    1.83  translations
    1.84    "{#x, xs#}" == "{#x#} + {#xs#}"
    1.85    "{#x#}" == "CONST single x"
    1.86 @@ -133,7 +126,7 @@
    1.87  begin
    1.88  
    1.89  instance
    1.90 -by default (transfer, simp add: fun_eq_iff)+
    1.91 +  by default (transfer; simp add: fun_eq_iff)
    1.92  
    1.93  end
    1.94  
    1.95 @@ -153,27 +146,25 @@
    1.96    by (fact add_diff_cancel_left')
    1.97  
    1.98  lemma diff_right_commute:
    1.99 -  "(M::'a multiset) - N - Q = M - Q - N"
   1.100 +  fixes M N Q :: "'a multiset"
   1.101 +  shows "M - N - Q = M - Q - N"
   1.102    by (fact diff_right_commute)
   1.103  
   1.104  lemma diff_add:
   1.105 -  "(M::'a multiset) - (N + Q) = M - N - Q"
   1.106 +  fixes M N Q :: "'a multiset"
   1.107 +  shows "M - (N + Q) = M - N - Q"
   1.108    by (rule sym) (fact diff_diff_add)
   1.109  
   1.110 -lemma insert_DiffM:
   1.111 -  "x \<in># M \<Longrightarrow> {#x#} + (M - {#x#}) = M"
   1.112 +lemma insert_DiffM: "x \<in># M \<Longrightarrow> {#x#} + (M - {#x#}) = M"
   1.113    by (clarsimp simp: multiset_eq_iff)
   1.114  
   1.115 -lemma insert_DiffM2 [simp]:
   1.116 -  "x \<in># M \<Longrightarrow> M - {#x#} + {#x#} = M"
   1.117 +lemma insert_DiffM2 [simp]: "x \<in># M \<Longrightarrow> M - {#x#} + {#x#} = M"
   1.118    by (clarsimp simp: multiset_eq_iff)
   1.119  
   1.120 -lemma diff_union_swap:
   1.121 -  "a \<noteq> b \<Longrightarrow> M - {#a#} + {#b#} = M + {#b#} - {#a#}"
   1.122 +lemma diff_union_swap: "a \<noteq> b \<Longrightarrow> M - {#a#} + {#b#} = M + {#b#} - {#a#}"
   1.123    by (auto simp add: multiset_eq_iff)
   1.124  
   1.125 -lemma diff_union_single_conv:
   1.126 -  "a \<in># J \<Longrightarrow> I + J - {#a#} = I + (J - {#a#})"
   1.127 +lemma diff_union_single_conv: "a \<in># J \<Longrightarrow> I + J - {#a#} = I + (J - {#a#})"
   1.128    by (simp add: multiset_eq_iff)
   1.129  
   1.130  
   1.131 @@ -194,45 +185,39 @@
   1.132  lemma multi_self_add_other_not_self [simp]: "M = M + {#x#} \<longleftrightarrow> False"
   1.133    by (auto simp add: multiset_eq_iff)
   1.134  
   1.135 -lemma diff_single_trivial:
   1.136 -  "\<not> x \<in># M \<Longrightarrow> M - {#x#} = M"
   1.137 +lemma diff_single_trivial: "\<not> x \<in># M \<Longrightarrow> M - {#x#} = M"
   1.138    by (auto simp add: multiset_eq_iff)
   1.139  
   1.140 -lemma diff_single_eq_union:
   1.141 -  "x \<in># M \<Longrightarrow> M - {#x#} = N \<longleftrightarrow> M = N + {#x#}"
   1.142 +lemma diff_single_eq_union: "x \<in># M \<Longrightarrow> M - {#x#} = N \<longleftrightarrow> M = N + {#x#}"
   1.143    by auto
   1.144  
   1.145 -lemma union_single_eq_diff:
   1.146 -  "M + {#x#} = N \<Longrightarrow> M = N - {#x#}"
   1.147 +lemma union_single_eq_diff: "M + {#x#} = N \<Longrightarrow> M = N - {#x#}"
   1.148    by (auto dest: sym)
   1.149  
   1.150 -lemma union_single_eq_member:
   1.151 -  "M + {#x#} = N \<Longrightarrow> x \<in># N"
   1.152 +lemma union_single_eq_member: "M + {#x#} = N \<Longrightarrow> x \<in># N"
   1.153    by auto
   1.154  
   1.155 -lemma union_is_single:
   1.156 -  "M + N = {#a#} \<longleftrightarrow> M = {#a#} \<and> N={#} \<or> M = {#} \<and> N = {#a#}" (is "?lhs = ?rhs")
   1.157 +lemma union_is_single: "M + N = {#a#} \<longleftrightarrow> M = {#a#} \<and> N={#} \<or> M = {#} \<and> N = {#a#}"
   1.158 +  (is "?lhs = ?rhs")
   1.159  proof
   1.160 -  assume ?rhs then show ?lhs by auto
   1.161 -next
   1.162 -  assume ?lhs then show ?rhs
   1.163 -    by (simp add: multiset_eq_iff split:if_splits) (metis add_is_1)
   1.164 +  show ?lhs if ?rhs using that by auto
   1.165 +  show ?rhs if ?lhs
   1.166 +    using that by (simp add: multiset_eq_iff split: if_splits) (metis add_is_1)
   1.167  qed
   1.168  
   1.169 -lemma single_is_union:
   1.170 -  "{#a#} = M + N \<longleftrightarrow> {#a#} = M \<and> N = {#} \<or> M = {#} \<and> {#a#} = N"
   1.171 +lemma single_is_union: "{#a#} = M + N \<longleftrightarrow> {#a#} = M \<and> N = {#} \<or> M = {#} \<and> {#a#} = N"
   1.172    by (auto simp add: eq_commute [of "{#a#}" "M + N"] union_is_single)
   1.173  
   1.174  lemma add_eq_conv_diff:
   1.175 -  "M + {#a#} = N + {#b#} \<longleftrightarrow> M = N \<and> a = b \<or> M = N - {#a#} + {#b#} \<and> N = M - {#b#} + {#a#}"  (is "?lhs = ?rhs")
   1.176 +  "M + {#a#} = N + {#b#} \<longleftrightarrow> M = N \<and> a = b \<or> M = N - {#a#} + {#b#} \<and> N = M - {#b#} + {#a#}"
   1.177 +  (is "?lhs \<longleftrightarrow> ?rhs")
   1.178  (* shorter: by (simp add: multiset_eq_iff) fastforce *)
   1.179  proof
   1.180 -  assume ?rhs then show ?lhs
   1.181 -  by (auto simp add: add.assoc add.commute [of "{#b#}"])
   1.182 -    (drule sym, simp add: add.assoc [symmetric])
   1.183 -next
   1.184 -  assume ?lhs
   1.185 -  show ?rhs
   1.186 +  show ?lhs if ?rhs
   1.187 +    using that
   1.188 +    by (auto simp add: add.assoc add.commute [of "{#b#}"])
   1.189 +      (drule sym, simp add: add.assoc [symmetric])
   1.190 +  show ?rhs if ?lhs
   1.191    proof (cases "a = b")
   1.192      case True with \<open>?lhs\<close> show ?thesis by simp
   1.193    next
   1.194 @@ -261,12 +246,12 @@
   1.195      (M = N \<and> a = b \<or> (\<exists>K. M = K + {#b#} \<and> N = K + {#a#}))"
   1.196    by (auto simp add: add_eq_conv_diff)
   1.197  
   1.198 -lemma multi_member_split:
   1.199 -  "x \<in># M \<Longrightarrow> \<exists>A. M = A + {#x#}"
   1.200 +lemma multi_member_split: "x \<in># M \<Longrightarrow> \<exists>A. M = A + {#x#}"
   1.201    by (rule_tac x = "M - {#x#}" in exI, simp)
   1.202  
   1.203  lemma multiset_add_sub_el_shuffle:
   1.204 -  assumes "c \<in># B" and "b \<noteq> c"
   1.205 +  assumes "c \<in># B"
   1.206 +    and "b \<noteq> c"
   1.207    shows "B - {#c#} + {#b#} = B + {#b#} - {#c#}"
   1.208  proof -
   1.209    from \<open>c \<in># B\<close> obtain A where B: "B = A + {#c#}"
   1.210 @@ -291,15 +276,13 @@
   1.211  
   1.212  notation (xsymbols) subset_mset (infix "\<subset>#" 50)
   1.213  
   1.214 -interpretation subset_mset: ordered_ab_semigroup_add_imp_le "op +" "op -" "op <=#" "op <#"
   1.215 +interpretation subset_mset: ordered_ab_semigroup_add_imp_le "op +" "op -" "op \<subseteq>#" "op \<subset>#"
   1.216    by default (auto simp add: subset_mset_def subseteq_mset_def multiset_eq_iff intro: order_trans antisym)
   1.217  
   1.218 -lemma mset_less_eqI:
   1.219 -  "(\<And>x. count A x \<le> count B x) \<Longrightarrow> A \<le># B"
   1.220 +lemma mset_less_eqI: "(\<And>x. count A x \<le> count B x) \<Longrightarrow> A \<le># B"
   1.221    by (simp add: subseteq_mset_def)
   1.222  
   1.223 -lemma mset_le_exists_conv:
   1.224 -  "(A::'a multiset) \<le># B \<longleftrightarrow> (\<exists>C. B = A + C)"
   1.225 +lemma mset_le_exists_conv: "(A::'a multiset) \<le># B \<longleftrightarrow> (\<exists>C. B = A + C)"
   1.226  apply (unfold subseteq_mset_def, rule iffI, rule_tac x = "B - A" in exI)
   1.227  apply (auto intro: multiset_eq_iff [THEN iffD2])
   1.228  done
   1.229 @@ -307,36 +290,32 @@
   1.230  interpretation subset_mset: ordered_cancel_comm_monoid_diff  "op +" "op -" 0 "op \<le>#" "op <#"
   1.231    by default (simp, fact mset_le_exists_conv)
   1.232  
   1.233 -lemma mset_le_mono_add_right_cancel [simp]:
   1.234 -  "(A::'a multiset) + C \<le># B + C \<longleftrightarrow> A \<le># B"
   1.235 +lemma mset_le_mono_add_right_cancel [simp]: "(A::'a multiset) + C \<le># B + C \<longleftrightarrow> A \<le># B"
   1.236    by (fact subset_mset.add_le_cancel_right)
   1.237  
   1.238 -lemma mset_le_mono_add_left_cancel [simp]:
   1.239 -  "C + (A::'a multiset) \<le># C + B \<longleftrightarrow> A \<le># B"
   1.240 +lemma mset_le_mono_add_left_cancel [simp]: "C + (A::'a multiset) \<le># C + B \<longleftrightarrow> A \<le># B"
   1.241    by (fact subset_mset.add_le_cancel_left)
   1.242  
   1.243 -lemma mset_le_mono_add:
   1.244 -  "(A::'a multiset) \<le># B \<Longrightarrow> C \<le># D \<Longrightarrow> A + C \<le># B + D"
   1.245 +lemma mset_le_mono_add: "(A::'a multiset) \<le># B \<Longrightarrow> C \<le># D \<Longrightarrow> A + C \<le># B + D"
   1.246    by (fact subset_mset.add_mono)
   1.247  
   1.248 -lemma mset_le_add_left [simp]:
   1.249 -  "(A::'a multiset) \<le># A + B"
   1.250 +lemma mset_le_add_left [simp]: "(A::'a multiset) \<le># A + B"
   1.251    unfolding subseteq_mset_def by auto
   1.252  
   1.253 -lemma mset_le_add_right [simp]:
   1.254 -  "B \<le># (A::'a multiset) + B"
   1.255 +lemma mset_le_add_right [simp]: "B \<le># (A::'a multiset) + B"
   1.256    unfolding subseteq_mset_def by auto
   1.257  
   1.258 -lemma mset_le_single:
   1.259 -  "a :# B \<Longrightarrow> {#a#} \<le># B"
   1.260 +lemma mset_le_single: "a :# B \<Longrightarrow> {#a#} \<le># B"
   1.261    by (simp add: subseteq_mset_def)
   1.262  
   1.263  lemma multiset_diff_union_assoc:
   1.264 -  "C \<le># B \<Longrightarrow> (A::'a multiset) + B - C = A + (B - C)"
   1.265 +  fixes A B C D :: "'a multiset"
   1.266 +  shows "C \<le># B \<Longrightarrow> A + B - C = A + (B - C)"
   1.267    by (simp add: subset_mset.diff_add_assoc)
   1.268  
   1.269  lemma mset_le_multiset_union_diff_commute:
   1.270 -  "B \<le># A \<Longrightarrow> (A::'a multiset) - B + C = A + C - B"
   1.271 +  fixes A B C D :: "'a multiset"
   1.272 +  shows "B \<le># A \<Longrightarrow> A - B + C = A + C - B"
   1.273  by (simp add: subset_mset.add_diff_assoc2)
   1.274  
   1.275  lemma diff_le_self[simp]: "(M::'a multiset) - N \<le># M"
   1.276 @@ -387,12 +366,10 @@
   1.277  lemma mset_less_add_bothsides: "N + {#x#} <# M + {#x#} \<Longrightarrow> N <# M"
   1.278    by (fact subset_mset.add_less_imp_less_right)
   1.279  
   1.280 -lemma mset_less_empty_nonempty:
   1.281 -  "{#} <# S \<longleftrightarrow> S \<noteq> {#}"
   1.282 +lemma mset_less_empty_nonempty: "{#} <# S \<longleftrightarrow> S \<noteq> {#}"
   1.283    by (auto simp: subset_mset_def subseteq_mset_def)
   1.284  
   1.285 -lemma mset_less_diff_self:
   1.286 -  "c \<in># B \<Longrightarrow> B - {#c#} <# B"
   1.287 +lemma mset_less_diff_self: "c \<in># B \<Longrightarrow> B - {#c#} <# B"
   1.288    by (auto simp: subset_mset_def subseteq_mset_def multiset_eq_iff)
   1.289  
   1.290  
   1.291 @@ -410,7 +387,8 @@
   1.292  
   1.293  
   1.294  lemma multiset_inter_count [simp]:
   1.295 -  "count ((A::'a multiset) #\<inter> B) x = min (count A x) (count B x)"
   1.296 +  fixes A B :: "'a multiset"
   1.297 +  shows "count (A #\<inter> B) x = min (count A x) (count B x)"
   1.298    by (simp add: multiset_inter_def)
   1.299  
   1.300  lemma multiset_inter_single: "a \<noteq> b \<Longrightarrow> {#a#} #\<inter> {#b#} = {#}"
   1.301 @@ -429,28 +407,22 @@
   1.302      by auto
   1.303  qed
   1.304  
   1.305 -lemma empty_inter [simp]:
   1.306 -  "{#} #\<inter> M = {#}"
   1.307 +lemma empty_inter [simp]: "{#} #\<inter> M = {#}"
   1.308    by (simp add: multiset_eq_iff)
   1.309  
   1.310 -lemma inter_empty [simp]:
   1.311 -  "M #\<inter> {#} = {#}"
   1.312 +lemma inter_empty [simp]: "M #\<inter> {#} = {#}"
   1.313    by (simp add: multiset_eq_iff)
   1.314  
   1.315 -lemma inter_add_left1:
   1.316 -  "\<not> x \<in># N \<Longrightarrow> (M + {#x#}) #\<inter> N = M #\<inter> N"
   1.317 +lemma inter_add_left1: "\<not> x \<in># N \<Longrightarrow> (M + {#x#}) #\<inter> N = M #\<inter> N"
   1.318    by (simp add: multiset_eq_iff)
   1.319  
   1.320 -lemma inter_add_left2:
   1.321 -  "x \<in># N \<Longrightarrow> (M + {#x#}) #\<inter> N = (M #\<inter> (N - {#x#})) + {#x#}"
   1.322 +lemma inter_add_left2: "x \<in># N \<Longrightarrow> (M + {#x#}) #\<inter> N = (M #\<inter> (N - {#x#})) + {#x#}"
   1.323    by (simp add: multiset_eq_iff)
   1.324  
   1.325 -lemma inter_add_right1:
   1.326 -  "\<not> x \<in># N \<Longrightarrow> N #\<inter> (M + {#x#}) = N #\<inter> M"
   1.327 +lemma inter_add_right1: "\<not> x \<in># N \<Longrightarrow> N #\<inter> (M + {#x#}) = N #\<inter> M"
   1.328    by (simp add: multiset_eq_iff)
   1.329  
   1.330 -lemma inter_add_right2:
   1.331 -  "x \<in># N \<Longrightarrow> N #\<inter> (M + {#x#}) = ((N - {#x#}) #\<inter> M) + {#x#}"
   1.332 +lemma inter_add_right2: "x \<in># N \<Longrightarrow> N #\<inter> (M + {#x#}) = ((N - {#x#}) #\<inter> M) + {#x#}"
   1.333    by (simp add: multiset_eq_iff)
   1.334  
   1.335  
   1.336 @@ -465,32 +437,25 @@
   1.337      by default (auto simp add: sup_subset_mset_def subseteq_mset_def aux)
   1.338  qed
   1.339  
   1.340 -lemma sup_subset_mset_count [simp]:
   1.341 -  "count (A #\<union> B) x = max (count A x) (count B x)"
   1.342 +lemma sup_subset_mset_count [simp]: "count (A #\<union> B) x = max (count A x) (count B x)"
   1.343    by (simp add: sup_subset_mset_def)
   1.344  
   1.345 -lemma empty_sup [simp]:
   1.346 -  "{#} #\<union> M = M"
   1.347 +lemma empty_sup [simp]: "{#} #\<union> M = M"
   1.348    by (simp add: multiset_eq_iff)
   1.349  
   1.350 -lemma sup_empty [simp]:
   1.351 -  "M #\<union> {#} = M"
   1.352 +lemma sup_empty [simp]: "M #\<union> {#} = M"
   1.353    by (simp add: multiset_eq_iff)
   1.354  
   1.355 -lemma sup_add_left1:
   1.356 -  "\<not> x \<in># N \<Longrightarrow> (M + {#x#}) #\<union> N = (M #\<union> N) + {#x#}"
   1.357 +lemma sup_add_left1: "\<not> x \<in># N \<Longrightarrow> (M + {#x#}) #\<union> N = (M #\<union> N) + {#x#}"
   1.358    by (simp add: multiset_eq_iff)
   1.359  
   1.360 -lemma sup_add_left2:
   1.361 -  "x \<in># N \<Longrightarrow> (M + {#x#}) #\<union> N = (M #\<union> (N - {#x#})) + {#x#}"
   1.362 +lemma sup_add_left2: "x \<in># N \<Longrightarrow> (M + {#x#}) #\<union> N = (M #\<union> (N - {#x#})) + {#x#}"
   1.363    by (simp add: multiset_eq_iff)
   1.364  
   1.365 -lemma sup_add_right1:
   1.366 -  "\<not> x \<in># N \<Longrightarrow> N #\<union> (M + {#x#}) = (N #\<union> M) + {#x#}"
   1.367 +lemma sup_add_right1: "\<not> x \<in># N \<Longrightarrow> N #\<union> (M + {#x#}) = (N #\<union> M) + {#x#}"
   1.368    by (simp add: multiset_eq_iff)
   1.369  
   1.370 -lemma sup_add_right2:
   1.371 -  "x \<in># N \<Longrightarrow> N #\<union> (M + {#x#}) = ((N - {#x#}) #\<union> M) + {#x#}"
   1.372 +lemma sup_add_right2: "x \<in># N \<Longrightarrow> N #\<union> (M + {#x#}) = ((N - {#x#}) #\<union> M) + {#x#}"
   1.373    by (simp add: multiset_eq_iff)
   1.374  
   1.375  subsubsection \<open>Subset is an order\<close>
   1.376 @@ -504,34 +469,29 @@
   1.377  is "\<lambda>P M. \<lambda>x. if P x then M x else 0"
   1.378  by (rule filter_preserves_multiset)
   1.379  
   1.380 -lemma count_filter_mset [simp]:
   1.381 -  "count (filter_mset P M) a = (if P a then count M a else 0)"
   1.382 +lemma count_filter_mset [simp]: "count (filter_mset P M) a = (if P a then count M a else 0)"
   1.383    by (simp add: filter_mset.rep_eq)
   1.384  
   1.385 -lemma filter_empty_mset [simp]:
   1.386 -  "filter_mset P {#} = {#}"
   1.387 +lemma filter_empty_mset [simp]: "filter_mset P {#} = {#}"
   1.388    by (rule multiset_eqI) simp
   1.389  
   1.390 -lemma filter_single_mset [simp]:
   1.391 -  "filter_mset P {#x#} = (if P x then {#x#} else {#})"
   1.392 +lemma filter_single_mset [simp]: "filter_mset P {#x#} = (if P x then {#x#} else {#})"
   1.393    by (rule multiset_eqI) simp
   1.394  
   1.395 -lemma filter_union_mset [simp]:
   1.396 -  "filter_mset P (M + N) = filter_mset P M + filter_mset P N"
   1.397 +lemma filter_union_mset [simp]: "filter_mset P (M + N) = filter_mset P M + filter_mset P N"
   1.398    by (rule multiset_eqI) simp
   1.399  
   1.400 -lemma filter_diff_mset [simp]:
   1.401 -  "filter_mset P (M - N) = filter_mset P M - filter_mset P N"
   1.402 +lemma filter_diff_mset [simp]: "filter_mset P (M - N) = filter_mset P M - filter_mset P N"
   1.403    by (rule multiset_eqI) simp
   1.404  
   1.405 -lemma filter_inter_mset [simp]:
   1.406 -  "filter_mset P (M #\<inter> N) = filter_mset P M #\<inter> filter_mset P N"
   1.407 +lemma filter_inter_mset [simp]: "filter_mset P (M #\<inter> N) = filter_mset P M #\<inter> filter_mset P N"
   1.408    by (rule multiset_eqI) simp
   1.409  
   1.410  lemma multiset_filter_subset[simp]: "filter_mset f M \<le># M"
   1.411    by (simp add: mset_less_eqI)
   1.412  
   1.413 -lemma multiset_filter_mono: assumes "A \<le># B"
   1.414 +lemma multiset_filter_mono:
   1.415 +  assumes "A \<le># B"
   1.416    shows "filter_mset f A \<le># filter_mset f B"
   1.417  proof -
   1.418    from assms[unfolded mset_le_exists_conv]
   1.419 @@ -549,8 +509,8 @@
   1.420  
   1.421  subsubsection \<open>Set of elements\<close>
   1.422  
   1.423 -definition set_mset :: "'a multiset => 'a set" where
   1.424 -  "set_mset M = {x. x :# M}"
   1.425 +definition set_mset :: "'a multiset \<Rightarrow> 'a set"
   1.426 +  where "set_mset M = {x. x :# M}"
   1.427  
   1.428  lemma set_mset_empty [simp]: "set_mset {#} = {}"
   1.429  by (simp add: set_mset_def)
   1.430 @@ -595,10 +555,13 @@
   1.431  
   1.432  lemmas size_multiset_eq = size_multiset_def[unfolded wcount_def]
   1.433  
   1.434 -instantiation multiset :: (type) size begin
   1.435 +instantiation multiset :: (type) size
   1.436 +begin
   1.437 +
   1.438  definition size_multiset where
   1.439    size_multiset_overloaded_def: "size_multiset = Multiset.size_multiset (\<lambda>_. 0)"
   1.440  instance ..
   1.441 +
   1.442  end
   1.443  
   1.444  lemmas size_multiset_overloaded_eq =
   1.445 @@ -642,7 +605,7 @@
   1.446  lemma nonempty_has_size: "(S \<noteq> {#}) = (0 < size S)"
   1.447  by (metis gr0I gr_implies_not0 size_empty size_eq_0_iff_empty)
   1.448  
   1.449 -lemma size_eq_Suc_imp_elem: "size M = Suc n ==> \<exists>a. a :# M"
   1.450 +lemma size_eq_Suc_imp_elem: "size M = Suc n \<Longrightarrow> \<exists>a. a :# M"
   1.451  apply (unfold size_multiset_overloaded_eq)
   1.452  apply (drule setsum_SucD)
   1.453  apply auto
   1.454 @@ -658,12 +621,14 @@
   1.455    then show ?thesis by blast
   1.456  qed
   1.457  
   1.458 -lemma size_mset_mono: assumes "A \<le># B"
   1.459 -  shows "size A \<le> size(B::_ multiset)"
   1.460 +lemma size_mset_mono:
   1.461 +  fixes A B :: "'a multiset"
   1.462 +  assumes "A \<le># B"
   1.463 +  shows "size A \<le> size B"
   1.464  proof -
   1.465    from assms[unfolded mset_le_exists_conv]
   1.466    obtain C where B: "B = A + C" by auto
   1.467 -  show ?thesis unfolding B by (induct C, auto)
   1.468 +  show ?thesis unfolding B by (induct C) auto
   1.469  qed
   1.470  
   1.471  lemma size_filter_mset_lesseq[simp]: "size (filter_mset f M) \<le> size M"
   1.472 @@ -746,10 +711,10 @@
   1.473  done
   1.474  
   1.475  lemma multi_subset_induct [consumes 2, case_names empty add]:
   1.476 -assumes "F \<le># A"
   1.477 -  and empty: "P {#}"
   1.478 -  and insert: "\<And>a F. a \<in># A \<Longrightarrow> P F \<Longrightarrow> P (F + {#a#})"
   1.479 -shows "P F"
   1.480 +  assumes "F \<le># A"
   1.481 +    and empty: "P {#}"
   1.482 +    and insert: "\<And>a F. a \<in># A \<Longrightarrow> P F \<Longrightarrow> P (F + {#a#})"
   1.483 +  shows "P F"
   1.484  proof -
   1.485    from \<open>F \<le># A\<close>
   1.486    show ?thesis
   1.487 @@ -774,15 +739,13 @@
   1.488  where
   1.489    "fold_mset f s M = Finite_Set.fold (\<lambda>x. f x ^^ count M x) s (set_mset M)"
   1.490  
   1.491 -lemma fold_mset_empty [simp]:
   1.492 -  "fold_mset f s {#} = s"
   1.493 +lemma fold_mset_empty [simp]: "fold_mset f s {#} = s"
   1.494    by (simp add: fold_mset_def)
   1.495  
   1.496  context comp_fun_commute
   1.497  begin
   1.498  
   1.499 -lemma fold_mset_insert:
   1.500 -  "fold_mset f s (M + {#x#}) = f x (fold_mset f s M)"
   1.501 +lemma fold_mset_insert: "fold_mset f s (M + {#x#}) = f x (fold_mset f s M)"
   1.502  proof -
   1.503    interpret mset: comp_fun_commute "\<lambda>y. f y ^^ count M y"
   1.504      by (fact comp_fun_commute_funpow)
   1.505 @@ -808,19 +771,16 @@
   1.506    qed
   1.507  qed
   1.508  
   1.509 -corollary fold_mset_single [simp]:
   1.510 -  "fold_mset f s {#x#} = f x s"
   1.511 +corollary fold_mset_single [simp]: "fold_mset f s {#x#} = f x s"
   1.512  proof -
   1.513    have "fold_mset f s ({#} + {#x#}) = f x s" by (simp only: fold_mset_insert) simp
   1.514    then show ?thesis by simp
   1.515  qed
   1.516  
   1.517 -lemma fold_mset_fun_left_comm:
   1.518 -  "f x (fold_mset f s M) = fold_mset f (f x s) M"
   1.519 +lemma fold_mset_fun_left_comm: "f x (fold_mset f s M) = fold_mset f (f x s) M"
   1.520    by (induct M) (simp_all add: fold_mset_insert fun_left_comm)
   1.521  
   1.522 -lemma fold_mset_union [simp]:
   1.523 -  "fold_mset f s (M + N) = fold_mset f (fold_mset f s M) N"
   1.524 +lemma fold_mset_union [simp]: "fold_mset f s (M + N) = fold_mset f (fold_mset f s M) N"
   1.525  proof (induct M)
   1.526    case empty then show ?case by simp
   1.527  next
   1.528 @@ -832,10 +792,11 @@
   1.529  
   1.530  lemma fold_mset_fusion:
   1.531    assumes "comp_fun_commute g"
   1.532 -  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")
   1.533 +    and *: "\<And>x y. h (g x y) = f x (h y)"
   1.534 +  shows "h (fold_mset g w A) = fold_mset f (h w) A"
   1.535  proof -
   1.536    interpret comp_fun_commute g by (fact assms)
   1.537 -  show "PROP ?P" by (induct A) auto
   1.538 +  from * show ?thesis by (induct A) auto
   1.539  qed
   1.540  
   1.541  end
   1.542 @@ -857,8 +818,7 @@
   1.543  definition image_mset :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a multiset \<Rightarrow> 'b multiset" where
   1.544    "image_mset f = fold_mset (plus o single o f) {#}"
   1.545  
   1.546 -lemma comp_fun_commute_mset_image:
   1.547 -  "comp_fun_commute (plus o single o f)"
   1.548 +lemma comp_fun_commute_mset_image: "comp_fun_commute (plus o single o f)"
   1.549  proof
   1.550  qed (simp add: ac_simps fun_eq_iff)
   1.551  
   1.552 @@ -872,35 +832,30 @@
   1.553    show ?thesis by (simp add: image_mset_def)
   1.554  qed
   1.555  
   1.556 -lemma image_mset_union [simp]:
   1.557 -  "image_mset f (M + N) = image_mset f M + image_mset f N"
   1.558 +lemma image_mset_union [simp]: "image_mset f (M + N) = image_mset f M + image_mset f N"
   1.559  proof -
   1.560    interpret comp_fun_commute "plus o single o f"
   1.561      by (fact comp_fun_commute_mset_image)
   1.562    show ?thesis by (induct N) (simp_all add: image_mset_def ac_simps)
   1.563  qed
   1.564  
   1.565 -corollary image_mset_insert:
   1.566 -  "image_mset f (M + {#a#}) = image_mset f M + {#f a#}"
   1.567 +corollary image_mset_insert: "image_mset f (M + {#a#}) = image_mset f M + {#f a#}"
   1.568    by simp
   1.569  
   1.570 -lemma set_image_mset [simp]:
   1.571 -  "set_mset (image_mset f M) = image f (set_mset M)"
   1.572 +lemma set_image_mset [simp]: "set_mset (image_mset f M) = image f (set_mset M)"
   1.573    by (induct M) simp_all
   1.574  
   1.575 -lemma size_image_mset [simp]:
   1.576 -  "size (image_mset f M) = size M"
   1.577 +lemma size_image_mset [simp]: "size (image_mset f M) = size M"
   1.578    by (induct M) simp_all
   1.579  
   1.580 -lemma image_mset_is_empty_iff [simp]:
   1.581 -  "image_mset f M = {#} \<longleftrightarrow> M = {#}"
   1.582 +lemma image_mset_is_empty_iff [simp]: "image_mset f M = {#} \<longleftrightarrow> M = {#}"
   1.583    by (cases M) auto
   1.584  
   1.585  syntax
   1.586    "_comprehension1_mset" :: "'a \<Rightarrow> 'b \<Rightarrow> 'b multiset \<Rightarrow> 'a multiset"
   1.587        ("({#_/. _ :# _#})")
   1.588  translations
   1.589 -  "{#e. x:#M#}" == "CONST image_mset (%x. e) M"
   1.590 +  "{#e. x:#M#}" == "CONST image_mset (\<lambda>x. e) M"
   1.591  
   1.592  syntax (xsymbols)
   1.593    "_comprehension2_mset" :: "'a \<Rightarrow> 'b \<Rightarrow> 'b multiset \<Rightarrow> 'a multiset"
   1.594 @@ -912,13 +867,13 @@
   1.595    "_comprehension3_mset" :: "'a \<Rightarrow> 'b \<Rightarrow> 'b multiset \<Rightarrow> bool \<Rightarrow> 'a multiset"
   1.596        ("({#_/ | _ :# _./ _#})")
   1.597  translations
   1.598 -  "{#e | x:#M. P#}" => "{#e. x :# {# x:#M. P#}#}"
   1.599 +  "{#e | x:#M. P#}" \<rightharpoonup> "{#e. x :# {# x:#M. P#}#}"
   1.600  
   1.601  syntax
   1.602    "_comprehension4_mset" :: "'a \<Rightarrow> 'b \<Rightarrow> 'b multiset \<Rightarrow> bool \<Rightarrow> 'a multiset"
   1.603        ("({#_/ | _ \<in># _./ _#})")
   1.604  translations
   1.605 -  "{#e | x\<in>#M. P#}" => "{#e. x \<in># {# x\<in>#M. P#}#}"
   1.606 +  "{#e | x\<in>#M. P#}" \<rightharpoonup> "{#e. x \<in># {# x\<in>#M. P#}#}"
   1.607  
   1.608  text \<open>
   1.609    This allows to write not just filters like @{term "{#x:#M. x<c#}"}
   1.610 @@ -990,12 +945,10 @@
   1.611  lemma size_mset [simp]: "size (mset xs) = length xs"
   1.612    by (induct xs) simp_all
   1.613  
   1.614 -lemma mset_append [simp]:
   1.615 -  "mset (xs @ ys) = mset xs + mset ys"
   1.616 +lemma mset_append [simp]: "mset (xs @ ys) = mset xs + mset ys"
   1.617    by (induct xs arbitrary: ys) (auto simp: ac_simps)
   1.618  
   1.619 -lemma mset_filter:
   1.620 -  "mset (filter P xs) = {#x :# mset xs. P x #}"
   1.621 +lemma mset_filter: "mset (filter P xs) = {#x :# mset xs. P x #}"
   1.622    by (induct xs) simp_all
   1.623  
   1.624  lemma mset_rev [simp]:
   1.625 @@ -1015,7 +968,7 @@
   1.626  by (induct x) auto
   1.627  
   1.628  lemma distinct_count_atmost_1:
   1.629 -  "distinct x = (! a. count (mset x) a = (if a \<in> set x then 1 else 0))"
   1.630 +  "distinct x = (\<forall>a. count (mset x) a = (if a \<in> set x then 1 else 0))"
   1.631  apply (induct x, simp, rule iffI, simp_all)
   1.632  apply (rename_tac a b)
   1.633  apply (rule conjI)
   1.634 @@ -1024,8 +977,7 @@
   1.635  apply (erule_tac x = aa in allE, simp)
   1.636  done
   1.637  
   1.638 -lemma mset_eq_setD:
   1.639 -  "mset xs = mset ys \<Longrightarrow> set xs = set ys"
   1.640 +lemma mset_eq_setD: "mset xs = mset ys \<Longrightarrow> set xs = set ys"
   1.641  by (rule) (auto simp add:multiset_eq_iff set_count_greater_0)
   1.642  
   1.643  lemma set_eq_iff_mset_eq_distinct:
   1.644 @@ -1042,8 +994,7 @@
   1.645  apply simp
   1.646  done
   1.647  
   1.648 -lemma mset_compl_union [simp]:
   1.649 -  "mset [x\<leftarrow>xs. P x] + mset [x\<leftarrow>xs. \<not>P x] = mset xs"
   1.650 +lemma mset_compl_union [simp]: "mset [x\<leftarrow>xs. P x] + mset [x\<leftarrow>xs. \<not>P x] = mset xs"
   1.651    by (induct xs) (auto simp: ac_simps)
   1.652  
   1.653  lemma nth_mem_mset: "i < length ls \<Longrightarrow> (ls ! i) :# mset ls"
   1.654 @@ -1053,8 +1004,7 @@
   1.655   apply auto
   1.656  done
   1.657  
   1.658 -lemma mset_remove1[simp]:
   1.659 -  "mset (remove1 a xs) = mset xs - {#a#}"
   1.660 +lemma mset_remove1[simp]: "mset (remove1 a xs) = mset xs - {#a#}"
   1.661  by (induct xs) (auto simp add: multiset_eq_iff)
   1.662  
   1.663  lemma mset_eq_length:
   1.664 @@ -1071,7 +1021,7 @@
   1.665    assumes f: "\<And>x y. x \<in> set xs \<Longrightarrow> y \<in> set xs \<Longrightarrow> f x \<circ> f y = f y \<circ> f x"
   1.666      and equiv: "mset xs = mset ys"
   1.667    shows "List.fold f xs = List.fold f ys"
   1.668 -using f equiv [symmetric]
   1.669 +  using f equiv [symmetric]
   1.670  proof (induct xs arbitrary: ys)
   1.671    case Nil then show ?case by simp
   1.672  next
   1.673 @@ -1085,12 +1035,10 @@
   1.674    ultimately show ?case by simp
   1.675  qed
   1.676  
   1.677 -lemma mset_insort [simp]:
   1.678 -  "mset (insort x xs) = mset xs + {#x#}"
   1.679 +lemma mset_insort [simp]: "mset (insort x xs) = mset xs + {#x#}"
   1.680    by (induct xs) (simp_all add: ac_simps)
   1.681  
   1.682 -lemma mset_map:
   1.683 -  "mset (map f xs) = image_mset f (mset xs)"
   1.684 +lemma mset_map: "mset (map f xs) = image_mset f (mset xs)"
   1.685    by (induct xs) simp_all
   1.686  
   1.687  definition mset_set :: "'a set \<Rightarrow> 'a multiset"
   1.688 @@ -1111,15 +1059,12 @@
   1.689    "\<not> finite A \<Longrightarrow> count (mset_set A) x = 0" (is "PROP ?Q")
   1.690    "x \<notin> A \<Longrightarrow> count (mset_set A) x = 0" (is "PROP ?R")
   1.691  proof -
   1.692 -  { fix A
   1.693 -    assume "x \<notin> A"
   1.694 -    have "count (mset_set A) x = 0"
   1.695 -    proof (cases "finite A")
   1.696 -      case False then show ?thesis by simp
   1.697 -    next
   1.698 -      case True from True \<open>x \<notin> A\<close> show ?thesis by (induct A) auto
   1.699 -    qed
   1.700 -  } note * = this
   1.701 +  have *: "count (mset_set A) x = 0" if "x \<notin> A" for A
   1.702 +  proof (cases "finite A")
   1.703 +    case False then show ?thesis by simp
   1.704 +  next
   1.705 +    case True from True \<open>x \<notin> A\<close> show ?thesis by (induct A) auto
   1.706 +  qed
   1.707    then show "PROP ?P" "PROP ?Q" "PROP ?R"
   1.708    by (auto elim!: Set.set_insert)
   1.709  qed -- \<open>TODO: maybe define @{const mset_set} also in terms of @{const Abs_multiset}\<close>
   1.710 @@ -1188,11 +1133,9 @@
   1.711  begin
   1.712  
   1.713  definition F :: "'a multiset \<Rightarrow> 'a"
   1.714 -where
   1.715 -  eq_fold: "F M = fold_mset f 1 M"
   1.716 -
   1.717 -lemma empty [simp]:
   1.718 -  "F {#} = 1"
   1.719 +  where eq_fold: "F M = fold_mset f 1 M"
   1.720 +
   1.721 +lemma empty [simp]: "F {#} = 1"
   1.722    by (simp add: eq_fold)
   1.723  
   1.724  lemma singleton [simp]:
   1.725 @@ -1203,8 +1146,7 @@
   1.726    show ?thesis by (simp add: eq_fold)
   1.727  qed
   1.728  
   1.729 -lemma union [simp]:
   1.730 -  "F (M + N) = F M * F N"
   1.731 +lemma union [simp]: "F (M + N) = F M * F N"
   1.732  proof -
   1.733    interpret comp_fun_commute f
   1.734      by default (simp add: fun_eq_iff left_commute)
   1.735 @@ -1228,12 +1170,10 @@
   1.736  begin
   1.737  
   1.738  definition msetsum :: "'a multiset \<Rightarrow> 'a"
   1.739 -where
   1.740 -  "msetsum = comm_monoid_mset.F plus 0"
   1.741 +  where "msetsum = comm_monoid_mset.F plus 0"
   1.742  
   1.743  sublocale msetsum!: comm_monoid_mset plus 0
   1.744 -where
   1.745 -  "comm_monoid_mset.F plus 0 = msetsum"
   1.746 +  where "comm_monoid_mset.F plus 0 = msetsum"
   1.747  proof -
   1.748    show "comm_monoid_mset plus 0" ..
   1.749    from msetsum_def show "comm_monoid_mset.F plus 0 = msetsum" ..
   1.750 @@ -1290,15 +1230,13 @@
   1.751  begin
   1.752  
   1.753  definition msetprod :: "'a multiset \<Rightarrow> 'a"
   1.754 -where
   1.755 -  "msetprod = comm_monoid_mset.F times 1"
   1.756 +  where "msetprod = comm_monoid_mset.F times 1"
   1.757  
   1.758  sublocale msetprod!: comm_monoid_mset times 1
   1.759 -where
   1.760 -  "comm_monoid_mset.F times 1 = msetprod"
   1.761 +  where "comm_monoid_mset.F times 1 = msetprod"
   1.762  proof -
   1.763    show "comm_monoid_mset times 1" ..
   1.764 -  from msetprod_def show "comm_monoid_mset.F times 1 = msetprod" ..
   1.765 +  show "comm_monoid_mset.F times 1 = msetprod" using msetprod_def ..
   1.766  qed
   1.767  
   1.768  lemma msetprod_empty:
   1.769 @@ -1401,10 +1339,10 @@
   1.770  
   1.771  lemma properties_for_sort_key:
   1.772    assumes "mset ys = mset xs"
   1.773 -  and "\<And>k. k \<in> set ys \<Longrightarrow> filter (\<lambda>x. f k = f x) ys = filter (\<lambda>x. f k = f x) xs"
   1.774 -  and "sorted (map f ys)"
   1.775 +    and "\<And>k. k \<in> set ys \<Longrightarrow> filter (\<lambda>x. f k = f x) ys = filter (\<lambda>x. f k = f x) xs"
   1.776 +    and "sorted (map f ys)"
   1.777    shows "sort_key f xs = ys"
   1.778 -using assms
   1.779 +  using assms
   1.780  proof (induct xs arbitrary: ys)
   1.781    case Nil then show ?case by simp
   1.782  next
   1.783 @@ -1421,7 +1359,7 @@
   1.784  
   1.785  lemma properties_for_sort:
   1.786    assumes multiset: "mset ys = mset xs"
   1.787 -  and "sorted ys"
   1.788 +    and "sorted ys"
   1.789    shows "sort xs = ys"
   1.790  proof (rule properties_for_sort_key)
   1.791    from multiset show "mset ys = mset xs" .
   1.792 @@ -1441,7 +1379,6 @@
   1.793  proof (rule properties_for_sort_key)
   1.794    show "mset ?rhs = mset ?lhs"
   1.795      by (rule multiset_eqI) (auto simp add: mset_filter)
   1.796 -next
   1.797    show "sorted (map f ?rhs)"
   1.798      by (auto simp add: sorted_append intro: sorted_map_same)
   1.799  next
   1.800 @@ -1493,11 +1430,14 @@
   1.801    by (auto simp add: part_def Let_def split_def)
   1.802  
   1.803  lemma sort_key_by_quicksort_code [code]:
   1.804 -  "sort_key f xs = (case xs of [] \<Rightarrow> []
   1.805 +  "sort_key f xs =
   1.806 +    (case xs of
   1.807 +      [] \<Rightarrow> []
   1.808      | [x] \<Rightarrow> xs
   1.809      | [x, y] \<Rightarrow> (if f x \<le> f y then xs else [y, x])
   1.810 -    | _ \<Rightarrow> (let (lts, eqs, gts) = part f (f (xs ! (length xs div 2))) xs
   1.811 -       in sort_key f lts @ eqs @ sort_key f gts))"
   1.812 +    | _ \<Rightarrow>
   1.813 +        let (lts, eqs, gts) = part f (f (xs ! (length xs div 2))) xs
   1.814 +        in sort_key f lts @ eqs @ sort_key f gts)"
   1.815  proof (cases xs)
   1.816    case Nil then show ?thesis by simp
   1.817  next
   1.818 @@ -1559,79 +1499,75 @@
   1.819  
   1.820  subsubsection \<open>Well-foundedness\<close>
   1.821  
   1.822 -definition mult1 :: "('a \<times> 'a) set => ('a multiset \<times> 'a multiset) set" where
   1.823 +definition mult1 :: "('a \<times> 'a) set \<Rightarrow> ('a multiset \<times> 'a multiset) set" where
   1.824    "mult1 r = {(N, M). \<exists>a M0 K. M = M0 + {#a#} \<and> N = M0 + K \<and>
   1.825 -      (\<forall>b. b :# K --> (b, a) \<in> r)}"
   1.826 -
   1.827 -definition mult :: "('a \<times> 'a) set => ('a multiset \<times> 'a multiset) set" where
   1.828 +      (\<forall>b. b :# K \<longrightarrow> (b, a) \<in> r)}"
   1.829 +
   1.830 +definition mult :: "('a \<times> 'a) set \<Rightarrow> ('a multiset \<times> 'a multiset) set" where
   1.831    "mult r = (mult1 r)\<^sup>+"
   1.832  
   1.833  lemma not_less_empty [iff]: "(M, {#}) \<notin> mult1 r"
   1.834  by (simp add: mult1_def)
   1.835  
   1.836 -lemma less_add: "(N, M0 + {#a#}) \<in> mult1 r ==>
   1.837 +lemma less_add: "(N, M0 + {#a#}) \<in> mult1 r \<Longrightarrow>
   1.838      (\<exists>M. (M, M0) \<in> mult1 r \<and> N = M + {#a#}) \<or>
   1.839 -    (\<exists>K. (\<forall>b. b :# K --> (b, a) \<in> r) \<and> N = M0 + K)"
   1.840 +    (\<exists>K. (\<forall>b. b :# K \<longrightarrow> (b, a) \<in> r) \<and> N = M0 + K)"
   1.841    (is "_ \<Longrightarrow> ?case1 (mult1 r) \<or> ?case2")
   1.842  proof (unfold mult1_def)
   1.843 -  let ?r = "\<lambda>K a. \<forall>b. b :# K --> (b, a) \<in> r"
   1.844 +  let ?r = "\<lambda>K a. \<forall>b. b :# K \<longrightarrow> (b, a) \<in> r"
   1.845    let ?R = "\<lambda>N M. \<exists>a M0 K. M = M0 + {#a#} \<and> N = M0 + K \<and> ?r K a"
   1.846    let ?case1 = "?case1 {(N, M). ?R N M}"
   1.847  
   1.848    assume "(N, M0 + {#a#}) \<in> {(N, M). ?R N M}"
   1.849 -  then have "\<exists>a' M0' K.
   1.850 -      M0 + {#a#} = M0' + {#a'#} \<and> N = M0' + K \<and> ?r K a'" by simp
   1.851 -  then show "?case1 \<or> ?case2"
   1.852 -  proof (elim exE conjE)
   1.853 -    fix a' M0' K
   1.854 -    assume N: "N = M0' + K" and r: "?r K a'"
   1.855 -    assume "M0 + {#a#} = M0' + {#a'#}"
   1.856 -    then have "M0 = M0' \<and> a = a' \<or>
   1.857 -        (\<exists>K'. M0 = K' + {#a'#} \<and> M0' = K' + {#a#})"
   1.858 -      by (simp only: add_eq_conv_ex)
   1.859 +  then obtain a' M0' K where M0: "M0 + {#a#} = M0' + {#a'#}" and N: "N = M0' + K" and r: "?r K a'"
   1.860 +    by auto
   1.861 +  show "?case1 \<or> ?case2"
   1.862 +  proof -
   1.863 +    from M0 consider "M0 = M0'" "a = a'"
   1.864 +      | K' where "M0 = K' + {#a'#}" "M0' = K' + {#a#}"
   1.865 +      by atomize_elim (simp only: add_eq_conv_ex)
   1.866      then show ?thesis
   1.867 -    proof (elim disjE conjE exE)
   1.868 -      assume "M0 = M0'" "a = a'"
   1.869 +    proof cases
   1.870 +      case 1
   1.871        with N r have "?r K a \<and> N = M0 + K" by simp
   1.872 -      then have ?case2 .. then show ?thesis ..
   1.873 +      then have ?case2 ..
   1.874 +      then show ?thesis ..
   1.875      next
   1.876 -      fix K'
   1.877 -      assume "M0' = K' + {#a#}"
   1.878 -      with N have n: "N = K' + K + {#a#}" by (simp add: ac_simps)
   1.879 -
   1.880 -      assume "M0 = K' + {#a'#}"
   1.881 -      with r have "?R (K' + K) M0" by blast
   1.882 -      with n have ?case1 by simp then show ?thesis ..
   1.883 +      case 2
   1.884 +      from N 2(2) have n: "N = K' + K + {#a#}" by (simp add: ac_simps)
   1.885 +      with r 2(1) have "?R (K' + K) M0" by blast
   1.886 +      with n have ?case1 by simp
   1.887 +      then show ?thesis ..
   1.888      qed
   1.889    qed
   1.890  qed
   1.891  
   1.892 -lemma all_accessible: "wf r ==> \<forall>M. M \<in> Wellfounded.acc (mult1 r)"
   1.893 +lemma all_accessible: "wf r \<Longrightarrow> \<forall>M. M \<in> Wellfounded.acc (mult1 r)"
   1.894  proof
   1.895    let ?R = "mult1 r"
   1.896    let ?W = "Wellfounded.acc ?R"
   1.897    {
   1.898      fix M M0 a
   1.899      assume M0: "M0 \<in> ?W"
   1.900 -      and wf_hyp: "!!b. (b, a) \<in> r ==> (\<forall>M \<in> ?W. M + {#b#} \<in> ?W)"
   1.901 -      and acc_hyp: "\<forall>M. (M, M0) \<in> ?R --> M + {#a#} \<in> ?W"
   1.902 +      and wf_hyp: "\<And>b. (b, a) \<in> r \<Longrightarrow> (\<forall>M \<in> ?W. M + {#b#} \<in> ?W)"
   1.903 +      and acc_hyp: "\<forall>M. (M, M0) \<in> ?R \<longrightarrow> M + {#a#} \<in> ?W"
   1.904      have "M0 + {#a#} \<in> ?W"
   1.905      proof (rule accI [of "M0 + {#a#}"])
   1.906        fix N
   1.907        assume "(N, M0 + {#a#}) \<in> ?R"
   1.908        then have "((\<exists>M. (M, M0) \<in> ?R \<and> N = M + {#a#}) \<or>
   1.909 -          (\<exists>K. (\<forall>b. b :# K --> (b, a) \<in> r) \<and> N = M0 + K))"
   1.910 +          (\<exists>K. (\<forall>b. b :# K \<longrightarrow> (b, a) \<in> r) \<and> N = M0 + K))"
   1.911          by (rule less_add)
   1.912        then show "N \<in> ?W"
   1.913        proof (elim exE disjE conjE)
   1.914          fix M assume "(M, M0) \<in> ?R" and N: "N = M + {#a#}"
   1.915 -        from acc_hyp have "(M, M0) \<in> ?R --> M + {#a#} \<in> ?W" ..
   1.916 +        from acc_hyp have "(M, M0) \<in> ?R \<longrightarrow> M + {#a#} \<in> ?W" ..
   1.917          from this and \<open>(M, M0) \<in> ?R\<close> have "M + {#a#} \<in> ?W" ..
   1.918          then show "N \<in> ?W" by (simp only: N)
   1.919        next
   1.920          fix K
   1.921          assume N: "N = M0 + K"
   1.922 -        assume "\<forall>b. b :# K --> (b, a) \<in> r"
   1.923 +        assume "\<forall>b. b :# K \<longrightarrow> (b, a) \<in> r"
   1.924          then have "M0 + K \<in> ?W"
   1.925          proof (induct K)
   1.926            case empty
   1.927 @@ -1663,7 +1599,7 @@
   1.928      from wf have "\<forall>M \<in> ?W. M + {#a#} \<in> ?W"
   1.929      proof induct
   1.930        fix a
   1.931 -      assume r: "!!b. (b, a) \<in> r ==> (\<forall>M \<in> ?W. M + {#b#} \<in> ?W)"
   1.932 +      assume r: "\<And>b. (b, a) \<in> r \<Longrightarrow> (\<forall>M \<in> ?W. M + {#b#} \<in> ?W)"
   1.933        show "\<forall>M \<in> ?W. M + {#a#} \<in> ?W"
   1.934        proof
   1.935          fix M assume "M \<in> ?W"
   1.936 @@ -1675,10 +1611,10 @@
   1.937    qed
   1.938  qed
   1.939  
   1.940 -theorem wf_mult1: "wf r ==> wf (mult1 r)"
   1.941 +theorem wf_mult1: "wf r \<Longrightarrow> wf (mult1 r)"
   1.942  by (rule acc_wfI) (rule all_accessible)
   1.943  
   1.944 -theorem wf_mult: "wf r ==> wf (mult r)"
   1.945 +theorem wf_mult: "wf r \<Longrightarrow> wf (mult r)"
   1.946  unfolding mult_def by (rule wf_trancl) (rule wf_mult1)
   1.947  
   1.948  
   1.949 @@ -1687,7 +1623,7 @@
   1.950  text \<open>One direction.\<close>
   1.951  
   1.952  lemma mult_implies_one_step:
   1.953 -  "trans r ==> (M, N) \<in> mult r ==>
   1.954 +  "trans r \<Longrightarrow> (M, N) \<in> mult r \<Longrightarrow>
   1.955      \<exists>I J K. N = I + J \<and> M = I + K \<and> J \<noteq> {#} \<and>
   1.956      (\<forall>k \<in> set_mset K. \<exists>j \<in> set_mset J. (k, j) \<in> r)"
   1.957  apply (unfold mult_def mult1_def set_mset_def)
   1.958 @@ -1719,9 +1655,9 @@
   1.959  done
   1.960  
   1.961  lemma one_step_implies_mult_aux:
   1.962 -  "trans r ==>
   1.963 -    \<forall>I J K. (size J = n \<and> J \<noteq> {#} \<and> (\<forall>k \<in> set_mset K. \<exists>j \<in> set_mset J. (k, j) \<in> r))
   1.964 -      --> (I + K, I + J) \<in> mult r"
   1.965 +  "trans r \<Longrightarrow>
   1.966 +    \<forall>I J K. size J = n \<and> J \<noteq> {#} \<and> (\<forall>k \<in> set_mset K. \<exists>j \<in> set_mset J. (k, j) \<in> r)
   1.967 +      \<longrightarrow> (I + K, I + J) \<in> mult r"
   1.968  apply (induct_tac n, auto)
   1.969  apply (frule size_eq_Suc_imp_eq_union, clarify)
   1.970  apply (rename_tac "J'", simp)
   1.971 @@ -1750,8 +1686,8 @@
   1.972  done
   1.973  
   1.974  lemma one_step_implies_mult:
   1.975 -  "trans r ==> J \<noteq> {#} ==> \<forall>k \<in> set_mset K. \<exists>j \<in> set_mset J. (k, j) \<in> r
   1.976 -    ==> (I + K, I + J) \<in> mult r"
   1.977 +  "trans r \<Longrightarrow> J \<noteq> {#} \<Longrightarrow> \<forall>k \<in> set_mset K. \<exists>j \<in> set_mset J. (k, j) \<in> r
   1.978 +    \<Longrightarrow> (I + K, I + J) \<in> mult r"
   1.979  using one_step_implies_mult_aux by blast
   1.980  
   1.981  
   1.982 @@ -1768,9 +1704,8 @@
   1.983  
   1.984  interpretation multiset_order: order le_multiset less_multiset
   1.985  proof -
   1.986 -  have irrefl: "\<And>M :: 'a multiset. \<not> M #\<subset># M"
   1.987 +  have irrefl: "\<not> M #\<subset># M" for M :: "'a multiset"
   1.988    proof
   1.989 -    fix M :: "'a multiset"
   1.990      assume "M #\<subset># M"
   1.991      then have MM: "(M, M) \<in> mult {(x, y). x < y}" by (simp add: less_multiset_def)
   1.992      have "trans {(x'::'a, x). x' < x}"
   1.993 @@ -1794,13 +1729,13 @@
   1.994      by default (auto simp add: le_multiset_def irrefl dest: trans)
   1.995  qed
   1.996  
   1.997 -lemma mult_less_irrefl [elim!]: "M #\<subset># (M::'a::order multiset) ==> R"
   1.998 +lemma mult_less_irrefl [elim!]: "M #\<subset># (M::'a::order multiset) \<Longrightarrow> R"
   1.999    by simp
  1.1000  
  1.1001  
  1.1002  subsubsection \<open>Monotonicity of multiset union\<close>
  1.1003  
  1.1004 -lemma mult1_union: "(B, D) \<in> mult1 r ==> (C + B, C + D) \<in> mult1 r"
  1.1005 +lemma mult1_union: "(B, D) \<in> mult1 r \<Longrightarrow> (C + B, C + D) \<in> mult1 r"
  1.1006  apply (unfold mult1_def)
  1.1007  apply auto
  1.1008  apply (rule_tac x = a in exI)
  1.1009 @@ -1808,26 +1743,26 @@
  1.1010  apply (simp add: add.assoc)
  1.1011  done
  1.1012  
  1.1013 -lemma union_less_mono2: "B #\<subset># D ==> C + B #\<subset># C + (D::'a::order multiset)"
  1.1014 +lemma union_less_mono2: "B #\<subset># D \<Longrightarrow> C + B #\<subset># C + (D::'a::order multiset)"
  1.1015  apply (unfold less_multiset_def mult_def)
  1.1016  apply (erule trancl_induct)
  1.1017   apply (blast intro: mult1_union)
  1.1018  apply (blast intro: mult1_union trancl_trans)
  1.1019  done
  1.1020  
  1.1021 -lemma union_less_mono1: "B #\<subset># D ==> B + C #\<subset># D + (C::'a::order multiset)"
  1.1022 +lemma union_less_mono1: "B #\<subset># D \<Longrightarrow> B + C #\<subset># D + (C::'a::order multiset)"
  1.1023  apply (subst add.commute [of B C])
  1.1024  apply (subst add.commute [of D C])
  1.1025  apply (erule union_less_mono2)
  1.1026  done
  1.1027  
  1.1028  lemma union_less_mono:
  1.1029 -  "A #\<subset># C ==> B #\<subset># D ==> A + B #\<subset># C + (D::'a::order multiset)"
  1.1030 +  fixes A B C D :: "'a::order multiset"
  1.1031 +  shows "A #\<subset># C \<Longrightarrow> B #\<subset># D \<Longrightarrow> A + B #\<subset># C + D"
  1.1032    by (blast intro!: union_less_mono1 union_less_mono2 multiset_order.less_trans)
  1.1033  
  1.1034  interpretation multiset_order: ordered_ab_semigroup_add plus le_multiset less_multiset
  1.1035 -proof
  1.1036 -qed (auto simp add: le_multiset_def intro: union_less_mono2)
  1.1037 +  by default (auto simp add: le_multiset_def intro: union_less_mono2)
  1.1038  
  1.1039  
  1.1040  subsubsection \<open>Termination proofs with multiset orders\<close>
  1.1041 @@ -1868,7 +1803,7 @@
  1.1042    assumes "pw_leq X Y"
  1.1043    shows "\<exists>A B Z. X = A + Z \<and> Y = B + Z \<and> ((set_mset A, set_mset B) \<in> max_strict \<or> (B = {#} \<and> A = {#}))"
  1.1044    using assms
  1.1045 -proof (induct)
  1.1046 +proof induct
  1.1047    case pw_leq_empty thus ?case by auto
  1.1048  next
  1.1049    case (pw_leq_step x y X Y)
  1.1050 @@ -1876,26 +1811,24 @@
  1.1051      [simp]: "X = A + Z" "Y = B + Z"
  1.1052        and 1[simp]: "(set_mset A, set_mset B) \<in> max_strict \<or> (B = {#} \<and> A = {#})"
  1.1053      by auto
  1.1054 -  from pw_leq_step have "x = y \<or> (x, y) \<in> pair_less"
  1.1055 +  from pw_leq_step consider "x = y" | "(x, y) \<in> pair_less"
  1.1056      unfolding pair_leq_def by auto
  1.1057    thus ?case
  1.1058 -  proof
  1.1059 -    assume [simp]: "x = y"
  1.1060 -    have
  1.1061 -      "{#x#} + X = A + ({#y#}+Z)
  1.1062 -      \<and> {#y#} + Y = B + ({#y#}+Z)
  1.1063 -      \<and> ((set_mset A, set_mset B) \<in> max_strict \<or> (B = {#} \<and> A = {#}))"
  1.1064 +  proof cases
  1.1065 +    case [simp]: 1
  1.1066 +    have "{#x#} + X = A + ({#y#}+Z) \<and> {#y#} + Y = B + ({#y#}+Z) \<and>
  1.1067 +      ((set_mset A, set_mset B) \<in> max_strict \<or> (B = {#} \<and> A = {#}))"
  1.1068        by (auto simp: ac_simps)
  1.1069 -    thus ?case by (intro exI)
  1.1070 +    thus ?thesis by blast
  1.1071    next
  1.1072 -    assume A: "(x, y) \<in> pair_less"
  1.1073 +    case 2
  1.1074      let ?A' = "{#x#} + A" and ?B' = "{#y#} + B"
  1.1075      have "{#x#} + X = ?A' + Z"
  1.1076        "{#y#} + Y = ?B' + Z"
  1.1077        by (auto simp add: ac_simps)
  1.1078      moreover have
  1.1079        "(set_mset ?A', set_mset ?B') \<in> max_strict"
  1.1080 -      using 1 A unfolding max_strict_def
  1.1081 +      using 1 2 unfolding max_strict_def
  1.1082        by (auto elim!: max_ext.cases)
  1.1083      ultimately show ?thesis by blast
  1.1084    qed
  1.1085 @@ -1904,8 +1837,8 @@
  1.1086  lemma
  1.1087    assumes pwleq: "pw_leq Z Z'"
  1.1088    shows ms_strictI: "(set_mset A, set_mset B) \<in> max_strict \<Longrightarrow> (Z + A, Z' + B) \<in> ms_strict"
  1.1089 -  and   ms_weakI1:  "(set_mset A, set_mset B) \<in> max_strict \<Longrightarrow> (Z + A, Z' + B) \<in> ms_weak"
  1.1090 -  and   ms_weakI2:  "(Z + {#}, Z' + {#}) \<in> ms_weak"
  1.1091 +    and ms_weakI1:  "(set_mset A, set_mset B) \<in> max_strict \<Longrightarrow> (Z + A, Z' + B) \<in> ms_weak"
  1.1092 +    and ms_weakI2:  "(Z + {#}, Z' + {#}) \<in> ms_weak"
  1.1093  proof -
  1.1094    from pw_leq_split[OF pwleq]
  1.1095    obtain A' B' Z''
  1.1096 @@ -1925,7 +1858,7 @@
  1.1097        assume [simp]: "A' = {#} \<and> B' = {#}"
  1.1098        show ?thesis by (rule smsI) (auto intro: max)
  1.1099      qed
  1.1100 -    thus "(Z + A, Z' + B) \<in> ms_strict" by (simp add:ac_simps)
  1.1101 +    thus "(Z + A, Z' + B) \<in> ms_strict" by (simp add: ac_simps)
  1.1102      thus "(Z + A, Z' + B) \<in> ms_weak" by (simp add: ms_weak_def)
  1.1103    }
  1.1104    from mx_or_empty
  1.1105 @@ -1939,45 +1872,45 @@
  1.1106  by auto
  1.1107  
  1.1108  setup \<open>
  1.1109 -let
  1.1110 -  fun msetT T = Type (@{type_name multiset}, [T]);
  1.1111 -
  1.1112 -  fun mk_mset T [] = Const (@{const_abbrev Mempty}, msetT T)
  1.1113 -    | mk_mset T [x] = Const (@{const_name single}, T --> msetT T) $ x
  1.1114 -    | mk_mset T (x :: xs) =
  1.1115 -          Const (@{const_name plus}, msetT T --> msetT T --> msetT T) $
  1.1116 -                mk_mset T [x] $ mk_mset T xs
  1.1117 -
  1.1118 -  fun mset_member_tac m i =
  1.1119 -      (if m <= 0 then
  1.1120 -           rtac @{thm multi_member_this} i ORELSE rtac @{thm multi_member_last} i
  1.1121 -       else
  1.1122 -           rtac @{thm multi_member_skip} i THEN mset_member_tac (m - 1) i)
  1.1123 -
  1.1124 -  val mset_nonempty_tac =
  1.1125 +  let
  1.1126 +    fun msetT T = Type (@{type_name multiset}, [T]);
  1.1127 +
  1.1128 +    fun mk_mset T [] = Const (@{const_abbrev Mempty}, msetT T)
  1.1129 +      | mk_mset T [x] = Const (@{const_name single}, T --> msetT T) $ x
  1.1130 +      | mk_mset T (x :: xs) =
  1.1131 +            Const (@{const_name plus}, msetT T --> msetT T --> msetT T) $
  1.1132 +                  mk_mset T [x] $ mk_mset T xs
  1.1133 +
  1.1134 +    fun mset_member_tac m i =
  1.1135 +      if m <= 0 then
  1.1136 +        rtac @{thm multi_member_this} i ORELSE rtac @{thm multi_member_last} i
  1.1137 +      else
  1.1138 +        rtac @{thm multi_member_skip} i THEN mset_member_tac (m - 1) i
  1.1139 +
  1.1140 +    val mset_nonempty_tac =
  1.1141        rtac @{thm nonempty_plus} ORELSE' rtac @{thm nonempty_single}
  1.1142  
  1.1143 -  fun regroup_munion_conv ctxt =
  1.1144 -    Function_Lib.regroup_conv ctxt @{const_abbrev Mempty} @{const_name plus}
  1.1145 -      (map (fn t => t RS eq_reflection) (@{thms ac_simps} @ @{thms empty_neutral}))
  1.1146 -
  1.1147 -  fun unfold_pwleq_tac i =
  1.1148 -    (rtac @{thm pw_leq_step} i THEN (fn st => unfold_pwleq_tac (i + 1) st))
  1.1149 -      ORELSE (rtac @{thm pw_leq_lstep} i)
  1.1150 -      ORELSE (rtac @{thm pw_leq_empty} i)
  1.1151 -
  1.1152 -  val set_mset_simps = [@{thm set_mset_empty}, @{thm set_mset_single}, @{thm set_mset_union},
  1.1153 -                      @{thm Un_insert_left}, @{thm Un_empty_left}]
  1.1154 -in
  1.1155 -  ScnpReconstruct.multiset_setup (ScnpReconstruct.Multiset
  1.1156 -  {
  1.1157 -    msetT=msetT, mk_mset=mk_mset, mset_regroup_conv=regroup_munion_conv,
  1.1158 -    mset_member_tac=mset_member_tac, mset_nonempty_tac=mset_nonempty_tac,
  1.1159 -    mset_pwleq_tac=unfold_pwleq_tac, set_of_simps=set_mset_simps,
  1.1160 -    smsI'= @{thm ms_strictI}, wmsI2''= @{thm ms_weakI2}, wmsI1= @{thm ms_weakI1},
  1.1161 -    reduction_pair= @{thm ms_reduction_pair}
  1.1162 -  })
  1.1163 -end
  1.1164 +    fun regroup_munion_conv ctxt =
  1.1165 +      Function_Lib.regroup_conv ctxt @{const_abbrev Mempty} @{const_name plus}
  1.1166 +        (map (fn t => t RS eq_reflection) (@{thms ac_simps} @ @{thms empty_neutral}))
  1.1167 +
  1.1168 +    fun unfold_pwleq_tac i =
  1.1169 +      (rtac @{thm pw_leq_step} i THEN (fn st => unfold_pwleq_tac (i + 1) st))
  1.1170 +        ORELSE (rtac @{thm pw_leq_lstep} i)
  1.1171 +        ORELSE (rtac @{thm pw_leq_empty} i)
  1.1172 +
  1.1173 +    val set_mset_simps = [@{thm set_mset_empty}, @{thm set_mset_single}, @{thm set_mset_union},
  1.1174 +                        @{thm Un_insert_left}, @{thm Un_empty_left}]
  1.1175 +  in
  1.1176 +    ScnpReconstruct.multiset_setup (ScnpReconstruct.Multiset
  1.1177 +    {
  1.1178 +      msetT=msetT, mk_mset=mk_mset, mset_regroup_conv=regroup_munion_conv,
  1.1179 +      mset_member_tac=mset_member_tac, mset_nonempty_tac=mset_nonempty_tac,
  1.1180 +      mset_pwleq_tac=unfold_pwleq_tac, set_of_simps=set_mset_simps,
  1.1181 +      smsI'= @{thm ms_strictI}, wmsI2''= @{thm ms_weakI2}, wmsI1= @{thm ms_weakI1},
  1.1182 +      reduction_pair= @{thm ms_reduction_pair}
  1.1183 +    })
  1.1184 +  end
  1.1185  \<close>
  1.1186  
  1.1187  
  1.1188 @@ -2022,50 +1955,41 @@
  1.1189    multiset_inter_assoc
  1.1190    multiset_inter_left_commute
  1.1191  
  1.1192 -lemma mult_less_not_refl:
  1.1193 -  "\<not> M #\<subset># (M::'a::order multiset)"
  1.1194 +lemma mult_less_not_refl: "\<not> M #\<subset># (M::'a::order multiset)"
  1.1195    by (fact multiset_order.less_irrefl)
  1.1196  
  1.1197 -lemma mult_less_trans:
  1.1198 -  "K #\<subset># M ==> M #\<subset># N ==> K #\<subset># (N::'a::order multiset)"
  1.1199 +lemma mult_less_trans: "K #\<subset># M \<Longrightarrow> M #\<subset># N \<Longrightarrow> K #\<subset># (N::'a::order multiset)"
  1.1200    by (fact multiset_order.less_trans)
  1.1201  
  1.1202 -lemma mult_less_not_sym:
  1.1203 -  "M #\<subset># N ==> \<not> N #\<subset># (M::'a::order multiset)"
  1.1204 +lemma mult_less_not_sym: "M #\<subset># N \<Longrightarrow> \<not> N #\<subset># (M::'a::order multiset)"
  1.1205    by (fact multiset_order.less_not_sym)
  1.1206  
  1.1207 -lemma mult_less_asym:
  1.1208 -  "M #\<subset># N ==> (\<not> P ==> N #\<subset># (M::'a::order multiset)) ==> P"
  1.1209 +lemma mult_less_asym: "M #\<subset># N \<Longrightarrow> (\<not> P \<Longrightarrow> N #\<subset># (M::'a::order multiset)) \<Longrightarrow> P"
  1.1210    by (fact multiset_order.less_asym)
  1.1211  
  1.1212 -ML \<open>
  1.1213 -fun multiset_postproc _ maybe_name all_values (T as Type (_, [elem_T]))
  1.1214 -                      (Const _ $ t') =
  1.1215 -    let
  1.1216 -      val (maybe_opt, ps) =
  1.1217 -        Nitpick_Model.dest_plain_fun t' ||> op ~~
  1.1218 -        ||> map (apsnd (snd o HOLogic.dest_number))
  1.1219 -      fun elems_for t =
  1.1220 -        case AList.lookup (op =) ps t of
  1.1221 -          SOME n => replicate n t
  1.1222 -        | NONE => [Const (maybe_name, elem_T --> elem_T) $ t]
  1.1223 -    in
  1.1224 -      case maps elems_for (all_values elem_T) @
  1.1225 -           (if maybe_opt then [Const (Nitpick_Model.unrep (), elem_T)]
  1.1226 -            else []) of
  1.1227 -        [] => Const (@{const_name zero_class.zero}, T)
  1.1228 -      | ts => foldl1 (fn (t1, t2) =>
  1.1229 -                         Const (@{const_name plus_class.plus}, T --> T --> T)
  1.1230 -                         $ t1 $ t2)
  1.1231 -                     (map (curry (op $) (Const (@{const_name single},
  1.1232 -                                                elem_T --> T))) ts)
  1.1233 -    end
  1.1234 -  | multiset_postproc _ _ _ _ t = t
  1.1235 -\<close>
  1.1236 -
  1.1237  declaration \<open>
  1.1238 -Nitpick_Model.register_term_postprocessor @{typ "'a multiset"}
  1.1239 -    multiset_postproc
  1.1240 +  let
  1.1241 +    fun multiset_postproc _ maybe_name all_values (T as Type (_, [elem_T])) (Const _ $ t') =
  1.1242 +          let
  1.1243 +            val (maybe_opt, ps) =
  1.1244 +              Nitpick_Model.dest_plain_fun t'
  1.1245 +              ||> op ~~
  1.1246 +              ||> map (apsnd (snd o HOLogic.dest_number))
  1.1247 +            fun elems_for t =
  1.1248 +              (case AList.lookup (op =) ps t of
  1.1249 +                SOME n => replicate n t
  1.1250 +              | NONE => [Const (maybe_name, elem_T --> elem_T) $ t])
  1.1251 +          in
  1.1252 +            (case maps elems_for (all_values elem_T) @
  1.1253 +                 (if maybe_opt then [Const (Nitpick_Model.unrep (), elem_T)] else []) of
  1.1254 +              [] => Const (@{const_name zero_class.zero}, T)
  1.1255 +            | ts =>
  1.1256 +                foldl1 (fn (t1, t2) =>
  1.1257 +                    Const (@{const_name plus_class.plus}, T --> T --> T) $ t1 $ t2)
  1.1258 +                  (map (curry (op $) (Const (@{const_name single}, elem_T --> T))) ts))
  1.1259 +          end
  1.1260 +      | multiset_postproc _ _ _ _ t = t
  1.1261 +  in Nitpick_Model.register_term_postprocessor @{typ "'a multiset"} multiset_postproc end
  1.1262  \<close>
  1.1263  
  1.1264  
  1.1265 @@ -2073,28 +1997,22 @@
  1.1266  
  1.1267  code_datatype mset
  1.1268  
  1.1269 -lemma [code]:
  1.1270 -  "{#} = mset []"
  1.1271 +lemma [code]: "{#} = mset []"
  1.1272    by simp
  1.1273  
  1.1274 -lemma [code]:
  1.1275 -  "{#x#} = mset [x]"
  1.1276 +lemma [code]: "{#x#} = mset [x]"
  1.1277    by simp
  1.1278  
  1.1279 -lemma union_code [code]:
  1.1280 -  "mset xs + mset ys = mset (xs @ ys)"
  1.1281 +lemma union_code [code]: "mset xs + mset ys = mset (xs @ ys)"
  1.1282    by simp
  1.1283  
  1.1284 -lemma [code]:
  1.1285 -  "image_mset f (mset xs) = mset (map f xs)"
  1.1286 +lemma [code]: "image_mset f (mset xs) = mset (map f xs)"
  1.1287    by (simp add: mset_map)
  1.1288  
  1.1289 -lemma [code]:
  1.1290 -  "filter_mset f (mset xs) = mset (filter f xs)"
  1.1291 +lemma [code]: "filter_mset f (mset xs) = mset (filter f xs)"
  1.1292    by (simp add: mset_filter)
  1.1293  
  1.1294 -lemma [code]:
  1.1295 -  "mset xs - mset ys = mset (fold remove1 ys xs)"
  1.1296 +lemma [code]: "mset xs - mset ys = mset (fold remove1 ys xs)"
  1.1297    by (rule sym, induct ys arbitrary: xs) (simp_all add: diff_add diff_right_commute)
  1.1298  
  1.1299  lemma [code]:
  1.1300 @@ -2122,8 +2040,7 @@
  1.1301  
  1.1302  declare in_multiset_in_set [code_unfold]
  1.1303  
  1.1304 -lemma [code]:
  1.1305 -  "count (mset xs) x = fold (\<lambda>y. if x = y then Suc else id) xs 0"
  1.1306 +lemma [code]: "count (mset xs) x = fold (\<lambda>y. if x = y then Suc else id) xs 0"
  1.1307  proof -
  1.1308    have "\<And>n. fold (\<lambda>y. if x = y then Suc else id) xs n = count (mset xs) x + n"
  1.1309      by (induct xs) simp_all
  1.1310 @@ -2207,12 +2124,10 @@
  1.1311    by default (simp add: equal_multiset_def)
  1.1312  end
  1.1313  
  1.1314 -lemma [code]:
  1.1315 -  "msetsum (mset xs) = listsum xs"
  1.1316 +lemma [code]: "msetsum (mset xs) = listsum xs"
  1.1317    by (induct xs) (simp_all add: add.commute)
  1.1318  
  1.1319 -lemma [code]:
  1.1320 -  "msetprod (mset xs) = fold times xs 1"
  1.1321 +lemma [code]: "msetprod (mset xs) = fold times xs 1"
  1.1322  proof -
  1.1323    have "\<And>x. fold times xs x = msetprod (mset xs) * x"
  1.1324      by (induct xs) (simp_all add: mult.assoc)
  1.1325 @@ -2270,7 +2185,7 @@
  1.1326    assumes "length xs = length ys" "j \<le> length xs"
  1.1327    shows "mset (zip (take j xs @ x # drop j xs) (take j ys @ y # drop j ys)) =
  1.1328      mset (zip xs ys) + {#(x, y)#}"
  1.1329 -using assms
  1.1330 +  using assms
  1.1331  proof (induct xs ys arbitrary: x y j rule: list_induct2)
  1.1332    case Nil
  1.1333    thus ?case
  1.1334 @@ -2368,38 +2283,30 @@
  1.1335  proof -
  1.1336    show "image_mset id = id"
  1.1337      by (rule image_mset.id)
  1.1338 -next
  1.1339 -  show "\<And>f g. image_mset (g \<circ> f) = image_mset g \<circ> image_mset f"
  1.1340 +  show "image_mset (g \<circ> f) = image_mset g \<circ> image_mset f" for f g
  1.1341      unfolding comp_def by (rule ext) (simp add: comp_def image_mset.compositionality)
  1.1342 -next
  1.1343 -  fix X :: "'a multiset"
  1.1344 -  show "\<And>f g. (\<And>z. z \<in> set_mset X \<Longrightarrow> f z = g z) \<Longrightarrow> image_mset f X = image_mset g X"
  1.1345 -    by (induct X, (simp (no_asm))+,
  1.1346 +  show "(\<And>z. z \<in> set_mset X \<Longrightarrow> f z = g z) \<Longrightarrow> image_mset f X = image_mset g X" for f g X
  1.1347 +    by (induct X) (simp_all (no_asm),
  1.1348        metis One_nat_def Un_iff count_single mem_set_mset_iff set_mset_union zero_less_Suc)
  1.1349 -next
  1.1350 -  show "\<And>f. set_mset \<circ> image_mset f = op ` f \<circ> set_mset"
  1.1351 +  show "set_mset \<circ> image_mset f = op ` f \<circ> set_mset" for f
  1.1352      by auto
  1.1353 -next
  1.1354    show "card_order natLeq"
  1.1355      by (rule natLeq_card_order)
  1.1356 -next
  1.1357    show "BNF_Cardinal_Arithmetic.cinfinite natLeq"
  1.1358      by (rule natLeq_cinfinite)
  1.1359 -next
  1.1360 -  show "\<And>X. ordLeq3 (card_of (set_mset X)) natLeq"
  1.1361 +  show "ordLeq3 (card_of (set_mset X)) natLeq" for X
  1.1362      by transfer
  1.1363        (auto intro!: ordLess_imp_ordLeq simp: finite_iff_ordLess_natLeq[symmetric] multiset_def)
  1.1364 -next
  1.1365 -  show "\<And>R S. rel_mset R OO rel_mset S \<le> rel_mset (R OO S)"
  1.1366 +  show "rel_mset R OO rel_mset S \<le> rel_mset (R OO S)" for R S
  1.1367      unfolding rel_mset_def[abs_def] OO_def
  1.1368      apply clarify
  1.1369      apply (rename_tac X Z Y xs ys' ys zs)
  1.1370      apply (drule_tac xs = ys' and ys = zs and xs' = ys in list_all2_reorder_left_invariance)
  1.1371 -    by (auto intro: list_all2_trans)
  1.1372 -next
  1.1373 -  show "\<And>R. rel_mset R =
  1.1374 +    apply (auto intro: list_all2_trans)
  1.1375 +    done
  1.1376 +  show "rel_mset R =
  1.1377      (BNF_Def.Grp {x. set_mset x \<subseteq> {(x, y). R x y}} (image_mset fst))\<inverse>\<inverse> OO
  1.1378 -    BNF_Def.Grp {x. set_mset x \<subseteq> {(x, y). R x y}} (image_mset snd)"
  1.1379 +    BNF_Def.Grp {x. set_mset x \<subseteq> {(x, y). R x y}} (image_mset snd)" for R
  1.1380      unfolding rel_mset_def[abs_def] BNF_Def.Grp_def OO_def
  1.1381      apply (rule ext)+
  1.1382      apply auto
  1.1383 @@ -2417,12 +2324,12 @@
  1.1384      apply (rule_tac x = "map snd xys" in exI)
  1.1385      apply (auto simp: mset_map list_all2I subset_eq zip_map_fst_snd)
  1.1386      done
  1.1387 -next
  1.1388 -  show "\<And>z. z \<in> set_mset {#} \<Longrightarrow> False"
  1.1389 +  show "z \<in> set_mset {#} \<Longrightarrow> False" for z
  1.1390      by auto
  1.1391  qed
  1.1392  
  1.1393 -inductive rel_mset' where
  1.1394 +inductive rel_mset'
  1.1395 +where
  1.1396    Zero[intro]: "rel_mset' R {#} {#}"
  1.1397  | Plus[intro]: "\<lbrakk>R a b; rel_mset' R M N\<rbrakk> \<Longrightarrow> rel_mset' R (M + {#a#}) (N + {#b#})"
  1.1398  
  1.1399 @@ -2435,27 +2342,25 @@
  1.1400  declare union_preserves_multiset[simp]
  1.1401  
  1.1402  lemma rel_mset_Plus:
  1.1403 -assumes ab: "R a b" and MN: "rel_mset R M N"
  1.1404 -shows "rel_mset R (M + {#a#}) (N + {#b#})"
  1.1405 -proof-
  1.1406 -  {fix y assume "R a b" and "set_mset y \<subseteq> {(x, y). R x y}"
  1.1407 -   hence "\<exists>ya. image_mset fst y + {#a#} = image_mset fst ya \<and>
  1.1408 -               image_mset snd y + {#b#} = image_mset snd ya \<and>
  1.1409 -               set_mset ya \<subseteq> {(x, y). R x y}"
  1.1410 -   apply(intro exI[of _ "y + {#(a,b)#}"]) by auto
  1.1411 -  }
  1.1412 +  assumes ab: "R a b"
  1.1413 +    and MN: "rel_mset R M N"
  1.1414 +  shows "rel_mset R (M + {#a#}) (N + {#b#})"
  1.1415 +proof -
  1.1416 +  have "\<exists>ya. image_mset fst y + {#a#} = image_mset fst ya \<and>
  1.1417 +    image_mset snd y + {#b#} = image_mset snd ya \<and>
  1.1418 +    set_mset ya \<subseteq> {(x, y). R x y}"
  1.1419 +    if "R a b" and "set_mset y \<subseteq> {(x, y). R x y}" for y
  1.1420 +    using that by (intro exI[of _ "y + {#(a,b)#}"]) auto
  1.1421    thus ?thesis
  1.1422    using assms
  1.1423    unfolding multiset.rel_compp_Grp Grp_def by blast
  1.1424  qed
  1.1425  
  1.1426 -lemma rel_mset'_imp_rel_mset:
  1.1427 -  "rel_mset' R M N \<Longrightarrow> rel_mset R M N"
  1.1428 +lemma rel_mset'_imp_rel_mset: "rel_mset' R M N \<Longrightarrow> rel_mset R M N"
  1.1429  apply(induct rule: rel_mset'.induct)
  1.1430  using rel_mset_Zero rel_mset_Plus by auto
  1.1431  
  1.1432 -lemma rel_mset_size:
  1.1433 -  "rel_mset R M N \<Longrightarrow> size M = size N"
  1.1434 +lemma rel_mset_size: "rel_mset R M N \<Longrightarrow> size M = size N"
  1.1435  unfolding multiset.rel_compp_Grp Grp_def by auto
  1.1436  
  1.1437  lemma multiset_induct2[case_names empty addL addR]:
  1.1438 @@ -2469,12 +2374,13 @@
  1.1439  done
  1.1440  
  1.1441  lemma multiset_induct2_size[consumes 1, case_names empty add]:
  1.1442 -assumes c: "size M = size N"
  1.1443 -and empty: "P {#} {#}"
  1.1444 -and add: "\<And>M N a b. P M N \<Longrightarrow> P (M + {#a#}) (N + {#b#})"
  1.1445 -shows "P M N"
  1.1446 +  assumes c: "size M = size N"
  1.1447 +    and empty: "P {#} {#}"
  1.1448 +    and add: "\<And>M N a b. P M N \<Longrightarrow> P (M + {#a#}) (N + {#b#})"
  1.1449 +  shows "P M N"
  1.1450  using c proof(induct M arbitrary: N rule: measure_induct_rule[of size])
  1.1451 -  case (less M)  show ?case
  1.1452 +  case (less M)
  1.1453 +  show ?case
  1.1454    proof(cases "M = {#}")
  1.1455      case True hence "N = {#}" using less.prems by auto
  1.1456      thus ?thesis using True empty by auto
  1.1457 @@ -2488,67 +2394,67 @@
  1.1458  qed
  1.1459  
  1.1460  lemma msed_map_invL:
  1.1461 -assumes "image_mset f (M + {#a#}) = N"
  1.1462 -shows "\<exists>N1. N = N1 + {#f a#} \<and> image_mset f M = N1"
  1.1463 -proof-
  1.1464 +  assumes "image_mset f (M + {#a#}) = N"
  1.1465 +  shows "\<exists>N1. N = N1 + {#f a#} \<and> image_mset f M = N1"
  1.1466 +proof -
  1.1467    have "f a \<in># N"
  1.1468 -  using assms multiset.set_map[of f "M + {#a#}"] by auto
  1.1469 +    using assms multiset.set_map[of f "M + {#a#}"] by auto
  1.1470    then obtain N1 where N: "N = N1 + {#f a#}" using multi_member_split by metis
  1.1471    have "image_mset f M = N1" using assms unfolding N by simp
  1.1472    thus ?thesis using N by blast
  1.1473  qed
  1.1474  
  1.1475  lemma msed_map_invR:
  1.1476 -assumes "image_mset f M = N + {#b#}"
  1.1477 -shows "\<exists>M1 a. M = M1 + {#a#} \<and> f a = b \<and> image_mset f M1 = N"
  1.1478 -proof-
  1.1479 +  assumes "image_mset f M = N + {#b#}"
  1.1480 +  shows "\<exists>M1 a. M = M1 + {#a#} \<and> f a = b \<and> image_mset f M1 = N"
  1.1481 +proof -
  1.1482    obtain a where a: "a \<in># M" and fa: "f a = b"
  1.1483 -  using multiset.set_map[of f M] unfolding assms
  1.1484 -  by (metis image_iff mem_set_mset_iff union_single_eq_member)
  1.1485 +    using multiset.set_map[of f M] unfolding assms
  1.1486 +    by (metis image_iff mem_set_mset_iff union_single_eq_member)
  1.1487    then obtain M1 where M: "M = M1 + {#a#}" using multi_member_split by metis
  1.1488    have "image_mset f M1 = N" using assms unfolding M fa[symmetric] by simp
  1.1489    thus ?thesis using M fa by blast
  1.1490  qed
  1.1491  
  1.1492  lemma msed_rel_invL:
  1.1493 -assumes "rel_mset R (M + {#a#}) N"
  1.1494 -shows "\<exists>N1 b. N = N1 + {#b#} \<and> R a b \<and> rel_mset R M N1"
  1.1495 -proof-
  1.1496 +  assumes "rel_mset R (M + {#a#}) N"
  1.1497 +  shows "\<exists>N1 b. N = N1 + {#b#} \<and> R a b \<and> rel_mset R M N1"
  1.1498 +proof -
  1.1499    obtain K where KM: "image_mset fst K = M + {#a#}"
  1.1500 -  and KN: "image_mset snd K = N" and sK: "set_mset K \<subseteq> {(a, b). R a b}"
  1.1501 -  using assms
  1.1502 -  unfolding multiset.rel_compp_Grp Grp_def by auto
  1.1503 +    and KN: "image_mset snd K = N" and sK: "set_mset K \<subseteq> {(a, b). R a b}"
  1.1504 +    using assms
  1.1505 +    unfolding multiset.rel_compp_Grp Grp_def by auto
  1.1506    obtain K1 ab where K: "K = K1 + {#ab#}" and a: "fst ab = a"
  1.1507 -  and K1M: "image_mset fst K1 = M" using msed_map_invR[OF KM] by auto
  1.1508 +    and K1M: "image_mset fst K1 = M" using msed_map_invR[OF KM] by auto
  1.1509    obtain N1 where N: "N = N1 + {#snd ab#}" and K1N1: "image_mset snd K1 = N1"
  1.1510 -  using msed_map_invL[OF KN[unfolded K]] by auto
  1.1511 +    using msed_map_invL[OF KN[unfolded K]] by auto
  1.1512    have Rab: "R a (snd ab)" using sK a unfolding K by auto
  1.1513    have "rel_mset R M N1" using sK K1M K1N1
  1.1514 -  unfolding K multiset.rel_compp_Grp Grp_def by auto
  1.1515 +    unfolding K multiset.rel_compp_Grp Grp_def by auto
  1.1516    thus ?thesis using N Rab by auto
  1.1517  qed
  1.1518  
  1.1519  lemma msed_rel_invR:
  1.1520 -assumes "rel_mset R M (N + {#b#})"
  1.1521 -shows "\<exists>M1 a. M = M1 + {#a#} \<and> R a b \<and> rel_mset R M1 N"
  1.1522 -proof-
  1.1523 +  assumes "rel_mset R M (N + {#b#})"
  1.1524 +  shows "\<exists>M1 a. M = M1 + {#a#} \<and> R a b \<and> rel_mset R M1 N"
  1.1525 +proof -
  1.1526    obtain K where KN: "image_mset snd K = N + {#b#}"
  1.1527 -  and KM: "image_mset fst K = M" and sK: "set_mset K \<subseteq> {(a, b). R a b}"
  1.1528 -  using assms
  1.1529 -  unfolding multiset.rel_compp_Grp Grp_def by auto
  1.1530 +    and KM: "image_mset fst K = M" and sK: "set_mset K \<subseteq> {(a, b). R a b}"
  1.1531 +    using assms
  1.1532 +    unfolding multiset.rel_compp_Grp Grp_def by auto
  1.1533    obtain K1 ab where K: "K = K1 + {#ab#}" and b: "snd ab = b"
  1.1534 -  and K1N: "image_mset snd K1 = N" using msed_map_invR[OF KN] by auto
  1.1535 +    and K1N: "image_mset snd K1 = N" using msed_map_invR[OF KN] by auto
  1.1536    obtain M1 where M: "M = M1 + {#fst ab#}" and K1M1: "image_mset fst K1 = M1"
  1.1537 -  using msed_map_invL[OF KM[unfolded K]] by auto
  1.1538 +    using msed_map_invL[OF KM[unfolded K]] by auto
  1.1539    have Rab: "R (fst ab) b" using sK b unfolding K by auto
  1.1540    have "rel_mset R M1 N" using sK K1N K1M1
  1.1541 -  unfolding K multiset.rel_compp_Grp Grp_def by auto
  1.1542 +    unfolding K multiset.rel_compp_Grp Grp_def by auto
  1.1543    thus ?thesis using M Rab by auto
  1.1544  qed
  1.1545  
  1.1546  lemma rel_mset_imp_rel_mset':
  1.1547 -assumes "rel_mset R M N"
  1.1548 -shows "rel_mset' R M N"
  1.1549 +  assumes "rel_mset R M N"
  1.1550 +  shows "rel_mset' R M N"
  1.1551  using assms proof(induct M arbitrary: N rule: measure_induct_rule[of size])
  1.1552    case (less M)
  1.1553    have c: "size M = size N" using rel_mset_size[OF less.prems] .
  1.1554 @@ -2559,19 +2465,18 @@
  1.1555    next
  1.1556      case False then obtain M1 a where M: "M = M1 + {#a#}" by (metis multi_nonempty_split)
  1.1557      obtain N1 b where N: "N = N1 + {#b#}" and R: "R a b" and ms: "rel_mset R M1 N1"
  1.1558 -    using msed_rel_invL[OF less.prems[unfolded M]] by auto
  1.1559 +      using msed_rel_invL[OF less.prems[unfolded M]] by auto
  1.1560      have "rel_mset' R M1 N1" using less.hyps[of M1 N1] ms unfolding M by simp
  1.1561      thus ?thesis using rel_mset'.Plus[of R a b, OF R] unfolding M N by simp
  1.1562    qed
  1.1563  qed
  1.1564  
  1.1565 -lemma rel_mset_rel_mset':
  1.1566 -"rel_mset R M N = rel_mset' R M N"
  1.1567 +lemma rel_mset_rel_mset': "rel_mset R M N = rel_mset' R M N"
  1.1568  using rel_mset_imp_rel_mset' rel_mset'_imp_rel_mset by auto
  1.1569  
  1.1570 -(* The main end product for rel_mset: inductive characterization *)
  1.1571 +text \<open>The main end product for rel_mset: inductive characterization:\<close>
  1.1572  theorems rel_mset_induct[case_names empty add, induct pred: rel_mset] =
  1.1573 -         rel_mset'.induct[unfolded rel_mset_rel_mset'[symmetric]]
  1.1574 +  rel_mset'.induct[unfolded rel_mset_rel_mset'[symmetric]]
  1.1575  
  1.1576  
  1.1577  subsection \<open>Size setup\<close>
  1.1578 @@ -2580,10 +2485,10 @@
  1.1579    unfolding o_apply by (rule ext) (induct_tac, auto)
  1.1580  
  1.1581  setup \<open>
  1.1582 -BNF_LFP_Size.register_size_global @{type_name multiset} @{const_name size_multiset}
  1.1583 -  @{thms size_multiset_empty size_multiset_single size_multiset_union size_empty size_single
  1.1584 -    size_union}
  1.1585 -  @{thms multiset_size_o_map}
  1.1586 +  BNF_LFP_Size.register_size_global @{type_name multiset} @{const_name size_multiset}
  1.1587 +    @{thms size_multiset_empty size_multiset_single size_multiset_union size_empty size_single
  1.1588 +      size_union}
  1.1589 +    @{thms multiset_size_o_map}
  1.1590  \<close>
  1.1591  
  1.1592  hide_const (open) wcount