src/HOL/Library/Permutation.thy
author nipkow
Mon, 05 Nov 2007 18:18:39 +0100
changeset 25287 094dab519ff5
parent 25277 95128fcdd7e8
child 25379 12bcf37252b1
permissions -rw-r--r--
added lemmas
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
15131
c69542757a4d New theory header syntax.
nipkow
parents: 15072
diff changeset
     7
theory Permutation
15140
322485b816ac import -> imports
nipkow
parents: 15131
diff changeset
     8
imports Multiset
15131
c69542757a4d New theory header syntax.
nipkow
parents: 15072
diff changeset
     9
begin
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    10
23755
1c4672d130b1 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    11
inductive
1c4672d130b1 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    12
  perm :: "'a list => 'a list => bool"  ("_ <~~> _"  [50, 50] 50)
1c4672d130b1 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    13
  where
11153
950ede59c05a Blast bug fix made old proof too slow
paulson
parents: 11054
diff changeset
    14
    Nil  [intro!]: "[] <~~> []"
23755
1c4672d130b1 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    15
  | swap [intro!]: "y # x # l <~~> x # y # l"
1c4672d130b1 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    16
  | Cons [intro!]: "xs <~~> ys ==> z # xs <~~> z # ys"
1c4672d130b1 Adapted to new inductive definition package.
berghofe
parents: 21404
diff changeset
    17
  | trans [intro]: "xs <~~> ys ==> ys <~~> zs ==> xs <~~> zs"
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    18
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    19
lemma perm_refl [iff]: "l <~~> l"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    20
  by (induct l) auto
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    21
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    22
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    23
subsection {* Some examples of rule induction on permutations *}
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    24
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    25
lemma xperm_empty_imp_aux: "xs <~~> ys ==> xs = [] --> ys = []"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    26
    -- {*the form of the premise lets the induction bind @{term xs}
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 15005
diff changeset
    27
         and @{term ys} *}
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    28
  apply (erule perm.induct)
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    29
     apply (simp_all (no_asm_simp))
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    30
  done
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    31
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    32
lemma xperm_empty_imp: "[] <~~> ys ==> ys = []"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    33
  using xperm_empty_imp_aux by blast
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    34
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    35
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    36
text {*
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    37
  \medskip This more general theorem is easier to understand!
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
lemma perm_length: "xs <~~> ys ==> length xs = length ys"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    41
  by (erule perm.induct) simp_all
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    42
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    43
lemma perm_empty_imp: "[] <~~> xs ==> xs = []"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    44
  by (drule perm_length) auto
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    45
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    46
lemma perm_sym: "xs <~~> ys ==> ys <~~> xs"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    47
  by (erule perm.induct) auto
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    48
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    49
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    50
subsection {* Ways of making new permutations *}
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    51
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    52
text {*
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    53
  We can insert the head anywhere in the list.
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    54
*}
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    55
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    56
lemma perm_append_Cons: "a # xs @ ys <~~> xs @ a # ys"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    57
  by (induct xs) auto
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    58
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    59
lemma perm_append_swap: "xs @ ys <~~> ys @ xs"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    60
  apply (induct xs)
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    61
    apply simp_all
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    62
  apply (blast intro: perm_append_Cons)
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    63
  done
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    64
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    65
lemma perm_append_single: "a # xs <~~> xs @ [a]"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    66
  by (rule perm.trans [OF _ perm_append_swap]) simp
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    67
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    68
lemma perm_rev: "rev xs <~~> xs"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    69
  apply (induct xs)
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    70
   apply simp_all
11153
950ede59c05a Blast bug fix made old proof too slow
paulson
parents: 11054
diff changeset
    71
  apply (blast intro!: perm_append_single intro: perm_sym)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    72
  done
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    73
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    74
lemma perm_append1: "xs <~~> ys ==> l @ xs <~~> l @ ys"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    75
  by (induct l) auto
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    76
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    77
lemma perm_append2: "xs <~~> ys ==> xs @ l <~~> ys @ l"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    78
  by (blast intro!: perm_append_swap perm_append1)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    79
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    80
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    81
subsection {* Further results *}
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    82
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    83
lemma perm_empty [iff]: "([] <~~> xs) = (xs = [])"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    84
  by (blast intro: perm_empty_imp)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    85
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    86
lemma perm_empty2 [iff]: "(xs <~~> []) = (xs = [])"
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    87
  apply auto
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    88
  apply (erule perm_sym [THEN perm_empty_imp])
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    89
  done
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    90
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    91
lemma perm_sing_imp [rule_format]: "ys <~~> xs ==> xs = [y] --> ys = [y]"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    92
  by (erule perm.induct) auto
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_sing_eq [iff]: "(ys <~~> [y]) = (ys = [y])"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    95
  by (blast intro: perm_sing_imp)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    96
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    97
lemma perm_sing_eq2 [iff]: "([y] <~~> ys) = (ys = [y])"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
    98
  by (blast dest: perm_sym)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
    99
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   100
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   101
subsection {* Removing elements *}
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   102
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   103
consts
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   104
  remove :: "'a => 'a list => 'a list"
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   105
primrec
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   106
  "remove x [] = []"
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   107
  "remove x (y # ys) = (if x = y then ys else y # remove x ys)"
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   108
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   109
lemma perm_remove: "x \<in> set ys ==> ys <~~> x # remove x ys"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   110
  by (induct ys) auto
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   111
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   112
lemma remove_commute: "remove x (remove y l) = remove y (remove x l)"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   113
  by (induct l) auto
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   114
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   115
lemma multiset_of_remove[simp]:
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   116
    "multiset_of (remove a x) = multiset_of x - {#a#}"
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   117
  apply (induct x)
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   118
   apply (auto simp: multiset_eq_conv_count_eq)
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   119
  done
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 15005
diff changeset
   120
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   121
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   122
text {* \medskip Congruence rule *}
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   123
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   124
lemma perm_remove_perm: "xs <~~> ys ==> remove z xs <~~> remove z ys"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   125
  by (erule perm.induct) auto
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   126
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   127
lemma remove_hd [simp]: "remove z (z # xs) = xs"
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 15005
diff changeset
   128
  by auto
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   129
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   130
lemma cons_perm_imp_perm: "z # xs <~~> z # ys ==> xs <~~> ys"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   131
  by (drule_tac z = z in perm_remove_perm) auto
11054
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_eq [iff]: "(z#xs <~~> z#ys) = (xs <~~> ys)"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   134
  by (blast intro: cons_perm_imp_perm)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   135
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   136
lemma append_perm_imp_perm: "!!xs ys. zs @ xs <~~> zs @ ys ==> xs <~~> ys"
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   137
  apply (induct zs rule: rev_induct)
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   138
   apply (simp_all (no_asm_use))
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   139
  apply blast
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   140
  done
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   141
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   142
lemma perm_append1_eq [iff]: "(zs @ xs <~~> zs @ ys) = (xs <~~> ys)"
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   143
  by (blast intro: append_perm_imp_perm perm_append1)
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   144
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   145
lemma perm_append2_eq [iff]: "(xs @ zs <~~> ys @ zs) = (xs <~~> ys)"
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   146
  apply (safe intro!: perm_append2)
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   147
  apply (rule append_perm_imp_perm)
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   148
  apply (rule perm_append_swap [THEN perm.trans])
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   149
    -- {* the previous step helps this @{text blast} call succeed quickly *}
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   150
  apply (blast intro: perm_append_swap)
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   151
  done
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   152
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 15005
diff changeset
   153
lemma multiset_of_eq_perm: "(multiset_of xs = multiset_of ys) = (xs <~~> ys) "
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   154
  apply (rule iffI)
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   155
  apply (erule_tac [2] perm.induct, simp_all add: union_ac)
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   156
  apply (erule rev_mp, rule_tac x=ys in spec)
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   157
  apply (induct_tac xs, auto)
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   158
  apply (erule_tac x = "remove a x" in allE, drule sym, simp)
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   159
  apply (subgoal_tac "a \<in> set x")
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   160
  apply (drule_tac z=a in perm.Cons)
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   161
  apply (erule perm.trans, rule perm_sym, erule perm_remove)
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   162
  apply (drule_tac f=set_of in arg_cong, simp)
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   163
  done
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   164
17200
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   165
lemma multiset_of_le_perm_append:
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   166
    "(multiset_of xs \<le># multiset_of ys) = (\<exists>zs. xs @ zs <~~> ys)";
3a4d03d1a31b tuned presentation;
wenzelm
parents: 15140
diff changeset
   167
  apply (auto simp: multiset_of_eq_perm[THEN sym] mset_le_exists_conv)
15072
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 15005
diff changeset
   168
  apply (insert surj_multiset_of, drule surjD)
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 15005
diff changeset
   169
  apply (blast intro: sym)+
4861bf6af0b4 new material courtesy of Norbert Voelker
paulson
parents: 15005
diff changeset
   170
  done
15005
546c8e7e28d4 Norbert Voelker
paulson
parents: 14706
diff changeset
   171
25277
95128fcdd7e8 added lemmas
nipkow
parents: 23755
diff changeset
   172
lemma perm_set_eq: "xs <~~> ys ==> set xs = set ys"
95128fcdd7e8 added lemmas
nipkow
parents: 23755
diff changeset
   173
by (metis multiset_of_eq_perm multiset_of_eq_setD)
95128fcdd7e8 added lemmas
nipkow
parents: 23755
diff changeset
   174
95128fcdd7e8 added lemmas
nipkow
parents: 23755
diff changeset
   175
lemma perm_distinct_iff: "xs <~~> ys ==> distinct xs = distinct ys"
95128fcdd7e8 added lemmas
nipkow
parents: 23755
diff changeset
   176
apply(induct rule:perm.induct)
95128fcdd7e8 added lemmas
nipkow
parents: 23755
diff changeset
   177
   apply simp_all
95128fcdd7e8 added lemmas
nipkow
parents: 23755
diff changeset
   178
 apply fastsimp
95128fcdd7e8 added lemmas
nipkow
parents: 23755
diff changeset
   179
apply (metis perm_set_eq)
95128fcdd7e8 added lemmas
nipkow
parents: 23755
diff changeset
   180
done
95128fcdd7e8 added lemmas
nipkow
parents: 23755
diff changeset
   181
25287
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   182
lemma eq_set_perm_remdups: "set xs = set ys ==> remdups xs <~~> remdups ys"
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   183
apply(induct xs arbitrary: ys rule:length_induct)
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   184
apply (case_tac "remdups xs", simp, simp)
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   185
apply(subgoal_tac "a : set (remdups ys)")
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   186
 prefer 2 apply (metis set.simps(2) insert_iff set_remdups)
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   187
apply(drule split_list) apply(elim exE conjE)
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   188
apply(drule_tac x=list in spec) apply(erule impE) prefer 2
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   189
 apply(drule_tac x="ysa@zs" in spec) apply(erule impE) prefer 2
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   190
  apply simp
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   191
  apply(subgoal_tac "a#list <~~> a#ysa@zs")
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   192
   apply (metis Cons_eq_appendI perm_append_Cons trans)
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   193
  apply (metis Cons Cons_eq_appendI distinct.simps(2) distinct_remdups distinct_remdups_id perm_append_swap perm_distinct_iff)
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   194
 apply(subgoal_tac "set (a#list) = set (ysa@a#zs) & distinct (a#list) & distinct (ysa@a#zs)")
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   195
  apply(fastsimp simp add: insert_ident)
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   196
 apply (metis distinct_remdups set_remdups)
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   197
apply (metis Nat.le_less_trans Suc_length_conv le_def length_remdups_leq less_Suc_eq)
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   198
done
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   199
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   200
lemma perm_remdups_iff_eq_set: "remdups x <~~> remdups y = (set x = set y)"
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   201
by (metis List.set_remdups perm_set_eq eq_set_perm_remdups)
094dab519ff5 added lemmas
nipkow
parents: 25277
diff changeset
   202
11054
a5404c70982f moved from Induct/ to Library/
wenzelm
parents:
diff changeset
   203
end