90 val fun_cong_rule: thm -> cterm -> thm |
90 val fun_cong_rule: thm -> cterm -> thm |
91 val beta_eta_conversion: cterm -> thm |
91 val beta_eta_conversion: cterm -> thm |
92 val eta_long_conversion: cterm -> thm |
92 val eta_long_conversion: cterm -> thm |
93 val eta_contraction_rule: thm -> thm |
93 val eta_contraction_rule: thm -> thm |
94 val norm_hhf_eq: thm |
94 val norm_hhf_eq: thm |
|
95 val norm_hhf_eqs: thm list |
95 val is_norm_hhf: term -> bool |
96 val is_norm_hhf: term -> bool |
96 val norm_hhf: theory -> term -> term |
97 val norm_hhf: theory -> term -> term |
97 val norm_hhf_cterm: cterm -> cterm |
98 val norm_hhf_cterm: cterm -> cterm |
98 val protect: cterm -> cterm |
99 val protect: cterm -> cterm |
99 val protectI: thm |
100 val protectI: thm |
104 val mk_term: cterm -> thm |
105 val mk_term: cterm -> thm |
105 val dest_term: thm -> cterm |
106 val dest_term: thm -> cterm |
106 val cterm_rule: (thm -> thm) -> cterm -> cterm |
107 val cterm_rule: (thm -> thm) -> cterm -> cterm |
107 val term_rule: theory -> (thm -> thm) -> term -> term |
108 val term_rule: theory -> (thm -> thm) -> term -> term |
108 val dummy_thm: thm |
109 val dummy_thm: thm |
|
110 val sort_constraintI: thm |
|
111 val sort_constraint_eq: thm |
109 val sort_triv: theory -> typ * sort -> thm list |
112 val sort_triv: theory -> typ * sort -> thm list |
110 val unconstrainTs: thm -> thm |
113 val unconstrainTs: thm -> thm |
111 val with_subgoal: int -> (thm -> thm) -> thm -> thm |
114 val with_subgoal: int -> (thm -> thm) -> thm -> thm |
112 val rename_bvars: (string * string) list -> thm -> thm |
115 val rename_bvars: (string * string) list -> thm -> thm |
113 val rename_bvars': string option list -> thm -> thm |
116 val rename_bvars': string option list -> thm -> thm |
665 |
668 |
666 (* PROP ?psi == PROP ?phi ==> PROP ?phi ==> PROP ?psi *) |
669 (* PROP ?psi == PROP ?phi ==> PROP ?phi ==> PROP ?psi *) |
667 val equal_elim_rule2 = |
670 val equal_elim_rule2 = |
668 store_standard_thm_open "equal_elim_rule2" (symmetric_thm RS equal_elim_rule1); |
671 store_standard_thm_open "equal_elim_rule2" (symmetric_thm RS equal_elim_rule1); |
669 |
672 |
670 (* "[| PROP ?phi; PROP ?phi; PROP ?psi |] ==> PROP ?psi" *) |
673 (* PROP ?phi ==> PROP ?phi ==> PROP ?psi ==> PROP ?psi *) |
671 val remdups_rl = |
674 val remdups_rl = |
672 let val P = read_prop "phi" and Q = read_prop "psi"; |
675 let val P = read_prop "phi" and Q = read_prop "psi"; |
673 in store_standard_thm_open "remdups_rl" (implies_intr_list [P, P, Q] (Thm.assume Q)) end; |
676 in store_standard_thm_open "remdups_rl" (implies_intr_list [P, P, Q] (Thm.assume Q)) end; |
674 |
677 |
675 |
678 |
676 (*(PROP ?phi ==> (!!x. PROP ?psi(x))) == (!!x. PROP ?phi ==> PROP ?psi(x)) |
679 |
677 Rewrite rule for HHF normalization.*) |
680 (** embedded terms and types **) |
678 |
681 |
|
682 local |
|
683 val A = certify (Free ("A", propT)); |
|
684 val get_axiom = Thm.unvarify o Thm.get_axiom (Context.the_theory (Context.the_thread_data ())); |
|
685 val prop_def = get_axiom "prop_def"; |
|
686 val term_def = get_axiom "term_def"; |
|
687 val sort_constraint_def = get_axiom "sort_constraint_def"; |
|
688 val C = Thm.lhs_of sort_constraint_def; |
|
689 val T = Thm.dest_arg C; |
|
690 val CA = mk_implies (C, A); |
|
691 in |
|
692 |
|
693 (* protect *) |
|
694 |
|
695 val protect = Thm.capply (certify Logic.protectC); |
|
696 |
|
697 val protectI = store_thm "protectI" (Thm.kind_rule Thm.internalK (standard |
|
698 (Thm.equal_elim (Thm.symmetric prop_def) (Thm.assume A)))); |
|
699 |
|
700 val protectD = store_thm "protectD" (Thm.kind_rule Thm.internalK (standard |
|
701 (Thm.equal_elim prop_def (Thm.assume (protect A))))); |
|
702 |
|
703 val protect_cong = store_standard_thm_open "protect_cong" (Thm.reflexive (protect A)); |
|
704 |
|
705 fun implies_intr_protected asms th = |
|
706 let val asms' = map protect asms in |
|
707 implies_elim_list |
|
708 (implies_intr_list asms th) |
|
709 (map (fn asm' => Thm.assume asm' RS protectD) asms') |
|
710 |> implies_intr_list asms' |
|
711 end; |
|
712 |
|
713 |
|
714 (* term *) |
|
715 |
|
716 val termI = store_thm "termI" (Thm.kind_rule Thm.internalK (standard |
|
717 (Thm.equal_elim (Thm.symmetric term_def) (Thm.forall_intr A (Thm.trivial A))))); |
|
718 |
|
719 fun mk_term ct = |
|
720 let |
|
721 val thy = Thm.theory_of_cterm ct; |
|
722 val cert = Thm.cterm_of thy; |
|
723 val certT = Thm.ctyp_of thy; |
|
724 val T = Thm.typ_of (Thm.ctyp_of_term ct); |
|
725 val a = certT (TVar (("'a", 0), [])); |
|
726 val x = cert (Var (("x", 0), T)); |
|
727 in Thm.instantiate ([(a, certT T)], [(x, ct)]) termI end; |
|
728 |
|
729 fun dest_term th = |
|
730 let val cprop = strip_imp_concl (Thm.cprop_of th) in |
|
731 if can Logic.dest_term (Thm.term_of cprop) then |
|
732 Thm.dest_arg cprop |
|
733 else raise THM ("dest_term", 0, [th]) |
|
734 end; |
|
735 |
|
736 fun cterm_rule f = dest_term o f o mk_term; |
|
737 fun term_rule thy f t = Thm.term_of (cterm_rule f (Thm.cterm_of thy t)); |
|
738 |
|
739 val dummy_thm = mk_term (certify (Term.dummy_pattern propT)); |
|
740 |
|
741 |
|
742 (* sort_constraint *) |
|
743 |
|
744 val sort_constraintI = store_thm "sort_constraintI" (Thm.kind_rule Thm.internalK (standard |
|
745 (Thm.equal_elim (Thm.symmetric sort_constraint_def) (mk_term T)))); |
|
746 |
|
747 val sort_constraint_eq = store_thm "sort_constraint_eq" (Thm.kind_rule Thm.internalK (standard |
|
748 (Thm.equal_intr |
|
749 (Thm.implies_intr CA (Thm.implies_elim (Thm.assume CA) (Thm.unvarify sort_constraintI))) |
|
750 (implies_intr_list [A, C] (Thm.assume A))))); |
|
751 |
|
752 end; |
|
753 |
|
754 |
|
755 (* HHF normalization *) |
|
756 |
|
757 (* (PROP ?phi ==> (!!x. PROP ?psi(x))) == (!!x. PROP ?phi ==> PROP ?psi(x)) *) |
679 val norm_hhf_eq = |
758 val norm_hhf_eq = |
680 let |
759 let |
681 val aT = TFree ("'a", []); |
760 val aT = TFree ("'a", []); |
682 val all = Term.all aT; |
761 val all = Term.all aT; |
683 val x = Free ("x", aT); |
762 val x = Free ("x", aT); |
702 |> Thm.implies_intr rhs) |
781 |> Thm.implies_intr rhs) |
703 |> store_standard_thm_open "norm_hhf_eq" |
782 |> store_standard_thm_open "norm_hhf_eq" |
704 end; |
783 end; |
705 |
784 |
706 val norm_hhf_prop = Logic.dest_equals (Thm.prop_of norm_hhf_eq); |
785 val norm_hhf_prop = Logic.dest_equals (Thm.prop_of norm_hhf_eq); |
|
786 val norm_hhf_eqs = [norm_hhf_eq, sort_constraint_eq]; |
707 |
787 |
708 fun is_norm_hhf tm = |
788 fun is_norm_hhf tm = |
709 let |
789 let |
710 fun is_norm (Const ("==>", _) $ _ $ (Const ("all", _) $ _)) = false |
790 fun is_norm (Const ("Pure.sort_constraint", _)) = false |
|
791 | is_norm (Const ("==>", _) $ _ $ (Const ("all", _) $ _)) = false |
711 | is_norm (t $ u) = is_norm t andalso is_norm u |
792 | is_norm (t $ u) = is_norm t andalso is_norm u |
712 | is_norm (Abs (_, _, t)) = is_norm t |
793 | is_norm (Abs (_, _, t)) = is_norm t |
713 | is_norm _ = true; |
794 | is_norm _ = true; |
714 in is_norm (Envir.beta_eta_contract tm) end; |
795 in is_norm (Envir.beta_eta_contract tm) end; |
715 |
796 |
780 raise THM("cterm_instantiate: incompatible theories",0,[th]) |
861 raise THM("cterm_instantiate: incompatible theories",0,[th]) |
781 | TYPE (msg, _, _) => raise THM(msg, 0, [th]) |
862 | TYPE (msg, _, _) => raise THM(msg, 0, [th]) |
782 end; |
863 end; |
783 |
864 |
784 |
865 |
785 (** protected propositions and embedded terms **) |
|
786 |
|
787 local |
|
788 val A = certify (Free ("A", propT)); |
|
789 val get_axiom = Thm.unvarify o Thm.get_axiom (Context.the_theory (Context.the_thread_data ())); |
|
790 val prop_def = get_axiom "prop_def"; |
|
791 val term_def = get_axiom "term_def"; |
|
792 in |
|
793 val protect = Thm.capply (certify Logic.protectC); |
|
794 val protectI = store_thm "protectI" (Thm.kind_rule Thm.internalK (standard |
|
795 (Thm.equal_elim (Thm.symmetric prop_def) (Thm.assume A)))); |
|
796 val protectD = store_thm "protectD" (Thm.kind_rule Thm.internalK (standard |
|
797 (Thm.equal_elim prop_def (Thm.assume (protect A))))); |
|
798 val protect_cong = store_standard_thm_open "protect_cong" (Thm.reflexive (protect A)); |
|
799 |
|
800 val termI = store_thm "termI" (Thm.kind_rule Thm.internalK (standard |
|
801 (Thm.equal_elim (Thm.symmetric term_def) (Thm.forall_intr A (Thm.trivial A))))); |
|
802 end; |
|
803 |
|
804 fun implies_intr_protected asms th = |
|
805 let val asms' = map protect asms in |
|
806 implies_elim_list |
|
807 (implies_intr_list asms th) |
|
808 (map (fn asm' => Thm.assume asm' RS protectD) asms') |
|
809 |> implies_intr_list asms' |
|
810 end; |
|
811 |
|
812 fun mk_term ct = |
|
813 let |
|
814 val thy = Thm.theory_of_cterm ct; |
|
815 val cert = Thm.cterm_of thy; |
|
816 val certT = Thm.ctyp_of thy; |
|
817 val T = Thm.typ_of (Thm.ctyp_of_term ct); |
|
818 val a = certT (TVar (("'a", 0), [])); |
|
819 val x = cert (Var (("x", 0), T)); |
|
820 in Thm.instantiate ([(a, certT T)], [(x, ct)]) termI end; |
|
821 |
|
822 fun dest_term th = |
|
823 let val cprop = strip_imp_concl (Thm.cprop_of th) in |
|
824 if can Logic.dest_term (Thm.term_of cprop) then |
|
825 Thm.dest_arg cprop |
|
826 else raise THM ("dest_term", 0, [th]) |
|
827 end; |
|
828 |
|
829 fun cterm_rule f = dest_term o f o mk_term; |
|
830 fun term_rule thy f t = Thm.term_of (cterm_rule f (Thm.cterm_of thy t)); |
|
831 |
|
832 val dummy_thm = mk_term (certify (Term.dummy_pattern propT)); |
|
833 |
|
834 |
|
835 |
866 |
836 (** variations on instantiate **) |
867 (** variations on instantiate **) |
837 |
868 |
838 (* instantiate by left-to-right occurrence of variables *) |
869 (* instantiate by left-to-right occurrence of variables *) |
839 |
870 |