src/HOL/Library/Permutations.thy
author hoelzl
Fri, 30 May 2014 14:55:10 +0200
changeset 57129 7edb7550663e
parent 56608 8e3c848008fa
child 57418 6ab1c7cb0b8d
permissions -rw-r--r--
introduce more powerful reindexing rules for big operators
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41959
b460124855b8 tuned headers;
wenzelm
parents: 39302
diff changeset
     1
(*  Title:      HOL/Library/Permutations.thy
b460124855b8 tuned headers;
wenzelm
parents: 39302
diff changeset
     2
    Author:     Amine Chaieb, University of Cambridge
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
     3
*)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
     4
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
     5
header {* Permutations, both general and specifically on finite sets.*}
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
     6
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
     7
theory Permutations
36335
ceea7e15c04b fix imports
huffman
parents: 34102
diff changeset
     8
imports Parity Fact
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
     9
begin
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    10
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    11
subsection {* Transpositions *}
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    12
56608
8e3c848008fa more simp rules for Fun.swap
haftmann
parents: 56545
diff changeset
    13
lemma swap_id_idempotent [simp]:
8e3c848008fa more simp rules for Fun.swap
haftmann
parents: 56545
diff changeset
    14
  "Fun.swap a b id \<circ> Fun.swap a b id = id"
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
    15
  by (rule ext, auto simp add: Fun.swap_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    16
56608
8e3c848008fa more simp rules for Fun.swap
haftmann
parents: 56545
diff changeset
    17
lemma inv_swap_id:
8e3c848008fa more simp rules for Fun.swap
haftmann
parents: 56545
diff changeset
    18
  "inv (Fun.swap a b id) = Fun.swap a b id"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    19
  by (rule inv_unique_comp) simp_all
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    20
56608
8e3c848008fa more simp rules for Fun.swap
haftmann
parents: 56545
diff changeset
    21
lemma swap_id_eq:
8e3c848008fa more simp rules for Fun.swap
haftmann
parents: 56545
diff changeset
    22
  "Fun.swap a b id x = (if x = a then b else if x = b then a else x)"
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
    23
  by (simp add: Fun.swap_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    24
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    25
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    26
subsection {* Basic consequences of the definition *}
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    27
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    28
definition permutes  (infixr "permutes" 41)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    29
  where "(p permutes S) \<longleftrightarrow> (\<forall>x. x \<notin> S \<longrightarrow> p x = x) \<and> (\<forall>y. \<exists>!x. p x = y)"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    30
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    31
lemma permutes_in_image: "p permutes S \<Longrightarrow> p x \<in> S \<longleftrightarrow> x \<in> S"
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    32
  unfolding permutes_def by metis
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    33
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    34
lemma permutes_image: "p permutes S \<Longrightarrow> p ` S = S"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
    35
  unfolding permutes_def
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
    36
  apply (rule set_eqI)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    37
  apply (simp add: image_iff)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    38
  apply metis
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    39
  done
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    40
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    41
lemma permutes_inj: "p permutes S \<Longrightarrow> inj p"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
    42
  unfolding permutes_def inj_on_def by blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    43
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    44
lemma permutes_surj: "p permutes s \<Longrightarrow> surj p"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
    45
  unfolding permutes_def surj_def by metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    46
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    47
lemma permutes_inv_o:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    48
  assumes pS: "p permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    49
  shows "p \<circ> inv p = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    50
    and "inv p \<circ> p = id"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    51
  using permutes_inj[OF pS] permutes_surj[OF pS]
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    52
  unfolding inj_iff[symmetric] surj_iff[symmetric] by blast+
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    53
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
    54
lemma permutes_inverses:
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    55
  fixes p :: "'a \<Rightarrow> 'a"
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    56
  assumes pS: "p permutes S"
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    57
  shows "p (inv p x) = x"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    58
    and "inv p (p x) = x"
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
    59
  using permutes_inv_o[OF pS, unfolded fun_eq_iff o_def] by auto
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    60
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    61
lemma permutes_subset: "p permutes S \<Longrightarrow> S \<subseteq> T \<Longrightarrow> p permutes T"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    62
  unfolding permutes_def by blast
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    63
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    64
lemma permutes_empty[simp]: "p permutes {} \<longleftrightarrow> p = id"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    65
  unfolding fun_eq_iff permutes_def by simp metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    66
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    67
lemma permutes_sing[simp]: "p permutes {a} \<longleftrightarrow> p = id"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    68
  unfolding fun_eq_iff permutes_def by simp metis
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
    69
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    70
lemma permutes_univ: "p permutes UNIV \<longleftrightarrow> (\<forall>y. \<exists>!x. p x = y)"
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    71
  unfolding permutes_def by simp
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    72
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    73
lemma permutes_inv_eq: "p permutes S \<Longrightarrow> inv p y = x \<longleftrightarrow> p x = y"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    74
  unfolding permutes_def inv_def
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    75
  apply auto
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    76
  apply (erule allE[where x=y])
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    77
  apply (erule allE[where x=y])
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    78
  apply (rule someI_ex)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    79
  apply blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    80
  apply (rule some1_equality)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    81
  apply blast
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    82
  apply blast
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    83
  done
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    84
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    85
lemma permutes_swap_id: "a \<in> S \<Longrightarrow> b \<in> S \<Longrightarrow> Fun.swap a b id permutes S"
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
    86
  unfolding permutes_def Fun.swap_def fun_upd_def by auto metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    87
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    88
lemma permutes_superset: "p permutes S \<Longrightarrow> (\<forall>x \<in> S - T. p x = x) \<Longrightarrow> p permutes T"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    89
  by (simp add: Ball_def permutes_def) metis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    90
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    91
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    92
subsection {* Group properties *}
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    93
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    94
lemma permutes_id: "id permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    95
  unfolding permutes_def by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    96
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    97
lemma permutes_compose: "p permutes S \<Longrightarrow> q permutes S \<Longrightarrow> q \<circ> p permutes S"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    98
  unfolding permutes_def o_def by metis
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    99
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   100
lemma permutes_inv:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   101
  assumes pS: "p permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   102
  shows "inv p permutes S"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   103
  using pS unfolding permutes_def permutes_inv_eq[OF pS] by metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   104
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   105
lemma permutes_inv_inv:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   106
  assumes pS: "p permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   107
  shows "inv (inv p) = p"
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
   108
  unfolding fun_eq_iff permutes_inv_eq[OF pS] permutes_inv_eq[OF permutes_inv[OF pS]]
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   109
  by blast
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   110
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   111
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   112
subsection {* The number of permutations on a finite set *}
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   113
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   114
lemma permutes_insert_lemma:
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   115
  assumes pS: "p permutes (insert a S)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   116
  shows "Fun.swap a (p a) id \<circ> p permutes S"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   117
  apply (rule permutes_superset[where S = "insert a S"])
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   118
  apply (rule permutes_compose[OF pS])
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   119
  apply (rule permutes_swap_id, simp)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   120
  using permutes_in_image[OF pS, of a]
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   121
  apply simp
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
   122
  apply (auto simp add: Ball_def Fun.swap_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   123
  done
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   124
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   125
lemma permutes_insert: "{p. p permutes (insert a S)} =
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   126
  (\<lambda>(b,p). Fun.swap a b id \<circ> p) ` {(b,p). b \<in> insert a S \<and> p \<in> {p. p permutes S}}"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   127
proof -
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   128
  {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   129
    fix p
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   130
    {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   131
      assume pS: "p permutes insert a S"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   132
      let ?b = "p a"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   133
      let ?q = "Fun.swap a (p a) id \<circ> p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   134
      have th0: "p = Fun.swap a ?b id \<circ> ?q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   135
        unfolding fun_eq_iff o_assoc by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   136
      have th1: "?b \<in> insert a S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   137
        unfolding permutes_in_image[OF pS] by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   138
      from permutes_insert_lemma[OF pS] th0 th1
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   139
      have "\<exists>b q. p = Fun.swap a b id \<circ> q \<and> b \<in> insert a S \<and> q permutes S" by blast
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   140
    }
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   141
    moreover
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   142
    {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   143
      fix b q
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   144
      assume bq: "p = Fun.swap a b id \<circ> q" "b \<in> insert a S" "q permutes S"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   145
      from permutes_subset[OF bq(3), of "insert a S"]
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   146
      have qS: "q permutes insert a S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   147
        by auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   148
      have aS: "a \<in> insert a S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   149
        by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   150
      from bq(1) permutes_compose[OF qS permutes_swap_id[OF aS bq(2)]]
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   151
      have "p permutes insert a S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   152
        by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   153
    }
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   154
    ultimately have "p permutes insert a S \<longleftrightarrow>
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   155
        (\<exists>b q. p = Fun.swap a b id \<circ> q \<and> b \<in> insert a S \<and> q permutes S)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   156
      by blast
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   157
  }
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   158
  then show ?thesis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   159
    by auto
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   160
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   161
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   162
lemma card_permutations:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   163
  assumes Sn: "card S = n"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   164
    and fS: "finite S"
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   165
  shows "card {p. p permutes S} = fact n"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   166
  using fS Sn
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   167
proof (induct arbitrary: n)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   168
  case empty
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   169
  then show ?case by simp
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   170
next
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   171
  case (insert x F)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   172
  {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   173
    fix n
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   174
    assume H0: "card (insert x F) = n"
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   175
    let ?xF = "{p. p permutes insert x F}"
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   176
    let ?pF = "{p. p permutes F}"
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   177
    let ?pF' = "{(b, p). b \<in> insert x F \<and> p \<in> ?pF}"
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   178
    let ?g = "(\<lambda>(b, p). Fun.swap x b id \<circ> p)"
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   179
    from permutes_insert[of x F]
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   180
    have xfgpF': "?xF = ?g ` ?pF'" .
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   181
    have Fs: "card F = n - 1"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   182
      using `x \<notin> F` H0 `finite F` by auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   183
    from insert.hyps Fs have pFs: "card ?pF = fact (n - 1)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   184
      using `finite F` by auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   185
    then have "finite ?pF"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   186
      using fact_gt_zero_nat by (auto intro: card_ge_0_finite)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   187
    then have pF'f: "finite ?pF'"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   188
      using H0 `finite F`
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   189
      apply (simp only: Collect_split Collect_mem_eq)
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   190
      apply (rule finite_cartesian_product)
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   191
      apply simp_all
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   192
      done
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   193
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   194
    have ginj: "inj_on ?g ?pF'"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   195
    proof -
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   196
      {
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   197
        fix b p c q
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   198
        assume bp: "(b,p) \<in> ?pF'"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   199
        assume cq: "(c,q) \<in> ?pF'"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   200
        assume eq: "?g (b,p) = ?g (c,q)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   201
        from bp cq have ths: "b \<in> insert x F" "c \<in> insert x F" "x \<in> insert x F"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   202
          "p permutes F" "q permutes F"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   203
          by auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   204
        from ths(4) `x \<notin> F` eq have "b = ?g (b,p) x"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   205
          unfolding permutes_def
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
   206
          by (auto simp add: Fun.swap_def fun_upd_def fun_eq_iff)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   207
        also have "\<dots> = ?g (c,q) x"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   208
          using ths(5) `x \<notin> F` eq
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
   209
          by (auto simp add: swap_def fun_upd_def fun_eq_iff)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   210
        also have "\<dots> = c"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   211
          using ths(5) `x \<notin> F`
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   212
          unfolding permutes_def
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
   213
          by (auto simp add: Fun.swap_def fun_upd_def fun_eq_iff)
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   214
        finally have bc: "b = c" .
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   215
        then have "Fun.swap x b id = Fun.swap x c id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   216
          by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   217
        with eq have "Fun.swap x b id \<circ> p = Fun.swap x b id \<circ> q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   218
          by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   219
        then have "Fun.swap x b id \<circ> (Fun.swap x b id \<circ> p) =
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   220
          Fun.swap x b id \<circ> (Fun.swap x b id \<circ> q)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   221
          by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   222
        then have "p = q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   223
          by (simp add: o_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   224
        with bc have "(b, p) = (c, q)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   225
          by simp
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   226
      }
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   227
      then show ?thesis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   228
        unfolding inj_on_def by blast
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   229
    qed
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   230
    from `x \<notin> F` H0 have n0: "n \<noteq> 0"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   231
      using `finite F` by auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   232
    then have "\<exists>m. n = Suc m"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   233
      by presburger
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   234
    then obtain m where n[simp]: "n = Suc m"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   235
      by blast
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   236
    from pFs H0 have xFc: "card ?xF = fact n"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   237
      unfolding xfgpF' card_image[OF ginj]
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   238
      using `finite F` `finite ?pF`
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   239
      apply (simp only: Collect_split Collect_mem_eq card_cartesian_product)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   240
      apply simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   241
      done
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   242
    from finite_imageI[OF pF'f, of ?g] have xFf: "finite ?xF"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   243
      unfolding xfgpF' by simp
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   244
    have "card ?xF = fact n"
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   245
      using xFf xFc unfolding xFf by blast
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   246
  }
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   247
  then show ?case
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   248
    using insert by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   249
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   250
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   251
lemma finite_permutations:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   252
  assumes fS: "finite S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   253
  shows "finite {p. p permutes S}"
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   254
  using card_permutations[OF refl fS] fact_gt_zero_nat
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   255
  by (auto intro: card_ge_0_finite)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   256
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   257
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   258
subsection {* Permutations of index set for iterated operations *}
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   259
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   260
lemma (in comm_monoid_set) permute:
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   261
  assumes "p permutes S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   262
  shows "F g S = F (g \<circ> p) S"
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   263
proof -
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   264
  from `p permutes S` have "inj p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   265
    by (rule permutes_inj)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   266
  then have "inj_on p S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   267
    by (auto intro: subset_inj_on)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   268
  then have "F g (p ` S) = F (g \<circ> p) S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   269
    by (rule reindex)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   270
  moreover from `p permutes S` have "p ` S = S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   271
    by (rule permutes_image)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   272
  ultimately show ?thesis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   273
    by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   274
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   275
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   276
lemma setsum_permute:
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   277
  assumes "p permutes S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   278
  shows "setsum f S = setsum (f \<circ> p) S"
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   279
  using assms by (fact setsum.permute)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   280
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   281
lemma setsum_permute_natseg:
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   282
  assumes pS: "p permutes {m .. n}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   283
  shows "setsum f {m .. n} = setsum (f \<circ> p) {m .. n}"
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   284
  using setsum_permute [OF pS, of f ] pS by blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   285
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   286
lemma setprod_permute:
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   287
  assumes "p permutes S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   288
  shows "setprod f S = setprod (f \<circ> p) S"
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   289
  using assms by (fact setprod.permute)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   290
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   291
lemma setprod_permute_natseg:
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   292
  assumes pS: "p permutes {m .. n}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   293
  shows "setprod f {m .. n} = setprod (f \<circ> p) {m .. n}"
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   294
  using setprod_permute [OF pS, of f ] pS by blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   295
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   296
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   297
subsection {* Various combinations of transpositions with 2, 1 and 0 common elements *}
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   298
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   299
lemma swap_id_common:" a \<noteq> c \<Longrightarrow> b \<noteq> c \<Longrightarrow>
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   300
  Fun.swap a b id \<circ> Fun.swap a c id = Fun.swap b c id \<circ> Fun.swap a b id"
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
   301
  by (simp add: fun_eq_iff Fun.swap_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   302
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   303
lemma swap_id_common': "a \<noteq> b \<Longrightarrow> a \<noteq> c \<Longrightarrow>
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   304
  Fun.swap a c id \<circ> Fun.swap b c id = Fun.swap b c id \<circ> Fun.swap a b id"
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
   305
  by (simp add: fun_eq_iff Fun.swap_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   306
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   307
lemma swap_id_independent: "a \<noteq> c \<Longrightarrow> a \<noteq> d \<Longrightarrow> b \<noteq> c \<Longrightarrow> b \<noteq> d \<Longrightarrow>
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   308
  Fun.swap a b id \<circ> Fun.swap c d id = Fun.swap c d id \<circ> Fun.swap a b id"
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
   309
  by (simp add: fun_eq_iff Fun.swap_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   310
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   311
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   312
subsection {* Permutations as transposition sequences *}
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   313
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   314
inductive swapidseq :: "nat \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> bool"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   315
where
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   316
  id[simp]: "swapidseq 0 id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   317
| comp_Suc: "swapidseq n p \<Longrightarrow> a \<noteq> b \<Longrightarrow> swapidseq (Suc n) (Fun.swap a b id \<circ> p)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   318
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   319
declare id[unfolded id_def, simp]
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   320
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   321
definition "permutation p \<longleftrightarrow> (\<exists>n. swapidseq n p)"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   322
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   323
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   324
subsection {* Some closure properties of the set of permutations, with lengths *}
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   325
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   326
lemma permutation_id[simp]: "permutation id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   327
  unfolding permutation_def by (rule exI[where x=0]) simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   328
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   329
declare permutation_id[unfolded id_def, simp]
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   330
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   331
lemma swapidseq_swap: "swapidseq (if a = b then 0 else 1) (Fun.swap a b id)"
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   332
  apply clarsimp
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   333
  using comp_Suc[of 0 id a b]
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   334
  apply simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   335
  done
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   336
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   337
lemma permutation_swap_id: "permutation (Fun.swap a b id)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   338
  apply (cases "a = b")
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   339
  apply simp_all
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   340
  unfolding permutation_def
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   341
  using swapidseq_swap[of a b]
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   342
  apply blast
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   343
  done
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   344
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   345
lemma swapidseq_comp_add: "swapidseq n p \<Longrightarrow> swapidseq m q \<Longrightarrow> swapidseq (n + m) (p \<circ> q)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   346
proof (induct n p arbitrary: m q rule: swapidseq.induct)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   347
  case (id m q)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   348
  then show ?case by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   349
next
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   350
  case (comp_Suc n p a b m q)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   351
  have th: "Suc n + m = Suc (n + m)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   352
    by arith
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   353
  show ?case
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   354
    unfolding th comp_assoc
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   355
    apply (rule swapidseq.comp_Suc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   356
    using comp_Suc.hyps(2)[OF comp_Suc.prems] comp_Suc.hyps(3)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   357
    apply blast+
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   358
    done
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   359
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   360
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   361
lemma permutation_compose: "permutation p \<Longrightarrow> permutation q \<Longrightarrow> permutation (p \<circ> q)"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   362
  unfolding permutation_def using swapidseq_comp_add[of _ p _ q] by metis
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   363
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   364
lemma swapidseq_endswap: "swapidseq n p \<Longrightarrow> a \<noteq> b \<Longrightarrow> swapidseq (Suc n) (p \<circ> Fun.swap a b id)"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   365
  apply (induct n p rule: swapidseq.induct)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   366
  using swapidseq_swap[of a b]
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   367
  apply (auto simp add: comp_assoc intro: swapidseq.comp_Suc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   368
  done
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   369
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   370
lemma swapidseq_inverse_exists: "swapidseq n p \<Longrightarrow> \<exists>q. swapidseq n q \<and> p \<circ> q = id \<and> q \<circ> p = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   371
proof (induct n p rule: swapidseq.induct)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   372
  case id
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   373
  then show ?case
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   374
    by (rule exI[where x=id]) simp
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   375
next
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   376
  case (comp_Suc n p a b)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   377
  from comp_Suc.hyps obtain q where q: "swapidseq n q" "p \<circ> q = id" "q \<circ> p = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   378
    by blast
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   379
  let ?q = "q \<circ> Fun.swap a b id"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   380
  note H = comp_Suc.hyps
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   381
  from swapidseq_swap[of a b] H(3) have th0: "swapidseq 1 (Fun.swap a b id)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   382
    by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   383
  from swapidseq_comp_add[OF q(1) th0] have th1: "swapidseq (Suc n) ?q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   384
    by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   385
  have "Fun.swap a b id \<circ> p \<circ> ?q = Fun.swap a b id \<circ> (p \<circ> q) \<circ> Fun.swap a b id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   386
    by (simp add: o_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   387
  also have "\<dots> = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   388
    by (simp add: q(2))
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   389
  finally have th2: "Fun.swap a b id \<circ> p \<circ> ?q = id" .
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   390
  have "?q \<circ> (Fun.swap a b id \<circ> p) = q \<circ> (Fun.swap a b id \<circ> Fun.swap a b id) \<circ> p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   391
    by (simp only: o_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   392
  then have "?q \<circ> (Fun.swap a b id \<circ> p) = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   393
    by (simp add: q(3))
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   394
  with th1 th2 show ?case
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   395
    by blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   396
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   397
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   398
lemma swapidseq_inverse:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   399
  assumes H: "swapidseq n p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   400
  shows "swapidseq n (inv p)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   401
  using swapidseq_inverse_exists[OF H] inv_unique_comp[of p] by auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   402
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   403
lemma permutation_inverse: "permutation p \<Longrightarrow> permutation (inv p)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   404
  using permutation_def swapidseq_inverse by blast
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   405
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   406
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   407
subsection {* The identity map only has even transposition sequences *}
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   408
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   409
lemma symmetry_lemma:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   410
  assumes "\<And>a b c d. P a b c d \<Longrightarrow> P a b d c"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   411
    and "\<And>a b c d. a \<noteq> b \<Longrightarrow> c \<noteq> d \<Longrightarrow>
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   412
      a = c \<and> b = d \<or> a = c \<and> b \<noteq> d \<or> a \<noteq> c \<and> b = d \<or> a \<noteq> c \<and> a \<noteq> d \<and> b \<noteq> c \<and> b \<noteq> d \<Longrightarrow>
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   413
      P a b c d"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   414
  shows "\<And>a b c d. a \<noteq> b \<longrightarrow> c \<noteq> d \<longrightarrow>  P a b c d"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   415
  using assms by metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   416
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   417
lemma swap_general: "a \<noteq> b \<Longrightarrow> c \<noteq> d \<Longrightarrow>
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   418
  Fun.swap a b id \<circ> Fun.swap c d id = id \<or>
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   419
  (\<exists>x y z. x \<noteq> a \<and> y \<noteq> a \<and> z \<noteq> a \<and> x \<noteq> y \<and>
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   420
    Fun.swap a b id \<circ> Fun.swap c d id = Fun.swap x y id \<circ> Fun.swap a z id)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   421
proof -
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   422
  assume H: "a \<noteq> b" "c \<noteq> d"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   423
  have "a \<noteq> b \<longrightarrow> c \<noteq> d \<longrightarrow>
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   424
    (Fun.swap a b id \<circ> Fun.swap c d id = id \<or>
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   425
      (\<exists>x y z. x \<noteq> a \<and> y \<noteq> a \<and> z \<noteq> a \<and> x \<noteq> y \<and>
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   426
        Fun.swap a b id \<circ> Fun.swap c d id = Fun.swap x y id \<circ> Fun.swap a z id))"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   427
    apply (rule symmetry_lemma[where a=a and b=b and c=c and d=d])
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
   428
    apply (simp_all only: swap_commute)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   429
    apply (case_tac "a = c \<and> b = d")
56608
8e3c848008fa more simp rules for Fun.swap
haftmann
parents: 56545
diff changeset
   430
    apply (clarsimp simp only: swap_commute swap_id_idempotent)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   431
    apply (case_tac "a = c \<and> b \<noteq> d")
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   432
    apply (rule disjI2)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   433
    apply (rule_tac x="b" in exI)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   434
    apply (rule_tac x="d" in exI)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   435
    apply (rule_tac x="b" in exI)
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
   436
    apply (clarsimp simp add: fun_eq_iff Fun.swap_def)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   437
    apply (case_tac "a \<noteq> c \<and> b = d")
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   438
    apply (rule disjI2)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   439
    apply (rule_tac x="c" in exI)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   440
    apply (rule_tac x="d" in exI)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   441
    apply (rule_tac x="c" in exI)
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
   442
    apply (clarsimp simp add: fun_eq_iff Fun.swap_def)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   443
    apply (rule disjI2)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   444
    apply (rule_tac x="c" in exI)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   445
    apply (rule_tac x="d" in exI)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   446
    apply (rule_tac x="b" in exI)
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
   447
    apply (clarsimp simp add: fun_eq_iff Fun.swap_def)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   448
    done
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   449
  with H show ?thesis by metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   450
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   451
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   452
lemma swapidseq_id_iff[simp]: "swapidseq 0 p \<longleftrightarrow> p = id"
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   453
  using swapidseq.cases[of 0 p "p = id"]
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   454
  by auto
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   455
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   456
lemma swapidseq_cases: "swapidseq n p \<longleftrightarrow>
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   457
  n = 0 \<and> p = id \<or> (\<exists>a b q m. n = Suc m \<and> p = Fun.swap a b id \<circ> q \<and> swapidseq m q \<and> a \<noteq> b)"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   458
  apply (rule iffI)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   459
  apply (erule swapidseq.cases[of n p])
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   460
  apply simp
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   461
  apply (rule disjI2)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   462
  apply (rule_tac x= "a" in exI)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   463
  apply (rule_tac x= "b" in exI)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   464
  apply (rule_tac x= "pa" in exI)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   465
  apply (rule_tac x= "na" in exI)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   466
  apply simp
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   467
  apply auto
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   468
  apply (rule comp_Suc, simp_all)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   469
  done
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   470
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   471
lemma fixing_swapidseq_decrease:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   472
  assumes spn: "swapidseq n p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   473
    and ab: "a \<noteq> b"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   474
    and pa: "(Fun.swap a b id \<circ> p) a = a"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   475
  shows "n \<noteq> 0 \<and> swapidseq (n - 1) (Fun.swap a b id \<circ> p)"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   476
  using spn ab pa
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   477
proof (induct n arbitrary: p a b)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   478
  case 0
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   479
  then show ?case
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
   480
    by (auto simp add: Fun.swap_def fun_upd_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   481
next
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   482
  case (Suc n p a b)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   483
  from Suc.prems(1) swapidseq_cases[of "Suc n" p]
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   484
  obtain c d q m where
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   485
    cdqm: "Suc n = Suc m" "p = Fun.swap c d id \<circ> q" "swapidseq m q" "c \<noteq> d" "n = m"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   486
    by auto
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   487
  {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   488
    assume H: "Fun.swap a b id \<circ> Fun.swap c d id = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   489
    have ?case by (simp only: cdqm o_assoc H) (simp add: cdqm)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   490
  }
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   491
  moreover
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   492
  {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   493
    fix x y z
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   494
    assume H: "x \<noteq> a" "y \<noteq> a" "z \<noteq> a" "x \<noteq> y"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   495
      "Fun.swap a b id \<circ> Fun.swap c d id = Fun.swap x y id \<circ> Fun.swap a z id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   496
    from H have az: "a \<noteq> z"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   497
      by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   498
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   499
    {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   500
      fix h
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   501
      have "(Fun.swap x y id \<circ> h) a = a \<longleftrightarrow> h a = a"
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
   502
        using H by (simp add: Fun.swap_def)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   503
    }
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   504
    note th3 = this
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   505
    from cdqm(2) have "Fun.swap a b id \<circ> p = Fun.swap a b id \<circ> (Fun.swap c d id \<circ> q)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   506
      by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   507
    then have "Fun.swap a b id \<circ> p = Fun.swap x y id \<circ> (Fun.swap a z id \<circ> q)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   508
      by (simp add: o_assoc H)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   509
    then have "(Fun.swap a b id \<circ> p) a = (Fun.swap x y id \<circ> (Fun.swap a z id \<circ> q)) a"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   510
      by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   511
    then have "(Fun.swap x y id \<circ> (Fun.swap a z id \<circ> q)) a = a"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   512
      unfolding Suc by metis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   513
    then have th1: "(Fun.swap a z id \<circ> q) a = a"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   514
      unfolding th3 .
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   515
    from Suc.hyps[OF cdqm(3)[ unfolded cdqm(5)[symmetric]] az th1]
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   516
    have th2: "swapidseq (n - 1) (Fun.swap a z id \<circ> q)" "n \<noteq> 0"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   517
      by blast+
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   518
    have th: "Suc n - 1 = Suc (n - 1)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   519
      using th2(2) by auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   520
    have ?case
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   521
      unfolding cdqm(2) H o_assoc th
49739
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 45922
diff changeset
   522
      apply (simp only: Suc_not_Zero simp_thms comp_assoc)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   523
      apply (rule comp_Suc)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   524
      using th2 H
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   525
      apply blast+
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   526
      done
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   527
  }
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   528
  ultimately show ?case
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   529
    using swap_general[OF Suc.prems(2) cdqm(4)] by metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   530
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   531
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   532
lemma swapidseq_identity_even:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   533
  assumes "swapidseq n (id :: 'a \<Rightarrow> 'a)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   534
  shows "even n"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   535
  using `swapidseq n id`
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   536
proof (induct n rule: nat_less_induct)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   537
  fix n
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   538
  assume H: "\<forall>m<n. swapidseq m (id::'a \<Rightarrow> 'a) \<longrightarrow> even m" "swapidseq n (id :: 'a \<Rightarrow> 'a)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   539
  {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   540
    assume "n = 0"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   541
    then have "even n" by presburger
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   542
  }
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   543
  moreover
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   544
  {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   545
    fix a b :: 'a and q m
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   546
    assume h: "n = Suc m" "(id :: 'a \<Rightarrow> 'a) = Fun.swap a b id \<circ> q" "swapidseq m q" "a \<noteq> b"
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   547
    from fixing_swapidseq_decrease[OF h(3,4), unfolded h(2)[symmetric]]
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   548
    have m: "m \<noteq> 0" "swapidseq (m - 1) (id :: 'a \<Rightarrow> 'a)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   549
      by auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   550
    from h m have mn: "m - 1 < n"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   551
      by arith
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   552
    from H(1)[rule_format, OF mn m(2)] h(1) m(1) have "even n"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   553
      by presburger
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   554
  }
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   555
  ultimately show "even n"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   556
    using H(2)[unfolded swapidseq_cases[of n id]] by auto
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   557
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   558
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   559
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   560
subsection {* Therefore we have a welldefined notion of parity *}
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   561
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   562
definition "evenperm p = even (SOME n. swapidseq n p)"
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   563
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   564
lemma swapidseq_even_even:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   565
  assumes m: "swapidseq m p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   566
    and n: "swapidseq n p"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   567
  shows "even m \<longleftrightarrow> even n"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   568
proof -
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   569
  from swapidseq_inverse_exists[OF n]
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   570
  obtain q where q: "swapidseq n q" "p \<circ> q = id" "q \<circ> p = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   571
    by blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   572
  from swapidseq_identity_even[OF swapidseq_comp_add[OF m q(1), unfolded q]]
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   573
  show ?thesis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   574
    by arith
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   575
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   576
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   577
lemma evenperm_unique:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   578
  assumes p: "swapidseq n p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   579
    and n:"even n = b"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   580
  shows "evenperm p = b"
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   581
  unfolding n[symmetric] evenperm_def
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   582
  apply (rule swapidseq_even_even[where p = p])
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   583
  apply (rule someI[where x = n])
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   584
  using p
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   585
  apply blast+
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   586
  done
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   587
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   588
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   589
subsection {* And it has the expected composition properties *}
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   590
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   591
lemma evenperm_id[simp]: "evenperm id = True"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   592
  by (rule evenperm_unique[where n = 0]) simp_all
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   593
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   594
lemma evenperm_swap: "evenperm (Fun.swap a b id) = (a = b)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   595
  by (rule evenperm_unique[where n="if a = b then 0 else 1"]) (simp_all add: swapidseq_swap)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   596
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   597
lemma evenperm_comp:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   598
  assumes p: "permutation p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   599
    and q:"permutation q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   600
  shows "evenperm (p \<circ> q) = (evenperm p = evenperm q)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   601
proof -
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   602
  from p q obtain n m where n: "swapidseq n p" and m: "swapidseq m q"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   603
    unfolding permutation_def by blast
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   604
  note nm =  swapidseq_comp_add[OF n m]
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   605
  have th: "even (n + m) = (even n \<longleftrightarrow> even m)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   606
    by arith
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   607
  from evenperm_unique[OF n refl] evenperm_unique[OF m refl]
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   608
    evenperm_unique[OF nm th]
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   609
  show ?thesis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   610
    by blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   611
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   612
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   613
lemma evenperm_inv:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   614
  assumes p: "permutation p"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   615
  shows "evenperm (inv p) = evenperm p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   616
proof -
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   617
  from p obtain n where n: "swapidseq n p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   618
    unfolding permutation_def by blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   619
  from evenperm_unique[OF swapidseq_inverse[OF n] evenperm_unique[OF n refl, symmetric]]
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   620
  show ?thesis .
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   621
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   622
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   623
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   624
subsection {* A more abstract characterization of permutations *}
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   625
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   626
lemma bij_iff: "bij f \<longleftrightarrow> (\<forall>x. \<exists>!y. f y = x)"
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   627
  unfolding bij_def inj_on_def surj_def
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   628
  apply auto
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   629
  apply metis
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   630
  apply metis
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   631
  done
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   632
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   633
lemma permutation_bijective:
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   634
  assumes p: "permutation p"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   635
  shows "bij p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   636
proof -
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   637
  from p obtain n where n: "swapidseq n p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   638
    unfolding permutation_def by blast
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   639
  from swapidseq_inverse_exists[OF n]
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   640
  obtain q where q: "swapidseq n q" "p \<circ> q = id" "q \<circ> p = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   641
    by blast
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   642
  then show ?thesis unfolding bij_iff
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   643
    apply (auto simp add: fun_eq_iff)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   644
    apply metis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   645
    done
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   646
qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   647
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   648
lemma permutation_finite_support:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   649
  assumes p: "permutation p"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   650
  shows "finite {x. p x \<noteq> x}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   651
proof -
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   652
  from p obtain n where n: "swapidseq n p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   653
    unfolding permutation_def by blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   654
  from n show ?thesis
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   655
  proof (induct n p rule: swapidseq.induct)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   656
    case id
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   657
    then show ?case by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   658
  next
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   659
    case (comp_Suc n p a b)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   660
    let ?S = "insert a (insert b {x. p x \<noteq> x})"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   661
    from comp_Suc.hyps(2) have fS: "finite ?S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   662
      by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   663
    from `a \<noteq> b` have th: "{x. (Fun.swap a b id \<circ> p) x \<noteq> x} \<subseteq> ?S"
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
   664
      by (auto simp add: Fun.swap_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   665
    from finite_subset[OF th fS] show ?case  .
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   666
  qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   667
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   668
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   669
lemma bij_inv_eq_iff: "bij p \<Longrightarrow> x = inv p y \<longleftrightarrow> p x = y"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   670
  using surj_f_inv_f[of p] by (auto simp add: bij_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   671
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   672
lemma bij_swap_comp:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   673
  assumes bp: "bij p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   674
  shows "Fun.swap a b id \<circ> p = Fun.swap (inv p a) (inv p b) p"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   675
  using surj_f_inv_f[OF bij_is_surj[OF bp]]
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
   676
  by (simp add: fun_eq_iff Fun.swap_def bij_inv_eq_iff[OF bp])
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   677
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   678
lemma bij_swap_ompose_bij: "bij p \<Longrightarrow> bij (Fun.swap a b id \<circ> p)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   679
proof -
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   680
  assume H: "bij p"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   681
  show ?thesis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   682
    unfolding bij_swap_comp[OF H] bij_swap_iff
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   683
    using H .
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   684
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   685
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   686
lemma permutation_lemma:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   687
  assumes fS: "finite S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   688
    and p: "bij p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   689
    and pS: "\<forall>x. x\<notin> S \<longrightarrow> p x = x"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   690
  shows "permutation p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   691
  using fS p pS
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   692
proof (induct S arbitrary: p rule: finite_induct)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   693
  case (empty p)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   694
  then show ?case by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   695
next
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   696
  case (insert a F p)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   697
  let ?r = "Fun.swap a (p a) id \<circ> p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   698
  let ?q = "Fun.swap a (p a) id \<circ> ?r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   699
  have raa: "?r a = a"
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
   700
    by (simp add: Fun.swap_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   701
  from bij_swap_ompose_bij[OF insert(4)]
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   702
  have br: "bij ?r"  .
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   703
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   704
  from insert raa have th: "\<forall>x. x \<notin> F \<longrightarrow> ?r x = x"
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
   705
    apply (clarsimp simp add: Fun.swap_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   706
    apply (erule_tac x="x" in allE)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   707
    apply auto
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   708
    unfolding bij_iff
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   709
    apply metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   710
    done
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   711
  from insert(3)[OF br th]
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   712
  have rp: "permutation ?r" .
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   713
  have "permutation ?q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   714
    by (simp add: permutation_compose permutation_swap_id rp)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   715
  then show ?case
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   716
    by (simp add: o_assoc)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   717
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   718
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   719
lemma permutation: "permutation p \<longleftrightarrow> bij p \<and> finite {x. p x \<noteq> x}"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   720
  (is "?lhs \<longleftrightarrow> ?b \<and> ?f")
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   721
proof
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   722
  assume p: ?lhs
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   723
  from p permutation_bijective permutation_finite_support show "?b \<and> ?f"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   724
    by auto
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   725
next
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   726
  assume "?b \<and> ?f"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   727
  then have "?f" "?b" by blast+
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   728
  from permutation_lemma[OF this] show ?lhs
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   729
    by blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   730
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   731
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   732
lemma permutation_inverse_works:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   733
  assumes p: "permutation p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   734
  shows "inv p \<circ> p = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   735
    and "p \<circ> inv p = id"
44227
78e033e8ba05 get Library/Permutations.thy compiled and working again
huffman
parents: 41959
diff changeset
   736
  using permutation_bijective [OF p]
78e033e8ba05 get Library/Permutations.thy compiled and working again
huffman
parents: 41959
diff changeset
   737
  unfolding bij_def inj_iff surj_iff by auto
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   738
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   739
lemma permutation_inverse_compose:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   740
  assumes p: "permutation p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   741
    and q: "permutation q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   742
  shows "inv (p \<circ> q) = inv q \<circ> inv p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   743
proof -
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   744
  note ps = permutation_inverse_works[OF p]
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   745
  note qs = permutation_inverse_works[OF q]
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   746
  have "p \<circ> q \<circ> (inv q \<circ> inv p) = p \<circ> (q \<circ> inv q) \<circ> inv p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   747
    by (simp add: o_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   748
  also have "\<dots> = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   749
    by (simp add: ps qs)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   750
  finally have th0: "p \<circ> q \<circ> (inv q \<circ> inv p) = id" .
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   751
  have "inv q \<circ> inv p \<circ> (p \<circ> q) = inv q \<circ> (inv p \<circ> p) \<circ> q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   752
    by (simp add: o_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   753
  also have "\<dots> = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   754
    by (simp add: ps qs)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   755
  finally have th1: "inv q \<circ> inv p \<circ> (p \<circ> q) = id" .
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   756
  from inv_unique_comp[OF th0 th1] show ?thesis .
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   757
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   758
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   759
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   760
subsection {* Relation to "permutes" *}
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   761
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   762
lemma permutation_permutes: "permutation p \<longleftrightarrow> (\<exists>S. finite S \<and> p permutes S)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   763
  unfolding permutation permutes_def bij_iff[symmetric]
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   764
  apply (rule iffI, clarify)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   765
  apply (rule exI[where x="{x. p x \<noteq> x}"])
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   766
  apply simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   767
  apply clarsimp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   768
  apply (rule_tac B="S" in finite_subset)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   769
  apply auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   770
  done
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   771
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   772
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   773
subsection {* Hence a sort of induction principle composing by swaps *}
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   774
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   775
lemma permutes_induct: "finite S \<Longrightarrow> P id \<Longrightarrow>
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   776
  (\<And> a b p. a \<in> S \<Longrightarrow> b \<in> S \<Longrightarrow> P p \<Longrightarrow> P p \<Longrightarrow> permutation p \<Longrightarrow> P (Fun.swap a b id \<circ> p)) \<Longrightarrow>
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   777
  (\<And>p. p permutes S \<Longrightarrow> P p)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   778
proof (induct S rule: finite_induct)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   779
  case empty
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   780
  then show ?case by auto
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   781
next
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   782
  case (insert x F p)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   783
  let ?r = "Fun.swap x (p x) id \<circ> p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   784
  let ?q = "Fun.swap x (p x) id \<circ> ?r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   785
  have qp: "?q = p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   786
    by (simp add: o_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   787
  from permutes_insert_lemma[OF insert.prems(3)] insert have Pr: "P ?r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   788
    by blast
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   789
  from permutes_in_image[OF insert.prems(3), of x]
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   790
  have pxF: "p x \<in> insert x F"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   791
    by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   792
  have xF: "x \<in> insert x F"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   793
    by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   794
  have rp: "permutation ?r"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   795
    unfolding permutation_permutes using insert.hyps(1)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   796
      permutes_insert_lemma[OF insert.prems(3)]
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   797
    by blast
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   798
  from insert.prems(2)[OF xF pxF Pr Pr rp]
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   799
  show ?case
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   800
    unfolding qp .
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   801
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   802
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   803
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   804
subsection {* Sign of a permutation as a real number *}
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   805
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   806
definition "sign p = (if evenperm p then (1::int) else -1)"
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   807
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   808
lemma sign_nz: "sign p \<noteq> 0"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   809
  by (simp add: sign_def)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   810
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   811
lemma sign_id: "sign id = 1"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   812
  by (simp add: sign_def)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   813
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   814
lemma sign_inverse: "permutation p \<Longrightarrow> sign (inv p) = sign p"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   815
  by (simp add: sign_def evenperm_inv)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   816
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   817
lemma sign_compose: "permutation p \<Longrightarrow> permutation q \<Longrightarrow> sign (p \<circ> q) = sign p * sign q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   818
  by (simp add: sign_def evenperm_comp)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   819
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   820
lemma sign_swap_id: "sign (Fun.swap a b id) = (if a = b then 1 else -1)"
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   821
  by (simp add: sign_def evenperm_swap)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   822
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   823
lemma sign_idempotent: "sign p * sign p = 1"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   824
  by (simp add: sign_def)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   825
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   826
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   827
subsection {* More lemmas about permutations *}
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   828
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   829
lemma permutes_natset_le:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   830
  fixes S :: "'a::wellorder set"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   831
  assumes p: "p permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   832
    and le: "\<forall>i \<in> S. p i \<le> i"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   833
  shows "p = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   834
proof -
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   835
  {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   836
    fix n
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   837
    have "p n = n"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   838
      using p le
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   839
    proof (induct n arbitrary: S rule: less_induct)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   840
      fix n S
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   841
      assume H:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   842
        "\<And>m S. m < n \<Longrightarrow> p permutes S \<Longrightarrow> \<forall>i\<in>S. p i \<le> i \<Longrightarrow> p m = m"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
   843
        "p permutes S" "\<forall>i \<in>S. p i \<le> i"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   844
      {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   845
        assume "n \<notin> S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   846
        with H(2) have "p n = n"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   847
          unfolding permutes_def by metis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   848
      }
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   849
      moreover
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   850
      {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   851
        assume ns: "n \<in> S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   852
        from H(3)  ns have "p n < n \<or> p n = n"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   853
          by auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   854
        moreover {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   855
          assume h: "p n < n"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   856
          from H h have "p (p n) = p n"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   857
            by metis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   858
          with permutes_inj[OF H(2)] have "p n = n"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   859
            unfolding inj_on_def by blast
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   860
          with h have False
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   861
            by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   862
        }
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   863
        ultimately have "p n = n"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   864
          by blast
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   865
      }
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   866
      ultimately show "p n = n"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   867
        by blast
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   868
    qed
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   869
  }
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   870
  then show ?thesis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   871
    by (auto simp add: fun_eq_iff)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   872
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   873
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   874
lemma permutes_natset_ge:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   875
  fixes S :: "'a::wellorder set"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   876
  assumes p: "p permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   877
    and le: "\<forall>i \<in> S. p i \<ge> i"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   878
  shows "p = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   879
proof -
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   880
  {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   881
    fix i
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   882
    assume i: "i \<in> S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   883
    from i permutes_in_image[OF permutes_inv[OF p]] have "inv p i \<in> S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   884
      by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   885
    with le have "p (inv p i) \<ge> inv p i"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   886
      by blast
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   887
    with permutes_inverses[OF p] have "i \<ge> inv p i"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   888
      by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   889
  }
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   890
  then have th: "\<forall>i\<in>S. inv p i \<le> i"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   891
    by blast
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   892
  from permutes_natset_le[OF permutes_inv[OF p] th]
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   893
  have "inv p = inv id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   894
    by simp
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   895
  then show ?thesis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   896
    apply (subst permutes_inv_inv[OF p, symmetric])
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   897
    apply (rule inv_unique_comp)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   898
    apply simp_all
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   899
    done
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   900
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   901
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   902
lemma image_inverse_permutations: "{inv p |p. p permutes S} = {p. p permutes S}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   903
  apply (rule set_eqI)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   904
  apply auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   905
  using permutes_inv_inv permutes_inv
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   906
  apply auto
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   907
  apply (rule_tac x="inv x" in exI)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   908
  apply auto
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   909
  done
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   910
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   911
lemma image_compose_permutations_left:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   912
  assumes q: "q permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   913
  shows "{q \<circ> p | p. p permutes S} = {p . p permutes S}"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   914
  apply (rule set_eqI)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   915
  apply auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   916
  apply (rule permutes_compose)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   917
  using q
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   918
  apply auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   919
  apply (rule_tac x = "inv q \<circ> x" in exI)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   920
  apply (simp add: o_assoc permutes_inv permutes_compose permutes_inv_o)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   921
  done
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   922
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   923
lemma image_compose_permutations_right:
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   924
  assumes q: "q permutes S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   925
  shows "{p \<circ> q | p. p permutes S} = {p . p permutes S}"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   926
  apply (rule set_eqI)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   927
  apply auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   928
  apply (rule permutes_compose)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   929
  using q
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   930
  apply auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   931
  apply (rule_tac x = "x \<circ> inv q" in exI)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   932
  apply (simp add: o_assoc permutes_inv permutes_compose permutes_inv_o comp_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   933
  done
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   934
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   935
lemma permutes_in_seg: "p permutes {1 ..n} \<Longrightarrow> i \<in> {1..n} \<Longrightarrow> 1 \<le> p i \<and> p i \<le> n"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   936
  by (simp add: permutes_def) metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   937
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   938
lemma setsum_permutations_inverse:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   939
  "setsum f {p. p permutes S} = setsum (\<lambda>p. f(inv p)) {p. p permutes S}"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   940
  (is "?lhs = ?rhs")
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   941
proof -
30036
3a074e3a9a18 generalize some lemmas
huffman
parents: 29840
diff changeset
   942
  let ?S = "{p . p permutes S}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   943
  have th0: "inj_on inv ?S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   944
  proof (auto simp add: inj_on_def)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   945
    fix q r
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   946
    assume q: "q permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   947
      and r: "r permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   948
      and qr: "inv q = inv r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   949
    then have "inv (inv q) = inv (inv r)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   950
      by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   951
    with permutes_inv_inv[OF q] permutes_inv_inv[OF r] show "q = r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   952
      by metis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   953
  qed
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   954
  have th1: "inv ` ?S = ?S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   955
    using image_inverse_permutations by blast
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   956
  have th2: "?rhs = setsum (f \<circ> inv) ?S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   957
    by (simp add: o_def)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   958
  from setsum_reindex[OF th0, of f] show ?thesis unfolding th1 th2 .
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   959
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   960
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   961
lemma setum_permutations_compose_left:
30036
3a074e3a9a18 generalize some lemmas
huffman
parents: 29840
diff changeset
   962
  assumes q: "q permutes S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   963
  shows "setsum f {p. p permutes S} = setsum (\<lambda>p. f(q \<circ> p)) {p. p permutes S}"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   964
  (is "?lhs = ?rhs")
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   965
proof -
30036
3a074e3a9a18 generalize some lemmas
huffman
parents: 29840
diff changeset
   966
  let ?S = "{p. p permutes S}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   967
  have th0: "?rhs = setsum (f \<circ> (op \<circ> q)) ?S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   968
    by (simp add: o_def)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   969
  have th1: "inj_on (op \<circ> q) ?S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   970
  proof (auto simp add: inj_on_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   971
    fix p r
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   972
    assume "p permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   973
      and r: "r permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   974
      and rp: "q \<circ> p = q \<circ> r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   975
    then have "inv q \<circ> q \<circ> p = inv q \<circ> q \<circ> r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   976
      by (simp add: comp_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   977
    with permutes_inj[OF q, unfolded inj_iff] show "p = r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   978
      by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   979
  qed
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   980
  have th3: "(op \<circ> q) ` ?S = ?S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   981
    using image_compose_permutations_left[OF q] by auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   982
  from setsum_reindex[OF th1, of f] show ?thesis unfolding th0 th1 th3 .
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   983
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   984
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   985
lemma sum_permutations_compose_right:
30036
3a074e3a9a18 generalize some lemmas
huffman
parents: 29840
diff changeset
   986
  assumes q: "q permutes S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   987
  shows "setsum f {p. p permutes S} = setsum (\<lambda>p. f(p \<circ> q)) {p. p permutes S}"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   988
  (is "?lhs = ?rhs")
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   989
proof -
30036
3a074e3a9a18 generalize some lemmas
huffman
parents: 29840
diff changeset
   990
  let ?S = "{p. p permutes S}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   991
  have th0: "?rhs = setsum (f \<circ> (\<lambda>p. p \<circ> q)) ?S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   992
    by (simp add: o_def)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   993
  have th1: "inj_on (\<lambda>p. p \<circ> q) ?S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   994
  proof (auto simp add: inj_on_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   995
    fix p r
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   996
    assume "p permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   997
      and r: "r permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   998
      and rp: "p \<circ> q = r \<circ> q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   999
    then have "p \<circ> (q \<circ> inv q) = r \<circ> (q \<circ> inv q)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1000
      by (simp add: o_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1001
    with permutes_surj[OF q, unfolded surj_iff] show "p = r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1002
      by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1003
  qed
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1004
  have th3: "(\<lambda>p. p \<circ> q) ` ?S = ?S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1005
    using image_compose_permutations_right[OF q] by auto
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1006
  from setsum_reindex[OF th1, of f]
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1007
  show ?thesis unfolding th0 th1 th3 .
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1008
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1009
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1010
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1011
subsection {* Sum over a set of permutations (could generalize to iteration) *}
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1012
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1013
lemma setsum_over_permutations_insert:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1014
  assumes fS: "finite S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1015
    and aS: "a \<notin> S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1016
  shows "setsum f {p. p permutes (insert a S)} =
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1017
    setsum (\<lambda>b. setsum (\<lambda>q. f (Fun.swap a b id \<circ> q)) {p. p permutes S}) (insert a S)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1018
proof -
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1019
  have th0: "\<And>f a b. (\<lambda>(b,p). f (Fun.swap a b id \<circ> p)) = f \<circ> (\<lambda>(b,p). Fun.swap a b id \<circ> p)"
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
  1020
    by (simp add: fun_eq_iff)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1021
  have th1: "\<And>P Q. P \<times> Q = {(a,b). a \<in> P \<and> b \<in> Q}"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1022
    by blast
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1023
  have th2: "\<And>P Q. P \<Longrightarrow> (P \<Longrightarrow> Q) \<Longrightarrow> P \<and> Q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1024
    by blast
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
  1025
  show ?thesis
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
  1026
    unfolding permutes_insert
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1027
    unfolding setsum_cartesian_product
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56608
diff changeset
  1028
    unfolding th1[symmetric]
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1029
    unfolding th0
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1030
  proof (rule setsum_reindex)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1031
    let ?f = "(\<lambda>(b, y). Fun.swap a b id \<circ> y)"
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1032
    let ?P = "{p. p permutes S}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1033
    {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1034
      fix b c p q
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1035
      assume b: "b \<in> insert a S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1036
      assume c: "c \<in> insert a S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1037
      assume p: "p permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1038
      assume q: "q permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1039
      assume eq: "Fun.swap a b id \<circ> p = Fun.swap a c id \<circ> q"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1040
      from p q aS have pa: "p a = a" and qa: "q a = a"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  1041
        unfolding permutes_def by metis+
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1042
      from eq have "(Fun.swap a b id \<circ> p) a  = (Fun.swap a c id \<circ> q) a"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1043
        by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1044
      then have bc: "b = c"
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 54681
diff changeset
  1045
        by (simp add: permutes_def pa qa o_def fun_upd_def Fun.swap_def id_def
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1046
            cong del: if_weak_cong split: split_if_asm)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1047
      from eq[unfolded bc] have "(\<lambda>p. Fun.swap a c id \<circ> p) (Fun.swap a c id \<circ> p) =
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1048
        (\<lambda>p. Fun.swap a c id \<circ> p) (Fun.swap a c id \<circ> q)" by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1049
      then have "p = q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1050
        unfolding o_assoc swap_id_idempotent
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
  1051
        by (simp add: o_def)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1052
      with bc have "b = c \<and> p = q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1053
        by blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1054
    }
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
  1055
    then show "inj_on ?f (insert a S \<times> ?P)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1056
      unfolding inj_on_def by clarify metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1057
  qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1058
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1059
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1060
end
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
  1061