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