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 |
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) |