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