src/HOL/Library/Multiset.thy
author kleing
Wed, 02 Jan 2008 04:10:47 +0100
changeset 25759 6326138c1bd7
parent 25623 baa627b6f962
child 26016 f9d1bf2fc59c
permissions -rw-r--r--
renamed foldM to fold_mset on general request added Tobias' lemmas on fold_mset (A+B) etc tuned default simp set for fold_mset
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Library/Multiset.thy
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
     3
    Author:     Tobias Nipkow, Markus Wenzel, Lawrence C Paulson, Norbert Voelker
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
     4
*)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
     5
14706
71590b7733b7 tuned document;
wenzelm
parents: 14691
diff changeset
     6
header {* Multisets *}
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
     7
15131
c69542757a4d New theory header syntax.
nipkow
parents: 15072
diff changeset
     8
theory Multiset
25595
6c48275f9c76 switched import from Main to List
haftmann
parents: 25571
diff changeset
     9
imports List
15131
c69542757a4d New theory header syntax.
nipkow
parents: 15072
diff changeset
    10
begin
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    11
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    12
subsection {* The type of multisets *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    13
25162
ad4d5365d9d8 went back to >0
nipkow
parents: 25140
diff changeset
    14
typedef 'a multiset = "{f::'a => nat. finite {x . f x > 0}}"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    15
proof
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
    16
  show "(\<lambda>x. 0::nat) \<in> ?multiset" by simp
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    17
qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    18
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    19
lemmas multiset_typedef [simp] =
10277
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
    20
    Abs_multiset_inverse Rep_multiset_inverse Rep_multiset
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
    21
  and [simp] = Rep_multiset_inject [symmetric]
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    22
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
    23
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21214
diff changeset
    24
  Mempty :: "'a multiset"  ("{#}") where
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
    25
  "{#} = Abs_multiset (\<lambda>a. 0)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    26
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21214
diff changeset
    27
definition
25507
d13468d40131 added {#.,.,...#}
nipkow
parents: 25208
diff changeset
    28
  single :: "'a => 'a multiset" where
d13468d40131 added {#.,.,...#}
nipkow
parents: 25208
diff changeset
    29
  "single a = Abs_multiset (\<lambda>b. if b = a then 1 else 0)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    30
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21214
diff changeset
    31
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21214
diff changeset
    32
  count :: "'a multiset => 'a => nat" where
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
    33
  "count = Rep_multiset"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    34
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21214
diff changeset
    35
definition
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21214
diff changeset
    36
  MCollect :: "'a multiset => ('a => bool) => 'a multiset" where
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
    37
  "MCollect M P = Abs_multiset (\<lambda>x. if P x then Rep_multiset M x else 0)"
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
    38
19363
667b5ea637dd refined 'abbreviation';
wenzelm
parents: 19086
diff changeset
    39
abbreviation
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21214
diff changeset
    40
  Melem :: "'a => 'a multiset => bool"  ("(_/ :# _)" [50, 51] 50) where
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
    41
  "a :# M == 0 < count M a"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
    42
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
    43
notation (xsymbols) Melem (infix "\<in>#" 50)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    44
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    45
syntax
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    46
  "_MCollect" :: "pttrn => 'a multiset => bool => 'a multiset"    ("(1{# _ : _./ _#})")
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    47
translations
20770
2c583720436e fixed translations: CONST;
wenzelm
parents: 20503
diff changeset
    48
  "{#x:M. P#}" == "CONST MCollect M (\<lambda>x. P)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    49
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
    50
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21214
diff changeset
    51
  set_of :: "'a multiset => 'a set" where
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
    52
  "set_of M = {x. x :# M}"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    53
25571
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25507
diff changeset
    54
instantiation multiset :: (type) "{plus, minus, zero, size}" 
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25507
diff changeset
    55
begin
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25507
diff changeset
    56
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25507
diff changeset
    57
definition
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
    58
  union_def: "M + N == Abs_multiset (\<lambda>a. Rep_multiset M a + Rep_multiset N a)"
25571
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25507
diff changeset
    59
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25507
diff changeset
    60
definition
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
    61
  diff_def: "M - N == Abs_multiset (\<lambda>a. Rep_multiset M a - Rep_multiset N a)"
25571
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25507
diff changeset
    62
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25507
diff changeset
    63
definition
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11655
diff changeset
    64
  Zero_multiset_def [simp]: "0 == {#}"
25571
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25507
diff changeset
    65
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25507
diff changeset
    66
definition
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25507
diff changeset
    67
  size_def: "size M == setsum (count M) (set_of M)"
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25507
diff changeset
    68
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25507
diff changeset
    69
instance ..
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25507
diff changeset
    70
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25507
diff changeset
    71
end
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    72
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
    73
definition
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21214
diff changeset
    74
  multiset_inter :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> 'a multiset"  (infixl "#\<inter>" 70) where
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
    75
  "multiset_inter A B = A - (A - B)"
15869
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
    76
25507
d13468d40131 added {#.,.,...#}
nipkow
parents: 25208
diff changeset
    77
syntax -- "Multiset Enumeration"
d13468d40131 added {#.,.,...#}
nipkow
parents: 25208
diff changeset
    78
  "@multiset" :: "args => 'a multiset"    ("{#(_)#}")
d13468d40131 added {#.,.,...#}
nipkow
parents: 25208
diff changeset
    79
d13468d40131 added {#.,.,...#}
nipkow
parents: 25208
diff changeset
    80
translations
d13468d40131 added {#.,.,...#}
nipkow
parents: 25208
diff changeset
    81
  "{#x, xs#}" == "{#x#} + {#xs#}"
d13468d40131 added {#.,.,...#}
nipkow
parents: 25208
diff changeset
    82
  "{#x#}" == "CONST single x"
d13468d40131 added {#.,.,...#}
nipkow
parents: 25208
diff changeset
    83
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    84
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    85
text {*
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    86
 \medskip Preservation of the representing set @{term multiset}.
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    87
*}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    88
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
    89
lemma const0_in_multiset [simp]: "(\<lambda>a. 0) \<in> multiset"
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
    90
  by (simp add: multiset_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    91
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11655
diff changeset
    92
lemma only1_in_multiset [simp]: "(\<lambda>b. if b = a then 1 else 0) \<in> multiset"
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
    93
  by (simp add: multiset_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    94
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    95
lemma union_preserves_multiset [simp]:
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
    96
    "M \<in> multiset ==> N \<in> multiset ==> (\<lambda>a. M a + N a) \<in> multiset"
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
    97
  apply (simp add: multiset_def)
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
    98
  apply (drule (1) finite_UnI)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    99
  apply (simp del: finite_Un add: Un_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   100
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   101
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   102
lemma diff_preserves_multiset [simp]:
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   103
    "M \<in> multiset ==> (\<lambda>a. M a - N a) \<in> multiset"
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   104
  apply (simp add: multiset_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   105
  apply (rule finite_subset)
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   106
   apply auto
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   107
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   108
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   109
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   110
subsection {* Algebraic properties of multisets *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   111
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   112
subsubsection {* Union *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   113
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   114
lemma union_empty [simp]: "M + {#} = M \<and> {#} + M = M"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   115
  by (simp add: union_def Mempty_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   116
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   117
lemma union_commute: "M + N = N + (M::'a multiset)"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   118
  by (simp add: union_def add_ac)
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   119
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   120
lemma union_assoc: "(M + N) + K = M + (N + (K::'a multiset))"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   121
  by (simp add: union_def add_ac)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   122
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   123
lemma union_lcomm: "M + (N + K) = N + (M + (K::'a multiset))"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   124
proof -
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   125
  have "M + (N + K) = (N + K) + M"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   126
    by (rule union_commute)
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   127
  also have "\<dots> = N + (K + M)"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   128
    by (rule union_assoc)
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   129
  also have "K + M = M + K"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   130
    by (rule union_commute)
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   131
  finally show ?thesis .
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   132
qed
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   133
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   134
lemmas union_ac = union_assoc union_commute union_lcomm
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   135
14738
83f1a514dcb4 changes made due to new Ring_and_Field theory
obua
parents: 14722
diff changeset
   136
instance multiset :: (type) comm_monoid_add
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   137
proof
14722
8e739a6eaf11 replaced apply-style proof for instance Multiset :: plus_ac0 by recommended Isar proof style
obua
parents: 14706
diff changeset
   138
  fix a b c :: "'a multiset"
8e739a6eaf11 replaced apply-style proof for instance Multiset :: plus_ac0 by recommended Isar proof style
obua
parents: 14706
diff changeset
   139
  show "(a + b) + c = a + (b + c)" by (rule union_assoc)
8e739a6eaf11 replaced apply-style proof for instance Multiset :: plus_ac0 by recommended Isar proof style
obua
parents: 14706
diff changeset
   140
  show "a + b = b + a" by (rule union_commute)
8e739a6eaf11 replaced apply-style proof for instance Multiset :: plus_ac0 by recommended Isar proof style
obua
parents: 14706
diff changeset
   141
  show "0 + a = a" by simp
8e739a6eaf11 replaced apply-style proof for instance Multiset :: plus_ac0 by recommended Isar proof style
obua
parents: 14706
diff changeset
   142
qed
10277
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   143
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   144
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   145
subsubsection {* Difference *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   146
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   147
lemma diff_empty [simp]: "M - {#} = M \<and> {#} - M = {#}"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   148
  by (simp add: Mempty_def diff_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   149
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   150
lemma diff_union_inverse2 [simp]: "M + {#a#} - {#a#} = M"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   151
  by (simp add: union_def diff_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   152
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   153
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   154
subsubsection {* Count of elements *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   155
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   156
lemma count_empty [simp]: "count {#} a = 0"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   157
  by (simp add: count_def Mempty_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   158
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   159
lemma count_single [simp]: "count {#b#} a = (if b = a then 1 else 0)"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   160
  by (simp add: count_def single_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   161
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   162
lemma count_union [simp]: "count (M + N) a = count M a + count N a"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   163
  by (simp add: count_def union_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   164
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   165
lemma count_diff [simp]: "count (M - N) a = count M a - count N a"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   166
  by (simp add: count_def diff_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   167
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   168
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   169
subsubsection {* Set of elements *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   170
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   171
lemma set_of_empty [simp]: "set_of {#} = {}"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   172
  by (simp add: set_of_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   173
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   174
lemma set_of_single [simp]: "set_of {#b#} = {b}"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   175
  by (simp add: set_of_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   176
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   177
lemma set_of_union [simp]: "set_of (M + N) = set_of M \<union> set_of N"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   178
  by (auto simp add: set_of_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   179
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   180
lemma set_of_eq_empty_iff [simp]: "(set_of M = {}) = (M = {#})"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   181
  by (auto simp add: set_of_def Mempty_def count_def expand_fun_eq)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   182
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   183
lemma mem_set_of_iff [simp]: "(x \<in> set_of M) = (x :# M)"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   184
  by (auto simp add: set_of_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   185
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   186
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   187
subsubsection {* Size *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   188
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   189
lemma size_empty [simp]: "size {#} = 0"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   190
  by (simp add: size_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   191
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   192
lemma size_single [simp]: "size {#b#} = 1"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   193
  by (simp add: size_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   194
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   195
lemma finite_set_of [iff]: "finite (set_of M)"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   196
  using Rep_multiset [of M]
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   197
  by (simp add: multiset_def set_of_def count_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   198
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   199
lemma setsum_count_Int:
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   200
    "finite A ==> setsum (count N) (A \<inter> set_of N) = setsum (count N) A"
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   201
  apply (induct rule: finite_induct)
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   202
   apply simp
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   203
  apply (simp add: Int_insert_left set_of_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   204
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   205
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   206
lemma size_union [simp]: "size (M + N::'a multiset) = size M + size N"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   207
  apply (unfold size_def)
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   208
  apply (subgoal_tac "count (M + N) = (\<lambda>a. count M a + count N a)")
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   209
   prefer 2
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   210
   apply (rule ext, simp)
15402
97204f3b4705 REorganized Finite_Set
nipkow
parents: 15316
diff changeset
   211
  apply (simp (no_asm_simp) add: setsum_Un_nat setsum_addf setsum_count_Int)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   212
  apply (subst Int_commute)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   213
  apply (simp (no_asm_simp) add: setsum_count_Int)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   214
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   215
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   216
lemma size_eq_0_iff_empty [iff]: "(size M = 0) = (M = {#})"
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   217
  apply (unfold size_def Mempty_def count_def, auto)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   218
  apply (simp add: set_of_def count_def expand_fun_eq)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   219
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   220
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   221
lemma size_eq_Suc_imp_elem: "size M = Suc n ==> \<exists>a. a :# M"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   222
  apply (unfold size_def)
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   223
  apply (drule setsum_SucD, auto)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   224
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   225
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   226
subsubsection {* Equality of multisets *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   227
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   228
lemma multiset_eq_conv_count_eq: "(M = N) = (\<forall>a. count M a = count N a)"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   229
  by (simp add: count_def expand_fun_eq)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   230
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   231
lemma single_not_empty [simp]: "{#a#} \<noteq> {#} \<and> {#} \<noteq> {#a#}"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   232
  by (simp add: single_def Mempty_def expand_fun_eq)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   233
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   234
lemma single_eq_single [simp]: "({#a#} = {#b#}) = (a = b)"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   235
  by (auto simp add: single_def expand_fun_eq)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   236
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   237
lemma union_eq_empty [iff]: "(M + N = {#}) = (M = {#} \<and> N = {#})"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   238
  by (auto simp add: union_def Mempty_def expand_fun_eq)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   239
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   240
lemma empty_eq_union [iff]: "({#} = M + N) = (M = {#} \<and> N = {#})"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   241
  by (auto simp add: union_def Mempty_def expand_fun_eq)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   242
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   243
lemma union_right_cancel [simp]: "(M + K = N + K) = (M = (N::'a multiset))"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   244
  by (simp add: union_def expand_fun_eq)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   245
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   246
lemma union_left_cancel [simp]: "(K + M = K + N) = (M = (N::'a multiset))"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   247
  by (simp add: union_def expand_fun_eq)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   248
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   249
lemma union_is_single:
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   250
    "(M + N = {#a#}) = (M = {#a#} \<and> N={#} \<or> M = {#} \<and> N = {#a#})"
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   251
  apply (simp add: Mempty_def single_def union_def add_is_1 expand_fun_eq)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   252
  apply blast
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   253
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   254
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   255
lemma single_is_union:
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   256
     "({#a#} = M + N) = ({#a#} = M \<and> N = {#} \<or> M = {#} \<and> {#a#} = N)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   257
  apply (unfold Mempty_def single_def union_def)
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   258
  apply (simp add: add_is_1 one_is_add expand_fun_eq)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   259
  apply (blast dest: sym)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   260
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   261
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   262
lemma add_eq_conv_diff:
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   263
  "(M + {#a#} = N + {#b#}) =
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   264
   (M = N \<and> a = b \<or> M = N - {#a#} + {#b#} \<and> N = M - {#b#} + {#a#})"
24035
74c032aea9ed simplified ResAtpset via NamedThmsFun;
wenzelm
parents: 23751
diff changeset
   265
  using [[simproc del: neq]]
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   266
  apply (unfold single_def union_def diff_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   267
  apply (simp (no_asm) add: expand_fun_eq)
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   268
  apply (rule conjI, force, safe, simp_all)
13601
fd3e3d6b37b2 Adapted to new simplifier.
berghofe
parents: 13596
diff changeset
   269
  apply (simp add: eq_sym_conv)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   270
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   271
15869
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   272
declare Rep_multiset_inject [symmetric, simp del]
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   273
23611
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   274
instance multiset :: (type) cancel_ab_semigroup_add
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   275
proof
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   276
  fix a b c :: "'a multiset"
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   277
  show "a + b = a + c \<Longrightarrow> b = c" by simp
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   278
qed
15869
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   279
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   280
lemma insert_DiffM:
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   281
  "x \<in># M \<Longrightarrow> {#x#} + (M - {#x#}) = M"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   282
  by (clarsimp simp: multiset_eq_conv_count_eq)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   283
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   284
lemma insert_DiffM2[simp]:
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   285
  "x \<in># M \<Longrightarrow> M - {#x#} + {#x#} = M"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   286
  by (clarsimp simp: multiset_eq_conv_count_eq)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   287
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   288
lemma multi_union_self_other_eq: 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   289
  "(A::'a multiset) + X = A + Y \<Longrightarrow> X = Y"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   290
  by (induct A arbitrary: X Y, auto)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   291
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   292
lemma multi_self_add_other_not_self[simp]: "(A = A + {#x#}) = False"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   293
proof -
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   294
  {
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   295
    assume a: "A = A + {#x#}"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   296
    have "A = A + {#}" by simp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   297
    hence "A + {#} = A + {#x#}" using a by auto 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   298
    hence "{#} = {#x#}"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   299
      by - (drule multi_union_self_other_eq)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   300
    hence False by auto
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   301
  }
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   302
  thus ?thesis by blast
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   303
qed
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   304
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   305
lemma insert_noteq_member: 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   306
  assumes BC: "B + {#b#} = C + {#c#}"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   307
   and bnotc: "b \<noteq> c"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   308
  shows "c \<in># B"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   309
proof -
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   310
  have "c \<in># C + {#c#}" by simp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   311
  have nc: "\<not> c \<in># {#b#}" using bnotc by simp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   312
  hence "c \<in># B + {#b#}" using BC by simp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   313
  thus "c \<in># B" using nc by simp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   314
qed
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   315
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   316
15869
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   317
subsubsection {* Intersection *}
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   318
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   319
lemma multiset_inter_count:
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   320
    "count (A #\<inter> B) x = min (count A x) (count B x)"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   321
  by (simp add: multiset_inter_def min_def)
15869
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   322
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   323
lemma multiset_inter_commute: "A #\<inter> B = B #\<inter> A"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   324
  by (simp add: multiset_eq_conv_count_eq multiset_inter_count
21214
a91bab12b2bd adjusted two lemma names due to name change in interpretation
haftmann
parents: 20770
diff changeset
   325
    min_max.inf_commute)
15869
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   326
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   327
lemma multiset_inter_assoc: "A #\<inter> (B #\<inter> C) = A #\<inter> B #\<inter> C"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   328
  by (simp add: multiset_eq_conv_count_eq multiset_inter_count
21214
a91bab12b2bd adjusted two lemma names due to name change in interpretation
haftmann
parents: 20770
diff changeset
   329
    min_max.inf_assoc)
15869
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   330
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   331
lemma multiset_inter_left_commute: "A #\<inter> (B #\<inter> C) = B #\<inter> (A #\<inter> C)"
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   332
  by (simp add: multiset_eq_conv_count_eq multiset_inter_count min_def)
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   333
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   334
lemmas multiset_inter_ac =
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   335
  multiset_inter_commute
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   336
  multiset_inter_assoc
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   337
  multiset_inter_left_commute
15869
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   338
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   339
lemma multiset_union_diff_commute: "B #\<inter> C = {#} \<Longrightarrow> A + B - C = A - C + B"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   340
  apply (simp add: multiset_eq_conv_count_eq multiset_inter_count min_def
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   341
    split: split_if_asm)
15869
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   342
  apply clarsimp
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   343
  apply (erule_tac x = a in allE)
15869
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   344
  apply auto
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   345
  done
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   346
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   347
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   348
subsection {* Induction over multisets *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   349
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   350
lemma setsum_decr:
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11655
diff changeset
   351
  "finite F ==> (0::nat) < f a ==>
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   352
    setsum (f (a := f a - 1)) F = (if a\<in>F then setsum f F - 1 else setsum f F)"
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   353
  apply (induct rule: finite_induct)
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   354
   apply auto
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   355
  apply (drule_tac a = a in mk_disjoint_insert, auto)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   356
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   357
10313
51e830bb7abe intro_classes by default;
wenzelm
parents: 10277
diff changeset
   358
lemma rep_multiset_induct_aux:
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   359
  assumes 1: "P (\<lambda>a. (0::nat))"
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   360
    and 2: "!!f b. f \<in> multiset ==> P f ==> P (f (b := f b + 1))"
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 24035
diff changeset
   361
  shows "\<forall>f. f \<in> multiset --> setsum f {x. f x \<noteq> 0} = n --> P f"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   362
  apply (unfold multiset_def)
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   363
  apply (induct_tac n, simp, clarify)
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   364
   apply (subgoal_tac "f = (\<lambda>a.0)")
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   365
    apply simp
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   366
    apply (rule 1)
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   367
   apply (rule ext, force, clarify)
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   368
  apply (frule setsum_SucD, clarify)
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   369
  apply (rename_tac a)
25162
ad4d5365d9d8 went back to >0
nipkow
parents: 25140
diff changeset
   370
  apply (subgoal_tac "finite {x. (f (a := f a - 1)) x > 0}")
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   371
   prefer 2
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   372
   apply (rule finite_subset)
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   373
    prefer 2
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   374
    apply assumption
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   375
   apply simp
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   376
   apply blast
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   377
  apply (subgoal_tac "f = (f (a := f a - 1))(a := (f (a := f a - 1)) a + 1)")
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   378
   prefer 2
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   379
   apply (rule ext)
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   380
   apply (simp (no_asm_simp))
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   381
   apply (erule ssubst, rule 2 [unfolded multiset_def], blast)
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   382
  apply (erule allE, erule impE, erule_tac [2] mp, blast)
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   383
  apply (simp (no_asm_simp) add: setsum_decr del: fun_upd_apply One_nat_def)
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 24035
diff changeset
   384
  apply (subgoal_tac "{x. x \<noteq> a --> f x \<noteq> 0} = {x. f x \<noteq> 0}")
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   385
   prefer 2
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   386
   apply blast
25134
3d4953e88449 Eliminated most of the neq0_conv occurrences. As a result, many
nipkow
parents: 24035
diff changeset
   387
  apply (subgoal_tac "{x. x \<noteq> a \<and> f x \<noteq> 0} = {x. f x \<noteq> 0} - {a}")
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   388
   prefer 2
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   389
   apply blast
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   390
  apply (simp add: le_imp_diff_is_add setsum_diff1_nat cong: conj_cong)
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   391
  done
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   392
10313
51e830bb7abe intro_classes by default;
wenzelm
parents: 10277
diff changeset
   393
theorem rep_multiset_induct:
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   394
  "f \<in> multiset ==> P (\<lambda>a. 0) ==>
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11655
diff changeset
   395
    (!!f b. f \<in> multiset ==> P f ==> P (f (b := f b + 1))) ==> P f"
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   396
  using rep_multiset_induct_aux by blast
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   397
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   398
theorem multiset_induct [case_names empty add, induct type: multiset]:
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   399
  assumes empty: "P {#}"
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   400
    and add: "!!M x. P M ==> P (M + {#x#})"
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   401
  shows "P M"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   402
proof -
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   403
  note defns = union_def single_def Mempty_def
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   404
  show ?thesis
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   405
    apply (rule Rep_multiset_inverse [THEN subst])
10313
51e830bb7abe intro_classes by default;
wenzelm
parents: 10277
diff changeset
   406
    apply (rule Rep_multiset [THEN rep_multiset_induct])
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   407
     apply (rule empty [unfolded defns])
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   408
    apply (subgoal_tac "f(b := f b + 1) = (\<lambda>a. f a + (if a=b then 1 else 0))")
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   409
     prefer 2
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   410
     apply (simp add: expand_fun_eq)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   411
    apply (erule ssubst)
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   412
    apply (erule Abs_multiset_inverse [THEN subst])
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   413
    apply (erule add [unfolded defns, simplified])
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   414
    done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   415
qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   416
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   417
lemma empty_multiset_count:
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   418
  "(\<forall>x. count A x = 0) = (A = {#})"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   419
  apply (rule iffI)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   420
   apply (induct A, simp)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   421
   apply (erule_tac x=x in allE)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   422
   apply auto
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   423
  done
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   424
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   425
subsection {* Case splits *}
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   426
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   427
lemma multi_nonempty_split: "M \<noteq> {#} \<Longrightarrow> \<exists>A a. M = A + {#a#}"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   428
  by (induct M, auto)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   429
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   430
lemma multiset_cases [cases type, case_names empty add]:
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   431
  assumes em:  "M = {#} \<Longrightarrow> P"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   432
  assumes add: "\<And>N x. M = N + {#x#} \<Longrightarrow> P"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   433
  shows "P"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   434
proof (cases "M = {#}")
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   435
  assume "M = {#}" thus ?thesis using em by simp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   436
next
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   437
  assume "M \<noteq> {#}"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   438
  then obtain M' m where "M = M' + {#m#}" 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   439
    by (blast dest: multi_nonempty_split)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   440
  thus ?thesis using add by simp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   441
qed
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   442
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   443
lemma multi_member_split: "x \<in># M \<Longrightarrow> \<exists>A. M = A + {#x#}"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   444
  apply (cases M, simp)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   445
  apply (rule_tac x="M - {#x#}" in exI, simp)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   446
  done
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   447
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   448
lemma MCollect_preserves_multiset:
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   449
    "M \<in> multiset ==> (\<lambda>x. if P x then M x else 0) \<in> multiset"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   450
  apply (simp add: multiset_def)
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   451
  apply (rule finite_subset, auto)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   452
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   453
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   454
lemma count_MCollect [simp]:
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   455
    "count {# x:M. P x #} a = (if P a then count M a else 0)"
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   456
  by (simp add: count_def MCollect_def MCollect_preserves_multiset)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   457
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   458
lemma set_of_MCollect [simp]: "set_of {# x:M. P x #} = set_of M \<inter> {x. P x}"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   459
  by (auto simp add: set_of_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   460
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   461
lemma multiset_partition: "M = {# x:M. P x #} + {# x:M. \<not> P x #}"
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   462
  by (subst multiset_eq_conv_count_eq, auto)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   463
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   464
lemma add_eq_conv_ex:
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   465
  "(M + {#a#} = N + {#b#}) =
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   466
    (M = N \<and> a = b \<or> (\<exists>K. M = K + {#b#} \<and> N = K + {#a#}))"
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   467
  by (auto simp add: add_eq_conv_diff)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   468
15869
3aca7f05cd12 intersection
kleing
parents: 15867
diff changeset
   469
declare multiset_typedef [simp del]
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   470
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   471
lemma nonempty_has_size: "(S \<noteq> {#}) = (0 < size S)"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   472
  apply (rule iffI)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   473
   apply (case_tac "size S = 0")
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   474
    apply clarsimp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   475
   apply (subst (asm) neq0_conv)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   476
   apply auto
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   477
  done
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   478
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   479
lemma multi_drop_mem_not_eq: "c \<in># B \<Longrightarrow> B - {#c#} \<noteq> B"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   480
  by (cases "B={#}", auto dest: multi_member_split)
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   481
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   482
subsection {* Multiset orderings *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   483
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   484
subsubsection {* Well-foundedness *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   485
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
   486
definition
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   487
  mult1 :: "('a \<times> 'a) set => ('a multiset \<times> 'a multiset) set" where
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
   488
  "mult1 r =
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   489
    {(N, M). \<exists>a M0 K. M = M0 + {#a#} \<and> N = M0 + K \<and>
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   490
      (\<forall>b. b :# K --> (b, a) \<in> r)}"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   491
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21214
diff changeset
   492
definition
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   493
  mult :: "('a \<times> 'a) set => ('a multiset \<times> 'a multiset) set" where
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   494
  "mult r = (mult1 r)\<^sup>+"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   495
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   496
lemma not_less_empty [iff]: "(M, {#}) \<notin> mult1 r"
10277
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   497
  by (simp add: mult1_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   498
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   499
lemma less_add: "(N, M0 + {#a#}) \<in> mult1 r ==>
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   500
    (\<exists>M. (M, M0) \<in> mult1 r \<and> N = M + {#a#}) \<or>
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   501
    (\<exists>K. (\<forall>b. b :# K --> (b, a) \<in> r) \<and> N = M0 + K)"
19582
a669c98b9c24 get rid of 'concl is';
wenzelm
parents: 19564
diff changeset
   502
  (is "_ \<Longrightarrow> ?case1 (mult1 r) \<or> ?case2")
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   503
proof (unfold mult1_def)
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   504
  let ?r = "\<lambda>K a. \<forall>b. b :# K --> (b, a) \<in> r"
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   505
  let ?R = "\<lambda>N M. \<exists>a M0 K. M = M0 + {#a#} \<and> N = M0 + K \<and> ?r K a"
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   506
  let ?case1 = "?case1 {(N, M). ?R N M}"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   507
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   508
  assume "(N, M0 + {#a#}) \<in> {(N, M). ?R N M}"
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   509
  then have "\<exists>a' M0' K.
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   510
      M0 + {#a#} = M0' + {#a'#} \<and> N = M0' + K \<and> ?r K a'" by simp
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   511
  then show "?case1 \<or> ?case2"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   512
  proof (elim exE conjE)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   513
    fix a' M0' K
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   514
    assume N: "N = M0' + K" and r: "?r K a'"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   515
    assume "M0 + {#a#} = M0' + {#a'#}"
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   516
    then have "M0 = M0' \<and> a = a' \<or>
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   517
        (\<exists>K'. M0 = K' + {#a'#} \<and> M0' = K' + {#a#})"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   518
      by (simp only: add_eq_conv_ex)
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   519
    then show ?thesis
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   520
    proof (elim disjE conjE exE)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   521
      assume "M0 = M0'" "a = a'"
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   522
      with N r have "?r K a \<and> N = M0 + K" by simp
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   523
      then have ?case2 .. then show ?thesis ..
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   524
    next
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   525
      fix K'
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   526
      assume "M0' = K' + {#a#}"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   527
      with N have n: "N = K' + K + {#a#}" by (simp add: union_ac)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   528
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   529
      assume "M0 = K' + {#a'#}"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   530
      with r have "?R (K' + K) M0" by blast
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   531
      with n have ?case1 by simp then show ?thesis ..
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   532
    qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   533
  qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   534
qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   535
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   536
lemma all_accessible: "wf r ==> \<forall>M. M \<in> acc (mult1 r)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   537
proof
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   538
  let ?R = "mult1 r"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   539
  let ?W = "acc ?R"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   540
  {
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   541
    fix M M0 a
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   542
    assume M0: "M0 \<in> ?W"
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   543
      and wf_hyp: "!!b. (b, a) \<in> r ==> (\<forall>M \<in> ?W. M + {#b#} \<in> ?W)"
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   544
      and acc_hyp: "\<forall>M. (M, M0) \<in> ?R --> M + {#a#} \<in> ?W"
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   545
    have "M0 + {#a#} \<in> ?W"
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   546
    proof (rule accI [of "M0 + {#a#}"])
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   547
      fix N
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   548
      assume "(N, M0 + {#a#}) \<in> ?R"
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   549
      then have "((\<exists>M. (M, M0) \<in> ?R \<and> N = M + {#a#}) \<or>
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   550
          (\<exists>K. (\<forall>b. b :# K --> (b, a) \<in> r) \<and> N = M0 + K))"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   551
        by (rule less_add)
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   552
      then show "N \<in> ?W"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   553
      proof (elim exE disjE conjE)
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   554
        fix M assume "(M, M0) \<in> ?R" and N: "N = M + {#a#}"
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   555
        from acc_hyp have "(M, M0) \<in> ?R --> M + {#a#} \<in> ?W" ..
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   556
        from this and `(M, M0) \<in> ?R` have "M + {#a#} \<in> ?W" ..
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   557
        then show "N \<in> ?W" by (simp only: N)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   558
      next
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   559
        fix K
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   560
        assume N: "N = M0 + K"
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   561
        assume "\<forall>b. b :# K --> (b, a) \<in> r"
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   562
        then have "M0 + K \<in> ?W"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   563
        proof (induct K)
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   564
          case empty
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   565
          from M0 show "M0 + {#} \<in> ?W" by simp
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   566
        next
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   567
          case (add K x)
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   568
          from add.prems have "(x, a) \<in> r" by simp
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   569
          with wf_hyp have "\<forall>M \<in> ?W. M + {#x#} \<in> ?W" by blast
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   570
          moreover from add have "M0 + K \<in> ?W" by simp
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   571
          ultimately have "(M0 + K) + {#x#} \<in> ?W" ..
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   572
          then show "M0 + (K + {#x#}) \<in> ?W" by (simp only: union_assoc)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   573
        qed
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   574
        then show "N \<in> ?W" by (simp only: N)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   575
      qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   576
    qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   577
  } note tedious_reasoning = this
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   578
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   579
  assume wf: "wf r"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   580
  fix M
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   581
  show "M \<in> ?W"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   582
  proof (induct M)
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   583
    show "{#} \<in> ?W"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   584
    proof (rule accI)
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   585
      fix b assume "(b, {#}) \<in> ?R"
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   586
      with not_less_empty show "b \<in> ?W" by contradiction
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   587
    qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   588
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   589
    fix M a assume "M \<in> ?W"
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   590
    from wf have "\<forall>M \<in> ?W. M + {#a#} \<in> ?W"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   591
    proof induct
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   592
      fix a
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   593
      assume r: "!!b. (b, a) \<in> r ==> (\<forall>M \<in> ?W. M + {#b#} \<in> ?W)"
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   594
      show "\<forall>M \<in> ?W. M + {#a#} \<in> ?W"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   595
      proof
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   596
        fix M assume "M \<in> ?W"
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   597
        then show "M + {#a#} \<in> ?W"
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 23281
diff changeset
   598
          by (rule acc_induct) (rule tedious_reasoning [OF _ r])
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   599
      qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   600
    qed
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   601
    from this and `M \<in> ?W` show "M + {#a#} \<in> ?W" ..
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   602
  qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   603
qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   604
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   605
theorem wf_mult1: "wf r ==> wf (mult1 r)"
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 23281
diff changeset
   606
  by (rule acc_wfI) (rule all_accessible)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   607
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   608
theorem wf_mult: "wf r ==> wf (mult r)"
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   609
  unfolding mult_def by (rule wf_trancl) (rule wf_mult1)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   610
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   611
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   612
subsubsection {* Closure-free presentation *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   613
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   614
(*Badly needed: a linear arithmetic procedure for multisets*)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   615
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   616
lemma diff_union_single_conv: "a :# J ==> I + J - {#a#} = I + (J - {#a#})"
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 23281
diff changeset
   617
  by (simp add: multiset_eq_conv_count_eq)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   618
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   619
text {* One direction. *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   620
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   621
lemma mult_implies_one_step:
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   622
  "trans r ==> (M, N) \<in> mult r ==>
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   623
    \<exists>I J K. N = I + J \<and> M = I + K \<and> J \<noteq> {#} \<and>
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   624
    (\<forall>k \<in> set_of K. \<exists>j \<in> set_of J. (k, j) \<in> r)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   625
  apply (unfold mult_def mult1_def set_of_def)
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   626
  apply (erule converse_trancl_induct, clarify)
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   627
   apply (rule_tac x = M0 in exI, simp, clarify)
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   628
  apply (case_tac "a :# K")
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   629
   apply (rule_tac x = I in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   630
   apply (simp (no_asm))
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   631
   apply (rule_tac x = "(K - {#a#}) + Ka" in exI)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   632
   apply (simp (no_asm_simp) add: union_assoc [symmetric])
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   633
   apply (drule_tac f = "\<lambda>M. M - {#a#}" in arg_cong)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   634
   apply (simp add: diff_union_single_conv)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   635
   apply (simp (no_asm_use) add: trans_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   636
   apply blast
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   637
  apply (subgoal_tac "a :# I")
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   638
   apply (rule_tac x = "I - {#a#}" in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   639
   apply (rule_tac x = "J + {#a#}" in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   640
   apply (rule_tac x = "K + Ka" in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   641
   apply (rule conjI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   642
    apply (simp add: multiset_eq_conv_count_eq split: nat_diff_split)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   643
   apply (rule conjI)
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   644
    apply (drule_tac f = "\<lambda>M. M - {#a#}" in arg_cong, simp)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   645
    apply (simp add: multiset_eq_conv_count_eq split: nat_diff_split)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   646
   apply (simp (no_asm_use) add: trans_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   647
   apply blast
10277
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   648
  apply (subgoal_tac "a :# (M0 + {#a#})")
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   649
   apply simp
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   650
  apply (simp (no_asm))
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   651
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   652
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   653
lemma elem_imp_eq_diff_union: "a :# M ==> M = M - {#a#} + {#a#}"
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 23281
diff changeset
   654
  by (simp add: multiset_eq_conv_count_eq)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   655
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   656
lemma size_eq_Suc_imp_eq_union: "size M = Suc n ==> \<exists>a N. M = N + {#a#}"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   657
  apply (erule size_eq_Suc_imp_elem [THEN exE])
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   658
  apply (drule elem_imp_eq_diff_union, auto)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   659
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   660
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   661
lemma one_step_implies_mult_aux:
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   662
  "trans r ==>
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   663
    \<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))
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   664
      --> (I + K, I + J) \<in> mult r"
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   665
  apply (induct_tac n, auto)
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   666
  apply (frule size_eq_Suc_imp_eq_union, clarify)
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   667
  apply (rename_tac "J'", simp)
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   668
  apply (erule notE, auto)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   669
  apply (case_tac "J' = {#}")
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   670
   apply (simp add: mult_def)
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   671
   apply (rule r_into_trancl)
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   672
   apply (simp add: mult1_def set_of_def, blast)
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   673
  txt {* Now we know @{term "J' \<noteq> {#}"}. *}
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   674
  apply (cut_tac M = K and P = "\<lambda>x. (x, a) \<in> r" in multiset_partition)
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   675
  apply (erule_tac P = "\<forall>k \<in> set_of K. ?P k" in rev_mp)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   676
  apply (erule ssubst)
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   677
  apply (simp add: Ball_def, auto)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   678
  apply (subgoal_tac
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   679
    "((I + {# x : K. (x, a) \<in> r #}) + {# x : K. (x, a) \<notin> r #},
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   680
      (I + {# x : K. (x, a) \<in> r #}) + J') \<in> mult r")
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   681
   prefer 2
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   682
   apply force
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   683
  apply (simp (no_asm_use) add: union_assoc [symmetric] mult_def)
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   684
  apply (erule trancl_trans)
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   685
  apply (rule r_into_trancl)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   686
  apply (simp add: mult1_def set_of_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   687
  apply (rule_tac x = a in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   688
  apply (rule_tac x = "I + J'" in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   689
  apply (simp add: union_ac)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   690
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   691
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   692
lemma one_step_implies_mult:
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   693
  "trans r ==> J \<noteq> {#} ==> \<forall>k \<in> set_of K. \<exists>j \<in> set_of J. (k, j) \<in> r
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   694
    ==> (I + K, I + J) \<in> mult r"
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 23281
diff changeset
   695
  using one_step_implies_mult_aux by blast
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   696
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   697
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   698
subsubsection {* Partial-order properties *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   699
12338
de0f4a63baa5 renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents: 11868
diff changeset
   700
instance multiset :: (type) ord ..
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   701
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   702
defs (overloaded)
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   703
  less_multiset_def: "M' < M == (M', M) \<in> mult {(x', x). x' < x}"
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   704
  le_multiset_def: "M' <= M == M' = M \<or> M' < (M::'a multiset)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   705
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   706
lemma trans_base_order: "trans {(x', x). x' < (x::'a::order)}"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   707
  unfolding trans_def by (blast intro: order_less_trans)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   708
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   709
text {*
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   710
 \medskip Irreflexivity.
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   711
*}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   712
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   713
lemma mult_irrefl_aux:
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   714
    "finite A ==> (\<forall>x \<in> A. \<exists>y \<in> A. x < (y::'a::order)) \<Longrightarrow> A = {}"
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 23281
diff changeset
   715
  by (induct rule: finite_induct) (auto intro: order_less_trans)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   716
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   717
lemma mult_less_not_refl: "\<not> M < (M::'a::order multiset)"
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   718
  apply (unfold less_multiset_def, auto)
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   719
  apply (drule trans_base_order [THEN mult_implies_one_step], auto)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   720
  apply (drule finite_set_of [THEN mult_irrefl_aux [rule_format (no_asm)]])
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   721
  apply (simp add: set_of_eq_empty_iff)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   722
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   723
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   724
lemma mult_less_irrefl [elim!]: "M < (M::'a::order multiset) ==> R"
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 23281
diff changeset
   725
  using insert mult_less_not_refl by fast
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   726
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   727
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   728
text {* Transitivity. *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   729
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   730
theorem mult_less_trans: "K < M ==> M < N ==> K < (N::'a::order multiset)"
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   731
  unfolding less_multiset_def mult_def by (blast intro: trancl_trans)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   732
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   733
text {* Asymmetry. *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   734
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   735
theorem mult_less_not_sym: "M < N ==> \<not> N < (M::'a::order multiset)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   736
  apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   737
  apply (rule mult_less_not_refl [THEN notE])
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   738
  apply (erule mult_less_trans, assumption)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   739
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   740
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   741
theorem mult_less_asym:
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   742
    "M < N ==> (\<not> P ==> N < (M::'a::order multiset)) ==> P"
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   743
  by (insert mult_less_not_sym, blast)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   744
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   745
theorem mult_le_refl [iff]: "M <= (M::'a::order multiset)"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   746
  unfolding le_multiset_def by auto
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   747
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   748
text {* Anti-symmetry. *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   749
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   750
theorem mult_le_antisym:
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   751
    "M <= N ==> N <= M ==> M = (N::'a::order multiset)"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   752
  unfolding le_multiset_def by (blast dest: mult_less_not_sym)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   753
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   754
text {* Transitivity. *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   755
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   756
theorem mult_le_trans:
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   757
    "K <= M ==> M <= N ==> K <= (N::'a::order multiset)"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   758
  unfolding le_multiset_def by (blast intro: mult_less_trans)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   759
11655
923e4d0d36d5 tuned parentheses in relational expressions;
wenzelm
parents: 11549
diff changeset
   760
theorem mult_less_le: "(M < N) = (M <= N \<and> M \<noteq> (N::'a::order multiset))"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   761
  unfolding le_multiset_def by auto
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   762
10277
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   763
text {* Partial order. *}
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   764
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   765
instance multiset :: (order) order
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   766
  apply intro_classes
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   767
  apply (rule mult_less_le)
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   768
  apply (rule mult_le_refl)
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   769
  apply (erule mult_le_trans, assumption)
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   770
  apply (erule mult_le_antisym, assumption)
10277
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   771
  done
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   772
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   773
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   774
subsubsection {* Monotonicity of multiset union *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   775
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   776
lemma mult1_union:
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   777
    "(B, D) \<in> mult1 r ==> trans r ==> (C + B, C + D) \<in> mult1 r"
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   778
  apply (unfold mult1_def, auto)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   779
  apply (rule_tac x = a in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   780
  apply (rule_tac x = "C + M0" in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   781
  apply (simp add: union_assoc)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   782
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   783
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   784
lemma union_less_mono2: "B < D ==> C + B < C + (D::'a::order multiset)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   785
  apply (unfold less_multiset_def mult_def)
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   786
  apply (erule trancl_induct)
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   787
   apply (blast intro: mult1_union transI order_less_trans r_into_trancl)
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   788
  apply (blast intro: mult1_union transI order_less_trans r_into_trancl trancl_trans)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   789
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   790
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   791
lemma union_less_mono1: "B < D ==> B + C < D + (C::'a::order multiset)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   792
  apply (subst union_commute [of B C])
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   793
  apply (subst union_commute [of D C])
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   794
  apply (erule union_less_mono2)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   795
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   796
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   797
lemma union_less_mono:
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   798
    "A < C ==> B < D ==> A + B < C + (D::'a::order multiset)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   799
  apply (blast intro!: union_less_mono1 union_less_mono2 mult_less_trans)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   800
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   801
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   802
lemma union_le_mono:
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   803
    "A <= C ==> B <= D ==> A + B <= C + (D::'a::order multiset)"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   804
  unfolding le_multiset_def
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   805
  by (blast intro: union_less_mono union_less_mono1 union_less_mono2)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   806
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   807
lemma empty_leI [iff]: "{#} <= (M::'a::order multiset)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   808
  apply (unfold le_multiset_def less_multiset_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   809
  apply (case_tac "M = {#}")
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   810
   prefer 2
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   811
   apply (subgoal_tac "({#} + {#}, {#} + M) \<in> mult (Collect (split op <))")
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   812
    prefer 2
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   813
    apply (rule one_step_implies_mult)
23751
a7c7edf2c5ad Restored set notation.
berghofe
parents: 23611
diff changeset
   814
      apply (simp only: trans_def, auto)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   815
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   816
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   817
lemma union_upper1: "A <= A + (B::'a::order multiset)"
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   818
proof -
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   819
  have "A + {#} <= A + B" by (blast intro: union_le_mono)
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   820
  then show ?thesis by simp
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   821
qed
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   822
17161
57c69627d71a tuned some proofs;
wenzelm
parents: 15869
diff changeset
   823
lemma union_upper2: "B <= A + (B::'a::order multiset)"
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   824
  by (subst union_commute) (rule union_upper1)
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   825
23611
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   826
instance multiset :: (order) pordered_ab_semigroup_add
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   827
apply intro_classes
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   828
apply(erule union_le_mono[OF mult_le_refl])
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   829
done
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   830
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   831
subsection {* Link with lists *}
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   832
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   833
consts
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   834
  multiset_of :: "'a list \<Rightarrow> 'a multiset"
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   835
primrec
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   836
  "multiset_of [] = {#}"
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   837
  "multiset_of (a # x) = multiset_of x + {# a #}"
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   838
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   839
lemma multiset_of_zero_iff[simp]: "(multiset_of x = {#}) = (x = [])"
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   840
  by (induct x) auto
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   841
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   842
lemma multiset_of_zero_iff_right[simp]: "({#} = multiset_of x) = (x = [])"
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   843
  by (induct x) auto
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   844
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   845
lemma set_of_multiset_of[simp]: "set_of(multiset_of x) = set x"
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   846
  by (induct x) auto
15867
5c63b6c2f4a5 some more lemmas about multiset_of
kleing
parents: 15630
diff changeset
   847
5c63b6c2f4a5 some more lemmas about multiset_of
kleing
parents: 15630
diff changeset
   848
lemma mem_set_multiset_eq: "x \<in> set xs = (x :# multiset_of xs)"
5c63b6c2f4a5 some more lemmas about multiset_of
kleing
parents: 15630
diff changeset
   849
  by (induct xs) auto
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   850
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   851
lemma multiset_of_append [simp]:
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   852
    "multiset_of (xs @ ys) = multiset_of xs + multiset_of ys"
20503
503ac4c5ef91 induct method: renamed 'fixing' to 'arbitrary';
wenzelm
parents: 19582
diff changeset
   853
  by (induct xs arbitrary: ys) (auto simp: union_ac)
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   854
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   855
lemma surj_multiset_of: "surj multiset_of"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   856
  apply (unfold surj_def, rule allI)
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   857
  apply (rule_tac M=y in multiset_induct, auto)
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   858
  apply (rule_tac x = "x # xa" in exI, auto)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   859
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   860
25162
ad4d5365d9d8 went back to >0
nipkow
parents: 25140
diff changeset
   861
lemma set_count_greater_0: "set x = {a. count (multiset_of x) a > 0}"
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   862
  by (induct x) auto
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   863
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   864
lemma distinct_count_atmost_1:
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   865
   "distinct x = (! a. count (multiset_of x) a = (if a \<in> set x then 1 else 0))"
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   866
   apply (induct x, simp, rule iffI, simp_all)
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   867
   apply (rule conjI)
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   868
   apply (simp_all add: set_of_multiset_of [THEN sym] del: set_of_multiset_of)
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   869
   apply (erule_tac x=a in allE, simp, clarify)
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   870
   apply (erule_tac x=aa in allE, simp)
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   871
   done
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   872
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   873
lemma multiset_of_eq_setD:
15867
5c63b6c2f4a5 some more lemmas about multiset_of
kleing
parents: 15630
diff changeset
   874
  "multiset_of xs = multiset_of ys \<Longrightarrow> set xs = set ys"
5c63b6c2f4a5 some more lemmas about multiset_of
kleing
parents: 15630
diff changeset
   875
  by (rule) (auto simp add:multiset_eq_conv_count_eq set_count_greater_0)
5c63b6c2f4a5 some more lemmas about multiset_of
kleing
parents: 15630
diff changeset
   876
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   877
lemma set_eq_iff_multiset_of_eq_distinct:
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   878
  "\<lbrakk>distinct x; distinct y\<rbrakk>
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   879
   \<Longrightarrow> (set x = set y) = (multiset_of x = multiset_of y)"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   880
  by (auto simp: multiset_eq_conv_count_eq distinct_count_atmost_1)
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   881
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   882
lemma set_eq_iff_multiset_of_remdups_eq:
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   883
   "(set x = set y) = (multiset_of (remdups x) = multiset_of (remdups y))"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   884
  apply (rule iffI)
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   885
  apply (simp add: set_eq_iff_multiset_of_eq_distinct[THEN iffD1])
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   886
  apply (drule distinct_remdups[THEN distinct_remdups
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   887
                      [THEN set_eq_iff_multiset_of_eq_distinct[THEN iffD2]]])
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   888
  apply simp
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   889
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   890
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   891
lemma multiset_of_compl_union [simp]:
23281
e26ec695c9b3 changed filter syntax from : to <-
nipkow
parents: 22316
diff changeset
   892
    "multiset_of [x\<leftarrow>xs. P x] + multiset_of [x\<leftarrow>xs. \<not>P x] = multiset_of xs"
15630
cc3776f004e2 fixed typo (multiset_append)
kleing
parents: 15402
diff changeset
   893
  by (induct xs) (auto simp: union_ac)
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   894
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   895
lemma count_filter:
23281
e26ec695c9b3 changed filter syntax from : to <-
nipkow
parents: 22316
diff changeset
   896
    "count (multiset_of xs) x = length [y \<leftarrow> xs. y = x]"
18258
836491e9b7d5 tuned induct proofs;
wenzelm
parents: 17778
diff changeset
   897
  by (induct xs) auto
15867
5c63b6c2f4a5 some more lemmas about multiset_of
kleing
parents: 15630
diff changeset
   898
5c63b6c2f4a5 some more lemmas about multiset_of
kleing
parents: 15630
diff changeset
   899
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   900
subsection {* Pointwise ordering induced by count *}
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   901
19086
1b3780be6cc2 new-style definitions/abbreviations;
wenzelm
parents: 18730
diff changeset
   902
definition
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   903
  mset_le :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> bool"  (infix "\<le>#" 50) where
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   904
  "(A \<le># B) = (\<forall>a. count A a \<le> count B a)"
23611
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   905
definition
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   906
  mset_less :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> bool"  (infix "<#" 50) where
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   907
  "(A <# B) = (A \<le># B \<and> A \<noteq> B)"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   908
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   909
notation mset_le (infix "\<subseteq>#" 50)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   910
notation mset_less (infix "\<subset>#" 50)
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   911
23611
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   912
lemma mset_le_refl[simp]: "A \<le># A"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   913
  unfolding mset_le_def by auto
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   914
23611
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   915
lemma mset_le_trans: "\<lbrakk> A \<le># B; B \<le># C \<rbrakk> \<Longrightarrow> A \<le># C"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   916
  unfolding mset_le_def by (fast intro: order_trans)
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   917
23611
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   918
lemma mset_le_antisym: "\<lbrakk> A \<le># B; B \<le># A \<rbrakk> \<Longrightarrow> A = B"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   919
  apply (unfold mset_le_def)
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   920
  apply (rule multiset_eq_conv_count_eq[THEN iffD2])
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   921
  apply (blast intro: order_antisym)
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   922
  done
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   923
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   924
lemma mset_le_exists_conv:
23611
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   925
  "(A \<le># B) = (\<exists>C. B = A + C)"
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   926
  apply (unfold mset_le_def, rule iffI, rule_tac x = "B - A" in exI)
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   927
  apply (auto intro: multiset_eq_conv_count_eq [THEN iffD2])
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   928
  done
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   929
23611
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   930
lemma mset_le_mono_add_right_cancel[simp]: "(A + C \<le># B + C) = (A \<le># B)"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   931
  unfolding mset_le_def by auto
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   932
23611
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   933
lemma mset_le_mono_add_left_cancel[simp]: "(C + A \<le># C + B) = (A \<le># B)"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   934
  unfolding mset_le_def by auto
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   935
23611
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   936
lemma mset_le_mono_add: "\<lbrakk> A \<le># B; C \<le># D \<rbrakk> \<Longrightarrow> A + C \<le># B + D"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   937
  apply (unfold mset_le_def)
3a4d03d1a31b tuned presentation;
wenzelm
parents: 17161
diff changeset
   938
  apply auto
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   939
  apply (erule_tac x=a in allE)+
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   940
  apply auto
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   941
  done
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   942
23611
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   943
lemma mset_le_add_left[simp]: "A \<le># A + B"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   944
  unfolding mset_le_def by auto
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   945
23611
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   946
lemma mset_le_add_right[simp]: "B \<le># A + B"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18258
diff changeset
   947
  unfolding mset_le_def by auto
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   948
23611
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   949
lemma multiset_of_remdups_le: "multiset_of (remdups xs) \<le># multiset_of xs"
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   950
apply (induct xs)
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   951
 apply auto
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   952
apply (rule mset_le_trans)
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   953
 apply auto
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   954
done
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   955
25208
1a7318a04068 changed order of class parameters
haftmann
parents: 25162
diff changeset
   956
interpretation mset_order:
1a7318a04068 changed order of class parameters
haftmann
parents: 25162
diff changeset
   957
  order ["op \<le>#" "op <#"]
1a7318a04068 changed order of class parameters
haftmann
parents: 25162
diff changeset
   958
  by (auto intro: order.intro mset_le_refl mset_le_antisym
1a7318a04068 changed order of class parameters
haftmann
parents: 25162
diff changeset
   959
    mset_le_trans simp: mset_less_def)
23611
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   960
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   961
interpretation mset_order_cancel_semigroup:
25622
6067d838041a changed order in class parameters
haftmann
parents: 25610
diff changeset
   962
  pordered_cancel_ab_semigroup_add ["op +" "op \<le>#" "op <#"]
25208
1a7318a04068 changed order of class parameters
haftmann
parents: 25162
diff changeset
   963
  by unfold_locales (erule mset_le_mono_add [OF mset_le_refl])
23611
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   964
65b168646309 more interpretations
nipkow
parents: 23373
diff changeset
   965
interpretation mset_order_semigroup_cancel:
25622
6067d838041a changed order in class parameters
haftmann
parents: 25610
diff changeset
   966
  pordered_ab_semigroup_add_imp_le ["op +" "op \<le>#" "op <#"]
25208
1a7318a04068 changed order of class parameters
haftmann
parents: 25162
diff changeset
   967
  by (unfold_locales) simp
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 14981
diff changeset
   968
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   969
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   970
lemma mset_lessD:
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   971
  "\<lbrakk> A \<subset># B ; x \<in># A \<rbrakk> \<Longrightarrow> x \<in># B"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   972
  apply (clarsimp simp: mset_le_def mset_less_def)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   973
  apply (erule_tac x=x in allE)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   974
  apply auto
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   975
  done
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   976
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   977
lemma mset_leD:
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   978
  "\<lbrakk> A \<subseteq># B ; x \<in># A \<rbrakk> \<Longrightarrow> x \<in># B"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   979
  apply (clarsimp simp: mset_le_def mset_less_def)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   980
  apply (erule_tac x=x in allE)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   981
  apply auto
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   982
  done
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   983
  
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   984
lemma mset_less_insertD:
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   985
  "(A + {#x#} \<subset># B) \<Longrightarrow> (x \<in># B \<and> A \<subset># B)"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   986
  apply (rule conjI)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   987
   apply (simp add: mset_lessD)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   988
  apply (clarsimp simp: mset_le_def mset_less_def)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   989
  apply safe
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   990
   apply (erule_tac x=a in allE)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   991
   apply (auto split: split_if_asm)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   992
  done
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   993
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   994
lemma mset_le_insertD:
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   995
  "(A + {#x#} \<subseteq># B) \<Longrightarrow> (x \<in># B \<and> A \<subseteq># B)"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   996
  apply (rule conjI)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   997
   apply (simp add: mset_leD)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   998
  apply (force simp: mset_le_def mset_less_def split: split_if_asm)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
   999
  done
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1000
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1001
lemma mset_less_of_empty[simp]: "A \<subset># {#} = False" 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1002
  by (induct A, auto simp: mset_le_def mset_less_def)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1003
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1004
lemma multi_psub_of_add_self[simp]: "A \<subset># A + {#x#}"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1005
  by (clarsimp simp: mset_le_def mset_less_def)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1006
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1007
lemma multi_psub_self[simp]: "A \<subset># A = False"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1008
  by (clarsimp simp: mset_le_def mset_less_def)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1009
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1010
lemma mset_less_add_bothsides:
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1011
  "T + {#x#} \<subset># S + {#x#} \<Longrightarrow> T \<subset># S"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1012
  by (clarsimp simp: mset_le_def mset_less_def)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1013
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1014
lemma mset_less_empty_nonempty: "({#} \<subset># S) = (S \<noteq> {#})"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1015
  by (auto simp: mset_le_def mset_less_def)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1016
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1017
lemma mset_less_size: "A \<subset># B \<Longrightarrow> size A < size B"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1018
proof (induct A arbitrary: B)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1019
  case (empty M)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1020
  hence "M \<noteq> {#}" by (simp add: mset_less_empty_nonempty)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1021
  then obtain M' x where "M = M' + {#x#}" 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1022
    by (blast dest: multi_nonempty_split)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1023
  thus ?case by simp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1024
next
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1025
  case (add S x T)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1026
  have IH: "\<And>B. S \<subset># B \<Longrightarrow> size S < size B" by fact
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1027
  have SxsubT: "S + {#x#} \<subset># T" by fact
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1028
  hence "x \<in># T" and "S \<subset># T" by (auto dest: mset_less_insertD)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1029
  then obtain T' where T: "T = T' + {#x#}" 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1030
    by (blast dest: multi_member_split)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1031
  hence "S \<subset># T'" using SxsubT 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1032
    by (blast intro: mset_less_add_bothsides)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1033
  hence "size S < size T'" using IH by simp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1034
  thus ?case using T by simp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1035
qed
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1036
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1037
lemmas mset_less_trans = mset_order.less_eq_less.less_trans
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1038
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1039
lemma mset_less_diff_self: "c \<in># B \<Longrightarrow> B - {#c#} \<subset># B"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1040
  by (auto simp: mset_le_def mset_less_def multi_drop_mem_not_eq)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1041
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1042
subsection {* Strong induction and subset induction for multisets *}
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1043
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1044
subsubsection {* Well-foundedness of proper subset operator *}
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1045
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1046
definition
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1047
  mset_less_rel  :: "('a multiset * 'a multiset) set" 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1048
  where
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1049
  --{* proper multiset subset *}
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1050
  "mset_less_rel \<equiv> {(A,B). A \<subset># B}"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1051
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1052
lemma multiset_add_sub_el_shuffle: 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1053
  assumes cinB: "c \<in># B" and bnotc: "b \<noteq> c" 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1054
  shows "B - {#c#} + {#b#} = B + {#b#} - {#c#}"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1055
proof -
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1056
  from cinB obtain A where B: "B = A + {#c#}" 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1057
    by (blast dest: multi_member_split)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1058
  have "A + {#b#} = A + {#b#} + {#c#} - {#c#}" by simp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1059
  hence "A + {#b#} = A + {#c#} + {#b#} - {#c#}" 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1060
    by (simp add: union_ac)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1061
  thus ?thesis using B by simp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1062
qed
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1063
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1064
lemma wf_mset_less_rel: "wf mset_less_rel"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1065
  apply (unfold mset_less_rel_def)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1066
  apply (rule wf_measure [THEN wf_subset, where f1=size])
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1067
  apply (clarsimp simp: measure_def inv_image_def mset_less_size)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1068
  done
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1069
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1070
subsubsection {* The induction rules *}
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1071
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1072
lemma full_multiset_induct [case_names less]:
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1073
  assumes ih: "\<And>B. \<forall>A. A \<subset># B \<longrightarrow> P A \<Longrightarrow> P B"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1074
  shows "P B"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1075
  apply (rule wf_mset_less_rel [THEN wf_induct])
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1076
  apply (rule ih, auto simp: mset_less_rel_def)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1077
  done
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1078
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1079
lemma multi_subset_induct [consumes 2, case_names empty add]:
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1080
  assumes "F \<subseteq># A"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1081
    and empty: "P {#}"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1082
    and insert: "\<And>a F. a \<in># A \<Longrightarrow> P F \<Longrightarrow> P (F + {#a#})"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1083
  shows "P F"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1084
proof -
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1085
  from `F \<subseteq># A`
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1086
  show ?thesis
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1087
  proof (induct F)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1088
    show "P {#}" by fact
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1089
  next
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1090
    fix x F
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1091
    assume P: "F \<subseteq># A \<Longrightarrow> P F" and i: "F + {#x#} \<subseteq># A"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1092
    show "P (F + {#x#})"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1093
    proof (rule insert)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1094
      from i show "x \<in># A" by (auto dest: mset_le_insertD)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1095
      from i have "F \<subseteq># A" by (auto simp: mset_le_insertD)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1096
      with P show "P F" .
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1097
    qed
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1098
  qed
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1099
qed 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1100
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1101
subsection {* Multiset extensionality *}
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1102
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1103
lemma multi_count_eq: 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1104
  "(\<forall>x. count A x = count B x) = (A = B)"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1105
  apply (rule iffI)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1106
   prefer 2
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1107
   apply clarsimp 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1108
  apply (induct A arbitrary: B rule: full_multiset_induct)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1109
  apply (rename_tac C)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1110
  apply (case_tac B rule: multiset_cases)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1111
   apply (simp add: empty_multiset_count)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1112
  apply simp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1113
  apply (case_tac "x \<in># C")
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1114
   apply (force dest: multi_member_split)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1115
  apply (erule_tac x=x in allE)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1116
  apply simp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1117
  done
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1118
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1119
lemmas multi_count_ext = multi_count_eq [THEN iffD1, rule_format]
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1120
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1121
subsection {* The fold combinator *}
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1122
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1123
text {* The intended behaviour is
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1124
@{text "fold_mset f z {#x\<^isub>1, ..., x\<^isub>n#} = f x\<^isub>1 (\<dots> (f x\<^isub>n z)\<dots>)"}
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1125
if @{text f} is associative-commutative. 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1126
*}
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1127
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1128
(* the graph of fold_mset, z = the start element, f = folding function, 
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1129
   A the multiset, y the result *)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1130
inductive 
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1131
  fold_msetG :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a multiset \<Rightarrow> 'b \<Rightarrow> bool" 
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1132
  for f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1133
  and z :: 'b
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1134
where
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1135
  emptyI [intro]:  "fold_msetG f z {#} z"
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1136
| insertI [intro]: "fold_msetG f z A y \<Longrightarrow> fold_msetG f z (A + {#x#}) (f x y)"
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1137
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1138
inductive_cases empty_fold_msetGE [elim!]: "fold_msetG f z {#} x"
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1139
inductive_cases insert_fold_msetGE: "fold_msetG f z (A + {#}) y" 
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1140
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1141
definition
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1142
  fold_mset :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a multiset \<Rightarrow> 'b"
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1143
where
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1144
  "fold_mset f z A \<equiv> THE x. fold_msetG f z A x"
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1145
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1146
lemma Diff1_fold_msetG:
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1147
  "\<lbrakk> fold_msetG f z (A - {#x#}) y; x \<in># A \<rbrakk> \<Longrightarrow> fold_msetG f z A (f x y)"
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1148
  by (frule_tac x=x in fold_msetG.insertI, auto)
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1149
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1150
lemma fold_msetG_nonempty: "\<exists>x. fold_msetG f z A x"
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1151
  apply (induct A)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1152
   apply blast
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1153
  apply clarsimp
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1154
  apply (drule_tac x=x in fold_msetG.insertI)
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1155
  apply auto
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1156
  done
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1157
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1158
lemma fold_mset_empty[simp]: "fold_mset f z {#} = z"
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1159
  by (unfold fold_mset_def, blast)
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1160
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1161
locale left_commutative = 
25623
baa627b6f962 removed syntax in locale left_commutative
kleing
parents: 25622
diff changeset
  1162
  fixes f :: "'a => 'b => 'b"
baa627b6f962 removed syntax in locale left_commutative
kleing
parents: 25622
diff changeset
  1163
  assumes left_commute: "f x (f y z) = f y (f x z)"
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1164
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1165
lemma (in left_commutative) fold_msetG_determ:
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1166
  "\<lbrakk>fold_msetG f z A x; fold_msetG f z A y\<rbrakk> \<Longrightarrow> y = x"
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1167
proof (induct arbitrary: x y z rule: full_multiset_induct)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1168
  case (less M x\<^isub>1 x\<^isub>2 Z)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1169
  have IH: "\<forall>A. A \<subset># M \<longrightarrow> 
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1170
    (\<forall>x x' x''. fold_msetG f x'' A x \<longrightarrow> fold_msetG f x'' A x'
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1171
               \<longrightarrow> x' = x)" by fact
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1172
  have Mfoldx\<^isub>1: "fold_msetG f Z M x\<^isub>1" and Mfoldx\<^isub>2: "fold_msetG f Z M x\<^isub>2" by fact+
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1173
  show ?case
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1174
  proof (rule fold_msetG.cases [OF Mfoldx\<^isub>1])
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1175
    assume "M = {#}" and "x\<^isub>1 = Z"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1176
    thus ?case using Mfoldx\<^isub>2 by auto 
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1177
  next
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1178
    fix B b u
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1179
    assume "M = B + {#b#}" and "x\<^isub>1 = f b u" and Bu: "fold_msetG f Z B u"
25623
baa627b6f962 removed syntax in locale left_commutative
kleing
parents: 25622
diff changeset
  1180
    hence MBb: "M = B + {#b#}" and x\<^isub>1: "x\<^isub>1 = f b u" by auto
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1181
    show ?case
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1182
    proof (rule fold_msetG.cases [OF Mfoldx\<^isub>2])
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1183
      assume "M = {#}" "x\<^isub>2 = Z"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1184
      thus ?case using Mfoldx\<^isub>1 by auto
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1185
    next
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1186
      fix C c v
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1187
      assume "M = C + {#c#}" and "x\<^isub>2 = f c v" and Cv: "fold_msetG f Z C v"
25623
baa627b6f962 removed syntax in locale left_commutative
kleing
parents: 25622
diff changeset
  1188
      hence MCc: "M = C + {#c#}" and x\<^isub>2: "x\<^isub>2 = f c v" by auto
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1189
      hence CsubM: "C \<subset># M" by simp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1190
      from MBb have BsubM: "B \<subset># M" by simp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1191
      show ?case
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1192
      proof cases
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1193
        assume "b=c"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1194
        then moreover have "B = C" using MBb MCc by auto
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1195
        ultimately show ?thesis using Bu Cv x\<^isub>1 x\<^isub>2 CsubM IH by auto
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1196
      next
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1197
        assume diff: "b \<noteq> c"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1198
        let ?D = "B - {#c#}"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1199
        have cinB: "c \<in># B" and binC: "b \<in># C" using MBb MCc diff
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1200
          by (auto intro: insert_noteq_member dest: sym)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1201
        have "B - {#c#} \<subset># B" using cinB by (rule mset_less_diff_self)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1202
        hence DsubM: "?D \<subset># M" using BsubM by (blast intro: mset_less_trans)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1203
        from MBb MCc have "B + {#b#} = C + {#c#}" by blast
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1204
        hence [simp]: "B + {#b#} - {#c#} = C"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1205
          using MBb MCc binC cinB by auto
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1206
        have B: "B = ?D + {#c#}" and C: "C = ?D + {#b#}"
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1207
          using MBb MCc diff binC cinB
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1208
          by (auto simp: multiset_add_sub_el_shuffle)
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1209
        then obtain d where Dfoldd: "fold_msetG f Z ?D d"
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1210
          using fold_msetG_nonempty by iprover
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1211
        hence "fold_msetG f Z B (f c d)" using cinB
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1212
          by (rule Diff1_fold_msetG)
25623
baa627b6f962 removed syntax in locale left_commutative
kleing
parents: 25622
diff changeset
  1213
        hence "f c d = u" using IH BsubM Bu by blast
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1214
        moreover 
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1215
        have "fold_msetG f Z C (f b d)" using binC cinB diff Dfoldd
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1216
          by (auto simp: multiset_add_sub_el_shuffle 
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1217
            dest: fold_msetG.insertI [where x=b])
25623
baa627b6f962 removed syntax in locale left_commutative
kleing
parents: 25622
diff changeset
  1218
        hence "f b d = v" using IH CsubM Cv by blast
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1219
        ultimately show ?thesis using x\<^isub>1 x\<^isub>2
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1220
          by (auto simp: left_commute)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1221
      qed
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1222
    qed
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1223
  qed
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1224
qed
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1225
        
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1226
lemma (in left_commutative) fold_mset_insert_aux: "
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1227
    (fold_msetG f z (A + {#x#}) v) =
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1228
    (\<exists>y. fold_msetG f z A y \<and> v = f x y)"
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1229
  apply (rule iffI)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1230
   prefer 2
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1231
   apply blast
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1232
  apply (rule_tac A=A and f=f in fold_msetG_nonempty [THEN exE, standard])
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1233
  apply (blast intro: fold_msetG_determ)
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1234
  done
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1235
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1236
lemma (in left_commutative) fold_mset_equality: "fold_msetG f z A y \<Longrightarrow> fold_mset f z A = y"
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1237
  by (unfold fold_mset_def) (blast intro: fold_msetG_determ)
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1238
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1239
lemma (in left_commutative) fold_mset_insert:
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1240
  "fold_mset f z (A + {#x#}) = f x (fold_mset f z A)"
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1241
  apply (simp add: fold_mset_def fold_mset_insert_aux union_commute)  
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1242
  apply (rule the_equality)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1243
  apply (auto cong add: conj_cong 
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1244
              simp add: fold_mset_def [symmetric] fold_mset_equality fold_msetG_nonempty)
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1245
  done
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1246
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1247
lemma (in left_commutative) fold_mset_insert_idem:
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1248
  shows "fold_mset f z (A + {#a#}) = f a (fold_mset f z A)"
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1249
  apply (simp add: fold_mset_def fold_mset_insert_aux)
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1250
  apply (rule the_equality)
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1251
  apply (auto cong add: conj_cong 
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1252
              simp add: fold_mset_def [symmetric] fold_mset_equality fold_msetG_nonempty)
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1253
  done
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1254
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1255
lemma (in left_commutative) fold_mset_commute:
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1256
  "f x (fold_mset f z A) = fold_mset f (f x z) A"
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1257
  by (induct A, auto simp: fold_mset_insert left_commute [of x])
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1258
  
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1259
lemma (in left_commutative) fold_mset_single [simp]:
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1260
   "fold_mset f z {#x#} = f x z"
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1261
using fold_mset_insert[of z "{#}"] by simp
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1262
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1263
lemma (in left_commutative) fold_mset_union [simp]:
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1264
   "fold_mset f z (A+B) = fold_mset f (fold_mset f z A) B"
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1265
proof (induct A)
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1266
   case empty thus ?case by simp
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1267
next
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1268
   case (add A x)
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1269
   have "A + {#x#} + B = (A+B) + {#x#}" by(simp add:union_ac)
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1270
   hence "fold_mset f z (A + {#x#} + B) = f x (fold_mset f z (A + B))" 
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1271
     by (simp add: fold_mset_insert)
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1272
   also have "\<dots> = fold_mset f (fold_mset f z (A + {#x#})) B"
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1273
     by (simp add: fold_mset_commute[of x,symmetric] add fold_mset_insert)
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1274
   finally show ?case .
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1275
qed
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1276
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1277
lemma (in left_commutative) fold_mset_fusion:
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1278
  includes left_commutative g
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1279
  shows "\<lbrakk>\<And>x y. h (g x y) = f x (h y) \<rbrakk> \<Longrightarrow> h (fold_mset g w A) = fold_mset f (h w) A"
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1280
  by (induct A, auto)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1281
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1282
lemma (in left_commutative) fold_mset_rec:
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1283
  assumes a: "a \<in># A" 
25759
6326138c1bd7 renamed foldM to fold_mset on general request
kleing
parents: 25623
diff changeset
  1284
  shows "fold_mset f z A = f a (fold_mset f z (A - {#a#}))"
25610
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1285
proof -
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1286
  from a obtain A' where "A = A' + {#a#}" by (blast dest: multi_member_split)
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1287
  thus ?thesis by simp
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1288
qed
72e1563aee09 a fold operation for multisets + more lemmas
kleing
parents: 25595
diff changeset
  1289
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
  1290
end