src/HOL/Library/Multiset.thy
author obua
Tue, 11 May 2004 20:11:08 +0200
changeset 14738 83f1a514dcb4
parent 14722 8e739a6eaf11
child 14981 e73f8140af78
permissions -rw-r--r--
changes made due to new Ring_and_Field theory
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$
12399
wenzelm
parents: 12338
diff changeset
     3
    Author:     Tobias Nipkow, Markus Wenzel, and Lawrence C Paulson
wenzelm
parents: 12338
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
     5
*)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
     6
14706
71590b7733b7 tuned document;
wenzelm
parents: 14691
diff changeset
     7
header {* Multisets *}
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
     8
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
     9
theory Multiset = Accessible_Part:
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    10
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    11
subsection {* The type of multisets *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    12
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    13
typedef 'a multiset = "{f::'a => nat. finite {x . 0 < f x}}"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    14
proof
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
    15
  show "(\<lambda>x. 0::nat) \<in> ?multiset" by simp
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    16
qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    17
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    18
lemmas multiset_typedef [simp] =
10277
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
    19
    Abs_multiset_inverse Rep_multiset_inverse Rep_multiset
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
    20
  and [simp] = Rep_multiset_inject [symmetric]
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    21
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    22
constdefs
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    23
  Mempty :: "'a multiset"    ("{#}")
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
    24
  "{#} == Abs_multiset (\<lambda>a. 0)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    25
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    26
  single :: "'a => 'a multiset"    ("{#_#}")
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11655
diff changeset
    27
  "{#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
    28
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    29
  count :: "'a multiset => 'a => nat"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    30
  "count == Rep_multiset"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    31
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    32
  MCollect :: "'a multiset => ('a => bool) => 'a multiset"
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
    33
  "MCollect M P == Abs_multiset (\<lambda>x. if P x then Rep_multiset M x else 0)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    34
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    35
syntax
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    36
  "_Melem" :: "'a => 'a multiset => bool"    ("(_/ :# _)" [50, 51] 50)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    37
  "_MCollect" :: "pttrn => 'a multiset => bool => 'a multiset"    ("(1{# _ : _./ _#})")
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    38
translations
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    39
  "a :# M" == "0 < count M a"
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
    40
  "{#x:M. P#}" == "MCollect M (\<lambda>x. P)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    41
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    42
constdefs
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    43
  set_of :: "'a multiset => 'a set"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    44
  "set_of M == {x. x :# M}"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    45
14691
e1eedc8cad37 tuned instance statements;
wenzelm
parents: 14445
diff changeset
    46
instance multiset :: (type) "{plus, minus, zero}" ..
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    47
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    48
defs (overloaded)
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
    49
  union_def: "M + N == Abs_multiset (\<lambda>a. Rep_multiset M a + Rep_multiset N a)"
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
    50
  diff_def: "M - N == Abs_multiset (\<lambda>a. Rep_multiset M a - Rep_multiset N a)"
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11655
diff changeset
    51
  Zero_multiset_def [simp]: "0 == {#}"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    52
  size_def: "size M == setsum (count M) (set_of M)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    53
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    54
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    55
text {*
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    56
 \medskip Preservation of the representing set @{term multiset}.
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    57
*}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    58
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
    59
lemma const0_in_multiset [simp]: "(\<lambda>a. 0) \<in> multiset"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    60
  apply (simp add: multiset_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    61
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    62
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11655
diff changeset
    63
lemma only1_in_multiset [simp]: "(\<lambda>b. if b = a then 1 else 0) \<in> multiset"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    64
  apply (simp add: multiset_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    65
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    66
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    67
lemma union_preserves_multiset [simp]:
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
    68
    "M \<in> multiset ==> N \<in> multiset ==> (\<lambda>a. M a + N a) \<in> multiset"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    69
  apply (unfold multiset_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    70
  apply simp
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    71
  apply (drule finite_UnI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    72
   apply assumption
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    73
  apply (simp del: finite_Un add: Un_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    74
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    75
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    76
lemma diff_preserves_multiset [simp]:
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
    77
    "M \<in> multiset ==> (\<lambda>a. M a - N a) \<in> multiset"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    78
  apply (unfold multiset_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    79
  apply simp
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    80
  apply (rule finite_subset)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    81
   prefer 2
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    82
   apply assumption
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    83
  apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    84
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    85
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    86
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    87
subsection {* Algebraic properties of multisets *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    88
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    89
subsubsection {* Union *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    90
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
    91
theorem union_empty [simp]: "M + {#} = M \<and> {#} + M = M"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    92
  apply (simp add: union_def Mempty_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    93
  done
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
theorem union_commute: "M + N = N + (M::'a multiset)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    96
  apply (simp add: union_def add_ac)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    97
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    98
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
    99
theorem union_assoc: "(M + N) + K = M + (N + (K::'a multiset))"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   100
  apply (simp add: union_def add_ac)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   101
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   102
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   103
theorem union_lcomm: "M + (N + K) = N + (M + (K::'a multiset))"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   104
  apply (rule union_commute [THEN trans])
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   105
  apply (rule union_assoc [THEN trans])
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   106
  apply (rule union_commute [THEN arg_cong])
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
theorems union_ac = union_assoc union_commute union_lcomm
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   110
14738
83f1a514dcb4 changes made due to new Ring_and_Field theory
obua
parents: 14722
diff changeset
   111
instance multiset :: (type) comm_monoid_add
14722
8e739a6eaf11 replaced apply-style proof for instance Multiset :: plus_ac0 by recommended Isar proof style
obua
parents: 14706
diff changeset
   112
proof 
8e739a6eaf11 replaced apply-style proof for instance Multiset :: plus_ac0 by recommended Isar proof style
obua
parents: 14706
diff changeset
   113
  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
   114
  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
   115
  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
   116
  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
   117
qed
10277
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   118
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   119
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   120
subsubsection {* Difference *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   121
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   122
theorem diff_empty [simp]: "M - {#} = M \<and> {#} - M = {#}"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   123
  apply (simp add: Mempty_def diff_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   124
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   125
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   126
theorem diff_union_inverse2 [simp]: "M + {#a#} - {#a#} = M"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   127
  apply (simp add: union_def diff_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   128
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   129
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   130
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   131
subsubsection {* Count of elements *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   132
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   133
theorem count_empty [simp]: "count {#} a = 0"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   134
  apply (simp add: count_def Mempty_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   135
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   136
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11655
diff changeset
   137
theorem count_single [simp]: "count {#b#} a = (if b = a then 1 else 0)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   138
  apply (simp add: count_def single_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   139
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   140
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   141
theorem count_union [simp]: "count (M + N) a = count M a + count N a"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   142
  apply (simp add: count_def union_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   143
  done
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
theorem count_diff [simp]: "count (M - N) a = count M a - count N a"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   146
  apply (simp add: count_def diff_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   147
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   148
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   149
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   150
subsubsection {* Set of elements *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   151
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   152
theorem set_of_empty [simp]: "set_of {#} = {}"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   153
  apply (simp add: set_of_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   154
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   155
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   156
theorem set_of_single [simp]: "set_of {#b#} = {b}"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   157
  apply (simp add: set_of_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   158
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   159
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   160
theorem set_of_union [simp]: "set_of (M + N) = set_of M \<union> set_of N"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   161
  apply (auto simp add: set_of_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   162
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   163
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   164
theorem set_of_eq_empty_iff [simp]: "(set_of M = {}) = (M = {#})"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   165
  apply (auto simp add: set_of_def Mempty_def count_def expand_fun_eq)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   166
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   167
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   168
theorem mem_set_of_iff [simp]: "(x \<in> set_of M) = (x :# M)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   169
  apply (auto simp add: set_of_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   170
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   171
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   172
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   173
subsubsection {* Size *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   174
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   175
theorem size_empty [simp]: "size {#} = 0"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   176
  apply (simp add: size_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   177
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   178
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   179
theorem size_single [simp]: "size {#b#} = 1"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   180
  apply (simp add: size_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   181
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   182
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   183
theorem finite_set_of [iff]: "finite (set_of M)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   184
  apply (cut_tac x = M in Rep_multiset)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   185
  apply (simp add: multiset_def set_of_def count_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   186
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   187
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   188
theorem setsum_count_Int:
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   189
    "finite A ==> setsum (count N) (A \<inter> set_of N) = setsum (count N) A"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   190
  apply (erule finite_induct)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   191
   apply simp
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   192
  apply (simp add: Int_insert_left set_of_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   193
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   194
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   195
theorem size_union [simp]: "size (M + N::'a multiset) = size M + size N"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   196
  apply (unfold size_def)
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   197
  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
   198
   prefer 2
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   199
   apply (rule ext)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   200
   apply simp
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   201
  apply (simp (no_asm_simp) add: setsum_Un setsum_addf setsum_count_Int)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   202
  apply (subst Int_commute)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   203
  apply (simp (no_asm_simp) add: setsum_count_Int)
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
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   206
theorem size_eq_0_iff_empty [iff]: "(size M = 0) = (M = {#})"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   207
  apply (unfold size_def Mempty_def count_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   208
  apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   209
  apply (simp add: set_of_def count_def expand_fun_eq)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   210
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   211
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   212
theorem 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
   213
  apply (unfold size_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   214
  apply (drule setsum_SucD)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   215
  apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   216
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   217
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   218
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   219
subsubsection {* Equality of multisets *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   220
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   221
theorem multiset_eq_conv_count_eq: "(M = N) = (\<forall>a. count M a = count N a)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   222
  apply (simp add: count_def expand_fun_eq)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   223
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   224
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   225
theorem single_not_empty [simp]: "{#a#} \<noteq> {#} \<and> {#} \<noteq> {#a#}"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   226
  apply (simp add: single_def Mempty_def expand_fun_eq)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   227
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   228
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   229
theorem single_eq_single [simp]: "({#a#} = {#b#}) = (a = b)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   230
  apply (auto simp add: single_def expand_fun_eq)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   231
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   232
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   233
theorem union_eq_empty [iff]: "(M + N = {#}) = (M = {#} \<and> N = {#})"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   234
  apply (auto simp add: union_def Mempty_def expand_fun_eq)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   235
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   236
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   237
theorem empty_eq_union [iff]: "({#} = M + N) = (M = {#} \<and> N = {#})"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   238
  apply (auto simp add: union_def Mempty_def expand_fun_eq)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   239
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   240
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   241
theorem union_right_cancel [simp]: "(M + K = N + K) = (M = (N::'a multiset))"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   242
  apply (simp add: union_def expand_fun_eq)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   243
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   244
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   245
theorem union_left_cancel [simp]: "(K + M = K + N) = (M = (N::'a multiset))"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   246
  apply (simp add: union_def expand_fun_eq)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   247
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   248
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   249
theorem 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#})"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   251
  apply (unfold Mempty_def single_def union_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   252
  apply (simp add: add_is_1 expand_fun_eq)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   253
  apply blast
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   254
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   255
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   256
theorem single_is_union:
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   257
  "({#a#} = M + N) =
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   258
    ({#a#} = M \<and> N = {#} \<or> M = {#} \<and> {#a#} = N)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   259
  apply (unfold Mempty_def single_def union_def)
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   260
  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
   261
  apply (blast dest: sym)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   262
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   263
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   264
theorem add_eq_conv_diff:
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   265
  "(M + {#a#} = N + {#b#}) =
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   266
    (M = N \<and> a = b \<or>
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   267
      M = N - {#a#} + {#b#} \<and> N = M - {#b#} + {#a#})"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   268
  apply (unfold single_def union_def diff_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   269
  apply (simp (no_asm) add: expand_fun_eq)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   270
  apply (rule conjI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   271
   apply force
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11701
diff changeset
   272
  apply safe
13601
fd3e3d6b37b2 Adapted to new simplifier.
berghofe
parents: 13596
diff changeset
   273
  apply simp_all
fd3e3d6b37b2 Adapted to new simplifier.
berghofe
parents: 13596
diff changeset
   274
  apply (simp add: eq_sym_conv)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   275
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   276
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   277
(*
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   278
val prems = Goal
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   279
 "[| !!F. [| finite F; !G. G < F --> P G |] ==> P F |] ==> finite F --> P F";
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   280
by (res_inst_tac [("a","F"),("f","\<lambda>A. if finite A then card A else 0")]
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   281
     measure_induct 1);
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   282
by (Clarify_tac 1);
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   283
by (resolve_tac prems 1);
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   284
 by (assume_tac 1);
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   285
by (Clarify_tac 1);
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   286
by (subgoal_tac "finite G" 1);
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   287
 by (fast_tac (claset() addDs [finite_subset,order_less_le RS iffD1]) 2);
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   288
by (etac allE 1);
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   289
by (etac impE 1);
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   290
 by (Blast_tac 2);
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   291
by (asm_simp_tac (simpset() addsimps [psubset_card]) 1);
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   292
no_qed();
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   293
val lemma = result();
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   294
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   295
val prems = Goal
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   296
 "[| finite F; !!F. [| finite F; !G. G < F --> P G |] ==> P F |] ==> P F";
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   297
by (rtac (lemma RS mp) 1);
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   298
by (REPEAT(ares_tac prems 1));
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   299
qed "finite_psubset_induct";
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   300
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   301
Better: use wf_finite_psubset in WF_Rel
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   302
*)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   303
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   304
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   305
subsection {* Induction over multisets *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   306
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   307
lemma setsum_decr:
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11655
diff changeset
   308
  "finite F ==> (0::nat) < f a ==>
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11655
diff changeset
   309
    setsum (f (a := f a - 1)) F = (if a \<in> F then setsum f F - 1 else setsum f F)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   310
  apply (erule finite_induct)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   311
   apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   312
  apply (drule_tac a = a in mk_disjoint_insert)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   313
  apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   314
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   315
10313
51e830bb7abe intro_classes by default;
wenzelm
parents: 10277
diff changeset
   316
lemma rep_multiset_induct_aux:
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11655
diff changeset
   317
  "P (\<lambda>a. (0::nat)) ==> (!!f b. f \<in> multiset ==> P f ==> P (f (b := f b + 1)))
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   318
    ==> \<forall>f. f \<in> multiset --> setsum f {x. 0 < f x} = n --> P f"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   319
proof -
11549
e7265e70fd7c renamed "antecedent" case to "rule_context";
wenzelm
parents: 11464
diff changeset
   320
  case rule_context
e7265e70fd7c renamed "antecedent" case to "rule_context";
wenzelm
parents: 11464
diff changeset
   321
  note premises = this [unfolded multiset_def]
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   322
  show ?thesis
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   323
    apply (unfold multiset_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   324
    apply (induct_tac n)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   325
     apply simp
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   326
     apply clarify
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   327
     apply (subgoal_tac "f = (\<lambda>a.0)")
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   328
      apply simp
11549
e7265e70fd7c renamed "antecedent" case to "rule_context";
wenzelm
parents: 11464
diff changeset
   329
      apply (rule premises)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   330
     apply (rule ext)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   331
     apply force
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   332
    apply clarify
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   333
    apply (frule setsum_SucD)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   334
    apply clarify
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   335
    apply (rename_tac a)
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11655
diff changeset
   336
    apply (subgoal_tac "finite {x. 0 < (f (a := f a - 1)) x}")
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   337
     prefer 2
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   338
     apply (rule finite_subset)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   339
      prefer 2
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   340
      apply assumption
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   341
     apply simp
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   342
     apply blast
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11655
diff changeset
   343
    apply (subgoal_tac "f = (f (a := f a - 1))(a := (f (a := f a - 1)) a + 1)")
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   344
     prefer 2
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   345
     apply (rule ext)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   346
     apply (simp (no_asm_simp))
11549
e7265e70fd7c renamed "antecedent" case to "rule_context";
wenzelm
parents: 11464
diff changeset
   347
     apply (erule ssubst, rule premises)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   348
     apply blast
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   349
    apply (erule allE, erule impE, erule_tac [2] mp)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   350
     apply blast
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11655
diff changeset
   351
    apply (simp (no_asm_simp) add: setsum_decr del: fun_upd_apply One_nat_def)
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   352
    apply (subgoal_tac "{x. x \<noteq> a --> 0 < f x} = {x. 0 < f x}")
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   353
     prefer 2
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   354
     apply blast
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   355
    apply (subgoal_tac "{x. x \<noteq> a \<and> 0 < f x} = {x. 0 < f x} - {a}")
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   356
     prefer 2
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   357
     apply blast
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   358
    apply (simp add: le_imp_diff_is_add setsum_diff1 cong: conj_cong)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   359
    done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   360
qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   361
10313
51e830bb7abe intro_classes by default;
wenzelm
parents: 10277
diff changeset
   362
theorem rep_multiset_induct:
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   363
  "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
   364
    (!!f b. f \<in> multiset ==> P f ==> P (f (b := f b + 1))) ==> P f"
10313
51e830bb7abe intro_classes by default;
wenzelm
parents: 10277
diff changeset
   365
  apply (insert rep_multiset_induct_aux)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   366
  apply blast
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   367
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   368
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   369
theorem multiset_induct [induct type: multiset]:
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   370
  "P {#} ==> (!!M x. P M ==> P (M + {#x#})) ==> P M"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   371
proof -
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   372
  note defns = union_def single_def Mempty_def
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   373
  assume prem1 [unfolded defns]: "P {#}"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   374
  assume prem2 [unfolded defns]: "!!M x. P M ==> P (M + {#x#})"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   375
  show ?thesis
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   376
    apply (rule Rep_multiset_inverse [THEN subst])
10313
51e830bb7abe intro_classes by default;
wenzelm
parents: 10277
diff changeset
   377
    apply (rule Rep_multiset [THEN rep_multiset_induct])
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   378
     apply (rule prem1)
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11655
diff changeset
   379
    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
   380
     prefer 2
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   381
     apply (simp add: expand_fun_eq)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   382
    apply (erule ssubst)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   383
    apply (erule Abs_multiset_inverse [THEN subst])
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   384
    apply (erule prem2 [simplified])
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   385
    done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   386
qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   387
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   388
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   389
lemma MCollect_preserves_multiset:
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   390
    "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
   391
  apply (simp add: multiset_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   392
  apply (rule finite_subset)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   393
   apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   394
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   395
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   396
theorem count_MCollect [simp]:
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   397
    "count {# x:M. P x #} a = (if P a then count M a else 0)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   398
  apply (unfold count_def MCollect_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   399
  apply (simp add: MCollect_preserves_multiset)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   400
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   401
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   402
theorem set_of_MCollect [simp]: "set_of {# x:M. P x #} = set_of M \<inter> {x. P x}"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   403
  apply (auto simp add: set_of_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   404
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   405
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   406
theorem multiset_partition: "M = {# x:M. P x #} + {# x:M. \<not> P x #}"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   407
  apply (subst multiset_eq_conv_count_eq)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   408
  apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   409
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   410
10277
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   411
declare Rep_multiset_inject [symmetric, simp del]
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   412
declare multiset_typedef [simp del]
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   413
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   414
theorem add_eq_conv_ex:
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   415
  "(M + {#a#} = N + {#b#}) =
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   416
    (M = N \<and> a = b \<or> (\<exists>K. M = K + {#b#} \<and> N = K + {#a#}))"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   417
  apply (auto simp add: add_eq_conv_diff)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   418
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   419
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   420
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   421
subsection {* Multiset orderings *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   422
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   423
subsubsection {* Well-foundedness *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   424
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   425
constdefs
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   426
  mult1 :: "('a \<times> 'a) set => ('a multiset \<times> 'a multiset) set"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   427
  "mult1 r ==
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   428
    {(N, M). \<exists>a M0 K. M = M0 + {#a#} \<and> N = M0 + K \<and>
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   429
      (\<forall>b. b :# K --> (b, a) \<in> r)}"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   430
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   431
  mult :: "('a \<times> 'a) set => ('a multiset \<times> 'a multiset) set"
10392
wenzelm
parents: 10313
diff changeset
   432
  "mult r == (mult1 r)\<^sup>+"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   433
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   434
lemma not_less_empty [iff]: "(M, {#}) \<notin> mult1 r"
10277
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   435
  by (simp add: mult1_def)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   436
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   437
lemma less_add: "(N, M0 + {#a#}) \<in> mult1 r ==>
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   438
    (\<exists>M. (M, M0) \<in> mult1 r \<and> N = M + {#a#}) \<or>
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   439
    (\<exists>K. (\<forall>b. b :# K --> (b, a) \<in> r) \<and> N = M0 + K)"
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   440
  (concl is "?case1 (mult1 r) \<or> ?case2")
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   441
proof (unfold mult1_def)
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   442
  let ?r = "\<lambda>K a. \<forall>b. b :# K --> (b, a) \<in> r"
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   443
  let ?R = "\<lambda>N M. \<exists>a M0 K. M = M0 + {#a#} \<and> N = M0 + K \<and> ?r K a"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   444
  let ?case1 = "?case1 {(N, M). ?R N M}"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   445
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   446
  assume "(N, M0 + {#a#}) \<in> {(N, M). ?R N M}"
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   447
  hence "\<exists>a' M0' K.
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   448
      M0 + {#a#} = M0' + {#a'#} \<and> N = M0' + K \<and> ?r K a'" by simp
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   449
  thus "?case1 \<or> ?case2"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   450
  proof (elim exE conjE)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   451
    fix a' M0' K
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   452
    assume N: "N = M0' + K" and r: "?r K a'"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   453
    assume "M0 + {#a#} = M0' + {#a'#}"
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   454
    hence "M0 = M0' \<and> a = a' \<or>
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   455
        (\<exists>K'. M0 = K' + {#a'#} \<and> M0' = K' + {#a#})"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   456
      by (simp only: add_eq_conv_ex)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   457
    thus ?thesis
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   458
    proof (elim disjE conjE exE)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   459
      assume "M0 = M0'" "a = a'"
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   460
      with N r have "?r K a \<and> N = M0 + K" by simp
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   461
      hence ?case2 .. thus ?thesis ..
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   462
    next
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   463
      fix K'
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   464
      assume "M0' = K' + {#a#}"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   465
      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
   466
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   467
      assume "M0 = K' + {#a'#}"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   468
      with r have "?R (K' + K) M0" by blast
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   469
      with n have ?case1 by simp thus ?thesis ..
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   470
    qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   471
  qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   472
qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   473
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   474
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
   475
proof
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   476
  let ?R = "mult1 r"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   477
  let ?W = "acc ?R"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   478
  {
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   479
    fix M M0 a
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   480
    assume M0: "M0 \<in> ?W"
12399
wenzelm
parents: 12338
diff changeset
   481
      and wf_hyp: "!!b. (b, a) \<in> r ==> (\<forall>M \<in> ?W. M + {#b#} \<in> ?W)"
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   482
      and acc_hyp: "\<forall>M. (M, M0) \<in> ?R --> M + {#a#} \<in> ?W"
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   483
    have "M0 + {#a#} \<in> ?W"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   484
    proof (rule accI [of "M0 + {#a#}"])
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   485
      fix N
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   486
      assume "(N, M0 + {#a#}) \<in> ?R"
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   487
      hence "((\<exists>M. (M, M0) \<in> ?R \<and> N = M + {#a#}) \<or>
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   488
          (\<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
   489
        by (rule less_add)
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   490
      thus "N \<in> ?W"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   491
      proof (elim exE disjE conjE)
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   492
        fix M assume "(M, M0) \<in> ?R" and N: "N = M + {#a#}"
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   493
        from acc_hyp have "(M, M0) \<in> ?R --> M + {#a#} \<in> ?W" ..
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   494
        hence "M + {#a#} \<in> ?W" ..
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   495
        thus "N \<in> ?W" by (simp only: N)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   496
      next
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   497
        fix K
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   498
        assume N: "N = M0 + K"
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   499
        assume "\<forall>b. b :# K --> (b, a) \<in> r"
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   500
        have "?this --> M0 + K \<in> ?W" (is "?P K")
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   501
        proof (induct K)
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   502
          from M0 have "M0 + {#} \<in> ?W" by simp
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   503
          thus "?P {#}" ..
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   504
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   505
          fix K x assume hyp: "?P K"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   506
          show "?P (K + {#x#})"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   507
          proof
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   508
            assume a: "\<forall>b. b :# (K + {#x#}) --> (b, a) \<in> r"
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   509
            hence "(x, a) \<in> r" by simp
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   510
            with wf_hyp have b: "\<forall>M \<in> ?W. M + {#x#} \<in> ?W" by blast
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   511
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   512
            from a hyp have "M0 + K \<in> ?W" by simp
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   513
            with b have "(M0 + K) + {#x#} \<in> ?W" ..
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   514
            thus "M0 + (K + {#x#}) \<in> ?W" by (simp only: union_assoc)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   515
          qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   516
        qed
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   517
        hence "M0 + K \<in> ?W" ..
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   518
        thus "N \<in> ?W" by (simp only: N)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   519
      qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   520
    qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   521
  } note tedious_reasoning = this
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   522
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   523
  assume wf: "wf r"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   524
  fix M
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   525
  show "M \<in> ?W"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   526
  proof (induct M)
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   527
    show "{#} \<in> ?W"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   528
    proof (rule accI)
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   529
      fix b assume "(b, {#}) \<in> ?R"
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   530
      with not_less_empty show "b \<in> ?W" by contradiction
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   531
    qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   532
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   533
    fix M a assume "M \<in> ?W"
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   534
    from wf have "\<forall>M \<in> ?W. M + {#a#} \<in> ?W"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   535
    proof induct
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   536
      fix a
12399
wenzelm
parents: 12338
diff changeset
   537
      assume "!!b. (b, a) \<in> r ==> (\<forall>M \<in> ?W. M + {#b#} \<in> ?W)"
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   538
      show "\<forall>M \<in> ?W. M + {#a#} \<in> ?W"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   539
      proof
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   540
        fix M assume "M \<in> ?W"
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   541
        thus "M + {#a#} \<in> ?W"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   542
          by (rule acc_induct) (rule tedious_reasoning)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   543
      qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   544
    qed
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   545
    thus "M + {#a#} \<in> ?W" ..
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   546
  qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   547
qed
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   548
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   549
theorem wf_mult1: "wf r ==> wf (mult1 r)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   550
  by (rule acc_wfI, rule all_accessible)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   551
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   552
theorem wf_mult: "wf r ==> wf (mult r)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   553
  by (unfold mult_def, rule wf_trancl, rule wf_mult1)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   554
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   555
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   556
subsubsection {* Closure-free presentation *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   557
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   558
(*Badly needed: a linear arithmetic procedure for multisets*)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   559
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   560
lemma diff_union_single_conv: "a :# J ==> I + J - {#a#} = I + (J - {#a#})"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   561
  apply (simp add: multiset_eq_conv_count_eq)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   562
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   563
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   564
text {* One direction. *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   565
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   566
lemma mult_implies_one_step:
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   567
  "trans r ==> (M, N) \<in> mult r ==>
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   568
    \<exists>I J K. N = I + J \<and> M = I + K \<and> J \<noteq> {#} \<and>
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   569
    (\<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
   570
  apply (unfold mult_def mult1_def set_of_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   571
  apply (erule converse_trancl_induct)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   572
  apply clarify
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   573
   apply (rule_tac x = M0 in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   574
   apply simp
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   575
  apply clarify
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   576
  apply (case_tac "a :# K")
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   577
   apply (rule_tac x = I in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   578
   apply (simp (no_asm))
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   579
   apply (rule_tac x = "(K - {#a#}) + Ka" in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   580
   apply (simp (no_asm_simp) add: union_assoc [symmetric])
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   581
   apply (drule_tac f = "\<lambda>M. M - {#a#}" in arg_cong)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   582
   apply (simp add: diff_union_single_conv)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   583
   apply (simp (no_asm_use) add: trans_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   584
   apply blast
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   585
  apply (subgoal_tac "a :# I")
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   586
   apply (rule_tac x = "I - {#a#}" in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   587
   apply (rule_tac x = "J + {#a#}" in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   588
   apply (rule_tac x = "K + Ka" in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   589
   apply (rule conjI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   590
    apply (simp add: multiset_eq_conv_count_eq split: nat_diff_split)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   591
   apply (rule conjI)
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   592
    apply (drule_tac f = "\<lambda>M. M - {#a#}" in arg_cong)
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   593
    apply simp
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   594
    apply (simp add: multiset_eq_conv_count_eq split: nat_diff_split)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   595
   apply (simp (no_asm_use) add: trans_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   596
   apply blast
10277
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   597
  apply (subgoal_tac "a :# (M0 + {#a#})")
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   598
   apply simp
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   599
  apply (simp (no_asm))
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   600
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   601
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   602
lemma elem_imp_eq_diff_union: "a :# M ==> M = M - {#a#} + {#a#}"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   603
  apply (simp add: multiset_eq_conv_count_eq)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   604
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   605
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   606
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
   607
  apply (erule size_eq_Suc_imp_elem [THEN exE])
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   608
  apply (drule elem_imp_eq_diff_union)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   609
  apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   610
  done
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
lemma one_step_implies_mult_aux:
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   613
  "trans r ==>
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   614
    \<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))
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   615
      --> (I + K, I + J) \<in> mult r"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   616
  apply (induct_tac n)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   617
   apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   618
  apply (frule size_eq_Suc_imp_eq_union)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   619
  apply clarify
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   620
  apply (rename_tac "J'")
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   621
  apply simp
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   622
  apply (erule notE)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   623
   apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   624
  apply (case_tac "J' = {#}")
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   625
   apply (simp add: mult_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   626
   apply (rule r_into_trancl)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   627
   apply (simp add: mult1_def set_of_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   628
   apply blast
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   629
  txt {* Now we know @{term "J' \<noteq> {#}"}. *}
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   630
  apply (cut_tac M = K and P = "\<lambda>x. (x, a) \<in> r" in multiset_partition)
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   631
  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
   632
  apply (erule ssubst)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   633
  apply (simp add: Ball_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   634
  apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   635
  apply (subgoal_tac
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   636
    "((I + {# x : K. (x, a) \<in> r #}) + {# x : K. (x, a) \<notin> r #},
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   637
      (I + {# x : K. (x, a) \<in> r #}) + J') \<in> mult r")
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   638
   prefer 2
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   639
   apply force
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   640
  apply (simp (no_asm_use) add: union_assoc [symmetric] mult_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   641
  apply (erule trancl_trans)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   642
  apply (rule r_into_trancl)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   643
  apply (simp add: mult1_def set_of_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   644
  apply (rule_tac x = a in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   645
  apply (rule_tac x = "I + J'" in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   646
  apply (simp add: union_ac)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   647
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   648
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   649
theorem one_step_implies_mult:
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   650
  "trans r ==> J \<noteq> {#} ==> \<forall>k \<in> set_of K. \<exists>j \<in> set_of J. (k, j) \<in> r
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   651
    ==> (I + K, I + J) \<in> mult r"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   652
  apply (insert one_step_implies_mult_aux)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   653
  apply blast
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   654
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   655
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   656
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   657
subsubsection {* Partial-order properties *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   658
12338
de0f4a63baa5 renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents: 11868
diff changeset
   659
instance multiset :: (type) ord ..
10249
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
defs (overloaded)
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   662
  less_multiset_def: "M' < M == (M', M) \<in> mult {(x', x). x' < x}"
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   663
  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
   664
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   665
lemma trans_base_order: "trans {(x', x). x' < (x::'a::order)}"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   666
  apply (unfold trans_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   667
  apply (blast intro: order_less_trans)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   668
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   669
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   670
text {*
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   671
 \medskip Irreflexivity.
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   672
*}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   673
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   674
lemma mult_irrefl_aux:
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   675
    "finite A ==> (\<forall>x \<in> A. \<exists>y \<in> A. x < (y::'a::order)) --> A = {}"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   676
  apply (erule finite_induct)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   677
   apply (auto intro: order_less_trans)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   678
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   679
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   680
theorem mult_less_not_refl: "\<not> M < (M::'a::order multiset)"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   681
  apply (unfold less_multiset_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   682
  apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   683
  apply (drule trans_base_order [THEN mult_implies_one_step])
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   684
  apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   685
  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
   686
  apply (simp add: set_of_eq_empty_iff)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   687
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   688
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   689
lemma mult_less_irrefl [elim!]: "M < (M::'a::order multiset) ==> R"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   690
  apply (insert mult_less_not_refl)
13596
ee5f79b210c1 modified induct method
nipkow
parents: 12399
diff changeset
   691
  apply fast
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   692
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   693
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   694
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   695
text {* Transitivity. *}
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
theorem mult_less_trans: "K < M ==> M < N ==> K < (N::'a::order multiset)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   698
  apply (unfold less_multiset_def mult_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   699
  apply (blast intro: trancl_trans)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   700
  done
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
text {* Asymmetry. *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   703
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   704
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
   705
  apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   706
  apply (rule mult_less_not_refl [THEN notE])
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   707
  apply (erule mult_less_trans)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   708
  apply assumption
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   709
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   710
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   711
theorem mult_less_asym:
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   712
    "M < N ==> (\<not> P ==> N < (M::'a::order multiset)) ==> P"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   713
  apply (insert mult_less_not_sym)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   714
  apply blast
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   715
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   716
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   717
theorem mult_le_refl [iff]: "M <= (M::'a::order multiset)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   718
  apply (unfold le_multiset_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   719
  apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   720
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   721
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   722
text {* Anti-symmetry. *}
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
theorem mult_le_antisym:
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   725
    "M <= N ==> N <= M ==> M = (N::'a::order multiset)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   726
  apply (unfold le_multiset_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   727
  apply (blast dest: mult_less_not_sym)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   728
  done
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
text {* Transitivity. *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   731
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   732
theorem mult_le_trans:
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   733
    "K <= M ==> M <= N ==> K <= (N::'a::order multiset)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   734
  apply (unfold le_multiset_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   735
  apply (blast intro: mult_less_trans)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   736
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   737
11655
923e4d0d36d5 tuned parentheses in relational expressions;
wenzelm
parents: 11549
diff changeset
   738
theorem mult_less_le: "(M < N) = (M <= N \<and> M \<noteq> (N::'a::order multiset))"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   739
  apply (unfold le_multiset_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   740
  apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   741
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   742
10277
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   743
text {* Partial order. *}
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   744
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   745
instance multiset :: (order) order
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   746
  apply intro_classes
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   747
     apply (rule mult_le_refl)
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   748
    apply (erule mult_le_trans)
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   749
    apply assumption
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   750
   apply (erule mult_le_antisym)
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   751
   apply assumption
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   752
  apply (rule mult_less_le)
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   753
  done
081c8641aa11 improved typedef;
wenzelm
parents: 10249
diff changeset
   754
10249
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
subsubsection {* Monotonicity of multiset union *}
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   757
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   758
theorem mult1_union:
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   759
    "(B, D) \<in> mult1 r ==> trans r ==> (C + B, C + D) \<in> mult1 r"
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   760
  apply (unfold mult1_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   761
  apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   762
  apply (rule_tac x = a in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   763
  apply (rule_tac x = "C + M0" in exI)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   764
  apply (simp add: union_assoc)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   765
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   766
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   767
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
   768
  apply (unfold less_multiset_def mult_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   769
  apply (erule trancl_induct)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   770
   apply (blast intro: mult1_union transI order_less_trans r_into_trancl)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   771
  apply (blast intro: mult1_union transI order_less_trans r_into_trancl trancl_trans)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   772
  done
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
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
   775
  apply (subst union_commute [of B C])
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   776
  apply (subst union_commute [of D C])
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   777
  apply (erule union_less_mono2)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   778
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   779
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   780
theorem union_less_mono:
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   781
    "A < C ==> B < D ==> A + B < C + (D::'a::order multiset)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   782
  apply (blast intro!: union_less_mono1 union_less_mono2 mult_less_trans)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   783
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   784
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   785
theorem union_le_mono:
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   786
    "A <= C ==> B <= D ==> A + B <= C + (D::'a::order multiset)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   787
  apply (unfold le_multiset_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   788
  apply (blast intro: union_less_mono union_less_mono1 union_less_mono2)
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
theorem empty_leI [iff]: "{#} <= (M::'a::order multiset)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   792
  apply (unfold le_multiset_def less_multiset_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   793
  apply (case_tac "M = {#}")
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   794
   prefer 2
11464
ddea204de5bc turned translation for 1::nat into def.
nipkow
parents: 10714
diff changeset
   795
   apply (subgoal_tac "({#} + {#}, {#} + M) \<in> mult (Collect (split op <))")
10249
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   796
    prefer 2
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   797
    apply (rule one_step_implies_mult)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   798
      apply (simp only: trans_def)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   799
      apply auto
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
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   802
theorem union_upper1: "A <= A + (B::'a::order multiset)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   803
  apply (subgoal_tac "A + {#} <= A + B")
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   804
   prefer 2
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   805
   apply (rule union_le_mono)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   806
    apply auto
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   807
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   808
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   809
theorem union_upper2: "B <= A + (B::'a::order multiset)"
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   810
  apply (subst union_commute, rule union_upper1)
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   811
  done
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   812
e4d13d8a9011 Multisets (from HOL/Induct/Multiset and friends);
wenzelm
parents:
diff changeset
   813
end