| author | wenzelm | 
| Fri, 18 Nov 2011 22:32:57 +0100 | |
| changeset 45582 | 78f59aaa30ff | 
| parent 45344 | e209da839ff4 | 
| child 46215 | 0da9433f959e | 
| permissions | -rw-r--r-- | 
| 9460 | 1 | (* Title: Pure/logic.ML | 
| 2 | Author: Lawrence C Paulson, Cambridge University Computer Laboratory | |
| 29276 | 3 | Author: Makarius | 
| 0 | 4 | |
| 9460 | 5 | Abstract syntax operations of the Pure meta-logic. | 
| 0 | 6 | *) | 
| 7 | ||
| 9460 | 8 | signature LOGIC = | 
| 4345 | 9 | sig | 
| 27334 | 10 | val all: term -> term -> term | 
| 11 | val is_all: term -> bool | |
| 12 | val dest_all: term -> (string * typ) * term | |
| 18181 | 13 | val mk_equals: term * term -> term | 
| 14 | val dest_equals: term -> term * term | |
| 27334 | 15 | val implies: term | 
| 18181 | 16 | val mk_implies: term * term -> term | 
| 17 | val dest_implies: term -> term * term | |
| 18 | val list_implies: term list * term -> term | |
| 19 | val strip_imp_prems: term -> term list | |
| 20 | val strip_imp_concl: term -> term | |
| 21 | val strip_prems: int * term list * term -> term list * term | |
| 21576 | 22 | val count_prems: term -> int | 
| 18181 | 23 | val nth_prem: int * term -> term | 
| 23418 | 24 | val true_prop: term | 
| 19125 
59b26248547b
simplified Pure conjunction, based on actual const;
 wenzelm parents: 
19103diff
changeset | 25 | val conjunction: term | 
| 18181 | 26 | val mk_conjunction: term * term -> term | 
| 12757 | 27 | val mk_conjunction_list: term list -> term | 
| 23418 | 28 | val mk_conjunction_balanced: term list -> term | 
| 18469 | 29 | val dest_conjunction: term -> term * term | 
| 19425 | 30 | val dest_conjunction_list: term -> term list | 
| 23418 | 31 | val dest_conjunction_balanced: int -> term -> term list | 
| 18469 | 32 | val dest_conjunctions: term -> term list | 
| 18181 | 33 | val strip_horn: term -> term list * term | 
| 21520 | 34 | val mk_type: typ -> term | 
| 18938 | 35 | val dest_type: term -> typ | 
| 21520 | 36 | val type_map: (term -> term) -> typ -> typ | 
| 18938 | 37 | val const_of_class: class -> string | 
| 38 | val class_of_const: string -> class | |
| 31943 
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
 wenzelm parents: 
30554diff
changeset | 39 | val mk_of_class: typ * class -> term | 
| 
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
 wenzelm parents: 
30554diff
changeset | 40 | val dest_of_class: term -> typ * class | 
| 35854 | 41 | val mk_of_sort: typ * sort -> term list | 
| 20630 | 42 | val name_classrel: string * string -> string | 
| 19406 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 43 | val mk_classrel: class * class -> term | 
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 44 | val dest_classrel: term -> class * class | 
| 20630 | 45 | val name_arities: arity -> string list | 
| 46 | val name_arity: string * sort list * class -> string | |
| 47 | val mk_arities: arity -> term list | |
| 19406 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 48 | val dest_arity: term -> string * sort list * class | 
| 45328 | 49 | val unconstrainT: sort list -> term -> | 
| 37230 
7b548f137276
outer_constraints with original variable names, to ensure that argsP is consistent with args
 berghofe parents: 
36768diff
changeset | 50 | ((typ -> typ) * ((typ * class) * term) list * (typ * class) list) * term | 
| 18181 | 51 | val protectC: term | 
| 52 | val protect: term -> term | |
| 53 | val unprotect: term -> term | |
| 19775 | 54 | val mk_term: term -> term | 
| 55 | val dest_term: term -> term | |
| 18181 | 56 | val occs: term * term -> bool | 
| 57 | val close_form: term -> term | |
| 18938 | 58 | val combound: term * int * int -> term | 
| 59 | val rlist_abs: (string * typ) list * term -> term | |
| 32023 | 60 | val incr_tvar_same: int -> typ Same.operation | 
| 61 | val incr_tvar: int -> typ -> typ | |
| 32026 | 62 | val incr_indexes_same: typ list * int -> term Same.operation | 
| 18181 | 63 | val incr_indexes: typ list * int -> term -> term | 
| 64 | val lift_abs: int -> term -> term -> term | |
| 65 | val lift_all: int -> term -> term -> term | |
| 66 | val strip_assums_hyp: term -> term list | |
| 9460 | 67 | val strip_assums_concl: term -> term | 
| 18181 | 68 | val strip_params: term -> (string * typ) list | 
| 23597 | 69 | val has_meta_prems: term -> bool | 
| 18181 | 70 | val flatten_params: int -> term -> term | 
| 45328 | 71 | val list_rename_params: string list -> term -> term | 
| 72 | val assum_pairs: int * term -> (term * term) list | |
| 30554 
73f8bd5f0af8
substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
 wenzelm parents: 
30364diff
changeset | 73 | val assum_problems: int * term -> (term -> term) * term list * term | 
| 35845 
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
 wenzelm parents: 
32784diff
changeset | 74 | val varifyT_global: typ -> typ | 
| 
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
 wenzelm parents: 
32784diff
changeset | 75 | val unvarifyT_global: typ -> typ | 
| 45344 
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
 wenzelm parents: 
45328diff
changeset | 76 | val varify_types_global: term -> term | 
| 
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
 wenzelm parents: 
45328diff
changeset | 77 | val unvarify_types_global: term -> term | 
| 35845 
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
 wenzelm parents: 
32784diff
changeset | 78 | val varify_global: term -> term | 
| 
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
 wenzelm parents: 
32784diff
changeset | 79 | val unvarify_global: term -> term | 
| 18181 | 80 | val get_goal: term -> int -> term | 
| 81 | val goal_params: term -> int -> term * term list | |
| 82 | val prems_of_goal: term -> int -> term list | |
| 83 | val concl_of_goal: term -> int -> term | |
| 4345 | 84 | end; | 
| 0 | 85 | |
| 1500 | 86 | structure Logic : LOGIC = | 
| 0 | 87 | struct | 
| 398 
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
 wenzelm parents: 
210diff
changeset | 88 | |
| 4345 | 89 | |
| 0 | 90 | (*** Abstract syntax operations on the meta-connectives ***) | 
| 91 | ||
| 23238 | 92 | (** all **) | 
| 5041 
a1d0a6d555cd
Goals may now contain assumptions, which are not returned.
 nipkow parents: 
4822diff
changeset | 93 | |
| 27334 | 94 | fun all v t = Const ("all", (Term.fastype_of v --> propT) --> propT) $ lambda v t;
 | 
| 95 | ||
| 96 | fun is_all (Const ("all", _) $ Abs _) = true
 | |
| 97 | | is_all _ = false; | |
| 98 | ||
| 99 | fun dest_all (Const ("all", _) $ Abs (abs as (_, T, _))) =
 | |
| 100 | let val (x, b) = Term.dest_abs abs (*potentially slow*) | |
| 101 | in ((x, T), b) end | |
| 18762 | 102 |   | dest_all t = raise TERM ("dest_all", [t]);
 | 
| 103 | ||
| 104 | ||
| 0 | 105 | (** equality **) | 
| 106 | ||
| 27334 | 107 | fun mk_equals (t, u) = | 
| 108 | let val T = Term.fastype_of t | |
| 109 |   in Const ("==", T --> T --> propT) $ t $ u end;
 | |
| 0 | 110 | |
| 20883 | 111 | fun dest_equals (Const ("==", _) $ t $ u) = (t, u)
 | 
| 112 |   | dest_equals t = raise TERM ("dest_equals", [t]);
 | |
| 637 | 113 | |
| 114 | ||
| 0 | 115 | (** implies **) | 
| 116 | ||
| 27334 | 117 | val implies = Const ("==>", propT --> propT --> propT);
 | 
| 118 | ||
| 20883 | 119 | fun mk_implies (A, B) = implies $ A $ B; | 
| 0 | 120 | |
| 20883 | 121 | fun dest_implies (Const ("==>", _) $ A $ B) = (A, B)
 | 
| 122 |   | dest_implies A = raise TERM ("dest_implies", [A]);
 | |
| 5041 
a1d0a6d555cd
Goals may now contain assumptions, which are not returned.
 nipkow parents: 
4822diff
changeset | 123 | |
| 4822 | 124 | |
| 0 | 125 | (** nested implications **) | 
| 126 | ||
| 127 | (* [A1,...,An], B goes to A1==>...An==>B *) | |
| 18181 | 128 | fun list_implies ([], B) = B | 
| 129 | | list_implies (A::As, B) = implies $ A $ list_implies(As,B); | |
| 0 | 130 | |
| 131 | (* A1==>...An==>B goes to [A1,...,An], where B is not an implication *) | |
| 132 | fun strip_imp_prems (Const("==>", _) $ A $ B) = A :: strip_imp_prems B
 | |
| 133 | | strip_imp_prems _ = []; | |
| 134 | ||
| 135 | (* A1==>...An==>B goes to B, where B is not an implication *) | |
| 136 | fun strip_imp_concl (Const("==>", _) $ A $ B) = strip_imp_concl B
 | |
| 137 | | strip_imp_concl A = A : term; | |
| 138 | ||
| 139 | (*Strip and return premises: (i, [], A1==>...Ai==>B) | |
| 9460 | 140 | goes to ([Ai, A(i-1),...,A1] , B) (REVERSED) | 
| 0 | 141 | if i<0 or else i too big then raises TERM*) | 
| 9460 | 142 | fun strip_prems (0, As, B) = (As, B) | 
| 143 |   | strip_prems (i, As, Const("==>", _) $ A $ B) =
 | |
| 144 | strip_prems (i-1, A::As, B) | |
| 0 | 145 |   | strip_prems (_, As, A) = raise TERM("strip_prems", A::As);
 | 
| 146 | ||
| 16130 | 147 | (*Count premises -- quicker than (length o strip_prems) *) | 
| 21576 | 148 | fun count_prems (Const ("==>", _) $ _ $ B) = 1 + count_prems B
 | 
| 149 | | count_prems _ = 0; | |
| 0 | 150 | |
| 16130 | 151 | (*Select Ai from A1 ==>...Ai==>B*) | 
| 152 | fun nth_prem (1, Const ("==>", _) $ A $ _) = A
 | |
| 153 |   | nth_prem (i, Const ("==>", _) $ _ $ B) = nth_prem (i - 1, B)
 | |
| 154 |   | nth_prem (_, A) = raise TERM ("nth_prem", [A]);
 | |
| 155 | ||
| 13659 
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
 berghofe parents: 
12902diff
changeset | 156 | (*strip a proof state (Horn clause): | 
| 
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
 berghofe parents: 
12902diff
changeset | 157 | B1 ==> ... Bn ==> C goes to ([B1, ..., Bn], C) *) | 
| 
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
 berghofe parents: 
12902diff
changeset | 158 | fun strip_horn A = (strip_imp_prems A, strip_imp_concl A); | 
| 
3cf622f6b0b2
Removed obsolete functions dealing with flex-flex constraints.
 berghofe parents: 
12902diff
changeset | 159 | |
| 4822 | 160 | |
| 23418 | 161 | |
| 12137 | 162 | (** conjunction **) | 
| 163 | ||
| 23418 | 164 | val true_prop = Term.all propT $ Abs ("dummy", propT, mk_implies (Bound 0, Bound 0));
 | 
| 26424 | 165 | val conjunction = Const ("Pure.conjunction", propT --> propT --> propT);
 | 
| 19125 
59b26248547b
simplified Pure conjunction, based on actual const;
 wenzelm parents: 
19103diff
changeset | 166 | |
| 23418 | 167 | |
| 28856 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28448diff
changeset | 168 | (*A &&& B*) | 
| 19125 
59b26248547b
simplified Pure conjunction, based on actual const;
 wenzelm parents: 
19103diff
changeset | 169 | fun mk_conjunction (A, B) = conjunction $ A $ B; | 
| 12137 | 170 | |
| 28856 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28448diff
changeset | 171 | (*A &&& B &&& C -- improper*) | 
| 23418 | 172 | fun mk_conjunction_list [] = true_prop | 
| 12757 | 173 | | mk_conjunction_list ts = foldr1 mk_conjunction ts; | 
| 12137 | 174 | |
| 28856 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28448diff
changeset | 175 | (*(A &&& B) &&& (C &&& D) -- balanced*) | 
| 23418 | 176 | fun mk_conjunction_balanced [] = true_prop | 
| 32765 | 177 | | mk_conjunction_balanced ts = Balanced_Tree.make mk_conjunction ts; | 
| 23418 | 178 | |
| 18499 | 179 | |
| 28856 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28448diff
changeset | 180 | (*A &&& B*) | 
| 26424 | 181 | fun dest_conjunction (Const ("Pure.conjunction", _) $ A $ B) = (A, B)
 | 
| 18469 | 182 |   | dest_conjunction t = raise TERM ("dest_conjunction", [t]);
 | 
| 183 | ||
| 28856 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28448diff
changeset | 184 | (*A &&& B &&& C -- improper*) | 
| 19425 | 185 | fun dest_conjunction_list t = | 
| 186 | (case try dest_conjunction t of | |
| 187 | NONE => [t] | |
| 188 | | SOME (A, B) => A :: dest_conjunction_list B); | |
| 189 | ||
| 28856 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28448diff
changeset | 190 | (*(A &&& B) &&& (C &&& D) -- balanced*) | 
| 23418 | 191 | fun dest_conjunction_balanced 0 _ = [] | 
| 32765 | 192 | | dest_conjunction_balanced n t = Balanced_Tree.dest dest_conjunction n t; | 
| 23418 | 193 | |
| 28856 
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
 wenzelm parents: 
28448diff
changeset | 194 | (*((A &&& B) &&& C) &&& D &&& E -- flat*) | 
| 18469 | 195 | fun dest_conjunctions t = | 
| 196 | (case try dest_conjunction t of | |
| 197 | NONE => [t] | |
| 198 | | SOME (A, B) => dest_conjunctions A @ dest_conjunctions B); | |
| 199 | ||
| 200 | ||
| 12137 | 201 | |
| 398 
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
 wenzelm parents: 
210diff
changeset | 202 | (** types as terms **) | 
| 
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
 wenzelm parents: 
210diff
changeset | 203 | |
| 19391 | 204 | fun mk_type ty = Const ("TYPE", Term.itselfT ty);
 | 
| 398 
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
 wenzelm parents: 
210diff
changeset | 205 | |
| 
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
 wenzelm parents: 
210diff
changeset | 206 | fun dest_type (Const ("TYPE", Type ("itself", [ty]))) = ty
 | 
| 
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
 wenzelm parents: 
210diff
changeset | 207 |   | dest_type t = raise TERM ("dest_type", [t]);
 | 
| 
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
 wenzelm parents: 
210diff
changeset | 208 | |
| 21520 | 209 | fun type_map f = dest_type o f o mk_type; | 
| 210 | ||
| 4822 | 211 | |
| 19406 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 212 | |
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 213 | (** type classes **) | 
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 214 | |
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 215 | (* const names *) | 
| 398 
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
 wenzelm parents: 
210diff
changeset | 216 | |
| 18938 | 217 | val classN = "_class"; | 
| 218 | ||
| 219 | val const_of_class = suffix classN; | |
| 19406 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 220 | |
| 18938 | 221 | fun class_of_const c = unsuffix classN c | 
| 222 |   handle Fail _ => raise TERM ("class_of_const: bad name " ^ quote c, []);
 | |
| 223 | ||
| 19406 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 224 | |
| 35854 | 225 | (* class/sort membership *) | 
| 19406 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 226 | |
| 31943 
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
 wenzelm parents: 
30554diff
changeset | 227 | fun mk_of_class (ty, c) = | 
| 19391 | 228 | Const (const_of_class c, Term.itselfT ty --> propT) $ mk_type ty; | 
| 398 
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
 wenzelm parents: 
210diff
changeset | 229 | |
| 32784 | 230 | fun dest_of_class (Const (c_class, _) $ ty) = (dest_type ty, class_of_const c_class) | 
| 31943 
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
 wenzelm parents: 
30554diff
changeset | 231 |   | dest_of_class t = raise TERM ("dest_of_class", [t]);
 | 
| 398 
41f279b477e2
added mk_type, dest_type, mk_inclass, dest_inclass (for axclasses);
 wenzelm parents: 
210diff
changeset | 232 | |
| 35854 | 233 | fun mk_of_sort (ty, S) = map (fn c => mk_of_class (ty, c)) S; | 
| 234 | ||
| 0 | 235 | |
| 19406 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 236 | (* class relations *) | 
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 237 | |
| 20630 | 238 | fun name_classrel (c1, c2) = | 
| 30364 
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
 wenzelm parents: 
30280diff
changeset | 239 | Long_Name.base_name c1 ^ "_" ^ Long_Name.base_name c2; | 
| 20630 | 240 | |
| 31943 
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
 wenzelm parents: 
30554diff
changeset | 241 | fun mk_classrel (c1, c2) = mk_of_class (Term.aT [c1], c2); | 
| 19406 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 242 | |
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 243 | fun dest_classrel tm = | 
| 31943 
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
 wenzelm parents: 
30554diff
changeset | 244 | (case dest_of_class tm of | 
| 19406 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 245 | (TVar (_, [c1]), c2) => (c1, c2) | 
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 246 |   | _ => raise TERM ("dest_classrel", [tm]));
 | 
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 247 | |
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 248 | |
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 249 | (* type arities *) | 
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 250 | |
| 20630 | 251 | fun name_arities (t, _, S) = | 
| 30364 
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
 wenzelm parents: 
30280diff
changeset | 252 | let val b = Long_Name.base_name t | 
| 
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
 wenzelm parents: 
30280diff
changeset | 253 | in S |> map (fn c => Long_Name.base_name c ^ "_" ^ b) end; | 
| 20630 | 254 | |
| 255 | fun name_arity (t, dom, c) = hd (name_arities (t, dom, [c])); | |
| 256 | ||
| 19406 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 257 | fun mk_arities (t, Ss, S) = | 
| 43329 
84472e198515
tuned signature: Name.invent and Name.invent_names;
 wenzelm parents: 
37230diff
changeset | 258 | let val T = Type (t, ListPair.map TFree (Name.invent Name.context Name.aT (length Ss), Ss)) | 
| 31943 
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
 wenzelm parents: 
30554diff
changeset | 259 | in map (fn c => mk_of_class (T, c)) S end; | 
| 19406 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 260 | |
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 261 | fun dest_arity tm = | 
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 262 | let | 
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 263 |     fun err () = raise TERM ("dest_arity", [tm]);
 | 
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 264 | |
| 31943 
5e960a0780a2
renamed inclass/Inclass to of_class/OfClass, in accordance to of_sort;
 wenzelm parents: 
30554diff
changeset | 265 | val (ty, c) = dest_of_class tm; | 
| 19406 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 266 | val (t, tvars) = | 
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 267 | (case ty of | 
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 268 | Type (t, tys) => (t, map dest_TVar tys handle TYPE _ => err ()) | 
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 269 | | _ => err ()); | 
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 270 | val Ss = | 
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 271 | if has_duplicates (eq_fst (op =)) tvars then err () | 
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 272 | else map snd tvars; | 
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 273 | in (t, Ss, c) end; | 
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 274 | |
| 
410b9d9bf9a1
added mk_classrel, dest_classrel, mk_arities, dest_arity (from axclass.ML);
 wenzelm parents: 
19391diff
changeset | 275 | |
| 36767 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 276 | (* internalized sort constraints *) | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 277 | |
| 36768 
46be86127972
just one version of Thm.unconstrainT, which affects all variables;
 wenzelm parents: 
36767diff
changeset | 278 | fun unconstrainT shyps prop = | 
| 36767 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 279 | let | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 280 | val present = rev ((fold_types o fold_atyps_sorts) (insert (eq_fst op =)) prop []); | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 281 | val extra = fold (Sorts.remove_sort o #2) present shyps; | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 282 | |
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 283 | val n = length present; | 
| 43329 
84472e198515
tuned signature: Name.invent and Name.invent_names;
 wenzelm parents: 
37230diff
changeset | 284 | val (names1, names2) = Name.invent Name.context Name.aT (n + length extra) |> chop n; | 
| 36767 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 285 | |
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 286 | val present_map = | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 287 | map2 (fn (T, S) => fn a => (T, TVar ((a, 0), S))) present names1; | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 288 | val constraints_map = | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 289 | map2 (fn (_, S) => fn a => (S, TVar ((a, 0), S))) present names1 @ | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 290 | map2 (fn S => fn a => (S, TVar ((a, 0), S))) extra names2; | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 291 | |
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 292 | fun atyp_map T = | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 293 | (case AList.lookup (op =) present_map T of | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 294 | SOME U => U | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 295 | | NONE => | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 296 | (case AList.lookup (op =) constraints_map (Type.sort_of_atyp T) of | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 297 | SOME U => U | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 298 |           | NONE => raise TYPE ("Dangling type variable", [T], [])));
 | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 299 | |
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 300 | val constraints = | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 301 | maps (fn (_, T as TVar (ai, S)) => | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 302 | map (fn c => ((T, c), mk_of_class (TVar (ai, []), c))) S) | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 303 | constraints_map; | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 304 | |
| 37230 
7b548f137276
outer_constraints with original variable names, to ensure that argsP is consistent with args
 berghofe parents: 
36768diff
changeset | 305 | val outer_constraints = | 
| 
7b548f137276
outer_constraints with original variable names, to ensure that argsP is consistent with args
 berghofe parents: 
36768diff
changeset | 306 | maps (fn (T, S) => map (pair T) S) | 
| 
7b548f137276
outer_constraints with original variable names, to ensure that argsP is consistent with args
 berghofe parents: 
36768diff
changeset | 307 |         (present @ map (fn S => (TFree ("'dummy", S), S)) extra);
 | 
| 
7b548f137276
outer_constraints with original variable names, to ensure that argsP is consistent with args
 berghofe parents: 
36768diff
changeset | 308 | |
| 36767 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 309 | val prop' = | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 310 | prop | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 311 | |> (Term.map_types o Term.map_atyps) (Type.strip_sorts o atyp_map) | 
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 312 | |> curry list_implies (map snd constraints); | 
| 37230 
7b548f137276
outer_constraints with original variable names, to ensure that argsP is consistent with args
 berghofe parents: 
36768diff
changeset | 313 | in ((atyp_map, constraints, outer_constraints), prop') end; | 
| 36767 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 314 | |
| 
d0095729e1f1
added Logic.unconstrain_allTs, based on calculations_for_thm_proof by krauss/schropp, but treat type variables uniformly as in strip_shyps (in thm.ML) or stripped_sorts (in more_thm.ML);
 wenzelm parents: 
35854diff
changeset | 315 | |
| 18938 | 316 | |
| 28448 | 317 | (** protected propositions and embedded terms **) | 
| 9460 | 318 | |
| 18029 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 319 | val protectC = Const ("prop", propT --> propT);
 | 
| 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 320 | fun protect t = protectC $ t; | 
| 9460 | 321 | |
| 18029 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 322 | fun unprotect (Const ("prop", _) $ t) = t
 | 
| 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 323 |   | unprotect t = raise TERM ("unprotect", [t]);
 | 
| 9460 | 324 | |
| 325 | ||
| 26424 | 326 | fun mk_term t = Const ("Pure.term", Term.fastype_of t --> propT) $ t;
 | 
| 19775 | 327 | |
| 26424 | 328 | fun dest_term (Const ("Pure.term", _) $ t) = t
 | 
| 19775 | 329 |   | dest_term t = raise TERM ("dest_term", [t]);
 | 
| 330 | ||
| 331 | ||
| 18181 | 332 | |
| 0 | 333 | (*** Low-level term operations ***) | 
| 334 | ||
| 335 | (*Does t occur in u? Or is alpha-convertible to u? | |
| 336 | The term t must contain no loose bound variables*) | |
| 16846 | 337 | fun occs (t, u) = exists_subterm (fn s => t aconv s) u; | 
| 0 | 338 | |
| 339 | (*Close up a formula over all free variables by quantification*) | |
| 340 | fun close_form A = | |
| 19425 | 341 | Term.list_all_free (rev (Term.add_frees A []), A); | 
| 0 | 342 | |
| 343 | ||
| 18938 | 344 | |
| 0 | 345 | (*** Specialized operations for resolution... ***) | 
| 346 | ||
| 18938 | 347 | (*computes t(Bound(n+k-1),...,Bound(n)) *) | 
| 348 | fun combound (t, n, k) = | |
| 349 | if k>0 then combound (t,n+1,k-1) $ (Bound n) else t; | |
| 350 | ||
| 351 | (* ([xn,...,x1], t) ======> (x1,...,xn)t *) | |
| 352 | fun rlist_abs ([], body) = body | |
| 353 | | rlist_abs ((a,T)::pairs, body) = rlist_abs(pairs, Abs(a, T, body)); | |
| 354 | ||
| 32026 | 355 | fun incr_tvar_same 0 = Same.same | 
| 356 | | incr_tvar_same k = Term_Subst.map_atypsT_same | |
| 357 | (fn TVar ((a, i), S) => TVar ((a, i + k), S) | |
| 358 | | _ => raise Same.SAME); | |
| 16879 
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
 wenzelm parents: 
16862diff
changeset | 359 | |
| 32026 | 360 | fun incr_tvar k T = incr_tvar_same k T handle Same.SAME => T; | 
| 32023 | 361 | |
| 0 | 362 | (*For all variables in the term, increment indexnames and lift over the Us | 
| 363 | result is ?Gidx(B.(lev+n-1),...,B.lev) where lev is abstraction level *) | |
| 32026 | 364 | fun incr_indexes_same ([], 0) = Same.same | 
| 365 | | incr_indexes_same (Ts, k) = | |
| 32020 | 366 | let | 
| 367 | val n = length Ts; | |
| 32026 | 368 | val incrT = incr_tvar_same k; | 
| 16879 
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
 wenzelm parents: 
16862diff
changeset | 369 | |
| 32020 | 370 | fun incr lev (Var ((x, i), T)) = | 
| 371 | combound (Var ((x, i + k), Ts ---> Same.commit incrT T), lev, n) | |
| 372 | | incr lev (Abs (x, T, body)) = | |
| 373 | (Abs (x, incrT T, incr (lev + 1) body handle Same.SAME => body) | |
| 374 | handle Same.SAME => Abs (x, T, incr (lev + 1) body)) | |
| 375 | | incr lev (t $ u) = | |
| 376 | (incr lev t $ (incr lev u handle Same.SAME => u) | |
| 377 | handle Same.SAME => t $ incr lev u) | |
| 378 | | incr _ (Const (c, T)) = Const (c, incrT T) | |
| 379 | | incr _ (Free (x, T)) = Free (x, incrT T) | |
| 32026 | 380 | | incr _ (Bound _) = raise Same.SAME; | 
| 381 | in incr 0 end; | |
| 382 | ||
| 383 | fun incr_indexes arg t = incr_indexes_same arg t handle Same.SAME => t; | |
| 16879 
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
 wenzelm parents: 
16862diff
changeset | 384 | |
| 0 | 385 | |
| 18248 | 386 | (* Lifting functions from subgoal and increment: | 
| 18029 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 387 | lift_abs operates on terms | 
| 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 388 | lift_all operates on propositions *) | 
| 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 389 | |
| 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 390 | fun lift_abs inc = | 
| 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 391 | let | 
| 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 392 |     fun lift Ts (Const ("==>", _) $ _ $ B) t = lift Ts B t
 | 
| 18248 | 393 |       | lift Ts (Const ("all", _) $ Abs (a, T, B)) t = Abs (a, T, lift (T :: Ts) B t)
 | 
| 18029 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 394 | | lift Ts _ t = incr_indexes (rev Ts, inc) t; | 
| 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 395 | in lift [] end; | 
| 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 396 | |
| 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 397 | fun lift_all inc = | 
| 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 398 | let | 
| 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 399 |     fun lift Ts ((c as Const ("==>", _)) $ A $ B) t = c $ A $ lift Ts B t
 | 
| 18248 | 400 |       | lift Ts ((c as Const ("all", _)) $ Abs (a, T, B)) t = c $ Abs (a, T, lift (T :: Ts) B t)
 | 
| 18029 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 401 | | lift Ts _ t = incr_indexes (rev Ts, inc) t; | 
| 
19f1ad18bece
renamed Goal constant to prop, more general protect/unprotect interfaces;
 wenzelm parents: 
17120diff
changeset | 402 | in lift [] end; | 
| 0 | 403 | |
| 404 | (*Strips assumptions in goal, yielding list of hypotheses. *) | |
| 21016 
430b35c9cd27
Repaired strip_assums_hyp (now also works for goals not
 berghofe parents: 
20883diff
changeset | 405 | fun strip_assums_hyp B = | 
| 
430b35c9cd27
Repaired strip_assums_hyp (now also works for goals not
 berghofe parents: 
20883diff
changeset | 406 | let | 
| 
430b35c9cd27
Repaired strip_assums_hyp (now also works for goals not
 berghofe parents: 
20883diff
changeset | 407 |     fun strip Hs (Const ("==>", _) $ H $ B) = strip (H :: Hs) B
 | 
| 
430b35c9cd27
Repaired strip_assums_hyp (now also works for goals not
 berghofe parents: 
20883diff
changeset | 408 |       | strip Hs (Const ("all", _) $ Abs (a, T, t)) =
 | 
| 
430b35c9cd27
Repaired strip_assums_hyp (now also works for goals not
 berghofe parents: 
20883diff
changeset | 409 | strip (map (incr_boundvars 1) Hs) t | 
| 
430b35c9cd27
Repaired strip_assums_hyp (now also works for goals not
 berghofe parents: 
20883diff
changeset | 410 | | strip Hs B = rev Hs | 
| 
430b35c9cd27
Repaired strip_assums_hyp (now also works for goals not
 berghofe parents: 
20883diff
changeset | 411 | in strip [] B end; | 
| 0 | 412 | |
| 413 | (*Strips assumptions in goal, yielding conclusion. *) | |
| 414 | fun strip_assums_concl (Const("==>", _) $ H $ B) = strip_assums_concl B
 | |
| 415 |   | strip_assums_concl (Const("all",_)$Abs(a,T,t)) = strip_assums_concl t
 | |
| 416 | | strip_assums_concl B = B; | |
| 417 | ||
| 418 | (*Make a list of all the parameters in a subgoal, even if nested*) | |
| 419 | fun strip_params (Const("==>", _) $ H $ B) = strip_params B
 | |
| 420 |   | strip_params (Const("all",_)$Abs(a,T,t)) = (a,T) :: strip_params t
 | |
| 421 | | strip_params B = []; | |
| 422 | ||
| 23597 | 423 | (*test for nested meta connectives in prems*) | 
| 424 | val has_meta_prems = | |
| 9667 | 425 | let | 
| 23597 | 426 |     fun is_meta (Const ("==", _) $ _ $ _) = true
 | 
| 427 |       | is_meta (Const ("==>", _) $ _ $ _) = true
 | |
| 9667 | 428 |       | is_meta (Const ("all", _) $ _) = true
 | 
| 429 | | is_meta _ = false; | |
| 23597 | 430 |     fun ex_meta (Const ("==>", _) $ A $ B) = is_meta A orelse ex_meta B
 | 
| 431 |       | ex_meta (Const ("all", _) $ Abs (_, _, B)) = ex_meta B
 | |
| 432 | | ex_meta _ = false; | |
| 433 | in ex_meta end; | |
| 9483 | 434 | |
| 0 | 435 | (*Removes the parameters from a subgoal and renumber bvars in hypotheses, | 
| 9460 | 436 | where j is the total number of parameters (precomputed) | 
| 0 | 437 | If n>0 then deletes assumption n. *) | 
| 9460 | 438 | fun remove_params j n A = | 
| 0 | 439 | if j=0 andalso n<=0 then A (*nothing left to do...*) | 
| 440 | else case A of | |
| 9460 | 441 |         Const("==>", _) $ H $ B =>
 | 
| 442 | if n=1 then (remove_params j (n-1) B) | |
| 443 | else implies $ (incr_boundvars j H) $ (remove_params j (n-1) B) | |
| 0 | 444 |       | Const("all",_)$Abs(a,T,t) => remove_params (j-1) n t
 | 
| 445 |       | _ => if n>0 then raise TERM("remove_params", [A])
 | |
| 446 | else A; | |
| 447 | ||
| 448 | (*Move all parameters to the front of the subgoal, renaming them apart; | |
| 449 | if n>0 then deletes assumption n. *) | |
| 450 | fun flatten_params n A = | |
| 451 | let val params = strip_params A; | |
| 25939 | 452 | val vars = ListPair.zip (Name.variant_list [] (map #1 params), | 
| 453 | map #2 params) | |
| 0 | 454 | in list_all (vars, remove_params (length vars) n A) | 
| 455 | end; | |
| 456 | ||
| 457 | (*Makes parameters in a goal have the names supplied by the list cs.*) | |
| 45328 | 458 | fun list_rename_params cs (Const ("==>", _) $ A $ B) =
 | 
| 459 | implies $ A $ list_rename_params cs B | |
| 460 |   | list_rename_params (c :: cs) ((a as Const ("all", _)) $ Abs (_, T, t)) =
 | |
| 461 | a $ Abs (c, T, list_rename_params cs t) | |
| 462 | | list_rename_params cs B = B; | |
| 0 | 463 | |
| 32008 | 464 | |
| 465 | ||
| 19806 | 466 | (*** Treatment of "assume", "erule", etc. ***) | 
| 0 | 467 | |
| 16879 
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
 wenzelm parents: 
16862diff
changeset | 468 | (*Strips assumptions in goal yielding | 
| 15451 
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
 paulson parents: 
14137diff
changeset | 469 | HS = [Hn,...,H1], params = [xm,...,x1], and B, | 
| 16879 
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
 wenzelm parents: 
16862diff
changeset | 470 | where x1...xm are the parameters. This version (21.1.2005) REQUIRES | 
| 
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
 wenzelm parents: 
16862diff
changeset | 471 | the the parameters to be flattened, but it allows erule to work on | 
| 15451 
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
 paulson parents: 
14137diff
changeset | 472 | assumptions of the form !!x. phi. Any !! after the outermost string | 
| 
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
 paulson parents: 
14137diff
changeset | 473 | will be regarded as belonging to the conclusion, and left untouched. | 
| 15454 | 474 | Used ONLY by assum_pairs. | 
| 475 | Unless nasms<0, it can terminate the recursion early; that allows | |
| 476 | erule to work on assumptions of the form P==>Q.*) | |
| 477 | fun strip_assums_imp (0, Hs, B) = (Hs, B) (*recursion terminated by nasms*) | |
| 16879 
b81d3f2ee565
incr_tvar (from term.ML), incr_indexes: avoid garbage;
 wenzelm parents: 
16862diff
changeset | 478 |   | strip_assums_imp (nasms, Hs, Const("==>", _) $ H $ B) =
 | 
| 15454 | 479 | strip_assums_imp (nasms-1, H::Hs, B) | 
| 480 | | strip_assums_imp (_, Hs, B) = (Hs, B); (*recursion terminated by B*) | |
| 481 | ||
| 32008 | 482 | (*Strips OUTER parameters only.*) | 
| 15451 
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
 paulson parents: 
14137diff
changeset | 483 | fun strip_assums_all (params, Const("all",_)$Abs(a,T,t)) =
 | 
| 
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
 paulson parents: 
14137diff
changeset | 484 | strip_assums_all ((a,T)::params, t) | 
| 
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
 paulson parents: 
14137diff
changeset | 485 | | strip_assums_all (params, B) = (params, B); | 
| 0 | 486 | |
| 487 | (*Produces disagreement pairs, one for each assumption proof, in order. | |
| 488 | A is the first premise of the lifted rule, and thus has the form | |
| 15454 | 489 | H1 ==> ... Hk ==> B and the pairs are (H1,B),...,(Hk,B). | 
| 490 | nasms is the number of assumptions in the original subgoal, needed when B | |
| 491 | has the form B1 ==> B2: it stops B1 from being taken as an assumption. *) | |
| 492 | fun assum_pairs(nasms,A) = | |
| 15451 
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
 paulson parents: 
14137diff
changeset | 493 | let val (params, A') = strip_assums_all ([],A) | 
| 15454 | 494 | val (Hs,B) = strip_assums_imp (nasms,[],A') | 
| 18938 | 495 | fun abspar t = rlist_abs(params, t) | 
| 15451 
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
 paulson parents: 
14137diff
changeset | 496 | val D = abspar B | 
| 
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
 paulson parents: 
14137diff
changeset | 497 | fun pairrev ([], pairs) = pairs | 
| 
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
 paulson parents: 
14137diff
changeset | 498 | | pairrev (H::Hs, pairs) = pairrev(Hs, (abspar H, D) :: pairs) | 
| 
c6c8786b9921
fixed thin_tac with higher-level assumptions by removing the old code to
 paulson parents: 
14137diff
changeset | 499 | in pairrev (Hs,[]) | 
| 0 | 500 | end; | 
| 501 | ||
| 30554 
73f8bd5f0af8
substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
 wenzelm parents: 
30364diff
changeset | 502 | fun assum_problems (nasms, A) = | 
| 
73f8bd5f0af8
substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
 wenzelm parents: 
30364diff
changeset | 503 | let | 
| 
73f8bd5f0af8
substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
 wenzelm parents: 
30364diff
changeset | 504 | val (params, A') = strip_assums_all ([], A) | 
| 
73f8bd5f0af8
substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
 wenzelm parents: 
30364diff
changeset | 505 | val (Hs, B) = strip_assums_imp (nasms, [], A') | 
| 
73f8bd5f0af8
substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
 wenzelm parents: 
30364diff
changeset | 506 | fun abspar t = rlist_abs (params, t) | 
| 
73f8bd5f0af8
substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
 wenzelm parents: 
30364diff
changeset | 507 | in (abspar, rev Hs, B) end; | 
| 
73f8bd5f0af8
substantial speedup of assumption and elim-resolution: Logic.assum_problems refrains from eager application of parameters, discriminate via Term.could_unify before invoking full unification (assumes terms in beta-normal form, as do higher term net operations anyway);
 wenzelm parents: 
30364diff
changeset | 508 | |
| 19806 | 509 | |
| 510 | (* global schematic variables *) | |
| 511 | ||
| 512 | fun bad_schematic xi = "Illegal schematic variable: " ^ quote (Term.string_of_vname xi); | |
| 513 | fun bad_fixed x = "Illegal fixed variable: " ^ quote x; | |
| 514 | ||
| 35845 
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
 wenzelm parents: 
32784diff
changeset | 515 | fun varifyT_global_same ty = ty | 
| 32020 | 516 | |> Term_Subst.map_atypsT_same | 
| 517 | (fn TFree (a, S) => TVar ((a, 0), S) | |
| 31981 
9c59cbb9c5a2
tuned varify/unvarify: use Term_Subst.map_XXX combinators;
 wenzelm parents: 
31943diff
changeset | 518 | | TVar (ai, _) => raise TYPE (bad_schematic ai, [ty], [])); | 
| 19806 | 519 | |
| 35845 
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
 wenzelm parents: 
32784diff
changeset | 520 | fun unvarifyT_global_same ty = ty | 
| 32020 | 521 | |> Term_Subst.map_atypsT_same | 
| 522 | (fn TVar ((a, 0), S) => TFree (a, S) | |
| 31981 
9c59cbb9c5a2
tuned varify/unvarify: use Term_Subst.map_XXX combinators;
 wenzelm parents: 
31943diff
changeset | 523 | | TVar (ai, _) => raise TYPE (bad_schematic ai, [ty], []) | 
| 
9c59cbb9c5a2
tuned varify/unvarify: use Term_Subst.map_XXX combinators;
 wenzelm parents: 
31943diff
changeset | 524 | | TFree (a, _) => raise TYPE (bad_fixed a, [ty], [])); | 
| 0 | 525 | |
| 35845 
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
 wenzelm parents: 
32784diff
changeset | 526 | val varifyT_global = Same.commit varifyT_global_same; | 
| 
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
 wenzelm parents: 
32784diff
changeset | 527 | val unvarifyT_global = Same.commit unvarifyT_global_same; | 
| 31981 
9c59cbb9c5a2
tuned varify/unvarify: use Term_Subst.map_XXX combinators;
 wenzelm parents: 
31943diff
changeset | 528 | |
| 45344 
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
 wenzelm parents: 
45328diff
changeset | 529 | fun varify_types_global tm = tm | 
| 
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
 wenzelm parents: 
45328diff
changeset | 530 | |> Same.commit (Term_Subst.map_types_same varifyT_global_same) | 
| 
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
 wenzelm parents: 
45328diff
changeset | 531 | handle TYPE (msg, _, _) => raise TERM (msg, [tm]); | 
| 
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
 wenzelm parents: 
45328diff
changeset | 532 | |
| 
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
 wenzelm parents: 
45328diff
changeset | 533 | fun unvarify_types_global tm = tm | 
| 
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
 wenzelm parents: 
45328diff
changeset | 534 | |> Same.commit (Term_Subst.map_types_same unvarifyT_global_same) | 
| 
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
 wenzelm parents: 
45328diff
changeset | 535 | handle TYPE (msg, _, _) => raise TERM (msg, [tm]); | 
| 
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
 wenzelm parents: 
45328diff
changeset | 536 | |
| 35845 
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
 wenzelm parents: 
32784diff
changeset | 537 | fun varify_global tm = tm | 
| 32020 | 538 | |> Same.commit (Term_Subst.map_aterms_same | 
| 539 | (fn Free (x, T) => Var ((x, 0), T) | |
| 19806 | 540 | | Var (xi, _) => raise TERM (bad_schematic xi, [tm]) | 
| 32020 | 541 | | _ => raise Same.SAME)) | 
| 45344 
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
 wenzelm parents: 
45328diff
changeset | 542 | |> varify_types_global; | 
| 19806 | 543 | |
| 35845 
e5980f0ad025
renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
 wenzelm parents: 
32784diff
changeset | 544 | fun unvarify_global tm = tm | 
| 32020 | 545 | |> Same.commit (Term_Subst.map_aterms_same | 
| 546 | (fn Var ((x, 0), T) => Free (x, T) | |
| 19806 | 547 | | Var (xi, _) => raise TERM (bad_schematic xi, [tm]) | 
| 548 | | Free (x, _) => raise TERM (bad_fixed x, [tm]) | |
| 32020 | 549 | | _ => raise Same.SAME)) | 
| 45344 
e209da839ff4
added Logic.varify_types_global/unvarify_types_global, which avoids somewhat expensive Term.map_types;
 wenzelm parents: 
45328diff
changeset | 550 | |> unvarify_types_global; | 
| 19806 | 551 | |
| 13799 
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
 berghofe parents: 
13659diff
changeset | 552 | |
| 16862 | 553 | (* goal states *) | 
| 554 | ||
| 555 | fun get_goal st i = nth_prem (i, st) | |
| 556 | handle TERM _ => error "Goal number out of range"; | |
| 13799 
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
 berghofe parents: 
13659diff
changeset | 557 | |
| 
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
 berghofe parents: 
13659diff
changeset | 558 | (*reverses parameters for substitution*) | 
| 
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
 berghofe parents: 
13659diff
changeset | 559 | fun goal_params st i = | 
| 
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
 berghofe parents: 
13659diff
changeset | 560 | let val gi = get_goal st i | 
| 29276 | 561 | val rfrees = map Free (Term.rename_wrt_term gi (strip_params gi)) | 
| 13799 
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
 berghofe parents: 
13659diff
changeset | 562 | in (gi, rfrees) end; | 
| 
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
 berghofe parents: 
13659diff
changeset | 563 | |
| 
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
 berghofe parents: 
13659diff
changeset | 564 | fun concl_of_goal st i = | 
| 
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
 berghofe parents: 
13659diff
changeset | 565 | let val (gi, rfrees) = goal_params st i | 
| 
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
 berghofe parents: 
13659diff
changeset | 566 | val B = strip_assums_concl gi | 
| 
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
 berghofe parents: 
13659diff
changeset | 567 | in subst_bounds (rfrees, B) end; | 
| 
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
 berghofe parents: 
13659diff
changeset | 568 | |
| 
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
 berghofe parents: 
13659diff
changeset | 569 | fun prems_of_goal st i = | 
| 
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
 berghofe parents: 
13659diff
changeset | 570 | let val (gi, rfrees) = goal_params st i | 
| 
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
 berghofe parents: 
13659diff
changeset | 571 | val As = strip_assums_hyp gi | 
| 
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
 berghofe parents: 
13659diff
changeset | 572 | in map (fn A => subst_bounds (rfrees, A)) As end; | 
| 
77614fe09362
Moved get_goal, prems_of_goal and concl_of_goal from goals.ML to logic.ML
 berghofe parents: 
13659diff
changeset | 573 | |
| 0 | 574 | end; |