author | wenzelm |
Wed, 04 Oct 2017 12:00:53 +0200 | |
changeset 66787 | 64b47495676d |
parent 66486 | ffaaa83543b2 |
child 67399 | eab6ce8368fa |
permissions | -rw-r--r-- |
41959 | 1 |
(* Title: HOL/Library/Permutations.thy |
2 |
Author: Amine Chaieb, University of Cambridge |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
3 |
*) |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
4 |
|
60500 | 5 |
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
|
6 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
7 |
theory Permutations |
65552
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
wenzelm
parents:
65342
diff
changeset
|
8 |
imports Multiset Disjoint_Sets |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
9 |
begin |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
10 |
|
60500 | 11 |
subsection \<open>Transpositions\<close> |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
12 |
|
65342 | 13 |
lemma swap_id_idempotent [simp]: "Fun.swap a b id \<circ> Fun.swap a b id = id" |
14 |
by (rule ext) (auto simp add: Fun.swap_def) |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
15 |
|
65342 | 16 |
lemma inv_swap_id: "inv (Fun.swap a b id) = Fun.swap a b id" |
54681 | 17 |
by (rule inv_unique_comp) simp_all |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
18 |
|
65342 | 19 |
lemma swap_id_eq: "Fun.swap a b id x = (if x = a then b else if x = b then a else x)" |
56545 | 20 |
by (simp add: Fun.swap_def) |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
21 |
|
64284
f3b905b2eee2
HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents:
64267
diff
changeset
|
22 |
lemma bij_inv_eq_iff: "bij p \<Longrightarrow> x = inv p y \<longleftrightarrow> p x = y" |
f3b905b2eee2
HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents:
64267
diff
changeset
|
23 |
using surj_f_inv_f[of p] by (auto simp add: bij_def) |
f3b905b2eee2
HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents:
64267
diff
changeset
|
24 |
|
f3b905b2eee2
HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents:
64267
diff
changeset
|
25 |
lemma bij_swap_comp: |
65342 | 26 |
assumes "bij p" |
64284
f3b905b2eee2
HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents:
64267
diff
changeset
|
27 |
shows "Fun.swap a b id \<circ> p = Fun.swap (inv p a) (inv p b) p" |
65342 | 28 |
using surj_f_inv_f[OF bij_is_surj[OF \<open>bij p\<close>]] |
29 |
by (simp add: fun_eq_iff Fun.swap_def bij_inv_eq_iff[OF \<open>bij p\<close>]) |
|
64284
f3b905b2eee2
HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents:
64267
diff
changeset
|
30 |
|
65342 | 31 |
lemma bij_swap_compose_bij: |
32 |
assumes "bij p" |
|
33 |
shows "bij (Fun.swap a b id \<circ> p)" |
|
34 |
by (simp only: bij_swap_comp[OF \<open>bij p\<close>] bij_swap_iff \<open>bij p\<close>) |
|
64284
f3b905b2eee2
HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents:
64267
diff
changeset
|
35 |
|
54681 | 36 |
|
60500 | 37 |
subsection \<open>Basic consequences of the definition\<close> |
54681 | 38 |
|
39 |
definition permutes (infixr "permutes" 41) |
|
40 |
where "(p permutes S) \<longleftrightarrow> (\<forall>x. x \<notin> S \<longrightarrow> p x = x) \<and> (\<forall>y. \<exists>!x. p x = y)" |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
41 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
42 |
lemma permutes_in_image: "p permutes S \<Longrightarrow> p x \<in> S \<longleftrightarrow> x \<in> S" |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
43 |
unfolding permutes_def by metis |
64284
f3b905b2eee2
HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents:
64267
diff
changeset
|
44 |
|
65342 | 45 |
lemma permutes_not_in: "f permutes S \<Longrightarrow> x \<notin> S \<Longrightarrow> f x = x" |
46 |
by (auto simp: permutes_def) |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
47 |
|
54681 | 48 |
lemma permutes_image: "p permutes S \<Longrightarrow> p ` S = S" |
30488 | 49 |
unfolding permutes_def |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
50 |
apply (rule set_eqI) |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
51 |
apply (simp add: image_iff) |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
52 |
apply metis |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
53 |
done |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
54 |
|
54681 | 55 |
lemma permutes_inj: "p permutes S \<Longrightarrow> inj p" |
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64543
diff
changeset
|
56 |
unfolding permutes_def inj_def by blast |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
57 |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
58 |
lemma permutes_inj_on: "f permutes S \<Longrightarrow> inj_on f A" |
65342 | 59 |
by (auto simp: permutes_def inj_on_def) |
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
60 |
|
54681 | 61 |
lemma permutes_surj: "p permutes s \<Longrightarrow> surj p" |
30488 | 62 |
unfolding permutes_def surj_def by metis |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
63 |
|
60601 | 64 |
lemma permutes_bij: "p permutes s \<Longrightarrow> bij p" |
65342 | 65 |
unfolding bij_def by (metis permutes_inj permutes_surj) |
60601 | 66 |
|
59474 | 67 |
lemma permutes_imp_bij: "p permutes S \<Longrightarrow> bij_betw p S S" |
65342 | 68 |
by (metis UNIV_I bij_betw_subset permutes_bij permutes_image subsetI) |
59669
de7792ea4090
renaming HOL/Fact.thy -> Binomial.thy
paulson <lp15@cam.ac.uk>
parents:
59474
diff
changeset
|
69 |
|
59474 | 70 |
lemma bij_imp_permutes: "bij_betw p S S \<Longrightarrow> (\<And>x. x \<notin> S \<Longrightarrow> p x = x) \<Longrightarrow> p permutes S" |
71 |
unfolding permutes_def bij_betw_def inj_on_def |
|
72 |
by auto (metis image_iff)+ |
|
73 |
||
54681 | 74 |
lemma permutes_inv_o: |
65342 | 75 |
assumes permutes: "p permutes S" |
54681 | 76 |
shows "p \<circ> inv p = id" |
77 |
and "inv p \<circ> p = id" |
|
65342 | 78 |
using permutes_inj[OF permutes] permutes_surj[OF permutes] |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
79 |
unfolding inj_iff[symmetric] surj_iff[symmetric] by blast+ |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
80 |
|
30488 | 81 |
lemma permutes_inverses: |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
82 |
fixes p :: "'a \<Rightarrow> 'a" |
65342 | 83 |
assumes permutes: "p permutes S" |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
84 |
shows "p (inv p x) = x" |
54681 | 85 |
and "inv p (p x) = x" |
65342 | 86 |
using permutes_inv_o[OF permutes, unfolded fun_eq_iff o_def] by auto |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
87 |
|
54681 | 88 |
lemma permutes_subset: "p permutes S \<Longrightarrow> S \<subseteq> T \<Longrightarrow> p permutes T" |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
89 |
unfolding permutes_def by blast |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
90 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
91 |
lemma permutes_empty[simp]: "p permutes {} \<longleftrightarrow> p = id" |
65342 | 92 |
by (auto simp add: fun_eq_iff permutes_def) |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
93 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
94 |
lemma permutes_sing[simp]: "p permutes {a} \<longleftrightarrow> p = id" |
65342 | 95 |
by (simp add: fun_eq_iff permutes_def) metis (*somewhat slow*) |
30488 | 96 |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
97 |
lemma permutes_univ: "p permutes UNIV \<longleftrightarrow> (\<forall>y. \<exists>!x. p x = y)" |
65342 | 98 |
by (simp add: permutes_def) |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
99 |
|
54681 | 100 |
lemma permutes_inv_eq: "p permutes S \<Longrightarrow> inv p y = x \<longleftrightarrow> p x = y" |
101 |
unfolding permutes_def inv_def |
|
102 |
apply auto |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
103 |
apply (erule allE[where x=y]) |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
104 |
apply (erule allE[where x=y]) |
54681 | 105 |
apply (rule someI_ex) |
106 |
apply blast |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
107 |
apply (rule some1_equality) |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
108 |
apply blast |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
109 |
apply blast |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
110 |
done |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
111 |
|
54681 | 112 |
lemma permutes_swap_id: "a \<in> S \<Longrightarrow> b \<in> S \<Longrightarrow> Fun.swap a b id permutes S" |
56545 | 113 |
unfolding permutes_def Fun.swap_def fun_upd_def by auto metis |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
114 |
|
54681 | 115 |
lemma permutes_superset: "p permutes S \<Longrightarrow> (\<forall>x \<in> S - T. p x = x) \<Longrightarrow> p permutes T" |
116 |
by (simp add: Ball_def permutes_def) metis |
|
117 |
||
63921
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
118 |
(* Next three lemmas contributed by Lukas Bulwahn *) |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
119 |
lemma permutes_bij_inv_into: |
65342 | 120 |
fixes A :: "'a set" |
121 |
and B :: "'b set" |
|
63921
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
122 |
assumes "p permutes A" |
65342 | 123 |
and "bij_betw f A B" |
63921
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
124 |
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
|
125 |
proof (rule bij_imp_permutes) |
65342 | 126 |
from assms have "bij_betw p A A" "bij_betw f A B" "bij_betw (inv_into A f) B A" |
127 |
by (auto simp add: permutes_imp_bij bij_betw_inv_into) |
|
128 |
then have "bij_betw (f \<circ> p \<circ> inv_into A f) B B" |
|
129 |
by (simp add: bij_betw_trans) |
|
130 |
then show "bij_betw (\<lambda>x. if x \<in> B then f (p (inv_into A f x)) else x) B B" |
|
131 |
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
|
132 |
next |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
133 |
fix x |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
134 |
assume "x \<notin> B" |
65342 | 135 |
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
|
136 |
qed |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
137 |
|
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
138 |
lemma permutes_image_mset: |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
139 |
assumes "p permutes A" |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
140 |
shows "image_mset p (mset_set A) = mset_set A" |
65342 | 141 |
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
|
142 |
|
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
143 |
lemma permutes_implies_image_mset_eq: |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
144 |
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
|
145 |
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
|
146 |
proof - |
65342 | 147 |
have "f x = f' (p x)" if "x \<in># mset_set A" for x |
148 |
using assms(2)[of x] that by (cases "finite A") auto |
|
149 |
with assms have "image_mset f (mset_set A) = image_mset (f' \<circ> p) (mset_set A)" |
|
150 |
by (auto intro!: image_mset_cong) |
|
63921
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
151 |
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
|
152 |
by (simp add: image_mset.compositionality) |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
153 |
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
|
154 |
proof - |
65342 | 155 |
from assms permutes_image_mset have "image_mset p (mset_set A) = mset_set A" |
156 |
by blast |
|
157 |
then show ?thesis by simp |
|
63921
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
158 |
qed |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
159 |
finally show ?thesis .. |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
160 |
qed |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
161 |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
162 |
|
60500 | 163 |
subsection \<open>Group properties\<close> |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
164 |
|
54681 | 165 |
lemma permutes_id: "id permutes S" |
65342 | 166 |
by (simp add: permutes_def) |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
167 |
|
54681 | 168 |
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
|
169 |
unfolding permutes_def o_def by metis |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
170 |
|
54681 | 171 |
lemma permutes_inv: |
65342 | 172 |
assumes "p permutes S" |
54681 | 173 |
shows "inv p permutes S" |
65342 | 174 |
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
|
175 |
|
54681 | 176 |
lemma permutes_inv_inv: |
65342 | 177 |
assumes "p permutes S" |
54681 | 178 |
shows "inv (inv p) = p" |
65342 | 179 |
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
|
180 |
by blast |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
181 |
|
64284
f3b905b2eee2
HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents:
64267
diff
changeset
|
182 |
lemma permutes_invI: |
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
183 |
assumes perm: "p permutes S" |
65342 | 184 |
and inv: "\<And>x. x \<in> S \<Longrightarrow> p' (p x) = x" |
185 |
and outside: "\<And>x. x \<notin> S \<Longrightarrow> p' x = x" |
|
186 |
shows "inv p = p'" |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
187 |
proof |
65342 | 188 |
show "inv p x = p' x" for x |
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
189 |
proof (cases "x \<in> S") |
65342 | 190 |
case True |
191 |
from assms have "p' x = p' (p (inv p x))" |
|
192 |
by (simp add: permutes_inverses) |
|
193 |
also from permutes_inv[OF perm] True have "\<dots> = inv p x" |
|
194 |
by (subst inv) (simp_all add: permutes_in_image) |
|
195 |
finally show ?thesis .. |
|
196 |
next |
|
197 |
case False |
|
198 |
with permutes_inv[OF perm] show ?thesis |
|
199 |
by (simp_all add: outside permutes_not_in) |
|
200 |
qed |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
201 |
qed |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
202 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
203 |
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
|
204 |
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
|
205 |
|
54681 | 206 |
|
66486
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
207 |
subsection \<open>Mapping permutations with bijections\<close> |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
208 |
|
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
209 |
lemma bij_betw_permutations: |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
210 |
assumes "bij_betw f A B" |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
211 |
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
|
212 |
{\<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
|
213 |
proof - |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
214 |
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
|
215 |
show ?thesis |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
216 |
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
|
217 |
case 3 |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
218 |
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
|
219 |
next |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
220 |
case 4 |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
221 |
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
|
222 |
{ |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
223 |
fix \<pi> assume "\<pi> permutes B" |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
224 |
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
|
225 |
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
|
226 |
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
|
227 |
} |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
228 |
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
|
229 |
next |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
230 |
case 1 |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
231 |
thus ?case using assms |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
232 |
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
|
233 |
dest: bij_betwE) |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
234 |
next |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
235 |
case 2 |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
236 |
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
|
237 |
by (intro bij_betw_inv_into assms) |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
238 |
ultimately show ?case using assms |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
239 |
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
|
240 |
dest: bij_betwE) |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
241 |
qed |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
242 |
qed |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
243 |
|
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
244 |
lemma bij_betw_derangements: |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
245 |
assumes "bij_betw f A B" |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
246 |
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
|
247 |
{\<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
|
248 |
(is "bij_betw ?f _ _") |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
249 |
proof - |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
250 |
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
|
251 |
show ?thesis |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
252 |
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
|
253 |
case 3 |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
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
|
258 |
next |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
259 |
case 4 |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
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
|
266 |
ultimately show ?case by auto |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
267 |
next |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
268 |
case 1 |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
269 |
thus ?case using assms |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
270 |
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
|
271 |
dest: bij_betwE) |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
272 |
next |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
273 |
case 2 |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
274 |
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
|
275 |
by (intro bij_betw_inv_into assms) |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
276 |
ultimately show ?case using assms |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
277 |
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
|
278 |
dest: bij_betwE) |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
279 |
qed |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
280 |
qed |
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
281 |
|
ffaaa83543b2
Lemmas about analysis and permutations
Manuel Eberl <eberlm@in.tum.de>
parents:
65552
diff
changeset
|
282 |
|
60500 | 283 |
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
|
284 |
|
30488 | 285 |
lemma permutes_insert_lemma: |
65342 | 286 |
assumes "p permutes (insert a S)" |
54681 | 287 |
shows "Fun.swap a (p a) id \<circ> p permutes S" |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
288 |
apply (rule permutes_superset[where S = "insert a S"]) |
65342 | 289 |
apply (rule permutes_compose[OF assms]) |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
290 |
apply (rule permutes_swap_id, simp) |
65342 | 291 |
using permutes_in_image[OF assms, of a] |
54681 | 292 |
apply simp |
56545 | 293 |
apply (auto simp add: Ball_def Fun.swap_def) |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
294 |
done |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
295 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
296 |
lemma permutes_insert: "{p. p permutes (insert a S)} = |
65342 | 297 |
(\<lambda>(b, p). Fun.swap a b id \<circ> p) ` {(b, p). b \<in> insert a S \<and> p \<in> {p. p permutes S}}" |
54681 | 298 |
proof - |
65342 | 299 |
have "p permutes insert a S \<longleftrightarrow> |
300 |
(\<exists>b q. p = Fun.swap a b id \<circ> q \<and> b \<in> insert a S \<and> q permutes S)" for p |
|
301 |
proof - |
|
302 |
have "\<exists>b q. p = Fun.swap a b id \<circ> q \<and> b \<in> insert a S \<and> q permutes S" |
|
303 |
if p: "p permutes insert a S" |
|
304 |
proof - |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
305 |
let ?b = "p a" |
54681 | 306 |
let ?q = "Fun.swap a (p a) id \<circ> p" |
65342 | 307 |
have *: "p = Fun.swap a ?b id \<circ> ?q" |
308 |
by (simp add: fun_eq_iff o_assoc) |
|
309 |
have **: "?b \<in> insert a S" |
|
310 |
unfolding permutes_in_image[OF p] by simp |
|
311 |
from permutes_insert_lemma[OF p] * ** show ?thesis |
|
312 |
by blast |
|
313 |
qed |
|
314 |
moreover have "p permutes insert a S" |
|
315 |
if bq: "p = Fun.swap a b id \<circ> q" "b \<in> insert a S" "q permutes S" for b q |
|
316 |
proof - |
|
317 |
from permutes_subset[OF bq(3), of "insert a S"] have q: "q permutes insert a S" |
|
54681 | 318 |
by auto |
65342 | 319 |
have a: "a \<in> insert a S" |
54681 | 320 |
by simp |
65342 | 321 |
from bq(1) permutes_compose[OF q permutes_swap_id[OF a bq(2)]] show ?thesis |
54681 | 322 |
by simp |
65342 | 323 |
qed |
324 |
ultimately show ?thesis by blast |
|
325 |
qed |
|
326 |
then show ?thesis by auto |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
327 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
328 |
|
54681 | 329 |
lemma card_permutations: |
65342 | 330 |
assumes "card S = n" |
331 |
and "finite S" |
|
33715 | 332 |
shows "card {p. p permutes S} = fact n" |
65342 | 333 |
using assms(2,1) |
54681 | 334 |
proof (induct arbitrary: n) |
335 |
case empty |
|
336 |
then show ?case by simp |
|
33715 | 337 |
next |
338 |
case (insert x F) |
|
54681 | 339 |
{ |
340 |
fix n |
|
65342 | 341 |
assume card_insert: "card (insert x F) = n" |
33715 | 342 |
let ?xF = "{p. p permutes insert x F}" |
343 |
let ?pF = "{p. p permutes F}" |
|
344 |
let ?pF' = "{(b, p). b \<in> insert x F \<and> p \<in> ?pF}" |
|
345 |
let ?g = "(\<lambda>(b, p). Fun.swap x b id \<circ> p)" |
|
65342 | 346 |
have xfgpF': "?xF = ?g ` ?pF'" |
347 |
by (rule permutes_insert[of x F]) |
|
348 |
from \<open>x \<notin> F\<close> \<open>finite F\<close> card_insert have Fs: "card F = n - 1" |
|
349 |
by auto |
|
350 |
from \<open>finite F\<close> insert.hyps Fs have pFs: "card ?pF = fact (n - 1)" |
|
351 |
by auto |
|
54681 | 352 |
then have "finite ?pF" |
59730
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents:
59669
diff
changeset
|
353 |
by (auto intro: card_ge_0_finite) |
65342 | 354 |
with \<open>finite F\<close> card_insert have pF'f: "finite ?pF'" |
61424
c3658c18b7bc
prod_case as canonical name for product type eliminator
haftmann
parents:
60601
diff
changeset
|
355 |
apply (simp only: Collect_case_prod Collect_mem_eq) |
33715 | 356 |
apply (rule finite_cartesian_product) |
357 |
apply simp_all |
|
358 |
done |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
359 |
|
33715 | 360 |
have ginj: "inj_on ?g ?pF'" |
54681 | 361 |
proof - |
33715 | 362 |
{ |
54681 | 363 |
fix b p c q |
65342 | 364 |
assume bp: "(b, p) \<in> ?pF'" |
365 |
assume cq: "(c, q) \<in> ?pF'" |
|
366 |
assume eq: "?g (b, p) = ?g (c, q)" |
|
367 |
from bp cq have pF: "p permutes F" and qF: "q permutes F" |
|
54681 | 368 |
by auto |
65342 | 369 |
from pF \<open>x \<notin> F\<close> eq have "b = ?g (b, p) x" |
370 |
by (auto simp: permutes_def Fun.swap_def fun_upd_def fun_eq_iff) |
|
371 |
also from qF \<open>x \<notin> F\<close> eq have "\<dots> = ?g (c, q) x" |
|
372 |
by (auto simp: swap_def fun_upd_def fun_eq_iff) |
|
373 |
also from qF \<open>x \<notin> F\<close> have "\<dots> = c" |
|
374 |
by (auto simp: permutes_def Fun.swap_def fun_upd_def fun_eq_iff) |
|
375 |
finally have "b = c" . |
|
54681 | 376 |
then have "Fun.swap x b id = Fun.swap x c id" |
377 |
by simp |
|
378 |
with eq have "Fun.swap x b id \<circ> p = Fun.swap x b id \<circ> q" |
|
379 |
by simp |
|
65342 | 380 |
then have "Fun.swap x b id \<circ> (Fun.swap x b id \<circ> p) = Fun.swap x b id \<circ> (Fun.swap x b id \<circ> q)" |
54681 | 381 |
by simp |
382 |
then have "p = q" |
|
383 |
by (simp add: o_assoc) |
|
65342 | 384 |
with \<open>b = c\<close> have "(b, p) = (c, q)" |
54681 | 385 |
by simp |
33715 | 386 |
} |
54681 | 387 |
then show ?thesis |
388 |
unfolding inj_on_def by blast |
|
33715 | 389 |
qed |
65342 | 390 |
from \<open>x \<notin> F\<close> \<open>finite F\<close> card_insert have "n \<noteq> 0" |
391 |
by auto |
|
54681 | 392 |
then have "\<exists>m. n = Suc m" |
393 |
by presburger |
|
65342 | 394 |
then obtain m where n: "n = Suc m" |
54681 | 395 |
by blast |
65342 | 396 |
from pFs card_insert have *: "card ?xF = fact n" |
54681 | 397 |
unfolding xfgpF' card_image[OF ginj] |
60500 | 398 |
using \<open>finite F\<close> \<open>finite ?pF\<close> |
65342 | 399 |
by (simp only: Collect_case_prod Collect_mem_eq card_cartesian_product) (simp add: n) |
54681 | 400 |
from finite_imageI[OF pF'f, of ?g] have xFf: "finite ?xF" |
65342 | 401 |
by (simp add: xfgpF' n) |
402 |
from * have "card ?xF = fact n" |
|
403 |
unfolding xFf by blast |
|
33715 | 404 |
} |
65342 | 405 |
with insert show ?case by simp |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
406 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
407 |
|
54681 | 408 |
lemma finite_permutations: |
65342 | 409 |
assumes "finite S" |
54681 | 410 |
shows "finite {p. p permutes S}" |
65342 | 411 |
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
|
412 |
|
54681 | 413 |
|
60500 | 414 |
subsection \<open>Permutations of index set for iterated operations\<close> |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
415 |
|
51489 | 416 |
lemma (in comm_monoid_set) permute: |
417 |
assumes "p permutes S" |
|
54681 | 418 |
shows "F g S = F (g \<circ> p) S" |
51489 | 419 |
proof - |
60500 | 420 |
from \<open>p permutes S\<close> have "inj p" |
54681 | 421 |
by (rule permutes_inj) |
422 |
then have "inj_on p S" |
|
423 |
by (auto intro: subset_inj_on) |
|
424 |
then have "F g (p ` S) = F (g \<circ> p) S" |
|
425 |
by (rule reindex) |
|
60500 | 426 |
moreover from \<open>p permutes S\<close> have "p ` S = S" |
54681 | 427 |
by (rule permutes_image) |
428 |
ultimately show ?thesis |
|
429 |
by simp |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
430 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
431 |
|
54681 | 432 |
|
60500 | 433 |
subsection \<open>Various combinations of transpositions with 2, 1 and 0 common elements\<close> |
54681 | 434 |
|
435 |
lemma swap_id_common:" a \<noteq> c \<Longrightarrow> b \<noteq> c \<Longrightarrow> |
|
436 |
Fun.swap a b id \<circ> Fun.swap a c id = Fun.swap b c id \<circ> Fun.swap a b id" |
|
56545 | 437 |
by (simp add: fun_eq_iff Fun.swap_def) |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
438 |
|
54681 | 439 |
lemma swap_id_common': "a \<noteq> b \<Longrightarrow> a \<noteq> c \<Longrightarrow> |
440 |
Fun.swap a c id \<circ> Fun.swap b c id = Fun.swap b c id \<circ> Fun.swap a b id" |
|
56545 | 441 |
by (simp add: fun_eq_iff Fun.swap_def) |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
442 |
|
54681 | 443 |
lemma swap_id_independent: "a \<noteq> c \<Longrightarrow> a \<noteq> d \<Longrightarrow> b \<noteq> c \<Longrightarrow> b \<noteq> d \<Longrightarrow> |
444 |
Fun.swap a b id \<circ> Fun.swap c d id = Fun.swap c d id \<circ> Fun.swap a b id" |
|
56545 | 445 |
by (simp add: fun_eq_iff Fun.swap_def) |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
446 |
|
54681 | 447 |
|
60500 | 448 |
subsection \<open>Permutations as transposition sequences\<close> |
54681 | 449 |
|
450 |
inductive swapidseq :: "nat \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> bool" |
|
65342 | 451 |
where |
452 |
id[simp]: "swapidseq 0 id" |
|
453 |
| comp_Suc: "swapidseq n p \<Longrightarrow> a \<noteq> b \<Longrightarrow> swapidseq (Suc n) (Fun.swap a b id \<circ> p)" |
|
54681 | 454 |
|
455 |
declare id[unfolded id_def, simp] |
|
456 |
||
457 |
definition "permutation p \<longleftrightarrow> (\<exists>n. swapidseq n p)" |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
458 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
459 |
|
60500 | 460 |
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
|
461 |
|
54681 | 462 |
lemma permutation_id[simp]: "permutation id" |
463 |
unfolding permutation_def by (rule exI[where x=0]) simp |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
464 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
465 |
declare permutation_id[unfolded id_def, simp] |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
466 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
467 |
lemma swapidseq_swap: "swapidseq (if a = b then 0 else 1) (Fun.swap a b id)" |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
468 |
apply clarsimp |
54681 | 469 |
using comp_Suc[of 0 id a b] |
470 |
apply simp |
|
471 |
done |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
472 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
473 |
lemma permutation_swap_id: "permutation (Fun.swap a b id)" |
65342 | 474 |
proof (cases "a = b") |
475 |
case True |
|
476 |
then show ?thesis by simp |
|
477 |
next |
|
478 |
case False |
|
479 |
then show ?thesis |
|
480 |
unfolding permutation_def |
|
481 |
using swapidseq_swap[of a b] by blast |
|
482 |
qed |
|
483 |
||
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
484 |
|
54681 | 485 |
lemma swapidseq_comp_add: "swapidseq n p \<Longrightarrow> swapidseq m q \<Longrightarrow> swapidseq (n + m) (p \<circ> q)" |
486 |
proof (induct n p arbitrary: m q rule: swapidseq.induct) |
|
487 |
case (id m q) |
|
488 |
then show ?case by simp |
|
489 |
next |
|
490 |
case (comp_Suc n p a b m q) |
|
65342 | 491 |
have eq: "Suc n + m = Suc (n + m)" |
54681 | 492 |
by arith |
493 |
show ?case |
|
65342 | 494 |
apply (simp only: eq comp_assoc) |
54681 | 495 |
apply (rule swapidseq.comp_Suc) |
496 |
using comp_Suc.hyps(2)[OF comp_Suc.prems] comp_Suc.hyps(3) |
|
65342 | 497 |
apply blast+ |
54681 | 498 |
done |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
499 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
500 |
|
54681 | 501 |
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
|
502 |
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
|
503 |
|
54681 | 504 |
lemma swapidseq_endswap: "swapidseq n p \<Longrightarrow> a \<noteq> b \<Longrightarrow> swapidseq (Suc n) (p \<circ> Fun.swap a b id)" |
65342 | 505 |
by (induct n p rule: swapidseq.induct) |
506 |
(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
|
507 |
|
54681 | 508 |
lemma swapidseq_inverse_exists: "swapidseq n p \<Longrightarrow> \<exists>q. swapidseq n q \<and> p \<circ> q = id \<and> q \<circ> p = id" |
509 |
proof (induct n p rule: swapidseq.induct) |
|
510 |
case id |
|
511 |
then show ?case |
|
512 |
by (rule exI[where x=id]) simp |
|
30488 | 513 |
next |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
514 |
case (comp_Suc n p a b) |
54681 | 515 |
from comp_Suc.hyps obtain q where q: "swapidseq n q" "p \<circ> q = id" "q \<circ> p = id" |
516 |
by blast |
|
517 |
let ?q = "q \<circ> Fun.swap a b id" |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
518 |
note H = comp_Suc.hyps |
65342 | 519 |
from swapidseq_swap[of a b] H(3) have *: "swapidseq 1 (Fun.swap a b id)" |
54681 | 520 |
by simp |
65342 | 521 |
from swapidseq_comp_add[OF q(1) *] have **: "swapidseq (Suc n) ?q" |
54681 | 522 |
by simp |
523 |
have "Fun.swap a b id \<circ> p \<circ> ?q = Fun.swap a b id \<circ> (p \<circ> q) \<circ> Fun.swap a b id" |
|
524 |
by (simp add: o_assoc) |
|
525 |
also have "\<dots> = id" |
|
526 |
by (simp add: q(2)) |
|
65342 | 527 |
finally have ***: "Fun.swap a b id \<circ> p \<circ> ?q = id" . |
54681 | 528 |
have "?q \<circ> (Fun.swap a b id \<circ> p) = q \<circ> (Fun.swap a b id \<circ> Fun.swap a b id) \<circ> p" |
529 |
by (simp only: o_assoc) |
|
530 |
then have "?q \<circ> (Fun.swap a b id \<circ> p) = id" |
|
531 |
by (simp add: q(3)) |
|
65342 | 532 |
with ** *** show ?case |
54681 | 533 |
by blast |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
534 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
535 |
|
54681 | 536 |
lemma swapidseq_inverse: |
65342 | 537 |
assumes "swapidseq n p" |
54681 | 538 |
shows "swapidseq n (inv p)" |
65342 | 539 |
using swapidseq_inverse_exists[OF assms] inv_unique_comp[of p] by auto |
54681 | 540 |
|
541 |
lemma permutation_inverse: "permutation p \<Longrightarrow> permutation (inv p)" |
|
542 |
using permutation_def swapidseq_inverse by blast |
|
543 |
||
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
544 |
|
60500 | 545 |
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
|
546 |
|
54681 | 547 |
lemma symmetry_lemma: |
548 |
assumes "\<And>a b c d. P a b c d \<Longrightarrow> P a b d c" |
|
549 |
and "\<And>a b c d. a \<noteq> b \<Longrightarrow> c \<noteq> d \<Longrightarrow> |
|
550 |
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> |
|
551 |
P a b c d" |
|
552 |
shows "\<And>a b c d. a \<noteq> b \<longrightarrow> c \<noteq> d \<longrightarrow> P a b c d" |
|
553 |
using assms by metis |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
554 |
|
54681 | 555 |
lemma swap_general: "a \<noteq> b \<Longrightarrow> c \<noteq> d \<Longrightarrow> |
556 |
Fun.swap a b id \<circ> Fun.swap c d id = id \<or> |
|
557 |
(\<exists>x y z. x \<noteq> a \<and> y \<noteq> a \<and> z \<noteq> a \<and> x \<noteq> y \<and> |
|
558 |
Fun.swap a b id \<circ> Fun.swap c d id = Fun.swap x y id \<circ> Fun.swap a z id)" |
|
559 |
proof - |
|
65342 | 560 |
assume neq: "a \<noteq> b" "c \<noteq> d" |
54681 | 561 |
have "a \<noteq> b \<longrightarrow> c \<noteq> d \<longrightarrow> |
562 |
(Fun.swap a b id \<circ> Fun.swap c d id = id \<or> |
|
563 |
(\<exists>x y z. x \<noteq> a \<and> y \<noteq> a \<and> z \<noteq> a \<and> x \<noteq> y \<and> |
|
564 |
Fun.swap a b id \<circ> Fun.swap c d id = Fun.swap x y id \<circ> Fun.swap a z id))" |
|
565 |
apply (rule symmetry_lemma[where a=a and b=b and c=c and d=d]) |
|
65342 | 566 |
apply (simp_all only: swap_commute) |
54681 | 567 |
apply (case_tac "a = c \<and> b = d") |
65342 | 568 |
apply (clarsimp simp only: swap_commute swap_id_idempotent) |
54681 | 569 |
apply (case_tac "a = c \<and> b \<noteq> d") |
65342 | 570 |
apply (rule disjI2) |
571 |
apply (rule_tac x="b" in exI) |
|
572 |
apply (rule_tac x="d" in exI) |
|
573 |
apply (rule_tac x="b" in exI) |
|
574 |
apply (clarsimp simp add: fun_eq_iff Fun.swap_def) |
|
54681 | 575 |
apply (case_tac "a \<noteq> c \<and> b = d") |
65342 | 576 |
apply (rule disjI2) |
577 |
apply (rule_tac x="c" in exI) |
|
578 |
apply (rule_tac x="d" in exI) |
|
579 |
apply (rule_tac x="c" in exI) |
|
580 |
apply (clarsimp simp add: fun_eq_iff Fun.swap_def) |
|
54681 | 581 |
apply (rule disjI2) |
582 |
apply (rule_tac x="c" in exI) |
|
583 |
apply (rule_tac x="d" in exI) |
|
584 |
apply (rule_tac x="b" in exI) |
|
56545 | 585 |
apply (clarsimp simp add: fun_eq_iff Fun.swap_def) |
54681 | 586 |
done |
65342 | 587 |
with neq show ?thesis by metis |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
588 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
589 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
590 |
lemma swapidseq_id_iff[simp]: "swapidseq 0 p \<longleftrightarrow> p = id" |
65342 | 591 |
using swapidseq.cases[of 0 p "p = id"] by auto |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
592 |
|
54681 | 593 |
lemma swapidseq_cases: "swapidseq n p \<longleftrightarrow> |
65342 | 594 |
n = 0 \<and> p = id \<or> (\<exists>a b q m. n = Suc m \<and> p = Fun.swap a b id \<circ> q \<and> swapidseq m q \<and> a \<noteq> b)" |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
595 |
apply (rule iffI) |
65342 | 596 |
apply (erule swapidseq.cases[of n p]) |
597 |
apply simp |
|
598 |
apply (rule disjI2) |
|
599 |
apply (rule_tac x= "a" in exI) |
|
600 |
apply (rule_tac x= "b" in exI) |
|
601 |
apply (rule_tac x= "pa" in exI) |
|
602 |
apply (rule_tac x= "na" in exI) |
|
603 |
apply simp |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
604 |
apply auto |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
605 |
apply (rule comp_Suc, simp_all) |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
606 |
done |
54681 | 607 |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
608 |
lemma fixing_swapidseq_decrease: |
65342 | 609 |
assumes "swapidseq n p" |
610 |
and "a \<noteq> b" |
|
611 |
and "(Fun.swap a b id \<circ> p) a = a" |
|
54681 | 612 |
shows "n \<noteq> 0 \<and> swapidseq (n - 1) (Fun.swap a b id \<circ> p)" |
65342 | 613 |
using assms |
54681 | 614 |
proof (induct n arbitrary: p a b) |
615 |
case 0 |
|
616 |
then show ?case |
|
56545 | 617 |
by (auto simp add: Fun.swap_def fun_upd_def) |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
618 |
next |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
619 |
case (Suc n p a b) |
54681 | 620 |
from Suc.prems(1) swapidseq_cases[of "Suc n" p] |
621 |
obtain c d q m where |
|
622 |
cdqm: "Suc n = Suc m" "p = Fun.swap c d id \<circ> q" "swapidseq m q" "c \<noteq> d" "n = m" |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
623 |
by auto |
65342 | 624 |
consider "Fun.swap a b id \<circ> Fun.swap c d id = id" |
625 |
| x y z where "x \<noteq> a" "y \<noteq> a" "z \<noteq> a" "x \<noteq> y" |
|
54681 | 626 |
"Fun.swap a b id \<circ> Fun.swap c d id = Fun.swap x y id \<circ> Fun.swap a z id" |
65342 | 627 |
using swap_general[OF Suc.prems(2) cdqm(4)] by metis |
628 |
then show ?case |
|
629 |
proof cases |
|
630 |
case 1 |
|
631 |
then show ?thesis |
|
632 |
by (simp only: cdqm o_assoc) (simp add: cdqm) |
|
633 |
next |
|
634 |
case prems: 2 |
|
635 |
then have az: "a \<noteq> z" |
|
54681 | 636 |
by simp |
65342 | 637 |
from prems have *: "(Fun.swap x y id \<circ> h) a = a \<longleftrightarrow> h a = a" for h |
638 |
by (simp add: Fun.swap_def) |
|
54681 | 639 |
from cdqm(2) have "Fun.swap a b id \<circ> p = Fun.swap a b id \<circ> (Fun.swap c d id \<circ> q)" |
640 |
by simp |
|
641 |
then have "Fun.swap a b id \<circ> p = Fun.swap x y id \<circ> (Fun.swap a z id \<circ> q)" |
|
65342 | 642 |
by (simp add: o_assoc prems) |
54681 | 643 |
then have "(Fun.swap a b id \<circ> p) a = (Fun.swap x y id \<circ> (Fun.swap a z id \<circ> q)) a" |
644 |
by simp |
|
645 |
then have "(Fun.swap x y id \<circ> (Fun.swap a z id \<circ> q)) a = a" |
|
646 |
unfolding Suc by metis |
|
65342 | 647 |
then have "(Fun.swap a z id \<circ> q) a = a" |
648 |
by (simp only: *) |
|
649 |
from Suc.hyps[OF cdqm(3)[ unfolded cdqm(5)[symmetric]] az this] |
|
650 |
have **: "swapidseq (n - 1) (Fun.swap a z id \<circ> q)" "n \<noteq> 0" |
|
54681 | 651 |
by blast+ |
65342 | 652 |
from \<open>n \<noteq> 0\<close> have ***: "Suc n - 1 = Suc (n - 1)" |
653 |
by auto |
|
654 |
show ?thesis |
|
655 |
apply (simp only: cdqm(2) prems o_assoc ***) |
|
49739 | 656 |
apply (simp only: Suc_not_Zero simp_thms comp_assoc) |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
657 |
apply (rule comp_Suc) |
65342 | 658 |
using ** prems |
659 |
apply blast+ |
|
54681 | 660 |
done |
65342 | 661 |
qed |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
662 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
663 |
|
30488 | 664 |
lemma swapidseq_identity_even: |
54681 | 665 |
assumes "swapidseq n (id :: 'a \<Rightarrow> 'a)" |
666 |
shows "even n" |
|
60500 | 667 |
using \<open>swapidseq n id\<close> |
54681 | 668 |
proof (induct n rule: nat_less_induct) |
65342 | 669 |
case H: (1 n) |
670 |
consider "n = 0" |
|
671 |
| a b :: 'a and q m where "n = Suc m" "id = Fun.swap a b id \<circ> q" "swapidseq m q" "a \<noteq> b" |
|
672 |
using H(2)[unfolded swapidseq_cases[of n id]] by auto |
|
673 |
then show ?case |
|
674 |
proof cases |
|
675 |
case 1 |
|
676 |
then show ?thesis by presburger |
|
677 |
next |
|
678 |
case h: 2 |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
679 |
from fixing_swapidseq_decrease[OF h(3,4), unfolded h(2)[symmetric]] |
54681 | 680 |
have m: "m \<noteq> 0" "swapidseq (m - 1) (id :: 'a \<Rightarrow> 'a)" |
681 |
by auto |
|
682 |
from h m have mn: "m - 1 < n" |
|
683 |
by arith |
|
65342 | 684 |
from H(1)[rule_format, OF mn m(2)] h(1) m(1) show ?thesis |
54681 | 685 |
by presburger |
65342 | 686 |
qed |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
687 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
688 |
|
54681 | 689 |
|
60500 | 690 |
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
|
691 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
692 |
definition "evenperm p = even (SOME n. swapidseq n p)" |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
693 |
|
54681 | 694 |
lemma swapidseq_even_even: |
695 |
assumes m: "swapidseq m p" |
|
696 |
and n: "swapidseq n p" |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
697 |
shows "even m \<longleftrightarrow> even n" |
54681 | 698 |
proof - |
65342 | 699 |
from swapidseq_inverse_exists[OF n] obtain q where q: "swapidseq n q" "p \<circ> q = id" "q \<circ> p = id" |
54681 | 700 |
by blast |
65342 | 701 |
from swapidseq_identity_even[OF swapidseq_comp_add[OF m q(1), unfolded q]] show ?thesis |
54681 | 702 |
by arith |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
703 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
704 |
|
54681 | 705 |
lemma evenperm_unique: |
706 |
assumes p: "swapidseq n p" |
|
707 |
and n:"even n = b" |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
708 |
shows "evenperm p = b" |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
709 |
unfolding n[symmetric] evenperm_def |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
710 |
apply (rule swapidseq_even_even[where p = p]) |
65342 | 711 |
apply (rule someI[where x = n]) |
54681 | 712 |
using p |
65342 | 713 |
apply blast+ |
54681 | 714 |
done |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
715 |
|
54681 | 716 |
|
60500 | 717 |
subsection \<open>And it has the expected composition properties\<close> |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
718 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
719 |
lemma evenperm_id[simp]: "evenperm id = True" |
54681 | 720 |
by (rule evenperm_unique[where n = 0]) simp_all |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
721 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
722 |
lemma evenperm_swap: "evenperm (Fun.swap a b id) = (a = b)" |
54681 | 723 |
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
|
724 |
|
30488 | 725 |
lemma evenperm_comp: |
65342 | 726 |
assumes "permutation p" "permutation q" |
727 |
shows "evenperm (p \<circ> q) \<longleftrightarrow> evenperm p = evenperm q" |
|
54681 | 728 |
proof - |
65342 | 729 |
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
|
730 |
unfolding permutation_def by blast |
65342 | 731 |
have "even (n + m) \<longleftrightarrow> (even n \<longleftrightarrow> even m)" |
54681 | 732 |
by arith |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
733 |
from evenperm_unique[OF n refl] evenperm_unique[OF m refl] |
65342 | 734 |
and evenperm_unique[OF swapidseq_comp_add[OF n m] this] show ?thesis |
54681 | 735 |
by blast |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
736 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
737 |
|
54681 | 738 |
lemma evenperm_inv: |
65342 | 739 |
assumes "permutation p" |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
740 |
shows "evenperm (inv p) = evenperm p" |
54681 | 741 |
proof - |
65342 | 742 |
from assms obtain n where n: "swapidseq n p" |
54681 | 743 |
unfolding permutation_def by blast |
65342 | 744 |
show ?thesis |
745 |
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
|
746 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
747 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
748 |
|
60500 | 749 |
subsection \<open>A more abstract characterization of permutations\<close> |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
750 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
751 |
lemma bij_iff: "bij f \<longleftrightarrow> (\<forall>x. \<exists>!y. f y = x)" |
64966
d53d7ca3303e
added inj_def (redundant, analogous to surj_def, bij_def);
wenzelm
parents:
64543
diff
changeset
|
752 |
unfolding bij_def inj_def surj_def |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
753 |
apply auto |
65342 | 754 |
apply metis |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
755 |
apply metis |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
756 |
done |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
757 |
|
30488 | 758 |
lemma permutation_bijective: |
65342 | 759 |
assumes "permutation p" |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
760 |
shows "bij p" |
54681 | 761 |
proof - |
65342 | 762 |
from assms obtain n where n: "swapidseq n p" |
54681 | 763 |
unfolding permutation_def by blast |
65342 | 764 |
from swapidseq_inverse_exists[OF n] obtain q where q: "swapidseq n q" "p \<circ> q = id" "q \<circ> p = id" |
54681 | 765 |
by blast |
65342 | 766 |
then show ?thesis |
767 |
unfolding bij_iff |
|
54681 | 768 |
apply (auto simp add: fun_eq_iff) |
769 |
apply metis |
|
770 |
done |
|
30488 | 771 |
qed |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
772 |
|
54681 | 773 |
lemma permutation_finite_support: |
65342 | 774 |
assumes "permutation p" |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
775 |
shows "finite {x. p x \<noteq> x}" |
54681 | 776 |
proof - |
65342 | 777 |
from assms obtain n where "swapidseq n p" |
54681 | 778 |
unfolding permutation_def by blast |
65342 | 779 |
then show ?thesis |
54681 | 780 |
proof (induct n p rule: swapidseq.induct) |
781 |
case id |
|
782 |
then show ?case by simp |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
783 |
next |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
784 |
case (comp_Suc n p a b) |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
785 |
let ?S = "insert a (insert b {x. p x \<noteq> x})" |
65342 | 786 |
from comp_Suc.hyps(2) have *: "finite ?S" |
54681 | 787 |
by simp |
65342 | 788 |
from \<open>a \<noteq> b\<close> have **: "{x. (Fun.swap a b id \<circ> p) x \<noteq> x} \<subseteq> ?S" |
789 |
by (auto simp: Fun.swap_def) |
|
790 |
show ?case |
|
791 |
by (rule finite_subset[OF ** *]) |
|
54681 | 792 |
qed |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
793 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
794 |
|
30488 | 795 |
lemma permutation_lemma: |
65342 | 796 |
assumes "finite S" |
797 |
and "bij p" |
|
798 |
and "\<forall>x. x\<notin> S \<longrightarrow> p x = x" |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
799 |
shows "permutation p" |
65342 | 800 |
using assms |
54681 | 801 |
proof (induct S arbitrary: p rule: finite_induct) |
65342 | 802 |
case empty |
803 |
then show ?case |
|
804 |
by simp |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
805 |
next |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
806 |
case (insert a F p) |
54681 | 807 |
let ?r = "Fun.swap a (p a) id \<circ> p" |
808 |
let ?q = "Fun.swap a (p a) id \<circ> ?r" |
|
65342 | 809 |
have *: "?r a = a" |
56545 | 810 |
by (simp add: Fun.swap_def) |
65342 | 811 |
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
|
812 |
by (metis bij_pointE comp_apply id_apply insert_iff swap_apply(3)) |
65342 | 813 |
have "bij ?r" |
814 |
by (rule bij_swap_compose_bij[OF insert(4)]) |
|
815 |
have "permutation ?r" |
|
816 |
by (rule insert(3)[OF \<open>bij ?r\<close> **]) |
|
817 |
then have "permutation ?q" |
|
818 |
by (simp add: permutation_compose permutation_swap_id) |
|
54681 | 819 |
then show ?case |
820 |
by (simp add: o_assoc) |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
821 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
822 |
|
30488 | 823 |
lemma permutation: "permutation p \<longleftrightarrow> bij p \<and> finite {x. p x \<noteq> x}" |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
824 |
(is "?lhs \<longleftrightarrow> ?b \<and> ?f") |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
825 |
proof |
65342 | 826 |
assume ?lhs |
827 |
with permutation_bijective permutation_finite_support show "?b \<and> ?f" |
|
54681 | 828 |
by auto |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
829 |
next |
54681 | 830 |
assume "?b \<and> ?f" |
831 |
then have "?f" "?b" by blast+ |
|
832 |
from permutation_lemma[OF this] show ?lhs |
|
833 |
by blast |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
834 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
835 |
|
54681 | 836 |
lemma permutation_inverse_works: |
65342 | 837 |
assumes "permutation p" |
54681 | 838 |
shows "inv p \<circ> p = id" |
839 |
and "p \<circ> inv p = id" |
|
65342 | 840 |
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
|
841 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
842 |
lemma permutation_inverse_compose: |
54681 | 843 |
assumes p: "permutation p" |
844 |
and q: "permutation q" |
|
845 |
shows "inv (p \<circ> q) = inv q \<circ> inv p" |
|
846 |
proof - |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
847 |
note ps = permutation_inverse_works[OF p] |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
848 |
note qs = permutation_inverse_works[OF q] |
54681 | 849 |
have "p \<circ> q \<circ> (inv q \<circ> inv p) = p \<circ> (q \<circ> inv q) \<circ> inv p" |
850 |
by (simp add: o_assoc) |
|
851 |
also have "\<dots> = id" |
|
852 |
by (simp add: ps qs) |
|
65342 | 853 |
finally have *: "p \<circ> q \<circ> (inv q \<circ> inv p) = id" . |
54681 | 854 |
have "inv q \<circ> inv p \<circ> (p \<circ> q) = inv q \<circ> (inv p \<circ> p) \<circ> q" |
855 |
by (simp add: o_assoc) |
|
856 |
also have "\<dots> = id" |
|
857 |
by (simp add: ps qs) |
|
65342 | 858 |
finally have **: "inv q \<circ> inv p \<circ> (p \<circ> q) = id" . |
859 |
show ?thesis |
|
860 |
by (rule inv_unique_comp[OF * **]) |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
861 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
862 |
|
54681 | 863 |
|
65342 | 864 |
subsection \<open>Relation to \<open>permutes\<close>\<close> |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
865 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
866 |
lemma permutation_permutes: "permutation p \<longleftrightarrow> (\<exists>S. finite S \<and> p permutes S)" |
54681 | 867 |
unfolding permutation permutes_def bij_iff[symmetric] |
868 |
apply (rule iffI, clarify) |
|
65342 | 869 |
apply (rule exI[where x="{x. p x \<noteq> x}"]) |
870 |
apply simp |
|
54681 | 871 |
apply clarsimp |
872 |
apply (rule_tac B="S" in finite_subset) |
|
65342 | 873 |
apply auto |
54681 | 874 |
done |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
875 |
|
54681 | 876 |
|
60500 | 877 |
subsection \<open>Hence a sort of induction principle composing by swaps\<close> |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
878 |
|
54681 | 879 |
lemma permutes_induct: "finite S \<Longrightarrow> P id \<Longrightarrow> |
65342 | 880 |
(\<And>a b p. a \<in> S \<Longrightarrow> b \<in> S \<Longrightarrow> P p \<Longrightarrow> P p \<Longrightarrow> permutation p \<Longrightarrow> P (Fun.swap a b id \<circ> p)) \<Longrightarrow> |
54681 | 881 |
(\<And>p. p permutes S \<Longrightarrow> P p)" |
882 |
proof (induct S rule: finite_induct) |
|
883 |
case empty |
|
884 |
then show ?case by auto |
|
30488 | 885 |
next |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
886 |
case (insert x F p) |
54681 | 887 |
let ?r = "Fun.swap x (p x) id \<circ> p" |
888 |
let ?q = "Fun.swap x (p x) id \<circ> ?r" |
|
889 |
have qp: "?q = p" |
|
890 |
by (simp add: o_assoc) |
|
891 |
from permutes_insert_lemma[OF insert.prems(3)] insert have Pr: "P ?r" |
|
892 |
by blast |
|
30488 | 893 |
from permutes_in_image[OF insert.prems(3), of x] |
54681 | 894 |
have pxF: "p x \<in> insert x F" |
895 |
by simp |
|
896 |
have xF: "x \<in> insert x F" |
|
897 |
by simp |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
898 |
have rp: "permutation ?r" |
65342 | 899 |
unfolding permutation_permutes |
900 |
using insert.hyps(1) permutes_insert_lemma[OF insert.prems(3)] |
|
54681 | 901 |
by blast |
65342 | 902 |
from insert.prems(2)[OF xF pxF Pr Pr rp] qp show ?case |
903 |
by (simp only:) |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
904 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
905 |
|
54681 | 906 |
|
60500 | 907 |
subsection \<open>Sign of a permutation as a real number\<close> |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
908 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
909 |
definition "sign p = (if evenperm p then (1::int) else -1)" |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
910 |
|
54681 | 911 |
lemma sign_nz: "sign p \<noteq> 0" |
912 |
by (simp add: sign_def) |
|
913 |
||
914 |
lemma sign_id: "sign id = 1" |
|
915 |
by (simp add: sign_def) |
|
916 |
||
917 |
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
|
918 |
by (simp add: sign_def evenperm_inv) |
54681 | 919 |
|
920 |
lemma sign_compose: "permutation p \<Longrightarrow> permutation q \<Longrightarrow> sign (p \<circ> q) = sign p * sign q" |
|
921 |
by (simp add: sign_def evenperm_comp) |
|
922 |
||
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
923 |
lemma sign_swap_id: "sign (Fun.swap a b id) = (if a = b then 1 else -1)" |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
924 |
by (simp add: sign_def evenperm_swap) |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
925 |
|
54681 | 926 |
lemma sign_idempotent: "sign p * sign p = 1" |
927 |
by (simp add: sign_def) |
|
928 |
||
64284
f3b905b2eee2
HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents:
64267
diff
changeset
|
929 |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
930 |
subsection \<open>Permuting a list\<close> |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
931 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
932 |
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
|
933 |
|
65342 | 934 |
definition permute_list :: "(nat \<Rightarrow> nat) \<Rightarrow> 'a list \<Rightarrow> 'a list" |
935 |
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
|
936 |
|
64284
f3b905b2eee2
HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents:
64267
diff
changeset
|
937 |
lemma permute_list_map: |
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
938 |
assumes "f permutes {..<length xs}" |
65342 | 939 |
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
|
940 |
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
|
941 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
942 |
lemma permute_list_nth: |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
943 |
assumes "f permutes {..<length xs}" "i < length xs" |
65342 | 944 |
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
|
945 |
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
|
946 |
by (simp add: permute_list_def) |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
947 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
948 |
lemma permute_list_Nil [simp]: "permute_list f [] = []" |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
949 |
by (simp add: permute_list_def) |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
950 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
951 |
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
|
952 |
by (simp add: permute_list_def) |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
953 |
|
64284
f3b905b2eee2
HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents:
64267
diff
changeset
|
954 |
lemma permute_list_compose: |
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
955 |
assumes "g permutes {..<length xs}" |
65342 | 956 |
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
|
957 |
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
|
958 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
959 |
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
|
960 |
by (simp add: permute_list_def map_nth) |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
961 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
962 |
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
|
963 |
by (simp add: id_def) |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
964 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
965 |
lemma mset_permute_list [simp]: |
65342 | 966 |
fixes xs :: "'a list" |
967 |
assumes "f permutes {..<length xs}" |
|
968 |
shows "mset (permute_list f xs) = mset xs" |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
969 |
proof (rule multiset_eqI) |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
970 |
fix y :: 'a |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
971 |
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
|
972 |
using permutes_in_image[OF assms] by auto |
65342 | 973 |
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
|
974 |
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
|
975 |
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
|
976 |
by auto |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
977 |
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
|
978 |
by (intro card_vimage_inj) (auto simp: permutes_inj permutes_surj) |
65342 | 979 |
also have "\<dots> = count (mset xs) y" |
980 |
by (simp add: count_mset length_filter_conv_card) |
|
981 |
finally show "count (mset (permute_list f xs)) y = count (mset xs) y" |
|
982 |
by simp |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
983 |
qed |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
984 |
|
64284
f3b905b2eee2
HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents:
64267
diff
changeset
|
985 |
lemma set_permute_list [simp]: |
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
986 |
assumes "f permutes {..<length xs}" |
65342 | 987 |
shows "set (permute_list f xs) = set xs" |
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
988 |
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
|
989 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
990 |
lemma distinct_permute_list [simp]: |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
991 |
assumes "f permutes {..<length xs}" |
65342 | 992 |
shows "distinct (permute_list f xs) = distinct xs" |
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
993 |
by (simp add: distinct_count_atmost_1 assms) |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
994 |
|
64284
f3b905b2eee2
HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents:
64267
diff
changeset
|
995 |
lemma permute_list_zip: |
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
996 |
assumes "f permutes A" "A = {..<length xs}" |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
997 |
assumes [simp]: "length xs = length ys" |
65342 | 998 |
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
|
999 |
proof - |
65342 | 1000 |
from permutes_in_image[OF assms(1)] assms(2) have *: "f i < length ys \<longleftrightarrow> i < length ys" for i |
1001 |
by simp |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1002 |
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
|
1003 |
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
|
1004 |
also have "\<dots> = map (\<lambda>(x, y). (xs ! f x, ys ! f y)) (zip [0..<length ys] [0..<length ys])" |
65342 | 1005 |
by (intro nth_equalityI) (simp_all add: *) |
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1006 |
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
|
1007 |
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
|
1008 |
finally show ?thesis . |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1009 |
qed |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1010 |
|
64284
f3b905b2eee2
HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents:
64267
diff
changeset
|
1011 |
lemma map_of_permute: |
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1012 |
assumes "\<sigma> permutes fst ` set xs" |
65342 | 1013 |
shows "map_of xs \<circ> \<sigma> = map_of (map (\<lambda>(x,y). (inv \<sigma> x, y)) xs)" |
1014 |
(is "_ = map_of (map ?f _)") |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1015 |
proof |
65342 | 1016 |
from assms have "inj \<sigma>" "surj \<sigma>" |
1017 |
by (simp_all add: permutes_inj permutes_surj) |
|
1018 |
then show "(map_of xs \<circ> \<sigma>) x = map_of (map ?f xs) x" for x |
|
1019 |
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
|
1020 |
qed |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1021 |
|
54681 | 1022 |
|
60500 | 1023 |
subsection \<open>More lemmas about permutations\<close> |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1024 |
|
65342 | 1025 |
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
|
1026 |
|
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1027 |
lemma count_image_mset_eq_card_vimage: |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1028 |
assumes "finite A" |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1029 |
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
|
1030 |
using assms |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1031 |
proof (induct A) |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1032 |
case empty |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1033 |
show ?case by simp |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1034 |
next |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1035 |
case (insert x F) |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1036 |
show ?case |
65342 | 1037 |
proof (cases "f x = b") |
1038 |
case True |
|
1039 |
with insert.hyps |
|
1040 |
have "count (image_mset f (mset_set (insert x F))) b = Suc (card {a \<in> F. f a = f x})" |
|
1041 |
by auto |
|
1042 |
also from insert.hyps(1,2) have "\<dots> = card (insert x {a \<in> F. f a = f x})" |
|
1043 |
by simp |
|
1044 |
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}" |
|
1045 |
by (auto intro: arg_cong[where f="card"]) |
|
1046 |
finally show ?thesis |
|
1047 |
using insert by auto |
|
63921
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1048 |
next |
65342 | 1049 |
case False |
1050 |
then have "{a \<in> F. f a = b} = {a \<in> insert x F. f a = b}" |
|
1051 |
by auto |
|
1052 |
with insert False show ?thesis |
|
1053 |
by simp |
|
63921
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1054 |
qed |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1055 |
qed |
64284
f3b905b2eee2
HOL-Analysis: more theorems from Sébastien Gouëzel's Ergodic_Theory
hoelzl
parents:
64267
diff
changeset
|
1056 |
|
63921
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1057 |
(* Prove image_mset_eq_implies_permutes *) |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1058 |
lemma image_mset_eq_implies_permutes: |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1059 |
fixes f :: "'a \<Rightarrow> 'b" |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1060 |
assumes "finite A" |
65342 | 1061 |
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
|
1062 |
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
|
1063 |
proof - |
63921
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1064 |
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
|
1065 |
have "f ` A = f' ` A" |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1066 |
proof - |
65342 | 1067 |
from \<open>finite A\<close> have "f ` A = f ` (set_mset (mset_set A))" |
1068 |
by simp |
|
1069 |
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
|
1070 |
by (metis mset_eq multiset.set_map) |
65342 | 1071 |
also from \<open>finite A\<close> have "\<dots> = f' ` A" |
1072 |
by simp |
|
63921
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1073 |
finally show ?thesis . |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1074 |
qed |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1075 |
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
|
1076 |
proof |
63921
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1077 |
fix b |
65342 | 1078 |
from mset_eq have "count (image_mset f (mset_set A)) b = count (image_mset f' (mset_set A)) b" |
1079 |
by simp |
|
1080 |
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
|
1081 |
by (simp add: count_image_mset_eq_card_vimage) |
65342 | 1082 |
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
|
1083 |
by (intro finite_same_card_bij) simp_all |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1084 |
qed |
65342 | 1085 |
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
|
1086 |
by (rule bchoice) |
65342 | 1087 |
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
|
1088 |
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
|
1089 |
have "p' permutes A" |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1090 |
proof (rule bij_imp_permutes) |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1091 |
have "disjoint_family_on (\<lambda>i. {a \<in> A. f' a = i}) (f ` A)" |
65342 | 1092 |
by (auto simp: disjoint_family_on_def) |
1093 |
moreover |
|
1094 |
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 |
|
1095 |
using p that by (subst bij_betw_cong[where g="p b"]) auto |
|
1096 |
ultimately |
|
1097 |
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
|
1098 |
by (rule bij_betw_UNION_disjoint) |
65342 | 1099 |
moreover have "(\<Union>b\<in>f ` A. {a \<in> A. f a = b}) = A" |
1100 |
by auto |
|
1101 |
moreover from \<open>f ` A = f' ` A\<close> have "(\<Union>b\<in>f ` A. {a \<in> A. f' a = b}) = A" |
|
1102 |
by auto |
|
63921
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1103 |
ultimately show "bij_betw p' A A" |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1104 |
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
|
1105 |
next |
65342 | 1106 |
show "\<And>x. x \<notin> A \<Longrightarrow> p' x = x" |
1107 |
by (simp add: p'_def) |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1108 |
qed |
63921
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1109 |
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
|
1110 |
unfolding p'_def using bij_betwE by fastforce |
65342 | 1111 |
ultimately show ?thesis .. |
63921
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1112 |
qed |
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1113 |
|
65342 | 1114 |
lemma mset_set_upto_eq_mset_upto: "mset_set {..<n} = mset [0..<n]" |
1115 |
by (induct n) (auto simp: add.commute lessThan_Suc) |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1116 |
|
63921
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1117 |
(* and derive the existing property: *) |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1118 |
lemma mset_eq_permutation: |
65342 | 1119 |
fixes xs ys :: "'a list" |
1120 |
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
|
1121 |
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
|
1122 |
proof - |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1123 |
from mset_eq have length_eq: "length xs = length ys" |
65342 | 1124 |
by (rule mset_eq_length) |
63921
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1125 |
have "mset_set {..<length ys} = mset [0..<length ys]" |
65342 | 1126 |
by (rule mset_set_upto_eq_mset_upto) |
1127 |
with mset_eq length_eq have "image_mset (\<lambda>i. xs ! i) (mset_set {..<length ys}) = |
|
1128 |
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
|
1129 |
by (metis map_nth mset_map) |
0a5184877cb7
Additions to permutations (contributed by Lukas Bulwahn)
eberlm <eberlm@in.tum.de>
parents:
63539
diff
changeset
|
1130 |
from image_mset_eq_implies_permutes[OF _ this] |
65342 | 1131 |
obtain p where p: "p permutes {..<length ys}" and "\<forall>i\<in>{..<length ys}. xs ! i = ys ! (p i)" |
1132 |
by auto |
|
1133 |
with length_eq have "permute_list p ys = xs" |
|
1134 |
by (auto intro!: nth_equalityI simp: permute_list_nth) |
|
1135 |
with p show thesis .. |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1136 |
qed |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1137 |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1138 |
lemma permutes_natset_le: |
54681 | 1139 |
fixes S :: "'a::wellorder set" |
65342 | 1140 |
assumes "p permutes S" |
1141 |
and "\<forall>i \<in> S. p i \<le> i" |
|
54681 | 1142 |
shows "p = id" |
1143 |
proof - |
|
65342 | 1144 |
have "p n = n" for n |
1145 |
using assms |
|
1146 |
proof (induct n arbitrary: S rule: less_induct) |
|
1147 |
case (less n) |
|
1148 |
show ?case |
|
1149 |
proof (cases "n \<in> S") |
|
1150 |
case False |
|
1151 |
with less(2) show ?thesis |
|
1152 |
unfolding permutes_def by metis |
|
1153 |
next |
|
1154 |
case True |
|
1155 |
with less(3) have "p n < n \<or> p n = n" |
|
1156 |
by auto |
|
1157 |
then show ?thesis |
|
1158 |
proof |
|
1159 |
assume "p n < n" |
|
1160 |
with less have "p (p n) = p n" |
|
1161 |
by metis |
|
1162 |
with permutes_inj[OF less(2)] have "p n = n" |
|
1163 |
unfolding inj_def by blast |
|
1164 |
with \<open>p n < n\<close> have False |
|
1165 |
by simp |
|
1166 |
then show ?thesis .. |
|
1167 |
qed |
|
54681 | 1168 |
qed |
65342 | 1169 |
qed |
1170 |
then show ?thesis by (auto simp: fun_eq_iff) |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1171 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1172 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1173 |
lemma permutes_natset_ge: |
54681 | 1174 |
fixes S :: "'a::wellorder set" |
1175 |
assumes p: "p permutes S" |
|
1176 |
and le: "\<forall>i \<in> S. p i \<ge> i" |
|
1177 |
shows "p = id" |
|
1178 |
proof - |
|
65342 | 1179 |
have "i \<ge> inv p i" if "i \<in> S" for i |
1180 |
proof - |
|
1181 |
from that permutes_in_image[OF permutes_inv[OF p]] have "inv p i \<in> S" |
|
54681 | 1182 |
by simp |
1183 |
with le have "p (inv p i) \<ge> inv p i" |
|
1184 |
by blast |
|
65342 | 1185 |
with permutes_inverses[OF p] show ?thesis |
54681 | 1186 |
by simp |
65342 | 1187 |
qed |
1188 |
then have "\<forall>i\<in>S. inv p i \<le> i" |
|
54681 | 1189 |
by blast |
65342 | 1190 |
from permutes_natset_le[OF permutes_inv[OF p] this] have "inv p = inv id" |
54681 | 1191 |
by simp |
30488 | 1192 |
then show ?thesis |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1193 |
apply (subst permutes_inv_inv[OF p, symmetric]) |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1194 |
apply (rule inv_unique_comp) |
65342 | 1195 |
apply simp_all |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1196 |
done |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1197 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1198 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1199 |
lemma image_inverse_permutations: "{inv p |p. p permutes S} = {p. p permutes S}" |
54681 | 1200 |
apply (rule set_eqI) |
1201 |
apply auto |
|
1202 |
using permutes_inv_inv permutes_inv |
|
65342 | 1203 |
apply auto |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1204 |
apply (rule_tac x="inv x" in exI) |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1205 |
apply auto |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1206 |
done |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1207 |
|
30488 | 1208 |
lemma image_compose_permutations_left: |
65342 | 1209 |
assumes "q permutes S" |
1210 |
shows "{q \<circ> p |p. p permutes S} = {p. p permutes S}" |
|
54681 | 1211 |
apply (rule set_eqI) |
1212 |
apply auto |
|
65342 | 1213 |
apply (rule permutes_compose) |
1214 |
using assms |
|
1215 |
apply auto |
|
54681 | 1216 |
apply (rule_tac x = "inv q \<circ> x" in exI) |
1217 |
apply (simp add: o_assoc permutes_inv permutes_compose permutes_inv_o) |
|
1218 |
done |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1219 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1220 |
lemma image_compose_permutations_right: |
65342 | 1221 |
assumes "q permutes S" |
54681 | 1222 |
shows "{p \<circ> q | p. p permutes S} = {p . p permutes S}" |
1223 |
apply (rule set_eqI) |
|
1224 |
apply auto |
|
65342 | 1225 |
apply (rule permutes_compose) |
1226 |
using assms |
|
1227 |
apply auto |
|
54681 | 1228 |
apply (rule_tac x = "x \<circ> inv q" in exI) |
1229 |
apply (simp add: o_assoc permutes_inv permutes_compose permutes_inv_o comp_assoc) |
|
1230 |
done |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1231 |
|
54681 | 1232 |
lemma permutes_in_seg: "p permutes {1 ..n} \<Longrightarrow> i \<in> {1..n} \<Longrightarrow> 1 \<le> p i \<and> p i \<le> n" |
1233 |
by (simp add: permutes_def) metis |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1234 |
|
65342 | 1235 |
lemma sum_permutations_inverse: "sum f {p. p permutes S} = sum (\<lambda>p. f(inv p)) {p. p permutes S}" |
54681 | 1236 |
(is "?lhs = ?rhs") |
1237 |
proof - |
|
30036 | 1238 |
let ?S = "{p . p permutes S}" |
65342 | 1239 |
have *: "inj_on inv ?S" |
54681 | 1240 |
proof (auto simp add: inj_on_def) |
1241 |
fix q r |
|
1242 |
assume q: "q permutes S" |
|
1243 |
and r: "r permutes S" |
|
1244 |
and qr: "inv q = inv r" |
|
1245 |
then have "inv (inv q) = inv (inv r)" |
|
1246 |
by simp |
|
1247 |
with permutes_inv_inv[OF q] permutes_inv_inv[OF r] show "q = r" |
|
1248 |
by metis |
|
1249 |
qed |
|
65342 | 1250 |
have **: "inv ` ?S = ?S" |
54681 | 1251 |
using image_inverse_permutations by blast |
65342 | 1252 |
have ***: "?rhs = sum (f \<circ> inv) ?S" |
54681 | 1253 |
by (simp add: o_def) |
65342 | 1254 |
from sum.reindex[OF *, of f] show ?thesis |
1255 |
by (simp only: ** ***) |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1256 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1257 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1258 |
lemma setum_permutations_compose_left: |
30036 | 1259 |
assumes q: "q permutes S" |
64267 | 1260 |
shows "sum f {p. p permutes S} = sum (\<lambda>p. f(q \<circ> p)) {p. p permutes S}" |
54681 | 1261 |
(is "?lhs = ?rhs") |
1262 |
proof - |
|
30036 | 1263 |
let ?S = "{p. p permutes S}" |
65342 | 1264 |
have *: "?rhs = sum (f \<circ> (op \<circ> q)) ?S" |
54681 | 1265 |
by (simp add: o_def) |
65342 | 1266 |
have **: "inj_on (op \<circ> q) ?S" |
54681 | 1267 |
proof (auto simp add: inj_on_def) |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1268 |
fix p r |
54681 | 1269 |
assume "p permutes S" |
1270 |
and r: "r permutes S" |
|
1271 |
and rp: "q \<circ> p = q \<circ> r" |
|
1272 |
then have "inv q \<circ> q \<circ> p = inv q \<circ> q \<circ> r" |
|
1273 |
by (simp add: comp_assoc) |
|
1274 |
with permutes_inj[OF q, unfolded inj_iff] show "p = r" |
|
1275 |
by simp |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1276 |
qed |
65342 | 1277 |
have "(op \<circ> q) ` ?S = ?S" |
54681 | 1278 |
using image_compose_permutations_left[OF q] by auto |
65342 | 1279 |
with * sum.reindex[OF **, of f] show ?thesis |
1280 |
by (simp only:) |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1281 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1282 |
|
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1283 |
lemma sum_permutations_compose_right: |
30036 | 1284 |
assumes q: "q permutes S" |
64267 | 1285 |
shows "sum f {p. p permutes S} = sum (\<lambda>p. f(p \<circ> q)) {p. p permutes S}" |
54681 | 1286 |
(is "?lhs = ?rhs") |
1287 |
proof - |
|
30036 | 1288 |
let ?S = "{p. p permutes S}" |
65342 | 1289 |
have *: "?rhs = sum (f \<circ> (\<lambda>p. p \<circ> q)) ?S" |
54681 | 1290 |
by (simp add: o_def) |
65342 | 1291 |
have **: "inj_on (\<lambda>p. p \<circ> q) ?S" |
54681 | 1292 |
proof (auto simp add: inj_on_def) |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1293 |
fix p r |
54681 | 1294 |
assume "p permutes S" |
1295 |
and r: "r permutes S" |
|
1296 |
and rp: "p \<circ> q = r \<circ> q" |
|
1297 |
then have "p \<circ> (q \<circ> inv q) = r \<circ> (q \<circ> inv q)" |
|
1298 |
by (simp add: o_assoc) |
|
1299 |
with permutes_surj[OF q, unfolded surj_iff] show "p = r" |
|
1300 |
by simp |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1301 |
qed |
65342 | 1302 |
from image_compose_permutations_right[OF q] have "(\<lambda>p. p \<circ> q) ` ?S = ?S" |
1303 |
by auto |
|
1304 |
with * sum.reindex[OF **, of f] show ?thesis |
|
1305 |
by (simp only:) |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1306 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1307 |
|
54681 | 1308 |
|
60500 | 1309 |
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
|
1310 |
|
64267 | 1311 |
lemma sum_over_permutations_insert: |
54681 | 1312 |
assumes fS: "finite S" |
1313 |
and aS: "a \<notin> S" |
|
64267 | 1314 |
shows "sum f {p. p permutes (insert a S)} = |
1315 |
sum (\<lambda>b. sum (\<lambda>q. f (Fun.swap a b id \<circ> q)) {p. p permutes S}) (insert a S)" |
|
54681 | 1316 |
proof - |
65342 | 1317 |
have *: "\<And>f a b. (\<lambda>(b, p). f (Fun.swap a b id \<circ> p)) = f \<circ> (\<lambda>(b,p). Fun.swap a b id \<circ> p)" |
39302
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents:
39198
diff
changeset
|
1318 |
by (simp add: fun_eq_iff) |
65342 | 1319 |
have **: "\<And>P Q. {(a, b). a \<in> P \<and> b \<in> Q} = P \<times> Q" |
54681 | 1320 |
by blast |
30488 | 1321 |
show ?thesis |
65342 | 1322 |
unfolding * ** sum.cartesian_product permutes_insert |
64267 | 1323 |
proof (rule sum.reindex) |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1324 |
let ?f = "(\<lambda>(b, y). Fun.swap a b id \<circ> y)" |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1325 |
let ?P = "{p. p permutes S}" |
54681 | 1326 |
{ |
1327 |
fix b c p q |
|
1328 |
assume b: "b \<in> insert a S" |
|
1329 |
assume c: "c \<in> insert a S" |
|
1330 |
assume p: "p permutes S" |
|
1331 |
assume q: "q permutes S" |
|
1332 |
assume eq: "Fun.swap a b id \<circ> p = Fun.swap a c id \<circ> q" |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1333 |
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
|
1334 |
unfolding permutes_def by metis+ |
54681 | 1335 |
from eq have "(Fun.swap a b id \<circ> p) a = (Fun.swap a c id \<circ> q) a" |
1336 |
by simp |
|
1337 |
then have bc: "b = c" |
|
56545 | 1338 |
by (simp add: permutes_def pa qa o_def fun_upd_def Fun.swap_def id_def |
62390 | 1339 |
cong del: if_weak_cong split: if_split_asm) |
54681 | 1340 |
from eq[unfolded bc] have "(\<lambda>p. Fun.swap a c id \<circ> p) (Fun.swap a c id \<circ> p) = |
1341 |
(\<lambda>p. Fun.swap a c id \<circ> p) (Fun.swap a c id \<circ> q)" by simp |
|
1342 |
then have "p = q" |
|
65342 | 1343 |
unfolding o_assoc swap_id_idempotent by simp |
54681 | 1344 |
with bc have "b = c \<and> p = q" |
1345 |
by blast |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1346 |
} |
30488 | 1347 |
then show "inj_on ?f (insert a S \<times> ?P)" |
54681 | 1348 |
unfolding inj_on_def by clarify metis |
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1349 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1350 |
qed |
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1351 |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1352 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1353 |
subsection \<open>Constructing permutations from association lists\<close> |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1354 |
|
65342 | 1355 |
definition list_permutes :: "('a \<times> 'a) list \<Rightarrow> 'a set \<Rightarrow> bool" |
1356 |
where "list_permutes xs A \<longleftrightarrow> |
|
1357 |
set (map fst xs) \<subseteq> A \<and> |
|
1358 |
set (map snd xs) = set (map fst xs) \<and> |
|
1359 |
distinct (map fst xs) \<and> |
|
1360 |
distinct (map snd xs)" |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1361 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1362 |
lemma list_permutesI [simp]: |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1363 |
assumes "set (map fst xs) \<subseteq> A" "set (map snd xs) = set (map fst xs)" "distinct (map fst xs)" |
65342 | 1364 |
shows "list_permutes xs A" |
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1365 |
proof - |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1366 |
from assms(2,3) have "distinct (map snd xs)" |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1367 |
by (intro card_distinct) (simp_all add: distinct_card del: set_map) |
65342 | 1368 |
with assms show ?thesis |
1369 |
by (simp add: list_permutes_def) |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1370 |
qed |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1371 |
|
65342 | 1372 |
definition permutation_of_list :: "('a \<times> 'a) list \<Rightarrow> 'a \<Rightarrow> 'a" |
1373 |
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
|
1374 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1375 |
lemma permutation_of_list_Cons: |
65342 | 1376 |
"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
|
1377 |
by (simp add: permutation_of_list_def) |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1378 |
|
65342 | 1379 |
fun inverse_permutation_of_list :: "('a \<times> 'a) list \<Rightarrow> 'a \<Rightarrow> 'a" |
1380 |
where |
|
1381 |
"inverse_permutation_of_list [] x = x" |
|
1382 |
| "inverse_permutation_of_list ((y, x') # xs) x = |
|
1383 |
(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
|
1384 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1385 |
declare inverse_permutation_of_list.simps [simp del] |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1386 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1387 |
lemma inj_on_map_of: |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1388 |
assumes "distinct (map snd xs)" |
65342 | 1389 |
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
|
1390 |
proof (rule inj_onI) |
65342 | 1391 |
fix x y |
1392 |
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
|
1393 |
assume eq: "map_of xs x = map_of xs y" |
65342 | 1394 |
from xy obtain x' y' where x'y': "map_of xs x = Some x'" "map_of xs y = Some y'" |
1395 |
by (cases "map_of xs x"; cases "map_of xs y") (simp_all add: map_of_eq_None_iff) |
|
1396 |
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
|
1397 |
by (force dest: map_of_SomeD)+ |
65342 | 1398 |
moreover from * eq x'y' have "x' = y'" |
1399 |
by simp |
|
1400 |
ultimately show "x = y" |
|
1401 |
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
|
1402 |
qed |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1403 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1404 |
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
|
1405 |
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
|
1406 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1407 |
lemma inj_on_map_of': |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1408 |
assumes "distinct (map snd xs)" |
65342 | 1409 |
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
|
1410 |
by (intro comp_inj_on inj_on_map_of assms inj_on_the) |
65342 | 1411 |
(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
|
1412 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1413 |
lemma image_map_of: |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1414 |
assumes "distinct (map fst xs)" |
65342 | 1415 |
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
|
1416 |
using assms by (auto simp: rev_image_eqI) |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1417 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1418 |
lemma the_Some_image [simp]: "the ` Some ` A = A" |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1419 |
by (subst image_image) simp |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1420 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1421 |
lemma image_map_of': |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1422 |
assumes "distinct (map fst xs)" |
65342 | 1423 |
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
|
1424 |
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
|
1425 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1426 |
lemma permutation_of_list_permutes [simp]: |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1427 |
assumes "list_permutes xs A" |
65342 | 1428 |
shows "permutation_of_list xs permutes A" |
1429 |
(is "?f permutes _") |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1430 |
proof (rule permutes_subset[OF bij_imp_permutes]) |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1431 |
from assms show "set (map fst xs) \<subseteq> A" |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1432 |
by (simp add: list_permutes_def) |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1433 |
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
|
1434 |
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
|
1435 |
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
|
1436 |
by (intro inj_on_cong) |
65342 | 1437 |
(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
|
1438 |
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
|
1439 |
by (rule inj_on_imp_bij_betw) |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1440 |
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
|
1441 |
by (intro image_cong refl) |
65342 | 1442 |
(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
|
1443 |
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
|
1444 |
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
|
1445 |
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
|
1446 |
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
|
1447 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1448 |
lemma eval_permutation_of_list [simp]: |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1449 |
"permutation_of_list [] x = x" |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1450 |
"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
|
1451 |
"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
|
1452 |
by (simp_all add: permutation_of_list_def) |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1453 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1454 |
lemma eval_inverse_permutation_of_list [simp]: |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1455 |
"inverse_permutation_of_list [] x = x" |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1456 |
"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
|
1457 |
"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
|
1458 |
by (simp_all add: inverse_permutation_of_list.simps) |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1459 |
|
65342 | 1460 |
lemma permutation_of_list_id: "x \<notin> set (map fst xs) \<Longrightarrow> permutation_of_list xs x = x" |
1461 |
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
|
1462 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1463 |
lemma permutation_of_list_unique': |
65342 | 1464 |
"distinct (map fst xs) \<Longrightarrow> (x, y) \<in> set xs \<Longrightarrow> permutation_of_list xs x = y" |
1465 |
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
|
1466 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1467 |
lemma permutation_of_list_unique: |
65342 | 1468 |
"list_permutes xs A \<Longrightarrow> (x, y) \<in> set xs \<Longrightarrow> permutation_of_list xs x = y" |
1469 |
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
|
1470 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1471 |
lemma inverse_permutation_of_list_id: |
65342 | 1472 |
"x \<notin> set (map snd xs) \<Longrightarrow> inverse_permutation_of_list xs x = x" |
1473 |
by (induct xs) auto |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1474 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1475 |
lemma inverse_permutation_of_list_unique': |
65342 | 1476 |
"distinct (map snd xs) \<Longrightarrow> (x, y) \<in> set xs \<Longrightarrow> inverse_permutation_of_list xs y = x" |
1477 |
by (induct xs) (force simp: inverse_permutation_of_list.simps)+ |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1478 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1479 |
lemma inverse_permutation_of_list_unique: |
65342 | 1480 |
"list_permutes xs A \<Longrightarrow> (x,y) \<in> set xs \<Longrightarrow> inverse_permutation_of_list xs y = x" |
1481 |
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
|
1482 |
|
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1483 |
lemma inverse_permutation_of_list_correct: |
65342 | 1484 |
fixes A :: "'a set" |
1485 |
assumes "list_permutes xs A" |
|
1486 |
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
|
1487 |
proof (rule ext, rule sym, subst permutes_inv_eq) |
65342 | 1488 |
from assms show "permutation_of_list xs permutes A" |
1489 |
by simp |
|
1490 |
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
|
1491 |
proof (cases "x \<in> set (map snd xs)") |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1492 |
case True |
65342 | 1493 |
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
|
1494 |
with assms show ?thesis |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1495 |
by (simp add: inverse_permutation_of_list_unique permutation_of_list_unique) |
65342 | 1496 |
next |
1497 |
case False |
|
1498 |
with assms show ?thesis |
|
1499 |
by (auto simp: list_permutes_def inverse_permutation_of_list_id permutation_of_list_id) |
|
1500 |
qed |
|
63099
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1501 |
qed |
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents:
62390
diff
changeset
|
1502 |
|
29840
cfab6a76aa13
Permutations, both general and specifically on finite sets.
chaieb
parents:
diff
changeset
|
1503 |
end |