src/Pure/drule.ML
changeset 33277 1bdc3c732fdd
parent 33095 bbd52d2f8696
child 33384 1b5ba4e6a953
equal deleted inserted replaced
33276:f2bc8bc6e73d 33277:1bdc3c732fdd
    76   val types_sorts: thm -> (indexname-> typ option) * (indexname-> sort option)
    76   val types_sorts: thm -> (indexname-> typ option) * (indexname-> sort option)
    77   val flexflex_unique: thm -> thm
    77   val flexflex_unique: thm -> thm
    78   val standard: thm -> thm
    78   val standard: thm -> thm
    79   val standard': thm -> thm
    79   val standard': thm -> thm
    80   val get_def: theory -> xstring -> thm
    80   val get_def: theory -> xstring -> thm
    81   val store_thm: bstring -> thm -> thm
    81   val store_thm: binding -> thm -> thm
    82   val store_standard_thm: bstring -> thm -> thm
    82   val store_standard_thm: binding -> thm -> thm
    83   val store_thm_open: bstring -> thm -> thm
    83   val store_thm_open: binding -> thm -> thm
    84   val store_standard_thm_open: bstring -> thm -> thm
    84   val store_standard_thm_open: binding -> thm -> thm
    85   val compose_single: thm * int * thm -> thm
    85   val compose_single: thm * int * thm -> thm
    86   val imp_cong_rule: thm -> thm -> thm
    86   val imp_cong_rule: thm -> thm -> thm
    87   val arg_cong_rule: cterm -> thm -> thm
    87   val arg_cong_rule: cterm -> thm -> thm
    88   val binop_cong_rule: cterm -> thm -> thm -> thm
    88   val binop_cong_rule: cterm -> thm -> thm -> thm
    89   val fun_cong_rule: thm -> cterm -> thm
    89   val fun_cong_rule: thm -> cterm -> thm
   453 val read_prop = certify o SimpleSyntax.read_prop;
   453 val read_prop = certify o SimpleSyntax.read_prop;
   454 
   454 
   455 fun get_def thy = Thm.axiom thy o Name_Space.intern (Theory.axiom_space thy) o Thm.def_name;
   455 fun get_def thy = Thm.axiom thy o Name_Space.intern (Theory.axiom_space thy) o Thm.def_name;
   456 
   456 
   457 fun store_thm name th =
   457 fun store_thm name th =
   458   Context.>>> (Context.map_theory_result (PureThy.store_thm (Binding.name name, th)));
   458   Context.>>> (Context.map_theory_result (PureThy.store_thm (name, th)));
   459 
   459 
   460 fun store_thm_open name th =
   460 fun store_thm_open name th =
   461   Context.>>> (Context.map_theory_result (PureThy.store_thm_open (Binding.name name, th)));
   461   Context.>>> (Context.map_theory_result (PureThy.store_thm_open (name, th)));
   462 
   462 
   463 fun store_standard_thm name th = store_thm name (standard th);
   463 fun store_standard_thm name th = store_thm name (standard th);
   464 fun store_standard_thm_open name thm = store_thm_open name (standard' thm);
   464 fun store_standard_thm_open name thm = store_thm_open name (standard' thm);
   465 
   465 
   466 val reflexive_thm =
   466 val reflexive_thm =
   467   let val cx = certify (Var(("x",0),TVar(("'a",0),[])))
   467   let val cx = certify (Var(("x",0),TVar(("'a",0),[])))
   468   in store_standard_thm_open "reflexive" (Thm.reflexive cx) end;
   468   in store_standard_thm_open (Binding.name "reflexive") (Thm.reflexive cx) end;
   469 
   469 
   470 val symmetric_thm =
   470 val symmetric_thm =
   471   let val xy = read_prop "x::'a == y::'a"
   471   let
   472   in store_standard_thm_open "symmetric" (Thm.implies_intr xy (Thm.symmetric (Thm.assume xy))) end;
   472     val xy = read_prop "x::'a == y::'a";
       
   473     val thm = Thm.implies_intr xy (Thm.symmetric (Thm.assume xy));
       
   474   in store_standard_thm_open (Binding.name "symmetric") thm end;
   473 
   475 
   474 val transitive_thm =
   476 val transitive_thm =
   475   let val xy = read_prop "x::'a == y::'a"
   477   let
   476       val yz = read_prop "y::'a == z::'a"
   478     val xy = read_prop "x::'a == y::'a";
   477       val xythm = Thm.assume xy and yzthm = Thm.assume yz
   479     val yz = read_prop "y::'a == z::'a";
   478   in store_standard_thm_open "transitive" (Thm.implies_intr yz (Thm.transitive xythm yzthm)) end;
   480     val xythm = Thm.assume xy;
       
   481     val yzthm = Thm.assume yz;
       
   482     val thm = Thm.implies_intr yz (Thm.transitive xythm yzthm);
       
   483   in store_standard_thm_open (Binding.name "transitive") thm end;
   479 
   484 
   480 fun symmetric_fun thm = thm RS symmetric_thm;
   485 fun symmetric_fun thm = thm RS symmetric_thm;
   481 
   486 
   482 fun extensional eq =
   487 fun extensional eq =
   483   let val eq' =
   488   let val eq' =
   484     abstract_rule "x" (Thm.dest_arg (fst (Thm.dest_equals (cprop_of eq)))) eq
   489     abstract_rule "x" (Thm.dest_arg (fst (Thm.dest_equals (cprop_of eq)))) eq
   485   in equal_elim (eta_conversion (cprop_of eq')) eq' end;
   490   in equal_elim (eta_conversion (cprop_of eq')) eq' end;
   486 
   491 
   487 val equals_cong =
   492 val equals_cong =
   488   store_standard_thm_open "equals_cong" (Thm.reflexive (read_prop "x::'a == y::'a"));
   493   store_standard_thm_open (Binding.name "equals_cong")
       
   494     (Thm.reflexive (read_prop "x::'a == y::'a"));
   489 
   495 
   490 val imp_cong =
   496 val imp_cong =
   491   let
   497   let
   492     val ABC = read_prop "A ==> B::prop == C::prop"
   498     val ABC = read_prop "A ==> B::prop == C::prop"
   493     val AB = read_prop "A ==> B"
   499     val AB = read_prop "A ==> B"
   494     val AC = read_prop "A ==> C"
   500     val AC = read_prop "A ==> C"
   495     val A = read_prop "A"
   501     val A = read_prop "A"
   496   in
   502   in
   497     store_standard_thm_open "imp_cong" (implies_intr ABC (equal_intr
   503     store_standard_thm_open (Binding.name "imp_cong") (implies_intr ABC (equal_intr
   498       (implies_intr AB (implies_intr A
   504       (implies_intr AB (implies_intr A
   499         (equal_elim (implies_elim (assume ABC) (assume A))
   505         (equal_elim (implies_elim (assume ABC) (assume A))
   500           (implies_elim (assume AB) (assume A)))))
   506           (implies_elim (assume AB) (assume A)))))
   501       (implies_intr AC (implies_intr A
   507       (implies_intr AC (implies_intr A
   502         (equal_elim (symmetric (implies_elim (assume ABC) (assume A)))
   508         (equal_elim (symmetric (implies_elim (assume ABC) (assume A)))
   508     val ABC = read_prop "A ==> B ==> C"
   514     val ABC = read_prop "A ==> B ==> C"
   509     val BAC = read_prop "B ==> A ==> C"
   515     val BAC = read_prop "B ==> A ==> C"
   510     val A = read_prop "A"
   516     val A = read_prop "A"
   511     val B = read_prop "B"
   517     val B = read_prop "B"
   512   in
   518   in
   513     store_standard_thm_open "swap_prems_eq" (equal_intr
   519     store_standard_thm_open (Binding.name "swap_prems_eq")
   514       (implies_intr ABC (implies_intr B (implies_intr A
   520       (equal_intr
   515         (implies_elim (implies_elim (assume ABC) (assume A)) (assume B)))))
   521         (implies_intr ABC (implies_intr B (implies_intr A
   516       (implies_intr BAC (implies_intr A (implies_intr B
   522           (implies_elim (implies_elim (assume ABC) (assume A)) (assume B)))))
   517         (implies_elim (implies_elim (assume BAC) (assume B)) (assume A))))))
   523         (implies_intr BAC (implies_intr A (implies_intr B
       
   524           (implies_elim (implies_elim (assume BAC) (assume B)) (assume A))))))
   518   end;
   525   end;
   519 
   526 
   520 val imp_cong_rule = Thm.combination o Thm.combination (Thm.reflexive implies);
   527 val imp_cong_rule = Thm.combination o Thm.combination (Thm.reflexive implies);
   521 
   528 
   522 fun arg_cong_rule ct th = Thm.combination (Thm.reflexive ct) th;    (*AP_TERM in LCF/HOL*)
   529 fun arg_cong_rule ct th = Thm.combination (Thm.reflexive ct) th;    (*AP_TERM in LCF/HOL*)
   575 
   582 
   576 
   583 
   577 (*** Some useful meta-theorems ***)
   584 (*** Some useful meta-theorems ***)
   578 
   585 
   579 (*The rule V/V, obtains assumption solving for eresolve_tac*)
   586 (*The rule V/V, obtains assumption solving for eresolve_tac*)
   580 val asm_rl = store_standard_thm_open "asm_rl" (Thm.trivial (read_prop "?psi"));
   587 val asm_rl = store_standard_thm_open (Binding.name "asm_rl") (Thm.trivial (read_prop "?psi"));
   581 val _ = store_thm_open "_" asm_rl;
   588 val _ = store_thm_open (Binding.name "_") asm_rl;
   582 
   589 
   583 (*Meta-level cut rule: [| V==>W; V |] ==> W *)
   590 (*Meta-level cut rule: [| V==>W; V |] ==> W *)
   584 val cut_rl =
   591 val cut_rl =
   585   store_standard_thm_open "cut_rl"
   592   store_standard_thm_open (Binding.name "cut_rl")
   586     (Thm.trivial (read_prop "?psi ==> ?theta"));
   593     (Thm.trivial (read_prop "?psi ==> ?theta"));
   587 
   594 
   588 (*Generalized elim rule for one conclusion; cut_rl with reversed premises:
   595 (*Generalized elim rule for one conclusion; cut_rl with reversed premises:
   589      [| PROP V;  PROP V ==> PROP W |] ==> PROP W *)
   596      [| PROP V;  PROP V ==> PROP W |] ==> PROP W *)
   590 val revcut_rl =
   597 val revcut_rl =
   591   let val V = read_prop "V"
   598   let
   592       and VW = read_prop "V ==> W";
   599     val V = read_prop "V";
       
   600     val VW = read_prop "V ==> W";
   593   in
   601   in
   594     store_standard_thm_open "revcut_rl"
   602     store_standard_thm_open (Binding.name "revcut_rl")
   595       (implies_intr V (implies_intr VW (implies_elim (assume VW) (assume V))))
   603       (implies_intr V (implies_intr VW (implies_elim (assume VW) (assume V))))
   596   end;
   604   end;
   597 
   605 
   598 (*for deleting an unwanted assumption*)
   606 (*for deleting an unwanted assumption*)
   599 val thin_rl =
   607 val thin_rl =
   600   let val V = read_prop "V"
   608   let
   601       and W = read_prop "W";
   609     val V = read_prop "V";
   602   in store_standard_thm_open "thin_rl" (implies_intr V (implies_intr W (assume W))) end;
   610     val W = read_prop "W";
       
   611     val thm = implies_intr V (implies_intr W (assume W));
       
   612   in store_standard_thm_open (Binding.name "thin_rl") thm end;
   603 
   613 
   604 (* (!!x. PROP ?V) == PROP ?V       Allows removal of redundant parameters*)
   614 (* (!!x. PROP ?V) == PROP ?V       Allows removal of redundant parameters*)
   605 val triv_forall_equality =
   615 val triv_forall_equality =
   606   let val V  = read_prop "V"
   616   let
   607       and QV = read_prop "!!x::'a. V"
   617     val V = read_prop "V";
   608       and x  = certify (Free ("x", Term.aT []));
   618     val QV = read_prop "!!x::'a. V";
       
   619     val x = certify (Free ("x", Term.aT []));
   609   in
   620   in
   610     store_standard_thm_open "triv_forall_equality"
   621     store_standard_thm_open (Binding.name "triv_forall_equality")
   611       (equal_intr (implies_intr QV (forall_elim x (assume QV)))
   622       (equal_intr (implies_intr QV (forall_elim x (assume QV)))
   612         (implies_intr V  (forall_intr x (assume V))))
   623         (implies_intr V  (forall_intr x (assume V))))
   613   end;
   624   end;
   614 
   625 
   615 (* (PROP ?Phi ==> PROP ?Phi ==> PROP ?Psi) ==>
   626 (* (PROP ?Phi ==> PROP ?Phi ==> PROP ?Psi) ==>
   616    (PROP ?Phi ==> PROP ?Psi)
   627    (PROP ?Phi ==> PROP ?Psi)
   617 *)
   628 *)
   618 val distinct_prems_rl =
   629 val distinct_prems_rl =
   619   let
   630   let
   620     val AAB = read_prop "Phi ==> Phi ==> Psi"
   631     val AAB = read_prop "Phi ==> Phi ==> Psi";
   621     val A = read_prop "Phi";
   632     val A = read_prop "Phi";
   622   in
   633   in
   623     store_standard_thm_open "distinct_prems_rl"
   634     store_standard_thm_open (Binding.name "distinct_prems_rl")
   624       (implies_intr_list [AAB, A] (implies_elim_list (assume AAB) [assume A, assume A]))
   635       (implies_intr_list [AAB, A] (implies_elim_list (assume AAB) [assume A, assume A]))
   625   end;
   636   end;
   626 
   637 
   627 (* (PROP ?PhiA ==> PROP ?PhiB ==> PROP ?Psi) ==>
   638 (* (PROP ?PhiA ==> PROP ?PhiB ==> PROP ?Psi) ==>
   628    (PROP ?PhiB ==> PROP ?PhiA ==> PROP ?Psi)
   639    (PROP ?PhiB ==> PROP ?PhiA ==> PROP ?Psi)
   629    `thm COMP swap_prems_rl' swaps the first two premises of `thm'
   640    `thm COMP swap_prems_rl' swaps the first two premises of `thm'
   630 *)
   641 *)
   631 val swap_prems_rl =
   642 val swap_prems_rl =
   632   let val cmajor = read_prop "PhiA ==> PhiB ==> Psi";
   643   let
   633       val major = assume cmajor;
   644     val cmajor = read_prop "PhiA ==> PhiB ==> Psi";
   634       val cminor1 = read_prop "PhiA";
   645     val major = assume cmajor;
   635       val minor1 = assume cminor1;
   646     val cminor1 = read_prop "PhiA";
   636       val cminor2 = read_prop "PhiB";
   647     val minor1 = assume cminor1;
   637       val minor2 = assume cminor2;
   648     val cminor2 = read_prop "PhiB";
   638   in store_standard_thm_open "swap_prems_rl"
   649     val minor2 = assume cminor2;
   639        (implies_intr cmajor (implies_intr cminor2 (implies_intr cminor1
   650   in
   640          (implies_elim (implies_elim major minor1) minor2))))
   651     store_standard_thm_open (Binding.name "swap_prems_rl")
       
   652       (implies_intr cmajor (implies_intr cminor2 (implies_intr cminor1
       
   653         (implies_elim (implies_elim major minor1) minor2))))
   641   end;
   654   end;
   642 
   655 
   643 (* [| PROP ?phi ==> PROP ?psi; PROP ?psi ==> PROP ?phi |]
   656 (* [| PROP ?phi ==> PROP ?psi; PROP ?psi ==> PROP ?phi |]
   644    ==> PROP ?phi == PROP ?psi
   657    ==> PROP ?phi == PROP ?psi
   645    Introduction rule for == as a meta-theorem.
   658    Introduction rule for == as a meta-theorem.
   646 *)
   659 *)
   647 val equal_intr_rule =
   660 val equal_intr_rule =
   648   let val PQ = read_prop "phi ==> psi"
   661   let
   649       and QP = read_prop "psi ==> phi"
   662     val PQ = read_prop "phi ==> psi";
       
   663     val QP = read_prop "psi ==> phi";
   650   in
   664   in
   651     store_standard_thm_open "equal_intr_rule"
   665     store_standard_thm_open (Binding.name "equal_intr_rule")
   652       (implies_intr PQ (implies_intr QP (equal_intr (assume PQ) (assume QP))))
   666       (implies_intr PQ (implies_intr QP (equal_intr (assume PQ) (assume QP))))
   653   end;
   667   end;
   654 
   668 
   655 (* PROP ?phi == PROP ?psi ==> PROP ?phi ==> PROP ?psi *)
   669 (* PROP ?phi == PROP ?psi ==> PROP ?phi ==> PROP ?psi *)
   656 val equal_elim_rule1 =
   670 val equal_elim_rule1 =
   657   let val eq = read_prop "phi::prop == psi::prop"
   671   let
   658       and P = read_prop "phi"
   672     val eq = read_prop "phi::prop == psi::prop";
   659   in store_standard_thm_open "equal_elim_rule1"
   673     val P = read_prop "phi";
   660     (Thm.equal_elim (assume eq) (assume P) |> implies_intr_list [eq, P])
   674   in
       
   675     store_standard_thm_open (Binding.name "equal_elim_rule1")
       
   676       (Thm.equal_elim (assume eq) (assume P) |> implies_intr_list [eq, P])
   661   end;
   677   end;
   662 
   678 
   663 (* PROP ?psi == PROP ?phi ==> PROP ?phi ==> PROP ?psi *)
   679 (* PROP ?psi == PROP ?phi ==> PROP ?phi ==> PROP ?psi *)
   664 val equal_elim_rule2 =
   680 val equal_elim_rule2 =
   665   store_standard_thm_open "equal_elim_rule2" (symmetric_thm RS equal_elim_rule1);
   681   store_standard_thm_open (Binding.name "equal_elim_rule2")
       
   682     (symmetric_thm RS equal_elim_rule1);
   666 
   683 
   667 (* PROP ?phi ==> PROP ?phi ==> PROP ?psi ==> PROP ?psi *)
   684 (* PROP ?phi ==> PROP ?phi ==> PROP ?psi ==> PROP ?psi *)
   668 val remdups_rl =
   685 val remdups_rl =
   669   let val P = read_prop "phi" and Q = read_prop "psi";
   686   let
   670   in store_standard_thm_open "remdups_rl" (implies_intr_list [P, P, Q] (Thm.assume Q)) end;
   687     val P = read_prop "phi";
       
   688     val Q = read_prop "psi";
       
   689     val thm = implies_intr_list [P, P, Q] (Thm.assume Q);
       
   690   in store_standard_thm_open (Binding.name "remdups_rl") thm end;
   671 
   691 
   672 
   692 
   673 
   693 
   674 (** embedded terms and types **)
   694 (** embedded terms and types **)
   675 
   695 
   686 
   706 
   687 (* protect *)
   707 (* protect *)
   688 
   708 
   689 val protect = Thm.capply (certify Logic.protectC);
   709 val protect = Thm.capply (certify Logic.protectC);
   690 
   710 
   691 val protectI = store_thm "protectI" (Thm.kind_rule Thm.internalK (standard
   711 val protectI =
   692     (Thm.equal_elim (Thm.symmetric prop_def) (Thm.assume A))));
   712   store_thm (Binding.conceal (Binding.name "protectI"))
   693 
   713     (Thm.kind_rule Thm.internalK (standard
   694 val protectD = store_thm "protectD" (Thm.kind_rule Thm.internalK (standard
   714       (Thm.equal_elim (Thm.symmetric prop_def) (Thm.assume A))));
   695     (Thm.equal_elim prop_def (Thm.assume (protect A)))));
   715 
   696 
   716 val protectD =
   697 val protect_cong = store_standard_thm_open "protect_cong" (Thm.reflexive (protect A));
   717   store_thm (Binding.conceal (Binding.name "protectD"))
       
   718     (Thm.kind_rule Thm.internalK (standard
       
   719       (Thm.equal_elim prop_def (Thm.assume (protect A)))));
       
   720 
       
   721 val protect_cong =
       
   722   store_standard_thm_open (Binding.name "protect_cong") (Thm.reflexive (protect A));
   698 
   723 
   699 fun implies_intr_protected asms th =
   724 fun implies_intr_protected asms th =
   700   let val asms' = map protect asms in
   725   let val asms' = map protect asms in
   701     implies_elim_list
   726     implies_elim_list
   702       (implies_intr_list asms th)
   727       (implies_intr_list asms th)
   705   end;
   730   end;
   706 
   731 
   707 
   732 
   708 (* term *)
   733 (* term *)
   709 
   734 
   710 val termI = store_thm "termI" (Thm.kind_rule Thm.internalK (standard
   735 val termI =
   711     (Thm.equal_elim (Thm.symmetric term_def) (Thm.forall_intr A (Thm.trivial A)))));
   736   store_thm (Binding.conceal (Binding.name "termI"))
       
   737     (Thm.kind_rule Thm.internalK (standard
       
   738       (Thm.equal_elim (Thm.symmetric term_def) (Thm.forall_intr A (Thm.trivial A)))));
   712 
   739 
   713 fun mk_term ct =
   740 fun mk_term ct =
   714   let
   741   let
   715     val thy = Thm.theory_of_cterm ct;
   742     val thy = Thm.theory_of_cterm ct;
   716     val cert = Thm.cterm_of thy;
   743     val cert = Thm.cterm_of thy;
   733 val dummy_thm = mk_term (certify (Term.dummy_pattern propT));
   760 val dummy_thm = mk_term (certify (Term.dummy_pattern propT));
   734 
   761 
   735 
   762 
   736 (* sort_constraint *)
   763 (* sort_constraint *)
   737 
   764 
   738 val sort_constraintI = store_thm "sort_constraintI" (Thm.kind_rule Thm.internalK (standard
   765 val sort_constraintI =
   739   (Thm.equal_elim (Thm.symmetric sort_constraint_def) (mk_term T))));
   766   store_thm (Binding.conceal (Binding.name "sort_constraintI"))
   740 
   767     (Thm.kind_rule Thm.internalK (standard
   741 val sort_constraint_eq = store_thm "sort_constraint_eq" (Thm.kind_rule Thm.internalK (standard
   768       (Thm.equal_elim (Thm.symmetric sort_constraint_def) (mk_term T))));
   742   (Thm.equal_intr
   769 
   743     (Thm.implies_intr CA (Thm.implies_elim (Thm.assume CA) (Thm.unvarify sort_constraintI)))
   770 val sort_constraint_eq =
   744     (implies_intr_list [A, C] (Thm.assume A)))));
   771   store_thm (Binding.conceal (Binding.name "sort_constraint_eq"))
       
   772     (Thm.kind_rule Thm.internalK (standard
       
   773       (Thm.equal_intr
       
   774         (Thm.implies_intr CA (Thm.implies_elim (Thm.assume CA) (Thm.unvarify sort_constraintI)))
       
   775         (implies_intr_list [A, C] (Thm.assume A)))));
   745 
   776 
   746 end;
   777 end;
   747 
   778 
   748 
   779 
   749 (* HHF normalization *)
   780 (* HHF normalization *)
   771       (Thm.implies_elim
   802       (Thm.implies_elim
   772           (Thm.assume rhs |> Thm.forall_elim cx) (Thm.assume cphi)
   803           (Thm.assume rhs |> Thm.forall_elim cx) (Thm.assume cphi)
   773         |> Thm.forall_intr cx
   804         |> Thm.forall_intr cx
   774         |> Thm.implies_intr cphi
   805         |> Thm.implies_intr cphi
   775         |> Thm.implies_intr rhs)
   806         |> Thm.implies_intr rhs)
   776     |> store_standard_thm_open "norm_hhf_eq"
   807     |> store_standard_thm_open (Binding.name "norm_hhf_eq")
   777   end;
   808   end;
   778 
   809 
   779 val norm_hhf_prop = Logic.dest_equals (Thm.prop_of norm_hhf_eq);
   810 val norm_hhf_prop = Logic.dest_equals (Thm.prop_of norm_hhf_eq);
   780 val norm_hhf_eqs = [norm_hhf_eq, sort_constraint_eq];
   811 val norm_hhf_eqs = [norm_hhf_eq, sort_constraint_eq];
   781 
   812