src/HOL/Induct/Multiset.ML
author paulson
Tue, 17 Oct 2000 10:21:12 +0200
changeset 10231 178a272bceeb
parent 9747 043098ba5098
permissions -rw-r--r--
renaming of contrapos rules
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/Induct/Multiset.ML
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
     2
    ID:         $Id$
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
     3
    Author:     Tobias Nipkow
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
     4
    Copyright   1998 TUM
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
     5
*)
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
     6
8952
921c35be6ffb tidying for overloaded 0, setsum, etc.
paulson
parents: 8914
diff changeset
     7
Addsimps [Abs_multiset_inverse, Rep_multiset_inverse, Rep_multiset,
921c35be6ffb tidying for overloaded 0, setsum, etc.
paulson
parents: 8914
diff changeset
     8
	  Zero_def];
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
     9
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    10
(** Preservation of representing set `multiset' **)
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    11
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    12
Goalw [multiset_def] "(%a. 0) : multiset";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    13
by (Simp_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    14
qed "const0_in_multiset";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    15
Addsimps [const0_in_multiset];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    16
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    17
Goalw [multiset_def] "(%b. if b=a then 1 else 0) : multiset";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    18
by (Simp_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    19
qed "only1_in_multiset";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    20
Addsimps [only1_in_multiset];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    21
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    22
Goalw [multiset_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    23
 "[| M : multiset; N : multiset |] ==> (%a. M a + N a) : multiset";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    24
by (Asm_full_simp_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    25
by (dtac finite_UnI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    26
by (assume_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    27
by (asm_full_simp_tac (simpset() delsimps [finite_Un]addsimps [Un_def]) 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    28
qed "union_preserves_multiset";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    29
Addsimps [union_preserves_multiset];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    30
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    31
Goalw [multiset_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    32
 "[| M : multiset |] ==> (%a. M a - N a) : multiset";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    33
by (Asm_full_simp_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    34
by (etac (rotate_prems 1 finite_subset) 1);
8952
921c35be6ffb tidying for overloaded 0, setsum, etc.
paulson
parents: 8914
diff changeset
    35
by Auto_tac;
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    36
qed "diff_preserves_multiset";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    37
Addsimps [diff_preserves_multiset];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    38
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    39
(** Injectivity of Rep_multiset **)
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    40
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    41
Goal "(M = N) = (Rep_multiset M = Rep_multiset N)";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    42
by (rtac iffI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    43
 by (Asm_simp_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    44
by (dres_inst_tac [("f","Abs_multiset")] arg_cong 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    45
by (Asm_full_simp_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    46
qed "multiset_eq_conv_Rep_eq";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    47
Addsimps [multiset_eq_conv_Rep_eq];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    48
Addsimps [expand_fun_eq];
9017
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
    49
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    50
(*
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    51
Goal
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    52
 "[| f : multiset; g : multiset |] ==> \
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    53
\ (Abs_multiset f = Abs_multiset g) = (!x. f x = g x)";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    54
by (rtac iffI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    55
 by (dres_inst_tac [("f","Rep_multiset")] arg_cong 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    56
 by (Asm_full_simp_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    57
by (subgoal_tac "f = g" 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    58
 by (Asm_simp_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    59
by (rtac ext 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    60
by (Blast_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    61
qed "Abs_multiset_eq";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    62
Addsimps [Abs_multiset_eq];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    63
*)
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    64
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    65
(** Equations **)
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    66
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    67
(* union *)
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    68
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    69
Goalw [union_def,empty_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    70
 "M + {#} = M & {#} + M = M";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    71
by (Simp_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    72
qed "union_empty";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    73
Addsimps [union_empty];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    74
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    75
Goalw [union_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    76
 "(M::'a multiset) + N = N + M";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    77
by (simp_tac (simpset() addsimps add_ac) 1);
9017
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
    78
qed "union_commute";
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    79
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    80
Goalw [union_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    81
 "((M::'a multiset)+N)+K = M+(N+K)";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    82
by (simp_tac (simpset() addsimps add_ac) 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    83
qed "union_assoc";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    84
9266
1b917b8b1b38 removal of batch style, and tidying
paulson
parents: 9089
diff changeset
    85
Goal "M+(N+K) = N+((M+K)::'a multiset)";
1b917b8b1b38 removal of batch style, and tidying
paulson
parents: 9089
diff changeset
    86
by (rtac (union_commute RS trans) 1);
1b917b8b1b38 removal of batch style, and tidying
paulson
parents: 9089
diff changeset
    87
by (rtac (union_assoc RS trans) 1);
1b917b8b1b38 removal of batch style, and tidying
paulson
parents: 9089
diff changeset
    88
by (rtac (union_commute RS arg_cong) 1);
1b917b8b1b38 removal of batch style, and tidying
paulson
parents: 9089
diff changeset
    89
qed "union_lcomm";
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    90
9017
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
    91
bind_thms ("union_ac", [union_assoc, union_commute, union_lcomm]);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    92
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    93
(* diff *)
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    94
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    95
Goalw [empty_def,diff_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    96
 "M-{#} = M & {#}-M = {#}";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
    97
by (Simp_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    98
qed "diff_empty";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
    99
Addsimps [diff_empty];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   100
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   101
Goalw [union_def,diff_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   102
 "M+{#a#}-{#a#} = M";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   103
by (Simp_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   104
qed "diff_union_inverse2";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   105
Addsimps [diff_union_inverse2];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   106
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   107
(* count *)
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   108
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   109
Goalw [count_def,empty_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   110
 "count {#} a = 0";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   111
by (Simp_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   112
qed "count_empty";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   113
Addsimps [count_empty];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   114
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   115
Goalw [count_def,single_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   116
 "count {#b#} a = (if b=a then 1 else 0)";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   117
by (Simp_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   118
qed "count_single";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   119
Addsimps [count_single];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   120
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   121
Goalw [count_def,union_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   122
 "count (M+N) a = count M a + count N a";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   123
by (Simp_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   124
qed "count_union";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   125
Addsimps [count_union];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   126
5772
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   127
Goalw [count_def,diff_def]
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   128
 "count (M-N) a = count M a - count N a";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   129
by (Simp_tac 1);
5772
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   130
qed "count_diff";
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   131
Addsimps [count_diff];
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   132
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   133
(* set_of *)
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   134
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   135
Goalw [set_of_def] "set_of {#} = {}";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   136
by (Simp_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   137
qed "set_of_empty";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   138
Addsimps [set_of_empty];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   139
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   140
Goalw [set_of_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   141
 "set_of {#b#} = {b}";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   142
by (Simp_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   143
qed "set_of_single";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   144
Addsimps [set_of_single];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   145
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   146
Goalw [set_of_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   147
 "set_of(M+N) = set_of M Un set_of N";
8952
921c35be6ffb tidying for overloaded 0, setsum, etc.
paulson
parents: 8914
diff changeset
   148
by Auto_tac;
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   149
qed "set_of_union";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   150
Addsimps [set_of_union];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   151
8914
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   152
Goalw [set_of_def, empty_def, count_def] "(set_of M = {}) = (M = {#})";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   153
by Auto_tac;
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   154
qed "set_of_eq_empty_iff";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   155
9017
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   156
Goalw [set_of_def] "(x : set_of M) = (x :# M)";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   157
by Auto_tac; 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   158
qed "mem_set_of_iff";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   159
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   160
(* size *)
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   161
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   162
Goalw [size_def] "size {#} = 0";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   163
by (Simp_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   164
qed "size_empty";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   165
Addsimps [size_empty];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   166
8914
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   167
Goalw [size_def] "size {#b#} = 1";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   168
by (Simp_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   169
qed "size_single";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   170
Addsimps [size_single];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   171
8914
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   172
Goal "finite (set_of M)";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   173
by (cut_inst_tac [("x", "M")] Rep_multiset 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   174
by (asm_full_simp_tac
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   175
    (simpset() addsimps [multiset_def, set_of_def, count_def]) 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   176
qed "finite_set_of";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   177
AddIffs [finite_set_of];
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   178
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   179
Goal "finite A ==> setsum (count N) (A Int set_of N) = setsum (count N) A";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   180
by (etac finite_induct 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   181
by (Simp_tac 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   182
by (asm_full_simp_tac (simpset() addsimps [Int_insert_left, set_of_def]) 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   183
qed "setsum_count_Int";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   184
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   185
Goalw [size_def] "size (M+N::'a multiset) = size M + size N";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   186
by (subgoal_tac "count (M+N) = (%a. count M a + count N a)" 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   187
by (rtac ext 2);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   188
by (Simp_tac 2);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   189
by (asm_simp_tac
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   190
    (simpset() addsimps [setsum_Un, setsum_addf, setsum_count_Int]) 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   191
by (stac Int_commute 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   192
by (asm_simp_tac (simpset() addsimps [setsum_count_Int]) 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   193
qed "size_union";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   194
Addsimps [size_union];
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   195
9017
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   196
Goalw [size_def, empty_def, count_def] "(size M = 0) = (M = {#})";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   197
by Auto_tac; 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   198
by (asm_full_simp_tac (simpset() addsimps [set_of_def, count_def]) 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   199
qed "size_eq_0_iff_empty";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   200
AddIffs [size_eq_0_iff_empty];
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   201
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   202
Goalw [size_def] "size M = Suc n ==> EX a. a :# M";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   203
by (dtac setsum_SucD 1);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   204
by Auto_tac; 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   205
qed "size_eq_Suc_imp_elem";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   206
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   207
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   208
(* equalities *)
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   209
5772
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   210
Goalw [count_def] "(M = N) = (!a. count M a = count N a)";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   211
by (Simp_tac 1);
5772
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   212
qed "multiset_eq_conv_count_eq";
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   213
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   214
Goalw [single_def,empty_def] "{#a#} ~= {#}  &  {#} ~= {#a#}";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   215
by (Simp_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   216
qed "single_not_empty";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   217
Addsimps [single_not_empty];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   218
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   219
Goalw [single_def] "({#a#}={#b#}) = (a=b)";
8952
921c35be6ffb tidying for overloaded 0, setsum, etc.
paulson
parents: 8914
diff changeset
   220
by Auto_tac;
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   221
qed "single_eq_single";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   222
Addsimps [single_eq_single];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   223
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   224
Goalw [union_def,empty_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   225
 "(M+N = {#}) = (M = {#} & N = {#})";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   226
by (Simp_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   227
by (Blast_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   228
qed "union_eq_empty";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   229
AddIffs [union_eq_empty];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   230
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   231
Goalw [union_def,empty_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   232
 "({#} = M+N) = (M = {#} & N = {#})";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   233
by (Simp_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   234
by (Blast_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   235
qed "empty_eq_union";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   236
AddIffs [empty_eq_union];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   237
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   238
Goalw [union_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   239
 "(M+K = N+K) = (M=(N::'a multiset))";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   240
by (Simp_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   241
qed "union_right_cancel";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   242
Addsimps [union_right_cancel];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   243
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   244
Goalw [union_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   245
 "(K+M = K+N) = (M=(N::'a multiset))";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   246
by (Simp_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   247
qed "union_left_cancel";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   248
Addsimps [union_left_cancel];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   249
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   250
Goalw [empty_def,single_def,union_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   251
 "(M+N = {#a#}) = (M={#a#} & N={#} | M={#} & N={#a#})";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   252
by (simp_tac (simpset() addsimps [add_is_1]) 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   253
by (Blast_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   254
qed "union_is_single";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   255
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   256
Goalw [empty_def,single_def,union_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   257
 "({#a#} = M+N) = ({#a#}=M & N={#} | M={#} & {#a#}=N)";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   258
by (simp_tac (simpset() addsimps [one_is_add]) 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   259
by (blast_tac (claset() addDs [sym]) 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   260
qed "single_is_union";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   261
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   262
Goalw [single_def,union_def,diff_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   263
 "(M+{#a#} = N+{#b#}) = (M=N & a=b | M = N-{#a#}+{#b#} & N = M-{#b#}+{#a#})";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   264
by (Simp_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   265
by (rtac conjI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   266
 by (Force_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   267
by (Clarify_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   268
by (rtac conjI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   269
 by (Blast_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   270
by (Clarify_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   271
by (rtac iffI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   272
 by (rtac conjI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   273
 by (Clarify_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   274
  by (rtac conjI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   275
   by (asm_full_simp_tac (simpset() addsimps [eq_sym_conv]) 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   276
(* PROOF FAILED:
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   277
by (Blast_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   278
*)
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   279
  by (Fast_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   280
 by (Asm_simp_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   281
by (Force_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   282
qed "add_eq_conv_diff";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   283
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   284
(* FIXME
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   285
val prems = Goal
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   286
 "[| !!F. [| finite F; !G. G < F --> P G |] ==> P F |] ==> finite F --> P F";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   287
by (res_inst_tac [("a","F"),("f","%A. if finite A then card A else 0")]
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   288
     measure_induct 1);
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   289
by (Clarify_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   290
by (resolve_tac prems 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   291
 by (assume_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   292
by (Clarify_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   293
by (subgoal_tac "finite G" 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   294
 by (fast_tac (claset() addDs [finite_subset,order_less_le RS iffD1]) 2);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   295
by (etac allE 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   296
by (etac impE 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   297
 by (Blast_tac 2);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   298
by (asm_simp_tac (simpset() addsimps [psubset_card]) 1);
7454
bde978e3d9bb no_qed;
wenzelm
parents: 6162
diff changeset
   299
no_qed();
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   300
val lemma = result();
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   301
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   302
val prems = Goal
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   303
 "[| finite F; !!F. [| finite F; !G. G < F --> P G |] ==> P F |] ==> P F";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   304
by (rtac (lemma RS mp) 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   305
by (REPEAT(ares_tac prems 1));
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   306
qed "finite_psubset_induct";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   307
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   308
Better: use wf_finite_psubset in WF_Rel
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   309
*)
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   310
9017
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   311
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   312
(** Towards the induction rule **)
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   313
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   314
Goal "[| finite F; 0 < f a |] ==> \
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   315
\     setsum (f(a:=f(a)-1)) F = (if a:F then setsum f F - 1 else setsum f F)";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   316
by (etac finite_induct 1);
8952
921c35be6ffb tidying for overloaded 0, setsum, etc.
paulson
parents: 8914
diff changeset
   317
by Auto_tac;
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   318
 by (asm_simp_tac (simpset() addsimps add_ac) 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   319
by (dres_inst_tac [("a","a")] mk_disjoint_insert 1);
8952
921c35be6ffb tidying for overloaded 0, setsum, etc.
paulson
parents: 8914
diff changeset
   320
by Auto_tac;
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   321
qed "setsum_decr";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   322
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   323
val prems = Goalw [multiset_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   324
 "[| P(%a.0); \
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   325
\    !!f b. [| f : multiset; P(f) |] ==> P(f(b:=f(b)+1)) |] \
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   326
\  ==> !f. f : multiset --> setsum f {x. 0 < f x} = n --> P(f)";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   327
by (induct_tac "n" 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   328
 by (Asm_simp_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   329
 by (Clarify_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   330
 by (subgoal_tac "f = (%a.0)" 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   331
  by (Asm_simp_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   332
  by (resolve_tac prems 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   333
 by (rtac ext 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   334
 by (Force_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   335
by (Clarify_tac 1);
7499
23e090051cb8 isatool expandshort;
wenzelm
parents: 7454
diff changeset
   336
by (ftac setsum_SucD 1);
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   337
by (Clarify_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   338
by (rename_tac "a" 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   339
by (subgoal_tac "finite{x. 0 < (f(a:=f(a)-1)) x}" 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   340
 by (etac (rotate_prems 1 finite_subset) 2);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   341
 by (Simp_tac 2);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   342
 by (Blast_tac 2);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   343
by (subgoal_tac
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   344
   "f = (f(a:=f(a)-1))(a:=(f(a:=f(a)-1))a+1)" 1);
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   345
 by (rtac ext 2);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   346
 by (Asm_simp_tac 2);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   347
by (EVERY1[etac ssubst, resolve_tac prems]);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   348
 by (Blast_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   349
by (EVERY[etac allE 1, etac impE 1, etac mp 2]);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   350
 by (Blast_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   351
by (asm_simp_tac (simpset() addsimps [setsum_decr] delsimps [fun_upd_apply]) 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   352
by (subgoal_tac "{x. x ~= a --> 0 < f x} = {x. 0 < f x}" 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   353
 by (Blast_tac 2);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   354
by (subgoal_tac "{x. x ~= a & 0 < f x} = {x. 0 < f x} - {a}" 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   355
 by (Blast_tac 2);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   356
by (asm_simp_tac (simpset() addsimps [le_imp_diff_is_add,setsum_diff1]
5983
79e301a6a51b At last: linear arithmetic for nat!
nipkow
parents: 5772
diff changeset
   357
                           addcongs [conj_cong]) 1);
7454
bde978e3d9bb no_qed;
wenzelm
parents: 6162
diff changeset
   358
no_qed();
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   359
val lemma = result();
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   360
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   361
val major::prems = Goal
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   362
 "[| f : multiset; \
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   363
\    P(%a.0); \
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   364
\    !!f b. [| f : multiset; P(f) |] ==> P(f(b:=f(b)+1)) |] ==> P(f)";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   365
by (rtac (major RSN (3, lemma RS spec RS mp RS mp)) 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   366
by (REPEAT(ares_tac (refl::prems) 1));
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   367
qed "Rep_multiset_induct";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   368
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   369
val [prem1,prem2] = Goalw [union_def,single_def,empty_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   370
 "[| P({#}); !!M x. P(M) ==> P(M + {#x#}) |] ==> P(M)";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   371
by (rtac (Rep_multiset_inverse RS subst) 1);
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   372
by (rtac (Rep_multiset RS Rep_multiset_induct) 1);
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   373
 by (rtac prem1 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   374
by (Clarify_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   375
by (subgoal_tac
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   376
    "f(b := f b + 1) = (%a. f a + (if a = b then 1 else 0))" 1);
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   377
 by (Simp_tac 2);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   378
by (etac ssubst 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   379
by (etac (Abs_multiset_inverse RS subst) 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   380
by (etac(simplify (simpset()) prem2)1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   381
qed "multiset_induct";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   382
9017
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   383
Goal "M : multiset ==> (%x. if P x then M x else 0) : multiset";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   384
by (asm_full_simp_tac (simpset() addsimps [multiset_def]) 1);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   385
by (rtac finite_subset 1);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   386
by Auto_tac; 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   387
qed "MCollect_preserves_multiset";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   388
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   389
Goalw [count_def,MCollect_def]
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   390
 "count {# x:M. P x #} a = (if P a then count M a else 0)";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   391
by (asm_full_simp_tac (simpset() addsimps [MCollect_preserves_multiset]) 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   392
qed "count_MCollect";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   393
Addsimps [count_MCollect];
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   394
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   395
Goalw [set_of_def]
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   396
 "set_of {# x:M. P x #} = set_of M Int {x. P x}";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   397
by Auto_tac; 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   398
qed "set_of_MCollect";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   399
Addsimps [set_of_MCollect];
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   400
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   401
Goal "M = {# x:M. P x #} + {# x:M. ~ P x #}";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   402
by (stac multiset_eq_conv_count_eq 1);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   403
by Auto_tac; 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   404
qed "multiset_partition";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   405
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   406
Delsimps [multiset_eq_conv_Rep_eq, expand_fun_eq];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   407
Delsimps [Abs_multiset_inverse,Rep_multiset_inverse,Rep_multiset];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   408
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   409
Goal
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   410
 "(M+{#a#} = N+{#b#}) = (M = N & a = b | (? K. M = K+{#b#} & N = K+{#a#}))";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   411
by (simp_tac (simpset() addsimps [add_eq_conv_diff]) 1);
8952
921c35be6ffb tidying for overloaded 0, setsum, etc.
paulson
parents: 8914
diff changeset
   412
by Auto_tac;
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   413
qed "add_eq_conv_ex";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   414
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   415
(** order **)
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   416
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   417
Goalw [mult1_def] "(M, {#}) ~: mult1(r)";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   418
by (Simp_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   419
qed "not_less_empty";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   420
AddIffs [not_less_empty];
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   421
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   422
Goalw [mult1_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   423
 "(N,M0 + {#a#}) : mult1(r) = \
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   424
\ ((? M. (M,M0) : mult1(r) & N = M + {#a#}) | \
9017
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   425
\  (? K. (!b. b :# K --> (b,a) : r) & N = M0 + K))";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   426
by (rtac iffI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   427
 by (asm_full_simp_tac (simpset() addsimps [add_eq_conv_ex]) 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   428
 by (Clarify_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   429
 by (etac disjE 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   430
  by (Blast_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   431
 by (Clarify_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   432
 by (res_inst_tac [("x","Ka+K")] exI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   433
 by (simp_tac (simpset() addsimps union_ac) 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   434
 by (Blast_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   435
by (etac disjE 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   436
 by (Clarify_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   437
 by (res_inst_tac [("x","aa")] exI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   438
 by (res_inst_tac [("x","M0+{#a#}")] exI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   439
 by (res_inst_tac [("x","K")] exI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   440
 by (simp_tac (simpset() addsimps union_ac) 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   441
by (Blast_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   442
qed "less_add_conv";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   443
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   444
Open_locale "MSOrd";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   445
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   446
val W_def = thm "W_def";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   447
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   448
Goalw [W_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   449
 "[| !b. (b,a) : r --> (!M : W. M+{#b#} : W); M0 : W; \
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   450
\    !M. (M,M0) : mult1(r) --> M+{#a#} : W |] \
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   451
\ ==> M0+{#a#} : W";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   452
by (rtac accI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   453
by (rename_tac "N" 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   454
by (full_simp_tac (simpset() addsimps [less_add_conv]) 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   455
by (etac disjE 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   456
 by (Blast_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   457
by (Clarify_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   458
by (rotate_tac ~1 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   459
by (etac rev_mp 1);
9747
043098ba5098 introduced induct_thm_tac
nipkow
parents: 9266
diff changeset
   460
by (induct_thm_tac multiset_induct "K" 1);
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   461
 by (Asm_simp_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   462
by (simp_tac (simpset() addsimps [union_assoc RS sym]) 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   463
by (Blast_tac 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   464
qed "lemma1";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   465
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   466
Goalw [W_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   467
 "[| !b. (b,a) : r --> (!M : W. M+{#b#} : W); M : W |] ==> M+{#a#} : W";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   468
by (etac acc_induct 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   469
by (blast_tac (claset() addIs [export lemma1]) 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   470
qed "lemma2";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   471
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   472
Goalw [W_def]
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   473
 "wf(r) ==> !M:W. M+{#a#} : W";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   474
by (eres_inst_tac [("a","a")] wf_induct 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   475
by (blast_tac (claset() addIs [export lemma2]) 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   476
qed "lemma3";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   477
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   478
Goalw [W_def] "wf(r) ==> M : W";
9747
043098ba5098 introduced induct_thm_tac
nipkow
parents: 9266
diff changeset
   479
by (induct_thm_tac multiset_induct "M" 1);
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   480
 by (rtac accI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   481
 by (Asm_full_simp_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   482
by (blast_tac (claset() addDs [export lemma3]) 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   483
qed "all_accessible";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   484
6024
cb87f103d114 new Close_locale synatx
paulson
parents: 5983
diff changeset
   485
Close_locale "MSOrd";
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   486
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   487
Goal "wf(r) ==> wf(mult1 r)";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   488
by (blast_tac (claset() addIs [acc_wfI, export all_accessible]) 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   489
qed "wf_mult1";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   490
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   491
Goalw [mult_def] "wf(r) ==> wf(mult r)";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   492
by (blast_tac (claset() addIs [wf_trancl,wf_mult1]) 1);
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   493
qed "wf_mult";
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   494
5772
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   495
(** Equivalence of mult with the usual (closure-free) def **)
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   496
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   497
(* Badly needed: a linear arithmetic tactic for multisets *)
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   498
9017
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   499
Goal "a :# J ==> I+J - {#a#} = I + (J-{#a#})";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   500
by (asm_simp_tac (simpset() addsimps [multiset_eq_conv_count_eq]) 1);
5772
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   501
qed "diff_union_single_conv";
5628
15b7f12ad919 Multisets at last!
nipkow
parents:
diff changeset
   502
5772
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   503
(* One direction *)
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   504
Goalw [mult_def,mult1_def,set_of_def]
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   505
 "trans r ==> \
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   506
\ (M,N) : mult r ==> (? I J K. N = I+J & M = I+K & J ~= {#} & \
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   507
\                            (!k : set_of K. ? j : set_of J. (k,j) : r))";
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   508
by (etac converse_trancl_induct 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   509
 by (Clarify_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   510
 by (res_inst_tac [("x","M0")] exI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   511
 by (Simp_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   512
by (Clarify_tac 1);
9017
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   513
by (case_tac "a :# K" 1);
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   514
 by (res_inst_tac [("x","I")] exI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   515
 by (Simp_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   516
 by (res_inst_tac [("x","(K - {#a#}) + Ka")] exI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   517
 by (asm_simp_tac (simpset() addsimps [union_assoc RS sym]) 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   518
 by (dres_inst_tac[("f","%M. M-{#a#}")] arg_cong 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   519
 by (asm_full_simp_tac (simpset() addsimps [diff_union_single_conv]) 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   520
 by (full_simp_tac (simpset() addsimps [trans_def]) 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   521
 by (Blast_tac 1);
9017
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   522
by (subgoal_tac "a :# I" 1);
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   523
 by (res_inst_tac [("x","I-{#a#}")] exI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   524
 by (res_inst_tac [("x","J+{#a#}")] exI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   525
 by (res_inst_tac [("x","K + Ka")] exI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   526
 by (rtac conjI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   527
  by (asm_simp_tac (simpset() addsimps [multiset_eq_conv_count_eq]
5772
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   528
                             addsplits [nat_diff_split]) 1);
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   529
 by (rtac conjI 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   530
  by (dres_inst_tac[("f","%M. M-{#a#}")] arg_cong 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   531
  by (Asm_full_simp_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   532
  by (asm_simp_tac (simpset() addsimps [multiset_eq_conv_count_eq]
5772
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   533
                             addsplits [nat_diff_split]) 1);
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   534
 by (full_simp_tac (simpset() addsimps [trans_def]) 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   535
 by (Blast_tac 1);
9017
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   536
by (subgoal_tac "a :# (M0 +{#a#})" 1);
6162
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   537
 by (Asm_full_simp_tac 1);
484adda70b65 expandshort
paulson
parents: 6024
diff changeset
   538
by (Simp_tac 1);
5772
d52d61a66c32 Some more proofs.
nipkow
parents: 5758
diff changeset
   539
qed "mult_implies_one_step";
8914
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   540
9017
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   541
Goal "a :# M ==> M = M - {#a#} + {#a#}";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   542
by (asm_simp_tac (simpset() addsimps [multiset_eq_conv_count_eq]) 1);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   543
qed "elem_imp_eq_diff_union";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   544
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   545
Goal "size M = Suc n ==> EX a N. M = N + {#a#}";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   546
by (etac (size_eq_Suc_imp_elem RS exE) 1);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   547
by (dtac elem_imp_eq_diff_union 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   548
by Auto_tac; 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   549
qed "size_eq_Suc_imp_eq_union";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   550
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   551
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   552
Goal  "trans r ==> \
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   553
\ ALL I J K. \
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   554
\  (size J = n & J ~= {#} & \
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   555
\   (! k : set_of K. ? j : set_of J. (k,j) : r)) --> (I+K, I+J) : mult r";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   556
by (induct_tac "n" 1);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   557
by Auto_tac; 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   558
by (ftac size_eq_Suc_imp_eq_union 1);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   559
by (Clarify_tac 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   560
ren "J'" 1;
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   561
by (Asm_full_simp_tac 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   562
by (etac notE 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   563
by Auto_tac; 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   564
by (case_tac "J' = {#}" 1);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   565
 by (asm_full_simp_tac (simpset() addsimps [mult_def]) 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   566
 by (rtac r_into_trancl 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   567
 by (asm_full_simp_tac (simpset() addsimps [mult1_def,set_of_def]) 1);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   568
 by (Blast_tac 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   569
(*Now we know J' ~= {#}*)
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   570
by (cut_inst_tac [("M","K"),("P", "%x. (x,a):r")] multiset_partition 1);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   571
by (eres_inst_tac [("P", "ALL k : set_of K. ?P k")] rev_mp 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   572
by (etac ssubst 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   573
by (asm_full_simp_tac (simpset() addsimps [Ball_def]) 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   574
by Auto_tac; 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   575
by (subgoal_tac "((I + {# x : K. (x, a) : r#}) + {# x : K. (x, a) ~: r#}, \
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   576
\                 (I + {# x : K. (x, a) : r#}) + J') : mult r" 1);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   577
 by (Force_tac 2);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   578
by (full_simp_tac (simpset() addsimps [union_assoc RS sym, mult_def]) 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   579
by (etac trancl_trans 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   580
by (rtac r_into_trancl 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   581
by (asm_full_simp_tac (simpset() addsimps [mult1_def,set_of_def]) 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   582
by (res_inst_tac [("x", "a")] exI 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   583
by (res_inst_tac [("x", "I + J'")] exI 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   584
by (asm_simp_tac (simpset() addsimps union_ac) 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   585
qed_spec_mp "one_step_implies_mult_lemma";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   586
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   587
Goal  "[| trans r;  J ~= {#};  \
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   588
\         ALL k : set_of K. EX j : set_of J. (k,j) : r |] \
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   589
\      ==> (I+K, I+J) : mult r";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   590
by (rtac one_step_implies_mult_lemma 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   591
by Auto_tac; 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   592
qed "one_step_implies_mult";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   593
8914
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   594
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   595
(** Proving that multisets are partially ordered **)
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   596
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   597
Goalw [trans_def] "trans {(x',x). x' < (x::'a::order)}";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   598
by (blast_tac (claset() addIs [order_less_trans]) 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   599
qed "trans_base_order";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   600
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   601
Goal "finite A ==> (ALL x: A. EX y : A. x < (y::'a::order)) --> A={}";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   602
by (etac finite_induct 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   603
by Auto_tac;
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   604
by (blast_tac (claset() addIs [order_less_trans]) 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   605
qed_spec_mp "mult_irrefl_lemma";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   606
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   607
(*irreflexivity*)
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   608
Goalw [mult_less_def] "~ M < (M :: ('a::order)multiset)";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   609
by Auto_tac;
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   610
by (dtac (trans_base_order RS mult_implies_one_step) 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   611
by Auto_tac;
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   612
by (dtac (finite_set_of RS mult_irrefl_lemma) 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   613
by (asm_full_simp_tac (simpset() addsimps [set_of_eq_empty_iff]) 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   614
qed "mult_less_not_refl";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   615
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   616
(* N<N ==> R *)
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   617
bind_thm ("mult_less_irrefl", mult_less_not_refl RS notE);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   618
AddSEs [mult_less_irrefl];
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   619
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   620
(*transitivity*)
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   621
Goalw [mult_less_def, mult_def]
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   622
     "[| K < M; M < N |] ==> K < (N :: ('a::order)multiset)";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   623
by (blast_tac (claset() addIs [trancl_trans]) 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   624
qed "mult_less_trans";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   625
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   626
(*asymmetry*)
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   627
Goal "M < N ==> ~ N < (M :: ('a::order)multiset)";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   628
by Auto_tac;
9017
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   629
by (rtac (mult_less_not_refl RS notE) 1);
8914
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   630
by (etac mult_less_trans 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   631
by (assume_tac 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   632
qed "mult_less_not_sym";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   633
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   634
(* [| M<N;  ~P ==> N<M |] ==> P *)
10231
178a272bceeb renaming of contrapos rules
paulson
parents: 9747
diff changeset
   635
bind_thm ("mult_less_asym", mult_less_not_sym RS contrapos_np);
8914
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   636
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   637
Goalw [mult_le_def] "M <= (M :: ('a::order)multiset)";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   638
by Auto_tac;
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   639
qed "mult_le_refl";
9017
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   640
AddIffs [mult_le_refl];
8914
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   641
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   642
(*anti-symmetry*)
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   643
Goalw [mult_le_def] "[| M <= N;  N <= M |] ==> M = (N :: ('a::order)multiset)";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   644
by (blast_tac (claset() addDs [mult_less_not_sym]) 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   645
qed "mult_le_antisym";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   646
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   647
(*transitivity*)
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   648
Goalw [mult_le_def]
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   649
     "[| K <= M; M <= N |] ==> K <= (N :: ('a::order)multiset)";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   650
by (blast_tac (claset() addIs [mult_less_trans]) 1);
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   651
qed "mult_le_trans";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   652
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   653
Goalw [mult_le_def] "M < N = (M <= N & M ~= (N :: ('a::order)multiset))";
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   654
by Auto_tac;
e1e4b7313063 Proving that multisets are partially ordered
paulson
parents: 7499
diff changeset
   655
qed "mult_less_le";
9017
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   656
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   657
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   658
(** Monotonicity of multiset union **)
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   659
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   660
Goalw [mult1_def]
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   661
     "[| (B,D) : mult1 r; trans r |] ==> (C + B, C + D) : mult1 r";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   662
by Auto_tac; 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   663
by (res_inst_tac [("x", "a")] exI 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   664
by (res_inst_tac [("x", "C+M0")] exI 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   665
by (asm_simp_tac (simpset() addsimps [union_assoc]) 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   666
qed "mult1_union";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   667
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   668
Goalw [mult_less_def, mult_def]
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   669
     "!!C:: ('a::order) multiset. B<D ==> C+B < C+D";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   670
by (etac trancl_induct 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   671
by (blast_tac (claset() addIs [mult1_union, transI, order_less_trans, 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   672
                               r_into_trancl]) 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   673
by (blast_tac (claset() addIs [mult1_union, transI, order_less_trans, 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   674
                               r_into_trancl, trancl_trans]) 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   675
qed "union_less_mono2";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   676
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   677
Goal "!!C:: ('a::order) multiset. B<D ==> B+C < D+C";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   678
by (simp_tac (simpset() addsimps [union_commute]) 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   679
by (etac union_less_mono2 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   680
qed "union_less_mono1";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   681
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   682
Goal "!!C:: ('a::order) multiset. [| A<C; B<D |] ==> A+B < C+D";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   683
by (blast_tac (claset() addIs [union_less_mono1, union_less_mono2,
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   684
                               mult_less_trans]) 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   685
qed "union_less_mono";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   686
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   687
Goalw [mult_le_def]
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   688
     "!!D:: ('a::order) multiset. [| A<=C;  B<=D |] ==> A+B <= C+D";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   689
by (blast_tac (claset() addIs [union_less_mono, union_less_mono1, 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   690
                               union_less_mono2]) 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   691
qed "union_le_mono";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   692
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   693
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   694
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   695
Goalw [mult_le_def, mult_less_def]
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   696
     "{#} <= (M :: ('a::order) multiset)";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   697
by (case_tac "M={#}" 1);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   698
by (subgoal_tac "({#} + {#}, {#} + M) : mult(Collect (split op <))" 2);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   699
by (rtac one_step_implies_mult 3);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   700
bw trans_def;
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   701
by Auto_tac; 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   702
by (blast_tac (claset() addIs [order_less_trans]) 1); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   703
qed "empty_leI";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   704
AddIffs [empty_leI];
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   705
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   706
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   707
Goal "!!A:: ('a::order) multiset. A <= A+B";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   708
by (subgoal_tac "A+{#} <= A+B" 1);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   709
by (rtac union_le_mono 2); 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   710
by Auto_tac; 
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   711
qed "union_upper1";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   712
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   713
Goal "!!A:: ('a::order) multiset. B <= A+B";
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   714
by (stac union_commute 1 THEN rtac union_upper1 1);
ff259b415c4d Many new theorems about multisets and their ordering, including basic
paulson
parents: 9004
diff changeset
   715
qed "union_upper2";