src/HOL/Combinatorics/Permutations.thy
author Manuel Eberl <eberlm@in.tum.de>
Tue, 03 Jun 2025 12:22:58 +0200
changeset 82683 71304514891e
parent 80777 623d46973cbe
permissions -rw-r--r--
HOL-Combinatorics: more lemmas about permutations
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
82683
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
     2
    
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
     3
    With various additions by Manuel Eberl
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
     4
*)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
     5
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
     6
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
     7
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
     8
theory Permutations
73477
1d8a79aa2a99 dedicated session for combinatorial material
haftmann
parents: 73466
diff changeset
     9
  imports
1d8a79aa2a99 dedicated session for combinatorial material
haftmann
parents: 73466
diff changeset
    10
    "HOL-Library.Multiset"
1d8a79aa2a99 dedicated session for combinatorial material
haftmann
parents: 73466
diff changeset
    11
    "HOL-Library.Disjoint_Sets"
73623
5020054b3a16 tuned theory structure
haftmann
parents: 73621
diff changeset
    12
    Transposition
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    13
begin
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    14
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    15
subsection \<open>Auxiliary\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    16
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    17
abbreviation (input) fixpoints :: \<open>('a \<Rightarrow> 'a) \<Rightarrow> 'a set\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    18
  where \<open>fixpoints f \<equiv> {x. f x = x}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    19
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    20
lemma inj_on_fixpoints:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    21
  \<open>inj_on f (fixpoints f)\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    22
  by (rule inj_onI) simp
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    23
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    24
lemma bij_betw_fixpoints:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    25
  \<open>bij_betw f (fixpoints f) (fixpoints f)\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    26
  using inj_on_fixpoints by (auto simp add: bij_betw_def)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    27
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    28
73328
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
    29
subsection \<open>Basic definition and consequences\<close>
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
    30
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    31
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
    32
  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
    33
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    34
lemma bij_imp_permutes:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    35
  \<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
    36
proof -
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    37
  note \<open>bij_betw p S S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    38
  moreover have \<open>bij_betw p (- S) (- S)\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    39
    by (auto simp add: stable intro!: bij_betw_imageI inj_onI)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    40
  ultimately have \<open>bij_betw p (S \<union> - S) (S \<union> - S)\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    41
    by (rule bij_betw_combine) simp
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    42
  then have \<open>\<exists>!x. p x = y\<close> for y
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    43
    by (simp add: bij_iff)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    44
  with stable show ?thesis
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    45
    by (simp add: permutes_def)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    46
qed
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
    47
82683
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    48
lemma inj_imp_permutes:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    49
  assumes i: "inj_on f S" and fin: "finite S"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    50
  and fS: "\<And>x. x \<in> S \<Longrightarrow> f x \<in> S"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    51
  and f:  "\<And>i. i \<notin> S \<Longrightarrow> f i = i"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    52
  shows "f permutes S"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    53
  unfolding permutes_def
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    54
proof (intro conjI allI impI, rule f)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    55
  fix y
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    56
  from endo_inj_surj[OF fin _ i] fS have fs: "f ` S = S" by auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    57
  show "\<exists>!x. f x = y"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    58
  proof (cases "y \<in> S")
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    59
    case False
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    60
    thus ?thesis by (intro ex1I[of _ y], insert fS f) force+
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    61
  next
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    62
    case True
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    63
    with fs obtain x where x: "x \<in> S" and fx: "f x = y" by force
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    64
    show ?thesis
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    65
    proof (rule ex1I, rule fx)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    66
      fix x'
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    67
      assume fx': "f x' = y"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    68
      with True f[of x'] have "x' \<in> S" by metis
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    69
      from inj_onD[OF i fx[folded fx'] x this]
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    70
      show "x' = x" by simp
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    71
    qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    72
  qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    73
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
    74
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    75
context
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    76
  fixes p :: \<open>'a \<Rightarrow> 'a\<close> and S :: \<open>'a set\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    77
  assumes perm: \<open>p permutes S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    78
begin
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    79
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    80
lemma permutes_inj:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    81
  \<open>inj p\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    82
  using perm by (auto simp: permutes_def inj_on_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
    83
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    84
lemma permutes_image:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    85
  \<open>p ` S = S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    86
proof (rule set_eqI)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    87
  fix x
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    88
  show \<open>x \<in> p ` S \<longleftrightarrow> x \<in> S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    89
  proof
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    90
    assume \<open>x \<in> p ` S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    91
    then obtain y where \<open>y \<in> S\<close> \<open>p y = x\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    92
      by blast
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    93
    with perm show \<open>x \<in> S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    94
      by (cases \<open>y = x\<close>) (auto simp add: permutes_def)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    95
  next
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    96
    assume \<open>x \<in> S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    97
    with perm obtain y where \<open>y \<in> S\<close> \<open>p y = x\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    98
      by (metis permutes_def)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
    99
    then show \<open>x \<in> p ` S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   100
      by blast
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   101
  qed
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   102
qed
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   103
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   104
lemma permutes_not_in:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   105
  \<open>x \<notin> S \<Longrightarrow> p x = x\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   106
  using perm by (auto simp: permutes_def)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   107
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   108
lemma permutes_image_complement:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   109
  \<open>p ` (- S) = - S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   110
  by (auto simp add: permutes_not_in)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   111
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   112
lemma permutes_in_image:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   113
  \<open>p x \<in> S \<longleftrightarrow> x \<in> S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   114
  using permutes_image permutes_inj by (auto dest: inj_image_mem_iff)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   115
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   116
lemma permutes_surj:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   117
  \<open>surj p\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   118
proof -
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   119
  have \<open>p ` (S \<union> - S) = p ` S \<union> p ` (- S)\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   120
    by (rule image_Un)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   121
  then show ?thesis
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   122
    by (simp add: permutes_image permutes_image_complement)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   123
qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   124
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   125
lemma permutes_inv_o:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   126
  shows "p \<circ> inv p = id"
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   127
    and "inv p \<circ> p = id"
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   128
  using permutes_inj permutes_surj
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   129
  unfolding inj_iff [symmetric] surj_iff [symmetric] by auto
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   130
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   131
lemma permutes_inverses:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   132
  shows "p (inv p x) = x"
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   133
    and "inv p (p x) = x"
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   134
  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
   135
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   136
lemma permutes_inv_eq:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   137
  \<open>inv p y = x \<longleftrightarrow> p x = y\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   138
  by (auto simp add: permutes_inverses)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   139
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   140
lemma permutes_inj_on:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   141
  \<open>inj_on p A\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   142
  by (rule inj_on_subset [of _ UNIV]) (auto intro: permutes_inj)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   143
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   144
lemma permutes_bij:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   145
  \<open>bij p\<close>
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   146
  unfolding bij_def by (metis permutes_inj permutes_surj)
60601
6e83d94760c4 added lemma
nipkow
parents: 60500
diff changeset
   147
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   148
lemma permutes_imp_bij:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   149
  \<open>bij_betw p S S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   150
  by (simp add: bij_betw_def permutes_image permutes_inj_on)
59474
4475b1a0141d related permutations with bij functions
hoelzl
parents: 58881
diff changeset
   151
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   152
lemma permutes_subset:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   153
  \<open>p permutes T\<close> if \<open>S \<subseteq> T\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   154
proof (rule bij_imp_permutes)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   155
  define R where \<open>R = T - S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   156
  with that have \<open>T = R \<union> S\<close> \<open>R \<inter> S = {}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   157
    by auto
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   158
  then have \<open>p x = x\<close> if \<open>x \<in> R\<close> for x
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   159
    using that by (auto intro: permutes_not_in)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   160
  then have \<open>p ` R = R\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   161
    by simp
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   162
  with \<open>T = R \<union> S\<close> show \<open>bij_betw p T T\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   163
    by (simp add: bij_betw_def permutes_inj_on image_Un permutes_image)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   164
  fix x
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   165
  assume \<open>x \<notin> T\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   166
  with \<open>T = R \<union> S\<close> show \<open>p x = x\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   167
    by (simp add: permutes_not_in)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   168
qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   169
73410
haftmann
parents: 73328
diff changeset
   170
lemma permutes_imp_permutes_insert:
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   171
  \<open>p permutes insert x S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   172
  by (rule permutes_subset) auto
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   173
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   174
end
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   175
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   176
lemma permutes_id [simp]:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   177
  \<open>id permutes S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   178
  by (auto intro: bij_imp_permutes)
73410
haftmann
parents: 73328
diff changeset
   179
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   180
lemma permutes_empty [simp]:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   181
  \<open>p permutes {} \<longleftrightarrow> p = id\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   182
proof
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   183
  assume \<open>p permutes {}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   184
  then show \<open>p = id\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   185
    by (auto simp add: fun_eq_iff permutes_not_in)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   186
next
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   187
  assume \<open>p = id\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   188
  then show \<open>p permutes {}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   189
    by simp
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   190
qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   191
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   192
lemma permutes_sing [simp]:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   193
  \<open>p permutes {a} \<longleftrightarrow> p = id\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   194
proof
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   195
  assume perm: \<open>p permutes {a}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   196
  show \<open>p = id\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   197
  proof
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   198
    fix x
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   199
    from perm have \<open>p ` {a} = {a}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   200
      by (rule permutes_image)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   201
    with perm show \<open>p x = id x\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   202
      by (cases \<open>x = a\<close>) (auto simp add: permutes_not_in)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   203
  qed
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   204
next
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   205
  assume \<open>p = id\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   206
  then show \<open>p permutes {a}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   207
    by simp
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   208
qed
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   209
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   210
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
   211
  by (simp add: permutes_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   212
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   213
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
   214
  by (rule bij_imp_permutes) (auto intro: transpose_apply_other)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   215
82683
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   216
lemma permutes_altdef: "p permutes A \<longleftrightarrow> bij_betw p A A \<and> {x. p x \<noteq> x} \<subseteq> A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   217
  using permutes_not_in[of p A]
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   218
  by (auto simp: permutes_imp_bij intro!: bij_imp_permutes)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   219
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   220
lemma permutes_superset:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   221
  \<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
   222
proof -
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   223
  define R U where \<open>R = T \<inter> S\<close> and \<open>U = S - T\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   224
  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
   225
    by auto
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   226
  from that \<open>U = S - T\<close> have \<open>p ` U = U\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   227
    by simp
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   228
  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
   229
    by (simp add: permutes_imp_bij \<open>S = R \<union> U\<close>)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   230
  moreover have \<open>bij_betw p U U\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   231
    using that \<open>U = S - T\<close> by (simp add: bij_betw_def permutes_inj_on)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   232
  ultimately have \<open>bij_betw p R R\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   233
    using \<open>R \<inter> U = {}\<close> \<open>R \<inter> U = {}\<close> by (rule bij_betw_partition)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   234
  then have \<open>p permutes R\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   235
  proof (rule bij_imp_permutes)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   236
    fix x
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   237
    assume \<open>x \<notin> R\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   238
    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
   239
      by (cases \<open>x \<in> S\<close>) (auto simp add: permutes_not_in that(2))
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   240
  qed
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   241
  then have \<open>p permutes R \<union> (T - S)\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   242
    by (rule permutes_subset) simp
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   243
  with \<open>T = R \<union> (T - S)\<close> show ?thesis
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   244
    by simp
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   245
qed
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   246
69895
6b03a8cf092d more formal contributors (with the help of the history);
wenzelm
parents: 67673
diff changeset
   247
lemma permutes_bij_inv_into: \<^marker>\<open>contributor \<open>Lukas Bulwahn\<close>\<close>
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   248
  fixes A :: "'a set"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   249
    and B :: "'b set"
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   250
  assumes "p permutes A"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   251
    and "bij_betw f A B"
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   252
  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
   253
proof (rule bij_imp_permutes)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   254
  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
   255
    by (auto simp add: permutes_imp_bij bij_betw_inv_into)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   256
  then have "bij_betw (f \<circ> p \<circ> inv_into A f) B B"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   257
    by (simp add: bij_betw_trans)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   258
  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
   259
    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
   260
next
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   261
  fix x
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   262
  assume "x \<notin> B"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   263
  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
   264
qed
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   265
69895
6b03a8cf092d more formal contributors (with the help of the history);
wenzelm
parents: 67673
diff changeset
   266
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
   267
  assumes "p permutes A"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   268
  shows "image_mset p (mset_set A) = mset_set A"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   269
  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
   270
69895
6b03a8cf092d more formal contributors (with the help of the history);
wenzelm
parents: 67673
diff changeset
   271
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
   272
  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
   273
  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
   274
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   275
  have "f x = f' (p x)" if "x \<in># mset_set A" for x
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   276
    using assms(2)[of x] that by (cases "finite A") auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   277
  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
   278
    by (auto intro!: image_mset_cong)
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   279
  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
   280
    by (simp add: image_mset.compositionality)
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   281
  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
   282
  proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   283
    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
   284
      by blast
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   285
    then show ?thesis by simp
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   286
  qed
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   287
  finally show ?thesis ..
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   288
qed
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
   289
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   290
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   291
subsection \<open>Group properties\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   292
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   293
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
   294
  unfolding permutes_def o_def by metis
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   295
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   296
lemma permutes_inv:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   297
  assumes "p permutes S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   298
  shows "inv p permutes S"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   299
  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
   300
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   301
lemma permutes_inv_inv:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   302
  assumes "p permutes S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   303
  shows "inv (inv p) = p"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   304
  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
   305
  by blast
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   306
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
   307
lemma permutes_invI:
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
   308
  assumes perm: "p permutes S"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   309
    and inv: "\<And>x. x \<in> S \<Longrightarrow> p' (p x) = x"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   310
    and outside: "\<And>x. x \<notin> S \<Longrightarrow> p' x = x"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   311
  shows "inv p = p'"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
   312
proof
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   313
  show "inv p x = p' x" for x
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
   314
  proof (cases "x \<in> S")
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   315
    case True
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   316
    from assms have "p' x = p' (p (inv p x))"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   317
      by (simp add: permutes_inverses)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   318
    also from permutes_inv[OF perm] True have "\<dots> = inv p x"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   319
      by (subst inv) (simp_all add: permutes_in_image)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   320
    finally show ?thesis ..
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   321
  next
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   322
    case False
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   323
    with permutes_inv[OF perm] show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   324
      by (simp_all add: outside permutes_not_in)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   325
  qed
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
   326
qed
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
   327
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
   328
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
   329
  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
   330
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   331
82683
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   332
subsection \<open>Restricting a permutation to a subset\<close>
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   333
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   334
definition restrict_id :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a set \<Rightarrow> 'a \<Rightarrow> 'a"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   335
  where "restrict_id f A = (\<lambda>x. if x \<in> A then f x else x)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   336
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   337
lemma restrict_id_cong [cong]:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   338
  assumes "\<And>x. x \<in> A \<Longrightarrow> f x = g x" "A = B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   339
  shows   "restrict_id f A = restrict_id g B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   340
  using assms unfolding restrict_id_def by auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   341
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   342
lemma restrict_id_cong':
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   343
  assumes "x \<in> A \<Longrightarrow> f x = g x" "A = B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   344
  shows   "restrict_id f A x = restrict_id g B x"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   345
  using assms unfolding restrict_id_def by auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   346
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   347
lemma restrict_id_simps [simp]:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   348
  "x \<in> A \<Longrightarrow> restrict_id f A x = f x"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   349
  "x \<notin> A \<Longrightarrow> restrict_id f A x = x"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   350
  by (auto simp: restrict_id_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   351
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   352
lemma bij_betw_restrict_id:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   353
  assumes "bij_betw f A A" "A \<subseteq> B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   354
  shows   "bij_betw (restrict_id f A) B B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   355
proof -
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   356
  have "bij_betw (restrict_id f A) (A \<union> (B - A)) (A \<union> (B - A))"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   357
    unfolding restrict_id_def
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   358
    by (rule bij_betw_disjoint_Un) (use assms in \<open>auto intro: bij_betwI\<close>)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   359
  also have "A \<union> (B - A) = B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   360
    using assms(2) by blast
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   361
  finally show ?thesis .
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   362
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   363
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   364
lemma permutes_restrict_id:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   365
  assumes "bij_betw f A A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   366
  shows   "restrict_id f A permutes A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   367
  by (intro bij_imp_permutes bij_betw_restrict_id assms) auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   368
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   369
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   370
subsection \<open>Mapping a permutation\<close>
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   371
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   372
definition map_permutation :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> 'b \<Rightarrow> 'b" where
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   373
  "map_permutation A f p = restrict_id (f \<circ> p \<circ> inv_into A f) (f ` A)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   374
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   375
lemma map_permutation_cong_strong:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   376
  assumes "A = B" "\<And>x. x \<in> A \<Longrightarrow> f x = g x" "\<And>x. x \<in> A \<Longrightarrow> p x = q x"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   377
  assumes "p ` A \<subseteq> A" "inj_on f A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   378
  shows   "map_permutation A f p = map_permutation B g q"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   379
proof -
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   380
  have fg: "f x = g y" if "x \<in> A" "x = y" for x y
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   381
    using assms(2) that by simp
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   382
  have pq: "p x = q y" if "x \<in> A" "x = y" for x y
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   383
    using assms(3) that by simp
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   384
  have p: "p x \<in> A" if "x \<in> A" for x
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   385
    using assms(4) that by blast
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   386
  have inv: "inv_into A f x = inv_into B g y" if "x \<in> f ` A" "x = y" for x y
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   387
  proof -
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   388
    from that obtain u where u: "u \<in> A" "x = f u"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   389
      by blast
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   390
    have "inv_into A f (f u) = inv_into A g (f u)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   391
      using \<open>inj_on f A\<close> u(1) by (metis assms(2) inj_on_cong inv_into_f_f)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   392
    thus ?thesis
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   393
      using u \<open>x = y\<close> \<open>A = B\<close> by simp
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   394
  qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   395
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   396
  show ?thesis
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   397
    unfolding map_permutation_def o_def
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   398
    by (intro restrict_id_cong image_cong fg pq inv_into_into p inv) (auto simp: \<open>A = B\<close>)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   399
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   400
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   401
lemma map_permutation_cong:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   402
  assumes "inj_on f A" "p permutes A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   403
  assumes "A = B" "\<And>x. x \<in> A \<Longrightarrow> f x = g x" "\<And>x. x \<in> A \<Longrightarrow> p x = q x"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   404
  shows   "map_permutation A f p = map_permutation B g q"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   405
proof (intro map_permutation_cong_strong assms)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   406
  show "p ` A \<subseteq> A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   407
    using \<open>p permutes A\<close> by (simp add: permutes_image)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   408
qed auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   409
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   410
lemma inv_into_id [simp]: "x \<in> A \<Longrightarrow> inv_into A id x = x"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   411
  by (metis f_inv_into_f id_apply image_eqI)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   412
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   413
lemma inv_into_ident [simp]: "x \<in> A \<Longrightarrow> inv_into A (\<lambda>x. x) x = x"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   414
  by (metis f_inv_into_f image_eqI)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   415
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   416
lemma map_permutation_id [simp]: "p permutes A \<Longrightarrow> map_permutation A id p = p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   417
  by (auto simp: fun_eq_iff map_permutation_def restrict_id_def permutes_not_in)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   418
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   419
lemma map_permutation_ident [simp]: "p permutes A \<Longrightarrow> map_permutation A (\<lambda>x. x) p = p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   420
  by (auto simp: fun_eq_iff map_permutation_def restrict_id_def permutes_not_in)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   421
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   422
lemma map_permutation_id': "inj_on f A \<Longrightarrow> map_permutation A f id = id"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   423
  unfolding map_permutation_def by (auto simp: restrict_id_def fun_eq_iff)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   424
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   425
lemma map_permutation_ident': "inj_on f A \<Longrightarrow> map_permutation A f (\<lambda>x. x) = (\<lambda>x. x)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   426
  unfolding map_permutation_def by (auto simp: restrict_id_def fun_eq_iff)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   427
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   428
lemma map_permutation_permutes:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   429
  assumes "bij_betw f A B" "p permutes A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   430
  shows   "map_permutation A f p permutes B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   431
proof (rule bij_imp_permutes)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   432
  have f_A: "f ` A = B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   433
    using assms(1) by (auto simp: bij_betw_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   434
  from assms(2) have "bij_betw p A A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   435
    by (simp add: permutes_imp_bij)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   436
  show "bij_betw (map_permutation A f p) B B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   437
    unfolding map_permutation_def f_A
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   438
    by (rule bij_betw_restrict_id bij_betw_trans bij_betw_inv_into assms(1)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   439
             permutes_imp_bij[OF assms(2)] order.refl)+
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   440
  show "map_permutation A f p x = x" if "x \<notin> B" for x
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   441
    using that unfolding map_permutation_def f_A by simp
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   442
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   443
                                                        
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   444
lemma map_permutation_compose:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   445
  fixes f :: "'a \<Rightarrow> 'b" and g :: "'b \<Rightarrow> 'c"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   446
  assumes "bij_betw f A B" "inj_on g B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   447
  shows   "map_permutation B g (map_permutation A f p) = map_permutation A (g \<circ> f) p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   448
proof
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   449
  fix c :: 'c
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   450
  have bij_g: "bij_betw g B (g ` B)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   451
    using \<open>inj_on g B\<close> unfolding bij_betw_def by blast
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   452
  have [simp]: "f x = f y \<longleftrightarrow> x = y" if "x \<in> A" "y \<in> A" for x y
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   453
    using assms(1) that by (auto simp: bij_betw_def inj_on_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   454
  have [simp]: "g x = g y \<longleftrightarrow> x = y" if "x \<in> B" "y \<in> B" for x y
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   455
    using assms(2) that by (auto simp: bij_betw_def inj_on_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   456
  show "map_permutation B g (map_permutation A f p) c = map_permutation A (g \<circ> f) p c"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   457
  proof (cases "c \<in> g ` B")
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   458
    case c: True
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   459
    then obtain a where a: "a \<in> A" "c = g (f a)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   460
      using assms(1,2) unfolding bij_betw_def by auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   461
    have "map_permutation B g (map_permutation A f p) c = g (f (p a))"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   462
      using a assms by (auto simp: map_permutation_def restrict_id_def bij_betw_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   463
    also have "\<dots> = map_permutation A (g \<circ> f) p c"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   464
      using a bij_betw_inv_into_left[OF bij_betw_trans[OF assms(1) bij_g]]
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   465
      by (auto simp: map_permutation_def restrict_id_def bij_betw_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   466
    finally show ?thesis .
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   467
  next
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   468
    case c: False
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   469
    thus ?thesis using assms
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   470
      by (auto simp: map_permutation_def bij_betw_def restrict_id_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   471
  qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   472
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   473
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   474
lemma map_permutation_compose_inv:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   475
  assumes "bij_betw f A B" "p permutes A" "\<And>x. x \<in> A \<Longrightarrow> g (f x) = x"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   476
  shows   "map_permutation B g (map_permutation A f p) = p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   477
proof -
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   478
  have "inj_on g B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   479
  proof
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   480
    fix x y assume "x \<in> B" "y \<in> B" "g x = g y"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   481
    then obtain x' y' where *: "x' \<in> A" "y' :  A" "x = f x'" "y = f y'"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   482
      using assms(1) unfolding bij_betw_def by blast
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   483
    thus "x = y"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   484
      using assms(3)[of x'] assms(3)[of y'] \<open>g x = g y\<close> by simp
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   485
  qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   486
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   487
  have "map_permutation B g (map_permutation A f p) = map_permutation A (g \<circ> f) p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   488
    by (rule map_permutation_compose) (use assms \<open>inj_on g B\<close> in auto)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   489
  also have "\<dots> = map_permutation A id p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   490
    by (intro map_permutation_cong assms comp_inj_on)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   491
       (use \<open>inj_on g B\<close> assms(1,3) in \<open>auto simp: bij_betw_def\<close>)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   492
  also have "\<dots> = p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   493
    by (rule map_permutation_id) fact
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   494
  finally show ?thesis .
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   495
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   496
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   497
lemma map_permutation_apply:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   498
  assumes "inj_on f A" "x \<in> A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   499
  shows   "map_permutation A f h (f x) = f (h x)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   500
  using assms by (auto simp: map_permutation_def inj_on_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   501
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   502
lemma map_permutation_compose':
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   503
  fixes f :: "'a \<Rightarrow> 'b"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   504
  assumes "inj_on f A" "q permutes A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   505
  shows   "map_permutation A f (p \<circ> q) = map_permutation A f p \<circ> map_permutation A f q"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   506
proof
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   507
  fix y :: 'b
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   508
  show "map_permutation A f (p \<circ> q) y = (map_permutation A f p \<circ> map_permutation A f q) y"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   509
  proof (cases "y \<in> f ` A")
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   510
    case True
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   511
    then obtain x where x: "x \<in> A" "y = f x"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   512
      by blast
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   513
    have "map_permutation A f (p \<circ> q) y = f (p (q x))"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   514
      unfolding x(2) by (subst map_permutation_apply) (use assms x in auto)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   515
    also have "\<dots> = (map_permutation A f p \<circ> map_permutation A f q) y"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   516
      unfolding x o_apply using x(1) assms
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   517
      by (simp add: map_permutation_apply permutes_in_image)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   518
    finally show ?thesis .
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   519
  next
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   520
    case False
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   521
    thus ?thesis
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   522
      using False by (simp add: map_permutation_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   523
  qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   524
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   525
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   526
lemma map_permutation_transpose:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   527
  assumes "inj_on f A" "a \<in> A" "b \<in> A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   528
  shows   "map_permutation A f (Transposition.transpose a b) = Transposition.transpose (f a) (f b)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   529
proof
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   530
  fix y :: 'b
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   531
  show "map_permutation A f (Transposition.transpose a b) y = Transposition.transpose (f a) (f b) y"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   532
  proof (cases "y \<in> f ` A")
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   533
    case False
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   534
    hence "map_permutation A f (Transposition.transpose a b) y = y"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   535
      unfolding map_permutation_def by (intro restrict_id_simps)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   536
    moreover have "Transposition.transpose (f a) (f b) y = y"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   537
      using False assms by (intro transpose_apply_other) auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   538
    ultimately show ?thesis
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   539
      by simp
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   540
  next
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   541
    case True
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   542
    then obtain x where x: "x \<in> A" "y = f x"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   543
      by blast
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   544
    have "map_permutation A f (Transposition.transpose a b) y =
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   545
            f (Transposition.transpose a b x)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   546
      unfolding x by (subst map_permutation_apply) (use x assms in auto)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   547
    also have "\<dots> = Transposition.transpose (f a) (f b) y"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   548
      using assms(2,3) x
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   549
      by (auto simp: Transposition.transpose_def inj_on_eq_iff[OF assms(1)])
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   550
    finally show ?thesis .
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   551
  qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   552
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   553
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   554
lemma map_permutation_permutes_iff:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   555
  assumes "bij_betw f A B" "p ` A \<subseteq> A" "\<And>x. x \<notin> A \<Longrightarrow> p x = x"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   556
  shows   "map_permutation A f p permutes B \<longleftrightarrow> p permutes A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   557
proof
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   558
  assume "p permutes A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   559
  thus "map_permutation A f p permutes B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   560
    by (intro map_permutation_permutes assms)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   561
next
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   562
  assume *: "map_permutation A f p permutes B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   563
  hence "map_permutation B (inv_into A f) (map_permutation A f p) permutes A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   564
    by (rule map_permutation_permutes[OF bij_betw_inv_into[OF assms(1)]])
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   565
  also have "map_permutation B (inv_into A f) (map_permutation A f p) = 
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   566
             map_permutation A (inv_into A f \<circ> f) p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   567
    by (rule map_permutation_compose[OF _ inj_on_inv_into]) 
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   568
       (use assms in \<open>auto simp: bij_betw_def\<close>)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   569
  also have "\<dots> = map_permutation A id p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   570
    unfolding o_def id_def
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   571
    by (rule sym, intro map_permutation_cong_strong inv_into_f_f[symmetric]
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   572
          assms(2) bij_betw_imp_inj_on[OF assms(1)]) auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   573
  also have "\<dots> = p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   574
    unfolding map_permutation_def using assms(3)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   575
    by (auto simp: restrict_id_def fun_eq_iff split: if_splits)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   576
  finally show "p permutes A" .
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   577
qed
66486
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   578
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   579
lemma bij_betw_permutations:
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   580
  assumes "bij_betw f A B"
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   581
  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
   582
             {\<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
   583
proof -
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   584
  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
   585
  show ?thesis
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   586
  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
   587
    case 3
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   588
    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
   589
  next
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   590
    case 4
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   591
    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
   592
    {
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   593
      fix \<pi> assume "\<pi> permutes B"
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   594
      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
   595
        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
   596
        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
   597
    }
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   598
    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
   599
  next
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   600
    case 1
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   601
    thus ?case using assms
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   602
      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
   603
               dest: bij_betwE)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   604
  next
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   605
    case 2
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   606
    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
   607
      by (intro bij_betw_inv_into assms)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   608
    ultimately show ?case using assms
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   609
      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
   610
               dest: bij_betwE)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   611
  qed
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   612
qed
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   613
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   614
lemma bij_betw_derangements:
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   615
  assumes "bij_betw f A B"
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   616
  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
   617
             {\<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
   618
           (is "bij_betw ?f _ _")
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   619
proof -
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   620
  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
   621
  show ?thesis
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   622
  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
   623
    case 3
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   624
    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
   625
      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
   626
                                     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
   627
    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
   628
  next
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   629
    case 4
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   630
    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
   631
    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
   632
      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
   633
      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
   634
    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
   635
      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
   636
    ultimately show ?case by auto
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   637
  next
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   638
    case 1
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   639
    thus ?case using assms
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   640
      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
   641
                dest: bij_betwE)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   642
  next
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   643
    case 2
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   644
    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
   645
      by (intro bij_betw_inv_into assms)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   646
    ultimately show ?case using assms
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   647
      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
   648
                dest: bij_betwE)
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   649
  qed
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   650
qed
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   651
ffaaa83543b2 Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 65552
diff changeset
   652
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   653
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
   654
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   655
lemma permutes_insert_lemma:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   656
  assumes "p permutes (insert a S)"
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   657
  shows "transpose a (p a) \<circ> p permutes S"
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   658
proof (rule permutes_superset[where S = "insert a S"])
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   659
  show "Transposition.transpose a (p a) \<circ> p permutes insert a S"
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   660
    by (meson assms insertI1 permutes_compose permutes_in_image permutes_swap_id)
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   661
qed auto
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   662
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   663
lemma permutes_insert: "{p. p permutes (insert a S)} =
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   664
  (\<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
   665
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   666
  have "p permutes insert a S \<longleftrightarrow>
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   667
    (\<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
   668
  proof -
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   669
    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
   670
      if p: "p permutes insert a S"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   671
    proof -
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   672
      let ?b = "p a"
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   673
      let ?q = "transpose a (p a) \<circ> p"
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   674
      have *: "p = transpose a ?b \<circ> ?q"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   675
        by (simp add: fun_eq_iff o_assoc)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   676
      have **: "?b \<in> insert a S"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   677
        unfolding permutes_in_image[OF p] by simp
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   678
      from permutes_insert_lemma[OF p] * ** show ?thesis
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   679
        by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   680
    qed
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   681
    moreover have "p permutes insert a S"
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   682
      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
   683
    proof -
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   684
      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
   685
        by auto
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   686
      have a: "a \<in> insert a S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   687
        by simp
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   688
      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
   689
        by simp
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   690
    qed
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   691
    ultimately show ?thesis by blast
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   692
  qed
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   693
  then show ?thesis by auto
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   694
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   695
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   696
lemma card_permutations:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   697
  assumes "card S = n"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   698
    and "finite S"
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   699
  shows "card {p. p permutes S} = fact n"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   700
  using assms(2,1)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   701
proof (induct arbitrary: n)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   702
  case empty
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   703
  then show ?case by simp
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   704
next
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   705
  case (insert x F)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   706
  {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   707
    fix n
72304
6fdeef6d6335 reverted the substitution here
paulson <lp15@cam.ac.uk>
parents: 72302
diff changeset
   708
    assume card_insert: "card (insert x F) = n"
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   709
    let ?xF = "{p. p permutes insert x F}"
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   710
    let ?pF = "{p. p permutes F}"
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   711
    let ?pF' = "{(b, p). b \<in> insert x F \<and> p \<in> ?pF}"
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   712
    let ?g = "(\<lambda>(b, p). transpose x b \<circ> p)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   713
    have xfgpF': "?xF = ?g ` ?pF'"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   714
      by (rule permutes_insert[of x F])
72304
6fdeef6d6335 reverted the substitution here
paulson <lp15@cam.ac.uk>
parents: 72302
diff changeset
   715
    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
   716
      by auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   717
    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
   718
      by auto
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   719
    then have "finite ?pF"
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 59669
diff changeset
   720
      by (auto intro: card_ge_0_finite)
72302
d7d90ed4c74e fixed some remarkably ugly proofs
paulson <lp15@cam.ac.uk>
parents: 69895
diff changeset
   721
    with \<open>finite F\<close> card.insert_remove have pF'f: "finite ?pF'"
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   722
      by simp
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   723
    have ginj: "inj_on ?g ?pF'"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   724
    proof -
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   725
      {
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   726
        fix b p c q
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   727
        assume bp: "(b, p) \<in> ?pF'"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   728
        assume cq: "(c, q) \<in> ?pF'"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   729
        assume eq: "?g (b, p) = ?g (c, q)"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   730
        from bp cq have pF: "p permutes F" and qF: "q permutes F"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   731
          by auto
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   732
        from pF \<open>x \<notin> F\<close> eq have "b = ?g (b, p) x"
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   733
          by (auto simp: permutes_def fun_upd_def fun_eq_iff)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   734
        also from qF \<open>x \<notin> F\<close> eq have "\<dots> = ?g (c, q) x"
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   735
          by (auto simp: fun_upd_def fun_eq_iff)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   736
        also from qF \<open>x \<notin> F\<close> have "\<dots> = c"
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   737
          by (auto simp: permutes_def fun_upd_def fun_eq_iff)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   738
        finally have "b = c" .
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   739
        then have "transpose x b = transpose x c"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   740
          by simp
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   741
        with eq have "transpose x b \<circ> p = transpose x b \<circ> q"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   742
          by simp
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   743
        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
   744
          by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   745
        then have "p = q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   746
          by (simp add: o_assoc)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   747
        with \<open>b = c\<close> have "(b, p) = (c, q)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   748
          by simp
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   749
      }
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   750
      then show ?thesis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   751
        unfolding inj_on_def by blast
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   752
    qed
72304
6fdeef6d6335 reverted the substitution here
paulson <lp15@cam.ac.uk>
parents: 72302
diff changeset
   753
    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
   754
      by auto
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   755
    then have "\<exists>m. n = Suc m"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   756
      by presburger
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   757
    then obtain m where n: "n = Suc m"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   758
      by blast
72304
6fdeef6d6335 reverted the substitution here
paulson <lp15@cam.ac.uk>
parents: 72302
diff changeset
   759
    from pFs card_insert have *: "card ?xF = fact n"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   760
      unfolding xfgpF' card_image[OF ginj]
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   761
      using \<open>finite F\<close> \<open>finite ?pF\<close>
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   762
      by (simp only: Collect_case_prod Collect_mem_eq card_cartesian_product) (simp add: n)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   763
    from finite_imageI[OF pF'f, of ?g] have xFf: "finite ?xF"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   764
      by (simp add: xfgpF' n)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   765
    from * have "card ?xF = fact n"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   766
      unfolding xFf by blast
33715
8cce3a34c122 removed hassize predicate
hoelzl
parents: 33057
diff changeset
   767
  }
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   768
  with insert show ?case by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   769
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   770
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   771
lemma finite_permutations:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   772
  assumes "finite S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   773
  shows "finite {p. p permutes S}"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   774
  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
   775
82683
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   776
lemma permutes_doubleton_iff: "f permutes {a, b} \<longleftrightarrow> f = id \<or> f = Transposition.transpose a b"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   777
proof (cases "a = b")
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   778
  case False
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   779
  have "{id, Transposition.transpose a b} \<subseteq> {f. f permutes {a, b}}"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   780
    by (auto simp: permutes_id permutes_swap_id)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   781
  moreover have "id \<noteq> Transposition.transpose a b"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   782
    using False by (auto simp: fun_eq_iff Transposition.transpose_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   783
  hence "card {id, Transposition.transpose a b} = card {f. f permutes {a, b}}"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   784
    using False by (simp add: card_permutations)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   785
  ultimately have "{id, Transposition.transpose a b} = {f. f permutes {a, b}}"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   786
    by (intro card_subset_eq finite_permutations) auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   787
  thus ?thesis by auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
   788
qed auto
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   789
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
   790
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   791
subsection \<open>Permutations of index set for iterated operations\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   792
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   793
lemma (in comm_monoid_set) permute:
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   794
  assumes "p permutes S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   795
  shows "F g S = F (g \<circ> p) S"
51489
f738e6dbd844 fundamental revision of big operators on sets
haftmann
parents: 49739
diff changeset
   796
proof -
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   797
  from \<open>p permutes S\<close> have "inj p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   798
    by (rule permutes_inj)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   799
  then have "inj_on p S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   800
    by (auto intro: subset_inj_on)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   801
  then have "F g (p ` S) = F (g \<circ> p) S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   802
    by (rule reindex)
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   803
  moreover from \<open>p permutes S\<close> have "p ` S = S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   804
    by (rule permutes_image)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   805
  ultimately show ?thesis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   806
    by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   807
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   808
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   809
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   810
subsection \<open>Permutations as transposition sequences\<close>
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   811
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   812
inductive swapidseq :: "nat \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> bool"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   813
  where
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   814
    id[simp]: "swapidseq 0 id"
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   815
  | 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
   816
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   817
declare id[unfolded id_def, simp]
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   818
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   819
definition "permutation p \<longleftrightarrow> (\<exists>n. swapidseq n p)"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   820
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   821
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   822
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
   823
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   824
lemma permutation_id[simp]: "permutation id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   825
  unfolding permutation_def by (rule exI[where x=0]) simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   826
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   827
declare permutation_id[unfolded id_def, simp]
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   828
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   829
lemma swapidseq_swap: "swapidseq (if a = b then 0 else 1) (transpose a b)"
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   830
  using swapidseq.simps by fastforce
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   831
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   832
lemma permutation_swap_id: "permutation (transpose a b)"
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   833
  by (meson permutation_def swapidseq_swap)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   834
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   835
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   836
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
   837
proof (induct n p arbitrary: m q rule: swapidseq.induct)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   838
  case (id m q)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   839
  then show ?case by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   840
next
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   841
  case (comp_Suc n p a b m q)
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   842
  then show ?case
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   843
    by (metis add_Suc comp_assoc swapidseq.comp_Suc)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   844
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   845
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   846
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
   847
  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
   848
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   849
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
   850
  by (induct n p rule: swapidseq.induct)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   851
    (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
   852
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   853
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
   854
proof (induct n p rule: swapidseq.induct)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   855
  case id
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   856
  then show ?case
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   857
    by (rule exI[where x=id]) simp
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   858
next
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   859
  case (comp_Suc n p a b)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   860
  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
   861
    by blast
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   862
  let ?q = "q \<circ> transpose a b"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   863
  note H = comp_Suc.hyps
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   864
  from swapidseq_swap[of a b] H(3) have *: "swapidseq 1 (transpose a b)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   865
    by simp
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   866
  from swapidseq_comp_add[OF q(1) *] have **: "swapidseq (Suc n) ?q"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   867
    by simp
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   868
  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
   869
    by (simp add: o_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   870
  also have "\<dots> = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   871
    by (simp add: q(2))
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   872
  finally have ***: "transpose a b \<circ> p \<circ> ?q = id" .
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   873
  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
   874
    by (simp only: o_assoc)
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   875
  then have "?q \<circ> (transpose a b \<circ> p) = id"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   876
    by (simp add: q(3))
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   877
  with ** *** show ?case
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   878
    by blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   879
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   880
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   881
lemma swapidseq_inverse:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   882
  assumes "swapidseq n p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   883
  shows "swapidseq n (inv p)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   884
  using swapidseq_inverse_exists[OF assms] inv_unique_comp[of p] by auto
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   885
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   886
lemma permutation_inverse: "permutation p \<Longrightarrow> permutation (inv p)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   887
  using permutation_def swapidseq_inverse by blast
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   888
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   889
73328
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   890
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   891
subsection \<open>Various combinations of transpositions with 2, 1 and 0 common elements\<close>
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   892
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   893
lemma swap_id_common:" a \<noteq> c \<Longrightarrow> b \<noteq> c \<Longrightarrow>
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   894
  transpose a b \<circ> transpose a c = transpose b c \<circ> transpose a b"
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   895
  by (simp add: fun_eq_iff transpose_def)
73328
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   896
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   897
lemma swap_id_common': "a \<noteq> b \<Longrightarrow> a \<noteq> c \<Longrightarrow>
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   898
  transpose a c \<circ> transpose b c = transpose b c \<circ> transpose a b"
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   899
  by (simp add: fun_eq_iff transpose_def)
73328
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   900
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   901
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
   902
  transpose a b \<circ> transpose c d = transpose c d \<circ> transpose a b"
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   903
  by (simp add: fun_eq_iff transpose_def)
73328
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   904
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
   905
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   906
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
   907
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   908
lemma symmetry_lemma:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   909
  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
   910
    and "\<And>a b c d. a \<noteq> b \<Longrightarrow> c \<noteq> d \<Longrightarrow>
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   911
      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
   912
      P a b c d"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   913
  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
   914
  using assms by metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   915
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   916
lemma swap_general:
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   917
  assumes "a \<noteq> b" "c \<noteq> d"
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   918
  shows "transpose a b \<circ> transpose c d = id \<or>
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   919
  (\<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
   920
    transpose a b \<circ> transpose c d = transpose x y \<circ> transpose a z)"
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   921
  by (metis assms swap_id_common' swap_id_independent transpose_commute transpose_comp_involutory)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   922
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   923
lemma swapidseq_id_iff[simp]: "swapidseq 0 p \<longleftrightarrow> p = id"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   924
  using swapidseq.cases[of 0 p "p = id"] by auto
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   925
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   926
lemma swapidseq_cases: "swapidseq n p \<longleftrightarrow>
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   927
    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)"
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   928
  by (meson comp_Suc id swapidseq.cases)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   929
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   930
lemma fixing_swapidseq_decrease:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   931
  assumes "swapidseq n p"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   932
    and "a \<noteq> b"
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   933
    and "(transpose a b \<circ> p) a = a"
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   934
  shows "n \<noteq> 0 \<and> swapidseq (n - 1) (transpose a b \<circ> p)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   935
  using assms
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   936
proof (induct n arbitrary: p a b)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   937
  case 0
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   938
  then show ?case
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
   939
    by (auto simp add: fun_upd_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   940
next
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   941
  case (Suc n p a b)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   942
  from Suc.prems(1) swapidseq_cases[of "Suc n" p]
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   943
  obtain c d q m where
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   944
    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
   945
    by auto
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   946
  consider "transpose a b \<circ> transpose c d = id"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   947
    | 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
   948
      "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
   949
    using swap_general[OF Suc.prems(2) cdqm(4)] by metis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   950
  then show ?case
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   951
  proof cases
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   952
    case 1
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   953
    then show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   954
      by (simp only: cdqm o_assoc) (simp add: cdqm)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   955
  next
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   956
    case 2
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   957
    then have az: "a \<noteq> z"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   958
      by simp
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   959
    from 2 have *: "(transpose x y \<circ> h) a = a \<longleftrightarrow> h a = a" for h
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   960
      by (simp add: transpose_def)
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   961
    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
   962
      by simp
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   963
    then have \<section>: "transpose a b \<circ> p = transpose x y \<circ> (transpose a z \<circ> q)"
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   964
      by (simp add: o_assoc 2)
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   965
    obtain **: "swapidseq (n - 1) (transpose a z \<circ> q)" and "n\<noteq>0"
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   966
      by (metis "*" "\<section>" Suc.hyps Suc.prems(3) az cdqm(3,5))
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   967
    then have "Suc n - 1 = Suc (n - 1)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   968
      by auto
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   969
    with 2 show ?thesis
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
   970
      using "**" \<section> swapidseq.simps by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   971
  qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   972
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   973
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
   974
lemma swapidseq_identity_even:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   975
  assumes "swapidseq n (id :: 'a \<Rightarrow> 'a)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   976
  shows "even n"
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
   977
  using \<open>swapidseq n id\<close>
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   978
proof (induct n rule: nat_less_induct)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   979
  case H: (1 n)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   980
  consider "n = 0"
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
   981
    | 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
   982
    using H(2)[unfolded swapidseq_cases[of n id]] by auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   983
  then show ?case
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   984
  proof cases
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   985
    case 1
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   986
    then show ?thesis by presburger
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   987
  next
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   988
    case h: 2
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   989
    from fixing_swapidseq_decrease[OF h(3,4), unfolded h(2)[symmetric]]
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   990
    have m: "m \<noteq> 0" "swapidseq (m - 1) (id :: 'a \<Rightarrow> 'a)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   991
      by auto
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   992
    from h m have mn: "m - 1 < n"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   993
      by arith
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   994
    from H(1)[rule_format, OF mn m(2)] h(1) m(1) show ?thesis
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   995
      by presburger
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
   996
  qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   997
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
   998
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
   999
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
  1000
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
  1001
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1002
definition "evenperm p = even (SOME n. swapidseq n p)"
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1003
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1004
lemma swapidseq_even_even:
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1005
  assumes m: "swapidseq m p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1006
    and n: "swapidseq n p"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1007
  shows "even m \<longleftrightarrow> even n"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1008
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1009
  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
  1010
    by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1011
  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
  1012
    by arith
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1013
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1014
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1015
lemma evenperm_unique:
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
  1016
  assumes "swapidseq n p" and"even n = b"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1017
  shows "evenperm p = b"
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
  1018
  by (metis evenperm_def assms someI swapidseq_even_even)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1019
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1020
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
  1021
subsection \<open>And it has the expected composition properties\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1022
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1023
lemma evenperm_id[simp]: "evenperm id = True"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1024
  by (rule evenperm_unique[where n = 0]) simp_all
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1025
73621
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1026
lemma evenperm_identity [simp]:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1027
  \<open>evenperm (\<lambda>x. x)\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1028
  using evenperm_id by (simp add: id_def [abs_def])
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1029
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
  1030
lemma evenperm_swap: "evenperm (transpose a b) = (a = b)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1031
  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
  1032
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
  1033
lemma evenperm_comp:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1034
  assumes "permutation p" "permutation q"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1035
  shows "evenperm (p \<circ> q) \<longleftrightarrow> evenperm p = evenperm q"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1036
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1037
  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
  1038
    unfolding permutation_def by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1039
  have "even (n + m) \<longleftrightarrow> (even n \<longleftrightarrow> even m)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1040
    by arith
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1041
  from evenperm_unique[OF n refl] evenperm_unique[OF m refl]
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1042
    and evenperm_unique[OF swapidseq_comp_add[OF n m] this] show ?thesis
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1043
    by blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1044
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1045
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1046
lemma evenperm_inv:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1047
  assumes "permutation p"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1048
  shows "evenperm (inv p) = evenperm p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1049
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1050
  from assms obtain n where n: "swapidseq n p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1051
    unfolding permutation_def by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1052
  show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1053
    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
  1054
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1055
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1056
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
  1057
subsection \<open>A more abstract characterization of permutations\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1058
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
  1059
lemma permutation_bijective:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1060
  assumes "permutation p"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1061
  shows "bij p"
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
  1062
  by (meson assms o_bij permutation_def swapidseq_inverse_exists)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1063
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1064
lemma permutation_finite_support:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1065
  assumes "permutation p"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1066
  shows "finite {x. p x \<noteq> x}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1067
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1068
  from assms obtain n where "swapidseq n p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1069
    unfolding permutation_def by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1070
  then show ?thesis
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1071
  proof (induct n p rule: swapidseq.induct)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1072
    case id
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1073
    then show ?case by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1074
  next
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1075
    case (comp_Suc n p a b)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1076
    let ?S = "insert a (insert b {x. p x \<noteq> x})"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1077
    from comp_Suc.hyps(2) have *: "finite ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1078
      by simp
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
  1079
    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
  1080
      by auto
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1081
    show ?case
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1082
      by (rule finite_subset[OF ** *])
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1083
  qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1084
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1085
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
  1086
lemma permutation_lemma:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1087
  assumes "finite S"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1088
    and "bij p"
73328
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
  1089
    and "\<forall>x. x \<notin> S \<longrightarrow> p x = x"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1090
  shows "permutation p"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1091
  using assms
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1092
proof (induct S arbitrary: p rule: finite_induct)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1093
  case empty
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1094
  then show ?case
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1095
    by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1096
next
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1097
  case (insert a F p)
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
  1098
  let ?r = "transpose a (p a) \<circ> p"
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
  1099
  let ?q = "transpose a (p a) \<circ> ?r"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1100
  have *: "?r a = a"
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
  1101
    by simp
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1102
  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
  1103
    by (metis bij_pointE comp_apply id_apply insert_iff swap_apply(3))
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1104
  have "bij ?r"
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
  1105
    using insert by (simp add: bij_comp)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1106
  have "permutation ?r"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1107
    by (rule insert(3)[OF \<open>bij ?r\<close> **])
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1108
  then have "permutation ?q"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1109
    by (simp add: permutation_compose permutation_swap_id)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1110
  then show ?case
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1111
    by (simp add: o_assoc)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1112
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1113
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
  1114
lemma permutation: "permutation p \<longleftrightarrow> bij p \<and> finite {x. p x \<noteq> x}"
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
  1115
  using permutation_bijective permutation_finite_support permutation_lemma by auto
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1116
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1117
lemma permutation_inverse_works:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1118
  assumes "permutation p"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1119
  shows "inv p \<circ> p = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1120
    and "p \<circ> inv p = id"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1121
  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
  1122
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1123
lemma permutation_inverse_compose:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1124
  assumes p: "permutation p"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1125
    and q: "permutation q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1126
  shows "inv (p \<circ> q) = inv q \<circ> inv p"
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
  1127
  by (simp add: o_inv_distrib p permutation_bijective q)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1128
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1129
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1130
subsection \<open>Relation to \<open>permutes\<close>\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1131
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1132
lemma permutes_imp_permutation:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1133
  \<open>permutation p\<close> if \<open>finite S\<close> \<open>p permutes S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1134
proof -
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1135
  from \<open>p permutes S\<close> have \<open>{x. p x \<noteq> x} \<subseteq> S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1136
    by (auto dest: permutes_not_in)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1137
  then have \<open>finite {x. p x \<noteq> x}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1138
    using \<open>finite S\<close> by (rule finite_subset)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1139
  moreover from \<open>p permutes S\<close> have \<open>bij p\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1140
    by (auto dest: permutes_bij)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1141
  ultimately show ?thesis
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1142
    by (simp add: permutation)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1143
qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1144
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1145
lemma permutation_permutesE:
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1146
  assumes \<open>permutation p\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1147
  obtains S where \<open>finite S\<close> \<open>p permutes S\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1148
proof -
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1149
  from assms have fin: \<open>finite {x. p x \<noteq> x}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1150
    by (simp add: permutation)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1151
  from assms have \<open>bij p\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1152
    by (simp add: permutation)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1153
  also have \<open>UNIV = {x. p x \<noteq> x} \<union> {x. p x = x}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1154
    by auto
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1155
  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
  1156
    by (rule bij_betw_partition) (auto simp add: bij_betw_fixpoints)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1157
  then have \<open>p permutes {x. p x \<noteq> x}\<close>
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1158
    by (auto intro: bij_imp_permutes)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1159
  with fin show thesis ..
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1160
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1161
73466
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1162
lemma permutation_permutes: "permutation p \<longleftrightarrow> (\<exists>S. finite S \<and> p permutes S)"
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1163
  by (auto elim: permutation_permutesE intro: permutes_imp_permutation)
ee1c4962671c more lemmas
haftmann
parents: 73410
diff changeset
  1164
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1165
82683
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1166
subsection \<open>Sign of a permutation\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1167
73328
ff24fe85ee57 lemma diffusion
haftmann
parents: 72304
diff changeset
  1168
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
  1169
  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
  1170
73621
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1171
lemma sign_cases [case_names even odd]:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1172
  obtains \<open>sign p = 1\<close> | \<open>sign p = - 1\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1173
  by (cases \<open>evenperm p\<close>) (simp_all add: sign_def)
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1174
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1175
lemma sign_nz [simp]: "sign p \<noteq> 0"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1176
  by (cases p rule: sign_cases) simp_all
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1177
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1178
lemma sign_id [simp]: "sign id = 1"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1179
  by (simp add: sign_def)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1180
73621
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1181
lemma sign_identity [simp]:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1182
  \<open>sign (\<lambda>x. x) = 1\<close>
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1183
  by (simp add: sign_def)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1184
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1185
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
  1186
  by (simp add: sign_def evenperm_inv)
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1187
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1188
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
  1189
  by (simp add: sign_def evenperm_comp)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1190
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
  1191
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
  1192
  by (simp add: sign_def evenperm_swap)
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1193
73621
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1194
lemma sign_idempotent [simp]: "sign p * sign p = 1"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1195
  by (simp add: sign_def)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1196
73621
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1197
lemma sign_left_idempotent [simp]:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1198
  \<open>sign p * (sign p * sign q) = sign q\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1199
  by (simp add: sign_def)
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1200
82683
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1201
lemma abs_sign [simp]: "\<bar>sign p\<bar> = 1"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1202
  by (simp add: sign_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1203
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1204
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1205
subsection \<open>An induction principle in terms of transpositions\<close>
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1206
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1207
definition apply_transps :: "('a \<times> 'a) list \<Rightarrow> 'a \<Rightarrow> 'a" where
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1208
  "apply_transps xs = foldr (\<circ>) (map (\<lambda>(a,b). Transposition.transpose a b) xs) id"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1209
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1210
lemma apply_transps_Nil [simp]: "apply_transps [] = id"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1211
  by (simp add: apply_transps_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1212
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1213
lemma apply_transps_Cons [simp]:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1214
  "apply_transps (x # xs) = Transposition.transpose (fst x) (snd x) \<circ> apply_transps xs"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1215
  by (simp add: apply_transps_def case_prod_unfold)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1216
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1217
lemma apply_transps_append [simp]:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1218
  "apply_transps (xs @ ys) = apply_transps xs \<circ> apply_transps ys"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1219
  by (induction xs) auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1220
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1221
lemma permutation_apply_transps [simp, intro]: "permutation (apply_transps xs)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1222
proof (induction xs)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1223
  case (Cons x xs)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1224
  thus ?case
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1225
    unfolding apply_transps_Cons by (intro permutation_compose permutation_swap_id)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1226
qed auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1227
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1228
lemma permutes_apply_transps:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1229
  assumes "\<forall>(a,b)\<in>set xs. a \<in> A \<and> b \<in> A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1230
  shows   "apply_transps xs permutes A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1231
  using assms
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1232
proof (induction xs)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1233
  case (Cons x xs)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1234
  from Cons.prems show ?case
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1235
    unfolding apply_transps_Cons
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1236
    by (intro permutes_compose permutes_swap_id Cons) auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1237
qed (auto simp: permutes_id)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1238
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1239
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1240
lemma permutes_induct [consumes 2, case_names id swap]: 
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1241
  assumes "p permutes S" "finite S"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1242
  assumes "P id"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1243
  assumes "\<And>a b p. a \<in> S \<Longrightarrow> b \<in> S \<Longrightarrow> a \<noteq> b \<Longrightarrow> P p \<Longrightarrow> p permutes S
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1244
             \<Longrightarrow> P (Transposition.transpose a b \<circ> p)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1245
  shows   "P p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1246
  using assms(2,1,4)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1247
proof (induct S arbitrary: p rule: finite_induct)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1248
  case empty
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1249
  then show ?case using assms by (auto simp: id_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1250
next
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1251
  case (insert x F p)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1252
  let ?r = "Transposition.transpose x (p x) \<circ> p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1253
  let ?q = "Transposition.transpose x (p x) \<circ> ?r"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1254
  have qp: "?q = p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1255
    by (simp add: o_assoc)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1256
  have "?r permutes F"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1257
    using permutes_insert_lemma[OF insert.prems(1)] .
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1258
  have "P ?r"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1259
    by (rule insert(3)[OF \<open>?r permutes F\<close>], rule insert(5)) (auto intro: permutes_subset)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1260
  show ?case
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1261
  proof (cases "x = p x")
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1262
    case False
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1263
    have "p x \<in> F"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1264
      using permutes_in_image[OF \<open>p permutes _\<close>, of x] False by auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1265
    have "P ?q"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1266
      by (rule insert(5))
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1267
         (use \<open>P ?r\<close> \<open>p x \<in> F\<close> \<open>?r permutes F\<close> False in \<open>auto simp: o_def intro: permutes_subset\<close>)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1268
    thus "P p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1269
      by (simp add: qp)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1270
  qed (use \<open>P ?r\<close> in simp)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1271
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1272
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1273
lemma permutes_rev_induct[consumes 2, case_names id swap]: 
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1274
  assumes "finite S" "p permutes S"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1275
  assumes "P id"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1276
  assumes "\<And>a b p. a \<in> S \<Longrightarrow> b \<in> S \<Longrightarrow> a \<noteq> b \<Longrightarrow> P p \<Longrightarrow> p permutes S
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1277
             \<Longrightarrow> P (p \<circ> Transposition.transpose a b)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1278
  shows   "P p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1279
proof -
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1280
  have "inv_into UNIV p permutes S"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1281
    using assms by (intro permutes_inv)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1282
  from this and assms(1,2) show ?thesis
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1283
  proof (induction "inv_into UNIV p" arbitrary: p rule: permutes_induct)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1284
    case id
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1285
    hence "p = id"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1286
      by (metis inv_id permutes_inv_inv)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1287
    thus ?case using \<open>P id\<close> by (auto simp: id_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1288
  next
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1289
    case (swap a b p p')
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1290
    have "p = Transposition.transpose a b \<circ> (Transposition.transpose a b \<circ> p)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1291
      by (simp add: o_assoc)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1292
    also have "\<dots> = Transposition.transpose a b \<circ> inv_into UNIV p'"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1293
      by (subst swap.hyps) auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1294
    also have "Transposition.transpose a b = inv_into UNIV (Transposition.transpose a b)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1295
      by (simp add: inv_swap_id)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1296
    also have "\<dots> \<circ> inv_into UNIV p' = inv_into UNIV (p' \<circ> Transposition.transpose a b)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1297
      using swap \<open>finite S\<close>
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1298
      by (intro permutation_inverse_compose [symmetric] permutation_swap_id permutation_inverse)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1299
         (auto simp: permutation_permutes)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1300
    finally have "p = inv (p' \<circ> Transposition.transpose a b)" .
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1301
    moreover have "p' \<circ> Transposition.transpose a b permutes S"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1302
      by (intro permutes_compose permutes_swap_id swap)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1303
    ultimately have *: "P (p' \<circ> Transposition.transpose a b)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1304
      by (rule swap(4))
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1305
    have "P (p' \<circ> Transposition.transpose a b \<circ> Transposition.transpose a b)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1306
      by (rule assms; intro * swap permutes_compose permutes_swap_id)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1307
    also have "p' \<circ> Transposition.transpose a b \<circ> Transposition.transpose a b = p'"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1308
      by (simp flip: o_assoc)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1309
    finally show ?case .
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1310
  qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1311
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1312
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1313
lemma map_permutation_apply_transps:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1314
  assumes f: "inj_on f A" and "set ts \<subseteq> A \<times> A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1315
  shows   "map_permutation A f (apply_transps ts) = apply_transps (map (map_prod f f) ts)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1316
  using assms(2)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1317
proof (induction ts)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1318
  case (Cons t ts)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1319
  obtain a b where [simp]: "t = (a, b)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1320
    by (cases t)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1321
  have "map_permutation A f (apply_transps (t # ts)) = 
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1322
          map_permutation A f (Transposition.transpose a b \<circ> apply_transps ts)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1323
    by simp
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1324
  also have "\<dots> = map_permutation A f (Transposition.transpose a b) \<circ>
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1325
                  map_permutation A f (apply_transps ts)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1326
    by (subst map_permutation_compose') 
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1327
       (use f Cons.prems in \<open>auto intro!: permutes_apply_transps\<close>)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1328
  also have "map_permutation A f (Transposition.transpose a b) =
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1329
             Transposition.transpose (f a) (f b)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1330
    by (intro map_permutation_transpose f) (use Cons.prems in auto)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1331
  also have "map_permutation A f (apply_transps ts) = apply_transps (map (map_prod f f) ts)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1332
    by (intro Cons.IH) (use Cons.prems in auto)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1333
  also have "Transposition.transpose (f a) (f b) \<circ> apply_transps (map (map_prod f f) ts) =
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1334
             apply_transps (map (map_prod f f) (t # ts))"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1335
    by simp
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1336
  finally show ?case .
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1337
qed (use f in \<open>auto simp: map_permutation_id'\<close>)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1338
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1339
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1340
lemma permutes_from_transpositions:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1341
  assumes "p permutes A" "finite A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1342
  shows   "\<exists>xs. (\<forall>(a,b)\<in>set xs. a \<noteq> b \<and> a \<in> A \<and> b \<in> A) \<and> apply_transps xs = p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1343
  using assms
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1344
proof (induction rule: permutes_induct)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1345
  case id
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1346
  thus ?case by (intro exI[of _ "[]"]) auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1347
next
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1348
  case (swap a b p)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1349
  from swap.IH obtain xs where
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1350
    xs: "(\<forall>(a,b)\<in>set xs. a \<noteq> b \<and> a \<in> A \<and> b \<in> A)" "apply_transps xs = p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1351
    by blast
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1352
  thus ?case
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1353
    using swap.hyps by (intro exI[of _ "(a,b) # xs"]) auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1354
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1355
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1356
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1357
subsection \<open>More on the sign of permutations\<close>
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1358
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1359
lemma evenperm_apply_transps_iff:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1360
  assumes "\<forall>(a,b)\<in>set xs. a \<noteq> b"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1361
  shows   "evenperm (apply_transps xs) \<longleftrightarrow> even (length xs)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1362
  using assms
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1363
  by (induction xs)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1364
     (simp_all add: case_prod_unfold evenperm_comp permutation_swap_id evenperm_swap)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1365
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1366
lemma evenperm_map_permutation:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1367
  assumes f: "inj_on f A" and "p permutes A" "finite A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1368
  shows   "evenperm (map_permutation A f p) \<longleftrightarrow> evenperm p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1369
proof -
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1370
  note [simp] = inj_on_eq_iff[OF f]
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1371
  obtain ts where ts: "\<forall>(a, b)\<in>set ts. a \<noteq> b \<and> a \<in> A \<and> b \<in> A" "apply_transps ts = p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1372
    using permutes_from_transpositions[OF assms(2,3)] by blast
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1373
  have "evenperm p \<longleftrightarrow> even (length ts)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1374
    by (subst ts(2) [symmetric], subst evenperm_apply_transps_iff) (use ts(1) in auto)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1375
  also have "\<dots> \<longleftrightarrow> even (length (map (map_prod f f) ts))"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1376
    by simp
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1377
  also have "\<dots> \<longleftrightarrow> evenperm (apply_transps (map (map_prod f f) ts))"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1378
    by (subst evenperm_apply_transps_iff) (use ts(1) in auto)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1379
  also have "apply_transps (map (map_prod f f) ts) = map_permutation A f p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1380
    unfolding ts(2)[symmetric] 
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1381
    by (rule map_permutation_apply_transps [symmetric]) (use f ts(1) in auto)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1382
  finally show ?thesis ..
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1383
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1384
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1385
lemma sign_map_permutation:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1386
  assumes "inj_on f A" "p permutes A" "finite A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1387
  shows   "sign (map_permutation A f p) = sign p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1388
  unfolding sign_def by (subst evenperm_map_permutation) (use assms in auto)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1389
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1390
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1391
text \<open>
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1392
  Sometimes it can be useful to consider the sign of a function that is not a permutation in the
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1393
  Isabelle/HOL sense, but its restriction to some finite subset is.
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1394
\<close>
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1395
definition sign_on :: "'a set \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> int"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1396
  where "sign_on A f = sign (restrict_id f A)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1397
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1398
lemma sign_on_cong [cong]:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1399
  assumes "A = B" "\<And>x. x \<in> A \<Longrightarrow> f x = g x"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1400
  shows   "sign_on A f = sign_on B g"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1401
  unfolding sign_on_def using assms
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1402
  by (intro arg_cong[of _ _ sign] restrict_id_cong)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1403
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1404
lemma sign_on_permutes:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1405
  assumes "f permutes A" "A \<subseteq> B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1406
  shows   "sign_on B f = sign f"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1407
proof -
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1408
  have f: "f permutes B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1409
    using assms permutes_subset by blast
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1410
  have "sign_on B f = sign (restrict_id f B)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1411
    by (simp add: sign_on_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1412
  also have "restrict_id f B = f"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1413
    using f by (auto simp: fun_eq_iff permutes_not_in restrict_id_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1414
  finally show ?thesis .
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1415
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1416
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1417
lemma sign_on_id [simp]: "sign_on A id = 1"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1418
  by (subst sign_on_permutes[of _ A]) auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1419
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1420
lemma sign_on_ident [simp]: "sign_on A (\<lambda>x. x) = 1"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1421
  using sign_on_id[of A] unfolding id_def by simp
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1422
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1423
lemma sign_on_transpose:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1424
  assumes "a \<in> A" "b \<in> A" "a \<noteq> b"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1425
  shows   "sign_on A (Transposition.transpose a b) = -1"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1426
  by (subst sign_on_permutes[of _ A])
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1427
     (use assms in \<open>auto simp: permutes_swap_id sign_swap_id\<close>)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1428
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1429
lemma sign_on_compose:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1430
  assumes "bij_betw f A A" "bij_betw g A A" "finite A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1431
  shows   "sign_on A (f \<circ> g) = sign_on A f * sign_on A g"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1432
proof -
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1433
  define restr where "restr = (\<lambda>f. restrict_id f A)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1434
  have "sign_on A (f \<circ> g) = sign (restr (f \<circ> g))"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1435
    by (simp add: sign_on_def restr_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1436
  also have "restr (f \<circ> g) = restr f \<circ> restr g"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1437
    using assms(2) by (auto simp: restr_def fun_eq_iff bij_betw_def restrict_id_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1438
  also have "sign \<dots> = sign (restr f) * sign (restr g)" unfolding restr_def
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1439
    by (rule sign_compose) (auto intro!: permutes_imp_permutation[of A] permutes_restrict_id assms)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1440
  also have "\<dots> = sign_on A f * sign_on A g"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1441
    by (simp add: sign_on_def restr_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1442
  finally show ?thesis .
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1443
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1444
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1445
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1446
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1447
subsection \<open>Transpositions of adjacent elements\<close>
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1448
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1449
text \<open>
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1450
  We have shown above that every permutation can be written as a product of transpositions.
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1451
  We will now furthermore show that any transposition of successive natural numbers
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1452
  $\{m, \ldots, n\}$ can be written as a product of transpositions of \<^emph>\<open>adjacent\<close> elements,
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1453
  i.e.\ transpositions of the form $i \leftrightarrow i+1$.
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1454
\<close>
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1455
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1456
function adj_transp_seq :: "nat \<Rightarrow> nat \<Rightarrow> nat list" where
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1457
  "adj_transp_seq a b =
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1458
     (if a \<ge> b then []
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1459
      else if b = a + 1 then [a]
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1460
      else a # adj_transp_seq (a+1) b @ [a])"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1461
  by auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1462
termination by (relation "measure (\<lambda>(a,b). b - a)") auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1463
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1464
lemmas [simp del] = adj_transp_seq.simps
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1465
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1466
lemma length_adj_transp_seq:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1467
  "a < b \<Longrightarrow> length (adj_transp_seq a b) = 2 * (b - a) - 1"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1468
  by (induction a b rule: adj_transp_seq.induct; subst adj_transp_seq.simps) auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1469
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1470
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1471
definition apply_adj_transps :: "nat list \<Rightarrow> nat \<Rightarrow> nat"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1472
  where "apply_adj_transps xs = foldl (\<circ>) id (map (\<lambda>x. Transposition.transpose x (x+1)) xs)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1473
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1474
lemma apply_adj_transps_aux:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1475
  "f \<circ> foldl (\<circ>) g (map (\<lambda>x. Transposition.transpose x (Suc x)) xs) =
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1476
   foldl (\<circ>) (f \<circ> g) (map (\<lambda>x. Transposition.transpose x (Suc x)) xs)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1477
  by (induction xs arbitrary: f g) (auto simp: o_assoc)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1478
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1479
lemma apply_adj_transps_Nil [simp]: "apply_adj_transps [] = id"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1480
  and apply_adj_transps_Cons [simp]:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1481
        "apply_adj_transps (x # xs) = Transposition.transpose x (x+1) \<circ> apply_adj_transps xs"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1482
  and apply_adj_transps_snoc [simp]:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1483
        "apply_adj_transps (xs @ [x]) = apply_adj_transps xs \<circ> Transposition.transpose x (x+1)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1484
   by (simp_all add: apply_adj_transps_def apply_adj_transps_aux)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1485
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1486
lemma adj_transp_seq_correct:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1487
  assumes "a < b"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1488
  shows   "apply_adj_transps (adj_transp_seq a b) = Transposition.transpose a b"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1489
  using assms
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1490
proof (induction a b rule: adj_transp_seq.induct)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1491
  case (1 a b)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1492
  show ?case
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1493
  proof (cases "b = a + 1")
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1494
    case True
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1495
    thus ?thesis
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1496
      by (subst adj_transp_seq.simps) (auto simp: o_def Transposition.transpose_def apply_adj_transps_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1497
  next
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1498
    case False
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1499
    hence "apply_adj_transps (adj_transp_seq a b) = 
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1500
            Transposition.transpose a (Suc a) \<circ> Transposition.transpose (Suc a) b \<circ> Transposition.transpose a (Suc a)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1501
      using 1 by (subst adj_transp_seq.simps)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1502
                 (simp add: o_assoc swap_id_common swap_id_common' id_def o_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1503
    also have "\<dots> = Transposition.transpose a b"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1504
      using False 1 by (simp add: Transposition.transpose_def fun_eq_iff)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1505
    finally show ?thesis .
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1506
  qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1507
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1508
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1509
lemma permutation_apply_adj_transps: "permutation (apply_adj_transps xs)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1510
proof (induction xs)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1511
  case (Cons x xs)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1512
  have "permutation (Transposition.transpose x (Suc x) \<circ> apply_adj_transps xs)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1513
    by (intro permutation_compose permutation_swap_id Cons)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1514
  thus ?case by (simp add: o_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1515
qed auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1516
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1517
lemma permutes_apply_adj_transps:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1518
  assumes "\<forall>x\<in>set xs. x \<in> A \<and> Suc x \<in> A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1519
  shows   "apply_adj_transps xs permutes A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1520
  using assms
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1521
  by (induction xs) (auto intro!: permutes_compose permutes_swap_id permutes_id)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1522
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1523
lemma set_adj_transp_seq:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1524
  "a < b \<Longrightarrow> set (adj_transp_seq a b) = {a..<b}"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1525
  by (induction a b rule: adj_transp_seq.induct, subst adj_transp_seq.simps) auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1526
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1527
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1528
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1529
subsection \<open>Transferring properties of permutations along bijections\<close>
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1530
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1531
locale permutes_bij =
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1532
  fixes p :: "'a \<Rightarrow> 'a" and A :: "'a set" and B :: "'b set"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1533
  fixes f :: "'a \<Rightarrow> 'b" and f' :: "'b \<Rightarrow> 'a"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1534
  fixes p' :: "'b \<Rightarrow> 'b"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1535
  defines "p' \<equiv> (\<lambda>x. if x \<in> B then f (p (f' x)) else x)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1536
  assumes permutes_p: "p permutes A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1537
  assumes bij_f: "bij_betw f A B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1538
  assumes f'_f: "x \<in> A \<Longrightarrow> f' (f x) = x"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1539
begin
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1540
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1541
lemma bij_f': "bij_betw f' B A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1542
  using bij_f f'_f by (auto simp: bij_betw_def) (auto simp: inj_on_def image_image)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1543
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1544
lemma f_f': "x \<in> B \<Longrightarrow> f (f' x) = x"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1545
  using f'_f bij_f by (auto simp: bij_betw_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1546
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1547
lemma f_in_B: "x \<in> A \<Longrightarrow> f x \<in> B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1548
  using bij_f by (auto simp: bij_betw_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1549
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1550
lemma f'_in_A: "x \<in> B \<Longrightarrow> f' x \<in> A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1551
  using bij_f' by (auto simp: bij_betw_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1552
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1553
lemma permutes_p': "p' permutes B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1554
proof -
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1555
  have p': "p' x = x" if "x \<notin> B" for x
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1556
    using that by (simp add: p'_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1557
  have bij_p: "bij_betw p A A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1558
    using permutes_p by (simp add: permutes_imp_bij)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1559
  have "bij_betw (f \<circ> p \<circ> f') B B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1560
    by (rule bij_betw_trans bij_f bij_f' bij_p)+
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1561
  also have "?this \<longleftrightarrow> bij_betw p' B B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1562
    by (intro bij_betw_cong) (auto simp: p'_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1563
  finally show ?thesis
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1564
    using p' by (rule bij_imp_permutes)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1565
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1566
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1567
lemma f_eq_iff [simp]: "f x = f y \<longleftrightarrow> x = y" if "x \<in> A" "y \<in> A" for x y
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1568
  using that bij_f by (auto simp: bij_betw_def inj_on_def)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1569
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1570
lemma apply_transps_map_f_aux:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1571
  assumes "\<forall>(a,b)\<in>set xs. a \<in> A \<and> b \<in> A" "y \<in> B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1572
  shows   "apply_transps (map (map_prod f f) xs) y = f (apply_transps xs (f' y))"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1573
  using assms
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1574
proof (induction xs arbitrary: y)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1575
  case Nil
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1576
  thus ?case by (auto simp: f_f')
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1577
next
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1578
  case (Cons x xs y)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1579
  from Cons.prems have "apply_transps xs permutes A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1580
    by (intro permutes_apply_transps) auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1581
  hence [simp]: "apply_transps xs z \<in> A \<longleftrightarrow> z \<in> A" for z
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1582
    by (simp add: permutes_in_image)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1583
  from Cons show ?case
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1584
    by (auto simp: Transposition.transpose_def f_f' f'_f case_prod_unfold f'_in_A)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1585
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1586
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1587
lemma apply_transps_map_f:
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1588
  assumes "\<forall>(a,b)\<in>set xs. a \<in> A \<and> b \<in> A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1589
  shows   "apply_transps (map (map_prod f f) xs) =
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1590
             (\<lambda>y. if y \<in> B then f (apply_transps xs (f' y)) else y)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1591
proof
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1592
  fix y
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1593
  show "apply_transps (map (map_prod f f) xs) y =
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1594
          (if y \<in> B then f (apply_transps xs (f' y)) else y)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1595
  proof (cases "y \<in> B")
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1596
    case True
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1597
    thus ?thesis
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1598
      using apply_transps_map_f_aux[OF assms] by simp
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1599
  next
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1600
    case False
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1601
    have "apply_transps (map (map_prod f f) xs) permutes B"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1602
      using assms by (intro permutes_apply_transps) (auto simp: case_prod_unfold f_in_B)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1603
    with False have "apply_transps (map (map_prod f f) xs) y = y"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1604
      by (intro permutes_not_in)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1605
    with False show ?thesis
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1606
      by simp
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1607
  qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1608
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1609
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1610
end
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1611
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1612
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1613
locale permutes_bij_finite = permutes_bij +
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1614
  assumes finite_A: "finite A"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1615
begin
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1616
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1617
lemma evenperm_p'_iff: "evenperm p' \<longleftrightarrow> evenperm p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1618
proof -
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1619
  obtain xs where xs: "\<forall>(a,b)\<in>set xs. a \<in> A \<and> b \<in> A \<and> a \<noteq> b" "apply_transps xs = p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1620
    using permutes_from_transpositions[OF permutes_p finite_A] by blast
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1621
  have "evenperm p \<longleftrightarrow> evenperm (apply_transps xs)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1622
    using xs by simp
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1623
  also have "\<dots> \<longleftrightarrow> even (length xs)"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1624
    using xs by (intro evenperm_apply_transps_iff) auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1625
  also have "\<dots> \<longleftrightarrow> even (length (map (map_prod f f) xs))"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1626
    by simp
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1627
  also have "\<dots> \<longleftrightarrow> evenperm (apply_transps (map (map_prod f f) xs))" using xs
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1628
    by (intro evenperm_apply_transps_iff [symmetric]) (auto simp: case_prod_unfold)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1629
  also have "apply_transps (map (map_prod f f) xs) = p'"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1630
    using xs unfolding p'_def by (subst apply_transps_map_f) auto
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1631
  finally show ?thesis ..
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1632
qed
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1633
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1634
lemma sign_p': "sign p' = sign p"
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1635
  by (auto simp: sign_def evenperm_p'_iff)
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1636
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1637
end
71304514891e HOL-Combinatorics: more lemmas about permutations
Manuel Eberl <eberlm@in.tum.de>
parents: 80777
diff changeset
  1638
73621
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  1639
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
  1640
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1641
subsection \<open>Permuting a list\<close>
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1642
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1643
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
  1644
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1645
definition permute_list :: "(nat \<Rightarrow> nat) \<Rightarrow> 'a list \<Rightarrow> 'a list"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1646
  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
  1647
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
  1648
lemma permute_list_map:
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1649
  assumes "f permutes {..<length xs}"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1650
  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
  1651
  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
  1652
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1653
lemma permute_list_nth:
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1654
  assumes "f permutes {..<length xs}" "i < length xs"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1655
  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
  1656
  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
  1657
  by (simp add: permute_list_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1658
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1659
lemma permute_list_Nil [simp]: "permute_list f [] = []"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1660
  by (simp add: permute_list_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1661
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1662
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
  1663
  by (simp add: permute_list_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1664
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
  1665
lemma permute_list_compose:
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1666
  assumes "g permutes {..<length xs}"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1667
  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
  1668
  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
  1669
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1670
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
  1671
  by (simp add: permute_list_def map_nth)
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 permute_list_id [simp]: "permute_list id xs = xs"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1674
  by (simp add: id_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1675
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1676
lemma mset_permute_list [simp]:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1677
  fixes xs :: "'a list"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1678
  assumes "f permutes {..<length xs}"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1679
  shows "mset (permute_list f xs) = mset xs"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1680
proof (rule multiset_eqI)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1681
  fix y :: 'a
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1682
  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
  1683
    using permutes_in_image[OF assms] by auto
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1684
  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
  1685
    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
  1686
  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
  1687
    by auto
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1688
  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
  1689
    by (intro card_vimage_inj) (auto simp: permutes_inj permutes_surj)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1690
  also have "\<dots> = count (mset xs) y"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1691
    by (simp add: count_mset length_filter_conv_card)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1692
  finally show "count (mset (permute_list f xs)) y = count (mset xs) y"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1693
    by simp
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1694
qed
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1695
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
  1696
lemma set_permute_list [simp]:
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1697
  assumes "f permutes {..<length xs}"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1698
  shows "set (permute_list f xs) = set xs"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1699
  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
  1700
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1701
lemma distinct_permute_list [simp]:
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1702
  assumes "f permutes {..<length xs}"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1703
  shows "distinct (permute_list f xs) = distinct xs"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1704
  by (simp add: distinct_count_atmost_1 assms)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1705
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
  1706
lemma permute_list_zip:
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1707
  assumes "f permutes A" "A = {..<length xs}"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1708
  assumes [simp]: "length xs = length ys"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1709
  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
  1710
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1711
  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
  1712
    by simp
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1713
  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
  1714
    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
  1715
  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
  1716
    by (intro nth_equalityI) (simp_all add: *)
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1717
  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
  1718
    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
  1719
  finally show ?thesis .
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1720
qed
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1721
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
  1722
lemma map_of_permute:
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1723
  assumes "\<sigma> permutes fst ` set xs"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1724
  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
  1725
    (is "_ = map_of (map ?f _)")
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1726
proof
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1727
  from assms have "inj \<sigma>" "surj \<sigma>"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1728
    by (simp_all add: permutes_inj permutes_surj)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1729
  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
  1730
    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
  1731
qed
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1732
73706
4b1386b2c23e mere abbreviation for logical alias
haftmann
parents: 73663
diff changeset
  1733
lemma list_all2_permute_list_iff:
4b1386b2c23e mere abbreviation for logical alias
haftmann
parents: 73663
diff changeset
  1734
  \<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
  1735
  if \<open>p permutes {..<length xs}\<close>
4b1386b2c23e mere abbreviation for logical alias
haftmann
parents: 73663
diff changeset
  1736
  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
  1737
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1738
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
  1739
subsection \<open>More lemmas about permutations\<close>
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1740
73555
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1741
lemma permutes_in_funpow_image: \<^marker>\<open>contributor \<open>Lars Noschinski\<close>\<close>
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1742
  assumes "f permutes S" "x \<in> S"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1743
  shows "(f ^^ n) x \<in> S"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1744
  using assms by (induction n) (auto simp: permutes_in_image)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1745
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1746
lemma permutation_self: \<^marker>\<open>contributor \<open>Lars Noschinski\<close>\<close>
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1747
  assumes \<open>permutation p\<close>
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1748
  obtains n where \<open>n > 0\<close> \<open>(p ^^ n) x = x\<close>
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1749
proof (cases \<open>p x = x\<close>)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1750
  case True
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1751
  with that [of 1] show thesis by simp
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1752
next
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1753
  case False
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1754
  from \<open>permutation p\<close> have \<open>inj p\<close>
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1755
    by (intro permutation_bijective bij_is_inj)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1756
  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
  1757
  proof (induction n arbitrary: x)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1758
    case 0 then show ?case by simp
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1759
  next
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1760
    case (Suc n)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1761
    have "p (p x) \<noteq> p x"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1762
    proof (rule notI)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1763
      assume "p (p x) = p x"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1764
      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
  1765
    qed
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1766
    have "(p ^^ Suc (Suc n)) x = (p ^^ Suc n) (p x)"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1767
      by (simp add: funpow_swap1)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1768
    also have "\<dots> \<noteq> (p ^^ n) (p x)"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1769
      by (rule Suc) fact
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1770
    also have "(p ^^ n) (p x) = (p ^^ Suc n) x"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1771
      by (simp add: funpow_swap1)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1772
    finally show ?case by simp
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1773
  qed
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1774
  then have "{y. \<exists>n. y = (p ^^ n) x} \<subseteq> {x. p x \<noteq> x}"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1775
    by auto
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1776
  then have "finite {y. \<exists>n. y = (p ^^ n) x}"
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1777
    using permutation_finite_support[OF assms] by (rule finite_subset)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1778
  ultimately obtain n where \<open>n > 0\<close> \<open>(p ^^ n) x = x\<close>
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1779
    by (rule funpow_inj_finite)
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1780
  with that [of n] show thesis by blast
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1781
qed
92783562ab78 collected combinatorial material
haftmann
parents: 73477
diff changeset
  1782
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1783
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
  1784
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1785
lemma count_image_mset_eq_card_vimage:
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1786
  assumes "finite A"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1787
  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
  1788
  using assms
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1789
proof (induct A)
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1790
  case empty
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1791
  show ?case by simp
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1792
next
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1793
  case (insert x F)
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1794
  show ?case
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1795
  proof (cases "f x = b")
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1796
    case True
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1797
    with insert.hyps
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1798
    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
  1799
      by auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1800
    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
  1801
      by simp
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1802
    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
  1803
      by (auto intro: arg_cong[where f="card"])
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1804
    finally show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1805
      using insert by auto
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1806
  next
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1807
    case False
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1808
    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
  1809
      by auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1810
    with insert False show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1811
      by simp
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1812
  qed
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1813
qed
64284
f3b905b2eee2 HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents: 64267
diff changeset
  1814
67408
4a4c14b24800 prefer formal comments;
wenzelm
parents: 67399
diff changeset
  1815
\<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
  1816
lemma image_mset_eq_implies_permutes:
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1817
  fixes f :: "'a \<Rightarrow> 'b"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1818
  assumes "finite A"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1819
    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
  1820
  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
  1821
proof -
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1822
  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
  1823
  have "f ` A = f' ` A"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1824
  proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1825
    from \<open>finite A\<close> have "f ` A = f ` (set_mset (mset_set A))"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1826
      by simp
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1827
    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
  1828
      by (metis mset_eq multiset.set_map)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1829
    also from \<open>finite A\<close> have "\<dots> = f' ` A"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1830
      by simp
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1831
    finally show ?thesis .
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1832
  qed
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1833
  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
  1834
  proof
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1835
    fix b
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1836
    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
  1837
      by simp
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1838
    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
  1839
      by (simp add: count_image_mset_eq_card_vimage)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1840
    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
  1841
      by (intro finite_same_card_bij) simp_all
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1842
  qed
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1843
  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
  1844
    by (rule bchoice)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1845
  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
  1846
  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
  1847
  have "p' permutes A"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1848
  proof (rule bij_imp_permutes)
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1849
    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
  1850
      by (auto simp: disjoint_family_on_def)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1851
    moreover
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1852
    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
  1853
      using p that by (subst bij_betw_cong[where g="p b"]) auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1854
    ultimately
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1855
    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
  1856
      by (rule bij_betw_UNION_disjoint)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1857
    moreover have "(\<Union>b\<in>f ` A. {a \<in> A. f a = b}) = A"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1858
      by auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1859
    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
  1860
      by auto
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1861
    ultimately show "bij_betw p' A A"
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1862
      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
  1863
  next
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1864
    show "\<And>x. x \<notin> A \<Longrightarrow> p' x = x"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1865
      by (simp add: p'_def)
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1866
  qed
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1867
  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
  1868
    unfolding p'_def using bij_betwE by fastforce
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1869
  ultimately show ?thesis ..
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1870
qed
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1871
67408
4a4c14b24800 prefer formal comments;
wenzelm
parents: 67399
diff changeset
  1872
\<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
  1873
lemma mset_eq_permutation:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1874
  fixes xs ys :: "'a list"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1875
  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
  1876
  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
  1877
proof -
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1878
  from mset_eq have length_eq: "length xs = length ys"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1879
    by (rule mset_eq_length)
63921
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1880
  have "mset_set {..<length ys} = mset [0..<length ys]"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1881
    by (rule mset_set_upto_eq_mset_upto)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1882
  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
  1883
    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
  1884
    by (metis map_nth mset_map)
0a5184877cb7 Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents: 63539
diff changeset
  1885
  from image_mset_eq_implies_permutes[OF _ this]
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1886
  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
  1887
    by auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1888
  with length_eq have "permute_list p ys = xs"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1889
    by (auto intro!: nth_equalityI simp: permute_list_nth)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1890
  with p show thesis ..
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1891
qed
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  1892
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1893
lemma permutes_natset_le:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1894
  fixes S :: "'a::wellorder set"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1895
  assumes "p permutes S"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1896
    and "\<forall>i \<in> S. p i \<le> i"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1897
  shows "p = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1898
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1899
  have "p n = n" for n
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1900
    using assms
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1901
  proof (induct n arbitrary: S rule: less_induct)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1902
    case (less n)
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1903
    show ?case
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1904
    proof (cases "n \<in> S")
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1905
      case False
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1906
      with less(2) show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1907
        unfolding permutes_def by metis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1908
    next
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1909
      case True
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1910
      with less(3) have "p n < n \<or> p n = n"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1911
        by auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1912
      then show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1913
      proof
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1914
        assume "p n < n"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1915
        with less have "p (p n) = p n"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1916
          by metis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1917
        with permutes_inj[OF less(2)] have "p n = n"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1918
          unfolding inj_def by blast
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1919
        with \<open>p n < n\<close> have False
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1920
          by simp
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1921
        then show ?thesis ..
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1922
      qed
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1923
    qed
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1924
  qed
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1925
  then show ?thesis by (auto simp: fun_eq_iff)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1926
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1927
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1928
lemma permutes_natset_ge:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1929
  fixes S :: "'a::wellorder set"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1930
  assumes p: "p permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1931
    and le: "\<forall>i \<in> S. p i \<ge> i"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1932
  shows "p = id"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1933
proof -
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1934
  have "i \<ge> inv p i" if "i \<in> S" for i
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1935
  proof -
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1936
    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
  1937
      by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1938
    with le have "p (inv p i) \<ge> inv p i"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1939
      by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1940
    with permutes_inverses[OF p] show ?thesis
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1941
      by simp
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1942
  qed
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1943
  then have "\<forall>i\<in>S. inv p i \<le> i"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1944
    by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1945
  from permutes_natset_le[OF permutes_inv[OF p] this] have "inv p = inv id"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1946
    by simp
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
  1947
  then show ?thesis
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
  1948
    using p permutes_inv_inv by fastforce
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1949
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1950
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1951
lemma image_inverse_permutations: "{inv p |p. p permutes S} = {p. p permutes S}"
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
  1952
  using permutes_inv permutes_inv_inv by force
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1953
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
  1954
lemma image_compose_permutations_left:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1955
  assumes "q permutes S"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1956
  shows "{q \<circ> p |p. p permutes S} = {p. p permutes S}"
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
  1957
proof -
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
  1958
  have "\<And>p. p permutes S \<Longrightarrow> q \<circ> p permutes S"
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
  1959
    by (simp add: assms permutes_compose)
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
  1960
  moreover have "\<And>x. x permutes S \<Longrightarrow> \<exists>p. x = q \<circ> p \<and> p permutes S"
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
  1961
    by (metis assms id_comp o_assoc permutes_compose permutes_inv permutes_inv_o(1))
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
  1962
  ultimately show ?thesis
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
  1963
    by auto
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
  1964
qed
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1965
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1966
lemma image_compose_permutations_right:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1967
  assumes "q permutes S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1968
  shows "{p \<circ> q | p. p permutes S} = {p . p permutes S}"
80777
623d46973cbe More tidying of old proofs
paulson <lp15@cam.ac.uk>
parents: 73706
diff changeset
  1969
  by (metis (no_types, opaque_lifting) assms comp_id fun.map_comp permutes_compose permutes_inv permutes_inv_o(2))
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1970
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1971
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
  1972
  by (simp add: permutes_def) metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1973
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1974
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
  1975
  (is "?lhs = ?rhs")
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1976
proof -
30036
3a074e3a9a18 generalize some lemmas
huffman
parents: 29840
diff changeset
  1977
  let ?S = "{p . p permutes S}"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1978
  have *: "inj_on inv ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1979
  proof (auto simp add: inj_on_def)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1980
    fix q r
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1981
    assume q: "q permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1982
      and r: "r permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1983
      and qr: "inv q = inv r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1984
    then have "inv (inv q) = inv (inv r)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1985
      by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1986
    with permutes_inv_inv[OF q] permutes_inv_inv[OF r] show "q = r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1987
      by metis
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1988
  qed
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1989
  have **: "inv ` ?S = ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1990
    using image_inverse_permutations by blast
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1991
  have ***: "?rhs = sum (f \<circ> inv) ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  1992
    by (simp add: o_def)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1993
  from sum.reindex[OF *, of f] show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  1994
    by (simp only: ** ***)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1995
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1996
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  1997
lemma setum_permutations_compose_left:
30036
3a074e3a9a18 generalize some lemmas
huffman
parents: 29840
diff changeset
  1998
  assumes q: "q permutes S"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63921
diff changeset
  1999
  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
  2000
  (is "?lhs = ?rhs")
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2001
proof -
30036
3a074e3a9a18 generalize some lemmas
huffman
parents: 29840
diff changeset
  2002
  let ?S = "{p. p permutes S}"
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 66486
diff changeset
  2003
  have *: "?rhs = sum (f \<circ> ((\<circ>) q)) ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2004
    by (simp add: o_def)
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 66486
diff changeset
  2005
  have **: "inj_on ((\<circ>) q) ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2006
  proof (auto simp add: inj_on_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  2007
    fix p r
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2008
    assume "p permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2009
      and r: "r permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2010
      and rp: "q \<circ> p = q \<circ> r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2011
    then have "inv q \<circ> q \<circ> p = inv q \<circ> q \<circ> r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2012
      by (simp add: comp_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2013
    with permutes_inj[OF q, unfolded inj_iff] show "p = r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2014
      by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  2015
  qed
67399
eab6ce8368fa ran isabelle update_op on all sources
nipkow
parents: 66486
diff changeset
  2016
  have "((\<circ>) q) ` ?S = ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2017
    using image_compose_permutations_left[OF q] by auto
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2018
  with * sum.reindex[OF **, of f] show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2019
    by (simp only:)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  2020
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  2021
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  2022
lemma sum_permutations_compose_right:
30036
3a074e3a9a18 generalize some lemmas
huffman
parents: 29840
diff changeset
  2023
  assumes q: "q permutes S"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63921
diff changeset
  2024
  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
  2025
  (is "?lhs = ?rhs")
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2026
proof -
30036
3a074e3a9a18 generalize some lemmas
huffman
parents: 29840
diff changeset
  2027
  let ?S = "{p. p permutes S}"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2028
  have *: "?rhs = sum (f \<circ> (\<lambda>p. p \<circ> q)) ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2029
    by (simp add: o_def)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2030
  have **: "inj_on (\<lambda>p. p \<circ> q) ?S"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2031
  proof (auto simp add: inj_on_def)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  2032
    fix p r
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2033
    assume "p permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2034
      and r: "r permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2035
      and rp: "p \<circ> q = r \<circ> q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2036
    then have "p \<circ> (q \<circ> inv q) = r \<circ> (q \<circ> inv q)"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2037
      by (simp add: o_assoc)
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2038
    with permutes_surj[OF q, unfolded surj_iff] show "p = r"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2039
      by simp
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  2040
  qed
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2041
  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
  2042
    by auto
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2043
  with * sum.reindex[OF **, of f] show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2044
    by (simp only:)
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  2045
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  2046
73621
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2047
lemma inv_inj_on_permutes:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2048
  \<open>inj_on inv {p. p permutes S}\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2049
proof (intro inj_onI, unfold mem_Collect_eq)
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2050
  fix p q
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2051
  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
  2052
  have "inv (inv p) = inv (inv q)" using eq by simp
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2053
  thus "p = q"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2054
    using inv_inv_eq[OF permutes_bij] p q by metis
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2055
qed
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2056
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2057
lemma permutes_pair_eq:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2058
  \<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
  2059
proof
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2060
  show "?L \<subseteq> ?R"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2061
  proof
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2062
    fix x assume "x \<in> ?L"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2063
    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
  2064
    note x
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2065
    also have "(p s, s) = (p s, Hilbert_Choice.inv p (p s))"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2066
      using permutes_inj [OF that] inv_f_f by auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2067
    also have "... \<in> ?R" using s permutes_in_image[OF that] by auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2068
    finally show "x \<in> ?R".
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2069
  qed
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2070
  show "?R \<subseteq> ?L"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2071
  proof
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2072
    fix x assume "x \<in> ?R"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2073
    then obtain s
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2074
      where x: "x = (s, Hilbert_Choice.inv p s)" (is "_ = (s, ?ips)")
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2075
        and s: "s \<in> S" by auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2076
    note x
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2077
    also have "(s, ?ips) = (p ?ips, ?ips)"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2078
      using inv_f_f[OF permutes_inj[OF permutes_inv[OF that]]]
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2079
      using inv_inv_eq[OF permutes_bij[OF that]] by auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2080
    also have "... \<in> ?L"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2081
      using s permutes_in_image[OF permutes_inv[OF that]] by auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2082
    finally show "x \<in> ?L".
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2083
  qed
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2084
qed
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2085
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2086
context
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2087
  fixes p and n i :: nat
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2088
  assumes p: \<open>p permutes {0..<n}\<close> and i: \<open>i < n\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2089
begin
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2090
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2091
lemma permutes_nat_less:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2092
  \<open>p i < n\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2093
proof -
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2094
  have \<open>?thesis \<longleftrightarrow> p i \<in> {0..<n}\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2095
    by simp
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2096
  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
  2097
    by (rule permutes_in_image)
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2098
  finally show ?thesis
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2099
    using i by simp
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2100
qed
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2101
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2102
lemma permutes_nat_inv_less:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2103
  \<open>inv p i < n\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2104
proof -
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2105
  from p have \<open>inv p permutes {0..<n}\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2106
    by (rule permutes_inv)
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2107
  then show ?thesis
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2108
    using i by (rule Permutations.permutes_nat_less)
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2109
qed
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2110
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2111
end
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2112
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2113
context comm_monoid_set
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2114
begin
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2115
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2116
lemma permutes_inv:
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2117
  \<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
  2118
  if \<open>p permutes S\<close>
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2119
proof -
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2120
  let ?g = "\<lambda>(x, y). g x y"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2121
  let ?ps = "\<lambda>s. (p s, s)"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2122
  let ?ips = "\<lambda>s. (s, inv p s)"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2123
  have inj1: "inj_on ?ps S" by (rule inj_onI) auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2124
  have inj2: "inj_on ?ips S" by (rule inj_onI) auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2125
  have "?l = F ?g (?ps ` S)"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2126
    using reindex [OF inj1, of ?g] by simp
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2127
  also have "?ps ` S = {(p s, s) |s. s \<in> S}" by auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2128
  also have "... = {(s, inv p s) |s. s \<in> S}"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2129
    unfolding permutes_pair_eq [OF that] by simp
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2130
  also have "... = ?ips ` S" by auto
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2131
  also have "F ?g ... = ?r"
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2132
    using reindex [OF inj2, of ?g] by simp
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2133
  finally show ?thesis.
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2134
qed
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2135
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2136
end
b4b70d13c995 collected lemmas on permutations
haftmann
parents: 73555
diff changeset
  2137
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2138
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
  2139
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
  2140
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63921
diff changeset
  2141
lemma sum_over_permutations_insert:
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2142
  assumes fS: "finite S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2143
    and aS: "a \<notin> S"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63921
diff changeset
  2144
  shows "sum f {p. p permutes (insert a S)} =
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
  2145
    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
  2146
proof -
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
  2147
  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
  2148
    by (simp add: fun_eq_iff)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2149
  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
  2150
    by blast
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
  2151
  show ?thesis
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2152
    unfolding * ** sum.cartesian_product permutes_insert
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63921
diff changeset
  2153
  proof (rule sum.reindex)
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
  2154
    let ?f = "(\<lambda>(b, y). transpose a b \<circ> y)"
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  2155
    let ?P = "{p. p permutes S}"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2156
    {
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2157
      fix b c p q
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2158
      assume b: "b \<in> insert a S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2159
      assume c: "c \<in> insert a S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2160
      assume p: "p permutes S"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2161
      assume q: "q permutes S"
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
  2162
      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
  2163
      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
  2164
        unfolding permutes_def by metis+
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
  2165
      from eq have "(transpose a b \<circ> p) a  = (transpose a c \<circ> q) a"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2166
        by simp
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2167
      then have bc: "b = c"
73663
7734c442802f avoid Fun.swap
haftmann
parents: 73648
diff changeset
  2168
        by (simp add: permutes_def pa qa o_def fun_upd_def id_def
62390
842917225d56 more canonical names
nipkow
parents: 61424
diff changeset
  2169
            cong del: if_weak_cong split: if_split_asm)
73648
1bd3463e30b8 more elementary swap
haftmann
parents: 73623
diff changeset
  2170
      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
  2171
        (\<lambda>p. transpose a c \<circ> p) (transpose a c \<circ> q)" by simp
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2172
      then have "p = q"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2173
        unfolding o_assoc swap_id_idempotent by simp
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2174
      with bc have "b = c \<and> p = q"
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2175
        by blast
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  2176
    }
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30267
diff changeset
  2177
    then show "inj_on ?f (insert a S \<times> ?P)"
54681
8a8e6db7f391 tuned proofs;
wenzelm
parents: 53374
diff changeset
  2178
      unfolding inj_on_def by clarify metis
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  2179
  qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  2180
qed
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  2181
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2182
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2183
subsection \<open>Constructing permutations from association lists\<close>
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2184
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2185
definition list_permutes :: "('a \<times> 'a) list \<Rightarrow> 'a set \<Rightarrow> bool"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2186
  where "list_permutes xs A \<longleftrightarrow>
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2187
    set (map fst xs) \<subseteq> A \<and>
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2188
    set (map snd xs) = set (map fst xs) \<and>
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2189
    distinct (map fst xs) \<and>
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2190
    distinct (map snd xs)"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2191
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2192
lemma list_permutesI [simp]:
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2193
  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
  2194
  shows "list_permutes xs A"
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2195
proof -
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2196
  from assms(2,3) have "distinct (map snd xs)"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2197
    by (intro card_distinct) (simp_all add: distinct_card del: set_map)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2198
  with assms show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2199
    by (simp add: list_permutes_def)
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2200
qed
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2201
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2202
definition permutation_of_list :: "('a \<times> 'a) list \<Rightarrow> 'a \<Rightarrow> 'a"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2203
  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
  2204
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2205
lemma permutation_of_list_Cons:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2206
  "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
  2207
  by (simp add: permutation_of_list_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2208
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2209
fun inverse_permutation_of_list :: "('a \<times> 'a) list \<Rightarrow> 'a \<Rightarrow> 'a"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2210
  where
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2211
    "inverse_permutation_of_list [] x = x"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2212
  | "inverse_permutation_of_list ((y, x') # xs) x =
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2213
      (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
  2214
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2215
declare inverse_permutation_of_list.simps [simp del]
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2216
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2217
lemma inj_on_map_of:
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2218
  assumes "distinct (map snd xs)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2219
  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
  2220
proof (rule inj_onI)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2221
  fix x y
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2222
  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
  2223
  assume eq: "map_of xs x = map_of xs y"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2224
  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
  2225
    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
  2226
  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
  2227
    by (force dest: map_of_SomeD)+
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2228
  moreover from * eq x'y' have "x' = y'"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2229
    by simp
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2230
  ultimately show "x = y"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2231
    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
  2232
qed
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2233
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2234
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
  2235
  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
  2236
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2237
lemma inj_on_map_of':
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2238
  assumes "distinct (map snd xs)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2239
  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
  2240
  by (intro comp_inj_on inj_on_map_of assms inj_on_the)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2241
    (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
  2242
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2243
lemma image_map_of:
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2244
  assumes "distinct (map fst xs)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2245
  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
  2246
  using assms by (auto simp: rev_image_eqI)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2247
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2248
lemma the_Some_image [simp]: "the ` Some ` A = A"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2249
  by (subst image_image) simp
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2250
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2251
lemma image_map_of':
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2252
  assumes "distinct (map fst xs)"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2253
  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
  2254
  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
  2255
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2256
lemma permutation_of_list_permutes [simp]:
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2257
  assumes "list_permutes xs A"
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2258
  shows "permutation_of_list xs permutes A"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2259
    (is "?f permutes _")
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2260
proof (rule permutes_subset[OF bij_imp_permutes])
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2261
  from assms show "set (map fst xs) \<subseteq> A"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2262
    by (simp add: list_permutes_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2263
  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
  2264
    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
  2265
  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
  2266
    by (intro inj_on_cong)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2267
      (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
  2268
  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
  2269
    by (rule inj_on_imp_bij_betw)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2270
  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
  2271
    by (intro image_cong refl)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2272
      (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
  2273
  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
  2274
    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
  2275
  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
  2276
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
  2277
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2278
lemma eval_permutation_of_list [simp]:
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2279
  "permutation_of_list [] x = x"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2280
  "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
  2281
  "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
  2282
  by (simp_all add: permutation_of_list_def)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2283
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2284
lemma eval_inverse_permutation_of_list [simp]:
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2285
  "inverse_permutation_of_list [] x = x"
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2286
  "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
  2287
  "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
  2288
  by (simp_all add: inverse_permutation_of_list.simps)
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2289
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2290
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
  2291
  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
  2292
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2293
lemma permutation_of_list_unique':
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2294
  "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
  2295
  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
  2296
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2297
lemma permutation_of_list_unique:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2298
  "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
  2299
  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
  2300
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2301
lemma inverse_permutation_of_list_id:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2302
  "x \<notin> set (map snd xs) \<Longrightarrow> inverse_permutation_of_list xs x = x"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2303
  by (induct xs) auto
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2304
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2305
lemma inverse_permutation_of_list_unique':
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2306
  "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
  2307
  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
  2308
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2309
lemma inverse_permutation_of_list_unique:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2310
  "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
  2311
  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
  2312
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2313
lemma inverse_permutation_of_list_correct:
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2314
  fixes A :: "'a set"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2315
  assumes "list_permutes xs A"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2316
  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
  2317
proof (rule ext, rule sym, subst permutes_inv_eq)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2318
  from assms show "permutation_of_list xs permutes A"
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2319
    by simp
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2320
  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
  2321
  proof (cases "x \<in> set (map snd xs)")
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2322
    case True
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2323
    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
  2324
    with assms show ?thesis
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2325
      by (simp add: inverse_permutation_of_list_unique permutation_of_list_unique)
65342
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2326
  next
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2327
    case False
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2328
    with assms show ?thesis
e32eb488c3a3 misc tuning and modernization;
wenzelm
parents: 64966
diff changeset
  2329
      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
  2330
  qed
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2331
qed
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 62390
diff changeset
  2332
29840
cfab6a76aa13 Permutations, both general and specifically on finite sets.
chaieb
parents:
diff changeset
  2333
end