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