| author | streckem | 
| Mon, 26 May 2003 18:36:15 +0200 | |
| changeset 14045 | a34d89ce6097 | 
| parent 13659 | 3cf622f6b0b2 | 
| child 14081 | 6c0f67e2f8d5 | 
| permissions | -rw-r--r-- | 
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 1 | (* Title: Pure/drule.ML | 
| 0 | 2 | ID: $Id$ | 
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 3 | Author: Lawrence C Paulson, Cambridge University Computer Laboratory | 
| 0 | 4 | Copyright 1993 University of Cambridge | 
| 5 | ||
| 3766 | 6 | Derived rules and other operations on theorems. | 
| 0 | 7 | *) | 
| 8 | ||
| 13606 
2f121149acfe
Removed nRS again because extract_rews now takes care of preserving names.
 berghofe parents: 
13569diff
changeset | 9 | infix 0 RS RSN RL RLN MRS MRL OF COMP; | 
| 0 | 10 | |
| 5903 | 11 | signature BASIC_DRULE = | 
| 3766 | 12 | sig | 
| 9547 | 13 | val mk_implies : cterm * cterm -> cterm | 
| 14 | val list_implies : cterm list * cterm -> cterm | |
| 4285 | 15 | val dest_implies : cterm -> cterm * cterm | 
| 10414 | 16 | val dest_equals : cterm -> cterm * cterm | 
| 8328 | 17 | val strip_imp_prems : cterm -> cterm list | 
| 10414 | 18 | val strip_imp_concl : cterm -> cterm | 
| 8328 | 19 | val cprems_of : thm -> cterm list | 
| 20 | val read_insts : | |
| 4285 | 21 | Sign.sg -> (indexname -> typ option) * (indexname -> sort option) | 
| 22 | -> (indexname -> typ option) * (indexname -> sort option) | |
| 23 | -> string list -> (string*string)list | |
| 24 | -> (indexname*ctyp)list * (cterm*cterm)list | |
| 25 | val types_sorts: thm -> (indexname-> typ option) * (indexname-> sort option) | |
| 7636 | 26 | val strip_shyps_warning : thm -> thm | 
| 8328 | 27 | val forall_intr_list : cterm list -> thm -> thm | 
| 28 | val forall_intr_frees : thm -> thm | |
| 29 | val forall_intr_vars : thm -> thm | |
| 30 | val forall_elim_list : cterm list -> thm -> thm | |
| 31 | val forall_elim_var : int -> thm -> thm | |
| 32 | val forall_elim_vars : int -> thm -> thm | |
| 12725 | 33 | val gen_all : thm -> thm | 
| 8328 | 34 | val freeze_thaw : thm -> thm * (thm -> thm) | 
| 35 | val implies_elim_list : thm -> thm list -> thm | |
| 36 | val implies_intr_list : cterm list -> thm -> thm | |
| 8129 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 37 | val instantiate : | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 38 | (indexname * ctyp) list * (cterm * cterm) list -> thm -> thm | 
| 8328 | 39 | val zero_var_indexes : thm -> thm | 
| 40 | val standard : thm -> thm | |
| 11512 
da3a96ab5630
Some basic rules are now stored with "open" derivations, to facilitate
 berghofe parents: 
11163diff
changeset | 41 | val standard' : thm -> thm | 
| 4610 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 42 | val rotate_prems : int -> thm -> thm | 
| 11163 | 43 | val rearrange_prems : int list -> thm -> thm | 
| 8328 | 44 | val assume_ax : theory -> string -> thm | 
| 45 | val RSN : thm * (int * thm) -> thm | |
| 46 | val RS : thm * thm -> thm | |
| 47 | val RLN : thm list * (int * thm list) -> thm list | |
| 48 | val RL : thm list * thm list -> thm list | |
| 49 | val MRS : thm list * thm -> thm | |
| 50 | val MRL : thm list list * thm list -> thm list | |
| 9288 
06a55195741b
infix 'OF' is a version of 'MRS' with more appropriate argument order;
 wenzelm parents: 
8605diff
changeset | 51 | val OF : thm * thm list -> thm | 
| 8328 | 52 | val compose : thm * int * thm -> thm list | 
| 53 | val COMP : thm * thm -> thm | |
| 0 | 54 | val read_instantiate_sg: Sign.sg -> (string*string)list -> thm -> thm | 
| 8328 | 55 | val read_instantiate : (string*string)list -> thm -> thm | 
| 56 | val cterm_instantiate : (cterm*cterm)list -> thm -> thm | |
| 13105 
3d1e7a199bdc
use eq_thm_prop instead of slightly inadequate eq_thm;
 wenzelm parents: 
12908diff
changeset | 57 | val eq_thm_sg : thm * thm -> bool | 
| 
3d1e7a199bdc
use eq_thm_prop instead of slightly inadequate eq_thm;
 wenzelm parents: 
12908diff
changeset | 58 | val eq_thm_prop : thm * thm -> bool | 
| 8328 | 59 | val weak_eq_thm : thm * thm -> bool | 
| 60 | val size_of_thm : thm -> int | |
| 61 | val reflexive_thm : thm | |
| 62 | val symmetric_thm : thm | |
| 63 | val transitive_thm : thm | |
| 2004 
3411fe560611
New operations on cterms.  Now same names as in Logic
 paulson parents: 
1906diff
changeset | 64 | val refl_implies : thm | 
| 4679 | 65 | val symmetric_fun : thm -> thm | 
| 11512 
da3a96ab5630
Some basic rules are now stored with "open" derivations, to facilitate
 berghofe parents: 
11163diff
changeset | 66 | val extensional : thm -> thm | 
| 10414 | 67 | val imp_cong : thm | 
| 68 | val swap_prems_eq : thm | |
| 8328 | 69 | val equal_abs_elim : cterm -> thm -> thm | 
| 4285 | 70 | val equal_abs_elim_list: cterm list -> thm -> thm | 
| 8328 | 71 | val asm_rl : thm | 
| 72 | val cut_rl : thm | |
| 73 | val revcut_rl : thm | |
| 74 | val thin_rl : thm | |
| 4285 | 75 | val triv_forall_equality: thm | 
| 1756 | 76 | val swap_prems_rl : thm | 
| 4285 | 77 | val equal_intr_rule : thm | 
| 13368 | 78 | val equal_elim_rule1 : thm | 
| 8550 
b44c185f8018
new meta-rule "inst", a shorthand for read_instantiate_sg
 paulson parents: 
8496diff
changeset | 79 | val inst : string -> string -> thm -> thm | 
| 8328 | 80 | val instantiate' : ctyp option list -> cterm option list -> thm -> thm | 
| 81 | val incr_indexes_wrt : int list -> ctyp list -> cterm list -> thm list -> thm -> thm | |
| 5903 | 82 | end; | 
| 83 | ||
| 84 | signature DRULE = | |
| 85 | sig | |
| 86 | include BASIC_DRULE | |
| 12908 
53bfe07a7916
New function strip_comb (cterm version of Term.strip_comb).
 berghofe parents: 
12800diff
changeset | 87 | val strip_comb: cterm -> cterm * cterm list | 
| 11975 | 88 |   val rule_attribute: ('a -> thm -> thm) -> 'a attribute
 | 
| 89 | val tag_rule: tag -> thm -> thm | |
| 90 | val untag_rule: string -> thm -> thm | |
| 91 | val tag: tag -> 'a attribute | |
| 92 | val untag: string -> 'a attribute | |
| 93 | val get_kind: thm -> string | |
| 94 | val kind: string -> 'a attribute | |
| 95 | val theoremK: string | |
| 96 | val lemmaK: string | |
| 97 | val corollaryK: string | |
| 98 | val internalK: string | |
| 99 | val kind_internal: 'a attribute | |
| 100 | val has_internal: tag list -> bool | |
| 101 | val impose_hyps: cterm list -> thm -> thm | |
| 13389 | 102 | val satisfy_hyps: thm list -> thm -> thm | 
| 11975 | 103 | val close_derivation: thm -> thm | 
| 12005 | 104 | val local_standard: thm -> thm | 
| 11975 | 105 | val compose_single: thm * int * thm -> thm | 
| 12373 | 106 | val add_rule: thm -> thm list -> thm list | 
| 107 | val del_rule: thm -> thm list -> thm list | |
| 11975 | 108 | val add_rules: thm list -> thm list -> thm list | 
| 109 | val del_rules: thm list -> thm list -> thm list | |
| 110 | val merge_rules: thm list * thm list -> thm list | |
| 111 | val norm_hhf_eq: thm | |
| 12800 | 112 | val is_norm_hhf: term -> bool | 
| 113 | val norm_hhf: Sign.sg -> term -> term | |
| 11975 | 114 | val triv_goal: thm | 
| 115 | val rev_triv_goal: thm | |
| 11815 | 116 | val implies_intr_goals: cterm list -> thm -> thm | 
| 11975 | 117 | val freeze_all: thm -> thm | 
| 118 | val mk_triv_goal: cterm -> thm | |
| 119 | val tvars_of_terms: term list -> (indexname * sort) list | |
| 120 | val vars_of_terms: term list -> (indexname * typ) list | |
| 121 | val tvars_of: thm -> (indexname * sort) list | |
| 122 | val vars_of: thm -> (indexname * typ) list | |
| 123 | val unvarifyT: thm -> thm | |
| 124 | val unvarify: thm -> thm | |
| 12495 | 125 | val tvars_intr_list: string list -> thm -> thm * (string * indexname) list | 
| 12297 | 126 | val remdups_rl: thm | 
| 11975 | 127 | val conj_intr: thm -> thm -> thm | 
| 128 | val conj_intr_list: thm list -> thm | |
| 129 | val conj_elim: thm -> thm * thm | |
| 130 | val conj_elim_list: thm -> thm list | |
| 12135 | 131 | val conj_elim_precise: int -> thm -> thm list | 
| 132 | val conj_intr_thm: thm | |
| 13325 | 133 | val abs_def: thm -> thm | 
| 3766 | 134 | end; | 
| 0 | 135 | |
| 5903 | 136 | structure Drule: DRULE = | 
| 0 | 137 | struct | 
| 138 | ||
| 3991 | 139 | |
| 708 
8422e50adce0
Pure/drule/cprems_of, cskip_flexpairs, cstrip_imp_prems: new cterm operations
 lcp parents: 
668diff
changeset | 140 | (** some cterm->cterm operations: much faster than calling cterm_of! **) | 
| 
8422e50adce0
Pure/drule/cprems_of, cskip_flexpairs, cstrip_imp_prems: new cterm operations
 lcp parents: 
668diff
changeset | 141 | |
| 2004 
3411fe560611
New operations on cterms.  Now same names as in Logic
 paulson parents: 
1906diff
changeset | 142 | (** SAME NAMES as in structure Logic: use compound identifiers! **) | 
| 
3411fe560611
New operations on cterms.  Now same names as in Logic
 paulson parents: 
1906diff
changeset | 143 | |
| 1703 
e22ad43bab5f
moved dest_cimplies to drule.ML; added adjust_maxidx
 clasohm parents: 
1596diff
changeset | 144 | (*dest_implies for cterms. Note T=prop below*) | 
| 2004 
3411fe560611
New operations on cterms.  Now same names as in Logic
 paulson parents: 
1906diff
changeset | 145 | fun dest_implies ct = | 
| 8328 | 146 | case term_of ct of | 
| 147 |         (Const("==>", _) $ _ $ _) =>
 | |
| 10767 
8fa4aafa7314
Thm: dest_comb, dest_abs, capply, cabs no longer global;
 wenzelm parents: 
10667diff
changeset | 148 | let val (ct1,ct2) = Thm.dest_comb ct | 
| 
8fa4aafa7314
Thm: dest_comb, dest_abs, capply, cabs no longer global;
 wenzelm parents: 
10667diff
changeset | 149 | in (#2 (Thm.dest_comb ct1), ct2) end | 
| 2004 
3411fe560611
New operations on cterms.  Now same names as in Logic
 paulson parents: 
1906diff
changeset | 150 |       | _ => raise TERM ("dest_implies", [term_of ct]) ;
 | 
| 1703 
e22ad43bab5f
moved dest_cimplies to drule.ML; added adjust_maxidx
 clasohm parents: 
1596diff
changeset | 151 | |
| 10414 | 152 | fun dest_equals ct = | 
| 153 | case term_of ct of | |
| 154 |         (Const("==", _) $ _ $ _) =>
 | |
| 10767 
8fa4aafa7314
Thm: dest_comb, dest_abs, capply, cabs no longer global;
 wenzelm parents: 
10667diff
changeset | 155 | let val (ct1,ct2) = Thm.dest_comb ct | 
| 
8fa4aafa7314
Thm: dest_comb, dest_abs, capply, cabs no longer global;
 wenzelm parents: 
10667diff
changeset | 156 | in (#2 (Thm.dest_comb ct1), ct2) end | 
| 10414 | 157 |       | _ => raise TERM ("dest_equals", [term_of ct]) ;
 | 
| 158 | ||
| 1703 
e22ad43bab5f
moved dest_cimplies to drule.ML; added adjust_maxidx
 clasohm parents: 
1596diff
changeset | 159 | |
| 708 
8422e50adce0
Pure/drule/cprems_of, cskip_flexpairs, cstrip_imp_prems: new cterm operations
 lcp parents: 
668diff
changeset | 160 | (* A1==>...An==>B goes to [A1,...,An], where B is not an implication *) | 
| 2004 
3411fe560611
New operations on cterms.  Now same names as in Logic
 paulson parents: 
1906diff
changeset | 161 | fun strip_imp_prems ct = | 
| 
3411fe560611
New operations on cterms.  Now same names as in Logic
 paulson parents: 
1906diff
changeset | 162 | let val (cA,cB) = dest_implies ct | 
| 
3411fe560611
New operations on cterms.  Now same names as in Logic
 paulson parents: 
1906diff
changeset | 163 | in cA :: strip_imp_prems cB end | 
| 708 
8422e50adce0
Pure/drule/cprems_of, cskip_flexpairs, cstrip_imp_prems: new cterm operations
 lcp parents: 
668diff
changeset | 164 | handle TERM _ => []; | 
| 
8422e50adce0
Pure/drule/cprems_of, cskip_flexpairs, cstrip_imp_prems: new cterm operations
 lcp parents: 
668diff
changeset | 165 | |
| 2004 
3411fe560611
New operations on cterms.  Now same names as in Logic
 paulson parents: 
1906diff
changeset | 166 | (* A1==>...An==>B goes to B, where B is not an implication *) | 
| 
3411fe560611
New operations on cterms.  Now same names as in Logic
 paulson parents: 
1906diff
changeset | 167 | fun strip_imp_concl ct = | 
| 8328 | 168 |     case term_of ct of (Const("==>", _) $ _ $ _) =>
 | 
| 10767 
8fa4aafa7314
Thm: dest_comb, dest_abs, capply, cabs no longer global;
 wenzelm parents: 
10667diff
changeset | 169 | strip_imp_concl (#2 (Thm.dest_comb ct)) | 
| 2004 
3411fe560611
New operations on cterms.  Now same names as in Logic
 paulson parents: 
1906diff
changeset | 170 | | _ => ct; | 
| 
3411fe560611
New operations on cterms.  Now same names as in Logic
 paulson parents: 
1906diff
changeset | 171 | |
| 708 
8422e50adce0
Pure/drule/cprems_of, cskip_flexpairs, cstrip_imp_prems: new cterm operations
 lcp parents: 
668diff
changeset | 172 | (*The premises of a theorem, as a cterm list*) | 
| 13659 
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
 berghofe parents: 
13650diff
changeset | 173 | val cprems_of = strip_imp_prems o cprop_of; | 
| 708 
8422e50adce0
Pure/drule/cprems_of, cskip_flexpairs, cstrip_imp_prems: new cterm operations
 lcp parents: 
668diff
changeset | 174 | |
| 9547 | 175 | val proto_sign = Theory.sign_of ProtoPure.thy; | 
| 176 | ||
| 177 | val implies = cterm_of proto_sign Term.implies; | |
| 178 | ||
| 179 | (*cterm version of mk_implies*) | |
| 10767 
8fa4aafa7314
Thm: dest_comb, dest_abs, capply, cabs no longer global;
 wenzelm parents: 
10667diff
changeset | 180 | fun mk_implies(A,B) = Thm.capply (Thm.capply implies A) B; | 
| 9547 | 181 | |
| 182 | (*cterm version of list_implies: [A1,...,An], B goes to [|A1;==>;An|]==>B *) | |
| 183 | fun list_implies([], B) = B | |
| 184 | | list_implies(A::AS, B) = mk_implies (A, list_implies(AS,B)); | |
| 185 | ||
| 12908 
53bfe07a7916
New function strip_comb (cterm version of Term.strip_comb).
 berghofe parents: 
12800diff
changeset | 186 | (*cterm version of strip_comb: maps f(t1,...,tn) to (f, [t1,...,tn]) *) | 
| 
53bfe07a7916
New function strip_comb (cterm version of Term.strip_comb).
 berghofe parents: 
12800diff
changeset | 187 | fun strip_comb ct = | 
| 
53bfe07a7916
New function strip_comb (cterm version of Term.strip_comb).
 berghofe parents: 
12800diff
changeset | 188 | let | 
| 
53bfe07a7916
New function strip_comb (cterm version of Term.strip_comb).
 berghofe parents: 
12800diff
changeset | 189 | fun stripc (p as (ct, cts)) = | 
| 
53bfe07a7916
New function strip_comb (cterm version of Term.strip_comb).
 berghofe parents: 
12800diff
changeset | 190 | let val (ct1, ct2) = Thm.dest_comb ct | 
| 
53bfe07a7916
New function strip_comb (cterm version of Term.strip_comb).
 berghofe parents: 
12800diff
changeset | 191 | in stripc (ct1, ct2 :: cts) end handle CTERM _ => p | 
| 
53bfe07a7916
New function strip_comb (cterm version of Term.strip_comb).
 berghofe parents: 
12800diff
changeset | 192 | in stripc (ct, []) end; | 
| 
53bfe07a7916
New function strip_comb (cterm version of Term.strip_comb).
 berghofe parents: 
12800diff
changeset | 193 | |
| 708 
8422e50adce0
Pure/drule/cprems_of, cskip_flexpairs, cstrip_imp_prems: new cterm operations
 lcp parents: 
668diff
changeset | 194 | |
| 229 
4002c4cd450c
Pure:  MAJOR CHANGE.  Moved ML types ctyp and cterm and their associated
 lcp parents: 
214diff
changeset | 195 | (** reading of instantiations **) | 
| 
4002c4cd450c
Pure:  MAJOR CHANGE.  Moved ML types ctyp and cterm and their associated
 lcp parents: 
214diff
changeset | 196 | |
| 
4002c4cd450c
Pure:  MAJOR CHANGE.  Moved ML types ctyp and cterm and their associated
 lcp parents: 
214diff
changeset | 197 | fun absent ixn = | 
| 
4002c4cd450c
Pure:  MAJOR CHANGE.  Moved ML types ctyp and cterm and their associated
 lcp parents: 
214diff
changeset | 198 |   error("No such variable in term: " ^ Syntax.string_of_vname ixn);
 | 
| 
4002c4cd450c
Pure:  MAJOR CHANGE.  Moved ML types ctyp and cterm and their associated
 lcp parents: 
214diff
changeset | 199 | |
| 
4002c4cd450c
Pure:  MAJOR CHANGE.  Moved ML types ctyp and cterm and their associated
 lcp parents: 
214diff
changeset | 200 | fun inst_failure ixn = | 
| 
4002c4cd450c
Pure:  MAJOR CHANGE.  Moved ML types ctyp and cterm and their associated
 lcp parents: 
214diff
changeset | 201 |   error("Instantiation of " ^ Syntax.string_of_vname ixn ^ " fails");
 | 
| 
4002c4cd450c
Pure:  MAJOR CHANGE.  Moved ML types ctyp and cterm and their associated
 lcp parents: 
214diff
changeset | 202 | |
| 4281 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 203 | fun read_insts sign (rtypes,rsorts) (types,sorts) used insts = | 
| 10403 | 204 | let | 
| 4281 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 205 | fun split([],tvs,vs) = (tvs,vs) | 
| 4691 | 206 | | split((sv,st)::l,tvs,vs) = (case Symbol.explode sv of | 
| 207 | "'"::cs => split(l,(Syntax.indexname cs,st)::tvs,vs) | |
| 208 | | cs => split(l,tvs,(Syntax.indexname cs,st)::vs)); | |
| 4281 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 209 | val (tvs,vs) = split(insts,[],[]); | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 210 | fun readT((a,i),st) = | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 211 |         let val ixn = ("'" ^ a,i);
 | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 212 | val S = case rsorts ixn of Some S => S | None => absent ixn; | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 213 | val T = Sign.read_typ (sign,sorts) st; | 
| 10403 | 214 | in if Sign.typ_instance sign (T, TVar(ixn,S)) then (ixn,T) | 
| 4281 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 215 | else inst_failure ixn | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 216 | end | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 217 | val tye = map readT tvs; | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 218 | fun mkty(ixn,st) = (case rtypes ixn of | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 219 | Some T => (ixn,(st,typ_subst_TVars tye T)) | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 220 | | None => absent ixn); | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 221 | val ixnsTs = map mkty vs; | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 222 | val ixns = map fst ixnsTs | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 223 | and sTs = map snd ixnsTs | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 224 | val (cts,tye2) = read_def_cterms(sign,types,sorts) used false sTs; | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 225 | fun mkcVar(ixn,T) = | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 226 | let val U = typ_subst_TVars tye2 T | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 227 | in cterm_of sign (Var(ixn,U)) end | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 228 | val ixnTs = ListPair.zip(ixns, map snd sTs) | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 229 | in (map (fn (ixn,T) => (ixn,ctyp_of sign T)) (tye2 @ tye), | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 230 | ListPair.zip(map mkcVar ixnTs,cts)) | 
| 
6c6073b13600
Added read_def_cterms for simultaneous reading/typing of terms under
 nipkow parents: 
4270diff
changeset | 231 | end; | 
| 229 
4002c4cd450c
Pure:  MAJOR CHANGE.  Moved ML types ctyp and cterm and their associated
 lcp parents: 
214diff
changeset | 232 | |
| 
4002c4cd450c
Pure:  MAJOR CHANGE.  Moved ML types ctyp and cterm and their associated
 lcp parents: 
214diff
changeset | 233 | |
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 234 | (*** Find the type (sort) associated with a (T)Var or (T)Free in a term | 
| 0 | 235 | Used for establishing default types (of variables) and sorts (of | 
| 236 | type variables) when reading another term. | |
| 237 | Index -1 indicates that a (T)Free rather than a (T)Var is wanted. | |
| 238 | ***) | |
| 239 | ||
| 240 | fun types_sorts thm = | |
| 241 |     let val {prop,hyps,...} = rep_thm thm;
 | |
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 242 | val big = list_comb(prop,hyps); (* bogus term! *) | 
| 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 243 | val vars = map dest_Var (term_vars big); | 
| 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 244 | val frees = map dest_Free (term_frees big); | 
| 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 245 | val tvars = term_tvars big; | 
| 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 246 | val tfrees = term_tfrees big; | 
| 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 247 | fun typ(a,i) = if i<0 then assoc(frees,a) else assoc(vars,(a,i)); | 
| 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 248 | fun sort(a,i) = if i<0 then assoc(tfrees,a) else assoc(tvars,(a,i)); | 
| 0 | 249 | in (typ,sort) end; | 
| 250 | ||
| 7636 | 251 | |
| 9455 | 252 | |
| 253 | (** basic attributes **) | |
| 254 | ||
| 255 | (* dependent rules *) | |
| 256 | ||
| 257 | fun rule_attribute f (x, thm) = (x, (f x thm)); | |
| 258 | ||
| 259 | ||
| 260 | (* add / delete tags *) | |
| 261 | ||
| 262 | fun map_tags f thm = | |
| 263 | Thm.put_name_tags (Thm.name_of_thm thm, f (#2 (Thm.get_name_tags thm))) thm; | |
| 264 | ||
| 265 | fun tag_rule tg = map_tags (fn tgs => if tg mem tgs then tgs else tgs @ [tg]); | |
| 266 | fun untag_rule s = map_tags (filter_out (equal s o #1)); | |
| 267 | ||
| 268 | fun tag tg x = rule_attribute (K (tag_rule tg)) x; | |
| 269 | fun untag s x = rule_attribute (K (untag_rule s)) x; | |
| 270 | ||
| 271 | fun simple_tag name x = tag (name, []) x; | |
| 272 | ||
| 11741 | 273 | |
| 274 | (* theorem kinds *) | |
| 275 | ||
| 276 | val theoremK = "theorem"; | |
| 277 | val lemmaK = "lemma"; | |
| 278 | val corollaryK = "corollary"; | |
| 279 | val internalK = "internal"; | |
| 9455 | 280 | |
| 11741 | 281 | fun get_kind thm = | 
| 282 | (case Library.assoc (#2 (Thm.get_name_tags thm), "kind") of | |
| 283 | Some (k :: _) => k | |
| 284 | | _ => "unknown"); | |
| 285 | ||
| 286 | fun kind_rule k = tag_rule ("kind", [k]) o untag_rule "kind";
 | |
| 12710 | 287 | fun kind k x = if k = "" then x else rule_attribute (K (kind_rule k)) x; | 
| 11741 | 288 | fun kind_internal x = kind internalK x; | 
| 289 | fun has_internal tags = exists (equal internalK o fst) tags; | |
| 9455 | 290 | |
| 291 | ||
| 292 | ||
| 0 | 293 | (** Standardization of rules **) | 
| 294 | ||
| 7636 | 295 | (*Strip extraneous shyps as far as possible*) | 
| 296 | fun strip_shyps_warning thm = | |
| 297 | let | |
| 298 | val str_of_sort = Sign.str_of_sort (Thm.sign_of_thm thm); | |
| 299 | val thm' = Thm.strip_shyps thm; | |
| 300 | val xshyps = Thm.extra_shyps thm'; | |
| 301 | in | |
| 302 | if null xshyps then () | |
| 303 |     else warning ("Pending sort hypotheses: " ^ commas (map str_of_sort xshyps));
 | |
| 304 | thm' | |
| 305 | end; | |
| 306 | ||
| 0 | 307 | (*Generalization over a list of variables, IGNORING bad ones*) | 
| 308 | fun forall_intr_list [] th = th | |
| 309 | | forall_intr_list (y::ys) th = | |
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 310 | let val gth = forall_intr_list ys th | 
| 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 311 | in forall_intr y gth handle THM _ => gth end; | 
| 0 | 312 | |
| 313 | (*Generalization over all suitable Free variables*) | |
| 314 | fun forall_intr_frees th = | |
| 315 |     let val {prop,sign,...} = rep_thm th
 | |
| 316 | in forall_intr_list | |
| 4440 | 317 | (map (cterm_of sign) (sort (make_ord atless) (term_frees prop))) | 
| 0 | 318 | th | 
| 319 | end; | |
| 320 | ||
| 7898 | 321 | val forall_elim_var = PureThy.forall_elim_var; | 
| 322 | val forall_elim_vars = PureThy.forall_elim_vars; | |
| 0 | 323 | |
| 12725 | 324 | fun gen_all thm = | 
| 12719 
41e0d086f8b6
improved forall_elim_vars_safe (no longer invents new indexes);
 wenzelm parents: 
12710diff
changeset | 325 | let | 
| 
41e0d086f8b6
improved forall_elim_vars_safe (no longer invents new indexes);
 wenzelm parents: 
12710diff
changeset | 326 |     val {sign, prop, maxidx, ...} = Thm.rep_thm thm;
 | 
| 
41e0d086f8b6
improved forall_elim_vars_safe (no longer invents new indexes);
 wenzelm parents: 
12710diff
changeset | 327 | fun elim (th, (x, T)) = Thm.forall_elim (Thm.cterm_of sign (Var ((x, maxidx + 1), T))) th; | 
| 
41e0d086f8b6
improved forall_elim_vars_safe (no longer invents new indexes);
 wenzelm parents: 
12710diff
changeset | 328 | val vs = Term.strip_all_vars prop; | 
| 
41e0d086f8b6
improved forall_elim_vars_safe (no longer invents new indexes);
 wenzelm parents: 
12710diff
changeset | 329 | in foldl elim (thm, Term.variantlist (map #1 vs, []) ~~ map #2 vs) end; | 
| 9554 | 330 | |
| 0 | 331 | (*Specialization over a list of cterms*) | 
| 332 | fun forall_elim_list cts th = foldr (uncurry forall_elim) (rev cts, th); | |
| 333 | ||
| 11815 | 334 | (* maps A1,...,An |- B to [| A1;...;An |] ==> B *) | 
| 0 | 335 | fun implies_intr_list cAs th = foldr (uncurry implies_intr) (cAs,th); | 
| 336 | ||
| 337 | (* maps [| A1;...;An |] ==> B and [A1,...,An] to B *) | |
| 338 | fun implies_elim_list impth ths = foldl (uncurry implies_elim) (impth,ths); | |
| 339 | ||
| 11960 | 340 | (* maps |- B to A1,...,An |- B *) | 
| 341 | fun impose_hyps chyps th = | |
| 12092 | 342 | let val chyps' = gen_rems (op aconv o apfst Thm.term_of) (chyps, #hyps (Thm.rep_thm th)) | 
| 343 | in implies_elim_list (implies_intr_list chyps' th) (map Thm.assume chyps') end; | |
| 11960 | 344 | |
| 13389 | 345 | (* maps A1,...,An and A1,...,An |- B to |- B *) | 
| 346 | fun satisfy_hyps ths th = | |
| 347 | implies_elim_list (implies_intr_list (map (#prop o Thm.crep_thm) ths) th) ths; | |
| 348 | ||
| 0 | 349 | (*Reset Var indexes to zero, renaming to preserve distinctness*) | 
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 350 | fun zero_var_indexes th = | 
| 0 | 351 |     let val {prop,sign,...} = rep_thm th;
 | 
| 352 | val vars = term_vars prop | |
| 353 | val bs = foldl add_new_id ([], map (fn Var((a,_),_)=>a) vars) | |
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 354 | val inrs = add_term_tvars(prop,[]); | 
| 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 355 | val nms' = rev(foldl add_new_id ([], map (#1 o #1) inrs)); | 
| 2266 | 356 | val tye = ListPair.map (fn ((v,rs),a) => (v, TVar((a,0),rs))) | 
| 8328 | 357 | (inrs, nms') | 
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 358 | val ctye = map (fn (v,T) => (v,ctyp_of sign T)) tye; | 
| 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 359 | fun varpairs([],[]) = [] | 
| 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 360 | | varpairs((var as Var(v,T)) :: vars, b::bs) = | 
| 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 361 | let val T' = typ_subst_TVars tye T | 
| 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 362 | in (cterm_of sign (Var(v,T')), | 
| 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 363 | cterm_of sign (Var((b,0),T'))) :: varpairs(vars,bs) | 
| 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 364 | end | 
| 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 365 |           | varpairs _ = raise TERM("varpairs", []);
 | 
| 8129 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 366 | in Thm.instantiate (ctye, varpairs(vars,rev bs)) th end; | 
| 0 | 367 | |
| 368 | ||
| 369 | (*Standard form of object-rule: no hypotheses, Frees, or outer quantifiers; | |
| 370 | all generality expressed by Vars having index 0.*) | |
| 10515 | 371 | |
| 372 | fun close_derivation thm = | |
| 373 |   if Thm.get_name_tags thm = ("", []) then Thm.name_thm ("", thm)
 | |
| 374 | else thm; | |
| 375 | ||
| 11512 
da3a96ab5630
Some basic rules are now stored with "open" derivations, to facilitate
 berghofe parents: 
11163diff
changeset | 376 | fun standard' th = | 
| 10515 | 377 |   let val {maxidx,...} = rep_thm th in
 | 
| 378 | th | |
| 379 | |> implies_intr_hyps | |
| 380 | |> forall_intr_frees |> forall_elim_vars (maxidx + 1) | |
| 381 | |> strip_shyps_warning | |
| 11512 
da3a96ab5630
Some basic rules are now stored with "open" derivations, to facilitate
 berghofe parents: 
11163diff
changeset | 382 | |> zero_var_indexes |> Thm.varifyT |> Thm.compress | 
| 1218 
59ed8ef1a3a1
modified pretty_thm, standard, eq_thm to handle shyps;
 wenzelm parents: 
1194diff
changeset | 383 | end; | 
| 
59ed8ef1a3a1
modified pretty_thm, standard, eq_thm to handle shyps;
 wenzelm parents: 
1194diff
changeset | 384 | |
| 11512 
da3a96ab5630
Some basic rules are now stored with "open" derivations, to facilitate
 berghofe parents: 
11163diff
changeset | 385 | val standard = close_derivation o standard'; | 
| 
da3a96ab5630
Some basic rules are now stored with "open" derivations, to facilitate
 berghofe parents: 
11163diff
changeset | 386 | |
| 12005 | 387 | fun local_standard th = | 
| 12221 
cc31140bba16
local_standard: plain strip_shyps instead of strip_shyps_warning;
 wenzelm parents: 
12135diff
changeset | 388 | th |> strip_shyps |> zero_var_indexes | 
| 12005 | 389 | |> Thm.compress |> close_derivation; | 
| 390 | ||
| 0 | 391 | |
| 8328 | 392 | (*Convert all Vars in a theorem to Frees. Also return a function for | 
| 4610 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 393 | reversing that operation. DOES NOT WORK FOR TYPE VARIABLES. | 
| 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 394 | Similar code in type/freeze_thaw*) | 
| 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 395 | fun freeze_thaw th = | 
| 7248 
322151fe6f02
new primitive rule permute_prems to underlie defer_tac and rotate_prems
 paulson parents: 
6995diff
changeset | 396 | let val fth = freezeT th | 
| 13659 
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
 berghofe parents: 
13650diff
changeset | 397 |      val {prop, tpairs, sign, ...} = rep_thm fth
 | 
| 7248 
322151fe6f02
new primitive rule permute_prems to underlie defer_tac and rotate_prems
 paulson parents: 
6995diff
changeset | 398 | in | 
| 13659 
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
 berghofe parents: 
13650diff
changeset | 399 | case foldr add_term_vars (prop :: Thm.terms_of_tpairs tpairs, []) of | 
| 7248 
322151fe6f02
new primitive rule permute_prems to underlie defer_tac and rotate_prems
 paulson parents: 
6995diff
changeset | 400 | [] => (fth, fn x => x) | 
| 
322151fe6f02
new primitive rule permute_prems to underlie defer_tac and rotate_prems
 paulson parents: 
6995diff
changeset | 401 | | vars => | 
| 8328 | 402 | let fun newName (Var(ix,_), (pairs,used)) = | 
| 403 | let val v = variant used (string_of_indexname ix) | |
| 404 | in ((ix,v)::pairs, v::used) end; | |
| 13659 
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
 berghofe parents: 
13650diff
changeset | 405 | val (alist, _) = foldr newName (vars, ([], foldr add_term_names | 
| 
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
 berghofe parents: 
13650diff
changeset | 406 | (prop :: Thm.terms_of_tpairs tpairs, []))) | 
| 8328 | 407 | fun mk_inst (Var(v,T)) = | 
| 408 | (cterm_of sign (Var(v,T)), | |
| 409 | cterm_of sign (Free(the (assoc(alist,v)), T))) | |
| 410 | val insts = map mk_inst vars | |
| 411 | fun thaw th' = | |
| 412 | th' |> forall_intr_list (map #2 insts) | |
| 413 | |> forall_elim_list (map #1 insts) | |
| 414 | in (Thm.instantiate ([],insts) fth, thaw) end | |
| 7248 
322151fe6f02
new primitive rule permute_prems to underlie defer_tac and rotate_prems
 paulson parents: 
6995diff
changeset | 415 | end; | 
| 4610 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 416 | |
| 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 417 | |
| 7248 
322151fe6f02
new primitive rule permute_prems to underlie defer_tac and rotate_prems
 paulson parents: 
6995diff
changeset | 418 | (*Rotates a rule's premises to the left by k*) | 
| 
322151fe6f02
new primitive rule permute_prems to underlie defer_tac and rotate_prems
 paulson parents: 
6995diff
changeset | 419 | val rotate_prems = permute_prems 0; | 
| 4610 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 420 | |
| 11163 | 421 | (* permute prems, where the i-th position in the argument list (counting from 0) | 
| 422 | gives the position within the original thm to be transferred to position i. | |
| 423 | Any remaining trailing positions are left unchanged. *) | |
| 424 | val rearrange_prems = let | |
| 425 | fun rearr new [] thm = thm | |
| 11815 | 426 | | rearr new (p::ps) thm = rearr (new+1) | 
| 11163 | 427 | (map (fn q => if new<=q andalso q<p then q+1 else q) ps) | 
| 428 | (permute_prems (new+1) (new-p) (permute_prems new (p-new) thm)) | |
| 429 | in rearr 0 end; | |
| 4610 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 430 | |
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 431 | (*Assume a new formula, read following the same conventions as axioms. | 
| 0 | 432 | Generalizes over Free variables, | 
| 433 | creates the assumption, and then strips quantifiers. | |
| 434 | Example is [| ALL x:?A. ?P(x) |] ==> [| ?P(?a) |] | |
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 435 | [ !(A,P,a)[| ALL x:A. P(x) |] ==> [| P(a) |] ] *) | 
| 0 | 436 | fun assume_ax thy sP = | 
| 6390 | 437 | let val sign = Theory.sign_of thy | 
| 4610 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 438 | val prop = Logic.close_form (term_of (read_cterm sign (sP, propT))) | 
| 229 
4002c4cd450c
Pure:  MAJOR CHANGE.  Moved ML types ctyp and cterm and their associated
 lcp parents: 
214diff
changeset | 439 | in forall_elim_vars 0 (assume (cterm_of sign prop)) end; | 
| 0 | 440 | |
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 441 | (*Resolution: exactly one resolvent must be produced.*) | 
| 0 | 442 | fun tha RSN (i,thb) = | 
| 4270 | 443 | case Seq.chop (2, biresolution false [(false,tha)] i thb) of | 
| 0 | 444 | ([th],_) => th | 
| 445 |     | ([],_)   => raise THM("RSN: no unifiers", i, [tha,thb])
 | |
| 446 |     |      _   => raise THM("RSN: multiple unifiers", i, [tha,thb]);
 | |
| 447 | ||
| 448 | (*resolution: P==>Q, Q==>R gives P==>R. *) | |
| 449 | fun tha RS thb = tha RSN (1,thb); | |
| 450 | ||
| 451 | (*For joining lists of rules*) | |
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 452 | fun thas RLN (i,thbs) = | 
| 0 | 453 | let val resolve = biresolution false (map (pair false) thas) i | 
| 4270 | 454 | fun resb thb = Seq.list_of (resolve thb) handle THM _ => [] | 
| 2672 
85d7e800d754
Replaced "flat" by the Basis Library function List.concat
 paulson parents: 
2266diff
changeset | 455 | in List.concat (map resb thbs) end; | 
| 0 | 456 | |
| 457 | fun thas RL thbs = thas RLN (1,thbs); | |
| 458 | ||
| 11 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML.  These support forward proof, resolving a
 lcp parents: 
0diff
changeset | 459 | (*Resolve a list of rules against bottom_rl from right to left; | 
| 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML.  These support forward proof, resolving a
 lcp parents: 
0diff
changeset | 460 | makes proof trees*) | 
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 461 | fun rls MRS bottom_rl = | 
| 11 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML.  These support forward proof, resolving a
 lcp parents: 
0diff
changeset | 462 | let fun rs_aux i [] = bottom_rl | 
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 463 | | rs_aux i (rl::rls) = rl RSN (i, rs_aux (i+1) rls) | 
| 11 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML.  These support forward proof, resolving a
 lcp parents: 
0diff
changeset | 464 | in rs_aux 1 rls end; | 
| 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML.  These support forward proof, resolving a
 lcp parents: 
0diff
changeset | 465 | |
| 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML.  These support forward proof, resolving a
 lcp parents: 
0diff
changeset | 466 | (*As above, but for rule lists*) | 
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 467 | fun rlss MRL bottom_rls = | 
| 11 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML.  These support forward proof, resolving a
 lcp parents: 
0diff
changeset | 468 | let fun rs_aux i [] = bottom_rls | 
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 469 | | rs_aux i (rls::rlss) = rls RLN (i, rs_aux (i+1) rlss) | 
| 11 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML.  These support forward proof, resolving a
 lcp parents: 
0diff
changeset | 470 | in rs_aux 1 rlss end; | 
| 
d0e17c42dbb4
Added MRS, MRL from ZF/ROOT.ML.  These support forward proof, resolving a
 lcp parents: 
0diff
changeset | 471 | |
| 9288 
06a55195741b
infix 'OF' is a version of 'MRS' with more appropriate argument order;
 wenzelm parents: 
8605diff
changeset | 472 | (*A version of MRS with more appropriate argument order*) | 
| 
06a55195741b
infix 'OF' is a version of 'MRS' with more appropriate argument order;
 wenzelm parents: 
8605diff
changeset | 473 | fun bottom_rl OF rls = rls MRS bottom_rl; | 
| 
06a55195741b
infix 'OF' is a version of 'MRS' with more appropriate argument order;
 wenzelm parents: 
8605diff
changeset | 474 | |
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 475 | (*compose Q and [...,Qi,Q(i+1),...]==>R to [...,Q(i+1),...]==>R | 
| 0 | 476 | with no lifting or renaming! Q may contain ==> or meta-quants | 
| 477 | ALWAYS deletes premise i *) | |
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 478 | fun compose(tha,i,thb) = | 
| 4270 | 479 | Seq.list_of (bicompose false (false,tha,0) i thb); | 
| 0 | 480 | |
| 6946 | 481 | fun compose_single (tha,i,thb) = | 
| 482 | (case compose (tha,i,thb) of | |
| 483 | [th] => th | |
| 484 |   | _ => raise THM ("compose: unique result expected", i, [tha,thb]));
 | |
| 485 | ||
| 0 | 486 | (*compose Q and [Q1,Q2,...,Qk]==>R to [Q2,...,Qk]==>R getting unique result*) | 
| 487 | fun tha COMP thb = | |
| 488 | case compose(tha,1,thb) of | |
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 489 | [th] => th | 
| 0 | 490 |       | _ =>   raise THM("COMP", 1, [tha,thb]);
 | 
| 491 | ||
| 13105 
3d1e7a199bdc
use eq_thm_prop instead of slightly inadequate eq_thm;
 wenzelm parents: 
12908diff
changeset | 492 | |
| 4016 | 493 | (** theorem equality **) | 
| 0 | 494 | |
| 13650 
31bd2a8cdbe2
fixing the cut_tac method to work when there are no instantiations and the
 paulson parents: 
13606diff
changeset | 495 | (*True if the two theorems have the same signature.*) | 
| 13105 
3d1e7a199bdc
use eq_thm_prop instead of slightly inadequate eq_thm;
 wenzelm parents: 
12908diff
changeset | 496 | val eq_thm_sg = Sign.eq_sg o pairself Thm.sign_of_thm; | 
| 13650 
31bd2a8cdbe2
fixing the cut_tac method to work when there are no instantiations and the
 paulson parents: 
13606diff
changeset | 497 | |
| 
31bd2a8cdbe2
fixing the cut_tac method to work when there are no instantiations and the
 paulson parents: 
13606diff
changeset | 498 | (*True if the two theorems have the same prop field, ignoring hyps, der, etc.*) | 
| 13105 
3d1e7a199bdc
use eq_thm_prop instead of slightly inadequate eq_thm;
 wenzelm parents: 
12908diff
changeset | 499 | val eq_thm_prop = op aconv o pairself Thm.prop_of; | 
| 0 | 500 | |
| 501 | (*Useful "distance" function for BEST_FIRST*) | |
| 12800 | 502 | val size_of_thm = size_of_term o prop_of; | 
| 0 | 503 | |
| 9829 | 504 | (*maintain lists of theorems --- preserving canonical order*) | 
| 13105 
3d1e7a199bdc
use eq_thm_prop instead of slightly inadequate eq_thm;
 wenzelm parents: 
12908diff
changeset | 505 | fun del_rules rs rules = Library.gen_rems eq_thm_prop (rules, rs); | 
| 9862 | 506 | fun add_rules rs rules = rs @ del_rules rs rules; | 
| 12373 | 507 | val del_rule = del_rules o single; | 
| 508 | val add_rule = add_rules o single; | |
| 13105 
3d1e7a199bdc
use eq_thm_prop instead of slightly inadequate eq_thm;
 wenzelm parents: 
12908diff
changeset | 509 | fun merge_rules (rules1, rules2) = gen_merge_lists' eq_thm_prop rules1 rules2; | 
| 9829 | 510 | |
| 0 | 511 | |
| 1194 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 512 | (** Mark Staples's weaker version of eq_thm: ignores variable renaming and | 
| 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 513 | (some) type variable renaming **) | 
| 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 514 | |
| 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 515 | (* Can't use term_vars, because it sorts the resulting list of variable names. | 
| 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 516 | We instead need the unique list noramlised by the order of appearance | 
| 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 517 | in the term. *) | 
| 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 518 | fun term_vars' (t as Var(v,T)) = [t] | 
| 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 519 | | term_vars' (Abs(_,_,b)) = term_vars' b | 
| 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 520 | | term_vars' (f$a) = (term_vars' f) @ (term_vars' a) | 
| 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 521 | | term_vars' _ = []; | 
| 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 522 | |
| 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 523 | fun forall_intr_vars th = | 
| 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 524 |   let val {prop,sign,...} = rep_thm th;
 | 
| 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 525 | val vars = distinct (term_vars' prop); | 
| 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 526 | in forall_intr_list (map (cterm_of sign) vars) th end; | 
| 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 527 | |
| 13105 
3d1e7a199bdc
use eq_thm_prop instead of slightly inadequate eq_thm;
 wenzelm parents: 
12908diff
changeset | 528 | val weak_eq_thm = Thm.eq_thm o pairself (forall_intr_vars o freezeT); | 
| 1194 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 529 | |
| 
563ecd14c1d8
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
 lcp parents: 
952diff
changeset | 530 | |
| 0 | 531 | (*** Meta-Rewriting Rules ***) | 
| 532 | ||
| 4610 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 533 | fun read_prop s = read_cterm proto_sign (s, propT); | 
| 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 534 | |
| 9455 | 535 | fun store_thm name thm = hd (PureThy.smart_store_thms (name, [thm])); | 
| 536 | fun store_standard_thm name thm = store_thm name (standard thm); | |
| 12135 | 537 | fun store_thm_open name thm = hd (PureThy.smart_store_thms_open (name, [thm])); | 
| 538 | fun store_standard_thm_open name thm = store_thm_open name (standard' thm); | |
| 4016 | 539 | |
| 0 | 540 | val reflexive_thm = | 
| 4610 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 541 |   let val cx = cterm_of proto_sign (Var(("x",0),TVar(("'a",0),logicS)))
 | 
| 12135 | 542 | in store_standard_thm_open "reflexive" (Thm.reflexive cx) end; | 
| 0 | 543 | |
| 544 | val symmetric_thm = | |
| 4610 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 545 | let val xy = read_prop "x::'a::logic == y" | 
| 12135 | 546 | in store_standard_thm_open "symmetric" (Thm.implies_intr_hyps (Thm.symmetric (Thm.assume xy))) end; | 
| 0 | 547 | |
| 548 | val transitive_thm = | |
| 4610 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 549 | let val xy = read_prop "x::'a::logic == y" | 
| 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 550 | val yz = read_prop "y::'a::logic == z" | 
| 0 | 551 | val xythm = Thm.assume xy and yzthm = Thm.assume yz | 
| 12135 | 552 | in store_standard_thm_open "transitive" (Thm.implies_intr yz (Thm.transitive xythm yzthm)) end; | 
| 0 | 553 | |
| 4679 | 554 | fun symmetric_fun thm = thm RS symmetric_thm; | 
| 555 | ||
| 11512 
da3a96ab5630
Some basic rules are now stored with "open" derivations, to facilitate
 berghofe parents: 
11163diff
changeset | 556 | fun extensional eq = | 
| 
da3a96ab5630
Some basic rules are now stored with "open" derivations, to facilitate
 berghofe parents: 
11163diff
changeset | 557 | let val eq' = | 
| 
da3a96ab5630
Some basic rules are now stored with "open" derivations, to facilitate
 berghofe parents: 
11163diff
changeset | 558 | abstract_rule "x" (snd (Thm.dest_comb (fst (dest_equals (cprop_of eq))))) eq | 
| 
da3a96ab5630
Some basic rules are now stored with "open" derivations, to facilitate
 berghofe parents: 
11163diff
changeset | 559 | in equal_elim (eta_conversion (cprop_of eq')) eq' end; | 
| 
da3a96ab5630
Some basic rules are now stored with "open" derivations, to facilitate
 berghofe parents: 
11163diff
changeset | 560 | |
| 10414 | 561 | val imp_cong = | 
| 562 | let | |
| 563 | val ABC = read_prop "PROP A ==> PROP B == PROP C" | |
| 564 | val AB = read_prop "PROP A ==> PROP B" | |
| 565 | val AC = read_prop "PROP A ==> PROP C" | |
| 566 | val A = read_prop "PROP A" | |
| 567 | in | |
| 12135 | 568 | store_standard_thm_open "imp_cong" (implies_intr ABC (equal_intr | 
| 10414 | 569 | (implies_intr AB (implies_intr A | 
| 570 | (equal_elim (implies_elim (assume ABC) (assume A)) | |
| 571 | (implies_elim (assume AB) (assume A))))) | |
| 572 | (implies_intr AC (implies_intr A | |
| 573 | (equal_elim (symmetric (implies_elim (assume ABC) (assume A))) | |
| 574 | (implies_elim (assume AC) (assume A))))))) | |
| 575 | end; | |
| 576 | ||
| 577 | val swap_prems_eq = | |
| 578 | let | |
| 579 | val ABC = read_prop "PROP A ==> PROP B ==> PROP C" | |
| 580 | val BAC = read_prop "PROP B ==> PROP A ==> PROP C" | |
| 581 | val A = read_prop "PROP A" | |
| 582 | val B = read_prop "PROP B" | |
| 583 | in | |
| 12135 | 584 | store_standard_thm_open "swap_prems_eq" (equal_intr | 
| 10414 | 585 | (implies_intr ABC (implies_intr B (implies_intr A | 
| 586 | (implies_elim (implies_elim (assume ABC) (assume A)) (assume B))))) | |
| 587 | (implies_intr BAC (implies_intr A (implies_intr B | |
| 588 | (implies_elim (implies_elim (assume BAC) (assume B)) (assume A)))))) | |
| 589 | end; | |
| 229 
4002c4cd450c
Pure:  MAJOR CHANGE.  Moved ML types ctyp and cterm and their associated
 lcp parents: 
214diff
changeset | 590 | |
| 9547 | 591 | val refl_implies = reflexive implies; | 
| 0 | 592 | |
| 13325 | 593 | fun abs_def thm = | 
| 594 | let | |
| 595 | val (_, cvs) = strip_comb (fst (dest_equals (cprop_of thm))); | |
| 596 | val thm' = foldr (fn (ct, thm) => Thm.abstract_rule | |
| 597 | (case term_of ct of Var ((a, _), _) => a | Free (a, _) => a | _ => "x") | |
| 598 | ct thm) (cvs, thm) | |
| 599 | in transitive | |
| 600 | (symmetric (eta_conversion (fst (dest_equals (cprop_of thm'))))) thm' | |
| 601 | end; | |
| 602 | ||
| 0 | 603 | |
| 604 | (*** Some useful meta-theorems ***) | |
| 605 | ||
| 606 | (*The rule V/V, obtains assumption solving for eresolve_tac*) | |
| 12135 | 607 | val asm_rl = store_standard_thm_open "asm_rl" (Thm.trivial (read_prop "PROP ?psi")); | 
| 7380 | 608 | val _ = store_thm "_" asm_rl; | 
| 0 | 609 | |
| 610 | (*Meta-level cut rule: [| V==>W; V |] ==> W *) | |
| 4016 | 611 | val cut_rl = | 
| 12135 | 612 | store_standard_thm_open "cut_rl" | 
| 9455 | 613 | (Thm.trivial (read_prop "PROP ?psi ==> PROP ?theta")); | 
| 0 | 614 | |
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 615 | (*Generalized elim rule for one conclusion; cut_rl with reversed premises: | 
| 0 | 616 | [| PROP V; PROP V ==> PROP W |] ==> PROP W *) | 
| 617 | val revcut_rl = | |
| 4610 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 618 | let val V = read_prop "PROP V" | 
| 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 619 | and VW = read_prop "PROP V ==> PROP W"; | 
| 4016 | 620 | in | 
| 12135 | 621 | store_standard_thm_open "revcut_rl" | 
| 4016 | 622 | (implies_intr V (implies_intr VW (implies_elim (assume VW) (assume V)))) | 
| 0 | 623 | end; | 
| 624 | ||
| 668 | 625 | (*for deleting an unwanted assumption*) | 
| 626 | val thin_rl = | |
| 4610 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 627 | let val V = read_prop "PROP V" | 
| 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 628 | and W = read_prop "PROP W"; | 
| 12135 | 629 | in store_standard_thm_open "thin_rl" (implies_intr V (implies_intr W (assume W))) end; | 
| 668 | 630 | |
| 0 | 631 | (* (!!x. PROP ?V) == PROP ?V Allows removal of redundant parameters*) | 
| 632 | val triv_forall_equality = | |
| 4610 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 633 | let val V = read_prop "PROP V" | 
| 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 634 | and QV = read_prop "!!x::'a. PROP V" | 
| 8086 | 635 |       and x  = read_cterm proto_sign ("x", TypeInfer.logicT);
 | 
| 4016 | 636 | in | 
| 12135 | 637 | store_standard_thm_open "triv_forall_equality" | 
| 11512 
da3a96ab5630
Some basic rules are now stored with "open" derivations, to facilitate
 berghofe parents: 
11163diff
changeset | 638 | (equal_intr (implies_intr QV (forall_elim x (assume QV))) | 
| 
da3a96ab5630
Some basic rules are now stored with "open" derivations, to facilitate
 berghofe parents: 
11163diff
changeset | 639 | (implies_intr V (forall_intr x (assume V)))) | 
| 0 | 640 | end; | 
| 641 | ||
| 1756 | 642 | (* (PROP ?PhiA ==> PROP ?PhiB ==> PROP ?Psi) ==> | 
| 643 | (PROP ?PhiB ==> PROP ?PhiA ==> PROP ?Psi) | |
| 644 | `thm COMP swap_prems_rl' swaps the first two premises of `thm' | |
| 645 | *) | |
| 646 | val swap_prems_rl = | |
| 4610 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 647 | let val cmajor = read_prop "PROP PhiA ==> PROP PhiB ==> PROP Psi"; | 
| 1756 | 648 | val major = assume cmajor; | 
| 4610 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 649 | val cminor1 = read_prop "PROP PhiA"; | 
| 1756 | 650 | val minor1 = assume cminor1; | 
| 4610 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 651 | val cminor2 = read_prop "PROP PhiB"; | 
| 1756 | 652 | val minor2 = assume cminor2; | 
| 12135 | 653 | in store_standard_thm_open "swap_prems_rl" | 
| 1756 | 654 | (implies_intr cmajor (implies_intr cminor2 (implies_intr cminor1 | 
| 655 | (implies_elim (implies_elim major minor1) minor2)))) | |
| 656 | end; | |
| 657 | ||
| 3653 | 658 | (* [| PROP ?phi ==> PROP ?psi; PROP ?psi ==> PROP ?phi |] | 
| 659 | ==> PROP ?phi == PROP ?psi | |
| 8328 | 660 | Introduction rule for == as a meta-theorem. | 
| 3653 | 661 | *) | 
| 662 | val equal_intr_rule = | |
| 4610 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 663 | let val PQ = read_prop "PROP phi ==> PROP psi" | 
| 
b1322be47244
Tidying; rotate_prems; moved freeze_thaw from tactic.ML
 paulson parents: 
4588diff
changeset | 664 | and QP = read_prop "PROP psi ==> PROP phi" | 
| 4016 | 665 | in | 
| 12135 | 666 | store_standard_thm_open "equal_intr_rule" | 
| 4016 | 667 | (implies_intr PQ (implies_intr QP (equal_intr (assume PQ) (assume QP)))) | 
| 3653 | 668 | end; | 
| 669 | ||
| 13368 | 670 | (* [| PROP ?phi == PROP ?psi; PROP ?phi |] ==> PROP ?psi *) | 
| 671 | val equal_elim_rule1 = | |
| 672 | let val eq = read_prop "PROP phi == PROP psi" | |
| 673 | and P = read_prop "PROP phi" | |
| 674 | in store_standard_thm_open "equal_elim_rule1" | |
| 675 | (Thm.equal_elim (assume eq) (assume P) |> implies_intr_list [eq, P]) | |
| 676 | end; | |
| 4285 | 677 | |
| 12297 | 678 | (* "[| PROP ?phi; PROP ?phi; PROP ?psi |] ==> PROP ?psi" *) | 
| 679 | ||
| 680 | val remdups_rl = | |
| 681 | let val P = read_prop "PROP phi" and Q = read_prop "PROP psi"; | |
| 682 | in store_standard_thm_open "remdups_rl" (implies_intr_list [P, P, Q] (Thm.assume Q)) end; | |
| 683 | ||
| 684 | ||
| 9554 | 685 | (*(PROP ?phi ==> (!!x. PROP ?psi(x))) == (!!x. PROP ?phi ==> PROP ?psi(x)) | 
| 12297 | 686 | Rewrite rule for HHF normalization.*) | 
| 9554 | 687 | |
| 688 | val norm_hhf_eq = | |
| 689 | let | |
| 690 | val cert = Thm.cterm_of proto_sign; | |
| 691 |     val aT = TFree ("'a", Term.logicS);
 | |
| 692 | val all = Term.all aT; | |
| 693 |     val x = Free ("x", aT);
 | |
| 694 |     val phi = Free ("phi", propT);
 | |
| 695 |     val psi = Free ("psi", aT --> propT);
 | |
| 696 | ||
| 697 | val cx = cert x; | |
| 698 | val cphi = cert phi; | |
| 699 |     val lhs = cert (Logic.mk_implies (phi, all $ Abs ("x", aT, psi $ Bound 0)));
 | |
| 700 |     val rhs = cert (all $ Abs ("x", aT, Logic.mk_implies (phi, psi $ Bound 0)));
 | |
| 701 | in | |
| 702 | Thm.equal_intr | |
| 703 | (Thm.implies_elim (Thm.assume lhs) (Thm.assume cphi) | |
| 704 | |> Thm.forall_elim cx | |
| 705 | |> Thm.implies_intr cphi | |
| 706 | |> Thm.forall_intr cx | |
| 707 | |> Thm.implies_intr lhs) | |
| 708 | (Thm.implies_elim | |
| 709 | (Thm.assume rhs |> Thm.forall_elim cx) (Thm.assume cphi) | |
| 710 | |> Thm.forall_intr cx | |
| 711 | |> Thm.implies_intr cphi | |
| 712 | |> Thm.implies_intr rhs) | |
| 12135 | 713 | |> store_standard_thm_open "norm_hhf_eq" | 
| 9554 | 714 | end; | 
| 715 | ||
| 12800 | 716 | fun is_norm_hhf tm = | 
| 717 | let | |
| 718 |     fun is_norm (Const ("==>", _) $ _ $ (Const ("all", _) $ _)) = false
 | |
| 719 | | is_norm (t $ u) = is_norm t andalso is_norm u | |
| 720 | | is_norm (Abs (_, _, t)) = is_norm t | |
| 721 | | is_norm _ = true; | |
| 722 | in is_norm (Pattern.beta_eta_contract tm) end; | |
| 723 | ||
| 724 | fun norm_hhf sg t = | |
| 725 | if is_norm_hhf t then t | |
| 13198 | 726 | else Pattern.rewrite_term (Sign.tsig_of sg) [Logic.dest_equals (prop_of norm_hhf_eq)] [] t; | 
| 12800 | 727 | |
| 9554 | 728 | |
| 8129 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 729 | (*** Instantiate theorem th, reading instantiations under signature sg ****) | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 730 | |
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 731 | (*Version that normalizes the result: Thm.instantiate no longer does that*) | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 732 | fun instantiate instpair th = Thm.instantiate instpair th COMP asm_rl; | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 733 | |
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 734 | fun read_instantiate_sg sg sinsts th = | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 735 | let val ts = types_sorts th; | 
| 12800 | 736 | val used = add_term_tvarnames (prop_of th, []); | 
| 8129 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 737 | in instantiate (read_insts sg ts ts used sinsts) th end; | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 738 | |
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 739 | (*Instantiate theorem th, reading instantiations under theory of th*) | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 740 | fun read_instantiate sinsts th = | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 741 | read_instantiate_sg (#sign (rep_thm th)) sinsts th; | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 742 | |
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 743 | |
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 744 | (*Left-to-right replacements: tpairs = [...,(vi,ti),...]. | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 745 | Instantiates distinct Vars by terms, inferring type instantiations. *) | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 746 | local | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 747 | fun add_types ((ct,cu), (sign,tye,maxidx)) = | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 748 |     let val {sign=signt, t=t, T= T, maxidx=maxt,...} = rep_cterm ct
 | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 749 |         and {sign=signu, t=u, T= U, maxidx=maxu,...} = rep_cterm cu;
 | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 750 | val maxi = Int.max(maxidx, Int.max(maxt, maxu)); | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 751 | val sign' = Sign.merge(sign, Sign.merge(signt, signu)) | 
| 12527 | 752 | val (tye',maxi') = Type.unify (#tsig(Sign.rep_sg sign')) (tye, maxi) (T, U) | 
| 10403 | 753 |           handle Type.TUNIFY => raise TYPE("Ill-typed instantiation", [T,U], [t,u])
 | 
| 8129 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 754 | in (sign', tye', maxi') end; | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 755 | in | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 756 | fun cterm_instantiate ctpairs0 th = | 
| 8406 
a217b0cd304d
Type.unify and Type.typ_match now use Vartab instead of association lists.
 berghofe parents: 
8365diff
changeset | 757 | let val (sign,tye,_) = foldr add_types (ctpairs0, (#sign(rep_thm th), Vartab.empty, 0)) | 
| 
a217b0cd304d
Type.unify and Type.typ_match now use Vartab instead of association lists.
 berghofe parents: 
8365diff
changeset | 758 | fun instT(ct,cu) = let val inst = subst_TVars_Vartab tye | 
| 8129 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 759 | in (cterm_fun inst ct, cterm_fun inst cu) end | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 760 | fun ctyp2 (ix,T) = (ix, ctyp_of sign T) | 
| 8406 
a217b0cd304d
Type.unify and Type.typ_match now use Vartab instead of association lists.
 berghofe parents: 
8365diff
changeset | 761 | in instantiate (map ctyp2 (Vartab.dest tye), map instT ctpairs0) th end | 
| 8129 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 762 | handle TERM _ => | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 763 |            raise THM("cterm_instantiate: incompatible signatures",0,[th])
 | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 764 | | TYPE (msg, _, _) => raise THM(msg, 0, [th]) | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 765 | end; | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 766 | |
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 767 | |
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 768 | (** Derived rules mainly for METAHYPS **) | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 769 | |
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 770 | (*Given the term "a", takes (%x.t)==(%x.u) to t[a/x]==u[a/x]*) | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 771 | fun equal_abs_elim ca eqth = | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 772 |   let val {sign=signa, t=a, ...} = rep_cterm ca
 | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 773 | and combth = combination eqth (reflexive ca) | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 774 |       val {sign,prop,...} = rep_thm eqth
 | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 775 | val (abst,absu) = Logic.dest_equals prop | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 776 | val cterm = cterm_of (Sign.merge (sign,signa)) | 
| 10414 | 777 | in transitive (symmetric (beta_conversion false (cterm (abst$a)))) | 
| 778 | (transitive combth (beta_conversion false (cterm (absu$a)))) | |
| 8129 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 779 | end | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 780 |   handle THM _ => raise THM("equal_abs_elim", 0, [eqth]);
 | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 781 | |
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 782 | (*Calling equal_abs_elim with multiple terms*) | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 783 | fun equal_abs_elim_list cts th = foldr (uncurry equal_abs_elim) (rev cts, th); | 
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 784 | |
| 
29e239c7b8c2
Thm.instantiate no longer normalizes, but Drule.instantiate does
 paulson parents: 
8086diff
changeset | 785 | |
| 10667 | 786 | (*** Goal (PROP A) <==> PROP A ***) | 
| 4789 | 787 | |
| 788 | local | |
| 10667 | 789 | val cert = Thm.cterm_of proto_sign; | 
| 790 |   val A = Free ("A", propT);
 | |
| 791 | val G = Logic.mk_goal A; | |
| 4789 | 792 | val (G_def, _) = freeze_thaw ProtoPure.Goal_def; | 
| 793 | in | |
| 11741 | 794 | val triv_goal = store_thm "triv_goal" (kind_rule internalK (standard | 
| 10667 | 795 | (Thm.equal_elim (Thm.symmetric G_def) (Thm.assume (cert A))))); | 
| 11741 | 796 | val rev_triv_goal = store_thm "rev_triv_goal" (kind_rule internalK (standard | 
| 10667 | 797 | (Thm.equal_elim G_def (Thm.assume (cert G))))); | 
| 4789 | 798 | end; | 
| 799 | ||
| 9460 | 800 | val mk_cgoal = Thm.capply (Thm.cterm_of proto_sign Logic.goal_const); | 
| 6995 | 801 | fun assume_goal ct = Thm.assume (mk_cgoal ct) RS rev_triv_goal; | 
| 802 | ||
| 11815 | 803 | fun implies_intr_goals cprops thm = | 
| 804 | implies_elim_list (implies_intr_list cprops thm) (map assume_goal cprops) | |
| 805 | |> implies_intr_list (map mk_cgoal cprops); | |
| 806 | ||
| 4789 | 807 | |
| 4285 | 808 | |
| 5688 | 809 | (** variations on instantiate **) | 
| 4285 | 810 | |
| 8550 
b44c185f8018
new meta-rule "inst", a shorthand for read_instantiate_sg
 paulson parents: 
8496diff
changeset | 811 | (*shorthand for instantiating just one variable in the current theory*) | 
| 
b44c185f8018
new meta-rule "inst", a shorthand for read_instantiate_sg
 paulson parents: 
8496diff
changeset | 812 | fun inst x t = read_instantiate_sg (sign_of (the_context())) [(x,t)]; | 
| 
b44c185f8018
new meta-rule "inst", a shorthand for read_instantiate_sg
 paulson parents: 
8496diff
changeset | 813 | |
| 
b44c185f8018
new meta-rule "inst", a shorthand for read_instantiate_sg
 paulson parents: 
8496diff
changeset | 814 | |
| 12495 | 815 | (* collect vars in left-to-right order *) | 
| 4285 | 816 | |
| 12495 | 817 | fun tvars_of_terms ts = rev (foldl Term.add_tvars ([], ts)); | 
| 818 | fun vars_of_terms ts = rev (foldl Term.add_vars ([], ts)); | |
| 5903 | 819 | |
| 12800 | 820 | fun tvars_of thm = tvars_of_terms [prop_of thm]; | 
| 821 | fun vars_of thm = vars_of_terms [prop_of thm]; | |
| 4285 | 822 | |
| 823 | ||
| 824 | (* instantiate by left-to-right occurrence of variables *) | |
| 825 | ||
| 826 | fun instantiate' cTs cts thm = | |
| 827 | let | |
| 828 | fun err msg = | |
| 829 |       raise TYPE ("instantiate': " ^ msg,
 | |
| 830 | mapfilter (apsome Thm.typ_of) cTs, | |
| 831 | mapfilter (apsome Thm.term_of) cts); | |
| 832 | ||
| 833 | fun inst_of (v, ct) = | |
| 834 | (Thm.cterm_of (#sign (Thm.rep_cterm ct)) (Var v), ct) | |
| 835 | handle TYPE (msg, _, _) => err msg; | |
| 836 | ||
| 837 | fun zip_vars _ [] = [] | |
| 838 | | zip_vars (_ :: vs) (None :: opt_ts) = zip_vars vs opt_ts | |
| 839 | | zip_vars (v :: vs) (Some t :: opt_ts) = (v, t) :: zip_vars vs opt_ts | |
| 840 | | zip_vars [] _ = err "more instantiations than variables in thm"; | |
| 841 | ||
| 842 | (*instantiate types first!*) | |
| 843 | val thm' = | |
| 844 | if forall is_none cTs then thm | |
| 845 | else Thm.instantiate (zip_vars (map fst (tvars_of thm)) cTs, []) thm; | |
| 846 | in | |
| 847 | if forall is_none cts then thm' | |
| 848 | else Thm.instantiate ([], map inst_of (zip_vars (vars_of thm') cts)) thm' | |
| 849 | end; | |
| 850 | ||
| 851 | ||
| 5688 | 852 | (* unvarify(T) *) | 
| 853 | ||
| 854 | (*assume thm in standard form, i.e. no frees, 0 var indexes*) | |
| 855 | ||
| 856 | fun unvarifyT thm = | |
| 857 | let | |
| 858 | val cT = Thm.ctyp_of (Thm.sign_of_thm thm); | |
| 859 | val tfrees = map (fn ((x, _), S) => Some (cT (TFree (x, S)))) (tvars_of thm); | |
| 860 | in instantiate' tfrees [] thm end; | |
| 861 | ||
| 862 | fun unvarify raw_thm = | |
| 863 | let | |
| 864 | val thm = unvarifyT raw_thm; | |
| 865 | val ct = Thm.cterm_of (Thm.sign_of_thm thm); | |
| 866 | val frees = map (fn ((x, _), T) => Some (ct (Free (x, T)))) (vars_of thm); | |
| 867 | in instantiate' [] frees thm end; | |
| 868 | ||
| 869 | ||
| 8605 | 870 | (* tvars_intr_list *) | 
| 871 | ||
| 872 | fun tfrees_of thm = | |
| 873 |   let val {hyps, prop, ...} = Thm.rep_thm thm
 | |
| 874 | in foldr Term.add_term_tfree_names (prop :: hyps, []) end; | |
| 875 | ||
| 876 | fun tvars_intr_list tfrees thm = | |
| 877 | Thm.varifyT' (tfrees_of thm \\ tfrees) thm; | |
| 878 | ||
| 879 | ||
| 6435 | 880 | (* increment var indexes *) | 
| 881 | ||
| 882 | fun incr_indexes_wrt is cTs cts thms = | |
| 883 | let | |
| 884 | val maxidx = | |
| 885 | foldl Int.max (~1, is @ | |
| 886 | map (maxidx_of_typ o #T o Thm.rep_ctyp) cTs @ | |
| 887 | map (#maxidx o Thm.rep_cterm) cts @ | |
| 888 | map (#maxidx o Thm.rep_thm) thms); | |
| 10414 | 889 | in Thm.incr_indexes (maxidx + 1) end; | 
| 6435 | 890 | |
| 891 | ||
| 8328 | 892 | (* freeze_all *) | 
| 893 | ||
| 894 | (*freeze all (T)Vars; assumes thm in standard form*) | |
| 895 | ||
| 896 | fun freeze_all_TVars thm = | |
| 897 | (case tvars_of thm of | |
| 898 | [] => thm | |
| 899 | | tvars => | |
| 900 | let val cert = Thm.ctyp_of (Thm.sign_of_thm thm) | |
| 901 | in instantiate' (map (fn ((x, _), S) => Some (cert (TFree (x, S)))) tvars) [] thm end); | |
| 902 | ||
| 903 | fun freeze_all_Vars thm = | |
| 904 | (case vars_of thm of | |
| 905 | [] => thm | |
| 906 | | vars => | |
| 907 | let val cert = Thm.cterm_of (Thm.sign_of_thm thm) | |
| 908 | in instantiate' [] (map (fn ((x, _), T) => Some (cert (Free (x, T)))) vars) thm end); | |
| 909 | ||
| 910 | val freeze_all = freeze_all_Vars o freeze_all_TVars; | |
| 911 | ||
| 912 | ||
| 5688 | 913 | (* mk_triv_goal *) | 
| 914 | ||
| 915 | (*make an initial proof state, "PROP A ==> (PROP A)" *) | |
| 5311 
f3f71669878e
Rule mk_triv_goal for making instances of triv_goal
 paulson parents: 
5079diff
changeset | 916 | fun mk_triv_goal ct = instantiate' [] [Some ct] triv_goal; | 
| 
f3f71669878e
Rule mk_triv_goal for making instances of triv_goal
 paulson parents: 
5079diff
changeset | 917 | |
| 11975 | 918 | |
| 919 | ||
| 920 | (** meta-level conjunction **) | |
| 921 | ||
| 922 | local | |
| 923 | val A = read_prop "PROP A"; | |
| 924 | val B = read_prop "PROP B"; | |
| 925 | val C = read_prop "PROP C"; | |
| 926 | val ABC = read_prop "PROP A ==> PROP B ==> PROP C"; | |
| 927 | ||
| 928 | val proj1 = | |
| 929 | forall_intr_list [A, B] (implies_intr_list [A, B] (Thm.assume A)) | |
| 930 | |> forall_elim_vars 0; | |
| 931 | ||
| 932 | val proj2 = | |
| 933 | forall_intr_list [A, B] (implies_intr_list [A, B] (Thm.assume B)) | |
| 934 | |> forall_elim_vars 0; | |
| 935 | ||
| 936 | val conj_intr_rule = | |
| 937 | forall_intr_list [A, B] (implies_intr_list [A, B] | |
| 938 | (Thm.forall_intr C (Thm.implies_intr ABC | |
| 939 | (implies_elim_list (Thm.assume ABC) [Thm.assume A, Thm.assume B])))) | |
| 940 | |> forall_elim_vars 0; | |
| 941 | ||
| 942 | val incr = incr_indexes_wrt [] [] []; | |
| 943 | in | |
| 944 | ||
| 945 | fun conj_intr tha thb = thb COMP (tha COMP incr [tha, thb] conj_intr_rule); | |
| 12756 
08bf3d911968
conj_intr_list and conj_elim_precise: cover 0 conjuncts;
 wenzelm parents: 
12725diff
changeset | 946 | |
| 
08bf3d911968
conj_intr_list and conj_elim_precise: cover 0 conjuncts;
 wenzelm parents: 
12725diff
changeset | 947 | fun conj_intr_list [] = asm_rl | 
| 
08bf3d911968
conj_intr_list and conj_elim_precise: cover 0 conjuncts;
 wenzelm parents: 
12725diff
changeset | 948 | | conj_intr_list ths = foldr1 (uncurry conj_intr) ths; | 
| 11975 | 949 | |
| 950 | fun conj_elim th = | |
| 951 | let val th' = forall_elim_var (#maxidx (Thm.rep_thm th) + 1) th | |
| 952 | in (incr [th'] proj1 COMP th', incr [th'] proj2 COMP th') end; | |
| 953 | ||
| 954 | fun conj_elim_list th = | |
| 955 | let val (th1, th2) = conj_elim th | |
| 956 | in conj_elim_list th1 @ conj_elim_list th2 end handle THM _ => [th]; | |
| 957 | ||
| 12756 
08bf3d911968
conj_intr_list and conj_elim_precise: cover 0 conjuncts;
 wenzelm parents: 
12725diff
changeset | 958 | fun conj_elim_precise 0 _ = [] | 
| 
08bf3d911968
conj_intr_list and conj_elim_precise: cover 0 conjuncts;
 wenzelm parents: 
12725diff
changeset | 959 | | conj_elim_precise 1 th = [th] | 
| 12135 | 960 | | conj_elim_precise n th = | 
| 961 | let val (th1, th2) = conj_elim th | |
| 962 | in th1 :: conj_elim_precise (n - 1) th2 end; | |
| 963 | ||
| 964 | val conj_intr_thm = store_standard_thm_open "conjunctionI" | |
| 965 | (implies_intr_list [A, B] (conj_intr (Thm.assume A) (Thm.assume B))); | |
| 966 | ||
| 0 | 967 | end; | 
| 252 
7532f95d7f44
removed eq_sg, pprint_sg, print_sg (now in sign.ML);
 wenzelm parents: 
229diff
changeset | 968 | |
| 11975 | 969 | end; | 
| 5903 | 970 | |
| 971 | structure BasicDrule: BASIC_DRULE = Drule; | |
| 972 | open BasicDrule; |