author | wenzelm |
Wed, 06 Dec 2023 20:57:53 +0100 | |
changeset 79157 | 00962876301c |
parent 79156 | 3b272da1d165 |
child 79158 | 3c7ab17380a8 |
permissions | -rw-r--r-- |
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Pure/zterm.ML |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
3 |
|
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
4 |
Tight representation of types / terms / proof terms, notably for proof recording. |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
5 |
*) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
6 |
|
79124 | 7 |
(*** global ***) |
8 |
||
9 |
(* types and terms *) |
|
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
10 |
|
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
11 |
datatype ztyp = |
79119 | 12 |
ZTVar of indexname * sort (*free: index ~1*) |
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
13 |
| ZFun of ztyp * ztyp |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
14 |
| ZProp |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
15 |
| ZItself of ztyp |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
16 |
| ZType0 of string (*type constant*) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
17 |
| ZType1 of string * ztyp (*type constructor: 1 argument*) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
18 |
| ZType of string * ztyp list (*type constructor: >= 2 arguments*) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
19 |
|
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
20 |
datatype zterm = |
79119 | 21 |
ZVar of indexname * ztyp (*free: index ~1*) |
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
22 |
| ZBound of int |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
23 |
| ZConst0 of string (*monomorphic constant*) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
24 |
| ZConst1 of string * ztyp (*polymorphic constant: 1 type argument*) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
25 |
| ZConst of string * ztyp list (*polymorphic constant: >= 2 type arguments*) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
26 |
| ZAbs of string * ztyp * zterm |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
27 |
| ZApp of zterm * zterm |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
28 |
| ZClass of ztyp * class (*OFCLASS proposition*) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
29 |
|
79124 | 30 |
structure ZTerm = |
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
31 |
struct |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
32 |
|
79119 | 33 |
(* fold *) |
34 |
||
35 |
fun fold_tvars f (ZTVar v) = f v |
|
36 |
| fold_tvars f (ZFun (T, U)) = fold_tvars f T #> fold_tvars f U |
|
37 |
| fold_tvars f (ZItself T) = fold_tvars f T |
|
38 |
| fold_tvars f (ZType1 (_, T)) = fold_tvars f T |
|
39 |
| fold_tvars f (ZType (_, Ts)) = fold (fold_tvars f) Ts |
|
40 |
| fold_tvars _ _ = I; |
|
41 |
||
42 |
fun fold_aterms f (ZApp (t, u)) = fold_aterms f t #> fold_aterms f u |
|
43 |
| fold_aterms f (ZAbs (_, _, t)) = fold_aterms f t |
|
44 |
| fold_aterms f a = f a; |
|
45 |
||
46 |
fun fold_types f (ZVar (_, T)) = f T |
|
47 |
| fold_types f (ZConst1 (_, T)) = f T |
|
48 |
| fold_types f (ZConst (_, As)) = fold f As |
|
49 |
| fold_types f (ZAbs (_, T, b)) = f T #> fold_types f b |
|
50 |
| fold_types f (ZApp (t, u)) = fold_types f t #> fold_types f u |
|
51 |
| fold_types f (ZClass (T, _)) = f T |
|
52 |
| fold_types _ _ = I; |
|
53 |
||
54 |
||
79124 | 55 |
(* ordering *) |
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
56 |
|
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
57 |
local |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
58 |
|
79119 | 59 |
fun cons_nr (ZTVar _) = 0 |
60 |
| cons_nr (ZFun _) = 1 |
|
61 |
| cons_nr ZProp = 2 |
|
62 |
| cons_nr (ZItself _) = 3 |
|
63 |
| cons_nr (ZType0 _) = 4 |
|
64 |
| cons_nr (ZType1 _) = 5 |
|
65 |
| cons_nr (ZType _) = 6; |
|
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
66 |
|
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
67 |
val fast_indexname_ord = Term_Ord.fast_indexname_ord; |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
68 |
val sort_ord = Term_Ord.sort_ord; |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
69 |
|
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
70 |
in |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
71 |
|
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
72 |
fun ztyp_ord TU = |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
73 |
if pointer_eq TU then EQUAL |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
74 |
else |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
75 |
(case TU of |
79119 | 76 |
(ZTVar (a, A), ZTVar (b, B)) => |
77 |
(case fast_indexname_ord (a, b) of EQUAL => sort_ord (A, B) | ord => ord) |
|
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
78 |
| (ZFun (T, T'), ZFun (U, U')) => |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
79 |
(case ztyp_ord (T, U) of EQUAL => ztyp_ord (T', U') | ord => ord) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
80 |
| (ZProp, ZProp) => EQUAL |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
81 |
| (ZItself T, ZItself U) => ztyp_ord (T, U) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
82 |
| (ZType0 a, ZType0 b) => fast_string_ord (a, b) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
83 |
| (ZType1 (a, T), ZType1 (b, U)) => |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
84 |
(case fast_string_ord (a, b) of EQUAL => ztyp_ord (T, U) | ord => ord) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
85 |
| (ZType (a, Ts), ZType (b, Us)) => |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
86 |
(case fast_string_ord (a, b) of EQUAL => dict_ord ztyp_ord (Ts, Us) | ord => ord) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
87 |
| (T, U) => int_ord (cons_nr T, cons_nr U)); |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
88 |
|
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
89 |
end; |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
90 |
|
79124 | 91 |
end; |
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
92 |
|
79124 | 93 |
|
94 |
(* term items *) |
|
95 |
||
96 |
structure ZTVars: |
|
97 |
sig |
|
98 |
include TERM_ITEMS |
|
99 |
val add_tvarsT: ztyp -> set -> set |
|
100 |
val add_tvars: zterm -> set -> set |
|
101 |
end = |
|
102 |
struct |
|
103 |
open TVars; |
|
104 |
val add_tvarsT = ZTerm.fold_tvars add_set; |
|
105 |
val add_tvars = ZTerm.fold_types add_tvarsT; |
|
106 |
end; |
|
107 |
||
108 |
structure ZVars: |
|
109 |
sig |
|
110 |
include TERM_ITEMS |
|
111 |
val add_vars: zterm -> set -> set |
|
112 |
end = |
|
113 |
struct |
|
114 |
||
115 |
structure Term_Items = Term_Items |
|
116 |
( |
|
117 |
type key = indexname * ztyp; |
|
118 |
val ord = pointer_eq_ord (prod_ord Term_Ord.fast_indexname_ord ZTerm.ztyp_ord); |
|
119 |
); |
|
120 |
open Term_Items; |
|
121 |
||
122 |
val add_vars = ZTerm.fold_aterms (fn ZVar v => add_set v | _ => I); |
|
123 |
||
124 |
end; |
|
125 |
||
126 |
||
127 |
(* proofs *) |
|
128 |
||
79126 | 129 |
datatype zproof_name = |
130 |
ZAxiom of string |
|
131 |
| ZOracle of string |
|
132 |
| ZBox of serial; |
|
133 |
||
79124 | 134 |
datatype zproof = |
135 |
ZDummy (*dummy proof*) |
|
79126 | 136 |
| ZConstP of zproof_name * zterm * ztyp ZTVars.table * zterm ZVars.table |
79124 | 137 |
| ZBoundP of int |
138 |
| ZHyp of zterm |
|
139 |
| ZAbst of string * ztyp * zproof |
|
140 |
| ZAbsP of string * zterm * zproof |
|
141 |
| ZAppt of zproof * zterm |
|
142 |
| ZAppP of zproof * zproof |
|
79126 | 143 |
| ZClassP of ztyp * class; (*OFCLASS proof from sorts algebra*) |
79124 | 144 |
|
145 |
||
146 |
||
147 |
(*** local ***) |
|
148 |
||
149 |
signature ZTERM = |
|
150 |
sig |
|
151 |
datatype ztyp = datatype ztyp |
|
152 |
datatype zterm = datatype zterm |
|
153 |
datatype zproof = datatype zproof |
|
154 |
val fold_tvars: (indexname * sort -> 'a -> 'a) -> ztyp -> 'a -> 'a |
|
155 |
val fold_aterms: (zterm -> 'a -> 'a) -> zterm -> 'a -> 'a |
|
156 |
val fold_types: (ztyp -> 'a -> 'a) -> zterm -> 'a -> 'a |
|
157 |
val ztyp_ord: ztyp * ztyp -> order |
|
158 |
val aconv_zterm: zterm * zterm -> bool |
|
159 |
val ztyp_of: typ -> ztyp |
|
160 |
val typ_of: ztyp -> typ |
|
161 |
val zterm_of: Consts.T -> term -> zterm |
|
162 |
val term_of: Consts.T -> zterm -> term |
|
163 |
val global_zterm_of: theory -> term -> zterm |
|
164 |
val global_term_of: theory -> zterm -> term |
|
165 |
val dummy_proof: 'a -> zproof |
|
166 |
val todo_proof: 'a -> zproof |
|
79126 | 167 |
val axiom_proof: theory -> string -> term -> zproof |
168 |
val oracle_proof: theory -> string -> term -> zproof |
|
79124 | 169 |
val assume_proof: theory -> term -> zproof |
170 |
val trivial_proof: theory -> term -> zproof |
|
171 |
val implies_intr_proof: theory -> term -> zproof -> zproof |
|
172 |
val forall_intr_proof: theory -> typ -> string * term -> zproof -> zproof |
|
173 |
val forall_elim_proof: theory -> term -> zproof -> zproof |
|
79128 | 174 |
val of_class_proof: typ * class -> zproof |
79124 | 175 |
val reflexive_proof: theory -> typ -> term -> zproof |
176 |
val symmetric_proof: theory -> typ -> term -> term -> zproof -> zproof |
|
177 |
val transitive_proof: theory -> typ -> term -> term -> term -> zproof -> zproof -> zproof |
|
178 |
val equal_intr_proof: theory -> term -> term -> zproof -> zproof -> zproof |
|
179 |
val equal_elim_proof: theory -> term -> term -> zproof -> zproof -> zproof |
|
180 |
val abstract_rule_proof: theory -> typ -> typ -> string * term -> term -> term -> zproof -> zproof |
|
181 |
val combination_proof: theory -> typ -> typ -> term -> term -> term -> term -> |
|
182 |
zproof -> zproof -> zproof |
|
79133 | 183 |
val generalize_proof: Names.set * Names.set -> int -> zproof -> zproof |
79149 | 184 |
val instantiate_proof: theory -> |
185 |
((indexname * sort) * typ) list * ((indexname * typ) * term) list -> zproof -> zproof |
|
79135 | 186 |
val varifyT_proof: ((string * sort) * (indexname * sort)) list -> zproof -> zproof |
79152 | 187 |
val legacy_freezeT_proof: term -> zproof -> zproof |
79150 | 188 |
val incr_indexes_proof: int -> zproof -> zproof |
79155 | 189 |
val rotate_proof: theory -> term list -> term -> (string * typ) list -> |
190 |
term list -> int -> zproof -> zproof |
|
191 |
val permute_prems_proof: theory -> term list -> int -> int -> zproof -> zproof |
|
79124 | 192 |
end; |
193 |
||
194 |
structure ZTerm: ZTERM = |
|
195 |
struct |
|
196 |
||
197 |
datatype ztyp = datatype ztyp; |
|
198 |
datatype zterm = datatype zterm; |
|
199 |
datatype zproof = datatype zproof; |
|
200 |
||
201 |
open ZTerm; |
|
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
202 |
|
79119 | 203 |
fun aconv_zterm (tm1, tm2) = |
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
204 |
pointer_eq (tm1, tm2) orelse |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
205 |
(case (tm1, tm2) of |
79119 | 206 |
(ZApp (t1, u1), ZApp (t2, u2)) => aconv_zterm (t1, t2) andalso aconv_zterm (u1, u2) |
207 |
| (ZAbs (_, T1, t1), ZAbs (_, T2, t2)) => aconv_zterm (t1, t2) andalso T1 = T2 |
|
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
208 |
| (a1, a2) => a1 = a2); |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
209 |
|
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
210 |
|
79155 | 211 |
(* derived operations *) |
212 |
||
213 |
val mk_ZAbst = fold_rev (fn (x, T) => fn prf => ZAbst (x, T, prf)); |
|
214 |
val mk_ZAbsP = fold_rev (fn t => fn prf => ZAbsP ("H", t, prf)); |
|
215 |
||
216 |
val mk_ZAppt = Library.foldl ZAppt; |
|
217 |
val mk_ZAppP = Library.foldl ZAppP; |
|
218 |
||
219 |
||
79132 | 220 |
(* map structure *) |
221 |
||
222 |
fun subst_type_same tvar = |
|
223 |
let |
|
224 |
fun typ (ZTVar x) = tvar x |
|
225 |
| typ (ZFun (T, U)) = (ZFun (typ T, Same.commit typ U) handle Same.SAME => ZFun (T, typ U)) |
|
226 |
| typ ZProp = raise Same.SAME |
|
227 |
| typ (ZItself T) = ZItself (typ T) |
|
228 |
| typ (ZType0 _) = raise Same.SAME |
|
229 |
| typ (ZType1 (a, T)) = ZType1 (a, typ T) |
|
230 |
| typ (ZType (a, Ts)) = ZType (a, Same.map typ Ts); |
|
231 |
in typ end; |
|
232 |
||
233 |
fun subst_term_same typ var = |
|
234 |
let |
|
235 |
fun term (ZVar (x, T)) = |
|
236 |
let val (T', same) = Same.commit_id typ T in |
|
237 |
(case Same.catch var (x, T') of |
|
238 |
NONE => if same then raise Same.SAME else ZVar (x, T') |
|
239 |
| SOME t' => t') |
|
240 |
end |
|
241 |
| term (ZBound _) = raise Same.SAME |
|
242 |
| term (ZConst0 _) = raise Same.SAME |
|
243 |
| term (ZConst1 (a, T)) = ZConst1 (a, typ T) |
|
244 |
| term (ZConst (a, Ts)) = ZConst (a, Same.map typ Ts) |
|
245 |
| term (ZAbs (a, T, t)) = |
|
246 |
(ZAbs (a, typ T, Same.commit term t) handle Same.SAME => ZAbs (a, T, term t)) |
|
247 |
| term (ZApp (t, u)) = |
|
248 |
(ZApp (term t, Same.commit term u) handle Same.SAME => ZApp (t, term u)) |
|
249 |
| term (ZClass (T, c)) = ZClass (typ T, c); |
|
250 |
in term end; |
|
251 |
||
79145 | 252 |
fun map_insts_same typ term (instT, inst) = |
253 |
let |
|
254 |
val changed = Unsynchronized.ref false; |
|
79146
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
255 |
fun apply f x = |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
256 |
(case Same.catch f x of |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
257 |
NONE => NONE |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
258 |
| some => (changed := true; some)); |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
259 |
|
79145 | 260 |
val instT' = |
261 |
(instT, instT) |-> ZTVars.fold (fn (v, T) => |
|
79146
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
262 |
(case apply typ T of |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
263 |
NONE => I |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
264 |
| SOME T' => ZTVars.update (v, T'))); |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
265 |
|
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
266 |
val vars' = |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
267 |
(inst, ZVars.empty) |-> ZVars.fold (fn ((v, T), _) => |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
268 |
(case apply typ T of |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
269 |
NONE => I |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
270 |
| SOME T' => ZVars.add ((v, T), (v, T')))); |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
271 |
|
79145 | 272 |
val inst' = |
79146
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
273 |
if ZVars.is_empty vars' then |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
274 |
(inst, inst) |-> ZVars.fold (fn (v, t) => |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
275 |
(case apply term t of |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
276 |
NONE => I |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
277 |
| SOME t' => ZVars.update (v, t'))) |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
278 |
else |
79145 | 279 |
ZVars.dest inst |
79146
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
280 |
|> map (fn (v, t) => (the_default v (ZVars.lookup vars' v), the_default t (apply term t))) |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
281 |
|> ZVars.make_strict; |
79145 | 282 |
in if ! changed then (instT', inst') else raise Same.SAME end; |
283 |
||
79132 | 284 |
fun map_proof_same typ term = |
285 |
let |
|
286 |
fun proof ZDummy = raise Same.SAME |
|
287 |
| proof (ZConstP (a, A, instT, inst)) = |
|
79148
99201e7b1d94
proper treatment of ZConstP: term represents body of closure;
wenzelm
parents:
79147
diff
changeset
|
288 |
let val (instT', inst') = map_insts_same typ term (instT, inst) |
99201e7b1d94
proper treatment of ZConstP: term represents body of closure;
wenzelm
parents:
79147
diff
changeset
|
289 |
in ZConstP (a, A, instT', inst') end |
79132 | 290 |
| proof (ZBoundP _) = raise Same.SAME |
291 |
| proof (ZHyp h) = ZHyp (term h) |
|
292 |
| proof (ZAbst (a, T, p)) = |
|
293 |
(ZAbst (a, typ T, Same.commit proof p) handle Same.SAME => ZAbst (a, T, proof p)) |
|
294 |
| proof (ZAbsP (a, t, p)) = |
|
295 |
(ZAbsP (a, term t, Same.commit proof p) handle Same.SAME => ZAbsP (a, t, proof p)) |
|
296 |
| proof (ZAppt (p, t)) = |
|
297 |
(ZAppt (proof p, Same.commit term t) handle Same.SAME => ZAppt (p, term t)) |
|
298 |
| proof (ZAppP (p, q)) = |
|
299 |
(ZAppP (proof p, Same.commit proof q) handle Same.SAME => ZAppP (p, proof q)) |
|
300 |
| proof (ZClassP (T, c)) = ZClassP (typ T, c); |
|
301 |
in proof end; |
|
302 |
||
79144 | 303 |
fun map_proof_types_same typ = |
304 |
map_proof_same typ (subst_term_same typ Same.same); |
|
305 |
||
79126 | 306 |
fun map_const_proof (f, g) prf = |
307 |
(case prf of |
|
308 |
ZConstP (a, A, instT, inst) => |
|
309 |
let |
|
310 |
val instT' = ZTVars.map (fn ((x, _), _) => fn y => the_default y (try f x)) instT; |
|
311 |
val inst' = ZVars.map (fn ((x, _), _) => fn y => the_default y (try g x)) inst; |
|
312 |
in ZConstP (a, A, instT', inst') end |
|
313 |
| _ => prf); |
|
79124 | 314 |
|
315 |
||
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
316 |
(* convert ztyp / zterm vs. regular typ / term *) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
317 |
|
79119 | 318 |
fun ztyp_of (TFree (a, S)) = ZTVar ((a, ~1), S) |
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
319 |
| ztyp_of (TVar v) = ZTVar v |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
320 |
| ztyp_of (Type ("fun", [T, U])) = ZFun (ztyp_of T, ztyp_of U) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
321 |
| ztyp_of (Type (c, [])) = if c = "prop" then ZProp else ZType0 c |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
322 |
| ztyp_of (Type (c, [T])) = if c = "itself" then ZItself (ztyp_of T) else ZType1 (c, ztyp_of T) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
323 |
| ztyp_of (Type (c, ts)) = ZType (c, map ztyp_of ts); |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
324 |
|
79119 | 325 |
fun typ_of (ZTVar ((a, ~1), S)) = TFree (a, S) |
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
326 |
| typ_of (ZTVar v) = TVar v |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
327 |
| typ_of (ZFun (T, U)) = typ_of T --> typ_of U |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
328 |
| typ_of ZProp = propT |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
329 |
| typ_of (ZItself T) = Term.itselfT (typ_of T) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
330 |
| typ_of (ZType0 c) = Type (c, []) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
331 |
| typ_of (ZType1 (c, T)) = Type (c, [typ_of T]) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
332 |
| typ_of (ZType (c, Ts)) = Type (c, map typ_of Ts); |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
333 |
|
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
334 |
fun zterm_of consts = |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
335 |
let |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
336 |
val typargs = Consts.typargs consts; |
79119 | 337 |
fun zterm (Free (x, T)) = ZVar ((x, ~1), ztyp_of T) |
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
338 |
| zterm (Var (xi, T)) = ZVar (xi, ztyp_of T) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
339 |
| zterm (Bound i) = ZBound i |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
340 |
| zterm (Const (c, T)) = |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
341 |
(case typargs (c, T) of |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
342 |
[] => ZConst0 c |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
343 |
| [T] => ZConst1 (c, ztyp_of T) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
344 |
| Ts => ZConst (c, map ztyp_of Ts)) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
345 |
| zterm (Abs (a, T, b)) = ZAbs (a, ztyp_of T, zterm b) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
346 |
| zterm ((t as Const (c, _)) $ (u as Const ("Pure.type", _))) = |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
347 |
if String.isSuffix Logic.class_suffix c then |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
348 |
ZClass (ztyp_of (Logic.dest_type u), Logic.class_of_const c) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
349 |
else ZApp (zterm t, zterm u) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
350 |
| zterm (t $ u) = ZApp (zterm t, zterm u); |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
351 |
in zterm end; |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
352 |
|
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
353 |
fun term_of consts = |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
354 |
let |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
355 |
val instance = Consts.instance consts; |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
356 |
fun const (c, Ts) = Const (c, instance (c, Ts)); |
79119 | 357 |
fun term (ZVar ((x, ~1), T)) = Free (x, typ_of T) |
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
358 |
| term (ZVar (xi, T)) = Var (xi, typ_of T) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
359 |
| term (ZBound i) = Bound i |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
360 |
| term (ZConst0 c) = const (c, []) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
361 |
| term (ZConst1 (c, T)) = const (c, [typ_of T]) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
362 |
| term (ZConst (c, Ts)) = const (c, map typ_of Ts) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
363 |
| term (ZAbs (a, T, b)) = Abs (a, typ_of T, term b) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
364 |
| term (ZApp (t, u)) = term t $ term u |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
365 |
| term (ZClass (T, c)) = Logic.mk_of_class (typ_of T, c); |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
366 |
in term end; |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
367 |
|
79119 | 368 |
val global_zterm_of = zterm_of o Sign.consts_of; |
369 |
val global_term_of = term_of o Sign.consts_of; |
|
79113
5109e4b2a292
pro-forma support for optional zproof: no proper content yet;
wenzelm
parents:
79098
diff
changeset
|
370 |
|
79119 | 371 |
|
372 |
||
373 |
(** proof construction **) |
|
79113
5109e4b2a292
pro-forma support for optional zproof: no proper content yet;
wenzelm
parents:
79098
diff
changeset
|
374 |
|
5109e4b2a292
pro-forma support for optional zproof: no proper content yet;
wenzelm
parents:
79098
diff
changeset
|
375 |
fun dummy_proof _ = ZDummy; |
5109e4b2a292
pro-forma support for optional zproof: no proper content yet;
wenzelm
parents:
79098
diff
changeset
|
376 |
val todo_proof = dummy_proof; |
5109e4b2a292
pro-forma support for optional zproof: no proper content yet;
wenzelm
parents:
79098
diff
changeset
|
377 |
|
79124 | 378 |
|
379 |
(* basic logic *) |
|
380 |
||
79126 | 381 |
fun const_proof thy a A = |
79119 | 382 |
let |
383 |
val t = global_zterm_of thy A; |
|
79154 | 384 |
val instT = |
385 |
ZTVars.build (t |> (fold_types o fold_tvars) (fn v => fn tab => |
|
386 |
if ZTVars.defined tab v then tab else ZTVars.update (v, ZTVar v) tab)); |
|
387 |
val inst = |
|
388 |
ZVars.build (t |> fold_aterms (fn a => fn tab => |
|
389 |
(case a of |
|
390 |
ZVar v => if ZVars.defined tab v then tab else ZVars.update (v, a) tab |
|
391 |
| _ => tab))); |
|
79126 | 392 |
in ZConstP (a, t, instT, inst) end; |
393 |
||
394 |
fun axiom_proof thy name = const_proof thy (ZAxiom name); |
|
395 |
fun oracle_proof thy name = const_proof thy (ZOracle name); |
|
79119 | 396 |
|
397 |
fun assume_proof thy A = |
|
398 |
ZHyp (global_zterm_of thy A); |
|
399 |
||
400 |
fun trivial_proof thy A = |
|
401 |
ZAbsP ("H", global_zterm_of thy A, ZBoundP 0); |
|
402 |
||
403 |
fun implies_intr_proof thy A prf = |
|
404 |
let |
|
405 |
val h = global_zterm_of thy A; |
|
79157 | 406 |
fun proof i (ZHyp t) = if aconv_zterm (h, t) then ZBoundP i else raise Same.SAME |
407 |
| proof i (ZAbst (x, T, p)) = ZAbst (x, T, proof i p) |
|
408 |
| proof i (ZAbsP (x, t, p)) = ZAbsP (x, t, proof (i + 1) p) |
|
409 |
| proof i (ZAppt (p, t)) = ZAppt (proof i p, t) |
|
410 |
| proof i (ZAppP (p, q)) = |
|
411 |
(ZAppP (proof i p, Same.commit (proof i) q) handle Same.SAME => |
|
412 |
ZAppP (p, proof i q)) |
|
413 |
| proof _ _ = raise Same.SAME; |
|
414 |
in ZAbsP ("H", h, Same.commit (proof 0) prf) end; |
|
79119 | 415 |
|
79124 | 416 |
fun forall_intr_proof thy T (a, x) prf = |
79119 | 417 |
let |
79124 | 418 |
val Z = ztyp_of T; |
79119 | 419 |
val z = global_zterm_of thy x; |
420 |
||
79157 | 421 |
fun term i b = |
79119 | 422 |
if aconv_zterm (b, z) then ZBound i |
423 |
else |
|
424 |
(case b of |
|
79157 | 425 |
ZAbs (x, T, t) => ZAbs (x, T, term (i + 1) t) |
79156 | 426 |
| ZApp (t, u) => |
79157 | 427 |
(ZApp (term i t, Same.commit (term i) u) handle Same.SAME => |
428 |
ZApp (t, term i u)) |
|
79156 | 429 |
| _ => raise Same.SAME); |
79119 | 430 |
|
79157 | 431 |
fun proof i (ZAbst (x, T, prf)) = ZAbst (x, T, proof (i + 1) prf) |
432 |
| proof i (ZAbsP (x, t, prf)) = |
|
433 |
(ZAbsP (x, term i t, Same.commit (proof i) prf) handle Same.SAME => |
|
434 |
ZAbsP (x, t, proof i prf)) |
|
435 |
| proof i (ZAppt (p, t)) = |
|
436 |
(ZAppt (proof i p, Same.commit (term i) t) handle Same.SAME => |
|
437 |
ZAppt (p, term i t)) |
|
438 |
| proof i (ZAppP (p, q)) = |
|
439 |
(ZAppP (proof i p, Same.commit (proof i) q) handle Same.SAME => |
|
440 |
ZAppP (p, proof i q)) |
|
441 |
| proof _ _ = raise Same.SAME; |
|
79119 | 442 |
|
79157 | 443 |
in ZAbst (a, Z, Same.commit (proof 0) prf) end; |
79119 | 444 |
|
445 |
fun forall_elim_proof thy t p = ZAppt (p, global_zterm_of thy t); |
|
446 |
||
79128 | 447 |
fun of_class_proof (T, c) = ZClassP (ztyp_of T, c); |
448 |
||
79124 | 449 |
|
450 |
(* equality *) |
|
451 |
||
452 |
local |
|
453 |
||
454 |
val thy0 = |
|
455 |
Context.the_global_context () |
|
456 |
|> Sign.add_types_global [(Binding.name "fun", 2, NoSyn), (Binding.name "prop", 0, NoSyn)] |
|
457 |
|> Sign.local_path |
|
458 |
|> Sign.add_consts |
|
459 |
[(Binding.name "all", (Term.aT [] --> propT) --> propT, NoSyn), |
|
460 |
(Binding.name "imp", propT --> propT --> propT, NoSyn), |
|
461 |
(Binding.name "eq", Term.aT [] --> Term.aT [] --> propT, NoSyn)]; |
|
462 |
||
463 |
val [reflexive_axiom, symmetric_axiom, transitive_axiom, equal_intr_axiom, equal_elim_axiom, |
|
464 |
abstract_rule_axiom, combination_axiom] = |
|
79126 | 465 |
Theory.equality_axioms |> map (fn (b, t) => axiom_proof thy0 (Sign.full_name thy0 b) t); |
79124 | 466 |
|
467 |
in |
|
468 |
||
469 |
val is_reflexive_proof = |
|
79126 | 470 |
fn ZConstP (ZAxiom "Pure.reflexive", _, _, _) => true | _ => false; |
79124 | 471 |
|
472 |
fun reflexive_proof thy T t = |
|
473 |
let |
|
474 |
val A = ztyp_of T; |
|
475 |
val x = global_zterm_of thy t; |
|
79126 | 476 |
in map_const_proof (fn "'a" => A, fn "x" => x) reflexive_axiom end; |
79124 | 477 |
|
478 |
fun symmetric_proof thy T t u prf = |
|
479 |
if is_reflexive_proof prf then prf |
|
480 |
else |
|
481 |
let |
|
482 |
val A = ztyp_of T; |
|
483 |
val x = global_zterm_of thy t; |
|
484 |
val y = global_zterm_of thy u; |
|
79126 | 485 |
val ax = map_const_proof (fn "'a" => A, fn "x" => x | "y" => y) symmetric_axiom; |
79124 | 486 |
in ZAppP (ax, prf) end; |
487 |
||
488 |
fun transitive_proof thy T t u v prf1 prf2 = |
|
489 |
if is_reflexive_proof prf1 then prf2 |
|
490 |
else if is_reflexive_proof prf2 then prf1 |
|
491 |
else |
|
492 |
let |
|
493 |
val A = ztyp_of T; |
|
494 |
val x = global_zterm_of thy t; |
|
495 |
val y = global_zterm_of thy u; |
|
496 |
val z = global_zterm_of thy v; |
|
79126 | 497 |
val ax = map_const_proof (fn "'a" => A, fn "x" => x | "y" => y | "z" => z) transitive_axiom; |
79124 | 498 |
in ZAppP (ZAppP (ax, prf1), prf2) end; |
499 |
||
500 |
fun equal_intr_proof thy t u prf1 prf2 = |
|
501 |
let |
|
502 |
val A = global_zterm_of thy t; |
|
503 |
val B = global_zterm_of thy u; |
|
79126 | 504 |
val ax = map_const_proof (undefined, fn "A" => A | "B" => B) equal_intr_axiom; |
79124 | 505 |
in ZAppP (ZAppP (ax, prf1), prf2) end; |
506 |
||
507 |
fun equal_elim_proof thy t u prf1 prf2 = |
|
508 |
let |
|
509 |
val A = global_zterm_of thy t; |
|
510 |
val B = global_zterm_of thy u; |
|
79126 | 511 |
val ax = map_const_proof (undefined, fn "A" => A | "B" => B) equal_elim_axiom; |
79124 | 512 |
in ZAppP (ZAppP (ax, prf1), prf2) end; |
513 |
||
514 |
fun abstract_rule_proof thy T U x t u prf = |
|
515 |
let |
|
516 |
val A = ztyp_of T; |
|
517 |
val B = ztyp_of U; |
|
518 |
val f = global_zterm_of thy t; |
|
519 |
val g = global_zterm_of thy u; |
|
79126 | 520 |
val ax = |
521 |
map_const_proof (fn "'a" => A | "'b" => B, fn "f" => f | "g" => g) |
|
522 |
abstract_rule_axiom; |
|
79124 | 523 |
in ZAppP (ax, forall_intr_proof thy T x prf) end; |
524 |
||
525 |
fun combination_proof thy T U f g t u prf1 prf2 = |
|
526 |
let |
|
527 |
val A = ztyp_of T; |
|
528 |
val B = ztyp_of U; |
|
529 |
val f' = global_zterm_of thy f; |
|
530 |
val g' = global_zterm_of thy g; |
|
531 |
val x = global_zterm_of thy t; |
|
532 |
val y = global_zterm_of thy u; |
|
533 |
val ax = |
|
79126 | 534 |
map_const_proof (fn "'a" => A | "'b" => B, fn "f" => f' | "g" => g' | "x" => x | "y" => y) |
79124 | 535 |
combination_axiom; |
536 |
in ZAppP (ZAppP (ax, prf1), prf2) end; |
|
537 |
||
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
538 |
end; |
79124 | 539 |
|
79133 | 540 |
|
541 |
(* substitution *) |
|
542 |
||
543 |
fun generalize_proof (tfrees, frees) idx prf = |
|
544 |
let |
|
545 |
val typ = |
|
546 |
if Names.is_empty tfrees then Same.same else |
|
547 |
subst_type_same (fn ((a, i), S) => |
|
548 |
if i = ~1 andalso Names.defined tfrees a then ZTVar ((a, idx), S) |
|
549 |
else raise Same.SAME); |
|
79136 | 550 |
val term = |
79147 | 551 |
subst_term_same typ (fn ((x, i), T) => |
552 |
if i = ~1 andalso Names.defined frees x then ZVar ((x, idx), T) |
|
553 |
else raise Same.SAME); |
|
79136 | 554 |
in Same.commit (map_proof_same typ term) prf end; |
79133 | 555 |
|
79149 | 556 |
fun instantiate_proof thy (Ts, ts) prf = |
557 |
let |
|
558 |
val instT = ZTVars.build (Ts |> fold (fn (v, T) => ZTVars.add (v, ztyp_of T))); |
|
559 |
val inst = |
|
560 |
ZVars.build (ts |> fold (fn ((v, T), t) => ZVars.add ((v, ztyp_of T), global_zterm_of thy t))); |
|
561 |
val typ = |
|
562 |
if ZTVars.is_empty instT then Same.same |
|
563 |
else subst_type_same (Same.function (ZTVars.lookup instT)); |
|
564 |
val term = subst_term_same typ (Same.function (ZVars.lookup inst)); |
|
565 |
in Same.commit (map_proof_same typ term) prf end; |
|
566 |
||
79135 | 567 |
fun varifyT_proof names prf = |
568 |
if null names then prf |
|
569 |
else |
|
570 |
let |
|
571 |
val tab = ZTVars.build (names |> fold (fn ((a, S), b) => ZTVars.add (((a, ~1), S), b))); |
|
79136 | 572 |
val typ = |
573 |
subst_type_same (fn v => |
|
574 |
(case ZTVars.lookup tab v of |
|
575 |
NONE => raise Same.SAME |
|
576 |
| SOME w => ZTVar w)); |
|
79144 | 577 |
in Same.commit (map_proof_types_same typ) prf end; |
79135 | 578 |
|
79152 | 579 |
fun legacy_freezeT_proof t prf = |
580 |
(case Type.legacy_freezeT t of |
|
581 |
NONE => prf |
|
582 |
| SOME f => |
|
583 |
let |
|
584 |
val tvar = ztyp_of o Same.function f; |
|
585 |
val typ = subst_type_same tvar; |
|
586 |
in Same.commit (map_proof_types_same typ) prf end); |
|
587 |
||
79150 | 588 |
fun incr_indexes_proof inc prf = |
589 |
let |
|
590 |
fun tvar ((a, i), S) = if i >= 0 then ZTVar ((a, i + inc), S) else raise Same.SAME; |
|
591 |
fun var ((x, i), T) = if i >= 0 then ZVar ((x, i + inc), T) else raise Same.SAME; |
|
592 |
val typ = subst_type_same tvar; |
|
593 |
val term = subst_term_same typ var; |
|
594 |
in Same.commit (map_proof_same typ term) prf end; |
|
595 |
||
79155 | 596 |
|
597 |
(* permutations *) |
|
598 |
||
599 |
fun rotate_proof thy Bs Bi' params asms m prf = |
|
600 |
let |
|
601 |
val ztyp = ztyp_of; |
|
602 |
val zterm = global_zterm_of thy; |
|
603 |
||
604 |
val i = length asms; |
|
605 |
val j = length Bs; |
|
606 |
in |
|
607 |
mk_ZAbsP (map zterm Bs @ [zterm Bi']) (mk_ZAppP (prf, map ZBoundP |
|
608 |
(j downto 1) @ [mk_ZAbst (map (apsnd ztyp) params) (mk_ZAbsP (map zterm asms) |
|
609 |
(mk_ZAppP (mk_ZAppt (ZBoundP i, map ZBound ((length params - 1) downto 0)), |
|
610 |
map ZBoundP (((i-m-1) downto 0) @ ((i-1) downto (i-m))))))])) |
|
611 |
end; |
|
612 |
||
613 |
fun permute_prems_proof thy prems' j k prf = |
|
614 |
let |
|
615 |
val zterm = global_zterm_of thy; |
|
616 |
val n = length prems'; |
|
617 |
in |
|
618 |
mk_ZAbsP (map zterm prems') |
|
619 |
(mk_ZAppP (prf, map ZBoundP ((n-1 downto n-j) @ (k-1 downto 0) @ (n-j-1 downto k)))) |
|
620 |
end; |
|
621 |
||
79124 | 622 |
end; |