1083 | Bound j => if i = j then error "make_inst" else t |
1076 | Bound j => if i = j then error "make_inst" else t |
1084 | _ => t); |
1077 | _ => t); |
1085 in (f, Abs ("x", T, mk_abs 0 g)) end; |
1078 in (f, Abs ("x", T, mk_abs 0 g)) end; |
1086 *} |
1079 *} |
1087 |
1080 |
1088 ML {* |
1081 (* It proves the QUOTIENT assumptions by calling quotient_tac *) |
1089 fun lambda_prs_simple_conv quot_thms ctxt ctrm = |
1082 ML {* |
1090 case (term_of ctrm) of ((Const (@{const_name "fun_map"}, _) $ r1 $ a2) $ (Abs _)) => |
1083 fun solve_quotient_assum i quot_thms ctxt thm = |
|
1084 let |
|
1085 val tac = |
|
1086 (compose_tac (false, thm, i)) THEN_ALL_NEW |
|
1087 (quotient_tac ctxt quot_thms); |
|
1088 val gc = Drule.strip_imp_concl (cprop_of thm); |
|
1089 in |
|
1090 Goal.prove_internal [] gc (fn _ => tac 1) |
|
1091 end |
|
1092 handle _ => error "solve_quotient_assum" |
|
1093 *} |
|
1094 |
|
1095 ML {* |
|
1096 fun lambda_allex_prs_simple_conv quot_thms ctxt ctrm = |
|
1097 case (term_of ctrm) of |
|
1098 ((Const (@{const_name fun_map}, _) $ r1 $ a2) $ (Abs _)) => |
1091 let |
1099 let |
1092 val (_, [ty_b, ty_a]) = dest_Type (fastype_of r1); |
1100 val (_, [ty_b, ty_a]) = dest_Type (fastype_of r1); |
1093 val (_, [ty_c, ty_d]) = dest_Type (fastype_of a2); |
1101 val (_, [ty_c, ty_d]) = dest_Type (fastype_of a2); |
1094 val thy = ProofContext.theory_of ctxt; |
1102 val thy = ProofContext.theory_of ctxt; |
1095 val [cty_a, cty_b, cty_c, cty_d] = map (ctyp_of thy) [ty_a, ty_b, ty_c, ty_d] |
1103 val [cty_a, cty_b, cty_c, cty_d] = map (ctyp_of thy) [ty_a, ty_b, ty_c, ty_d] |
1096 val tyinst = [SOME cty_a, SOME cty_b, SOME cty_c, SOME cty_d]; |
1104 val tyinst = [SOME cty_a, SOME cty_b, SOME cty_c, SOME cty_d]; |
1097 val tinst = [NONE, NONE, SOME (cterm_of thy r1), NONE, SOME (cterm_of thy a2)] |
1105 val tinst = [NONE, NONE, SOME (cterm_of thy r1), NONE, SOME (cterm_of thy a2)] |
1098 val lpi = Drule.instantiate' tyinst tinst @{thm LAMBDA_PRS}; |
1106 val lpi = Drule.instantiate' tyinst tinst @{thm LAMBDA_PRS}; |
1099 val tac = |
1107 val te = @{thm eq_reflection} OF [solve_quotient_assum 2 quot_thms ctxt lpi] |
1100 (compose_tac (false, lpi, 2)) THEN_ALL_NEW |
|
1101 (quotient_tac ctxt quot_thms); |
|
1102 val gc = Drule.strip_imp_concl (cprop_of lpi); |
|
1103 val t = Goal.prove_internal [] gc (fn _ => tac 1) |
|
1104 val te = @{thm eq_reflection} OF [t] |
|
1105 val ts = MetaSimplifier.rewrite_rule @{thms id_simps} te |
1108 val ts = MetaSimplifier.rewrite_rule @{thms id_simps} te |
1106 val tl = Thm.lhs_of ts; |
1109 val tl = Thm.lhs_of ts; |
1107 val (insp, inst) = make_inst (term_of tl) (term_of ctrm); |
1110 val (insp, inst) = make_inst (term_of tl) (term_of ctrm); |
1108 val ti = Drule.instantiate ([], [(cterm_of thy insp, cterm_of thy inst)]) ts; |
1111 val ti = Drule.instantiate ([], [(cterm_of thy insp, cterm_of thy inst)]) ts; |
1109 (* val _ = writeln (Syntax.string_of_term @{context} (term_of (cprop_of ti)));*) |
1112 in |
|
1113 Conv.rewr_conv ti ctrm |
|
1114 end |
|
1115 | (Const (@{const_name Ball}, _) $ (Const (@{const_name Respects}, _) $ R) $ |
|
1116 (((Const (@{const_name fun_map}, _) $ absf $ (Const (@{const_name id}, _)))) $ f)) => |
|
1117 let |
|
1118 val (_, [ty_a, ty_b]) = dest_Type (fastype_of absf); |
|
1119 val thy = ProofContext.theory_of ctxt; |
|
1120 val (cty_a, cty_b) = (ctyp_of thy ty_a, ctyp_of thy ty_b); |
|
1121 val tyinst = [SOME cty_a, SOME cty_b]; |
|
1122 val tinst = [SOME (cterm_of thy R), SOME (cterm_of thy absf), NONE, SOME (cterm_of thy f)]; |
|
1123 val thm = Drule.instantiate' tyinst tinst @{thm all_prs}; |
|
1124 val ti = @{thm eq_reflection} OF [solve_quotient_assum 1 quot_thms ctxt thm]; |
|
1125 in |
|
1126 Conv.rewr_conv ti ctrm |
|
1127 end |
|
1128 | (Const (@{const_name Bex}, _) $ (Const (@{const_name Respects}, _) $ R) $ |
|
1129 (((Const (@{const_name fun_map}, _) $ absf $ (Const (@{const_name id}, _)))) $ f)) => |
|
1130 let |
|
1131 val (_, [ty_a, ty_b]) = dest_Type (fastype_of absf); |
|
1132 val thy = ProofContext.theory_of ctxt; |
|
1133 val (cty_a, cty_b) = (ctyp_of thy ty_a, ctyp_of thy ty_b); |
|
1134 val tyinst = [SOME cty_a, SOME cty_b]; |
|
1135 val tinst = [SOME (cterm_of thy R), SOME (cterm_of thy absf), NONE, SOME (cterm_of thy f)]; |
|
1136 val thm = Drule.instantiate' tyinst tinst @{thm ex_prs}; |
|
1137 val ti = @{thm eq_reflection} OF [solve_quotient_assum 1 quot_thms ctxt thm]; |
1110 in |
1138 in |
1111 Conv.rewr_conv ti ctrm |
1139 Conv.rewr_conv ti ctrm |
1112 end |
1140 end |
1113 | _ => Conv.all_conv ctrm |
1141 | _ => Conv.all_conv ctrm |
1114 *} |
1142 *} |
1115 |
1143 |
1116 (* quot stands for the QUOTIENT theorems: *) |
1144 (* quot stands for the QUOTIENT theorems: *) |
1117 (* could be potentially all of them *) |
1145 (* could be potentially all of them *) |
1118 ML {* |
1146 ML {* |
1119 fun lambda_prs_conv quot = |
1147 fun lambda_allex_prs_conv quot = |
1120 More_Conv.top_conv (lambda_prs_simple_conv quot) |
1148 More_Conv.top_conv (lambda_allex_prs_simple_conv quot) |
1121 *} |
1149 *} |
1122 |
1150 |
1123 ML {* |
1151 ML {* |
1124 fun lambda_prs_tac quot ctxt = CONVERSION (lambda_prs_conv quot ctxt) |
1152 fun lambda_allex_prs_tac quot ctxt = CONVERSION (lambda_allex_prs_conv quot ctxt) |
1125 *} |
1153 *} |
1126 |
1154 |
1127 (* |
1155 (* |
1128 Cleaning the theorem consists of 6 kinds of rewrites. |
1156 Cleaning the theorem consists of 6 kinds of rewrites. |
1129 The first two need to be done before fun_map is unfolded |
1157 The first two need to be done before fun_map is unfolded |
1162 val meta_reps_same = map (fn x => @{thm eq_reflection} OF [x]) reps_same |
1187 val meta_reps_same = map (fn x => @{thm eq_reflection} OF [x]) reps_same |
1163 val simp_ctxt = (Simplifier.context lthy empty_ss) addsimps |
1188 val simp_ctxt = (Simplifier.context lthy empty_ss) addsimps |
1164 (@{thm eq_reflection[OF fun_map.simps]} :: @{thms id_simps} @ meta_absrep @ meta_reps_same @ defs) |
1189 (@{thm eq_reflection[OF fun_map.simps]} :: @{thms id_simps} @ meta_absrep @ meta_reps_same @ defs) |
1165 in |
1190 in |
1166 EVERY' [ |
1191 EVERY' [ |
1167 |
|
1168 (* (Rep1 ---> Abs2) (\<lambda>x. Rep2 (f (Abs1 x))) ----> f *) |
1192 (* (Rep1 ---> Abs2) (\<lambda>x. Rep2 (f (Abs1 x))) ----> f *) |
1169 DT lthy "a" (TRY o lambda_prs_tac quot lthy), |
|
1170 |
|
1171 (* \<forall>x\<in>Respects R. (abs ---> id) f ----> \<forall>x. f *) |
1193 (* \<forall>x\<in>Respects R. (abs ---> id) f ----> \<forall>x. f *) |
1172 DT lthy "b" (TRY o REPEAT_ALL_NEW (allex_prs_tac lthy quot)), |
1194 NDT lthy "a" (TRY o lambda_allex_prs_tac quot lthy), |
1173 |
1195 |
1174 (* NewConst ----> (rep ---> abs) oldConst *) |
1196 (* NewConst ----> (rep ---> abs) oldConst *) |
1175 (* Abs (Rep x) ----> x *) |
1197 (* Abs (Rep x) ----> x *) |
1176 (* id_simps; fun_map.simps *) |
1198 (* id_simps; fun_map.simps *) |
1177 DT lthy "c" (TRY o simp_tac simp_ctxt), |
1199 NDT lthy "c" (TRY o simp_tac simp_ctxt), |
1178 |
1200 |
1179 (* final step *) |
1201 (* final step *) |
1180 DT lthy "d" (TRY o rtac refl) |
1202 NDT lthy "d" (TRY o rtac refl) |
1181 ] |
1203 ] |
1182 end |
1204 end |
1183 *} |
1205 *} |
1184 |
1206 |
1185 section {* Genralisation of free variables in a goal *} |
1207 section {* Genralisation of free variables in a goal *} |