src/HOL/Library/Permutation.thy
author paulson
Thu, 24 Jun 2004 17:54:53 +0200
changeset 15005 546c8e7e28d4
parent 14706 71590b7733b7
child 15072 4861bf6af0b4
permissions -rw-r--r--
Norbert Voelker
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Library/Permutation.thy
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
     2
    Author:     Lawrence C Paulson and Thomas M Rasmussen and Norbert Voelker
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
     3
*)
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
     4
14706
71590b7733b7 tuned document;
wenzelm
parents: 11153
diff changeset
     5
header {* Permutations *}
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
     6
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
     7
theory Permutation = Multiset:
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
     8
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
     9
consts
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    10
  perm :: "('a list * 'a list) set"
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    11
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    12
syntax
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    13
  "_perm" :: "'a list => 'a list => bool"    ("_ <~~> _"  [50, 50] 50)
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    14
translations
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    15
  "x <~~> y" == "(x, y) \<in> perm"
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    16
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    17
inductive perm
11153
950ede59c05a Blast bug fix made old proof too slow
paulson
parents: 11054
diff changeset
    18
  intros
950ede59c05a Blast bug fix made old proof too slow
paulson
parents: 11054
diff changeset
    19
    Nil  [intro!]: "[] <~~> []"
950ede59c05a Blast bug fix made old proof too slow
paulson
parents: 11054
diff changeset
    20
    swap [intro!]: "y # x # l <~~> x # y # l"
950ede59c05a Blast bug fix made old proof too slow
paulson
parents: 11054
diff changeset
    21
    Cons [intro!]: "xs <~~> ys ==> z # xs <~~> z # ys"
950ede59c05a Blast bug fix made old proof too slow
paulson
parents: 11054
diff changeset
    22
    trans [intro]: "xs <~~> ys ==> ys <~~> zs ==> xs <~~> zs"
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    23
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    24
lemma perm_refl [iff]: "l <~~> l"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
    25
by (induct l, auto)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    26
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    27
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    28
subsection {* Some examples of rule induction on permutations *}
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    29
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    30
lemma xperm_empty_imp_aux: "xs <~~> ys ==> xs = [] --> ys = []"
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    31
    -- {* the form of the premise lets the induction bind @{term xs} and @{term ys} *}
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    32
  apply (erule perm.induct)
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    33
     apply (simp_all (no_asm_simp))
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    34
  done
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    35
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    36
lemma xperm_empty_imp: "[] <~~> ys ==> ys = []"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
    37
by (insert xperm_empty_imp_aux, blast)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    38
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    39
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    40
text {*
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    41
  \medskip This more general theorem is easier to understand!
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    42
  *}
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    43
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    44
lemma perm_length: "xs <~~> ys ==> length xs = length ys"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
    45
by (erule perm.induct, simp_all)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    46
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    47
lemma perm_empty_imp: "[] <~~> xs ==> xs = []"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
    48
by (drule perm_length, auto)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    49
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    50
lemma perm_sym: "xs <~~> ys ==> ys <~~> xs"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
    51
by (erule perm.induct, auto)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    52
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    53
lemma perm_mem [rule_format]: "xs <~~> ys ==> x mem xs --> x mem ys"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
    54
by (erule perm.induct, auto)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    55
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    56
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    57
subsection {* Ways of making new permutations *}
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    58
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    59
text {*
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    60
  We can insert the head anywhere in the list.
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    61
*}
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    62
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    63
lemma perm_append_Cons: "a # xs @ ys <~~> xs @ a # ys"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
    64
by (induct xs, auto)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    65
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    66
lemma perm_append_swap: "xs @ ys <~~> ys @ xs"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
    67
  apply (induct xs, simp_all)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    68
  apply (blast intro: perm_append_Cons)
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    69
  done
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    70
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    71
lemma perm_append_single: "a # xs <~~> xs @ [a]"
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    72
  apply (rule perm.trans)
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    73
   prefer 2
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
    74
   apply (rule perm_append_swap, simp)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    75
  done
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    76
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    77
lemma perm_rev: "rev xs <~~> xs"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
    78
  apply (induct xs, simp_all)
11153
950ede59c05a Blast bug fix made old proof too slow
paulson
parents: 11054
diff changeset
    79
  apply (blast intro!: perm_append_single intro: perm_sym)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    80
  done
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    81
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    82
lemma perm_append1: "xs <~~> ys ==> l @ xs <~~> l @ ys"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
    83
by (induct l, auto)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    84
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    85
lemma perm_append2: "xs <~~> ys ==> xs @ l <~~> ys @ l"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
    86
by (blast intro!: perm_append_swap perm_append1)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    87
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    88
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    89
subsection {* Further results *}
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    90
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    91
lemma perm_empty [iff]: "([] <~~> xs) = (xs = [])"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
    92
by (blast intro: perm_empty_imp)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    93
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    94
lemma perm_empty2 [iff]: "(xs <~~> []) = (xs = [])"
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    95
  apply auto
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    96
  apply (erule perm_sym [THEN perm_empty_imp])
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    97
  done
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    98
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    99
lemma perm_sing_imp [rule_format]: "ys <~~> xs ==> xs = [y] --> ys = [y]"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   100
by (erule perm.induct, auto)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   101
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   102
lemma perm_sing_eq [iff]: "(ys <~~> [y]) = (ys = [y])"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   103
by (blast intro: perm_sing_imp)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   104
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   105
lemma perm_sing_eq2 [iff]: "([y] <~~> ys) = (ys = [y])"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   106
by (blast dest: perm_sym)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   107
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   108
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   109
subsection {* Removing elements *}
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   110
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   111
consts
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   112
  remove :: "'a => 'a list => 'a list"
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   113
primrec
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   114
  "remove x [] = []"
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   115
  "remove x (y # ys) = (if x = y then ys else y # remove x ys)"
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   116
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   117
lemma perm_remove: "x \<in> set ys ==> ys <~~> x # remove x ys"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   118
by (induct ys, auto)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   119
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   120
lemma remove_commute: "remove x (remove y l) = remove y (remove x l)"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   121
by (induct l, auto)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   122
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   123
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   124
text {* \medskip Congruence rule *}
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   125
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   126
lemma perm_remove_perm: "xs <~~> ys ==> remove z xs <~~> remove z ys"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   127
by (erule perm.induct, auto)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   128
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   129
lemma remove_hd [simp]: "remove z (z # xs) = xs"
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   130
  apply auto
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   131
  done
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   132
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   133
lemma cons_perm_imp_perm: "z # xs <~~> z # ys ==> xs <~~> ys"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   134
by (drule_tac z = z in perm_remove_perm, auto)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   135
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   136
lemma cons_perm_eq [iff]: "(z#xs <~~> z#ys) = (xs <~~> ys)"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   137
by (blast intro: cons_perm_imp_perm)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   138
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   139
lemma append_perm_imp_perm: "!!xs ys. zs @ xs <~~> zs @ ys ==> xs <~~> ys"
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   140
  apply (induct zs rule: rev_induct)
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   141
   apply (simp_all (no_asm_use))
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   142
  apply blast
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   143
  done
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   144
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   145
lemma perm_append1_eq [iff]: "(zs @ xs <~~> zs @ ys) = (xs <~~> ys)"
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   146
by (blast intro: append_perm_imp_perm perm_append1)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   147
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   148
lemma perm_append2_eq [iff]: "(xs @ zs <~~> ys @ zs) = (xs <~~> ys)"
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   149
  apply (safe intro!: perm_append2)
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   150
  apply (rule append_perm_imp_perm)
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   151
  apply (rule perm_append_swap [THEN perm.trans])
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   152
    -- {* the previous step helps this @{text blast} call succeed quickly *}
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   153
  apply (blast intro: perm_append_swap)
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   154
  done
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   155
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   156
(****************** Norbert Voelker 17 June 2004 **************) 
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   157
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   158
consts 
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   159
  multiset_of :: "'a list \<Rightarrow> 'a multiset"
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   160
primrec
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   161
  "multiset_of [] = {#}"
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   162
  "multiset_of (a # x) = multiset_of x + {# a #}"
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   163
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   164
lemma multiset_of_zero_iff[simp]: "(multiset_of x = {#}) = (x = [])"
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   165
  by (induct_tac x, auto) 
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   166
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   167
lemma multiset_of_zero_iff_right[simp]: "({#} = multiset_of x) = (x = [])"
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   168
  by (induct_tac x, auto)
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   169
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   170
lemma set_of_multiset_of[simp]: "set_of(multiset_of x) = set x"
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   171
 by (induct_tac x, auto) 
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   172
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   173
lemma multiset_of_remove[simp]: 
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   174
  "multiset_of (remove a x) = multiset_of x - {#a#}"
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   175
  by (induct_tac x, auto simp: multiset_eq_conv_count_eq) 
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   176
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   177
lemma multiset_of_eq_perm:  "(multiset_of xs = multiset_of ys) = (xs <~~> ys) "
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   178
  apply (rule iffI) 
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   179
  apply (erule_tac [2] perm.induct, simp_all add: union_ac) 
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   180
  apply (erule rev_mp, rule_tac x=ys in spec, induct_tac xs, auto) 
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   181
  apply (erule_tac x = "remove a x" in allE, drule sym, simp) 
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   182
  apply (subgoal_tac "a \<in> set x") 
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   183
  apply (drule_tac z=a in perm.Cons) 
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   184
  apply (erule perm.trans, rule perm_sym, erule perm_remove) 
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   185
  apply (drule_tac f=set_of in arg_cong, simp)
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   186
  done
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   187
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   188
lemma set_count_multiset_of: "set x = {a. 0 < count (multiset_of x) a}"
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   189
  by (induct_tac x, auto)  
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   190
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   191
lemma distinct_count_multiset_of: 
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   192
   "distinct x \<Longrightarrow> count (multiset_of x) a = (if a \<in> set x then 1 else 0)"
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   193
  by (erule rev_mp, induct_tac x, auto) 
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   194
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   195
lemma distinct_set_eq_iff_multiset_of_eq: 
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   196
  "\<lbrakk>distinct x; distinct y\<rbrakk> \<Longrightarrow> (set x = set y) = (multiset_of x = multiset_of y)"
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   197
  by (auto simp: multiset_eq_conv_count_eq distinct_count_multiset_of) 
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   198
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   199
end