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