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