QuotMain.thy
changeset 330 1a0f0b758071
parent 326 e755a5da14c8
child 334 5a7024be9083
equal deleted inserted replaced
329:5d06e1dba69a 330:1a0f0b758071
  1204 (* version with explicit qtrm             *)
  1204 (* version with explicit qtrm             *)
  1205 (******************************************)
  1205 (******************************************)
  1206 (******************************************)
  1206 (******************************************)
  1207 
  1207 
  1208 ML {*
  1208 ML {*
       
  1209 (* builds the relation for respects *)
       
  1210  
  1209 fun mk_resp_arg lthy (rty, qty) =
  1211 fun mk_resp_arg lthy (rty, qty) =
  1210 let
  1212 let
  1211   val thy = ProofContext.theory_of lthy
  1213   val thy = ProofContext.theory_of lthy
  1212 in  
  1214 in  
  1213   case (rty, qty) of
  1215   case (rty, qty) of
  1219             in
  1221             in
  1220               list_comb (Const (#relfun map_info, dummyT), args) 
  1222               list_comb (Const (#relfun map_info, dummyT), args) 
  1221             end  
  1223             end  
  1222        else let  
  1224        else let  
  1223               val SOME qinfo = quotdata_lookup_thy thy s'
  1225               val SOME qinfo = quotdata_lookup_thy thy s'
       
  1226               (* FIXME: check in this case that the rty and qty *)
       
  1227               (* FIXME: correspond to each other *)
  1224             in
  1228             in
  1225               #rel qinfo
  1229               #rel qinfo
  1226             end
  1230             end
  1227     | _ => HOLogic.eq_const dummyT
  1231     | _ => HOLogic.eq_const dummyT 
       
  1232            (* FIXME: do the types correspond to each other? *)
  1228 end
  1233 end
  1229 *}
  1234 *}
  1230 
  1235 
  1231 ML {*
  1236 ML {*
  1232 val mk_babs = Const (@{const_name "Babs"}, dummyT)
  1237 val mk_babs = Const (@{const_name "Babs"}, dummyT)
  1245   raise LIFT_MATCH (space_implode " " msg)
  1250   raise LIFT_MATCH (space_implode " " msg)
  1246 end 
  1251 end 
  1247 *}
  1252 *}
  1248 
  1253 
  1249 ML {*
  1254 ML {*
  1250 (* applies f to the subterm of an abstractions, otherwise to the given term *)
  1255 (* - applies f to the subterm of an abstraction,   *)
  1251 (* abstracted variables do not have to be treated specially *)
  1256 (*   otherwise to the given term,                  *)
       
  1257 (* - used by REGUKARIZE, therefore abstracted      *)
       
  1258 (*   variables do not have to be treated specially *)
       
  1259 
  1252 fun apply_subt f trm1 trm2 =
  1260 fun apply_subt f trm1 trm2 =
  1253   case (trm1, trm2) of
  1261   case (trm1, trm2) of
  1254     (Abs (x, T, t), Abs (x', T', t')) => Abs (x, T, f t t')
  1262     (Abs (x, T, t), Abs (x', T', t')) => Abs (x, T, f t t')
  1255   | _ => f trm1 trm2
  1263   | _ => f trm1 trm2
  1256 
  1264 
       
  1265 (* the major type of All and Ex quantifiers *)
  1257 fun qnt_typ ty = domain_type (domain_type ty)
  1266 fun qnt_typ ty = domain_type (domain_type ty)
  1258 *}
  1267 *}
  1259 
  1268 
  1260 (*
  1269 (*
  1261 Regularizing an rterm means:
  1270 Regularizing an rtrm means:
  1262  - Quantifiers over a type that needs lifting are replaced by
  1271  - quantifiers over a type that needs lifting are replaced by
  1263    bounded quantifiers, for example:
  1272    bounded quantifiers, for example:
  1264       \<forall>x. P     \<Longrightarrow>     \<forall>x\<in>(Respects R). P
  1273       \<forall>x. P     \<Longrightarrow>     \<forall>x \<in> (Respects R). P  /  All (Respects R) P
  1265  - Abstractions over a type that needs lifting are replaced
  1274 
       
  1275    the relation R is given by the rty and qty;
       
  1276  
       
  1277  - abstractions over a type that needs lifting are replaced
  1266    by bounded abstractions:
  1278    by bounded abstractions:
  1267       \<lambda>x. P     \<Longrightarrow>     Ball (Respects R) (\<lambda>x. P)
  1279       \<lambda>x. P     \<Longrightarrow>     Ball (Respects R) (\<lambda>x. P)
  1268 
  1280 
  1269  - Equalities over the type being lifted are replaced by
  1281  - equalities over the type being lifted are replaced by
  1270    appropriate relations:
  1282    corresponding relations:
  1271       A = B     \<Longrightarrow>     A \<approx> B
  1283       A = B     \<Longrightarrow>     A \<approx> B
  1272    Example with more complicated types of A, B:
  1284 
       
  1285    example with more complicated types of A, B:
  1273       A = B     \<Longrightarrow>     (op = \<Longrightarrow> op \<approx>) A B
  1286       A = B     \<Longrightarrow>     (op = \<Longrightarrow> op \<approx>) A B
  1274 *)
  1287 *)
  1275 
  1288 
  1276 ML {*
  1289 ML {*
       
  1290 (* produces a regularized version of rtm      *)
       
  1291 (* - the result is still not completely typed *)
       
  1292 (* - does not need any special treatment of   *)
       
  1293 (*   bound variables                          *)
       
  1294 
  1277 fun REGULARIZE_trm lthy rtrm qtrm =
  1295 fun REGULARIZE_trm lthy rtrm qtrm =
  1278   case (rtrm, qtrm) of
  1296   case (rtrm, qtrm) of
  1279     (Abs (x, ty, t), Abs (x', ty', t')) =>
  1297     (Abs (x, ty, t), Abs (x', ty', t')) =>
  1280        let
  1298        let
  1281          val subtrm = REGULARIZE_trm lthy t t'
  1299          val subtrm = REGULARIZE_trm lthy t t'
  1311        end 
  1329        end 
  1312   | (t1 $ t2, t1' $ t2') =>
  1330   | (t1 $ t2, t1' $ t2') =>
  1313        (REGULARIZE_trm lthy t1 t1') $ (REGULARIZE_trm lthy t2 t2')
  1331        (REGULARIZE_trm lthy t1 t1') $ (REGULARIZE_trm lthy t2 t2')
  1314   | (Free (x, ty), Free (x', ty')) =>
  1332   | (Free (x, ty), Free (x', ty')) =>
  1315        if x = x' 
  1333        if x = x' 
  1316        then rtrm 
  1334        then rtrm     (* FIXME: check whether types corresponds *)
  1317        else trm_lift_error lthy rtrm qtrm
  1335        else trm_lift_error lthy rtrm qtrm
  1318   | (Bound i, Bound i') =>
  1336   | (Bound i, Bound i') =>
  1319        if i = i' 
  1337        if i = i' 
  1320        then rtrm 
  1338        then rtrm 
  1321        else trm_lift_error lthy rtrm qtrm
  1339        else trm_lift_error lthy rtrm qtrm
  1326   | _ => trm_lift_error lthy rtrm qtrm
  1344   | _ => trm_lift_error lthy rtrm qtrm
  1327 *}
  1345 *}
  1328 
  1346 
  1329 ML {*
  1347 ML {*
  1330 fun mk_REGULARIZE_goal lthy rtrm qtrm =
  1348 fun mk_REGULARIZE_goal lthy rtrm qtrm =
  1331       Logic.mk_implies (rtrm, REGULARIZE_trm lthy rtrm qtrm |> Syntax.check_term lthy)
  1349   Logic.mk_implies (rtrm, Syntax.check_term lthy (REGULARIZE_trm lthy rtrm qtrm))
  1332 *}
  1350 *}
  1333 
  1351 
  1334 (*
  1352 (*
  1335 To prove that the old theorem implies the new one, we first
  1353 To prove that the old theorem implies the new one, we first
  1336 atomize it and then try:
  1354 atomize it and then try:
       
  1355 
  1337  - Reflexivity of the relation
  1356  - Reflexivity of the relation
  1338  - Assumption
  1357  - Assumption
  1339  - Elimnating quantifiers on both sides of toplevel implication
  1358  - Elimnating quantifiers on both sides of toplevel implication
  1340  - Simplifying implications on both sides of toplevel implication
  1359  - Simplifying implications on both sides of toplevel implication
  1341  - Ball (Respects ?E) ?P = All ?P
  1360  - Ball (Respects ?E) ?P = All ?P
  1360 apply(rule a)
  1379 apply(rule a)
  1361 apply(rule b)
  1380 apply(rule b)
  1362 done
  1381 done
  1363 
  1382 
  1364 ML {*
  1383 ML {*
       
  1384 (* FIXME: get_rid of rel_refl rel_eqv *)
  1365 fun REGULARIZE_tac lthy rel_refl rel_eqv =
  1385 fun REGULARIZE_tac lthy rel_refl rel_eqv =
  1366    (REPEAT1 o FIRST1) 
  1386    (REPEAT1 o FIRST1) 
  1367      [rtac rel_refl,
  1387      [rtac rel_refl,
  1368       atac,
  1388       atac,
  1369       rtac @{thm universal_twice},
  1389       rtac @{thm universal_twice},
  1374       (* For a = b \<longrightarrow> a \<approx> b *)
  1394       (* For a = b \<longrightarrow> a \<approx> b *)
  1375       rtac @{thm impI} THEN' (asm_full_simp_tac HOL_ss) THEN' rtac rel_refl,
  1395       rtac @{thm impI} THEN' (asm_full_simp_tac HOL_ss) THEN' rtac rel_refl,
  1376       rtac @{thm RIGHT_RES_FORALL_REGULAR}]
  1396       rtac @{thm RIGHT_RES_FORALL_REGULAR}]
  1377 *}
  1397 *}
  1378 
  1398 
  1379 (* same version including debugging information *)
  1399 (* version of REGULARIZE_tac including debugging information *)
  1380 ML {*
  1400 ML {*
  1381 fun my_print_tac ctxt s thm =
  1401 fun my_print_tac ctxt s thm =
  1382 let
  1402 let
  1383   val prems_str = prems_of thm
  1403   val prems_str = prems_of thm
  1384                   |> map (Syntax.string_of_term ctxt)
  1404                   |> map (Syntax.string_of_term ctxt)
  1390  
  1410  
  1391 fun DT ctxt s tac = EVERY' [tac, K (my_print_tac ctxt ("after " ^ s))]
  1411 fun DT ctxt s tac = EVERY' [tac, K (my_print_tac ctxt ("after " ^ s))]
  1392 *}
  1412 *}
  1393 
  1413 
  1394 ML {*
  1414 ML {*
  1395 (* FIXME: change rel_refl rel_eqv *)
       
  1396 fun REGULARIZE_tac' lthy rel_refl rel_eqv =
  1415 fun REGULARIZE_tac' lthy rel_refl rel_eqv =
  1397    (REPEAT1 o FIRST1) 
  1416    (REPEAT1 o FIRST1) 
  1398      [(K (print_tac "start")) THEN' (K no_tac), 
  1417      [(K (print_tac "start")) THEN' (K no_tac), 
  1399       DT lthy "1" (rtac rel_refl),
  1418       DT lthy "1" (rtac rel_refl),
  1400       DT lthy "2" atac,
  1419       DT lthy "2" atac,
  1410 
  1429 
  1411 ML {*
  1430 ML {*
  1412 fun REGULARIZE_prove rtrm qtrm rel_eqv rel_refl lthy =
  1431 fun REGULARIZE_prove rtrm qtrm rel_eqv rel_refl lthy =
  1413   let
  1432   let
  1414     val goal = mk_REGULARIZE_goal lthy rtrm qtrm
  1433     val goal = mk_REGULARIZE_goal lthy rtrm qtrm
  1415     val cthm = Goal.prove lthy [] [] goal 
  1434   in
       
  1435     Goal.prove lthy [] [] goal 
  1416       (fn {context, ...} => REGULARIZE_tac' context rel_refl rel_eqv)
  1436       (fn {context, ...} => REGULARIZE_tac' context rel_refl rel_eqv)
  1417   in
       
  1418     cthm 
       
  1419   end
  1437   end
  1420 *}
  1438 *}
  1421 
  1439 
  1422 
  1440 
  1423 end
  1441 end