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