24 val forall_intr_frees : thm -> thm |
24 val forall_intr_frees : thm -> thm |
25 val forall_intr_vars : thm -> thm |
25 val forall_intr_vars : thm -> thm |
26 val forall_elim_list : cterm list -> thm -> thm |
26 val forall_elim_list : cterm list -> thm -> thm |
27 val forall_elim_var : int -> thm -> thm |
27 val forall_elim_var : int -> thm -> thm |
28 val forall_elim_vars : int -> thm -> thm |
28 val forall_elim_vars : int -> thm -> thm |
|
29 val freeze_thaw : thm -> thm * (thm -> thm) |
29 val implies_elim_list : thm -> thm list -> thm |
30 val implies_elim_list : thm -> thm list -> thm |
30 val implies_intr_list : cterm list -> thm -> thm |
31 val implies_intr_list : cterm list -> thm -> thm |
31 val zero_var_indexes : thm -> thm |
32 val zero_var_indexes : thm -> thm |
32 val standard : thm -> thm |
33 val standard : thm -> thm |
|
34 val rotate_prems : int -> thm -> thm |
33 val assume_ax : theory -> string -> thm |
35 val assume_ax : theory -> string -> thm |
34 val RSN : thm * (int * thm) -> thm |
36 val RSN : thm * (int * thm) -> thm |
35 val RS : thm * thm -> thm |
37 val RS : thm * thm -> thm |
36 val RLN : thm list * (int * thm list) -> thm list |
38 val RLN : thm list * (int * thm list) -> thm list |
37 val RL : thm list * thm list -> thm list |
39 val RL : thm list * thm list -> thm list |
238 |> Thm.strip_shyps |> Thm.implies_intr_shyps |
240 |> Thm.strip_shyps |> Thm.implies_intr_shyps |
239 |> zero_var_indexes |> Thm.varifyT |> Thm.compress |
241 |> zero_var_indexes |> Thm.varifyT |> Thm.compress |
240 end; |
242 end; |
241 |
243 |
242 |
244 |
|
245 (*Convert all Vars in a theorem to Frees. Also return a function for |
|
246 reversing that operation. DOES NOT WORK FOR TYPE VARIABLES. |
|
247 Similar code in type/freeze_thaw*) |
|
248 fun freeze_thaw th = |
|
249 let val fth = freezeT th |
|
250 val {prop,sign,...} = rep_thm fth |
|
251 val used = add_term_names (prop, []) |
|
252 and vars = term_vars prop |
|
253 fun newName (Var(ix,_), (pairs,used)) = |
|
254 let val v = variant used (string_of_indexname ix) |
|
255 in ((ix,v)::pairs, v::used) end; |
|
256 val (alist, _) = foldr newName (vars, ([], used)) |
|
257 fun mk_inst (Var(v,T)) = |
|
258 (cterm_of sign (Var(v,T)), |
|
259 cterm_of sign (Free(the (assoc(alist,v)), T))) |
|
260 val insts = map mk_inst vars |
|
261 fun thaw th' = |
|
262 th' |> forall_intr_list (map #2 insts) |
|
263 |> forall_elim_list (map #1 insts) |
|
264 in (instantiate ([],insts) fth, thaw) end; |
|
265 |
|
266 |
|
267 (*Rotates a rule's premises to the left by k. Does nothing if k=0 or |
|
268 if k equals the number of premises. Useful, for instance, with etac. |
|
269 Similar to tactic/defer_tac*) |
|
270 fun rotate_prems k rl = |
|
271 let val (rl',thaw) = freeze_thaw rl |
|
272 val hyps = strip_imp_prems (adjust_maxidx (cprop_of rl')) |
|
273 val hyps' = List.drop(hyps, k) |
|
274 in implies_elim_list rl' (map assume hyps) |
|
275 |> implies_intr_list (hyps' @ List.take(hyps, k)) |
|
276 |> thaw |> varifyT |
|
277 end; |
|
278 |
|
279 |
243 (*Assume a new formula, read following the same conventions as axioms. |
280 (*Assume a new formula, read following the same conventions as axioms. |
244 Generalizes over Free variables, |
281 Generalizes over Free variables, |
245 creates the assumption, and then strips quantifiers. |
282 creates the assumption, and then strips quantifiers. |
246 Example is [| ALL x:?A. ?P(x) |] ==> [| ?P(?a) |] |
283 Example is [| ALL x:?A. ?P(x) |] ==> [| ?P(?a) |] |
247 [ !(A,P,a)[| ALL x:A. P(x) |] ==> [| P(a) |] ] *) |
284 [ !(A,P,a)[| ALL x:A. P(x) |] ==> [| P(a) |] ] *) |
248 fun assume_ax thy sP = |
285 fun assume_ax thy sP = |
249 let val sign = sign_of thy |
286 let val sign = sign_of thy |
250 val prop = Logic.close_form (term_of (read_cterm sign |
287 val prop = Logic.close_form (term_of (read_cterm sign (sP, propT))) |
251 (sP, propT))) |
|
252 in forall_elim_vars 0 (assume (cterm_of sign prop)) end; |
288 in forall_elim_vars 0 (assume (cterm_of sign prop)) end; |
253 |
289 |
254 (*Resolution: exactly one resolvent must be produced.*) |
290 (*Resolution: exactly one resolvent must be produced.*) |
255 fun tha RSN (i,thb) = |
291 fun tha RSN (i,thb) = |
256 case Seq.chop (2, biresolution false [(false,tha)] i thb) of |
292 case Seq.chop (2, biresolution false [(false,tha)] i thb) of |
360 |
396 |
361 |
397 |
362 |
398 |
363 (*** Meta-Rewriting Rules ***) |
399 (*** Meta-Rewriting Rules ***) |
364 |
400 |
|
401 val proto_sign = sign_of ProtoPure.thy; |
|
402 |
|
403 fun read_prop s = read_cterm proto_sign (s, propT); |
|
404 |
365 fun store_thm name thm = PureThy.smart_store_thm (name, standard thm); |
405 fun store_thm name thm = PureThy.smart_store_thm (name, standard thm); |
366 |
406 |
367 val reflexive_thm = |
407 val reflexive_thm = |
368 let val cx = cterm_of (sign_of ProtoPure.thy) (Var(("x",0),TVar(("'a",0),logicS))) |
408 let val cx = cterm_of proto_sign (Var(("x",0),TVar(("'a",0),logicS))) |
369 in store_thm "reflexive" (Thm.reflexive cx) end; |
409 in store_thm "reflexive" (Thm.reflexive cx) end; |
370 |
410 |
371 val symmetric_thm = |
411 val symmetric_thm = |
372 let val xy = read_cterm (sign_of ProtoPure.thy) ("x::'a::logic == y",propT) |
412 let val xy = read_prop "x::'a::logic == y" |
373 in store_thm "symmetric" (Thm.implies_intr_hyps(Thm.symmetric(Thm.assume xy))) end; |
413 in store_thm "symmetric" |
|
414 (Thm.implies_intr_hyps(Thm.symmetric(Thm.assume xy))) |
|
415 end; |
374 |
416 |
375 val transitive_thm = |
417 val transitive_thm = |
376 let val xy = read_cterm (sign_of ProtoPure.thy) ("x::'a::logic == y",propT) |
418 let val xy = read_prop "x::'a::logic == y" |
377 val yz = read_cterm (sign_of ProtoPure.thy) ("y::'a::logic == z",propT) |
419 val yz = read_prop "y::'a::logic == z" |
378 val xythm = Thm.assume xy and yzthm = Thm.assume yz |
420 val xythm = Thm.assume xy and yzthm = Thm.assume yz |
379 in store_thm "transitive" (Thm.implies_intr yz (Thm.transitive xythm yzthm)) end; |
421 in store_thm "transitive" (Thm.implies_intr yz (Thm.transitive xythm yzthm)) |
|
422 end; |
380 |
423 |
381 (** Below, a "conversion" has type cterm -> thm **) |
424 (** Below, a "conversion" has type cterm -> thm **) |
382 |
425 |
383 val refl_implies = reflexive (cterm_of (sign_of ProtoPure.thy) implies); |
426 val refl_implies = reflexive (cterm_of proto_sign implies); |
384 |
427 |
385 (*In [A1,...,An]==>B, rewrite the selected A's only -- for rewrite_goals_tac*) |
428 (*In [A1,...,An]==>B, rewrite the selected A's only -- for rewrite_goals_tac*) |
386 (*Do not rewrite flex-flex pairs*) |
429 (*Do not rewrite flex-flex pairs*) |
387 fun goals_conv pred cv = |
430 fun goals_conv pred cv = |
388 let fun gconv i ct = |
431 let fun gconv i ct = |
461 |
504 |
462 (*** Some useful meta-theorems ***) |
505 (*** Some useful meta-theorems ***) |
463 |
506 |
464 (*The rule V/V, obtains assumption solving for eresolve_tac*) |
507 (*The rule V/V, obtains assumption solving for eresolve_tac*) |
465 val asm_rl = |
508 val asm_rl = |
466 store_thm "asm_rl" (trivial(read_cterm (sign_of ProtoPure.thy) ("PROP ?psi",propT))); |
509 store_thm "asm_rl" (trivial(read_prop "PROP ?psi")); |
467 |
510 |
468 (*Meta-level cut rule: [| V==>W; V |] ==> W *) |
511 (*Meta-level cut rule: [| V==>W; V |] ==> W *) |
469 val cut_rl = |
512 val cut_rl = |
470 store_thm "cut_rl" |
513 store_thm "cut_rl" |
471 (trivial(read_cterm (sign_of ProtoPure.thy) ("PROP ?psi ==> PROP ?theta", propT))); |
514 (trivial(read_prop "PROP ?psi ==> PROP ?theta")); |
472 |
515 |
473 (*Generalized elim rule for one conclusion; cut_rl with reversed premises: |
516 (*Generalized elim rule for one conclusion; cut_rl with reversed premises: |
474 [| PROP V; PROP V ==> PROP W |] ==> PROP W *) |
517 [| PROP V; PROP V ==> PROP W |] ==> PROP W *) |
475 val revcut_rl = |
518 val revcut_rl = |
476 let val V = read_cterm (sign_of ProtoPure.thy) ("PROP V", propT) |
519 let val V = read_prop "PROP V" |
477 and VW = read_cterm (sign_of ProtoPure.thy) ("PROP V ==> PROP W", propT); |
520 and VW = read_prop "PROP V ==> PROP W"; |
478 in |
521 in |
479 store_thm "revcut_rl" |
522 store_thm "revcut_rl" |
480 (implies_intr V (implies_intr VW (implies_elim (assume VW) (assume V)))) |
523 (implies_intr V (implies_intr VW (implies_elim (assume VW) (assume V)))) |
481 end; |
524 end; |
482 |
525 |
483 (*for deleting an unwanted assumption*) |
526 (*for deleting an unwanted assumption*) |
484 val thin_rl = |
527 val thin_rl = |
485 let val V = read_cterm (sign_of ProtoPure.thy) ("PROP V", propT) |
528 let val V = read_prop "PROP V" |
486 and W = read_cterm (sign_of ProtoPure.thy) ("PROP W", propT); |
529 and W = read_prop "PROP W"; |
487 in store_thm "thin_rl" (implies_intr V (implies_intr W (assume W))) |
530 in store_thm "thin_rl" (implies_intr V (implies_intr W (assume W))) |
488 end; |
531 end; |
489 |
532 |
490 (* (!!x. PROP ?V) == PROP ?V Allows removal of redundant parameters*) |
533 (* (!!x. PROP ?V) == PROP ?V Allows removal of redundant parameters*) |
491 val triv_forall_equality = |
534 val triv_forall_equality = |
492 let val V = read_cterm (sign_of ProtoPure.thy) ("PROP V", propT) |
535 let val V = read_prop "PROP V" |
493 and QV = read_cterm (sign_of ProtoPure.thy) ("!!x::'a. PROP V", propT) |
536 and QV = read_prop "!!x::'a. PROP V" |
494 and x = read_cterm (sign_of ProtoPure.thy) ("x", TFree("'a",logicS)); |
537 and x = read_cterm proto_sign ("x", TFree("'a",logicS)); |
495 in |
538 in |
496 store_thm "triv_forall_equality" |
539 store_thm "triv_forall_equality" |
497 (equal_intr (implies_intr QV (forall_elim x (assume QV))) |
540 (equal_intr (implies_intr QV (forall_elim x (assume QV))) |
498 (implies_intr V (forall_intr x (assume V)))) |
541 (implies_intr V (forall_intr x (assume V)))) |
499 end; |
542 end; |
501 (* (PROP ?PhiA ==> PROP ?PhiB ==> PROP ?Psi) ==> |
544 (* (PROP ?PhiA ==> PROP ?PhiB ==> PROP ?Psi) ==> |
502 (PROP ?PhiB ==> PROP ?PhiA ==> PROP ?Psi) |
545 (PROP ?PhiB ==> PROP ?PhiA ==> PROP ?Psi) |
503 `thm COMP swap_prems_rl' swaps the first two premises of `thm' |
546 `thm COMP swap_prems_rl' swaps the first two premises of `thm' |
504 *) |
547 *) |
505 val swap_prems_rl = |
548 val swap_prems_rl = |
506 let val cmajor = read_cterm (sign_of ProtoPure.thy) |
549 let val cmajor = read_prop "PROP PhiA ==> PROP PhiB ==> PROP Psi"; |
507 ("PROP PhiA ==> PROP PhiB ==> PROP Psi", propT); |
|
508 val major = assume cmajor; |
550 val major = assume cmajor; |
509 val cminor1 = read_cterm (sign_of ProtoPure.thy) ("PROP PhiA", propT); |
551 val cminor1 = read_prop "PROP PhiA"; |
510 val minor1 = assume cminor1; |
552 val minor1 = assume cminor1; |
511 val cminor2 = read_cterm (sign_of ProtoPure.thy) ("PROP PhiB", propT); |
553 val cminor2 = read_prop "PROP PhiB"; |
512 val minor2 = assume cminor2; |
554 val minor2 = assume cminor2; |
513 in store_thm "swap_prems_rl" |
555 in store_thm "swap_prems_rl" |
514 (implies_intr cmajor (implies_intr cminor2 (implies_intr cminor1 |
556 (implies_intr cmajor (implies_intr cminor2 (implies_intr cminor1 |
515 (implies_elim (implies_elim major minor1) minor2)))) |
557 (implies_elim (implies_elim major minor1) minor2)))) |
516 end; |
558 end; |
517 |
559 |
518 (* [| PROP ?phi ==> PROP ?psi; PROP ?psi ==> PROP ?phi |] |
560 (* [| PROP ?phi ==> PROP ?psi; PROP ?psi ==> PROP ?phi |] |
519 ==> PROP ?phi == PROP ?psi |
561 ==> PROP ?phi == PROP ?psi |
520 Introduction rule for == using ==> not meta-hyps. |
562 Introduction rule for == as a meta-theorem. |
521 *) |
563 *) |
522 val equal_intr_rule = |
564 val equal_intr_rule = |
523 let val PQ = read_cterm (sign_of ProtoPure.thy) ("PROP phi ==> PROP psi", propT) |
565 let val PQ = read_prop "PROP phi ==> PROP psi" |
524 and QP = read_cterm (sign_of ProtoPure.thy) ("PROP psi ==> PROP phi", propT) |
566 and QP = read_prop "PROP psi ==> PROP phi" |
525 in |
567 in |
526 store_thm "equal_intr_rule" |
568 store_thm "equal_intr_rule" |
527 (implies_intr PQ (implies_intr QP (equal_intr (assume PQ) (assume QP)))) |
569 (implies_intr PQ (implies_intr QP (equal_intr (assume PQ) (assume QP)))) |
528 end; |
570 end; |
529 |
571 |