src/HOL/Combinatorics/Permutations.thy
author wenzelm
Mon, 26 Jun 2023 23:20:32 +0200
changeset 78209 50c5be88ad59
parent 73706 4b1386b2c23e
child 80777 623d46973cbe
permissions -rw-r--r--
tuned signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
73477
1d8a79aa2a99 dedicated session for combinatorial material
haftmann
parents: 73466
diff changeset
     1
(*  Author:     Amine Chaieb, University of Cambridge
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
     2
*)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
     3
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
     4
section \<open>Permutations, both general and specifically on finite sets.\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
     5
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
     6
theory Permutations
73477
1d8a79aa2a99 dedicated session for combinatorial material
haftmann
parents: 73466
diff changeset
     7
  imports
1d8a79aa2a99 dedicated session for combinatorial material
haftmann
parents: 73466
diff changeset
     8
    "HOL-Library.Multiset"
1d8a79aa2a99 dedicated session for combinatorial material
haftmann
parents: 73466
diff changeset
     9
    "HOL-Library.Disjoint_Sets"
73623
5020054b3a16 tuned theory structure
haftmann
parents: 73621
diff changeset
    10
    Transposition
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    11
begin
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    12
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    13
subsection \<open>Auxiliary\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    14
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    15
abbreviation (input) fixpoints :: \<open>('a \<Rightarrow> 'a) \<Rightarrow> 'a set\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    16
  where \<open>fixpoints f \<equiv> {x. f x = x}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    17
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    18
lemma inj_on_fixpoints:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    19
  \<open>inj_on f (fixpoints f)\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    20
  by (rule inj_onI) simp
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    21
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    22
lemma bij_betw_fixpoints:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    23
  \<open>bij_betw f (fixpoints f) (fixpoints f)\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    24
  using inj_on_fixpoints by (auto simp add: bij_betw_def)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    25
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    26
73328
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
    27
subsection \<open>Basic definition and consequences\<close>
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    28
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    29
definition permutes :: \<open>('a \<Rightarrow> 'a) \<Rightarrow> 'a set \<Rightarrow> bool\<close>  (infixr \<open>permutes\<close> 41)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    30
  where \<open>p permutes S \<longleftrightarrow> (\<forall>x. x \<notin> S \<longrightarrow> p x = x) \<and> (\<forall>y. \<exists>!x. p x = y)\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    31
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    32
lemma bij_imp_permutes:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    33
  \<open>p permutes S\<close> if \<open>bij_betw p S S\<close> and stable: \<open>\<And>x. x \<notin> S \<Longrightarrow> p x = x\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    34
proof -
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    35
  note \<open>bij_betw p S S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    36
  moreover have \<open>bij_betw p (- S) (- S)\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    37
    by (auto simp add: stable intro!: bij_betw_imageI inj_onI)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    38
  ultimately have \<open>bij_betw p (S \<union> - S) (S \<union> - S)\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    39
    by (rule bij_betw_combine) simp
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    40
  then have \<open>\<exists>!x. p x = y\<close> for y
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    41
    by (simp add: bij_iff)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    42
  with stable show ?thesis
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    43
    by (simp add: permutes_def)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    44
qed
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
    45
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    46
context
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    47
  fixes p :: \<open>'a \<Rightarrow> 'a\<close> and S :: \<open>'a set\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    48
  assumes perm: \<open>p permutes S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    49
begin
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    50
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    51
lemma permutes_inj:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    52
  \<open>inj p\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    53
  using perm by (auto simp: permutes_def inj_on_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    54
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    55
lemma permutes_image:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    56
  \<open>p ` S = S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    57
proof (rule set_eqI)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    58
  fix x
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    59
  show \<open>x \<in> p ` S \<longleftrightarrow> x \<in> S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    60
  proof
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    61
    assume \<open>x \<in> p ` S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    62
    then obtain y where \<open>y \<in> S\<close> \<open>p y = x\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    63
      by blast
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    64
    with perm show \<open>x \<in> S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    65
      by (cases \<open>y = x\<close>) (auto simp add: permutes_def)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    66
  next
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    67
    assume \<open>x \<in> S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    68
    with perm obtain y where \<open>y \<in> S\<close> \<open>p y = x\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    69
      by (metis permutes_def)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    70
    then show \<open>x \<in> p ` S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    71
      by blast
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    72
  qed
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    73
qed
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    74
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    75
lemma permutes_not_in:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    76
  \<open>x \<notin> S \<Longrightarrow> p x = x\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    77
  using perm by (auto simp: permutes_def)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    78
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    79
lemma permutes_image_complement:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    80
  \<open>p ` (- S) = - S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    81
  by (auto simp add: permutes_not_in)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    82
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    83
lemma permutes_in_image:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    84
  \<open>p x \<in> S \<longleftrightarrow> x \<in> S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    85
  using permutes_image permutes_inj by (auto dest: inj_image_mem_iff)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    86
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    87
lemma permutes_surj:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    88
  \<open>surj p\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    89
proof -
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    90
  have \<open>p ` (S \<union> - S) = p ` S \<union> p ` (- S)\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    91
    by (rule image_Un)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    92
  then show ?thesis
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    93
    by (simp add: permutes_image permutes_image_complement)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    94
qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    95
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    96
lemma permutes_inv_o:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    97
  shows "p \<circ> inv p = id"
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    98
    and "inv p \<circ> p = id"
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    99
  using permutes_inj permutes_surj
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   100
  unfolding inj_iff [symmetric] surj_iff [symmetric] by auto
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   101
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   102
lemma permutes_inverses:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   103
  shows "p (inv p x) = x"
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   104
    and "inv p (p x) = x"
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   105
  using permutes_inv_o [unfolded fun_eq_iff o_def] by auto
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
   106
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   107
lemma permutes_inv_eq:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   108
  \<open>inv p y = x \<longleftrightarrow> p x = y\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   109
  by (auto simp add: permutes_inverses)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   110
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   111
lemma permutes_inj_on:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   112
  \<open>inj_on p A\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   113
  by (rule inj_on_subset [of _ UNIV]) (auto intro: permutes_inj)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   114
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   115
lemma permutes_bij:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   116
  \<open>bij p\<close>
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   117
  unfolding bij_def by (metis permutes_inj permutes_surj)
60601
6e83d94760c4 added lemma
nipkow
parents: 60500
diff changeset
   118
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   119
lemma permutes_imp_bij:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   120
  \<open>bij_betw p S S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   121
  by (simp add: bij_betw_def permutes_image permutes_inj_on)
59474
4475b1a0141d related permutations with bij functions
hoelzl
parents: 58881
diff changeset
   122
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   123
lemma permutes_subset:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   124
  \<open>p permutes T\<close> if \<open>S \<subseteq> T\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   125
proof (rule bij_imp_permutes)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   126
  define R where \<open>R = T - S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   127
  with that have \<open>T = R \<union> S\<close> \<open>R \<inter> S = {}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   128
    by auto
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   129
  then have \<open>p x = x\<close> if \<open>x \<in> R\<close> for x
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   130
    using that by (auto intro: permutes_not_in)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   131
  then have \<open>p ` R = R\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   132
    by simp
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   133
  with \<open>T = R \<union> S\<close> show \<open>bij_betw p T T\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   134
    by (simp add: bij_betw_def permutes_inj_on image_Un permutes_image)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   135
  fix x
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   136
  assume \<open>x \<notin> T\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   137
  with \<open>T = R \<union> S\<close> show \<open>p x = x\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   138
    by (simp add: permutes_not_in)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   139
qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   140
73410
haftmann
parents: 73328
diff changeset
   141
lemma permutes_imp_permutes_insert:
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   142
  \<open>p permutes insert x S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   143
  by (rule permutes_subset) auto
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   144
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   145
end
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   146
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   147
lemma permutes_id [simp]:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   148
  \<open>id permutes S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   149
  by (auto intro: bij_imp_permutes)
73410
haftmann
parents: 73328
diff changeset
   150
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   151
lemma permutes_empty [simp]:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   152
  \<open>p permutes {} \<longleftrightarrow> p = id\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   153
proof
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   154
  assume \<open>p permutes {}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   155
  then show \<open>p = id\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   156
    by (auto simp add: fun_eq_iff permutes_not_in)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   157
next
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   158
  assume \<open>p = id\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   159
  then show \<open>p permutes {}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   160
    by simp
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   161
qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   162
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   163
lemma permutes_sing [simp]:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   164
  \<open>p permutes {a} \<longleftrightarrow> p = id\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   165
proof
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   166
  assume perm: \<open>p permutes {a}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   167
  show \<open>p = id\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   168
  proof
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   169
    fix x
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   170
    from perm have \<open>p ` {a} = {a}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   171
      by (rule permutes_image)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   172
    with perm show \<open>p x = id x\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   173
      by (cases \<open>x = a\<close>) (auto simp add: permutes_not_in)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   174
  qed
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   175
next
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   176
  assume \<open>p = id\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   177
  then show \<open>p permutes {a}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   178
    by simp
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   179
qed
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   180
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   181
lemma permutes_univ: "p permutes UNIV \<longleftrightarrow> (\<forall>y. \<exists>!x. p x = y)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   182
  by (simp add: permutes_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   183
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   184
lemma permutes_swap_id: "a \<in> S \<Longrightarrow> b \<in> S \<Longrightarrow> transpose a b permutes S"
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   185
  by (rule bij_imp_permutes) (auto intro: transpose_apply_other)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   186
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   187
lemma permutes_superset:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   188
  \<open>p permutes T\<close> if \<open>p permutes S\<close> \<open>\<And>x. x \<in> S - T \<Longrightarrow> p x = x\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   189
proof -
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   190
  define R U where \<open>R = T \<inter> S\<close> and \<open>U = S - T\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   191
  then have \<open>T = R \<union> (T - S)\<close> \<open>S = R \<union> U\<close> \<open>R \<inter> U = {}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   192
    by auto
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   193
  from that \<open>U = S - T\<close> have \<open>p ` U = U\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   194
    by simp
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   195
  from \<open>p permutes S\<close> have \<open>bij_betw p (R \<union> U) (R \<union> U)\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   196
    by (simp add: permutes_imp_bij \<open>S = R \<union> U\<close>)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   197
  moreover have \<open>bij_betw p U U\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   198
    using that \<open>U = S - T\<close> by (simp add: bij_betw_def permutes_inj_on)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   199
  ultimately have \<open>bij_betw p R R\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   200
    using \<open>R \<inter> U = {}\<close> \<open>R \<inter> U = {}\<close> by (rule bij_betw_partition)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   201
  then have \<open>p permutes R\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   202
  proof (rule bij_imp_permutes)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   203
    fix x
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   204
    assume \<open>x \<notin> R\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   205
    with \<open>R = T \<inter> S\<close> \<open>p permutes S\<close> show \<open>p x = x\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   206
      by (cases \<open>x \<in> S\<close>) (auto simp add: permutes_not_in that(2))
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   207
  qed
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   208
  then have \<open>p permutes R \<union> (T - S)\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   209
    by (rule permutes_subset) simp
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   210
  with \<open>T = R \<union> (T - S)\<close> show ?thesis
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   211
    by simp
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   212
qed
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   213
69895
6b03a8cf092d more formal contributors (with the help of the history);
wenzelm
parents: 67673
diff changeset
   214
lemma permutes_bij_inv_into: \<^marker>\<open>contributor \<open>Lukas Bulwahn\<close>\<close>
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   215
  fixes A :: "'a set"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   216
    and B :: "'b set"
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   217
  assumes "p permutes A"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   218
    and "bij_betw f A B"
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   219
  shows "(\<lambda>x. if x \<in> B then f (p (inv_into A f x)) else x) permutes B"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   220
proof (rule bij_imp_permutes)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   221
  from assms have "bij_betw p A A" "bij_betw f A B" "bij_betw (inv_into A f) B A"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   222
    by (auto simp add: permutes_imp_bij bij_betw_inv_into)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   223
  then have "bij_betw (f \<circ> p \<circ> inv_into A f) B B"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   224
    by (simp add: bij_betw_trans)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   225
  then show "bij_betw (\<lambda>x. if x \<in> B then f (p (inv_into A f x)) else x) B B"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   226
    by (subst bij_betw_cong[where g="f \<circ> p \<circ> inv_into A f"]) auto
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   227
next
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   228
  fix x
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   229
  assume "x \<notin> B"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   230
  then show "(if x \<in> B then f (p (inv_into A f x)) else x) = x" by auto
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   231
qed
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   232
69895
6b03a8cf092d more formal contributors (with the help of the history);
wenzelm
parents: 67673
diff changeset
   233
lemma permutes_image_mset: \<^marker>\<open>contributor \<open>Lukas Bulwahn\<close>\<close>
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   234
  assumes "p permutes A"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   235
  shows "image_mset p (mset_set A) = mset_set A"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   236
  using assms by (metis image_mset_mset_set bij_betw_imp_inj_on permutes_imp_bij permutes_image)
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   237
69895
6b03a8cf092d more formal contributors (with the help of the history);
wenzelm
parents: 67673
diff changeset
   238
lemma permutes_implies_image_mset_eq: \<^marker>\<open>contributor \<open>Lukas Bulwahn\<close>\<close>
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   239
  assumes "p permutes A" "\<And>x. x \<in> A \<Longrightarrow> f x = f' (p x)"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   240
  shows "image_mset f' (mset_set A) = image_mset f (mset_set A)"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   241
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   242
  have "f x = f' (p x)" if "x \<in># mset_set A" for x
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   243
    using assms(2)[of x] that by (cases "finite A") auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   244
  with assms have "image_mset f (mset_set A) = image_mset (f' \<circ> p) (mset_set A)"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   245
    by (auto intro!: image_mset_cong)
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   246
  also have "\<dots> = image_mset f' (image_mset p (mset_set A))"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   247
    by (simp add: image_mset.compositionality)
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   248
  also have "\<dots> = image_mset f' (mset_set A)"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   249
  proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   250
    from assms permutes_image_mset have "image_mset p (mset_set A) = mset_set A"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   251
      by blast
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   252
    then show ?thesis by simp
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   253
  qed
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   254
  finally show ?thesis ..
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   255
qed
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   256
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   257
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   258
subsection \<open>Group properties\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   259
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   260
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
   261
  unfolding permutes_def o_def by metis
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   262
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   263
lemma permutes_inv:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   264
  assumes "p permutes S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   265
  shows "inv p permutes S"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   266
  using assms unfolding permutes_def permutes_inv_eq[OF assms] by metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   267
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   268
lemma permutes_inv_inv:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   269
  assumes "p permutes S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   270
  shows "inv (inv p) = p"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   271
  unfolding fun_eq_iff permutes_inv_eq[OF assms] permutes_inv_eq[OF permutes_inv[OF assms]]
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   272
  by blast
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   273
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
   274
lemma permutes_invI:
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
   275
  assumes perm: "p permutes S"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   276
    and inv: "\<And>x. x \<in> S \<Longrightarrow> p' (p x) = x"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   277
    and outside: "\<And>x. x \<notin> S \<Longrightarrow> p' x = x"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   278
  shows "inv p = p'"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
   279
proof
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   280
  show "inv p x = p' x" for x
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
   281
  proof (cases "x \<in> S")
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   282
    case True
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   283
    from assms have "p' x = p' (p (inv p x))"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   284
      by (simp add: permutes_inverses)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   285
    also from permutes_inv[OF perm] True have "\<dots> = inv p x"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   286
      by (subst inv) (simp_all add: permutes_in_image)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   287
    finally show ?thesis ..
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   288
  next
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   289
    case False
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   290
    with permutes_inv[OF perm] show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   291
      by (simp_all add: outside permutes_not_in)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   292
  qed
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
   293
qed
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
   294
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
   295
lemma permutes_vimage: "f permutes A \<Longrightarrow> f -` A = A"
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
   296
  by (simp add: bij_vimage_eq_inv_image permutes_bij permutes_image[OF permutes_inv])
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
   297
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   298
66486
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   299
subsection \<open>Mapping permutations with bijections\<close>
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   300
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   301
lemma bij_betw_permutations:
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   302
  assumes "bij_betw f A B"
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   303
  shows   "bij_betw (\<lambda>\<pi> x. if x \<in> B then f (\<pi> (inv_into A f x)) else x) 
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   304
             {\<pi>. \<pi> permutes A} {\<pi>. \<pi> permutes B}" (is "bij_betw ?f _ _")
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   305
proof -
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   306
  let ?g = "(\<lambda>\<pi> x. if x \<in> A then inv_into A f (\<pi> (f x)) else x)"
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   307
  show ?thesis
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   308
  proof (rule bij_betw_byWitness [of _ ?g], goal_cases)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   309
    case 3
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   310
    show ?case using permutes_bij_inv_into[OF _ assms] by auto
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   311
  next
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   312
    case 4
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   313
    have bij_inv: "bij_betw (inv_into A f) B A" by (intro bij_betw_inv_into assms)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   314
    {
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   315
      fix \<pi> assume "\<pi> permutes B"
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   316
      from permutes_bij_inv_into[OF this bij_inv] and assms
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   317
        have "(\<lambda>x. if x \<in> A then inv_into A f (\<pi> (f x)) else x) permutes A"
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   318
        by (simp add: inv_into_inv_into_eq cong: if_cong)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   319
    }
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   320
    from this show ?case by (auto simp: permutes_inv)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   321
  next
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   322
    case 1
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   323
    thus ?case using assms
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   324
      by (auto simp: fun_eq_iff permutes_not_in permutes_in_image bij_betw_inv_into_left
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   325
               dest: bij_betwE)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   326
  next
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   327
    case 2
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   328
    moreover have "bij_betw (inv_into A f) B A"
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   329
      by (intro bij_betw_inv_into assms)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   330
    ultimately show ?case using assms
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   331
      by (auto simp: fun_eq_iff permutes_not_in permutes_in_image bij_betw_inv_into_right 
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   332
               dest: bij_betwE)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   333
  qed
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   334
qed
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   335
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   336
lemma bij_betw_derangements:
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   337
  assumes "bij_betw f A B"
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   338
  shows   "bij_betw (\<lambda>\<pi> x. if x \<in> B then f (\<pi> (inv_into A f x)) else x) 
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   339
             {\<pi>. \<pi> permutes A \<and> (\<forall>x\<in>A. \<pi> x \<noteq> x)} {\<pi>. \<pi> permutes B \<and> (\<forall>x\<in>B. \<pi> x \<noteq> x)}" 
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   340
           (is "bij_betw ?f _ _")
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   341
proof -
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   342
  let ?g = "(\<lambda>\<pi> x. if x \<in> A then inv_into A f (\<pi> (f x)) else x)"
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   343
  show ?thesis
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   344
  proof (rule bij_betw_byWitness [of _ ?g], goal_cases)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   345
    case 3
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   346
    have "?f \<pi> x \<noteq> x" if "\<pi> permutes A" "\<And>x. x \<in> A \<Longrightarrow> \<pi> x \<noteq> x" "x \<in> B" for \<pi> x
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   347
      using that and assms by (metis bij_betwE bij_betw_imp_inj_on bij_betw_imp_surj_on
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   348
                                     inv_into_f_f inv_into_into permutes_imp_bij)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   349
    with permutes_bij_inv_into[OF _ assms] show ?case by auto
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   350
  next
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   351
    case 4
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   352
    have bij_inv: "bij_betw (inv_into A f) B A" by (intro bij_betw_inv_into assms)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   353
    have "?g \<pi> permutes A" if "\<pi> permutes B" for \<pi>
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   354
      using permutes_bij_inv_into[OF that bij_inv] and assms
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   355
      by (simp add: inv_into_inv_into_eq cong: if_cong)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   356
    moreover have "?g \<pi> x \<noteq> x" if "\<pi> permutes B" "\<And>x. x \<in> B \<Longrightarrow> \<pi> x \<noteq> x" "x \<in> A" for \<pi> x
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   357
      using that and assms by (metis bij_betwE bij_betw_imp_surj_on f_inv_into_f permutes_imp_bij)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   358
    ultimately show ?case by auto
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   359
  next
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   360
    case 1
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   361
    thus ?case using assms
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   362
      by (force simp: fun_eq_iff permutes_not_in permutes_in_image bij_betw_inv_into_left
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   363
                dest: bij_betwE)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   364
  next
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   365
    case 2
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   366
    moreover have "bij_betw (inv_into A f) B A"
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   367
      by (intro bij_betw_inv_into assms)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   368
    ultimately show ?case using assms
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   369
      by (force simp: fun_eq_iff permutes_not_in permutes_in_image bij_betw_inv_into_right 
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   370
                dest: bij_betwE)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   371
  qed
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   372
qed
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   373
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   374
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   375
subsection \<open>The number of permutations on a finite set\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   376
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   377
lemma permutes_insert_lemma:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   378
  assumes "p permutes (insert a S)"
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   379
  shows "transpose a (p a) \<circ> p permutes S"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   380
  apply (rule permutes_superset[where S = "insert a S"])
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   381
  apply (rule permutes_compose[OF assms])
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   382
  apply (rule permutes_swap_id, simp)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   383
  using permutes_in_image[OF assms, of a]
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   384
  apply simp
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   385
  apply (auto simp add: Ball_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   386
  done
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   387
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   388
lemma permutes_insert: "{p. p permutes (insert a S)} =
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   389
  (\<lambda>(b, p). transpose a b \<circ> p) ` {(b, p). b \<in> insert a S \<and> p \<in> {p. p permutes S}}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   390
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   391
  have "p permutes insert a S \<longleftrightarrow>
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   392
    (\<exists>b q. p = transpose a b \<circ> q \<and> b \<in> insert a S \<and> q permutes S)" for p
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   393
  proof -
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   394
    have "\<exists>b q. p = transpose a b \<circ> q \<and> b \<in> insert a S \<and> q permutes S"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   395
      if p: "p permutes insert a S"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   396
    proof -
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   397
      let ?b = "p a"
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   398
      let ?q = "transpose a (p a) \<circ> p"
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   399
      have *: "p = transpose a ?b \<circ> ?q"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   400
        by (simp add: fun_eq_iff o_assoc)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   401
      have **: "?b \<in> insert a S"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   402
        unfolding permutes_in_image[OF p] by simp
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   403
      from permutes_insert_lemma[OF p] * ** show ?thesis
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   404
        by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   405
    qed
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   406
    moreover have "p permutes insert a S"
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   407
      if bq: "p = transpose a b \<circ> q" "b \<in> insert a S" "q permutes S" for b q
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   408
    proof -
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   409
      from permutes_subset[OF bq(3), of "insert a S"] have q: "q permutes insert a S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   410
        by auto
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   411
      have a: "a \<in> insert a S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   412
        by simp
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   413
      from bq(1) permutes_compose[OF q permutes_swap_id[OF a bq(2)]] show ?thesis
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   414
        by simp
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   415
    qed
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   416
    ultimately show ?thesis by blast
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   417
  qed
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   418
  then show ?thesis by auto
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   419
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   420
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   421
lemma card_permutations:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   422
  assumes "card S = n"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   423
    and "finite S"
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   424
  shows "card {p. p permutes S} = fact n"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   425
  using assms(2,1)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   426
proof (induct arbitrary: n)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   427
  case empty
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   428
  then show ?case by simp
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   429
next
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   430
  case (insert x F)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   431
  {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   432
    fix n
72304
6fdeef6d6335 reverted the substitution here
paulson <lp15@cam.ac.uk>
parents: 72302
diff changeset
   433
    assume card_insert: "card (insert x F) = n"
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   434
    let ?xF = "{p. p permutes insert x F}"
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   435
    let ?pF = "{p. p permutes F}"
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   436
    let ?pF' = "{(b, p). b \<in> insert x F \<and> p \<in> ?pF}"
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   437
    let ?g = "(\<lambda>(b, p). transpose x b \<circ> p)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   438
    have xfgpF': "?xF = ?g ` ?pF'"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   439
      by (rule permutes_insert[of x F])
72304
6fdeef6d6335 reverted the substitution here
paulson <lp15@cam.ac.uk>
parents: 72302
diff changeset
   440
    from \<open>x \<notin> F\<close> \<open>finite F\<close> card_insert have Fs: "card F = n - 1"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   441
      by auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   442
    from \<open>finite F\<close> insert.hyps Fs have pFs: "card ?pF = fact (n - 1)"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   443
      by auto
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   444
    then have "finite ?pF"
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   445
      by (auto intro: card_ge_0_finite)
72302
d7d90ed4c74e fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents: 69895
diff changeset
   446
    with \<open>finite F\<close> card.insert_remove have pF'f: "finite ?pF'"
61424
c3658c18b7bc prod_case as canonical name for product type eliminator
haftmann
parents: 60601
diff changeset
   447
      apply (simp only: Collect_case_prod Collect_mem_eq)
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   448
      apply (rule finite_cartesian_product)
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   449
      apply simp_all
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   450
      done
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   451
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   452
    have ginj: "inj_on ?g ?pF'"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   453
    proof -
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   454
      {
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   455
        fix b p c q
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   456
        assume bp: "(b, p) \<in> ?pF'"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   457
        assume cq: "(c, q) \<in> ?pF'"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   458
        assume eq: "?g (b, p) = ?g (c, q)"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   459
        from bp cq have pF: "p permutes F" and qF: "q permutes F"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   460
          by auto
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   461
        from pF \<open>x \<notin> F\<close> eq have "b = ?g (b, p) x"
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   462
          by (auto simp: permutes_def fun_upd_def fun_eq_iff)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   463
        also from qF \<open>x \<notin> F\<close> eq have "\<dots> = ?g (c, q) x"
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   464
          by (auto simp: fun_upd_def fun_eq_iff)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   465
        also from qF \<open>x \<notin> F\<close> have "\<dots> = c"
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   466
          by (auto simp: permutes_def fun_upd_def fun_eq_iff)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   467
        finally have "b = c" .
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   468
        then have "transpose x b = transpose x c"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   469
          by simp
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   470
        with eq have "transpose x b \<circ> p = transpose x b \<circ> q"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   471
          by simp
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   472
        then have "transpose x b \<circ> (transpose x b \<circ> p) = transpose x b \<circ> (transpose x b \<circ> q)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   473
          by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   474
        then have "p = q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   475
          by (simp add: o_assoc)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   476
        with \<open>b = c\<close> have "(b, p) = (c, q)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   477
          by simp
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   478
      }
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   479
      then show ?thesis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   480
        unfolding inj_on_def by blast
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   481
    qed
72304
6fdeef6d6335 reverted the substitution here
paulson <lp15@cam.ac.uk>
parents: 72302
diff changeset
   482
    from \<open>x \<notin> F\<close> \<open>finite F\<close> card_insert have "n \<noteq> 0"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   483
      by auto
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   484
    then have "\<exists>m. n = Suc m"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   485
      by presburger
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   486
    then obtain m where n: "n = Suc m"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   487
      by blast
72304
6fdeef6d6335 reverted the substitution here
paulson <lp15@cam.ac.uk>
parents: 72302
diff changeset
   488
    from pFs card_insert have *: "card ?xF = fact n"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   489
      unfolding xfgpF' card_image[OF ginj]
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   490
      using \<open>finite F\<close> \<open>finite ?pF\<close>
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   491
      by (simp only: Collect_case_prod Collect_mem_eq card_cartesian_product) (simp add: n)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   492
    from finite_imageI[OF pF'f, of ?g] have xFf: "finite ?xF"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   493
      by (simp add: xfgpF' n)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   494
    from * have "card ?xF = fact n"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   495
      unfolding xFf by blast
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   496
  }
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   497
  with insert show ?case by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   498
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   499
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   500
lemma finite_permutations:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   501
  assumes "finite S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   502
  shows "finite {p. p permutes S}"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   503
  using card_permutations[OF refl assms] by (auto intro: card_ge_0_finite)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   504
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   505
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   506
subsection \<open>Hence a sort of induction principle composing by swaps\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   507
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   508
lemma permutes_induct [consumes 2, case_names id swap]:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   509
  \<open>P p\<close> if \<open>p permutes S\<close> \<open>finite S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   510
  and id: \<open>P id\<close>
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   511
  and swap: \<open>\<And>a b p. a \<in> S \<Longrightarrow> b \<in> S \<Longrightarrow> p permutes S \<Longrightarrow> P p \<Longrightarrow> P (transpose a b \<circ> p)\<close>
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   512
using \<open>finite S\<close> \<open>p permutes S\<close> swap proof (induction S arbitrary: p)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   513
  case empty
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   514
  with id show ?case
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   515
    by (simp only: permutes_empty)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   516
next
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   517
  case (insert x S p)
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   518
  define q where \<open>q = transpose x (p x) \<circ> p\<close>
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   519
  then have swap_q: \<open>transpose x (p x) \<circ> q = p\<close>
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   520
    by (simp add: o_assoc)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   521
  from \<open>p permutes insert x S\<close> have \<open>q permutes S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   522
    by (simp add: q_def permutes_insert_lemma)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   523
  then have \<open>q permutes insert x S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   524
    by (simp add: permutes_imp_permutes_insert)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   525
  from \<open>q permutes S\<close> have \<open>P q\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   526
    by (auto intro: insert.IH insert.prems(2) permutes_imp_permutes_insert)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   527
  have \<open>x \<in> insert x S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   528
    by simp
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   529
  moreover from \<open>p permutes insert x S\<close> have \<open>p x \<in> insert x S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   530
    using permutes_in_image [of p \<open>insert x S\<close> x] by simp
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   531
  ultimately have \<open>P (transpose x (p x) \<circ> q)\<close>
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   532
    using \<open>q permutes insert x S\<close> \<open>P q\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   533
    by (rule insert.prems(2))
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   534
  then show ?case
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   535
    by (simp add: swap_q)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   536
qed
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   537
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   538
lemma permutes_rev_induct [consumes 2, case_names id swap]:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   539
  \<open>P p\<close> if \<open>p permutes S\<close> \<open>finite S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   540
  and id': \<open>P id\<close>
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   541
  and swap': \<open>\<And>a b p. a \<in> S \<Longrightarrow> b \<in> S \<Longrightarrow> p permutes S \<Longrightarrow> P p \<Longrightarrow> P (p \<circ> transpose a b)\<close>
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   542
using \<open>p permutes S\<close> \<open>finite S\<close> proof (induction rule: permutes_induct)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   543
  case id
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   544
  from id' show ?case .
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   545
next
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   546
  case (swap a b p)
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   547
  then have \<open>bij p\<close>
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   548
    using permutes_bij by blast
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   549
  have \<open>P (p \<circ> transpose (inv p a) (inv p b))\<close>
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   550
    by (rule swap') (auto simp add: swap permutes_in_image permutes_inv)
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   551
  also have \<open>p \<circ> transpose (inv p a) (inv p b) = transpose a b \<circ> p\<close>
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   552
    using \<open>bij p\<close> by (rule transpose_comp_eq [symmetric])
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   553
  finally show ?case .
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   554
qed
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   555
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   556
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   557
subsection \<open>Permutations of index set for iterated operations\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   558
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   559
lemma (in comm_monoid_set) permute:
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   560
  assumes "p permutes S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   561
  shows "F g S = F (g \<circ> p) S"
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   562
proof -
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   563
  from \<open>p permutes S\<close> have "inj p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   564
    by (rule permutes_inj)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   565
  then have "inj_on p S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   566
    by (auto intro: subset_inj_on)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   567
  then have "F g (p ` S) = F (g \<circ> p) S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   568
    by (rule reindex)
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   569
  moreover from \<open>p permutes S\<close> have "p ` S = S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   570
    by (rule permutes_image)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   571
  ultimately show ?thesis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   572
    by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   573
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   574
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   575
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   576
subsection \<open>Permutations as transposition sequences\<close>
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   577
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   578
inductive swapidseq :: "nat \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> bool"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   579
  where
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   580
    id[simp]: "swapidseq 0 id"
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   581
  | comp_Suc: "swapidseq n p \<Longrightarrow> a \<noteq> b \<Longrightarrow> swapidseq (Suc n) (transpose a b \<circ> p)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   582
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   583
declare id[unfolded id_def, simp]
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   584
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   585
definition "permutation p \<longleftrightarrow> (\<exists>n. swapidseq n p)"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   586
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   587
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   588
subsection \<open>Some closure properties of the set of permutations, with lengths\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   589
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   590
lemma permutation_id[simp]: "permutation id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   591
  unfolding permutation_def by (rule exI[where x=0]) simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   592
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   593
declare permutation_id[unfolded id_def, simp]
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   594
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   595
lemma swapidseq_swap: "swapidseq (if a = b then 0 else 1) (transpose a b)"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   596
  apply clarsimp
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   597
  using comp_Suc[of 0 id a b]
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   598
  apply simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   599
  done
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   600
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   601
lemma permutation_swap_id: "permutation (transpose a b)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   602
proof (cases "a = b")
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   603
  case True
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   604
  then show ?thesis by simp
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   605
next
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   606
  case False
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   607
  then show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   608
    unfolding permutation_def
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   609
    using swapidseq_swap[of a b] by blast
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   610
qed
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   611
29840
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 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
   614
proof (induct n p arbitrary: m q rule: swapidseq.induct)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   615
  case (id m q)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   616
  then show ?case by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   617
next
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   618
  case (comp_Suc n p a b m q)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   619
  have eq: "Suc n + m = Suc (n + m)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   620
    by arith
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   621
  show ?case
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   622
    apply (simp only: eq comp_assoc)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   623
    apply (rule swapidseq.comp_Suc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   624
    using comp_Suc.hyps(2)[OF comp_Suc.prems] comp_Suc.hyps(3)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   625
     apply blast+
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   626
    done
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   627
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   628
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   629
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
   630
  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
   631
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   632
lemma swapidseq_endswap: "swapidseq n p \<Longrightarrow> a \<noteq> b \<Longrightarrow> swapidseq (Suc n) (p \<circ> transpose a b)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   633
  by (induct n p rule: swapidseq.induct)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   634
    (use swapidseq_swap[of a b] in \<open>auto simp add: comp_assoc intro: swapidseq.comp_Suc\<close>)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   635
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   636
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
   637
proof (induct n p rule: swapidseq.induct)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   638
  case id
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   639
  then show ?case
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   640
    by (rule exI[where x=id]) simp
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   641
next
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   642
  case (comp_Suc n p a b)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   643
  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
   644
    by blast
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   645
  let ?q = "q \<circ> transpose a b"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   646
  note H = comp_Suc.hyps
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   647
  from swapidseq_swap[of a b] H(3) have *: "swapidseq 1 (transpose a b)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   648
    by simp
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   649
  from swapidseq_comp_add[OF q(1) *] have **: "swapidseq (Suc n) ?q"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   650
    by simp
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   651
  have "transpose a b \<circ> p \<circ> ?q = transpose a b \<circ> (p \<circ> q) \<circ> transpose a b"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   652
    by (simp add: o_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   653
  also have "\<dots> = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   654
    by (simp add: q(2))
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   655
  finally have ***: "transpose a b \<circ> p \<circ> ?q = id" .
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   656
  have "?q \<circ> (transpose a b \<circ> p) = q \<circ> (transpose a b \<circ> transpose a b) \<circ> p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   657
    by (simp only: o_assoc)
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   658
  then have "?q \<circ> (transpose a b \<circ> p) = id"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   659
    by (simp add: q(3))
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   660
  with ** *** show ?case
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   661
    by blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   662
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   663
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   664
lemma swapidseq_inverse:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   665
  assumes "swapidseq n p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   666
  shows "swapidseq n (inv p)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   667
  using swapidseq_inverse_exists[OF assms] inv_unique_comp[of p] by auto
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   668
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   669
lemma permutation_inverse: "permutation p \<Longrightarrow> permutation (inv p)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   670
  using permutation_def swapidseq_inverse by blast
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   671
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   672
73328
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   673
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   674
subsection \<open>Various combinations of transpositions with 2, 1 and 0 common elements\<close>
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   675
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   676
lemma swap_id_common:" a \<noteq> c \<Longrightarrow> b \<noteq> c \<Longrightarrow>
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   677
  transpose a b \<circ> transpose a c = transpose b c \<circ> transpose a b"
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   678
  by (simp add: fun_eq_iff transpose_def)
73328
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   679
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   680
lemma swap_id_common': "a \<noteq> b \<Longrightarrow> a \<noteq> c \<Longrightarrow>
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   681
  transpose a c \<circ> transpose b c = transpose b c \<circ> transpose a b"
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   682
  by (simp add: fun_eq_iff transpose_def)
73328
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   683
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   684
lemma swap_id_independent: "a \<noteq> c \<Longrightarrow> a \<noteq> d \<Longrightarrow> b \<noteq> c \<Longrightarrow> b \<noteq> d \<Longrightarrow>
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   685
  transpose a b \<circ> transpose c d = transpose c d \<circ> transpose a b"
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   686
  by (simp add: fun_eq_iff transpose_def)
73328
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   687
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   688
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   689
subsection \<open>The identity map only has even transposition sequences\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   690
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   691
lemma symmetry_lemma:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   692
  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
   693
    and "\<And>a b c d. a \<noteq> b \<Longrightarrow> c \<noteq> d \<Longrightarrow>
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   694
      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
   695
      P a b c d"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   696
  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
   697
  using assms by metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   698
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   699
lemma swap_general: "a \<noteq> b \<Longrightarrow> c \<noteq> d \<Longrightarrow>
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   700
  transpose a b \<circ> transpose c d = id \<or>
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   701
  (\<exists>x y z. x \<noteq> a \<and> y \<noteq> a \<and> z \<noteq> a \<and> x \<noteq> y \<and>
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   702
    transpose a b \<circ> transpose c d = transpose x y \<circ> transpose a z)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   703
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   704
  assume neq: "a \<noteq> b" "c \<noteq> d"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   705
  have "a \<noteq> b \<longrightarrow> c \<noteq> d \<longrightarrow>
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   706
    (transpose a b \<circ> transpose c d = id \<or>
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   707
      (\<exists>x y z. x \<noteq> a \<and> y \<noteq> a \<and> z \<noteq> a \<and> x \<noteq> y \<and>
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   708
        transpose a b \<circ> transpose c d = transpose x y \<circ> transpose a z))"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   709
    apply (rule symmetry_lemma[where a=a and b=b and c=c and d=d])
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   710
     apply (simp_all only: ac_simps)
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   711
    apply (metis id_comp swap_id_common swap_id_common' swap_id_independent transpose_comp_involutory)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   712
    done
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   713
  with neq show ?thesis by metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   714
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   715
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   716
lemma swapidseq_id_iff[simp]: "swapidseq 0 p \<longleftrightarrow> p = id"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   717
  using swapidseq.cases[of 0 p "p = id"] by auto
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   718
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   719
lemma swapidseq_cases: "swapidseq n p \<longleftrightarrow>
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   720
    n = 0 \<and> p = id \<or> (\<exists>a b q m. n = Suc m \<and> p = transpose a b \<circ> q \<and> swapidseq m q \<and> a \<noteq> b)"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   721
  apply (rule iffI)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   722
   apply (erule swapidseq.cases[of n p])
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   723
    apply simp
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   724
   apply (rule disjI2)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   725
   apply (rule_tac x= "a" in exI)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   726
   apply (rule_tac x= "b" in exI)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   727
   apply (rule_tac x= "pa" in exI)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   728
   apply (rule_tac x= "na" in exI)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   729
   apply simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   730
  apply auto
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   731
  apply (rule comp_Suc, simp_all)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   732
  done
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   733
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   734
lemma fixing_swapidseq_decrease:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   735
  assumes "swapidseq n p"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   736
    and "a \<noteq> b"
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   737
    and "(transpose a b \<circ> p) a = a"
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   738
  shows "n \<noteq> 0 \<and> swapidseq (n - 1) (transpose a b \<circ> p)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   739
  using assms
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   740
proof (induct n arbitrary: p a b)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   741
  case 0
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   742
  then show ?case
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   743
    by (auto simp add: fun_upd_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   744
next
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   745
  case (Suc n p a b)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   746
  from Suc.prems(1) swapidseq_cases[of "Suc n" p]
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   747
  obtain c d q m where
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   748
    cdqm: "Suc n = Suc m" "p = transpose c d \<circ> q" "swapidseq m q" "c \<noteq> d" "n = m"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   749
    by auto
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   750
  consider "transpose a b \<circ> transpose c d = id"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   751
    | x y z where "x \<noteq> a" "y \<noteq> a" "z \<noteq> a" "x \<noteq> y"
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   752
      "transpose a b \<circ> transpose c d = transpose x y \<circ> transpose a z"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   753
    using swap_general[OF Suc.prems(2) cdqm(4)] by metis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   754
  then show ?case
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   755
  proof cases
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   756
    case 1
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   757
    then show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   758
      by (simp only: cdqm o_assoc) (simp add: cdqm)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   759
  next
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   760
    case prems: 2
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   761
    then have az: "a \<noteq> z"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   762
      by simp
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   763
    from prems have *: "(transpose x y \<circ> h) a = a \<longleftrightarrow> h a = a" for h
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   764
      by (simp add: transpose_def)
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   765
    from cdqm(2) have "transpose a b \<circ> p = transpose a b \<circ> (transpose c d \<circ> q)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   766
      by simp
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   767
    then have "transpose a b \<circ> p = transpose x y \<circ> (transpose a z \<circ> q)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   768
      by (simp add: o_assoc prems)
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   769
    then have "(transpose a b \<circ> p) a = (transpose x y \<circ> (transpose a z \<circ> q)) a"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   770
      by simp
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   771
    then have "(transpose x y \<circ> (transpose a z \<circ> q)) a = a"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   772
      unfolding Suc by metis
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   773
    then have "(transpose a z \<circ> q) a = a"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   774
      by (simp only: *)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   775
    from Suc.hyps[OF cdqm(3)[ unfolded cdqm(5)[symmetric]] az this]
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   776
    have **: "swapidseq (n - 1) (transpose a z \<circ> q)" "n \<noteq> 0"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   777
      by blast+
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   778
    from \<open>n \<noteq> 0\<close> have ***: "Suc n - 1 = Suc (n - 1)"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   779
      by auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   780
    show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   781
      apply (simp only: cdqm(2) prems o_assoc ***)
49739
13aa6d8268ec consolidated names of theorems on composition;
haftmann
parents: 45922
diff changeset
   782
      apply (simp only: Suc_not_Zero simp_thms comp_assoc)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   783
      apply (rule comp_Suc)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   784
      using ** prems
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   785
       apply blast+
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   786
      done
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   787
  qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   788
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   789
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   790
lemma swapidseq_identity_even:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   791
  assumes "swapidseq n (id :: 'a \<Rightarrow> 'a)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   792
  shows "even n"
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   793
  using \<open>swapidseq n id\<close>
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   794
proof (induct n rule: nat_less_induct)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   795
  case H: (1 n)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   796
  consider "n = 0"
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   797
    | a b :: 'a and q m where "n = Suc m" "id = transpose a b \<circ> q" "swapidseq m q" "a \<noteq> b"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   798
    using H(2)[unfolded swapidseq_cases[of n id]] by auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   799
  then show ?case
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   800
  proof cases
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   801
    case 1
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   802
    then show ?thesis by presburger
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   803
  next
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   804
    case h: 2
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   805
    from fixing_swapidseq_decrease[OF h(3,4), unfolded h(2)[symmetric]]
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   806
    have m: "m \<noteq> 0" "swapidseq (m - 1) (id :: 'a \<Rightarrow> 'a)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   807
      by auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   808
    from h m have mn: "m - 1 < n"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   809
      by arith
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   810
    from H(1)[rule_format, OF mn m(2)] h(1) m(1) show ?thesis
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   811
      by presburger
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   812
  qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   813
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   814
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   815
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   816
subsection \<open>Therefore we have a welldefined notion of parity\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   817
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   818
definition "evenperm p = even (SOME n. swapidseq n p)"
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   819
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   820
lemma swapidseq_even_even:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   821
  assumes m: "swapidseq m p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   822
    and n: "swapidseq n p"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   823
  shows "even m \<longleftrightarrow> even n"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   824
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   825
  from swapidseq_inverse_exists[OF n] obtain q where q: "swapidseq n q" "p \<circ> q = id" "q \<circ> p = id"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   826
    by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   827
  from swapidseq_identity_even[OF swapidseq_comp_add[OF m q(1), unfolded q]] show ?thesis
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   828
    by arith
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   829
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   830
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   831
lemma evenperm_unique:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   832
  assumes p: "swapidseq n p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   833
    and n:"even n = b"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   834
  shows "evenperm p = b"
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   835
  unfolding n[symmetric] evenperm_def
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   836
  apply (rule swapidseq_even_even[where p = p])
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   837
   apply (rule someI[where x = n])
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   838
  using p
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   839
   apply blast+
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   840
  done
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   841
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   842
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   843
subsection \<open>And it has the expected composition properties\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   844
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   845
lemma evenperm_id[simp]: "evenperm id = True"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   846
  by (rule evenperm_unique[where n = 0]) simp_all
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   847
73621
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
   848
lemma evenperm_identity [simp]:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
   849
  \<open>evenperm (\<lambda>x. x)\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
   850
  using evenperm_id by (simp add: id_def [abs_def])
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
   851
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   852
lemma evenperm_swap: "evenperm (transpose a b) = (a = b)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   853
  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
   854
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   855
lemma evenperm_comp:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   856
  assumes "permutation p" "permutation q"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   857
  shows "evenperm (p \<circ> q) \<longleftrightarrow> evenperm p = evenperm q"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   858
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   859
  from assms 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
   860
    unfolding permutation_def by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   861
  have "even (n + m) \<longleftrightarrow> (even n \<longleftrightarrow> even m)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   862
    by arith
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   863
  from evenperm_unique[OF n refl] evenperm_unique[OF m refl]
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   864
    and evenperm_unique[OF swapidseq_comp_add[OF n m] this] show ?thesis
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   865
    by blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   866
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   867
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   868
lemma evenperm_inv:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   869
  assumes "permutation p"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   870
  shows "evenperm (inv p) = evenperm p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   871
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   872
  from assms obtain n where n: "swapidseq n p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   873
    unfolding permutation_def by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   874
  show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   875
    by (rule evenperm_unique[OF swapidseq_inverse[OF n] evenperm_unique[OF n refl, symmetric]])
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   876
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   877
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   878
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   879
subsection \<open>A more abstract characterization of permutations\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   880
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   881
lemma permutation_bijective:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   882
  assumes "permutation p"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   883
  shows "bij p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   884
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   885
  from assms obtain n where n: "swapidseq n p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   886
    unfolding permutation_def by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   887
  from swapidseq_inverse_exists[OF n] obtain q where q: "swapidseq n q" "p \<circ> q = id" "q \<circ> p = id"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   888
    by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   889
  then show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   890
    unfolding bij_iff
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   891
    apply (auto simp add: fun_eq_iff)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   892
    apply metis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   893
    done
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   894
qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   895
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   896
lemma permutation_finite_support:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   897
  assumes "permutation p"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   898
  shows "finite {x. p x \<noteq> x}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   899
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   900
  from assms obtain n where "swapidseq n p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   901
    unfolding permutation_def by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   902
  then show ?thesis
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   903
  proof (induct n p rule: swapidseq.induct)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   904
    case id
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   905
    then show ?case by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   906
  next
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   907
    case (comp_Suc n p a b)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   908
    let ?S = "insert a (insert b {x. p x \<noteq> x})"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   909
    from comp_Suc.hyps(2) have *: "finite ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   910
      by simp
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   911
    from \<open>a \<noteq> b\<close> have **: "{x. (transpose a b \<circ> p) x \<noteq> x} \<subseteq> ?S"
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   912
      by auto
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   913
    show ?case
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   914
      by (rule finite_subset[OF ** *])
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   915
  qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   916
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   917
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   918
lemma permutation_lemma:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   919
  assumes "finite S"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   920
    and "bij p"
73328
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   921
    and "\<forall>x. x \<notin> S \<longrightarrow> p x = x"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   922
  shows "permutation p"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   923
  using assms
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   924
proof (induct S arbitrary: p rule: finite_induct)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   925
  case empty
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   926
  then show ?case
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   927
    by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   928
next
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   929
  case (insert a F p)
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   930
  let ?r = "transpose a (p a) \<circ> p"
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   931
  let ?q = "transpose a (p a) \<circ> ?r"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   932
  have *: "?r a = a"
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   933
    by simp
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   934
  from insert * have **: "\<forall>x. x \<notin> F \<longrightarrow> ?r x = x"
64966
d53d7ca3303e added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents: 64543
diff changeset
   935
    by (metis bij_pointE comp_apply id_apply insert_iff swap_apply(3))
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   936
  have "bij ?r"
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   937
    using insert by (simp add: bij_comp)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   938
  have "permutation ?r"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   939
    by (rule insert(3)[OF \<open>bij ?r\<close> **])
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   940
  then have "permutation ?q"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   941
    by (simp add: permutation_compose permutation_swap_id)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   942
  then show ?case
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   943
    by (simp add: o_assoc)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   944
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   945
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   946
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
   947
  (is "?lhs \<longleftrightarrow> ?b \<and> ?f")
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   948
proof
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   949
  assume ?lhs
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   950
  with permutation_bijective permutation_finite_support show "?b \<and> ?f"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   951
    by auto
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   952
next
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   953
  assume "?b \<and> ?f"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   954
  then have "?f" "?b" by blast+
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   955
  from permutation_lemma[OF this] show ?lhs
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   956
    by blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   957
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   958
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   959
lemma permutation_inverse_works:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   960
  assumes "permutation p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   961
  shows "inv p \<circ> p = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   962
    and "p \<circ> inv p = id"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   963
  using permutation_bijective [OF assms] by (auto simp: bij_def inj_iff surj_iff)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   964
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   965
lemma permutation_inverse_compose:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   966
  assumes p: "permutation p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   967
    and q: "permutation q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   968
  shows "inv (p \<circ> q) = inv q \<circ> inv p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   969
proof -
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   970
  note ps = permutation_inverse_works[OF p]
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   971
  note qs = permutation_inverse_works[OF q]
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   972
  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
   973
    by (simp add: o_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   974
  also have "\<dots> = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   975
    by (simp add: ps qs)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   976
  finally have *: "p \<circ> q \<circ> (inv q \<circ> inv p) = id" .
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   977
  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
   978
    by (simp add: o_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   979
  also have "\<dots> = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   980
    by (simp add: ps qs)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   981
  finally have **: "inv q \<circ> inv p \<circ> (p \<circ> q) = id" .
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   982
  show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   983
    by (rule inv_unique_comp[OF * **])
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   984
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   985
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   986
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   987
subsection \<open>Relation to \<open>permutes\<close>\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   988
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   989
lemma permutes_imp_permutation:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   990
  \<open>permutation p\<close> if \<open>finite S\<close> \<open>p permutes S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   991
proof -
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   992
  from \<open>p permutes S\<close> have \<open>{x. p x \<noteq> x} \<subseteq> S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   993
    by (auto dest: permutes_not_in)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   994
  then have \<open>finite {x. p x \<noteq> x}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   995
    using \<open>finite S\<close> by (rule finite_subset)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   996
  moreover from \<open>p permutes S\<close> have \<open>bij p\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   997
    by (auto dest: permutes_bij)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   998
  ultimately show ?thesis
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   999
    by (simp add: permutation)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1000
qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1001
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1002
lemma permutation_permutesE:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1003
  assumes \<open>permutation p\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1004
  obtains S where \<open>finite S\<close> \<open>p permutes S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1005
proof -
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1006
  from assms have fin: \<open>finite {x. p x \<noteq> x}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1007
    by (simp add: permutation)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1008
  from assms have \<open>bij p\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1009
    by (simp add: permutation)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1010
  also have \<open>UNIV = {x. p x \<noteq> x} \<union> {x. p x = x}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1011
    by auto
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1012
  finally have \<open>bij_betw p {x. p x \<noteq> x} {x. p x \<noteq> x}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1013
    by (rule bij_betw_partition) (auto simp add: bij_betw_fixpoints)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1014
  then have \<open>p permutes {x. p x \<noteq> x}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1015
    by (auto intro: bij_imp_permutes)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1016
  with fin show thesis ..
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1017
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1018
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1019
lemma permutation_permutes: "permutation p \<longleftrightarrow> (\<exists>S. finite S \<and> p permutes S)"
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1020
  by (auto elim: permutation_permutesE intro: permutes_imp_permutation)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1021
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1022
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
  1023
subsection \<open>Sign of a permutation as a real number\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1024
73328
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
  1025
definition sign :: \<open>('a \<Rightarrow> 'a) \<Rightarrow> int\<close> \<comment> \<open>TODO: prefer less generic name\<close>
73621
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1026
  where \<open>sign p = (if evenperm p then 1 else - 1)\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1027
73621
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1028
lemma sign_cases [case_names even odd]:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1029
  obtains \<open>sign p = 1\<close> | \<open>sign p = - 1\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1030
  by (cases \<open>evenperm p\<close>) (simp_all add: sign_def)
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1031
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1032
lemma sign_nz [simp]: "sign p \<noteq> 0"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1033
  by (cases p rule: sign_cases) simp_all
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1034
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1035
lemma sign_id [simp]: "sign id = 1"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1036
  by (simp add: sign_def)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1037
73621
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1038
lemma sign_identity [simp]:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1039
  \<open>sign (\<lambda>x. x) = 1\<close>
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1040
  by (simp add: sign_def)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1041
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1042
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
  1043
  by (simp add: sign_def evenperm_inv)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1044
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1045
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
  1046
  by (simp add: sign_def evenperm_comp)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1047
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
  1048
lemma sign_swap_id: "sign (transpose a b) = (if a = b then 1 else - 1)"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1049
  by (simp add: sign_def evenperm_swap)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1050
73621
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1051
lemma sign_idempotent [simp]: "sign p * sign p = 1"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1052
  by (simp add: sign_def)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1053
73621
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1054
lemma sign_left_idempotent [simp]:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1055
  \<open>sign p * (sign p * sign q) = sign q\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1056
  by (simp add: sign_def)
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1057
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1058
term "(bij, bij_betw, permutation)"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1059
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
  1060
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1061
subsection \<open>Permuting a list\<close>
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1062
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1063
text \<open>This function permutes a list by applying a permutation to the indices.\<close>
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1064
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1065
definition permute_list :: "(nat \<Rightarrow> nat) \<Rightarrow> 'a list \<Rightarrow> 'a list"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1066
  where "permute_list f xs = map (\<lambda>i. xs ! (f i)) [0..<length xs]"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1067
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
  1068
lemma permute_list_map:
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1069
  assumes "f permutes {..<length xs}"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1070
  shows "permute_list f (map g xs) = map g (permute_list f xs)"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1071
  using permutes_in_image[OF assms] by (auto simp: permute_list_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1072
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1073
lemma permute_list_nth:
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1074
  assumes "f permutes {..<length xs}" "i < length xs"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1075
  shows "permute_list f xs ! i = xs ! f i"
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
  1076
  using permutes_in_image[OF assms(1)] assms(2)
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1077
  by (simp add: permute_list_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1078
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1079
lemma permute_list_Nil [simp]: "permute_list f [] = []"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1080
  by (simp add: permute_list_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1081
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1082
lemma length_permute_list [simp]: "length (permute_list f xs) = length xs"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1083
  by (simp add: permute_list_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1084
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
  1085
lemma permute_list_compose:
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1086
  assumes "g permutes {..<length xs}"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1087
  shows "permute_list (f \<circ> g) xs = permute_list g (permute_list f xs)"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1088
  using assms[THEN permutes_in_image] by (auto simp add: permute_list_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1089
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1090
lemma permute_list_ident [simp]: "permute_list (\<lambda>x. x) xs = xs"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1091
  by (simp add: permute_list_def map_nth)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1092
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1093
lemma permute_list_id [simp]: "permute_list id xs = xs"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1094
  by (simp add: id_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1095
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1096
lemma mset_permute_list [simp]:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1097
  fixes xs :: "'a list"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1098
  assumes "f permutes {..<length xs}"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1099
  shows "mset (permute_list f xs) = mset xs"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1100
proof (rule multiset_eqI)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1101
  fix y :: 'a
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1102
  from assms have [simp]: "f x < length xs \<longleftrightarrow> x < length xs" for x
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1103
    using permutes_in_image[OF assms] by auto
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1104
  have "count (mset (permute_list f xs)) y = card ((\<lambda>i. xs ! f i) -` {y} \<inter> {..<length xs})"
64543
6b13586ef1a2 remove typo in bij_swap_compose_bij theorem name; tune proof
bulwahn
parents: 64284
diff changeset
  1105
    by (simp add: permute_list_def count_image_mset atLeast0LessThan)
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1106
  also have "(\<lambda>i. xs ! f i) -` {y} \<inter> {..<length xs} = f -` {i. i < length xs \<and> y = xs ! i}"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1107
    by auto
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1108
  also from assms have "card \<dots> = card {i. i < length xs \<and> y = xs ! i}"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1109
    by (intro card_vimage_inj) (auto simp: permutes_inj permutes_surj)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1110
  also have "\<dots> = count (mset xs) y"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1111
    by (simp add: count_mset length_filter_conv_card)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1112
  finally show "count (mset (permute_list f xs)) y = count (mset xs) y"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1113
    by simp
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1114
qed
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1115
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
  1116
lemma set_permute_list [simp]:
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1117
  assumes "f permutes {..<length xs}"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1118
  shows "set (permute_list f xs) = set xs"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1119
  by (rule mset_eq_setD[OF mset_permute_list]) fact
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1120
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1121
lemma distinct_permute_list [simp]:
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1122
  assumes "f permutes {..<length xs}"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1123
  shows "distinct (permute_list f xs) = distinct xs"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1124
  by (simp add: distinct_count_atmost_1 assms)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1125
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
  1126
lemma permute_list_zip:
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1127
  assumes "f permutes A" "A = {..<length xs}"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1128
  assumes [simp]: "length xs = length ys"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1129
  shows "permute_list f (zip xs ys) = zip (permute_list f xs) (permute_list f ys)"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1130
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1131
  from permutes_in_image[OF assms(1)] assms(2) have *: "f i < length ys \<longleftrightarrow> i < length ys" for i
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1132
    by simp
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1133
  have "permute_list f (zip xs ys) = map (\<lambda>i. zip xs ys ! f i) [0..<length ys]"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1134
    by (simp_all add: permute_list_def zip_map_map)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1135
  also have "\<dots> = map (\<lambda>(x, y). (xs ! f x, ys ! f y)) (zip [0..<length ys] [0..<length ys])"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1136
    by (intro nth_equalityI) (simp_all add: *)
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1137
  also have "\<dots> = zip (permute_list f xs) (permute_list f ys)"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1138
    by (simp_all add: permute_list_def zip_map_map)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1139
  finally show ?thesis .
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1140
qed
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1141
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
  1142
lemma map_of_permute:
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1143
  assumes "\<sigma> permutes fst ` set xs"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1144
  shows "map_of xs \<circ> \<sigma> = map_of (map (\<lambda>(x,y). (inv \<sigma> x, y)) xs)"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1145
    (is "_ = map_of (map ?f _)")
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1146
proof
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1147
  from assms have "inj \<sigma>" "surj \<sigma>"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1148
    by (simp_all add: permutes_inj permutes_surj)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1149
  then show "(map_of xs \<circ> \<sigma>) x = map_of (map ?f xs) x" for x
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1150
    by (induct xs) (auto simp: inv_f_f surj_f_inv_f)
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1151
qed
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1152
73706
4b1386b2c23e mere abbreviation for logical alias
haftmann
parents: 73663
diff changeset
  1153
lemma list_all2_permute_list_iff:
4b1386b2c23e mere abbreviation for logical alias
haftmann
parents: 73663
diff changeset
  1154
  \<open>list_all2 P (permute_list p xs) (permute_list p ys) \<longleftrightarrow> list_all2 P xs ys\<close>
4b1386b2c23e mere abbreviation for logical alias
haftmann
parents: 73663
diff changeset
  1155
  if \<open>p permutes {..<length xs}\<close>
4b1386b2c23e mere abbreviation for logical alias
haftmann
parents: 73663
diff changeset
  1156
  using that by (auto simp add: list_all2_iff simp flip: permute_list_zip)
4b1386b2c23e mere abbreviation for logical alias
haftmann
parents: 73663
diff changeset
  1157
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1158
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
  1159
subsection \<open>More lemmas about permutations\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1160
73555
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1161
lemma permutes_in_funpow_image: \<^marker>\<open>contributor \<open>Lars Noschinski\<close>\<close>
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1162
  assumes "f permutes S" "x \<in> S"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1163
  shows "(f ^^ n) x \<in> S"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1164
  using assms by (induction n) (auto simp: permutes_in_image)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1165
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1166
lemma permutation_self: \<^marker>\<open>contributor \<open>Lars Noschinski\<close>\<close>
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1167
  assumes \<open>permutation p\<close>
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1168
  obtains n where \<open>n > 0\<close> \<open>(p ^^ n) x = x\<close>
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1169
proof (cases \<open>p x = x\<close>)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1170
  case True
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1171
  with that [of 1] show thesis by simp
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1172
next
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1173
  case False
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1174
  from \<open>permutation p\<close> have \<open>inj p\<close>
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1175
    by (intro permutation_bijective bij_is_inj)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1176
  moreover from \<open>p x \<noteq> x\<close> have \<open>(p ^^ Suc n) x \<noteq> (p ^^ n) x\<close> for n
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1177
  proof (induction n arbitrary: x)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1178
    case 0 then show ?case by simp
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1179
  next
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1180
    case (Suc n)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1181
    have "p (p x) \<noteq> p x"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1182
    proof (rule notI)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1183
      assume "p (p x) = p x"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1184
      then show False using \<open>p x \<noteq> x\<close> \<open>inj p\<close> by (simp add: inj_eq)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1185
    qed
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1186
    have "(p ^^ Suc (Suc n)) x = (p ^^ Suc n) (p x)"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1187
      by (simp add: funpow_swap1)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1188
    also have "\<dots> \<noteq> (p ^^ n) (p x)"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1189
      by (rule Suc) fact
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1190
    also have "(p ^^ n) (p x) = (p ^^ Suc n) x"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1191
      by (simp add: funpow_swap1)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1192
    finally show ?case by simp
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1193
  qed
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1194
  then have "{y. \<exists>n. y = (p ^^ n) x} \<subseteq> {x. p x \<noteq> x}"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1195
    by auto
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1196
  then have "finite {y. \<exists>n. y = (p ^^ n) x}"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1197
    using permutation_finite_support[OF assms] by (rule finite_subset)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1198
  ultimately obtain n where \<open>n > 0\<close> \<open>(p ^^ n) x = x\<close>
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1199
    by (rule funpow_inj_finite)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1200
  with that [of n] show thesis by blast
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1201
qed
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1202
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1203
text \<open>The following few lemmas were contributed by Lukas Bulwahn.\<close>
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1204
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1205
lemma count_image_mset_eq_card_vimage:
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1206
  assumes "finite A"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1207
  shows "count (image_mset f (mset_set A)) b = card {a \<in> A. f a = b}"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1208
  using assms
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1209
proof (induct A)
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1210
  case empty
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1211
  show ?case by simp
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1212
next
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1213
  case (insert x F)
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1214
  show ?case
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1215
  proof (cases "f x = b")
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1216
    case True
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1217
    with insert.hyps
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1218
    have "count (image_mset f (mset_set (insert x F))) b = Suc (card {a \<in> F. f a = f x})"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1219
      by auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1220
    also from insert.hyps(1,2) have "\<dots> = card (insert x {a \<in> F. f a = f x})"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1221
      by simp
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1222
    also from \<open>f x = b\<close> have "card (insert x {a \<in> F. f a = f x}) = card {a \<in> insert x F. f a = b}"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1223
      by (auto intro: arg_cong[where f="card"])
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1224
    finally show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1225
      using insert by auto
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1226
  next
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1227
    case False
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1228
    then have "{a \<in> F. f a = b} = {a \<in> insert x F. f a = b}"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1229
      by auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1230
    with insert False show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1231
      by simp
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1232
  qed
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1233
qed
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
  1234
67408
4a4c14b24800 prefer formal comments;
wenzelm
parents: 67399
diff changeset
  1235
\<comment> \<open>Prove \<open>image_mset_eq_implies_permutes\<close> ...\<close>
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1236
lemma image_mset_eq_implies_permutes:
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1237
  fixes f :: "'a \<Rightarrow> 'b"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1238
  assumes "finite A"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1239
    and mset_eq: "image_mset f (mset_set A) = image_mset f' (mset_set A)"
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1240
  obtains p where "p permutes A" and "\<forall>x\<in>A. f x = f' (p x)"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1241
proof -
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1242
  from \<open>finite A\<close> have [simp]: "finite {a \<in> A. f a = (b::'b)}" for f b by auto
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1243
  have "f ` A = f' ` A"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1244
  proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1245
    from \<open>finite A\<close> have "f ` A = f ` (set_mset (mset_set A))"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1246
      by simp
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1247
    also have "\<dots> = f' ` set_mset (mset_set A)"
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1248
      by (metis mset_eq multiset.set_map)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1249
    also from \<open>finite A\<close> have "\<dots> = f' ` A"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1250
      by simp
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1251
    finally show ?thesis .
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1252
  qed
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1253
  have "\<forall>b\<in>(f ` A). \<exists>p. bij_betw p {a \<in> A. f a = b} {a \<in> A. f' a = b}"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1254
  proof
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1255
    fix b
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1256
    from mset_eq have "count (image_mset f (mset_set A)) b = count (image_mset f' (mset_set A)) b"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1257
      by simp
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1258
    with \<open>finite A\<close> have "card {a \<in> A. f a = b} = card {a \<in> A. f' a = b}"
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1259
      by (simp add: count_image_mset_eq_card_vimage)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1260
    then show "\<exists>p. bij_betw p {a\<in>A. f a = b} {a \<in> A. f' a = b}"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1261
      by (intro finite_same_card_bij) simp_all
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1262
  qed
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1263
  then have "\<exists>p. \<forall>b\<in>f ` A. bij_betw (p b) {a \<in> A. f a = b} {a \<in> A. f' a = b}"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1264
    by (rule bchoice)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1265
  then obtain p where p: "\<forall>b\<in>f ` A. bij_betw (p b) {a \<in> A. f a = b} {a \<in> A. f' a = b}" ..
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1266
  define p' where "p' = (\<lambda>a. if a \<in> A then p (f a) a else a)"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1267
  have "p' permutes A"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1268
  proof (rule bij_imp_permutes)
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1269
    have "disjoint_family_on (\<lambda>i. {a \<in> A. f' a = i}) (f ` A)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1270
      by (auto simp: disjoint_family_on_def)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1271
    moreover
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1272
    have "bij_betw (\<lambda>a. p (f a) a) {a \<in> A. f a = b} {a \<in> A. f' a = b}" if "b \<in> f ` A" for b
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1273
      using p that by (subst bij_betw_cong[where g="p b"]) auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1274
    ultimately
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1275
    have "bij_betw (\<lambda>a. p (f a) a) (\<Union>b\<in>f ` A. {a \<in> A. f a = b}) (\<Union>b\<in>f ` A. {a \<in> A. f' a = b})"
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1276
      by (rule bij_betw_UNION_disjoint)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1277
    moreover have "(\<Union>b\<in>f ` A. {a \<in> A. f a = b}) = A"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1278
      by auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1279
    moreover from \<open>f ` A = f' ` A\<close> have "(\<Union>b\<in>f ` A. {a \<in> A. f' a = b}) = A"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1280
      by auto
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1281
    ultimately show "bij_betw p' A A"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1282
      unfolding p'_def by (subst bij_betw_cong[where g="(\<lambda>a. p (f a) a)"]) auto
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1283
  next
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1284
    show "\<And>x. x \<notin> A \<Longrightarrow> p' x = x"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1285
      by (simp add: p'_def)
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1286
  qed
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1287
  moreover from p have "\<forall>x\<in>A. f x = f' (p' x)"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1288
    unfolding p'_def using bij_betwE by fastforce
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1289
  ultimately show ?thesis ..
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1290
qed
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1291
67408
4a4c14b24800 prefer formal comments;
wenzelm
parents: 67399
diff changeset
  1292
\<comment> \<open>... and derive the existing property:\<close>
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1293
lemma mset_eq_permutation:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1294
  fixes xs ys :: "'a list"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1295
  assumes mset_eq: "mset xs = mset ys"
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1296
  obtains p where "p permutes {..<length ys}" "permute_list p ys = xs"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1297
proof -
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1298
  from mset_eq have length_eq: "length xs = length ys"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1299
    by (rule mset_eq_length)
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1300
  have "mset_set {..<length ys} = mset [0..<length ys]"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1301
    by (rule mset_set_upto_eq_mset_upto)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1302
  with mset_eq length_eq have "image_mset (\<lambda>i. xs ! i) (mset_set {..<length ys}) =
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1303
    image_mset (\<lambda>i. ys ! i) (mset_set {..<length ys})"
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1304
    by (metis map_nth mset_map)
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1305
  from image_mset_eq_implies_permutes[OF _ this]
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1306
  obtain p where p: "p permutes {..<length ys}" and "\<forall>i\<in>{..<length ys}. xs ! i = ys ! (p i)"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1307
    by auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1308
  with length_eq have "permute_list p ys = xs"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1309
    by (auto intro!: nth_equalityI simp: permute_list_nth)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1310
  with p show thesis ..
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1311
qed
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1312
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1313
lemma permutes_natset_le:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1314
  fixes S :: "'a::wellorder set"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1315
  assumes "p permutes S"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1316
    and "\<forall>i \<in> S. p i \<le> i"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1317
  shows "p = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1318
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1319
  have "p n = n" for n
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1320
    using assms
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1321
  proof (induct n arbitrary: S rule: less_induct)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1322
    case (less n)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1323
    show ?case
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1324
    proof (cases "n \<in> S")
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1325
      case False
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1326
      with less(2) show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1327
        unfolding permutes_def by metis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1328
    next
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1329
      case True
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1330
      with less(3) have "p n < n \<or> p n = n"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1331
        by auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1332
      then show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1333
      proof
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1334
        assume "p n < n"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1335
        with less have "p (p n) = p n"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1336
          by metis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1337
        with permutes_inj[OF less(2)] have "p n = n"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1338
          unfolding inj_def by blast
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1339
        with \<open>p n < n\<close> have False
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1340
          by simp
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1341
        then show ?thesis ..
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1342
      qed
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1343
    qed
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1344
  qed
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1345
  then show ?thesis by (auto simp: fun_eq_iff)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1346
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1347
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1348
lemma permutes_natset_ge:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1349
  fixes S :: "'a::wellorder set"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1350
  assumes p: "p permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1351
    and le: "\<forall>i \<in> S. p i \<ge> i"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1352
  shows "p = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1353
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1354
  have "i \<ge> inv p i" if "i \<in> S" for i
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1355
  proof -
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1356
    from that permutes_in_image[OF permutes_inv[OF p]] have "inv p i \<in> S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1357
      by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1358
    with le have "p (inv p i) \<ge> inv p i"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1359
      by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1360
    with permutes_inverses[OF p] show ?thesis
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1361
      by simp
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1362
  qed
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1363
  then have "\<forall>i\<in>S. inv p i \<le> i"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1364
    by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1365
  from permutes_natset_le[OF permutes_inv[OF p] this] have "inv p = inv id"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1366
    by simp
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
  1367
  then show ?thesis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1368
    apply (subst permutes_inv_inv[OF p, symmetric])
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1369
    apply (rule inv_unique_comp)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1370
     apply simp_all
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1371
    done
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1372
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1373
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1374
lemma image_inverse_permutations: "{inv p |p. p permutes S} = {p. p permutes S}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1375
  apply (rule set_eqI)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1376
  apply auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1377
  using permutes_inv_inv permutes_inv
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1378
   apply auto
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1379
  apply (rule_tac x="inv x" in exI)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1380
  apply auto
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1381
  done
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1382
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
  1383
lemma image_compose_permutations_left:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1384
  assumes "q permutes S"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1385
  shows "{q \<circ> p |p. p permutes S} = {p. p permutes S}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1386
  apply (rule set_eqI)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1387
  apply auto
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1388
   apply (rule permutes_compose)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1389
  using assms
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1390
    apply auto
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1391
  apply (rule_tac x = "inv q \<circ> x" in exI)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1392
  apply (simp add: o_assoc permutes_inv permutes_compose permutes_inv_o)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1393
  done
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1394
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1395
lemma image_compose_permutations_right:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1396
  assumes "q permutes S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1397
  shows "{p \<circ> q | p. p permutes S} = {p . p permutes S}"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1398
  apply (rule set_eqI)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1399
  apply auto
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1400
   apply (rule permutes_compose)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1401
  using assms
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1402
    apply auto
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1403
  apply (rule_tac x = "x \<circ> inv q" in exI)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1404
  apply (simp add: o_assoc permutes_inv permutes_compose permutes_inv_o comp_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1405
  done
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1406
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1407
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
  1408
  by (simp add: permutes_def) metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1409
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1410
lemma sum_permutations_inverse: "sum f {p. p permutes S} = sum (\<lambda>p. f(inv p)) {p. p permutes S}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1411
  (is "?lhs = ?rhs")
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1412
proof -
30036
3a074e3a9a18 generalize some lemmas
huffman
parents: 29840
diff changeset
  1413
  let ?S = "{p . p permutes S}"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1414
  have *: "inj_on inv ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1415
  proof (auto simp add: inj_on_def)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1416
    fix q r
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1417
    assume q: "q permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1418
      and r: "r permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1419
      and qr: "inv q = inv r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1420
    then have "inv (inv q) = inv (inv r)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1421
      by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1422
    with permutes_inv_inv[OF q] permutes_inv_inv[OF r] show "q = r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1423
      by metis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1424
  qed
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1425
  have **: "inv ` ?S = ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1426
    using image_inverse_permutations by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1427
  have ***: "?rhs = sum (f \<circ> inv) ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1428
    by (simp add: o_def)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1429
  from sum.reindex[OF *, of f] show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1430
    by (simp only: ** ***)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1431
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1432
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1433
lemma setum_permutations_compose_left:
30036
3a074e3a9a18 generalize some lemmas
huffman
parents: 29840
diff changeset
  1434
  assumes q: "q permutes S"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63921
diff changeset
  1435
  shows "sum f {p. p permutes S} = sum (\<lambda>p. f(q \<circ> p)) {p. p permutes S}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1436
  (is "?lhs = ?rhs")
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1437
proof -
30036
3a074e3a9a18 generalize some lemmas
huffman
parents: 29840
diff changeset
  1438
  let ?S = "{p. p permutes S}"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 66486
diff changeset
  1439
  have *: "?rhs = sum (f \<circ> ((\<circ>) q)) ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1440
    by (simp add: o_def)
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 66486
diff changeset
  1441
  have **: "inj_on ((\<circ>) q) ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1442
  proof (auto simp add: inj_on_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1443
    fix p r
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1444
    assume "p permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1445
      and r: "r permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1446
      and rp: "q \<circ> p = q \<circ> r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1447
    then have "inv q \<circ> q \<circ> p = inv q \<circ> q \<circ> r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1448
      by (simp add: comp_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1449
    with permutes_inj[OF q, unfolded inj_iff] show "p = r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1450
      by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1451
  qed
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 66486
diff changeset
  1452
  have "((\<circ>) q) ` ?S = ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1453
    using image_compose_permutations_left[OF q] by auto
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1454
  with * sum.reindex[OF **, of f] show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1455
    by (simp only:)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1456
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1457
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1458
lemma sum_permutations_compose_right:
30036
3a074e3a9a18 generalize some lemmas
huffman
parents: 29840
diff changeset
  1459
  assumes q: "q permutes S"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63921
diff changeset
  1460
  shows "sum f {p. p permutes S} = sum (\<lambda>p. f(p \<circ> q)) {p. p permutes S}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1461
  (is "?lhs = ?rhs")
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1462
proof -
30036
3a074e3a9a18 generalize some lemmas
huffman
parents: 29840
diff changeset
  1463
  let ?S = "{p. p permutes S}"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1464
  have *: "?rhs = sum (f \<circ> (\<lambda>p. p \<circ> q)) ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1465
    by (simp add: o_def)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1466
  have **: "inj_on (\<lambda>p. p \<circ> q) ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1467
  proof (auto simp add: inj_on_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1468
    fix p r
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1469
    assume "p permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1470
      and r: "r permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1471
      and rp: "p \<circ> q = r \<circ> q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1472
    then have "p \<circ> (q \<circ> inv q) = r \<circ> (q \<circ> inv q)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1473
      by (simp add: o_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1474
    with permutes_surj[OF q, unfolded surj_iff] show "p = r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1475
      by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1476
  qed
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1477
  from image_compose_permutations_right[OF q] have "(\<lambda>p. p \<circ> q) ` ?S = ?S"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1478
    by auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1479
  with * sum.reindex[OF **, of f] show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1480
    by (simp only:)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1481
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1482
73621
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1483
lemma inv_inj_on_permutes:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1484
  \<open>inj_on inv {p. p permutes S}\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1485
proof (intro inj_onI, unfold mem_Collect_eq)
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1486
  fix p q
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1487
  assume p: "p permutes S" and q: "q permutes S" and eq: "inv p = inv q"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1488
  have "inv (inv p) = inv (inv q)" using eq by simp
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1489
  thus "p = q"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1490
    using inv_inv_eq[OF permutes_bij] p q by metis
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1491
qed
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1492
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1493
lemma permutes_pair_eq:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1494
  \<open>{(p s, s) |s. s \<in> S} = {(s, inv p s) |s. s \<in> S}\<close> (is \<open>?L = ?R\<close>) if \<open>p permutes S\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1495
proof
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1496
  show "?L \<subseteq> ?R"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1497
  proof
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1498
    fix x assume "x \<in> ?L"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1499
    then obtain s where x: "x = (p s, s)" and s: "s \<in> S" by auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1500
    note x
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1501
    also have "(p s, s) = (p s, Hilbert_Choice.inv p (p s))"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1502
      using permutes_inj [OF that] inv_f_f by auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1503
    also have "... \<in> ?R" using s permutes_in_image[OF that] by auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1504
    finally show "x \<in> ?R".
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1505
  qed
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1506
  show "?R \<subseteq> ?L"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1507
  proof
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1508
    fix x assume "x \<in> ?R"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1509
    then obtain s
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1510
      where x: "x = (s, Hilbert_Choice.inv p s)" (is "_ = (s, ?ips)")
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1511
        and s: "s \<in> S" by auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1512
    note x
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1513
    also have "(s, ?ips) = (p ?ips, ?ips)"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1514
      using inv_f_f[OF permutes_inj[OF permutes_inv[OF that]]]
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1515
      using inv_inv_eq[OF permutes_bij[OF that]] by auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1516
    also have "... \<in> ?L"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1517
      using s permutes_in_image[OF permutes_inv[OF that]] by auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1518
    finally show "x \<in> ?L".
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1519
  qed
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1520
qed
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1521
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1522
context
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1523
  fixes p and n i :: nat
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1524
  assumes p: \<open>p permutes {0..<n}\<close> and i: \<open>i < n\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1525
begin
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1526
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1527
lemma permutes_nat_less:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1528
  \<open>p i < n\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1529
proof -
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1530
  have \<open>?thesis \<longleftrightarrow> p i \<in> {0..<n}\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1531
    by simp
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1532
  also from p have \<open>p i \<in> {0..<n} \<longleftrightarrow> i \<in> {0..<n}\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1533
    by (rule permutes_in_image)
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1534
  finally show ?thesis
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1535
    using i by simp
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1536
qed
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1537
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1538
lemma permutes_nat_inv_less:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1539
  \<open>inv p i < n\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1540
proof -
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1541
  from p have \<open>inv p permutes {0..<n}\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1542
    by (rule permutes_inv)
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1543
  then show ?thesis
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1544
    using i by (rule Permutations.permutes_nat_less)
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1545
qed
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1546
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1547
end
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1548
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1549
context comm_monoid_set
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1550
begin
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1551
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1552
lemma permutes_inv:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1553
  \<open>F (\<lambda>s. g (p s) s) S = F (\<lambda>s. g s (inv p s)) S\<close> (is \<open>?l = ?r\<close>)
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1554
  if \<open>p permutes S\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1555
proof -
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1556
  let ?g = "\<lambda>(x, y). g x y"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1557
  let ?ps = "\<lambda>s. (p s, s)"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1558
  let ?ips = "\<lambda>s. (s, inv p s)"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1559
  have inj1: "inj_on ?ps S" by (rule inj_onI) auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1560
  have inj2: "inj_on ?ips S" by (rule inj_onI) auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1561
  have "?l = F ?g (?ps ` S)"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1562
    using reindex [OF inj1, of ?g] by simp
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1563
  also have "?ps ` S = {(p s, s) |s. s \<in> S}" by auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1564
  also have "... = {(s, inv p s) |s. s \<in> S}"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1565
    unfolding permutes_pair_eq [OF that] by simp
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1566
  also have "... = ?ips ` S" by auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1567
  also have "F ?g ... = ?r"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1568
    using reindex [OF inj2, of ?g] by simp
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1569
  finally show ?thesis.
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1570
qed
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1571
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1572
end
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1573
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1574
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
  1575
subsection \<open>Sum over a set of permutations (could generalize to iteration)\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1576
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63921
diff changeset
  1577
lemma sum_over_permutations_insert:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1578
  assumes fS: "finite S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1579
    and aS: "a \<notin> S"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63921
diff changeset
  1580
  shows "sum f {p. p permutes (insert a S)} =
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
  1581
    sum (\<lambda>b. sum (\<lambda>q. f (transpose a b \<circ> q)) {p. p permutes S}) (insert a S)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1582
proof -
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
  1583
  have *: "\<And>f a b. (\<lambda>(b, p). f (transpose a b \<circ> p)) = f \<circ> (\<lambda>(b,p). transpose a b \<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
  1584
    by (simp add: fun_eq_iff)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1585
  have **: "\<And>P Q. {(a, b). a \<in> P \<and> b \<in> Q} = P \<times> Q"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1586
    by blast
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
  1587
  show ?thesis
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1588
    unfolding * ** sum.cartesian_product permutes_insert
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63921
diff changeset
  1589
  proof (rule sum.reindex)
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
  1590
    let ?f = "(\<lambda>(b, y). transpose a b \<circ> y)"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1591
    let ?P = "{p. p permutes S}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1592
    {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1593
      fix b c p q
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1594
      assume b: "b \<in> insert a S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1595
      assume c: "c \<in> insert a S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1596
      assume p: "p permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1597
      assume q: "q permutes S"
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
  1598
      assume eq: "transpose a b \<circ> p = transpose a c \<circ> q"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1599
      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
  1600
        unfolding permutes_def by metis+
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
  1601
      from eq have "(transpose a b \<circ> p) a  = (transpose a c \<circ> q) a"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1602
        by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1603
      then have bc: "b = c"
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
  1604
        by (simp add: permutes_def pa qa o_def fun_upd_def id_def
62390
842917225d56 more canonical names
nipkow
parents: 61424
diff changeset
  1605
            cong del: if_weak_cong split: if_split_asm)
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
  1606
      from eq[unfolded bc] have "(\<lambda>p. transpose a c \<circ> p) (transpose a c \<circ> p) =
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
  1607
        (\<lambda>p. transpose a c \<circ> p) (transpose a c \<circ> q)" by simp
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1608
      then have "p = q"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1609
        unfolding o_assoc swap_id_idempotent by simp
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1610
      with bc have "b = c \<and> p = q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1611
        by blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1612
    }
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
  1613
    then show "inj_on ?f (insert a S \<times> ?P)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1614
      unfolding inj_on_def by clarify metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1615
  qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1616
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1617
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1618
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1619
subsection \<open>Constructing permutations from association lists\<close>
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1620
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1621
definition list_permutes :: "('a \<times> 'a) list \<Rightarrow> 'a set \<Rightarrow> bool"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1622
  where "list_permutes xs A \<longleftrightarrow>
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1623
    set (map fst xs) \<subseteq> A \<and>
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1624
    set (map snd xs) = set (map fst xs) \<and>
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1625
    distinct (map fst xs) \<and>
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1626
    distinct (map snd xs)"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1627
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1628
lemma list_permutesI [simp]:
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1629
  assumes "set (map fst xs) \<subseteq> A" "set (map snd xs) = set (map fst xs)" "distinct (map fst xs)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1630
  shows "list_permutes xs A"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1631
proof -
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1632
  from assms(2,3) have "distinct (map snd xs)"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1633
    by (intro card_distinct) (simp_all add: distinct_card del: set_map)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1634
  with assms show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1635
    by (simp add: list_permutes_def)
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1636
qed
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1637
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1638
definition permutation_of_list :: "('a \<times> 'a) list \<Rightarrow> 'a \<Rightarrow> 'a"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1639
  where "permutation_of_list xs x = (case map_of xs x of None \<Rightarrow> x | Some y \<Rightarrow> y)"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1640
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1641
lemma permutation_of_list_Cons:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1642
  "permutation_of_list ((x, y) # xs) x' = (if x = x' then y else permutation_of_list xs x')"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1643
  by (simp add: permutation_of_list_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1644
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1645
fun inverse_permutation_of_list :: "('a \<times> 'a) list \<Rightarrow> 'a \<Rightarrow> 'a"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1646
  where
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1647
    "inverse_permutation_of_list [] x = x"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1648
  | "inverse_permutation_of_list ((y, x') # xs) x =
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1649
      (if x = x' then y else inverse_permutation_of_list xs x)"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1650
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1651
declare inverse_permutation_of_list.simps [simp del]
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1652
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1653
lemma inj_on_map_of:
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1654
  assumes "distinct (map snd xs)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1655
  shows "inj_on (map_of xs) (set (map fst xs))"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1656
proof (rule inj_onI)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1657
  fix x y
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1658
  assume xy: "x \<in> set (map fst xs)" "y \<in> set (map fst xs)"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1659
  assume eq: "map_of xs x = map_of xs y"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1660
  from xy obtain x' y' where x'y': "map_of xs x = Some x'" "map_of xs y = Some y'"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1661
    by (cases "map_of xs x"; cases "map_of xs y") (simp_all add: map_of_eq_None_iff)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1662
  moreover from x'y' have *: "(x, x') \<in> set xs" "(y, y') \<in> set xs"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1663
    by (force dest: map_of_SomeD)+
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1664
  moreover from * eq x'y' have "x' = y'"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1665
    by simp
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1666
  ultimately show "x = y"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1667
    using assms by (force simp: distinct_map dest: inj_onD[of _ _ "(x,x')" "(y,y')"])
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1668
qed
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1669
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1670
lemma inj_on_the: "None \<notin> A \<Longrightarrow> inj_on the A"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1671
  by (auto simp: inj_on_def option.the_def split: option.splits)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1672
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1673
lemma inj_on_map_of':
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1674
  assumes "distinct (map snd xs)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1675
  shows "inj_on (the \<circ> map_of xs) (set (map fst xs))"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1676
  by (intro comp_inj_on inj_on_map_of assms inj_on_the)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1677
    (force simp: eq_commute[of None] map_of_eq_None_iff)
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1678
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1679
lemma image_map_of:
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1680
  assumes "distinct (map fst xs)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1681
  shows "map_of xs ` set (map fst xs) = Some ` set (map snd xs)"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1682
  using assms by (auto simp: rev_image_eqI)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1683
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1684
lemma the_Some_image [simp]: "the ` Some ` A = A"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1685
  by (subst image_image) simp
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1686
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1687
lemma image_map_of':
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1688
  assumes "distinct (map fst xs)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1689
  shows "(the \<circ> map_of xs) ` set (map fst xs) = set (map snd xs)"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1690
  by (simp only: image_comp [symmetric] image_map_of assms the_Some_image)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1691
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1692
lemma permutation_of_list_permutes [simp]:
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1693
  assumes "list_permutes xs A"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1694
  shows "permutation_of_list xs permutes A"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1695
    (is "?f permutes _")
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1696
proof (rule permutes_subset[OF bij_imp_permutes])
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1697
  from assms show "set (map fst xs) \<subseteq> A"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1698
    by (simp add: list_permutes_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1699
  from assms have "inj_on (the \<circ> map_of xs) (set (map fst xs))" (is ?P)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1700
    by (intro inj_on_map_of') (simp_all add: list_permutes_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1701
  also have "?P \<longleftrightarrow> inj_on ?f (set (map fst xs))"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1702
    by (intro inj_on_cong)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1703
      (auto simp: permutation_of_list_def map_of_eq_None_iff split: option.splits)
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1704
  finally have "bij_betw ?f (set (map fst xs)) (?f ` set (map fst xs))"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1705
    by (rule inj_on_imp_bij_betw)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1706
  also from assms have "?f ` set (map fst xs) = (the \<circ> map_of xs) ` set (map fst xs)"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1707
    by (intro image_cong refl)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1708
      (auto simp: permutation_of_list_def map_of_eq_None_iff split: option.splits)
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
  1709
  also from assms have "\<dots> = set (map fst xs)"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1710
    by (subst image_map_of') (simp_all add: list_permutes_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1711
  finally show "bij_betw ?f (set (map fst xs)) (set (map fst xs))" .
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1712
qed (force simp: permutation_of_list_def dest!: map_of_SomeD split: option.splits)+
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1713
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1714
lemma eval_permutation_of_list [simp]:
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1715
  "permutation_of_list [] x = x"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1716
  "x = x' \<Longrightarrow> permutation_of_list ((x',y)#xs) x = y"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1717
  "x \<noteq> x' \<Longrightarrow> permutation_of_list ((x',y')#xs) x = permutation_of_list xs x"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1718
  by (simp_all add: permutation_of_list_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1719
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1720
lemma eval_inverse_permutation_of_list [simp]:
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1721
  "inverse_permutation_of_list [] x = x"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1722
  "x = x' \<Longrightarrow> inverse_permutation_of_list ((y,x')#xs) x = y"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1723
  "x \<noteq> x' \<Longrightarrow> inverse_permutation_of_list ((y',x')#xs) x = inverse_permutation_of_list xs x"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1724
  by (simp_all add: inverse_permutation_of_list.simps)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1725
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1726
lemma permutation_of_list_id: "x \<notin> set (map fst xs) \<Longrightarrow> permutation_of_list xs x = x"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1727
  by (induct xs) (auto simp: permutation_of_list_Cons)
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1728
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1729
lemma permutation_of_list_unique':
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1730
  "distinct (map fst xs) \<Longrightarrow> (x, y) \<in> set xs \<Longrightarrow> permutation_of_list xs x = y"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1731
  by (induct xs) (force simp: permutation_of_list_Cons)+
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1732
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1733
lemma permutation_of_list_unique:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1734
  "list_permutes xs A \<Longrightarrow> (x, y) \<in> set xs \<Longrightarrow> permutation_of_list xs x = y"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1735
  by (intro permutation_of_list_unique') (simp_all add: list_permutes_def)
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1736
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1737
lemma inverse_permutation_of_list_id:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1738
  "x \<notin> set (map snd xs) \<Longrightarrow> inverse_permutation_of_list xs x = x"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1739
  by (induct xs) auto
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1740
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1741
lemma inverse_permutation_of_list_unique':
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1742
  "distinct (map snd xs) \<Longrightarrow> (x, y) \<in> set xs \<Longrightarrow> inverse_permutation_of_list xs y = x"
73328
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
  1743
  by (induct xs) (force simp: inverse_permutation_of_list.simps(2))+
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1744
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1745
lemma inverse_permutation_of_list_unique:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1746
  "list_permutes xs A \<Longrightarrow> (x,y) \<in> set xs \<Longrightarrow> inverse_permutation_of_list xs y = x"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1747
  by (intro inverse_permutation_of_list_unique') (simp_all add: list_permutes_def)
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1748
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1749
lemma inverse_permutation_of_list_correct:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1750
  fixes A :: "'a set"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1751
  assumes "list_permutes xs A"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1752
  shows "inverse_permutation_of_list xs = inv (permutation_of_list xs)"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1753
proof (rule ext, rule sym, subst permutes_inv_eq)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1754
  from assms show "permutation_of_list xs permutes A"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1755
    by simp
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1756
  show "permutation_of_list xs (inverse_permutation_of_list xs x) = x" for x
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1757
  proof (cases "x \<in> set (map snd xs)")
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1758
    case True
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1759
    then obtain y where "(y, x) \<in> set xs" by auto
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1760
    with assms show ?thesis
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1761
      by (simp add: inverse_permutation_of_list_unique permutation_of_list_unique)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1762
  next
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1763
    case False
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1764
    with assms show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1765
      by (auto simp: list_permutes_def inverse_permutation_of_list_id permutation_of_list_id)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1766
  qed
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1767
qed
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1768
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1769
end