src/HOL/NumberTheory/BijectionRel.thy
 author paulson Fri Mar 05 11:43:55 2004 +0100 (2004-03-05) changeset 14434 5f14c1207499 parent 13630 a013a9dd370f child 16417 9bc16273c2d4 permissions -rw-r--r--
patch to NumberTheory problems caused by Parity
1 (*  Title:      HOL/NumberTheory/BijectionRel.thy
2     ID:         \$Id\$
3     Author:     Thomas M. Rasmussen
4     Copyright   2000  University of Cambridge
5 *)
7 header {* Bijections between sets *}
9 theory BijectionRel = Main:
11 text {*
12   Inductive definitions of bijections between two different sets and
13   between the same set.  Theorem for relating the two definitions.
15   \bigskip
16 *}
18 consts
19   bijR :: "('a => 'b => bool) => ('a set * 'b set) set"
21 inductive "bijR P"
22   intros
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"
27 text {*
28   Add extra condition to @{term insert}: @{term "\<forall>b \<in> B. \<not> P a b"}
29   (and similar for @{term A}).
30 *}
32 constdefs
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"
42 consts
43   bijER :: "('a => 'a => bool) => 'a set set"
45 inductive "bijER P"
46   intros
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)
57   apply auto
58   done
60 lemma fin_bijRr: "(A, B) \<in> bijR P ==> finite B"
61   apply (erule bijR.induct)
62   apply auto
63   done
65 lemma aux_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))
68   ==> P F"
69 proof -
70   case rule_context
71   assume major: "finite F"
72     and subs: "F \<subseteq> A"
73   show ?thesis
74     apply (rule subs [THEN rev_mp])
75     apply (rule major [THEN finite_induct])
76      apply (blast intro: rule_context)+
77     done
78 qed
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)
83   apply auto
84   done
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)
91       apply auto
92   apply (rule bijR.insert)
93      apply (rule_tac [3] inj_func_bijR_aux1)
94         apply auto
95   done
97 lemma inj_func_bijR:
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)
101      apply auto
102   done
105 text {* \medskip @{term bijER} *}
107 lemma fin_bijER: "A \<in> bijER P ==> finite A"
108   apply (erule bijER.induct)
109     apply auto
110   done
112 lemma aux1:
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)
116   apply auto
117   done
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)
123   apply auto
124   done
126 lemma aux_uniq: "uniqP P ==> P a b ==> P c d ==> (a = c) = (b = d)"
127   apply (unfold uniqP_def)
128   apply auto
129   done
131 lemma aux_sym: "symP P ==> P a b = P b a"
132   apply (unfold symP_def)
133   apply auto
134   done
136 lemma aux_in1:
137     "uniqP P ==> b \<notin> C ==> P b b ==> bijP P (insert b C) ==> bijP P C"
138   apply (unfold bijP_def)
139   apply auto
140   apply (subgoal_tac "b \<noteq> a")
141    prefer 2
142    apply clarify
144   apply auto
145   done
147 lemma aux_in2:
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)
151   apply auto
152   apply (subgoal_tac "aa \<noteq> a")
153    prefer 2
154    apply clarify
155   apply (subgoal_tac "aa \<noteq> b")
156    prefer 2
157    apply clarify
159   apply (subgoal_tac "ba \<noteq> a")
160    apply auto
161   apply (subgoal_tac "P a aa")
162    prefer 2
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)
167       apply auto
168   done
170 lemma aux_foo: "\<forall>a b. Q a \<and> P a b --> R b ==> P a b ==> Q a ==> R b"
171   apply auto
172   done
174 lemma aux_bij: "bijP P F ==> symP P ==> P a b ==> (a \<in> F) = (b \<in> F)"
175   apply (unfold bijP_def)
176   apply (rule iffI)
177   apply (erule_tac [!] aux_foo)
178       apply simp_all
179   apply (rule iffD2)
180    apply (rule_tac P = P in aux_sym)
181    apply simp_all
182   done
185 lemma aux_bijRER:
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)
189    apply simp
190   apply (case_tac "a = b")
191    apply clarify
192    apply (case_tac "b \<in> F")
193     prefer 2
195    apply (cut_tac F = F and a = b and A = A and B = B in aux1)
196         prefer 6
197         apply clarify
198         apply (rule bijER.insert1)
199           apply simp_all
200    apply (subgoal_tac "bijP P C")
201     apply simp
202    apply (rule aux_in1)
203       apply simp_all
204   apply clarify
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
208        in aux2)
210     apply clarify
211     apply (rule bijER.insert2)
212         apply simp_all
213     apply (subgoal_tac "bijP P C")
214      apply simp
215     apply (rule aux_in2)
216           apply simp_all
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)
224        apply auto
225   done
227 lemma bijR_bijER:
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)
231      apply auto
232   done
234 end