src/HOL/Library/Multiset.thy
changeset 10714 07f75bf77a33
parent 10392 f27afee8475d
child 11464 ddea204de5bc
     1.1 --- a/src/HOL/Library/Multiset.thy	Thu Dec 21 10:11:10 2000 +0100
     1.2 +++ b/src/HOL/Library/Multiset.thy	Thu Dec 21 10:16:07 2000 +0100
     1.3 @@ -16,7 +16,7 @@
     1.4  
     1.5  typedef 'a multiset = "{f::'a => nat. finite {x . 0 < f x}}"
     1.6  proof
     1.7 -  show "(\<lambda>x. 0::nat) \<in> ?multiset" by simp
     1.8 +  show "(\\<lambda>x. 0::nat) \\<in> ?multiset" by simp
     1.9  qed
    1.10  
    1.11  lemmas multiset_typedef [simp] =
    1.12 @@ -25,23 +25,23 @@
    1.13  
    1.14  constdefs
    1.15    Mempty :: "'a multiset"    ("{#}")
    1.16 -  "{#} == Abs_multiset (\<lambda>a. 0)"
    1.17 +  "{#} == Abs_multiset (\\<lambda>a. 0)"
    1.18  
    1.19    single :: "'a => 'a multiset"    ("{#_#}")
    1.20 -  "{#a#} == Abs_multiset (\<lambda>b. if b = a then 1 else 0)"
    1.21 +  "{#a#} == Abs_multiset (\\<lambda>b. if b = a then 1 else 0)"
    1.22  
    1.23    count :: "'a multiset => 'a => nat"
    1.24    "count == Rep_multiset"
    1.25  
    1.26    MCollect :: "'a multiset => ('a => bool) => 'a multiset"
    1.27 -  "MCollect M P == Abs_multiset (\<lambda>x. if P x then Rep_multiset M x else 0)"
    1.28 +  "MCollect M P == Abs_multiset (\\<lambda>x. if P x then Rep_multiset M x else 0)"
    1.29  
    1.30  syntax
    1.31    "_Melem" :: "'a => 'a multiset => bool"    ("(_/ :# _)" [50, 51] 50)
    1.32    "_MCollect" :: "pttrn => 'a multiset => bool => 'a multiset"    ("(1{# _ : _./ _#})")
    1.33  translations
    1.34    "a :# M" == "0 < count M a"
    1.35 -  "{#x:M. P#}" == "MCollect M (\<lambda>x. P)"
    1.36 +  "{#x:M. P#}" == "MCollect M (\\<lambda>x. P)"
    1.37  
    1.38  constdefs
    1.39    set_of :: "'a multiset => 'a set"
    1.40 @@ -52,8 +52,8 @@
    1.41  instance multiset :: ("term") zero ..
    1.42  
    1.43  defs (overloaded)
    1.44 -  union_def: "M + N == Abs_multiset (\<lambda>a. Rep_multiset M a + Rep_multiset N a)"
    1.45 -  diff_def: "M - N == Abs_multiset (\<lambda>a. Rep_multiset M a - Rep_multiset N a)"
    1.46 +  union_def: "M + N == Abs_multiset (\\<lambda>a. Rep_multiset M a + Rep_multiset N a)"
    1.47 +  diff_def: "M - N == Abs_multiset (\\<lambda>a. Rep_multiset M a - Rep_multiset N a)"
    1.48    Zero_def [simp]: "0 == {#}"
    1.49    size_def: "size M == setsum (count M) (set_of M)"
    1.50  
    1.51 @@ -62,16 +62,16 @@
    1.52   \medskip Preservation of the representing set @{term multiset}.
    1.53  *}
    1.54  
    1.55 -lemma const0_in_multiset [simp]: "(\<lambda>a. 0) \<in> multiset"
    1.56 +lemma const0_in_multiset [simp]: "(\\<lambda>a. 0) \\<in> multiset"
    1.57    apply (simp add: multiset_def)
    1.58    done
    1.59  
    1.60 -lemma only1_in_multiset [simp]: "(\<lambda>b. if b = a then 1 else 0) \<in> multiset"
    1.61 +lemma only1_in_multiset [simp]: "(\\<lambda>b. if b = a then 1 else 0) \\<in> multiset"
    1.62    apply (simp add: multiset_def)
    1.63    done
    1.64  
    1.65  lemma union_preserves_multiset [simp]:
    1.66 -    "M \<in> multiset ==> N \<in> multiset ==> (\<lambda>a. M a + N a) \<in> multiset"
    1.67 +    "M \\<in> multiset ==> N \\<in> multiset ==> (\\<lambda>a. M a + N a) \\<in> multiset"
    1.68    apply (unfold multiset_def)
    1.69    apply simp
    1.70    apply (drule finite_UnI)
    1.71 @@ -80,7 +80,7 @@
    1.72    done
    1.73  
    1.74  lemma diff_preserves_multiset [simp]:
    1.75 -    "M \<in> multiset ==> (\<lambda>a. M a - N a) \<in> multiset"
    1.76 +    "M \\<in> multiset ==> (\\<lambda>a. M a - N a) \\<in> multiset"
    1.77    apply (unfold multiset_def)
    1.78    apply simp
    1.79    apply (rule finite_subset)
    1.80 @@ -94,7 +94,7 @@
    1.81  
    1.82  subsubsection {* Union *}
    1.83  
    1.84 -theorem union_empty [simp]: "M + {#} = M \<and> {#} + M = M"
    1.85 +theorem union_empty [simp]: "M + {#} = M \\<and> {#} + M = M"
    1.86    apply (simp add: union_def Mempty_def)
    1.87    done
    1.88  
    1.89 @@ -124,7 +124,7 @@
    1.90  
    1.91  subsubsection {* Difference *}
    1.92  
    1.93 -theorem diff_empty [simp]: "M - {#} = M \<and> {#} - M = {#}"
    1.94 +theorem diff_empty [simp]: "M - {#} = M \\<and> {#} - M = {#}"
    1.95    apply (simp add: Mempty_def diff_def)
    1.96    done
    1.97  
    1.98 @@ -162,7 +162,7 @@
    1.99    apply (simp add: set_of_def)
   1.100    done
   1.101  
   1.102 -theorem set_of_union [simp]: "set_of (M + N) = set_of M \<union> set_of N"
   1.103 +theorem set_of_union [simp]: "set_of (M + N) = set_of M \\<union> set_of N"
   1.104    apply (auto simp add: set_of_def)
   1.105    done
   1.106  
   1.107 @@ -170,7 +170,7 @@
   1.108    apply (auto simp add: set_of_def Mempty_def count_def expand_fun_eq)
   1.109    done
   1.110  
   1.111 -theorem mem_set_of_iff [simp]: "(x \<in> set_of M) = (x :# M)"
   1.112 +theorem mem_set_of_iff [simp]: "(x \\<in> set_of M) = (x :# M)"
   1.113    apply (auto simp add: set_of_def)
   1.114    done
   1.115  
   1.116 @@ -191,7 +191,7 @@
   1.117    done
   1.118  
   1.119  theorem setsum_count_Int:
   1.120 -    "finite A ==> setsum (count N) (A \<inter> set_of N) = setsum (count N) A"
   1.121 +    "finite A ==> setsum (count N) (A \\<inter> set_of N) = setsum (count N) A"
   1.122    apply (erule finite_induct)
   1.123     apply simp
   1.124    apply (simp add: Int_insert_left set_of_def)
   1.125 @@ -199,7 +199,7 @@
   1.126  
   1.127  theorem size_union [simp]: "size (M + N::'a multiset) = size M + size N"
   1.128    apply (unfold size_def)
   1.129 -  apply (subgoal_tac "count (M + N) = (\<lambda>a. count M a + count N a)")
   1.130 +  apply (subgoal_tac "count (M + N) = (\\<lambda>a. count M a + count N a)")
   1.131     prefer 2
   1.132     apply (rule ext)
   1.133     apply simp
   1.134 @@ -214,7 +214,7 @@
   1.135    apply (simp add: set_of_def count_def expand_fun_eq)
   1.136    done
   1.137  
   1.138 -theorem size_eq_Suc_imp_elem: "size M = Suc n ==> \<exists>a. a :# M"
   1.139 +theorem size_eq_Suc_imp_elem: "size M = Suc n ==> \\<exists>a. a :# M"
   1.140    apply (unfold size_def)
   1.141    apply (drule setsum_SucD)
   1.142    apply auto
   1.143 @@ -223,11 +223,11 @@
   1.144  
   1.145  subsubsection {* Equality of multisets *}
   1.146  
   1.147 -theorem multiset_eq_conv_count_eq: "(M = N) = (\<forall>a. count M a = count N a)"
   1.148 +theorem multiset_eq_conv_count_eq: "(M = N) = (\\<forall>a. count M a = count N a)"
   1.149    apply (simp add: count_def expand_fun_eq)
   1.150    done
   1.151  
   1.152 -theorem single_not_empty [simp]: "{#a#} \<noteq> {#} \<and> {#} \<noteq> {#a#}"
   1.153 +theorem single_not_empty [simp]: "{#a#} \\<noteq> {#} \\<and> {#} \\<noteq> {#a#}"
   1.154    apply (simp add: single_def Mempty_def expand_fun_eq)
   1.155    done
   1.156  
   1.157 @@ -235,11 +235,11 @@
   1.158    apply (auto simp add: single_def expand_fun_eq)
   1.159    done
   1.160  
   1.161 -theorem union_eq_empty [iff]: "(M + N = {#}) = (M = {#} \<and> N = {#})"
   1.162 +theorem union_eq_empty [iff]: "(M + N = {#}) = (M = {#} \\<and> N = {#})"
   1.163    apply (auto simp add: union_def Mempty_def expand_fun_eq)
   1.164    done
   1.165  
   1.166 -theorem empty_eq_union [iff]: "({#} = M + N) = (M = {#} \<and> N = {#})"
   1.167 +theorem empty_eq_union [iff]: "({#} = M + N) = (M = {#} \\<and> N = {#})"
   1.168    apply (auto simp add: union_def Mempty_def expand_fun_eq)
   1.169    done
   1.170  
   1.171 @@ -252,7 +252,7 @@
   1.172    done
   1.173  
   1.174  theorem union_is_single:
   1.175 -    "(M + N = {#a#}) = (M = {#a#} \<and> N={#} \<or> M = {#} \<and> N = {#a#})"
   1.176 +    "(M + N = {#a#}) = (M = {#a#} \\<and> N={#} \\<or> M = {#} \\<and> N = {#a#})"
   1.177    apply (unfold Mempty_def single_def union_def)
   1.178    apply (simp add: add_is_1 expand_fun_eq)
   1.179    apply blast
   1.180 @@ -260,16 +260,16 @@
   1.181  
   1.182  theorem single_is_union:
   1.183    "({#a#} = M + N) =
   1.184 -    ({#a#} = M \<and> N = {#} \<or> M = {#} \<and> {#a#} = N)"
   1.185 +    ({#a#} = M \\<and> N = {#} \\<or> M = {#} \\<and> {#a#} = N)"
   1.186    apply (unfold Mempty_def single_def union_def)
   1.187 -  apply (simp add: one_is_add expand_fun_eq)
   1.188 +  apply (simp add: add_is_1 expand_fun_eq)
   1.189    apply (blast dest: sym)
   1.190    done
   1.191  
   1.192  theorem add_eq_conv_diff:
   1.193    "(M + {#a#} = N + {#b#}) =
   1.194 -    (M = N \<and> a = b \<or>
   1.195 -      M = N - {#a#} + {#b#} \<and> N = M - {#b#} + {#a#})"
   1.196 +    (M = N \\<and> a = b \\<or>
   1.197 +      M = N - {#a#} + {#b#} \\<and> N = M - {#b#} + {#a#})"
   1.198    apply (unfold single_def union_def diff_def)
   1.199    apply (simp (no_asm) add: expand_fun_eq)
   1.200    apply (rule conjI)
   1.201 @@ -291,7 +291,7 @@
   1.202  (*
   1.203  val prems = Goal
   1.204   "[| !!F. [| finite F; !G. G < F --> P G |] ==> P F |] ==> finite F --> P F";
   1.205 -by (res_inst_tac [("a","F"),("f","\<lambda>A. if finite A then card A else 0")]
   1.206 +by (res_inst_tac [("a","F"),("f","\\<lambda>A. if finite A then card A else 0")]
   1.207       measure_induct 1);
   1.208  by (Clarify_tac 1);
   1.209  by (resolve_tac prems 1);
   1.210 @@ -320,7 +320,7 @@
   1.211  
   1.212  lemma setsum_decr:
   1.213    "finite F ==> 0 < f a ==>
   1.214 -    setsum (f (a := f a - 1)) F = (if a \<in> F then setsum f F - 1 else setsum f F)"
   1.215 +    setsum (f (a := f a - 1)) F = (if a \\<in> F then setsum f F - 1 else setsum f F)"
   1.216    apply (erule finite_induct)
   1.217     apply auto
   1.218    apply (drule_tac a = a in mk_disjoint_insert)
   1.219 @@ -328,8 +328,8 @@
   1.220    done
   1.221  
   1.222  lemma rep_multiset_induct_aux:
   1.223 -  "P (\<lambda>a. 0) ==> (!!f b. f \<in> multiset ==> P f ==> P (f (b := f b + 1)))
   1.224 -    ==> \<forall>f. f \<in> multiset --> setsum f {x. 0 < f x} = n --> P f"
   1.225 +  "P (\\<lambda>a. 0) ==> (!!f b. f \\<in> multiset ==> P f ==> P (f (b := f b + 1)))
   1.226 +    ==> \\<forall>f. f \\<in> multiset --> setsum f {x. 0 < f x} = n --> P f"
   1.227  proof -
   1.228    case antecedent
   1.229    note prems = this [unfolded multiset_def]
   1.230 @@ -338,7 +338,7 @@
   1.231      apply (induct_tac n)
   1.232       apply simp
   1.233       apply clarify
   1.234 -     apply (subgoal_tac "f = (\<lambda>a.0)")
   1.235 +     apply (subgoal_tac "f = (\\<lambda>a.0)")
   1.236        apply simp
   1.237        apply (rule prems)
   1.238       apply (rule ext)
   1.239 @@ -363,10 +363,10 @@
   1.240      apply (erule allE, erule impE, erule_tac [2] mp)
   1.241       apply blast
   1.242      apply (simp (no_asm_simp) add: setsum_decr del: fun_upd_apply)
   1.243 -    apply (subgoal_tac "{x. x \<noteq> a --> 0 < f x} = {x. 0 < f x}")
   1.244 +    apply (subgoal_tac "{x. x \\<noteq> a --> 0 < f x} = {x. 0 < f x}")
   1.245       prefer 2
   1.246       apply blast
   1.247 -    apply (subgoal_tac "{x. x \<noteq> a \<and> 0 < f x} = {x. 0 < f x} - {a}")
   1.248 +    apply (subgoal_tac "{x. x \\<noteq> a \\<and> 0 < f x} = {x. 0 < f x} - {a}")
   1.249       prefer 2
   1.250       apply blast
   1.251      apply (simp add: le_imp_diff_is_add setsum_diff1 cong: conj_cong)
   1.252 @@ -374,8 +374,8 @@
   1.253  qed
   1.254  
   1.255  theorem rep_multiset_induct:
   1.256 -  "f \<in> multiset ==> P (\<lambda>a. 0) ==>
   1.257 -    (!!f b. f \<in> multiset ==> P f ==> P (f (b := f b + 1))) ==> P f"
   1.258 +  "f \\<in> multiset ==> P (\\<lambda>a. 0) ==>
   1.259 +    (!!f b. f \\<in> multiset ==> P f ==> P (f (b := f b + 1))) ==> P f"
   1.260    apply (insert rep_multiset_induct_aux)
   1.261    apply blast
   1.262    done
   1.263 @@ -390,7 +390,7 @@
   1.264      apply (rule Rep_multiset_inverse [THEN subst])
   1.265      apply (rule Rep_multiset [THEN rep_multiset_induct])
   1.266       apply (rule prem1)
   1.267 -    apply (subgoal_tac "f (b := f b + 1) = (\<lambda>a. f a + (if a = b then 1 else 0))")
   1.268 +    apply (subgoal_tac "f (b := f b + 1) = (\\<lambda>a. f a + (if a = b then 1 else 0))")
   1.269       prefer 2
   1.270       apply (simp add: expand_fun_eq)
   1.271      apply (erule ssubst)
   1.272 @@ -401,7 +401,7 @@
   1.273  
   1.274  
   1.275  lemma MCollect_preserves_multiset:
   1.276 -    "M \<in> multiset ==> (\<lambda>x. if P x then M x else 0) \<in> multiset"
   1.277 +    "M \\<in> multiset ==> (\\<lambda>x. if P x then M x else 0) \\<in> multiset"
   1.278    apply (simp add: multiset_def)
   1.279    apply (rule finite_subset)
   1.280     apply auto
   1.281 @@ -413,11 +413,11 @@
   1.282    apply (simp add: MCollect_preserves_multiset)
   1.283    done
   1.284  
   1.285 -theorem set_of_MCollect [simp]: "set_of {# x:M. P x #} = set_of M \<inter> {x. P x}"
   1.286 +theorem set_of_MCollect [simp]: "set_of {# x:M. P x #} = set_of M \\<inter> {x. P x}"
   1.287    apply (auto simp add: set_of_def)
   1.288    done
   1.289  
   1.290 -theorem multiset_partition: "M = {# x:M. P x #} + {# x:M. \<not> P x #}"
   1.291 +theorem multiset_partition: "M = {# x:M. P x #} + {# x:M. \\<not> P x #}"
   1.292    apply (subst multiset_eq_conv_count_eq)
   1.293    apply auto
   1.294    done
   1.295 @@ -427,7 +427,7 @@
   1.296  
   1.297  theorem add_eq_conv_ex:
   1.298    "(M + {#a#} = N + {#b#}) =
   1.299 -    (M = N \<and> a = b \<or> (\<exists>K. M = K + {#b#} \<and> N = K + {#a#}))"
   1.300 +    (M = N \\<and> a = b \\<or> (\\<exists>K. M = K + {#b#} \\<and> N = K + {#a#}))"
   1.301    apply (auto simp add: add_eq_conv_diff)
   1.302    done
   1.303  
   1.304 @@ -437,41 +437,41 @@
   1.305  subsubsection {* Well-foundedness *}
   1.306  
   1.307  constdefs
   1.308 -  mult1 :: "('a \<times> 'a) set => ('a multiset \<times> 'a multiset) set"
   1.309 +  mult1 :: "('a \\<times> 'a) set => ('a multiset \\<times> 'a multiset) set"
   1.310    "mult1 r ==
   1.311 -    {(N, M). \<exists>a M0 K. M = M0 + {#a#} \<and> N = M0 + K \<and>
   1.312 -      (\<forall>b. b :# K --> (b, a) \<in> r)}"
   1.313 +    {(N, M). \\<exists>a M0 K. M = M0 + {#a#} \\<and> N = M0 + K \\<and>
   1.314 +      (\\<forall>b. b :# K --> (b, a) \\<in> r)}"
   1.315  
   1.316 -  mult :: "('a \<times> 'a) set => ('a multiset \<times> 'a multiset) set"
   1.317 +  mult :: "('a \\<times> 'a) set => ('a multiset \\<times> 'a multiset) set"
   1.318    "mult r == (mult1 r)\<^sup>+"
   1.319  
   1.320 -lemma not_less_empty [iff]: "(M, {#}) \<notin> mult1 r"
   1.321 +lemma not_less_empty [iff]: "(M, {#}) \\<notin> mult1 r"
   1.322    by (simp add: mult1_def)
   1.323  
   1.324 -lemma less_add: "(N, M0 + {#a#}) \<in> mult1 r ==>
   1.325 -    (\<exists>M. (M, M0) \<in> mult1 r \<and> N = M + {#a#}) \<or>
   1.326 -    (\<exists>K. (\<forall>b. b :# K --> (b, a) \<in> r) \<and> N = M0 + K)"
   1.327 -  (concl is "?case1 (mult1 r) \<or> ?case2")
   1.328 +lemma less_add: "(N, M0 + {#a#}) \\<in> mult1 r ==>
   1.329 +    (\\<exists>M. (M, M0) \\<in> mult1 r \\<and> N = M + {#a#}) \\<or>
   1.330 +    (\\<exists>K. (\\<forall>b. b :# K --> (b, a) \\<in> r) \\<and> N = M0 + K)"
   1.331 +  (concl is "?case1 (mult1 r) \\<or> ?case2")
   1.332  proof (unfold mult1_def)
   1.333 -  let ?r = "\<lambda>K a. \<forall>b. b :# K --> (b, a) \<in> r"
   1.334 -  let ?R = "\<lambda>N M. \<exists>a M0 K. M = M0 + {#a#} \<and> N = M0 + K \<and> ?r K a"
   1.335 +  let ?r = "\\<lambda>K a. \\<forall>b. b :# K --> (b, a) \\<in> r"
   1.336 +  let ?R = "\\<lambda>N M. \\<exists>a M0 K. M = M0 + {#a#} \\<and> N = M0 + K \\<and> ?r K a"
   1.337    let ?case1 = "?case1 {(N, M). ?R N M}"
   1.338  
   1.339 -  assume "(N, M0 + {#a#}) \<in> {(N, M). ?R N M}"
   1.340 -  hence "\<exists>a' M0' K.
   1.341 -      M0 + {#a#} = M0' + {#a'#} \<and> N = M0' + K \<and> ?r K a'" by simp
   1.342 -  thus "?case1 \<or> ?case2"
   1.343 +  assume "(N, M0 + {#a#}) \\<in> {(N, M). ?R N M}"
   1.344 +  hence "\\<exists>a' M0' K.
   1.345 +      M0 + {#a#} = M0' + {#a'#} \\<and> N = M0' + K \\<and> ?r K a'" by simp
   1.346 +  thus "?case1 \\<or> ?case2"
   1.347    proof (elim exE conjE)
   1.348      fix a' M0' K
   1.349      assume N: "N = M0' + K" and r: "?r K a'"
   1.350      assume "M0 + {#a#} = M0' + {#a'#}"
   1.351 -    hence "M0 = M0' \<and> a = a' \<or>
   1.352 -        (\<exists>K'. M0 = K' + {#a'#} \<and> M0' = K' + {#a#})"
   1.353 +    hence "M0 = M0' \\<and> a = a' \\<or>
   1.354 +        (\\<exists>K'. M0 = K' + {#a'#} \\<and> M0' = K' + {#a#})"
   1.355        by (simp only: add_eq_conv_ex)
   1.356      thus ?thesis
   1.357      proof (elim disjE conjE exE)
   1.358        assume "M0 = M0'" "a = a'"
   1.359 -      with N r have "?r K a \<and> N = M0 + K" by simp
   1.360 +      with N r have "?r K a \\<and> N = M0 + K" by simp
   1.361        hence ?case2 .. thus ?thesis ..
   1.362      next
   1.363        fix K'
   1.364 @@ -485,78 +485,78 @@
   1.365    qed
   1.366  qed
   1.367  
   1.368 -lemma all_accessible: "wf r ==> \<forall>M. M \<in> acc (mult1 r)"
   1.369 +lemma all_accessible: "wf r ==> \\<forall>M. M \\<in> acc (mult1 r)"
   1.370  proof
   1.371    let ?R = "mult1 r"
   1.372    let ?W = "acc ?R"
   1.373    {
   1.374      fix M M0 a
   1.375 -    assume M0: "M0 \<in> ?W"
   1.376 -      and wf_hyp: "\<forall>b. (b, a) \<in> r --> (\<forall>M \<in> ?W. M + {#b#} \<in> ?W)"
   1.377 -      and acc_hyp: "\<forall>M. (M, M0) \<in> ?R --> M + {#a#} \<in> ?W"
   1.378 -    have "M0 + {#a#} \<in> ?W"
   1.379 +    assume M0: "M0 \\<in> ?W"
   1.380 +      and wf_hyp: "\\<forall>b. (b, a) \\<in> r --> (\\<forall>M \\<in> ?W. M + {#b#} \\<in> ?W)"
   1.381 +      and acc_hyp: "\\<forall>M. (M, M0) \\<in> ?R --> M + {#a#} \\<in> ?W"
   1.382 +    have "M0 + {#a#} \\<in> ?W"
   1.383      proof (rule accI [of "M0 + {#a#}"])
   1.384        fix N
   1.385 -      assume "(N, M0 + {#a#}) \<in> ?R"
   1.386 -      hence "((\<exists>M. (M, M0) \<in> ?R \<and> N = M + {#a#}) \<or>
   1.387 -          (\<exists>K. (\<forall>b. b :# K --> (b, a) \<in> r) \<and> N = M0 + K))"
   1.388 +      assume "(N, M0 + {#a#}) \\<in> ?R"
   1.389 +      hence "((\\<exists>M. (M, M0) \\<in> ?R \\<and> N = M + {#a#}) \\<or>
   1.390 +          (\\<exists>K. (\\<forall>b. b :# K --> (b, a) \\<in> r) \\<and> N = M0 + K))"
   1.391          by (rule less_add)
   1.392 -      thus "N \<in> ?W"
   1.393 +      thus "N \\<in> ?W"
   1.394        proof (elim exE disjE conjE)
   1.395 -        fix M assume "(M, M0) \<in> ?R" and N: "N = M + {#a#}"
   1.396 -        from acc_hyp have "(M, M0) \<in> ?R --> M + {#a#} \<in> ?W" ..
   1.397 -        hence "M + {#a#} \<in> ?W" ..
   1.398 -        thus "N \<in> ?W" by (simp only: N)
   1.399 +        fix M assume "(M, M0) \\<in> ?R" and N: "N = M + {#a#}"
   1.400 +        from acc_hyp have "(M, M0) \\<in> ?R --> M + {#a#} \\<in> ?W" ..
   1.401 +        hence "M + {#a#} \\<in> ?W" ..
   1.402 +        thus "N \\<in> ?W" by (simp only: N)
   1.403        next
   1.404          fix K
   1.405          assume N: "N = M0 + K"
   1.406 -        assume "\<forall>b. b :# K --> (b, a) \<in> r"
   1.407 -        have "?this --> M0 + K \<in> ?W" (is "?P K")
   1.408 +        assume "\\<forall>b. b :# K --> (b, a) \\<in> r"
   1.409 +        have "?this --> M0 + K \\<in> ?W" (is "?P K")
   1.410          proof (induct K)
   1.411 -          from M0 have "M0 + {#} \<in> ?W" by simp
   1.412 +          from M0 have "M0 + {#} \\<in> ?W" by simp
   1.413            thus "?P {#}" ..
   1.414  
   1.415            fix K x assume hyp: "?P K"
   1.416            show "?P (K + {#x#})"
   1.417            proof
   1.418 -            assume a: "\<forall>b. b :# (K + {#x#}) --> (b, a) \<in> r"
   1.419 -            hence "(x, a) \<in> r" by simp
   1.420 -            with wf_hyp have b: "\<forall>M \<in> ?W. M + {#x#} \<in> ?W" by blast
   1.421 +            assume a: "\\<forall>b. b :# (K + {#x#}) --> (b, a) \\<in> r"
   1.422 +            hence "(x, a) \\<in> r" by simp
   1.423 +            with wf_hyp have b: "\\<forall>M \\<in> ?W. M + {#x#} \\<in> ?W" by blast
   1.424  
   1.425 -            from a hyp have "M0 + K \<in> ?W" by simp
   1.426 -            with b have "(M0 + K) + {#x#} \<in> ?W" ..
   1.427 -            thus "M0 + (K + {#x#}) \<in> ?W" by (simp only: union_assoc)
   1.428 +            from a hyp have "M0 + K \\<in> ?W" by simp
   1.429 +            with b have "(M0 + K) + {#x#} \\<in> ?W" ..
   1.430 +            thus "M0 + (K + {#x#}) \\<in> ?W" by (simp only: union_assoc)
   1.431            qed
   1.432          qed
   1.433 -        hence "M0 + K \<in> ?W" ..
   1.434 -        thus "N \<in> ?W" by (simp only: N)
   1.435 +        hence "M0 + K \\<in> ?W" ..
   1.436 +        thus "N \\<in> ?W" by (simp only: N)
   1.437        qed
   1.438      qed
   1.439    } note tedious_reasoning = this
   1.440  
   1.441    assume wf: "wf r"
   1.442    fix M
   1.443 -  show "M \<in> ?W"
   1.444 +  show "M \\<in> ?W"
   1.445    proof (induct M)
   1.446 -    show "{#} \<in> ?W"
   1.447 +    show "{#} \\<in> ?W"
   1.448      proof (rule accI)
   1.449 -      fix b assume "(b, {#}) \<in> ?R"
   1.450 -      with not_less_empty show "b \<in> ?W" by contradiction
   1.451 +      fix b assume "(b, {#}) \\<in> ?R"
   1.452 +      with not_less_empty show "b \\<in> ?W" by contradiction
   1.453      qed
   1.454  
   1.455 -    fix M a assume "M \<in> ?W"
   1.456 -    from wf have "\<forall>M \<in> ?W. M + {#a#} \<in> ?W"
   1.457 +    fix M a assume "M \\<in> ?W"
   1.458 +    from wf have "\\<forall>M \\<in> ?W. M + {#a#} \\<in> ?W"
   1.459      proof induct
   1.460        fix a
   1.461 -      assume "\<forall>b. (b, a) \<in> r --> (\<forall>M \<in> ?W. M + {#b#} \<in> ?W)"
   1.462 -      show "\<forall>M \<in> ?W. M + {#a#} \<in> ?W"
   1.463 +      assume "\\<forall>b. (b, a) \\<in> r --> (\\<forall>M \\<in> ?W. M + {#b#} \\<in> ?W)"
   1.464 +      show "\\<forall>M \\<in> ?W. M + {#a#} \\<in> ?W"
   1.465        proof
   1.466 -        fix M assume "M \<in> ?W"
   1.467 -        thus "M + {#a#} \<in> ?W"
   1.468 +        fix M assume "M \\<in> ?W"
   1.469 +        thus "M + {#a#} \\<in> ?W"
   1.470            by (rule acc_induct) (rule tedious_reasoning)
   1.471        qed
   1.472      qed
   1.473 -    thus "M + {#a#} \<in> ?W" ..
   1.474 +    thus "M + {#a#} \\<in> ?W" ..
   1.475    qed
   1.476  qed
   1.477  
   1.478 @@ -578,9 +578,9 @@
   1.479  text {* One direction. *}
   1.480  
   1.481  lemma mult_implies_one_step:
   1.482 -  "trans r ==> (M, N) \<in> mult r ==>
   1.483 -    \<exists>I J K. N = I + J \<and> M = I + K \<and> J \<noteq> {#} \<and>
   1.484 -    (\<forall>k \<in> set_of K. \<exists>j \<in> set_of J. (k, j) \<in> r)"
   1.485 +  "trans r ==> (M, N) \\<in> mult r ==>
   1.486 +    \\<exists>I J K. N = I + J \\<and> M = I + K \\<and> J \\<noteq> {#} \\<and>
   1.487 +    (\\<forall>k \\<in> set_of K. \\<exists>j \\<in> set_of J. (k, j) \\<in> r)"
   1.488    apply (unfold mult_def mult1_def set_of_def)
   1.489    apply (erule converse_trancl_induct)
   1.490    apply clarify
   1.491 @@ -592,7 +592,7 @@
   1.492     apply (simp (no_asm))
   1.493     apply (rule_tac x = "(K - {#a#}) + Ka" in exI)
   1.494     apply (simp (no_asm_simp) add: union_assoc [symmetric])
   1.495 -   apply (drule_tac f = "\<lambda>M. M - {#a#}" in arg_cong)
   1.496 +   apply (drule_tac f = "\\<lambda>M. M - {#a#}" in arg_cong)
   1.497     apply (simp add: diff_union_single_conv)
   1.498     apply (simp (no_asm_use) add: trans_def)
   1.499     apply blast
   1.500 @@ -603,7 +603,7 @@
   1.501     apply (rule conjI)
   1.502      apply (simp add: multiset_eq_conv_count_eq split: nat_diff_split)
   1.503     apply (rule conjI)
   1.504 -    apply (drule_tac f = "\<lambda>M. M - {#a#}" in arg_cong)
   1.505 +    apply (drule_tac f = "\\<lambda>M. M - {#a#}" in arg_cong)
   1.506      apply simp
   1.507      apply (simp add: multiset_eq_conv_count_eq split: nat_diff_split)
   1.508     apply (simp (no_asm_use) add: trans_def)
   1.509 @@ -617,7 +617,7 @@
   1.510    apply (simp add: multiset_eq_conv_count_eq)
   1.511    done
   1.512  
   1.513 -lemma size_eq_Suc_imp_eq_union: "size M = Suc n ==> \<exists>a N. M = N + {#a#}"
   1.514 +lemma size_eq_Suc_imp_eq_union: "size M = Suc n ==> \\<exists>a N. M = N + {#a#}"
   1.515    apply (erule size_eq_Suc_imp_elem [THEN exE])
   1.516    apply (drule elem_imp_eq_diff_union)
   1.517    apply auto
   1.518 @@ -625,8 +625,8 @@
   1.519  
   1.520  lemma one_step_implies_mult_aux:
   1.521    "trans r ==>
   1.522 -    \<forall>I J K. (size J = n \<and> J \<noteq> {#} \<and> (\<forall>k \<in> set_of K. \<exists>j \<in> set_of J. (k, j) \<in> r))
   1.523 -      --> (I + K, I + J) \<in> mult r"
   1.524 +    \\<forall>I J K. (size J = n \\<and> J \\<noteq> {#} \\<and> (\\<forall>k \\<in> set_of K. \\<exists>j \\<in> set_of J. (k, j) \\<in> r))
   1.525 +      --> (I + K, I + J) \\<in> mult r"
   1.526    apply (induct_tac n)
   1.527     apply auto
   1.528    apply (frule size_eq_Suc_imp_eq_union)
   1.529 @@ -640,15 +640,15 @@
   1.530     apply (rule r_into_trancl)
   1.531     apply (simp add: mult1_def set_of_def)
   1.532     apply blast
   1.533 -  txt {* Now we know @{term "J' \<noteq> {#}"}. *}
   1.534 -  apply (cut_tac M = K and P = "\<lambda>x. (x, a) \<in> r" in multiset_partition)
   1.535 -  apply (erule_tac P = "\<forall>k \<in> set_of K. ?P k" in rev_mp)
   1.536 +  txt {* Now we know @{term "J' \\<noteq> {#}"}. *}
   1.537 +  apply (cut_tac M = K and P = "\\<lambda>x. (x, a) \\<in> r" in multiset_partition)
   1.538 +  apply (erule_tac P = "\\<forall>k \\<in> set_of K. ?P k" in rev_mp)
   1.539    apply (erule ssubst)
   1.540    apply (simp add: Ball_def)
   1.541    apply auto
   1.542    apply (subgoal_tac
   1.543 -    "((I + {# x : K. (x, a) \<in> r #}) + {# x : K. (x, a) \<notin> r #},
   1.544 -      (I + {# x : K. (x, a) \<in> r #}) + J') \<in> mult r")
   1.545 +    "((I + {# x : K. (x, a) \\<in> r #}) + {# x : K. (x, a) \\<notin> r #},
   1.546 +      (I + {# x : K. (x, a) \\<in> r #}) + J') \\<in> mult r")
   1.547     prefer 2
   1.548     apply force
   1.549    apply (simp (no_asm_use) add: union_assoc [symmetric] mult_def)
   1.550 @@ -661,8 +661,8 @@
   1.551    done
   1.552  
   1.553  theorem one_step_implies_mult:
   1.554 -  "trans r ==> J \<noteq> {#} ==> \<forall>k \<in> set_of K. \<exists>j \<in> set_of J. (k, j) \<in> r
   1.555 -    ==> (I + K, I + J) \<in> mult r"
   1.556 +  "trans r ==> J \\<noteq> {#} ==> \\<forall>k \\<in> set_of K. \\<exists>j \\<in> set_of J. (k, j) \\<in> r
   1.557 +    ==> (I + K, I + J) \\<in> mult r"
   1.558    apply (insert one_step_implies_mult_aux)
   1.559    apply blast
   1.560    done
   1.561 @@ -673,8 +673,8 @@
   1.562  instance multiset :: ("term") ord ..
   1.563  
   1.564  defs (overloaded)
   1.565 -  less_multiset_def: "M' < M == (M', M) \<in> mult {(x', x). x' < x}"
   1.566 -  le_multiset_def: "M' <= M == M' = M \<or> M' < (M::'a multiset)"
   1.567 +  less_multiset_def: "M' < M == (M', M) \\<in> mult {(x', x). x' < x}"
   1.568 +  le_multiset_def: "M' <= M == M' = M \\<or> M' < (M::'a multiset)"
   1.569  
   1.570  lemma trans_base_order: "trans {(x', x). x' < (x::'a::order)}"
   1.571    apply (unfold trans_def)
   1.572 @@ -686,12 +686,12 @@
   1.573  *}
   1.574  
   1.575  lemma mult_irrefl_aux:
   1.576 -    "finite A ==> (\<forall>x \<in> A. \<exists>y \<in> A. x < (y::'a::order)) --> A = {}"
   1.577 +    "finite A ==> (\\<forall>x \\<in> A. \\<exists>y \\<in> A. x < (y::'a::order)) --> A = {}"
   1.578    apply (erule finite_induct)
   1.579     apply (auto intro: order_less_trans)
   1.580    done
   1.581  
   1.582 -theorem mult_less_not_refl: "\<not> M < (M::'a::order multiset)"
   1.583 +theorem mult_less_not_refl: "\\<not> M < (M::'a::order multiset)"
   1.584    apply (unfold less_multiset_def)
   1.585    apply auto
   1.586    apply (drule trans_base_order [THEN mult_implies_one_step])
   1.587 @@ -715,7 +715,7 @@
   1.588  
   1.589  text {* Asymmetry. *}
   1.590  
   1.591 -theorem mult_less_not_sym: "M < N ==> \<not> N < (M::'a::order multiset)"
   1.592 +theorem mult_less_not_sym: "M < N ==> \\<not> N < (M::'a::order multiset)"
   1.593    apply auto
   1.594    apply (rule mult_less_not_refl [THEN notE])
   1.595    apply (erule mult_less_trans)
   1.596 @@ -723,7 +723,7 @@
   1.597    done
   1.598  
   1.599  theorem mult_less_asym:
   1.600 -    "M < N ==> (\<not> P ==> N < (M::'a::order multiset)) ==> P"
   1.601 +    "M < N ==> (\\<not> P ==> N < (M::'a::order multiset)) ==> P"
   1.602    apply (insert mult_less_not_sym)
   1.603    apply blast
   1.604    done
   1.605 @@ -749,7 +749,7 @@
   1.606    apply (blast intro: mult_less_trans)
   1.607    done
   1.608  
   1.609 -theorem mult_less_le: "M < N = (M <= N \<and> M \<noteq> (N::'a::order multiset))"
   1.610 +theorem mult_less_le: "M < N = (M <= N \\<and> M \\<noteq> (N::'a::order multiset))"
   1.611    apply (unfold le_multiset_def)
   1.612    apply auto
   1.613    done
   1.614 @@ -770,7 +770,7 @@
   1.615  subsubsection {* Monotonicity of multiset union *}
   1.616  
   1.617  theorem mult1_union:
   1.618 -    "(B, D) \<in> mult1 r ==> trans r ==> (C + B, C + D) \<in> mult1 r"
   1.619 +    "(B, D) \\<in> mult1 r ==> trans r ==> (C + B, C + D) \\<in> mult1 r"
   1.620    apply (unfold mult1_def)
   1.621    apply auto
   1.622    apply (rule_tac x = a in exI)
   1.623 @@ -806,7 +806,7 @@
   1.624    apply (unfold le_multiset_def less_multiset_def)
   1.625    apply (case_tac "M = {#}")
   1.626     prefer 2
   1.627 -   apply (subgoal_tac "({#} + {#}, {#} + M) \<in> mult (Collect (split op <))")
   1.628 +   apply (subgoal_tac "({#} + {#}, {#} + M) \\<in> mult (Collect (split op <))")
   1.629      prefer 2
   1.630      apply (rule one_step_implies_mult)
   1.631        apply (simp only: trans_def)