1 (* Title: HOL/NumberTheory/BijectionRel.thy
3 Author: Thomas M. Rasmussen
4 Copyright 2000 University of Cambridge
7 header {* Bijections between sets *}
9 theory BijectionRel = Main:
12 Inductive definitions of bijections between two different sets and
13 between the same set. Theorem for relating the two definitions.
19 bijR :: "('a => 'b => bool) => ('a set * 'b set) set"
23 empty [simp]: "({}, {}) \<in> bijR P"
24 insert: "P a b ==> a \<notin> A ==> b \<notin> B ==> (A, B) \<in> bijR P
25 ==> (insert a A, insert b B) \<in> bijR P"
28 Add extra condition to @{term insert}: @{term "\<forall>b \<in> B. \<not> P a b"}
29 (and similar for @{term A}).
33 bijP :: "('a => 'a => bool) => 'a set => bool"
34 "bijP P F == \<forall>a b. a \<in> F \<and> P a b --> b \<in> F"
36 uniqP :: "('a => 'a => bool) => bool"
37 "uniqP P == \<forall>a b c d. P a b \<and> P c d --> (a = c) = (b = d)"
39 symP :: "('a => 'a => bool) => bool"
40 "symP P == \<forall>a b. P a b = P b a"
43 bijER :: "('a => 'a => bool) => 'a set set"
47 empty [simp]: "{} \<in> bijER P"
48 insert1: "P a a ==> a \<notin> A ==> A \<in> bijER P ==> insert a A \<in> bijER P"
49 insert2: "P a b ==> a \<noteq> b ==> a \<notin> A ==> b \<notin> A ==> A \<in> bijER P
50 ==> insert a (insert b A) \<in> bijER P"
53 text {* \medskip @{term bijR} *}
55 lemma fin_bijRl: "(A, B) \<in> bijR P ==> finite A"
56 apply (erule bijR.induct)
60 lemma fin_bijRr: "(A, B) \<in> bijR P ==> finite B"
61 apply (erule bijR.induct)
66 "finite F ==> F \<subseteq> A ==> P {} ==>
67 (!!F a. F \<subseteq> A ==> a \<in> A ==> a \<notin> F ==> P F ==> P (insert a F))
71 assume major: "finite F"
72 and subs: "F \<subseteq> A"
74 apply (rule subs [THEN rev_mp])
75 apply (rule major [THEN finite_induct])
76 apply (blast intro: rule_context)+
80 lemma inj_func_bijR_aux1:
81 "A \<subseteq> B ==> a \<notin> A ==> a \<in> B ==> inj_on f B ==> f a \<notin> f ` A"
82 apply (unfold inj_on_def)
86 lemma inj_func_bijR_aux2:
87 "\<forall>a. a \<in> A --> P a (f a) ==> inj_on f A ==> finite A ==> F <= A
88 ==> (F, f ` F) \<in> bijR P"
89 apply (rule_tac F = F and A = A in aux_induct)
90 apply (rule finite_subset)
92 apply (rule bijR.insert)
93 apply (rule_tac [3] inj_func_bijR_aux1)
98 "\<forall>a. a \<in> A --> P a (f a) ==> inj_on f A ==> finite A
99 ==> (A, f ` A) \<in> bijR P"
100 apply (rule inj_func_bijR_aux2)
105 text {* \medskip @{term bijER} *}
107 lemma fin_bijER: "A \<in> bijER P ==> finite A"
108 apply (erule bijER.induct)
113 "a \<notin> A ==> a \<notin> B ==> F \<subseteq> insert a A ==> F \<subseteq> insert a B ==> a \<in> F
114 ==> \<exists>C. F = insert a C \<and> a \<notin> C \<and> C <= A \<and> C <= B"
115 apply (rule_tac x = "F - {a}" in exI)
119 lemma aux2: "a \<noteq> b ==> a \<notin> A ==> b \<notin> B ==> a \<in> F ==> b \<in> F
120 ==> F \<subseteq> insert a A ==> F \<subseteq> insert b B
121 ==> \<exists>C. F = insert a (insert b C) \<and> a \<notin> C \<and> b \<notin> C \<and> C \<subseteq> A \<and> C \<subseteq> B"
122 apply (rule_tac x = "F - {a, b}" in exI)
126 lemma aux_uniq: "uniqP P ==> P a b ==> P c d ==> (a = c) = (b = d)"
127 apply (unfold uniqP_def)
131 lemma aux_sym: "symP P ==> P a b = P b a"
132 apply (unfold symP_def)
137 "uniqP P ==> b \<notin> C ==> P b b ==> bijP P (insert b C) ==> bijP P C"
138 apply (unfold bijP_def)
140 apply (subgoal_tac "b \<noteq> a")
143 apply (simp add: aux_uniq)
148 "symP P ==> uniqP P ==> a \<notin> C ==> b \<notin> C ==> a \<noteq> b ==> P a b
149 ==> bijP P (insert a (insert b C)) ==> bijP P C"
150 apply (unfold bijP_def)
152 apply (subgoal_tac "aa \<noteq> a")
155 apply (subgoal_tac "aa \<noteq> b")
158 apply (simp add: aux_uniq)
159 apply (subgoal_tac "ba \<noteq> a")
161 apply (subgoal_tac "P a aa")
163 apply (simp add: aux_sym)
164 apply (subgoal_tac "b = aa")
165 apply (rule_tac [2] iffD1)
166 apply (rule_tac [2] a = a and c = a and P = P in aux_uniq)
170 lemma aux_foo: "\<forall>a b. Q a \<and> P a b --> R b ==> P a b ==> Q a ==> R b"
174 lemma aux_bij: "bijP P F ==> symP P ==> P a b ==> (a \<in> F) = (b \<in> F)"
175 apply (unfold bijP_def)
177 apply (erule_tac [!] aux_foo)
180 apply (rule_tac P = P in aux_sym)
186 "(A, B) \<in> bijR P ==> uniqP P ==> symP P
187 ==> \<forall>F. bijP P F \<and> F \<subseteq> A \<and> F \<subseteq> B --> F \<in> bijER P"
188 apply (erule bijR.induct)
190 apply (case_tac "a = b")
192 apply (case_tac "b \<in> F")
194 apply (simp add: subset_insert)
195 apply (cut_tac F = F and a = b and A = A and B = B in aux1)
198 apply (rule bijER.insert1)
200 apply (subgoal_tac "bijP P C")
205 apply (case_tac "a \<in> F")
206 apply (case_tac [!] "b \<in> F")
207 apply (cut_tac F = F and a = a and b = b and A = A and B = B
209 apply (simp_all add: subset_insert)
211 apply (rule bijER.insert2)
213 apply (subgoal_tac "bijP P C")
217 apply (subgoal_tac "b \<in> F")
218 apply (rule_tac [2] iffD1)
219 apply (rule_tac [2] a = a and F = F and P = P in aux_bij)
220 apply (simp_all (no_asm_simp))
221 apply (subgoal_tac [2] "a \<in> F")
222 apply (rule_tac [3] iffD2)
223 apply (rule_tac [3] b = b and F = F and P = P in aux_bij)
228 "(A, A) \<in> bijR P ==>
229 bijP P A ==> uniqP P ==> symP P ==> A \<in> bijER P"
230 apply (cut_tac A = A and B = A and P = P in aux_bijRER)