31 "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)))" |
31 "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)))" |
32 |
32 |
33 lemma equivp_IMP_part_equivp: |
33 lemma equivp_IMP_part_equivp: |
34 assumes a: "equivp E" |
34 assumes a: "equivp E" |
35 shows "part_equivp E" |
35 shows "part_equivp E" |
36 using a unfolding equivp_def part_equivp_def |
36 using a unfolding equivp_def part_equivp_def |
37 by auto |
37 by auto |
38 |
38 |
39 definition |
39 definition |
40 "Quotient E Abs Rep \<equiv> (\<forall>a. Abs (Rep a) = a) \<and> |
40 "Quotient E Abs Rep \<equiv> (\<forall>a. Abs (Rep a) = a) \<and> |
41 (\<forall>a. E (Rep a) (Rep a)) \<and> |
41 (\<forall>a. E (Rep a) (Rep a)) \<and> |
42 (\<forall>r s. E r s = (E r r \<and> E s s \<and> (Abs r = Abs s)))" |
42 (\<forall>r s. E r s = (E r r \<and> E s s \<and> (Abs r = Abs s)))" |
43 |
43 |
44 lemma Quotient_abs_rep: |
44 lemma Quotient_abs_rep: |
45 assumes a: "Quotient E Abs Rep" |
45 assumes a: "Quotient E Abs Rep" |
46 shows "Abs (Rep a) = a" |
46 shows "Abs (Rep a) = a" |
47 using a unfolding Quotient_def |
47 using a unfolding Quotient_def |
48 by simp |
48 by simp |
49 |
49 |
50 lemma Quotient_rep_reflp: |
50 lemma Quotient_rep_reflp: |
51 assumes a: "Quotient E Abs Rep" |
51 assumes a: "Quotient E Abs Rep" |
52 shows "E (Rep a) (Rep a)" |
52 shows "E (Rep a) (Rep a)" |
53 using a unfolding Quotient_def |
53 using a unfolding Quotient_def |
54 by blast |
54 by blast |
55 |
55 |
56 lemma Quotient_rel: |
56 lemma Quotient_rel: |
57 assumes a: "Quotient E Abs Rep" |
57 assumes a: "Quotient E Abs Rep" |
58 shows " E r s = (E r r \<and> E s s \<and> (Abs r = Abs s))" |
58 shows " E r s = (E r r \<and> E s s \<and> (Abs r = Abs s))" |
59 using a unfolding Quotient_def |
59 using a unfolding Quotient_def |
60 by blast |
60 by blast |
61 |
61 |
62 lemma Quotient_rel_rep: |
62 lemma Quotient_rel_rep: |
63 assumes a: "Quotient R Abs Rep" |
63 assumes a: "Quotient R Abs Rep" |
64 shows "R (Rep a) (Rep b) \<equiv> (a = b)" |
64 shows "R (Rep a) (Rep b) \<equiv> (a = b)" |
65 apply (rule eq_reflection) |
65 apply (rule eq_reflection) |
66 using a unfolding Quotient_def |
66 using a unfolding Quotient_def |
67 by metis |
67 by metis |
68 |
68 |
69 lemma Quotient_rep_abs: |
69 lemma Quotient_rep_abs: |
70 assumes a: "Quotient R Abs Rep" |
70 assumes a: "Quotient R Abs Rep" |
71 shows "R r r \<Longrightarrow> R (Rep (Abs r)) r" |
71 shows "R r r \<Longrightarrow> R (Rep (Abs r)) r" |
72 using a unfolding Quotient_def |
72 using a unfolding Quotient_def |
73 by blast |
73 by blast |
74 |
74 |
75 lemma identity_equivp: |
75 lemma identity_equivp: |
76 shows "equivp (op =)" |
76 shows "equivp (op =)" |
77 unfolding equivp_def |
77 unfolding equivp_def |
78 by auto |
78 by auto |
79 |
79 |
80 lemma identity_quotient: |
80 lemma identity_quotient: |
81 shows "Quotient (op =) id id" |
81 shows "Quotient (op =) id id" |
82 unfolding Quotient_def id_def |
82 unfolding Quotient_def id_def |
83 by blast |
83 by blast |
84 |
84 |
85 lemma Quotient_symp: |
85 lemma Quotient_symp: |
86 assumes a: "Quotient E Abs Rep" |
86 assumes a: "Quotient E Abs Rep" |
87 shows "symp E" |
87 shows "symp E" |
88 using a unfolding Quotient_def symp_def |
88 using a unfolding Quotient_def symp_def |
89 by metis |
89 by metis |
90 |
90 |
91 lemma Quotient_transp: |
91 lemma Quotient_transp: |
92 assumes a: "Quotient E Abs Rep" |
92 assumes a: "Quotient E Abs Rep" |
93 shows "transp E" |
93 shows "transp E" |
94 using a unfolding Quotient_def transp_def |
94 using a unfolding Quotient_def transp_def |
95 by metis |
95 by metis |
96 |
96 |
97 fun |
97 fun |
98 prod_rel |
98 prod_rel |
99 where |
99 where |
100 "prod_rel r1 r2 = (\<lambda>(a,b) (c,d). r1 a c \<and> r2 b d)" |
100 "prod_rel r1 r2 = (\<lambda>(a,b) (c,d). r1 a c \<and> r2 b d)" |
167 where |
166 where |
168 "Respects R x \<equiv> (R x x)" |
167 "Respects R x \<equiv> (R x x)" |
169 |
168 |
170 lemma in_respects: |
169 lemma in_respects: |
171 shows "(x \<in> Respects R) = R x x" |
170 shows "(x \<in> Respects R) = R x x" |
172 unfolding mem_def Respects_def by simp |
171 unfolding mem_def Respects_def by simp |
173 |
|
174 (* TODO: it is the same as APPLY_RSP *) |
|
175 (* q1 and q2 not used; see next lemma *) |
|
176 lemma fun_rel_MP: |
|
177 assumes q1: "Quotient R1 Abs1 Rep1" |
|
178 and q2: "Quotient R2 Abs2 Rep2" |
|
179 shows "(R1 ===> R2) f g \<Longrightarrow> R1 x y \<Longrightarrow> R2 (f x) (g y)" |
|
180 by simp |
|
181 |
|
182 lemma fun_rel_IMP: |
|
183 shows "(R1 ===> R2) f g \<Longrightarrow> R1 x y \<Longrightarrow> R2 (f x) (g y)" |
|
184 by simp |
|
185 |
|
186 |
172 |
187 lemma equals_rsp: |
173 lemma equals_rsp: |
188 assumes q: "Quotient R Abs Rep" |
174 assumes q: "Quotient R Abs Rep" |
189 and a: "R xa xb" "R ya yb" |
175 and a: "R xa xb" "R ya yb" |
190 shows "R xa ya = R xb yb" |
176 shows "R xa ya = R xb yb" |
191 using Quotient_symp[OF q] Quotient_transp[OF q] unfolding symp_def transp_def |
177 using Quotient_symp[OF q] Quotient_transp[OF q] unfolding symp_def transp_def |
192 using a by blast |
178 using a by blast |
193 |
179 |
194 lemma lambda_prs: |
180 lemma lambda_prs: |
195 assumes q1: "Quotient R1 Abs1 Rep1" |
181 assumes q1: "Quotient R1 Abs1 Rep1" |
196 and q2: "Quotient R2 Abs2 Rep2" |
182 and q2: "Quotient R2 Abs2 Rep2" |
197 shows "(Rep1 ---> Abs2) (\<lambda>x. Rep2 (f (Abs1 x))) = (\<lambda>x. f x)" |
183 shows "(Rep1 ---> Abs2) (\<lambda>x. Rep2 (f (Abs1 x))) = (\<lambda>x. f x)" |
198 unfolding expand_fun_eq |
184 unfolding expand_fun_eq |
199 using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] |
185 using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] |
200 by simp |
186 by simp |
201 |
187 |
202 lemma lambda_prs1: |
188 lemma lambda_prs1: |
203 assumes q1: "Quotient R1 Abs1 Rep1" |
189 assumes q1: "Quotient R1 Abs1 Rep1" |
204 and q2: "Quotient R2 Abs2 Rep2" |
190 and q2: "Quotient R2 Abs2 Rep2" |
205 shows "(Rep1 ---> Abs2) (\<lambda>x. (Abs1 ---> Rep2) f x) = (\<lambda>x. f x)" |
191 shows "(Rep1 ---> Abs2) (\<lambda>x. (Abs1 ---> Rep2) f x) = (\<lambda>x. f x)" |
206 unfolding expand_fun_eq |
192 unfolding expand_fun_eq |
207 using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] |
193 using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] |
208 by simp |
194 by simp |
209 |
195 |
210 lemma rep_abs_rsp: |
196 lemma rep_abs_rsp: |
211 assumes q: "Quotient R Abs Rep" |
197 assumes q: "Quotient R Abs Rep" |
212 and a: "R x1 x2" |
198 and a: "R x1 x2" |
213 shows "R x1 (Rep (Abs x2))" |
199 shows "R x1 (Rep (Abs x2))" |
214 using q a by (metis Quotient_rel[OF q] Quotient_abs_rep[OF q] Quotient_rep_reflp[OF q]) |
200 using q a by (metis Quotient_rel[OF q] Quotient_abs_rep[OF q] Quotient_rep_reflp[OF q]) |
215 |
|
216 (* ----------------------------------------------------- *) |
|
217 (* Quantifiers: FORALL, EXISTS, EXISTS_UNIQUE, *) |
|
218 (* Ball, Bex, RES_EXISTS_EQUIV *) |
|
219 (* ----------------------------------------------------- *) |
|
220 |
|
221 (* bool theory: COND, LET *) |
|
222 |
|
223 lemma IF_PRS: |
|
224 assumes q: "Quotient R Abs Rep" |
|
225 shows "If a b c = Abs (If a (Rep b) (Rep c))" |
|
226 using Quotient_abs_rep[OF q] by auto |
|
227 |
|
228 (* ask peter: no use of q *) |
|
229 lemma IF_RSP: |
|
230 assumes q: "Quotient R Abs Rep" |
|
231 and a: "a1 = a2" "R b1 b2" "R c1 c2" |
|
232 shows "R (If a1 b1 c1) (If a2 b2 c2)" |
|
233 using a by auto |
|
234 |
|
235 lemma LET_PRS: |
|
236 assumes q1: "Quotient R1 Abs1 Rep1" |
|
237 and q2: "Quotient R2 Abs2 Rep2" |
|
238 shows "Let x f = Abs2 (Let (Rep1 x) ((Abs1 ---> Rep2) f))" |
|
239 using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] by auto |
|
240 |
|
241 lemma LET_RSP: |
|
242 assumes q1: "Quotient R1 Abs1 Rep1" |
|
243 and q2: "Quotient R2 Abs2 Rep2" |
|
244 and a1: "(R1 ===> R2) f g" |
|
245 and a2: "R1 x y" |
|
246 shows "R2 (Let x f) (Let y g)" |
|
247 using fun_rel_MP[OF q1 q2 a1] a2 |
|
248 by auto |
|
249 |
|
250 |
|
251 (* ask peter what are literal_case *) |
|
252 (* literal_case_PRS *) |
|
253 (* literal_case_RSP *) |
|
254 |
|
255 |
|
256 (* FUNCTION APPLICATION *) |
|
257 |
201 |
258 (* In the following theorem R1 can be instantiated with anything, |
202 (* In the following theorem R1 can be instantiated with anything, |
259 but we know some of the types of the Rep and Abs functions; |
203 but we know some of the types of the Rep and Abs functions; |
260 so by solving Quotient assumptions we can get a unique R2 that |
204 so by solving Quotient assumptions we can get a unique R1 that |
261 will be provable; which is why we need to use APPLY_RSP *) |
205 will be provable; which is why we need to use apply_rsp and |
|
206 not the primed version *) |
262 lemma apply_rsp: |
207 lemma apply_rsp: |
263 assumes q: "Quotient R1 Abs1 Rep1" |
208 assumes q: "Quotient R1 Abs1 Rep1" |
264 and a: "(R1 ===> R2) f g" "R1 x y" |
209 and a: "(R1 ===> R2) f g" "R1 x y" |
265 shows "R2 ((f::'a\<Rightarrow>'c) x) ((g::'a\<Rightarrow>'c) y)" |
210 shows "R2 ((f::'a\<Rightarrow>'c) x) ((g::'a\<Rightarrow>'c) y)" |
266 using a by (rule fun_rel_IMP) |
211 using a by simp |
267 |
212 |
268 lemma apply_rsp': |
213 lemma apply_rsp': |
269 assumes a: "(R1 ===> R2) f g" "R1 x y" |
214 assumes a: "(R1 ===> R2) f g" "R1 x y" |
270 shows "R2 (f x) (g y)" |
215 shows "R2 (f x) (g y)" |
271 using a by (rule fun_rel_IMP) |
216 using a by simp |
272 |
|
273 |
|
274 (* combinators: I, K, o, C, W *) |
|
275 |
|
276 (* We use id_simps which includes id_apply; so these 2 theorems can be removed *) |
|
277 lemma I_PRS: |
|
278 assumes q: "Quotient R Abs Rep" |
|
279 shows "id e = Abs (id (Rep e))" |
|
280 using Quotient_abs_rep[OF q] by auto |
|
281 |
|
282 lemma I_RSP: |
|
283 assumes q: "Quotient R Abs Rep" |
|
284 and a: "R e1 e2" |
|
285 shows "R (id e1) (id e2)" |
|
286 using a by auto |
|
287 |
|
288 lemma o_PRS: |
|
289 assumes q1: "Quotient R1 Abs1 Rep1" |
|
290 and q2: "Quotient R2 Abs2 Rep2" |
|
291 and q3: "Quotient R3 Abs3 Rep3" |
|
292 shows "f o g = (Rep1 ---> Abs3) (((Abs2 ---> Rep3) f) o ((Abs1 ---> Rep2) g))" |
|
293 using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] Quotient_abs_rep[OF q3] |
|
294 unfolding o_def expand_fun_eq |
|
295 by simp |
|
296 |
|
297 lemma o_RSP: |
|
298 assumes q1: "Quotient R1 Abs1 Rep1" |
|
299 and q2: "Quotient R2 Abs2 Rep2" |
|
300 and q3: "Quotient R3 Abs3 Rep3" |
|
301 and a1: "(R2 ===> R3) f1 f2" |
|
302 and a2: "(R1 ===> R2) g1 g2" |
|
303 shows "(R1 ===> R3) (f1 o g1) (f2 o g2)" |
|
304 using a1 a2 unfolding o_def expand_fun_eq |
|
305 by (auto) |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 lemma COND_PRS: |
|
312 assumes a: "Quotient R absf repf" |
|
313 shows "(if a then b else c) = absf (if a then repf b else repf c)" |
|
314 using a unfolding Quotient_def by auto |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
217 |
320 (* Set of lemmas for regularisation of ball and bex *) |
218 (* Set of lemmas for regularisation of ball and bex *) |
|
219 |
321 lemma ball_reg_eqv: |
220 lemma ball_reg_eqv: |
322 fixes P :: "'a \<Rightarrow> bool" |
221 fixes P :: "'a \<Rightarrow> bool" |
323 assumes a: "equivp R" |
222 assumes a: "equivp R" |
324 shows "Ball (Respects R) P = (All P)" |
223 shows "Ball (Respects R) P = (All P)" |
325 by (metis equivp_def in_respects a) |
224 by (metis equivp_def in_respects a) |
551 and a: "R x1 x2" |
456 and a: "R x1 x2" |
552 shows "R x1 (Rep (Abs x2))" |
457 shows "R x1 (Rep (Abs x2))" |
553 using q a by (metis Quotient_rel[OF q] Quotient_abs_rep[OF q] Quotient_rep_reflp[OF q]) |
458 using q a by (metis Quotient_rel[OF q] Quotient_abs_rep[OF q] Quotient_rep_reflp[OF q]) |
554 |
459 |
555 |
460 |
|
461 |
|
462 (* bool theory: COND, LET *) |
|
463 lemma IF_PRS: |
|
464 assumes q: "Quotient R Abs Rep" |
|
465 shows "If a b c = Abs (If a (Rep b) (Rep c))" |
|
466 using Quotient_abs_rep[OF q] by auto |
|
467 |
|
468 (* ask peter: no use of q *) |
|
469 lemma IF_RSP: |
|
470 assumes q: "Quotient R Abs Rep" |
|
471 and a: "a1 = a2" "R b1 b2" "R c1 c2" |
|
472 shows "R (If a1 b1 c1) (If a2 b2 c2)" |
|
473 using a by auto |
|
474 |
|
475 lemma LET_PRS: |
|
476 assumes q1: "Quotient R1 Abs1 Rep1" |
|
477 and q2: "Quotient R2 Abs2 Rep2" |
|
478 shows "Let x f = Abs2 (Let (Rep1 x) ((Abs1 ---> Rep2) f))" |
|
479 using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] by auto |
|
480 |
|
481 lemma LET_RSP: |
|
482 assumes q1: "Quotient R1 Abs1 Rep1" |
|
483 and a1: "(R1 ===> R2) f g" |
|
484 and a2: "R1 x y" |
|
485 shows "R2 ((Let x f)::'c) ((Let y g)::'c)" |
|
486 using apply_rsp[OF q1 a1] a2 |
|
487 by auto |
|
488 |
|
489 |
|
490 |
|
491 (* ask peter what are literal_case *) |
|
492 (* literal_case_PRS *) |
|
493 (* literal_case_RSP *) |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 (* combinators: I, K, o, C, W *) |
|
500 |
|
501 (* We use id_simps which includes id_apply; so these 2 theorems can be removed *) |
|
502 |
|
503 lemma I_PRS: |
|
504 assumes q: "Quotient R Abs Rep" |
|
505 shows "id e = Abs (id (Rep e))" |
|
506 using Quotient_abs_rep[OF q] by auto |
|
507 |
|
508 lemma I_RSP: |
|
509 assumes q: "Quotient R Abs Rep" |
|
510 and a: "R e1 e2" |
|
511 shows "R (id e1) (id e2)" |
|
512 using a by auto |
|
513 |
|
514 lemma o_PRS: |
|
515 assumes q1: "Quotient R1 Abs1 Rep1" |
|
516 and q2: "Quotient R2 Abs2 Rep2" |
|
517 and q3: "Quotient R3 Abs3 Rep3" |
|
518 shows "f o g = (Rep1 ---> Abs3) (((Abs2 ---> Rep3) f) o ((Abs1 ---> Rep2) g))" |
|
519 using Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2] Quotient_abs_rep[OF q3] |
|
520 unfolding o_def expand_fun_eq |
|
521 by simp |
|
522 |
|
523 lemma o_RSP: |
|
524 assumes q1: "Quotient R1 Abs1 Rep1" |
|
525 and q2: "Quotient R2 Abs2 Rep2" |
|
526 and q3: "Quotient R3 Abs3 Rep3" |
|
527 and a1: "(R2 ===> R3) f1 f2" |
|
528 and a2: "(R1 ===> R2) g1 g2" |
|
529 shows "(R1 ===> R3) (f1 o g1) (f2 o g2)" |
|
530 using a1 a2 unfolding o_def expand_fun_eq |
|
531 by (auto) |
|
532 |
|
533 lemma COND_PRS: |
|
534 assumes a: "Quotient R absf repf" |
|
535 shows "(if a then b else c) = absf (if a then repf b else repf c)" |
|
536 using a unfolding Quotient_def by auto |
|
537 |
|
538 |
556 end |
539 end |
557 |
540 |