7 |
7 |
8 locale QUOT_TYPE = |
8 locale QUOT_TYPE = |
9 fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool" |
9 fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool" |
10 and Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b" |
10 and Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b" |
11 and Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)" |
11 and Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)" |
12 assumes equiv: "EQUIV R" |
12 assumes equiv: "equivp R" |
13 and rep_prop: "\<And>y. \<exists>x. Rep y = R x" |
13 and rep_prop: "\<And>y. \<exists>x. Rep y = R x" |
14 and rep_inverse: "\<And>x. Abs (Rep x) = x" |
14 and rep_inverse: "\<And>x. Abs (Rep x) = x" |
15 and abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)" |
15 and abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)" |
16 and rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)" |
16 and rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)" |
17 begin |
17 begin |
27 "REP a = Eps (Rep a)" |
27 "REP a = Eps (Rep a)" |
28 |
28 |
29 lemma lem9: |
29 lemma lem9: |
30 shows "R (Eps (R x)) = R x" |
30 shows "R (Eps (R x)) = R x" |
31 proof - |
31 proof - |
32 have a: "R x x" using equiv by (simp add: EQUIV_REFL_SYM_TRANS REFL_def) |
32 have a: "R x x" using equiv by (simp add: equivp_reflp_symp_transp reflp_def) |
33 then have "R x (Eps (R x))" by (rule someI) |
33 then have "R x (Eps (R x))" by (rule someI) |
34 then show "R (Eps (R x)) = R x" |
34 then show "R (Eps (R x)) = R x" |
35 using equiv unfolding EQUIV_def by simp |
35 using equiv unfolding equivp_def by simp |
36 qed |
36 qed |
37 |
37 |
38 theorem thm10: |
38 theorem thm10: |
39 shows "ABS (REP a) \<equiv> a" |
39 shows "ABS (REP a) \<equiv> a" |
40 apply (rule eq_reflection) |
40 apply (rule eq_reflection) |
64 done |
64 done |
65 |
65 |
66 theorem thm11: |
66 theorem thm11: |
67 shows "R r r' = (ABS r = ABS r')" |
67 shows "R r r' = (ABS r = ABS r')" |
68 unfolding ABS_def |
68 unfolding ABS_def |
69 by (simp only: equiv[simplified EQUIV_def] lem7) |
69 by (simp only: equiv[simplified equivp_def] lem7) |
70 |
70 |
71 |
71 |
72 lemma REP_ABS_rsp: |
72 lemma REP_ABS_rsp: |
73 shows "R f (REP (ABS g)) = R f g" |
73 shows "R f (REP (ABS g)) = R f g" |
74 and "R (REP (ABS g)) f = R g f" |
74 and "R (REP (ABS g)) f = R g f" |
75 by (simp_all add: thm10 thm11) |
75 by (simp_all add: thm10 thm11) |
76 |
76 |
77 lemma QUOTIENT: |
77 lemma Quotient: |
78 "QUOTIENT R ABS REP" |
78 "Quotient R ABS REP" |
79 apply(unfold QUOTIENT_def) |
79 apply(unfold Quotient_def) |
80 apply(simp add: thm10) |
80 apply(simp add: thm10) |
81 apply(simp add: REP_refl) |
81 apply(simp add: REP_refl) |
82 apply(subst thm11[symmetric]) |
82 apply(subst thm11[symmetric]) |
83 apply(simp add: equiv[simplified EQUIV_def]) |
83 apply(simp add: equiv[simplified equivp_def]) |
84 done |
84 done |
85 |
85 |
86 lemma R_trans: |
86 lemma R_trans: |
87 assumes ab: "R a b" |
87 assumes ab: "R a b" |
88 and bc: "R b c" |
88 and bc: "R b c" |
89 shows "R a c" |
89 shows "R a c" |
90 proof - |
90 proof - |
91 have tr: "TRANS R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp |
91 have tr: "transp R" using equiv equivp_reflp_symp_transp[of R] by simp |
92 moreover have ab: "R a b" by fact |
92 moreover have ab: "R a b" by fact |
93 moreover have bc: "R b c" by fact |
93 moreover have bc: "R b c" by fact |
94 ultimately show "R a c" unfolding TRANS_def by blast |
94 ultimately show "R a c" unfolding transp_def by blast |
95 qed |
95 qed |
96 |
96 |
97 lemma R_sym: |
97 lemma R_sym: |
98 assumes ab: "R a b" |
98 assumes ab: "R a b" |
99 shows "R b a" |
99 shows "R b a" |
100 proof - |
100 proof - |
101 have re: "SYM R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp |
101 have re: "symp R" using equiv equivp_reflp_symp_transp[of R] by simp |
102 then show "R b a" using ab unfolding SYM_def by blast |
102 then show "R b a" using ab unfolding symp_def by blast |
103 qed |
103 qed |
104 |
104 |
105 lemma R_trans2: |
105 lemma R_trans2: |
106 assumes ac: "R a c" |
106 assumes ac: "R a c" |
107 and bd: "R b d" |
107 and bd: "R b d" |
126 then have "ABS x = ABS y" using thm11 by simp |
126 then have "ABS x = ABS y" using thm11 by simp |
127 then have "Abs (Rep a) = Abs (Rep b)" using eqs unfolding ABS_def by simp |
127 then have "Abs (Rep a) = Abs (Rep b)" using eqs unfolding ABS_def by simp |
128 then show "a = b" using rep_inverse by simp |
128 then show "a = b" using rep_inverse by simp |
129 next |
129 next |
130 assume ab: "a = b" |
130 assume ab: "a = b" |
131 have "REFL R" using equiv EQUIV_REFL_SYM_TRANS[of R] by simp |
131 have "reflp R" using equiv equivp_reflp_symp_transp[of R] by simp |
132 then show "R (REP a) (REP b)" unfolding REFL_def using ab by auto |
132 then show "R (REP a) (REP b)" unfolding reflp_def using ab by auto |
133 qed |
133 qed |
134 then show "R (REP a) (REP b) \<equiv> (a = b)" by simp |
134 then show "R (REP a) (REP b) \<equiv> (a = b)" by simp |
135 qed |
135 qed |
136 |
136 |
137 end |
137 end |
144 declare [[map list = (map, LIST_REL)]] |
144 declare [[map list = (map, LIST_REL)]] |
145 declare [[map * = (prod_fun, prod_rel)]] |
145 declare [[map * = (prod_fun, prod_rel)]] |
146 declare [[map "fun" = (fun_map, FUN_REL)]] |
146 declare [[map "fun" = (fun_map, FUN_REL)]] |
147 |
147 |
148 lemmas [quotient_thm] = |
148 lemmas [quotient_thm] = |
149 FUN_QUOTIENT LIST_QUOTIENT |
149 FUN_Quotient LIST_Quotient |
150 |
150 |
151 ML {* maps_lookup @{theory} "List.list" *} |
151 ML {* maps_lookup @{theory} "List.list" *} |
152 ML {* maps_lookup @{theory} "*" *} |
152 ML {* maps_lookup @{theory} "*" *} |
153 ML {* maps_lookup @{theory} "fun" *} |
153 ML {* maps_lookup @{theory} "fun" *} |
154 |
154 |
263 (* cu: Changed the lookup\<dots>not sure whether this works *) |
263 (* cu: Changed the lookup\<dots>not sure whether this works *) |
264 (* TODO: Should no longer be needed *) |
264 (* TODO: Should no longer be needed *) |
265 val rty = Logic.unvarifyT (#rtyp quotdata) |
265 val rty = Logic.unvarifyT (#rtyp quotdata) |
266 val rel = #rel quotdata |
266 val rel = #rel quotdata |
267 val rel_eqv = #equiv_thm quotdata |
267 val rel_eqv = #equiv_thm quotdata |
268 val rel_refl = @{thm EQUIV_REFL} OF [rel_eqv] |
268 val rel_refl = @{thm equivp_reflp} OF [rel_eqv] |
269 in |
269 in |
270 (rty, rel, rel_refl, rel_eqv) |
270 (rty, rel, rel_refl, rel_eqv) |
271 end |
271 end |
272 *} |
272 *} |
273 |
273 |
276 let |
276 let |
277 val thy = ProofContext.theory_of lthy; |
277 val thy = ProofContext.theory_of lthy; |
278 val trans2 = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".R_trans2") |
278 val trans2 = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".R_trans2") |
279 val reps_same = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".REPS_same") |
279 val reps_same = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".REPS_same") |
280 val absrep = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".thm10") |
280 val absrep = PureThy.get_thm thy ("QUOT_TYPE_I_" ^ qty_name ^ ".thm10") |
281 val quot = PureThy.get_thm thy ("QUOTIENT_" ^ qty_name) |
281 val quot = PureThy.get_thm thy ("Quotient_" ^ qty_name) |
282 in |
282 in |
283 (trans2, reps_same, absrep, quot) |
283 (trans2, reps_same, absrep, quot) |
284 end |
284 end |
285 *} |
285 *} |
286 |
286 |
453 by blast |
453 by blast |
454 |
454 |
455 lemma [mono]: "P \<longrightarrow> Q \<Longrightarrow> \<not>Q \<longrightarrow> \<not>P" |
455 lemma [mono]: "P \<longrightarrow> Q \<Longrightarrow> \<not>Q \<longrightarrow> \<not>P" |
456 by auto |
456 by auto |
457 |
457 |
458 (* FIXME: OPTION_EQUIV, PAIR_EQUIV, ... *) |
458 (* FIXME: OPTION_equivp, PAIR_equivp, ... *) |
459 ML {* |
459 ML {* |
460 fun equiv_tac rel_eqvs = |
460 fun equiv_tac rel_eqvs = |
461 REPEAT_ALL_NEW (FIRST' |
461 REPEAT_ALL_NEW (FIRST' |
462 [resolve_tac rel_eqvs, |
462 [resolve_tac rel_eqvs, |
463 rtac @{thm IDENTITY_EQUIV}, |
463 rtac @{thm IDENTITY_equivp}, |
464 rtac @{thm LIST_EQUIV}]) |
464 rtac @{thm LIST_equivp}]) |
465 *} |
465 *} |
466 |
466 |
467 ML {* |
467 ML {* |
468 fun ball_reg_eqv_simproc rel_eqvs ss redex = |
468 fun ball_reg_eqv_simproc rel_eqvs ss redex = |
469 let |
469 let |
472 in |
472 in |
473 case redex of |
473 case redex of |
474 (ogl as ((Const (@{const_name "Ball"}, _)) $ |
474 (ogl as ((Const (@{const_name "Ball"}, _)) $ |
475 ((Const (@{const_name "Respects"}, _)) $ R) $ P1)) => |
475 ((Const (@{const_name "Respects"}, _)) $ R) $ P1)) => |
476 (let |
476 (let |
477 val gl = Const (@{const_name "EQUIV"}, dummyT) $ R; |
477 val gl = Const (@{const_name "equivp"}, dummyT) $ R; |
478 val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl); |
478 val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl); |
479 val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1); |
479 val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1); |
480 val thm = (@{thm eq_reflection} OF [@{thm ball_reg_eqv} OF [eqv]]); |
480 val thm = (@{thm eq_reflection} OF [@{thm ball_reg_eqv} OF [eqv]]); |
481 (* val _ = tracing (Syntax.string_of_term ctxt (prop_of thm)); *) |
481 (* val _ = tracing (Syntax.string_of_term ctxt (prop_of thm)); *) |
482 in |
482 in |
496 in |
496 in |
497 case redex of |
497 case redex of |
498 (ogl as ((Const (@{const_name "Bex"}, _)) $ |
498 (ogl as ((Const (@{const_name "Bex"}, _)) $ |
499 ((Const (@{const_name "Respects"}, _)) $ R) $ P1)) => |
499 ((Const (@{const_name "Respects"}, _)) $ R) $ P1)) => |
500 (let |
500 (let |
501 val gl = Const (@{const_name "EQUIV"}, dummyT) $ R; |
501 val gl = Const (@{const_name "equivp"}, dummyT) $ R; |
502 val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl); |
502 val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl); |
503 val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1); |
503 val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1); |
504 val thm = (@{thm eq_reflection} OF [@{thm bex_reg_eqv} OF [eqv]]); |
504 val thm = (@{thm eq_reflection} OF [@{thm bex_reg_eqv} OF [eqv]]); |
505 (* val _ = tracing (Syntax.string_of_term ctxt (prop_of thm)); *) |
505 (* val _ = tracing (Syntax.string_of_term ctxt (prop_of thm)); *) |
506 in |
506 in |
540 in |
540 in |
541 case redex of |
541 case redex of |
542 (ogl as ((Const (@{const_name "Ball"}, _)) $ |
542 (ogl as ((Const (@{const_name "Ball"}, _)) $ |
543 ((Const (@{const_name "Respects"}, _)) $ ((Const (@{const_name "FUN_REL"}, _)) $ R1 $ R2)) $ _)) => |
543 ((Const (@{const_name "Respects"}, _)) $ ((Const (@{const_name "FUN_REL"}, _)) $ R1 $ R2)) $ _)) => |
544 (let |
544 (let |
545 val gl = Const (@{const_name "EQUIV"}, dummyT) $ R2; |
545 val gl = Const (@{const_name "equivp"}, dummyT) $ R2; |
546 val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl); |
546 val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl); |
547 (* val _ = tracing (Syntax.string_of_term ctxt glc);*) |
547 (* val _ = tracing (Syntax.string_of_term ctxt glc);*) |
548 val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1); |
548 val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1); |
549 val thm = (@{thm eq_reflection} OF [@{thm ball_reg_eqv_range} OF [eqv]]); |
549 val thm = (@{thm eq_reflection} OF [@{thm ball_reg_eqv_range} OF [eqv]]); |
550 val R1c = cterm_of thy R1; |
550 val R1c = cterm_of thy R1; |
571 in |
571 in |
572 case redex of |
572 case redex of |
573 (ogl as ((Const (@{const_name "Bex"}, _)) $ |
573 (ogl as ((Const (@{const_name "Bex"}, _)) $ |
574 ((Const (@{const_name "Respects"}, _)) $ ((Const (@{const_name "FUN_REL"}, _)) $ R1 $ R2)) $ _)) => |
574 ((Const (@{const_name "Respects"}, _)) $ ((Const (@{const_name "FUN_REL"}, _)) $ R1 $ R2)) $ _)) => |
575 (let |
575 (let |
576 val gl = Const (@{const_name "EQUIV"}, dummyT) $ R2; |
576 val gl = Const (@{const_name "equivp"}, dummyT) $ R2; |
577 val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl); |
577 val glc = HOLogic.mk_Trueprop (Syntax.check_term ctxt gl); |
578 (* val _ = tracing (Syntax.string_of_term ctxt glc); *) |
578 (* val _ = tracing (Syntax.string_of_term ctxt glc); *) |
579 val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1); |
579 val eqv = Goal.prove ctxt [] [] glc (fn _ => equiv_tac rel_eqvs 1); |
580 val thm = (@{thm eq_reflection} OF [@{thm bex_reg_eqv_range} OF [eqv]]); |
580 val thm = (@{thm eq_reflection} OF [@{thm bex_reg_eqv_range} OF [eqv]]); |
581 val R1c = cterm_of thy R1; |
581 val R1c = cterm_of thy R1; |
722 *} |
722 *} |
723 |
723 |
724 ML {* |
724 ML {* |
725 fun quotient_tac ctxt = |
725 fun quotient_tac ctxt = |
726 REPEAT_ALL_NEW (FIRST' |
726 REPEAT_ALL_NEW (FIRST' |
727 [rtac @{thm IDENTITY_QUOTIENT}, |
727 [rtac @{thm IDENTITY_Quotient}, |
728 resolve_tac (quotient_rules_get ctxt)]) |
728 resolve_tac (quotient_rules_get ctxt)]) |
729 *} |
729 *} |
730 |
730 |
731 lemma FUN_REL_I: |
731 lemma FUN_REL_I: |
732 assumes a: "\<And>x y. R1 x y \<Longrightarrow> R2 (f x) (g y)" |
732 assumes a: "\<And>x y. R1 x y \<Longrightarrow> R2 (f x) (g y)" |
774 SOME (_ $ (_ $ (f $ a))) => (f, a) |
774 SOME (_ $ (_ $ (f $ a))) => (f, a) |
775 | _ => error "find_qt_asm" |
775 | _ => error "find_qt_asm" |
776 end |
776 end |
777 *} |
777 *} |
778 |
778 |
779 (* It proves the QUOTIENT assumptions by calling quotient_tac *) |
779 (* It proves the Quotient assumptions by calling quotient_tac *) |
780 ML {* |
780 ML {* |
781 fun solve_quotient_assum i ctxt thm = |
781 fun solve_quotient_assum i ctxt thm = |
782 let |
782 let |
783 val tac = |
783 val tac = |
784 (compose_tac (false, thm, i)) THEN_ALL_NEW |
784 (compose_tac (false, thm, i)) THEN_ALL_NEW |
1105 fun clean_tac lthy = |
1105 fun clean_tac lthy = |
1106 let |
1106 let |
1107 val thy = ProofContext.theory_of lthy; |
1107 val thy = ProofContext.theory_of lthy; |
1108 val quotients = quotient_rules_get lthy |
1108 val quotients = quotient_rules_get lthy |
1109 val defs = map (Thm.varifyT o #def) (qconsts_dest thy); |
1109 val defs = map (Thm.varifyT o #def) (qconsts_dest thy); |
1110 val absrep = map (fn x => @{thm QUOTIENT_ABS_REP} OF [x]) quotients |
1110 val absrep = map (fn x => @{thm Quotient_ABS_REP} OF [x]) quotients |
1111 val meta_absrep = map (fn x => @{thm eq_reflection} OF [x]) absrep; |
1111 val meta_absrep = map (fn x => @{thm eq_reflection} OF [x]) absrep; |
1112 val reps_same = map (fn x => @{thm QUOTIENT_REL_REP} OF [x]) quotients |
1112 val reps_same = map (fn x => @{thm Quotient_REL_REP} OF [x]) quotients |
1113 val meta_reps_same = map (fn x => @{thm eq_reflection} OF [x]) reps_same |
1113 val meta_reps_same = map (fn x => @{thm eq_reflection} OF [x]) reps_same |
1114 val simp_ctxt = (Simplifier.context lthy empty_ss) addsimps |
1114 val simp_ctxt = (Simplifier.context lthy empty_ss) addsimps |
1115 (@{thm eq_reflection[OF fun_map.simps]} :: @{thms id_simps} @ meta_absrep @ meta_reps_same @ defs) |
1115 (@{thm eq_reflection[OF fun_map.simps]} :: @{thms id_simps} @ meta_absrep @ meta_reps_same @ defs) |
1116 in |
1116 in |
1117 EVERY' [ |
1117 EVERY' [ |
1235 THEN' gen_frees_tac lthy |
1235 THEN' gen_frees_tac lthy |
1236 THEN' Subgoal.FOCUS (fn {context, concl, ...} => |
1236 THEN' Subgoal.FOCUS (fn {context, concl, ...} => |
1237 let |
1237 let |
1238 val rthm' = atomize_thm rthm |
1238 val rthm' = atomize_thm rthm |
1239 val rule = procedure_inst context (prop_of rthm') (term_of concl) |
1239 val rule = procedure_inst context (prop_of rthm') (term_of concl) |
1240 val rel_refl = map (fn x => @{thm EQUIV_REFL} OF [x]) rel_eqv |
1240 val rel_refl = map (fn x => @{thm equivp_reflp} OF [x]) rel_eqv |
1241 val quotients = quotient_rules_get lthy |
1241 val quotients = quotient_rules_get lthy |
1242 val trans2 = map (fn x => @{thm equals_rsp} OF [x]) quotients |
1242 val trans2 = map (fn x => @{thm equals_rsp} OF [x]) quotients |
1243 val thm = Drule.instantiate' [] [SOME (snd (Thm.dest_comb concl))] @{thm QUOT_TRUE_i} |
1243 val thm = Drule.instantiate' [] [SOME (snd (Thm.dest_comb concl))] @{thm QUOT_TRUE_i} |
1244 in |
1244 in |
1245 EVERY1 |
1245 EVERY1 |