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