1 theory QuotScript |
|
2 imports Plain ATP_Linkup Predicate |
|
3 begin |
|
4 |
|
5 definition |
|
6 "equivp E \<equiv> \<forall>x y. E x y = (E x = E y)" |
|
7 |
|
8 definition |
|
9 "reflp E \<equiv> \<forall>x. E x x" |
|
10 |
|
11 definition |
|
12 "symp E \<equiv> \<forall>x y. E x y \<longrightarrow> E y x" |
|
13 |
|
14 definition |
|
15 "transp E \<equiv> \<forall>x y z. E x y \<and> E y z \<longrightarrow> E x z" |
|
16 |
|
17 lemma equivp_reflp_symp_transp: |
|
18 shows "equivp E = (reflp E \<and> symp E \<and> transp E)" |
|
19 unfolding equivp_def reflp_def symp_def transp_def expand_fun_eq |
|
20 by (blast) |
|
21 |
|
22 lemma equivp_reflp: |
|
23 shows "equivp E \<Longrightarrow> (\<And>x. E x x)" |
|
24 by (simp only: equivp_reflp_symp_transp reflp_def) |
|
25 |
|
26 lemma equivp_symp: |
|
27 shows "equivp E \<Longrightarrow> (\<And>x y. E x y \<Longrightarrow> E y x)" |
|
28 by (metis equivp_reflp_symp_transp symp_def) |
|
29 |
|
30 lemma equivp_transp: |
|
31 shows "equivp E \<Longrightarrow> (\<And>x y z. E x y \<Longrightarrow> E y z \<Longrightarrow> E x z)" |
|
32 by (metis equivp_reflp_symp_transp transp_def) |
|
33 |
|
34 lemma equivpI: |
|
35 assumes "reflp R" "symp R" "transp R" |
|
36 shows "equivp R" |
|
37 using assms by (simp add: equivp_reflp_symp_transp) |
|
38 |
|
39 lemma eq_imp_rel: |
|
40 shows "equivp R \<Longrightarrow> a = b \<longrightarrow> R a b" |
|
41 by (simp add: equivp_reflp) |
|
42 |
|
43 definition |
|
44 "part_equivp E \<equiv> (\<exists>x. E x x) \<and> (\<forall>x y. E x y = (E x x \<and> E y y \<and> (E x = E y)))" |
|
45 |
|
46 lemma equivp_IMP_part_equivp: |
|
47 assumes a: "equivp E" |
|
48 shows "part_equivp E" |
|
49 using a unfolding equivp_def part_equivp_def |
|
50 by auto |
|
51 |
|
52 |
|
53 abbreviation |
|
54 rel_conj (infixr "OOO" 75) |
|
55 where |
|
56 "r1 OOO r2 \<equiv> r1 OO r2 OO r1" |
|
57 |
|
58 definition |
|
59 "Quotient E Abs Rep \<equiv> (\<forall>a. Abs (Rep a) = a) \<and> |
|
60 (\<forall>a. E (Rep a) (Rep a)) \<and> |
|
61 (\<forall>r s. E r s = (E r r \<and> E s s \<and> (Abs r = Abs s)))" |
|
62 |
|
63 (* TEST |
|
64 lemma |
|
65 fixes Abs1::"'b \<Rightarrow> 'c" |
|
66 and Abs2::"'a \<Rightarrow> 'b" |
|
67 and Rep1::"'c \<Rightarrow> 'b" |
|
68 and Rep2::"'b \<Rightarrow> 'a" |
|
69 assumes "Quotient R1 Abs1 Rep1" |
|
70 and "Quotient R2 Abs2 Rep2" |
|
71 shows "Quotient (f R2 R1) (Abs1 \<circ> Abs2) (Rep2 \<circ> Rep1)" |
|
72 *) |
|
73 |
|
74 lemma Quotient_abs_rep: |
|
75 assumes a: "Quotient E Abs Rep" |
|
76 shows "Abs (Rep a) \<equiv> a" |
|
77 using a unfolding Quotient_def |
|
78 by simp |
|
79 |
|
80 lemma Quotient_rep_reflp: |
|
81 assumes a: "Quotient E Abs Rep" |
|
82 shows "E (Rep a) (Rep a)" |
|
83 using a unfolding Quotient_def |
|
84 by blast |
|
85 |
|
86 lemma Quotient_rel: |
|
87 assumes a: "Quotient E Abs Rep" |
|
88 shows " E r s = (E r r \<and> E s s \<and> (Abs r = Abs s))" |
|
89 using a unfolding Quotient_def |
|
90 by blast |
|
91 |
|
92 lemma Quotient_rel_rep: |
|
93 assumes a: "Quotient R Abs Rep" |
|
94 shows "R (Rep a) (Rep b) \<equiv> (a = b)" |
|
95 apply (rule eq_reflection) |
|
96 using a unfolding Quotient_def |
|
97 by metis |
|
98 |
|
99 lemma Quotient_rep_abs: |
|
100 assumes a: "Quotient R Abs Rep" |
|
101 shows "R r r \<Longrightarrow> R (Rep (Abs r)) r" |
|
102 using a unfolding Quotient_def |
|
103 by blast |
|
104 |
|
105 lemma Quotient_rel_abs: |
|
106 assumes a: "Quotient E Abs Rep" |
|
107 shows "E r s \<Longrightarrow> Abs r = Abs s" |
|
108 using a unfolding Quotient_def |
|
109 by blast |
|
110 |
|
111 lemma identity_equivp: |
|
112 shows "equivp (op =)" |
|
113 unfolding equivp_def |
|
114 by auto |
|
115 |
|
116 lemma identity_quotient: |
|
117 shows "Quotient (op =) id id" |
|
118 unfolding Quotient_def id_def |
|
119 by blast |
|
120 |
|
121 lemma Quotient_symp: |
|
122 assumes a: "Quotient E Abs Rep" |
|
123 shows "symp E" |
|
124 using a unfolding Quotient_def symp_def |
|
125 by metis |
|
126 |
|
127 lemma Quotient_transp: |
|
128 assumes a: "Quotient E Abs Rep" |
|
129 shows "transp E" |
|
130 using a unfolding Quotient_def transp_def |
|
131 by metis |
|
132 |
|
133 definition |
|
134 fun_map (infixr "--->" 55) |
|
135 where |
|
136 [simp]: "fun_map f g h x = g (h (f x))" |
|
137 |
|
138 lemma fun_map_id: |
|
139 shows "(id ---> id) = id" |
|
140 by (simp add: expand_fun_eq id_def) |
|
141 |
|
142 definition |
|
143 fun_rel (infixr "===>" 55) |
|
144 where |
|
145 [simp]: "fun_rel E1 E2 f g = (\<forall>x y. E1 x y \<longrightarrow> E2 (f x) (g y))" |
|
146 |
|
147 lemma fun_rel_eq: |
|
148 "(op =) ===> (op =) \<equiv> (op =)" |
|
149 by (rule eq_reflection) (simp add: expand_fun_eq) |
|
150 |
|
151 lemma fun_quotient: |
|
152 assumes q1: "Quotient R1 abs1 rep1" |
|
153 and q2: "Quotient R2 abs2 rep2" |
|
154 shows "Quotient (R1 ===> R2) (rep1 ---> abs2) (abs1 ---> rep2)" |
|
155 proof - |
|
156 have "\<forall>a. (rep1 ---> abs2) ((abs1 ---> rep2) a) = a" |
|
157 apply(simp add: expand_fun_eq) |
|
158 using q1 q2 |
|
159 apply(simp add: Quotient_def) |
|
160 done |
|
161 moreover |
|
162 have "\<forall>a. (R1 ===> R2) ((abs1 ---> rep2) a) ((abs1 ---> rep2) a)" |
|
163 apply(auto) |
|
164 using q1 q2 unfolding Quotient_def |
|
165 apply(metis) |
|
166 done |
|
167 moreover |
|
168 have "\<forall>r s. (R1 ===> R2) r s = ((R1 ===> R2) r r \<and> (R1 ===> R2) s s \<and> |
|
169 (rep1 ---> abs2) r = (rep1 ---> abs2) s)" |
|
170 apply(auto simp add: expand_fun_eq) |
|
171 using q1 q2 unfolding Quotient_def |
|
172 apply(metis) |
|
173 using q1 q2 unfolding Quotient_def |
|
174 apply(metis) |
|
175 using q1 q2 unfolding Quotient_def |
|
176 apply(metis) |
|
177 using q1 q2 unfolding Quotient_def |
|
178 apply(metis) |
|
179 done |
|
180 ultimately |
|
181 show "Quotient (R1 ===> R2) (rep1 ---> abs2) (abs1 ---> rep2)" |
|
182 unfolding Quotient_def by blast |
|
183 qed |
|
184 |
|
185 definition |
|
186 Respects |
|
187 where |
|
188 "Respects R x \<equiv> (R x x)" |
|
189 |
|
190 lemma in_respects: |
|
191 shows "(x \<in> Respects R) = R x x" |
|
192 unfolding mem_def Respects_def by simp |
|
193 |
|
194 lemma equals_rsp: |
|
195 assumes q: "Quotient R Abs Rep" |
|
196 and a: "R xa xb" "R ya yb" |
|
197 shows "R xa ya = R xb yb" |
|
198 using Quotient_symp[OF q] Quotient_transp[OF q] unfolding symp_def transp_def |
|
199 using a by blast |
|
200 |
|
201 lemma lambda_prs: |
|
202 assumes q1: "Quotient R1 Abs1 Rep1" |
|
203 and q2: "Quotient R2 Abs2 Rep2" |
|
204 shows "(Rep1 ---> Abs2) (\<lambda>x. Rep2 (f (Abs1 x))) = (\<lambda>x. f x)" |
|
205 unfolding expand_fun_eq |
|
206 using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] |
|
207 by simp |
|
208 |
|
209 lemma lambda_prs1: |
|
210 assumes q1: "Quotient R1 Abs1 Rep1" |
|
211 and q2: "Quotient R2 Abs2 Rep2" |
|
212 shows "(Rep1 ---> Abs2) (\<lambda>x. (Abs1 ---> Rep2) f x) = (\<lambda>x. f x)" |
|
213 unfolding expand_fun_eq |
|
214 using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] |
|
215 by simp |
|
216 |
|
217 lemma rep_abs_rsp: |
|
218 assumes q: "Quotient R Abs Rep" |
|
219 and a: "R x1 x2" |
|
220 shows "R x1 (Rep (Abs x2))" |
|
221 using q a by (metis Quotient_rel[OF q] Quotient_abs_rep[OF q] Quotient_rep_reflp[OF q]) |
|
222 |
|
223 lemma rep_abs_rsp_left: |
|
224 assumes q: "Quotient R Abs Rep" |
|
225 and a: "R x1 x2" |
|
226 shows "R (Rep (Abs x1)) x2" |
|
227 using q a by (metis Quotient_rel[OF q] Quotient_abs_rep[OF q] Quotient_rep_reflp[OF q]) |
|
228 |
|
229 (* In the following theorem R1 can be instantiated with anything, |
|
230 but we know some of the types of the Rep and Abs functions; |
|
231 so by solving Quotient assumptions we can get a unique R1 that |
|
232 will be provable; which is why we need to use apply_rsp and |
|
233 not the primed version *) |
|
234 lemma apply_rsp: |
|
235 fixes f g::"'a \<Rightarrow> 'c" |
|
236 assumes q: "Quotient R1 Abs1 Rep1" |
|
237 and a: "(R1 ===> R2) f g" "R1 x y" |
|
238 shows "R2 (f x) (g y)" |
|
239 using a by simp |
|
240 |
|
241 lemma apply_rsp': |
|
242 assumes a: "(R1 ===> R2) f g" "R1 x y" |
|
243 shows "R2 (f x) (g y)" |
|
244 using a by simp |
|
245 |
|
246 (* Set of lemmas for regularisation of ball and bex *) |
|
247 |
|
248 lemma ball_reg_eqv: |
|
249 fixes P :: "'a \<Rightarrow> bool" |
|
250 assumes a: "equivp R" |
|
251 shows "Ball (Respects R) P = (All P)" |
|
252 by (metis equivp_def in_respects a) |
|
253 |
|
254 lemma bex_reg_eqv: |
|
255 fixes P :: "'a \<Rightarrow> bool" |
|
256 assumes a: "equivp R" |
|
257 shows "Bex (Respects R) P = (Ex P)" |
|
258 by (metis equivp_def in_respects a) |
|
259 |
|
260 lemma ball_reg_right: |
|
261 assumes a: "\<And>x. R x \<Longrightarrow> P x \<longrightarrow> Q x" |
|
262 shows "All P \<longrightarrow> Ball R Q" |
|
263 by (metis COMBC_def Collect_def Collect_mem_eq a) |
|
264 |
|
265 lemma bex_reg_left: |
|
266 assumes a: "\<And>x. R x \<Longrightarrow> Q x \<longrightarrow> P x" |
|
267 shows "Bex R Q \<longrightarrow> Ex P" |
|
268 by (metis COMBC_def Collect_def Collect_mem_eq a) |
|
269 |
|
270 lemma ball_reg_left: |
|
271 assumes a: "equivp R" |
|
272 shows "(\<And>x. (Q x \<longrightarrow> P x)) \<Longrightarrow> Ball (Respects R) Q \<longrightarrow> All P" |
|
273 by (metis equivp_reflp in_respects a) |
|
274 |
|
275 lemma bex_reg_right: |
|
276 assumes a: "equivp R" |
|
277 shows "(\<And>x. (Q x \<longrightarrow> P x)) \<Longrightarrow> Ex Q \<longrightarrow> Bex (Respects R) P" |
|
278 by (metis equivp_reflp in_respects a) |
|
279 |
|
280 lemma ball_reg_eqv_range: |
|
281 fixes P::"'a \<Rightarrow> bool" |
|
282 and x::"'a" |
|
283 assumes a: "equivp R2" |
|
284 shows "(Ball (Respects (R1 ===> R2)) (\<lambda>f. P (f x)) = All (\<lambda>f. P (f x)))" |
|
285 apply(rule iffI) |
|
286 apply(rule allI) |
|
287 apply(drule_tac x="\<lambda>y. f x" in bspec) |
|
288 apply(simp add: in_respects) |
|
289 apply(rule impI) |
|
290 using a equivp_reflp_symp_transp[of "R2"] |
|
291 apply(simp add: reflp_def) |
|
292 apply(simp) |
|
293 apply(simp) |
|
294 done |
|
295 |
|
296 lemma bex_reg_eqv_range: |
|
297 assumes a: "equivp R2" |
|
298 shows "(Bex (Respects (R1 ===> R2)) (\<lambda>f. P (f x)) = Ex (\<lambda>f. P (f x)))" |
|
299 apply(auto) |
|
300 apply(rule_tac x="\<lambda>y. f x" in bexI) |
|
301 apply(simp) |
|
302 apply(simp add: Respects_def in_respects) |
|
303 apply(rule impI) |
|
304 using a equivp_reflp_symp_transp[of "R2"] |
|
305 apply(simp add: reflp_def) |
|
306 done |
|
307 |
|
308 lemma all_reg: |
|
309 assumes a: "!x :: 'a. (P x --> Q x)" |
|
310 and b: "All P" |
|
311 shows "All Q" |
|
312 using a b by (metis) |
|
313 |
|
314 lemma ex_reg: |
|
315 assumes a: "!x :: 'a. (P x --> Q x)" |
|
316 and b: "Ex P" |
|
317 shows "Ex Q" |
|
318 using a b by (metis) |
|
319 |
|
320 lemma ball_reg: |
|
321 assumes a: "!x :: 'a. (R x --> P x --> Q x)" |
|
322 and b: "Ball R P" |
|
323 shows "Ball R Q" |
|
324 using a b by (metis COMBC_def Collect_def Collect_mem_eq) |
|
325 |
|
326 lemma bex_reg: |
|
327 assumes a: "!x :: 'a. (R x --> P x --> Q x)" |
|
328 and b: "Bex R P" |
|
329 shows "Bex R Q" |
|
330 using a b by (metis COMBC_def Collect_def Collect_mem_eq) |
|
331 |
|
332 lemma ball_all_comm: |
|
333 "(\<And>y. (\<forall>x\<in>P. A x y) \<longrightarrow> (\<forall>x. B x y)) \<Longrightarrow> ((\<forall>x\<in>P. \<forall>y. A x y) \<longrightarrow> (\<forall>x. \<forall>y. B x y))" |
|
334 by auto |
|
335 |
|
336 lemma bex_ex_comm: |
|
337 "((\<exists>y. \<exists>x. A x y) \<longrightarrow> (\<exists>y. \<exists>x\<in>P. B x y)) \<Longrightarrow> ((\<exists>x. \<exists>y. A x y) \<longrightarrow> (\<exists>x\<in>P. \<exists>y. B x y))" |
|
338 by auto |
|
339 |
|
340 (* Bounded abstraction *) |
|
341 definition |
|
342 Babs :: "('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b" |
|
343 where |
|
344 "(x \<in> p) \<Longrightarrow> (Babs p m x = m x)" |
|
345 |
|
346 definition |
|
347 Bexeq :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool" |
|
348 where |
|
349 "Bexeq R P \<equiv> (\<exists>x \<in> Respects R. P x) \<and> (\<forall>x \<in> Respects R. \<forall>y \<in> Respects R. ((P x \<and> P y) \<longrightarrow> (R x y)))" |
|
350 |
|
351 (* 3 lemmas needed for proving repabs_inj *) |
|
352 lemma ball_rsp: |
|
353 assumes a: "(R ===> (op =)) f g" |
|
354 shows "Ball (Respects R) f = Ball (Respects R) g" |
|
355 using a by (simp add: Ball_def in_respects) |
|
356 |
|
357 lemma bex_rsp: |
|
358 assumes a: "(R ===> (op =)) f g" |
|
359 shows "(Bex (Respects R) f = Bex (Respects R) g)" |
|
360 using a by (simp add: Bex_def in_respects) |
|
361 |
|
362 lemma bex1_rsp: |
|
363 assumes a: "(R ===> (op =)) f g" |
|
364 shows "(Bex1 (Respects R) f = Bex1 (Respects R) g)" |
|
365 using a |
|
366 by (simp add: Ex1_def Bex1_def in_respects) auto |
|
367 |
|
368 (* TODO/FIXME: simplify the repetitions in this proof *) |
|
369 lemma bexeq_rsp: |
|
370 assumes a: "Quotient R absf repf" |
|
371 shows "((R ===> op =) ===> op =) (Bexeq R) (Bexeq R)" |
|
372 apply simp |
|
373 unfolding Bexeq_def |
|
374 apply rule |
|
375 apply rule |
|
376 apply rule |
|
377 apply rule |
|
378 apply (erule conjE)+ |
|
379 apply (erule bexE) |
|
380 apply rule |
|
381 apply (rule_tac x="xa" in bexI) |
|
382 apply metis |
|
383 apply metis |
|
384 apply rule+ |
|
385 apply (erule_tac x="xb" in ballE) |
|
386 prefer 2 |
|
387 apply (metis) |
|
388 apply (erule_tac x="ya" in ballE) |
|
389 prefer 2 |
|
390 apply (metis) |
|
391 apply (metis in_respects) |
|
392 apply (erule conjE)+ |
|
393 apply (erule bexE) |
|
394 apply rule |
|
395 apply (rule_tac x="xa" in bexI) |
|
396 apply metis |
|
397 apply metis |
|
398 apply rule+ |
|
399 apply (erule_tac x="xb" in ballE) |
|
400 prefer 2 |
|
401 apply (metis) |
|
402 apply (erule_tac x="ya" in ballE) |
|
403 prefer 2 |
|
404 apply (metis) |
|
405 apply (metis in_respects) |
|
406 done |
|
407 |
|
408 lemma babs_rsp: |
|
409 assumes q: "Quotient R1 Abs1 Rep1" |
|
410 and a: "(R1 ===> R2) f g" |
|
411 shows "(R1 ===> R2) (Babs (Respects R1) f) (Babs (Respects R1) g)" |
|
412 apply (auto simp add: Babs_def) |
|
413 apply (subgoal_tac "x \<in> Respects R1 \<and> y \<in> Respects R1") |
|
414 using a apply (simp add: Babs_def) |
|
415 apply (simp add: in_respects) |
|
416 using Quotient_rel[OF q] |
|
417 by metis |
|
418 |
|
419 lemma babs_prs: |
|
420 assumes q1: "Quotient R1 Abs1 Rep1" |
|
421 and q2: "Quotient R2 Abs2 Rep2" |
|
422 shows "(Rep1 ---> Abs2) (Babs (Respects R1) ((Abs1 ---> Rep2) f)) \<equiv> f" |
|
423 apply(rule eq_reflection) |
|
424 apply(rule ext) |
|
425 apply simp |
|
426 apply (subgoal_tac "Rep1 x \<in> Respects R1") |
|
427 apply (simp add: Babs_def Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2]) |
|
428 apply (simp add: in_respects Quotient_rel_rep[OF q1]) |
|
429 done |
|
430 |
|
431 lemma babs_simp: |
|
432 assumes q: "Quotient R1 Abs Rep" |
|
433 shows "((R1 ===> R2) (Babs (Respects R1) f) (Babs (Respects R1) g)) = ((R1 ===> R2) f g)" |
|
434 apply(rule iffI) |
|
435 apply(simp_all only: babs_rsp[OF q]) |
|
436 apply(auto simp add: Babs_def) |
|
437 apply (subgoal_tac "x \<in> Respects R1 \<and> y \<in> Respects R1") |
|
438 apply(metis Babs_def) |
|
439 apply (simp add: in_respects) |
|
440 using Quotient_rel[OF q] |
|
441 by metis |
|
442 |
|
443 (* If a user proves that a particular functional relation |
|
444 is an equivalence this may be useful in regularising *) |
|
445 lemma babs_reg_eqv: |
|
446 shows "equivp R \<Longrightarrow> Babs (Respects R) P = P" |
|
447 by (simp add: expand_fun_eq Babs_def in_respects equivp_reflp) |
|
448 |
|
449 (* 3 lemmas needed for cleaning of quantifiers *) |
|
450 lemma all_prs: |
|
451 assumes a: "Quotient R absf repf" |
|
452 shows "Ball (Respects R) ((absf ---> id) f) = All f" |
|
453 using a unfolding Quotient_def Ball_def in_respects fun_map_def id_apply |
|
454 by metis |
|
455 |
|
456 lemma ex_prs: |
|
457 assumes a: "Quotient R absf repf" |
|
458 shows "Bex (Respects R) ((absf ---> id) f) = Ex f" |
|
459 using a unfolding Quotient_def Bex_def in_respects fun_map_def id_apply |
|
460 by metis |
|
461 |
|
462 lemma ex1_prs: |
|
463 assumes a: "Quotient R absf repf" |
|
464 shows "((absf ---> id) ---> id) (Bexeq R) f = Ex1 f" |
|
465 apply simp |
|
466 apply (subst Bexeq_def) |
|
467 apply (subst Bex_def) |
|
468 apply (subst Ex1_def) |
|
469 apply simp |
|
470 apply rule |
|
471 apply (erule conjE)+ |
|
472 apply (erule_tac exE) |
|
473 apply (erule conjE) |
|
474 apply (subgoal_tac "\<forall>y. R y y \<longrightarrow> f (absf y) \<longrightarrow> R x y") |
|
475 apply (rule_tac x="absf x" in exI) |
|
476 apply (thin_tac "\<forall>x\<in>Respects R. \<forall>y\<in>Respects R. f (absf x) \<and> f (absf y) \<longrightarrow> R x y") |
|
477 apply (simp) |
|
478 apply rule+ |
|
479 using a unfolding Quotient_def |
|
480 apply metis |
|
481 apply rule+ |
|
482 apply (erule_tac x="x" in ballE) |
|
483 apply (erule_tac x="y" in ballE) |
|
484 apply simp |
|
485 apply (simp add: in_respects) |
|
486 apply (simp add: in_respects) |
|
487 apply (erule_tac exE) |
|
488 apply rule |
|
489 apply (rule_tac x="repf x" in exI) |
|
490 apply (simp only: in_respects) |
|
491 apply rule |
|
492 apply (metis Quotient_rel_rep[OF a]) |
|
493 using a unfolding Quotient_def apply (simp) |
|
494 apply rule+ |
|
495 using a unfolding Quotient_def in_respects |
|
496 apply metis |
|
497 done |
|
498 |
|
499 lemma fun_rel_id: |
|
500 assumes a: "\<And>x y. R1 x y \<Longrightarrow> R2 (f x) (g y)" |
|
501 shows "(R1 ===> R2) f g" |
|
502 using a by simp |
|
503 |
|
504 lemma fun_rel_id_asm: |
|
505 assumes a: "\<And>x y. R1 x y \<Longrightarrow> (A \<longrightarrow> R2 (f x) (g y))" |
|
506 shows "A \<longrightarrow> (R1 ===> R2) f g" |
|
507 using a by auto |
|
508 |
|
509 lemma quot_rel_rsp: |
|
510 assumes a: "Quotient R Abs Rep" |
|
511 shows "(R ===> R ===> op =) R R" |
|
512 apply(rule fun_rel_id)+ |
|
513 apply(rule equals_rsp[OF a]) |
|
514 apply(assumption)+ |
|
515 done |
|
516 |
|
517 lemma o_prs: |
|
518 assumes q1: "Quotient R1 Abs1 Rep1" |
|
519 and q2: "Quotient R2 Abs2 Rep2" |
|
520 and q3: "Quotient R3 Abs3 Rep3" |
|
521 shows "(Rep1 ---> Abs3) (((Abs2 ---> Rep3) f) o ((Abs1 ---> Rep2) g)) = f o g" |
|
522 using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] Quotient_abs_rep[OF q3] |
|
523 unfolding o_def expand_fun_eq by simp |
|
524 |
|
525 lemma o_rsp: |
|
526 assumes q1: "Quotient R1 Abs1 Rep1" |
|
527 and q2: "Quotient R2 Abs2 Rep2" |
|
528 and q3: "Quotient R3 Abs3 Rep3" |
|
529 and a1: "(R2 ===> R3) f1 f2" |
|
530 and a2: "(R1 ===> R2) g1 g2" |
|
531 shows "(R1 ===> R3) (f1 o g1) (f2 o g2)" |
|
532 using a1 a2 unfolding o_def expand_fun_eq |
|
533 by (auto) |
|
534 |
|
535 lemma cond_prs: |
|
536 assumes a: "Quotient R absf repf" |
|
537 shows "absf (if a then repf b else repf c) = (if a then b else c)" |
|
538 using a unfolding Quotient_def by auto |
|
539 |
|
540 lemma if_prs: |
|
541 assumes q: "Quotient R Abs Rep" |
|
542 shows "Abs (If a (Rep b) (Rep c)) = If a b c" |
|
543 using Quotient_abs_rep[OF q] by auto |
|
544 |
|
545 (* q not used *) |
|
546 lemma if_rsp: |
|
547 assumes q: "Quotient R Abs Rep" |
|
548 and a: "a1 = a2" "R b1 b2" "R c1 c2" |
|
549 shows "R (If a1 b1 c1) (If a2 b2 c2)" |
|
550 using a by auto |
|
551 |
|
552 lemma let_prs: |
|
553 assumes q1: "Quotient R1 Abs1 Rep1" |
|
554 and q2: "Quotient R2 Abs2 Rep2" |
|
555 shows "Abs2 (Let (Rep1 x) ((Abs1 ---> Rep2) f)) = Let x f" |
|
556 using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] by auto |
|
557 |
|
558 lemma let_rsp: |
|
559 assumes q1: "Quotient R1 Abs1 Rep1" |
|
560 and a1: "(R1 ===> R2) f g" |
|
561 and a2: "R1 x y" |
|
562 shows "R2 ((Let x f)::'c) ((Let y g)::'c)" |
|
563 using apply_rsp[OF q1 a1] a2 by auto |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 (******************************************) |
|
569 (* REST OF THE FILE IS UNUSED (until now) *) |
|
570 (******************************************) |
|
571 |
|
572 lemma in_fun: |
|
573 shows "x \<in> ((f ---> g) s) = g (f x \<in> s)" |
|
574 by (simp add: mem_def) |
|
575 |
|
576 lemma respects_thm: |
|
577 shows "Respects (R1 ===> R2) f = (\<forall>x y. R1 x y \<longrightarrow> R2 (f x) (f y))" |
|
578 unfolding Respects_def |
|
579 by (simp add: expand_fun_eq) |
|
580 |
|
581 lemma respects_rep_abs: |
|
582 assumes a: "Quotient R1 Abs1 Rep1" |
|
583 and b: "Respects (R1 ===> R2) f" |
|
584 and c: "R1 x x" |
|
585 shows "R2 (f (Rep1 (Abs1 x))) (f x)" |
|
586 using a b[simplified respects_thm] c unfolding Quotient_def |
|
587 by blast |
|
588 |
|
589 lemma respects_mp: |
|
590 assumes a: "Respects (R1 ===> R2) f" |
|
591 and b: "R1 x y" |
|
592 shows "R2 (f x) (f y)" |
|
593 using a b unfolding Respects_def |
|
594 by simp |
|
595 |
|
596 lemma respects_o: |
|
597 assumes a: "Respects (R2 ===> R3) f" |
|
598 and b: "Respects (R1 ===> R2) g" |
|
599 shows "Respects (R1 ===> R3) (f o g)" |
|
600 using a b unfolding Respects_def |
|
601 by simp |
|
602 |
|
603 lemma abs_o_rep: |
|
604 assumes a: "Quotient r absf repf" |
|
605 shows "absf o repf = id" |
|
606 apply(rule ext) |
|
607 apply(simp add: Quotient_abs_rep[OF a]) |
|
608 done |
|
609 |
|
610 lemma eq_comp_r: "op = OO R OO op = \<equiv> R" |
|
611 apply (rule eq_reflection) |
|
612 apply (rule ext)+ |
|
613 apply auto |
|
614 done |
|
615 |
|
616 lemma fun_rel_eq_rel: |
|
617 assumes q1: "Quotient R1 Abs1 Rep1" |
|
618 and q2: "Quotient R2 Abs2 Rep2" |
|
619 shows "(R1 ===> R2) f g = ((Respects (R1 ===> R2) f) \<and> (Respects (R1 ===> R2) g) |
|
620 \<and> ((Rep1 ---> Abs2) f = (Rep1 ---> Abs2) g))" |
|
621 using fun_quotient[OF q1 q2] unfolding Respects_def Quotient_def expand_fun_eq |
|
622 by blast |
|
623 |
|
624 lemma let_babs: |
|
625 "v \<in> r \<Longrightarrow> Let v (Babs r lam) = Let v lam" |
|
626 by (simp add: Babs_def) |
|
627 |
|
628 lemma fun_rel_equals: |
|
629 assumes q1: "Quotient R1 Abs1 Rep1" |
|
630 and q2: "Quotient R2 Abs2 Rep2" |
|
631 and r1: "Respects (R1 ===> R2) f" |
|
632 and r2: "Respects (R1 ===> R2) g" |
|
633 shows "((Rep1 ---> Abs2) f = (Rep1 ---> Abs2) g) = (\<forall>x y. R1 x y \<longrightarrow> R2 (f x) (g y))" |
|
634 apply(rule_tac iffI) |
|
635 apply(rule)+ |
|
636 apply (rule apply_rsp'[of "R1" "R2"]) |
|
637 apply(subst Quotient_rel[OF fun_quotient[OF q1 q2]]) |
|
638 apply auto |
|
639 using fun_quotient[OF q1 q2] r1 r2 unfolding Quotient_def Respects_def |
|
640 apply (metis let_rsp q1) |
|
641 apply (metis fun_rel_eq_rel let_rsp q1 q2 r2) |
|
642 using r1 unfolding Respects_def expand_fun_eq |
|
643 apply(simp (no_asm_use)) |
|
644 apply(metis Quotient_rel[OF q2] Quotient_rel_rep[OF q1]) |
|
645 done |
|
646 |
|
647 (* ask Peter: fun_rel_IMP used twice *) |
|
648 lemma fun_rel_IMP2: |
|
649 assumes q1: "Quotient R1 Abs1 Rep1" |
|
650 and q2: "Quotient R2 Abs2 Rep2" |
|
651 and r1: "Respects (R1 ===> R2) f" |
|
652 and r2: "Respects (R1 ===> R2) g" |
|
653 and a: "(Rep1 ---> Abs2) f = (Rep1 ---> Abs2) g" |
|
654 shows "R1 x y \<Longrightarrow> R2 (f x) (g y)" |
|
655 using q1 q2 r1 r2 a |
|
656 by (simp add: fun_rel_equals) |
|
657 |
|
658 lemma lambda_rep_abs_rsp: |
|
659 assumes r1: "\<And>r r'. R1 r r' \<Longrightarrow>R1 r (Rep1 (Abs1 r'))" |
|
660 and r2: "\<And>r r'. R2 r r' \<Longrightarrow>R2 r (Rep2 (Abs2 r'))" |
|
661 shows "(R1 ===> R2) f1 f2 \<Longrightarrow> (R1 ===> R2) f1 ((Abs1 ---> Rep2) ((Rep1 ---> Abs2) f2))" |
|
662 using r1 r2 by auto |
|
663 |
|
664 (* ask peter what are literal_case *) |
|
665 (* literal_case_PRS *) |
|
666 (* literal_case_RSP *) |
|
667 (* Cez: !f x. literal_case f x = f x *) |
|
668 |
|
669 (* We use id_simps which includes id_apply; so these 2 theorems can be removed *) |
|
670 lemma id_prs: |
|
671 assumes q: "Quotient R Abs Rep" |
|
672 shows "Abs (id (Rep e)) = id e" |
|
673 using Quotient_abs_rep[OF q] by auto |
|
674 |
|
675 lemma id_rsp: |
|
676 assumes q: "Quotient R Abs Rep" |
|
677 and a: "R e1 e2" |
|
678 shows "R (id e1) (id e2)" |
|
679 using a by auto |
|
680 |
|
681 end |
|
682 |
|