|
73623
|
1 |
section \<open>Transposition function\<close>
|
|
|
2 |
|
|
|
3 |
theory Transposition
|
|
|
4 |
imports Main
|
|
|
5 |
begin
|
|
|
6 |
|
|
|
7 |
setup \<open>Context.theory_map (Name_Space.map_naming (Name_Space.qualified_path true \<^binding>\<open>Fun\<close>))\<close>
|
|
|
8 |
|
|
|
9 |
definition swap :: \<open>'a \<Rightarrow> 'a \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b)\<close>
|
|
|
10 |
where \<open>swap a b f = f (a := f b, b:= f a)\<close>
|
|
|
11 |
|
|
|
12 |
setup \<open>Context.theory_map (Name_Space.map_naming (Name_Space.parent_path))\<close>
|
|
|
13 |
|
|
|
14 |
lemma swap_apply [simp]:
|
|
|
15 |
"Fun.swap a b f a = f b"
|
|
|
16 |
"Fun.swap a b f b = f a"
|
|
|
17 |
"c \<noteq> a \<Longrightarrow> c \<noteq> b \<Longrightarrow> Fun.swap a b f c = f c"
|
|
|
18 |
by (simp_all add: Fun.swap_def)
|
|
|
19 |
|
|
|
20 |
lemma swap_self [simp]: "Fun.swap a a f = f"
|
|
|
21 |
by (simp add: Fun.swap_def)
|
|
|
22 |
|
|
|
23 |
lemma swap_commute: "Fun.swap a b f = Fun.swap b a f"
|
|
|
24 |
by (simp add: fun_upd_def Fun.swap_def fun_eq_iff)
|
|
|
25 |
|
|
|
26 |
lemma swap_nilpotent [simp]: "Fun.swap a b (Fun.swap a b f) = f"
|
|
|
27 |
by (rule ext) (simp add: fun_upd_def Fun.swap_def)
|
|
|
28 |
|
|
|
29 |
lemma swap_comp_involutory [simp]: "Fun.swap a b \<circ> Fun.swap a b = id"
|
|
|
30 |
by (rule ext) simp
|
|
|
31 |
|
|
|
32 |
lemma swap_triple:
|
|
|
33 |
assumes "a \<noteq> c" and "b \<noteq> c"
|
|
|
34 |
shows "Fun.swap a b (Fun.swap b c (Fun.swap a b f)) = Fun.swap a c f"
|
|
|
35 |
using assms by (simp add: fun_eq_iff Fun.swap_def)
|
|
|
36 |
|
|
|
37 |
lemma comp_swap: "f \<circ> Fun.swap a b g = Fun.swap a b (f \<circ> g)"
|
|
|
38 |
by (rule ext) (simp add: fun_upd_def Fun.swap_def)
|
|
|
39 |
|
|
|
40 |
lemma swap_image_eq [simp]:
|
|
|
41 |
assumes "a \<in> A" "b \<in> A"
|
|
|
42 |
shows "Fun.swap a b f ` A = f ` A"
|
|
|
43 |
proof -
|
|
|
44 |
have subset: "\<And>f. Fun.swap a b f ` A \<subseteq> f ` A"
|
|
|
45 |
using assms by (auto simp: image_iff Fun.swap_def)
|
|
|
46 |
then have "Fun.swap a b (Fun.swap a b f) ` A \<subseteq> (Fun.swap a b f) ` A" .
|
|
|
47 |
with subset[of f] show ?thesis by auto
|
|
|
48 |
qed
|
|
|
49 |
|
|
|
50 |
lemma inj_on_imp_inj_on_swap: "inj_on f A \<Longrightarrow> a \<in> A \<Longrightarrow> b \<in> A \<Longrightarrow> inj_on (Fun.swap a b f) A"
|
|
|
51 |
by (auto simp add: inj_on_def Fun.swap_def)
|
|
|
52 |
|
|
|
53 |
lemma inj_on_swap_iff [simp]:
|
|
|
54 |
assumes A: "a \<in> A" "b \<in> A"
|
|
|
55 |
shows "inj_on (Fun.swap a b f) A \<longleftrightarrow> inj_on f A"
|
|
|
56 |
proof
|
|
|
57 |
assume "inj_on (Fun.swap a b f) A"
|
|
|
58 |
with A have "inj_on (Fun.swap a b (Fun.swap a b f)) A"
|
|
|
59 |
by (iprover intro: inj_on_imp_inj_on_swap)
|
|
|
60 |
then show "inj_on f A" by simp
|
|
|
61 |
next
|
|
|
62 |
assume "inj_on f A"
|
|
|
63 |
with A show "inj_on (Fun.swap a b f) A"
|
|
|
64 |
by (iprover intro: inj_on_imp_inj_on_swap)
|
|
|
65 |
qed
|
|
|
66 |
|
|
|
67 |
lemma surj_imp_surj_swap: "surj f \<Longrightarrow> surj (Fun.swap a b f)"
|
|
|
68 |
by simp
|
|
|
69 |
|
|
|
70 |
lemma surj_swap_iff [simp]: "surj (Fun.swap a b f) \<longleftrightarrow> surj f"
|
|
|
71 |
by simp
|
|
|
72 |
|
|
|
73 |
lemma bij_betw_swap_iff [simp]: "x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> bij_betw (Fun.swap x y f) A B \<longleftrightarrow> bij_betw f A B"
|
|
|
74 |
by (auto simp: bij_betw_def)
|
|
|
75 |
|
|
|
76 |
lemma bij_swap_iff [simp]: "bij (Fun.swap a b f) \<longleftrightarrow> bij f"
|
|
|
77 |
by simp
|
|
|
78 |
|
|
|
79 |
lemma swap_image:
|
|
|
80 |
\<open>Fun.swap i j f ` A = f ` (A - {i, j}
|
|
|
81 |
\<union> (if i \<in> A then {j} else {}) \<union> (if j \<in> A then {i} else {}))\<close>
|
|
|
82 |
by (auto simp add: Fun.swap_def)
|
|
|
83 |
|
|
|
84 |
lemma inv_swap_id: "inv (Fun.swap a b id) = Fun.swap a b id"
|
|
|
85 |
by (rule inv_unique_comp) (simp_all add: fun_eq_iff Fun.swap_def)
|
|
|
86 |
|
|
|
87 |
lemma bij_swap_comp:
|
|
|
88 |
assumes "bij p"
|
|
|
89 |
shows "Fun.swap a b id \<circ> p = Fun.swap (inv p a) (inv p b) p"
|
|
|
90 |
using surj_f_inv_f[OF bij_is_surj[OF \<open>bij p\<close>]]
|
|
|
91 |
by (simp add: fun_eq_iff Fun.swap_def bij_inv_eq_iff[OF \<open>bij p\<close>])
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
subsection \<open>Transpositions\<close>
|
|
|
95 |
|
|
|
96 |
lemma swap_id_eq: "Fun.swap a b id x = (if x = a then b else if x = b then a else x)"
|
|
|
97 |
by (simp add: Fun.swap_def)
|
|
|
98 |
|
|
|
99 |
lemma swap_unfold:
|
|
|
100 |
\<open>Fun.swap a b p = p \<circ> Fun.swap a b id\<close>
|
|
|
101 |
by (simp add: fun_eq_iff Fun.swap_def)
|
|
|
102 |
|
|
|
103 |
lemma swap_id_idempotent [simp]: "Fun.swap a b id \<circ> Fun.swap a b id = id"
|
|
|
104 |
by (simp flip: swap_unfold)
|
|
|
105 |
|
|
|
106 |
lemma bij_swap_compose_bij:
|
|
|
107 |
\<open>bij (Fun.swap a b id \<circ> p)\<close> if \<open>bij p\<close>
|
|
|
108 |
using that by (rule bij_comp) simp
|
|
|
109 |
|
|
|
110 |
end
|