author | wenzelm |
Mon, 18 Dec 2023 11:15:22 +0100 | |
changeset 79276 | 18287f3f48ca |
parent 79275 | 8368160d3c65 |
child 79277 | 7c415c73ebf7 |
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 |
||
79264
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
55 |
(* type 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 |
|
79264
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
91 |
|
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
92 |
(* term ordering and alpha-conversion *) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
93 |
|
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
94 |
local |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
95 |
|
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
96 |
fun cons_nr (ZVar _) = 0 |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
97 |
| cons_nr (ZBound _) = 1 |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
98 |
| cons_nr (ZConst0 _) = 2 |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
99 |
| cons_nr (ZConst1 _) = 3 |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
100 |
| cons_nr (ZConst _) = 4 |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
101 |
| cons_nr (ZAbs _) = 5 |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
102 |
| cons_nr (ZApp _) = 6 |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
103 |
| cons_nr (ZClass _) = 7; |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
104 |
|
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
105 |
fun struct_ord tu = |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
106 |
if pointer_eq tu then EQUAL |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
107 |
else |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
108 |
(case tu of |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
109 |
(ZAbs (_, _, t), ZAbs (_, _, u)) => struct_ord (t, u) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
110 |
| (ZApp (t1, t2), ZApp (u1, u2)) => |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
111 |
(case struct_ord (t1, u1) of EQUAL => struct_ord (t2, u2) | ord => ord) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
112 |
| (t, u) => int_ord (cons_nr t, cons_nr u)); |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
113 |
|
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
114 |
fun atoms_ord tu = |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
115 |
if pointer_eq tu then EQUAL |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
116 |
else |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
117 |
(case tu of |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
118 |
(ZAbs (_, _, t), ZAbs (_, _, u)) => atoms_ord (t, u) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
119 |
| (ZApp (t1, t2), ZApp (u1, u2)) => |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
120 |
(case atoms_ord (t1, u1) of EQUAL => atoms_ord (t2, u2) | ord => ord) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
121 |
| (ZConst0 a, ZConst0 b) => fast_string_ord (a, b) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
122 |
| (ZConst1 (a, _), ZConst1 (b, _)) => fast_string_ord (a, b) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
123 |
| (ZConst (a, _), ZConst (b, _)) => fast_string_ord (a, b) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
124 |
| (ZVar (xi, _), ZVar (yj, _)) => Term_Ord.fast_indexname_ord (xi, yj) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
125 |
| (ZBound i, ZBound j) => int_ord (i, j) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
126 |
| (ZClass (_, a), ZClass (_, b)) => fast_string_ord (a, b) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
127 |
| _ => EQUAL); |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
128 |
|
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
129 |
fun types_ord tu = |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
130 |
if pointer_eq tu then EQUAL |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
131 |
else |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
132 |
(case tu of |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
133 |
(ZAbs (_, T, t), ZAbs (_, U, u)) => |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
134 |
(case ztyp_ord (T, U) of EQUAL => types_ord (t, u) | ord => ord) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
135 |
| (ZApp (t1, t2), ZApp (u1, u2)) => |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
136 |
(case types_ord (t1, u1) of EQUAL => types_ord (t2, u2) | ord => ord) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
137 |
| (ZConst1 (_, T), ZConst1 (_, U)) => ztyp_ord (T, U) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
138 |
| (ZConst (_, Ts), ZConst (_, Us)) => dict_ord ztyp_ord (Ts, Us) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
139 |
| (ZVar (_, T), ZVar (_, U)) => ztyp_ord (T, U) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
140 |
| (ZClass (T, _), ZClass (U, _)) => ztyp_ord (T, U) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
141 |
| _ => EQUAL); |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
142 |
|
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
143 |
in |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
144 |
|
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
145 |
val fast_zterm_ord = struct_ord ||| atoms_ord ||| types_ord; |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
146 |
|
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
147 |
end; |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
148 |
|
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
149 |
fun aconv_zterm (tm1, tm2) = |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
150 |
pointer_eq (tm1, tm2) orelse |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
151 |
(case (tm1, tm2) of |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
152 |
(ZApp (t1, u1), ZApp (t2, u2)) => aconv_zterm (t1, t2) andalso aconv_zterm (u1, u2) |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
153 |
| (ZAbs (_, T1, t1), ZAbs (_, T2, t2)) => aconv_zterm (t1, t2) andalso T1 = T2 |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
154 |
| (a1, a2) => a1 = a2); |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
155 |
|
79124 | 156 |
end; |
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
157 |
|
79124 | 158 |
|
79264
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
159 |
(* tables and term items *) |
79124 | 160 |
|
79163 | 161 |
structure ZTypes = Table(type key = ztyp val ord = ZTerm.ztyp_ord); |
79264
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
162 |
structure ZTerms = Table(type key = zterm val ord = ZTerm.fast_zterm_ord); |
79163 | 163 |
|
79124 | 164 |
structure ZTVars: |
165 |
sig |
|
166 |
include TERM_ITEMS |
|
167 |
val add_tvarsT: ztyp -> set -> set |
|
168 |
val add_tvars: zterm -> set -> set |
|
169 |
end = |
|
170 |
struct |
|
171 |
open TVars; |
|
172 |
val add_tvarsT = ZTerm.fold_tvars add_set; |
|
173 |
val add_tvars = ZTerm.fold_types add_tvarsT; |
|
174 |
end; |
|
175 |
||
176 |
structure ZVars: |
|
177 |
sig |
|
178 |
include TERM_ITEMS |
|
179 |
val add_vars: zterm -> set -> set |
|
180 |
end = |
|
181 |
struct |
|
182 |
||
183 |
structure Term_Items = Term_Items |
|
184 |
( |
|
185 |
type key = indexname * ztyp; |
|
186 |
val ord = pointer_eq_ord (prod_ord Term_Ord.fast_indexname_ord ZTerm.ztyp_ord); |
|
187 |
); |
|
188 |
open Term_Items; |
|
189 |
||
190 |
val add_vars = ZTerm.fold_aterms (fn ZVar v => add_set v | _ => I); |
|
191 |
||
192 |
end; |
|
193 |
||
194 |
||
195 |
(* proofs *) |
|
196 |
||
79126 | 197 |
datatype zproof_name = |
198 |
ZAxiom of string |
|
199 |
| ZOracle of string |
|
200 |
| ZBox of serial; |
|
201 |
||
79124 | 202 |
datatype zproof = |
203 |
ZDummy (*dummy proof*) |
|
79212 | 204 |
| ZConstp of zproof_name * zterm * ztyp ZTVars.table * zterm ZVars.table |
205 |
| ZBoundp of int |
|
79124 | 206 |
| ZHyp of zterm |
207 |
| ZAbst of string * ztyp * zproof |
|
79212 | 208 |
| ZAbsp of string * zterm * zproof |
79124 | 209 |
| ZAppt of zproof * zterm |
79212 | 210 |
| ZAppp of zproof * zproof |
211 |
| ZClassp of ztyp * class; (*OFCLASS proof from sorts algebra*) |
|
79124 | 212 |
|
213 |
||
214 |
||
215 |
(*** local ***) |
|
216 |
||
217 |
signature ZTERM = |
|
218 |
sig |
|
219 |
datatype ztyp = datatype ztyp |
|
220 |
datatype zterm = datatype zterm |
|
221 |
datatype zproof = datatype zproof |
|
79265 | 222 |
exception ZTERM of string * ztyp list * zterm list * zproof list |
79263 | 223 |
type zproof_const = zproof_name * zterm * ztyp ZTVars.table * zterm ZVars.table |
79124 | 224 |
val fold_tvars: (indexname * sort -> 'a -> 'a) -> ztyp -> 'a -> 'a |
225 |
val fold_aterms: (zterm -> 'a -> 'a) -> zterm -> 'a -> 'a |
|
226 |
val fold_types: (ztyp -> 'a -> 'a) -> zterm -> 'a -> 'a |
|
79264
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
227 |
val ztyp_ord: ztyp ord |
07b93dee105f
more operations: zterm ordering that follows fast_term_ord;
wenzelm
parents:
79263
diff
changeset
|
228 |
val fast_zterm_ord: zterm ord |
79124 | 229 |
val aconv_zterm: zterm * zterm -> bool |
79212 | 230 |
val ZAbsts: (string * ztyp) list -> zproof -> zproof |
231 |
val ZAbsps: zterm list -> zproof -> zproof |
|
232 |
val ZAppts: zproof * zterm list -> zproof |
|
233 |
val ZAppps: zproof * zproof list -> zproof |
|
79214 | 234 |
val fold_proof_terms: (zterm -> 'a -> 'a) -> zproof -> 'a -> 'a |
235 |
val exists_proof_terms: (zterm -> bool) -> zproof -> bool |
|
79200 | 236 |
val incr_bv_same: int -> int -> zterm Same.operation |
237 |
val incr_bv: int -> int -> zterm -> zterm |
|
238 |
val incr_boundvars: int -> zterm -> zterm |
|
79273 | 239 |
val map_proof: ztyp Same.operation -> zterm Same.operation -> zproof -> zproof |
240 |
val map_proof_types: ztyp Same.operation -> zproof -> zproof |
|
79124 | 241 |
val ztyp_of: typ -> ztyp |
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
242 |
val zterm_cache: theory -> {zterm: term -> zterm, ztyp: typ -> ztyp} |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
243 |
val zterm_of: theory -> term -> zterm |
79124 | 244 |
val typ_of: ztyp -> typ |
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
245 |
val term_of: theory -> zterm -> term |
79214 | 246 |
val could_beta_contract: zterm -> bool |
79200 | 247 |
val norm_type: Type.tyenv -> ztyp -> ztyp |
248 |
val norm_term: theory -> Envir.env -> zterm -> zterm |
|
79270
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
249 |
val norm_proof: theory -> Envir.env -> term list -> zproof -> zproof |
79265 | 250 |
type zboxes = (zterm * zproof future) Inttab.table |
251 |
val empty_zboxes: zboxes |
|
252 |
val union_zboxes: zboxes -> zboxes -> zboxes |
|
253 |
val box_proof: theory -> term list -> term -> zboxes * zproof -> zboxes * zproof |
|
79126 | 254 |
val axiom_proof: theory -> string -> term -> zproof |
255 |
val oracle_proof: theory -> string -> term -> zproof |
|
79124 | 256 |
val assume_proof: theory -> term -> zproof |
257 |
val trivial_proof: theory -> term -> zproof |
|
258 |
val implies_intr_proof: theory -> term -> zproof -> zproof |
|
259 |
val forall_intr_proof: theory -> typ -> string * term -> zproof -> zproof |
|
260 |
val forall_elim_proof: theory -> term -> zproof -> zproof |
|
79128 | 261 |
val of_class_proof: typ * class -> zproof |
79124 | 262 |
val reflexive_proof: theory -> typ -> term -> zproof |
263 |
val symmetric_proof: theory -> typ -> term -> term -> zproof -> zproof |
|
264 |
val transitive_proof: theory -> typ -> term -> term -> term -> zproof -> zproof -> zproof |
|
265 |
val equal_intr_proof: theory -> term -> term -> zproof -> zproof -> zproof |
|
266 |
val equal_elim_proof: theory -> term -> term -> zproof -> zproof -> zproof |
|
267 |
val abstract_rule_proof: theory -> typ -> typ -> string * term -> term -> term -> zproof -> zproof |
|
268 |
val combination_proof: theory -> typ -> typ -> term -> term -> term -> term -> |
|
269 |
zproof -> zproof -> zproof |
|
79133 | 270 |
val generalize_proof: Names.set * Names.set -> int -> zproof -> zproof |
79149 | 271 |
val instantiate_proof: theory -> |
272 |
((indexname * sort) * typ) list * ((indexname * typ) * term) list -> zproof -> zproof |
|
79135 | 273 |
val varifyT_proof: ((string * sort) * (indexname * sort)) list -> zproof -> zproof |
79152 | 274 |
val legacy_freezeT_proof: term -> zproof -> zproof |
79155 | 275 |
val rotate_proof: theory -> term list -> term -> (string * typ) list -> |
276 |
term list -> int -> zproof -> zproof |
|
277 |
val permute_prems_proof: theory -> term list -> int -> int -> zproof -> zproof |
|
79234 | 278 |
val incr_indexes_proof: int -> zproof -> zproof |
79237 | 279 |
val lift_proof: theory -> term -> int -> term list -> zproof -> zproof |
79270
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
280 |
val assumption_proof: theory -> Envir.env -> term list -> term -> int -> term list -> |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
281 |
zproof -> zproof |
79261 | 282 |
val bicompose_proof: theory -> Envir.env -> int -> bool -> term list -> term list -> |
79270
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
283 |
term option -> term list -> int -> int -> term list -> zproof -> zproof -> zproof |
79124 | 284 |
end; |
285 |
||
286 |
structure ZTerm: ZTERM = |
|
287 |
struct |
|
288 |
||
289 |
datatype ztyp = datatype ztyp; |
|
290 |
datatype zterm = datatype zterm; |
|
291 |
datatype zproof = datatype zproof; |
|
292 |
||
79265 | 293 |
exception ZTERM of string * ztyp list * zterm list * zproof list; |
294 |
||
79124 | 295 |
open ZTerm; |
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
296 |
|
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
297 |
|
79155 | 298 |
(* derived operations *) |
299 |
||
79234 | 300 |
val ZFuns = Library.foldr ZFun; |
301 |
||
79212 | 302 |
val ZAbsts = fold_rev (fn (x, T) => fn prf => ZAbst (x, T, prf)); |
303 |
val ZAbsps = fold_rev (fn t => fn prf => ZAbsp ("H", t, prf)); |
|
79155 | 304 |
|
79212 | 305 |
val ZAppts = Library.foldl ZAppt; |
306 |
val ZAppps = Library.foldl ZAppp; |
|
79155 | 307 |
|
79234 | 308 |
fun combound (t, n, k) = |
309 |
if k > 0 then ZApp (combound (t, n + 1, k - 1), ZBound n) else t; |
|
310 |
||
79155 | 311 |
|
79214 | 312 |
(* fold *) |
313 |
||
314 |
fun fold_proof_terms f = |
|
315 |
let |
|
316 |
fun proof (ZConstp (_, _, _, inst)) = ZVars.fold (f o #2) inst |
|
317 |
| proof (ZAbst (_, _, p)) = proof p |
|
318 |
| proof (ZAbsp (_, t, p)) = f t #> proof p |
|
319 |
| proof (ZAppt (p, t)) = proof p #> f t |
|
320 |
| proof (ZAppp (p, q)) = proof p #> proof q |
|
321 |
| proof _ = I; |
|
322 |
in proof end; |
|
323 |
||
324 |
local exception Found in |
|
325 |
||
326 |
fun exists_proof_terms P prf = |
|
327 |
(fold_proof_terms (fn t => fn () => if P t then raise Found else ()) prf (); true) |
|
328 |
handle Found => true; |
|
329 |
||
330 |
end; |
|
331 |
||
332 |
||
79200 | 333 |
(* substitution of bound variables *) |
334 |
||
335 |
fun incr_bv_same inc = |
|
336 |
if inc = 0 then fn _ => Same.same |
|
337 |
else |
|
338 |
let |
|
339 |
fun term lev (ZBound i) = if i >= lev then ZBound (i + inc) else raise Same.SAME |
|
340 |
| term lev (ZAbs (a, T, t)) = ZAbs (a, T, term (lev + 1) t) |
|
341 |
| term lev (ZApp (t, u)) = |
|
342 |
(ZApp (term lev t, Same.commit (term lev) u) handle Same.SAME => |
|
343 |
ZApp (t, term lev u)) |
|
344 |
| term _ _ = raise Same.SAME; |
|
345 |
in term end; |
|
346 |
||
347 |
fun incr_bv inc lev = Same.commit (incr_bv_same inc lev); |
|
348 |
||
349 |
fun incr_boundvars inc = incr_bv inc 0; |
|
350 |
||
351 |
fun subst_bound arg body = |
|
352 |
let |
|
353 |
fun term lev (ZBound i) = |
|
354 |
if i < lev then raise Same.SAME (*var is locally bound*) |
|
355 |
else if i = lev then incr_boundvars lev arg |
|
356 |
else ZBound (i - 1) (*loose: change it*) |
|
357 |
| term lev (ZAbs (a, T, t)) = ZAbs (a, T, term (lev + 1) t) |
|
358 |
| term lev (ZApp (t, u)) = |
|
359 |
(ZApp (term lev t, Same.commit (term lev) u) |
|
360 |
handle Same.SAME => ZApp (t, term lev u)) |
|
361 |
| term _ _ = raise Same.SAME; |
|
362 |
in Same.commit (term 0) body end; |
|
363 |
||
364 |
||
79268 | 365 |
(* substitution of free or schematic variables *) |
79132 | 366 |
|
367 |
fun subst_type_same tvar = |
|
368 |
let |
|
369 |
fun typ (ZTVar x) = tvar x |
|
370 |
| typ (ZFun (T, U)) = (ZFun (typ T, Same.commit typ U) handle Same.SAME => ZFun (T, typ U)) |
|
371 |
| typ ZProp = raise Same.SAME |
|
372 |
| typ (ZItself T) = ZItself (typ T) |
|
373 |
| typ (ZType0 _) = raise Same.SAME |
|
374 |
| typ (ZType1 (a, T)) = ZType1 (a, typ T) |
|
375 |
| typ (ZType (a, Ts)) = ZType (a, Same.map typ Ts); |
|
376 |
in typ end; |
|
377 |
||
378 |
fun subst_term_same typ var = |
|
379 |
let |
|
380 |
fun term (ZVar (x, T)) = |
|
381 |
let val (T', same) = Same.commit_id typ T in |
|
382 |
(case Same.catch var (x, T') of |
|
383 |
NONE => if same then raise Same.SAME else ZVar (x, T') |
|
384 |
| SOME t' => t') |
|
385 |
end |
|
386 |
| term (ZBound _) = raise Same.SAME |
|
387 |
| term (ZConst0 _) = raise Same.SAME |
|
388 |
| term (ZConst1 (a, T)) = ZConst1 (a, typ T) |
|
389 |
| term (ZConst (a, Ts)) = ZConst (a, Same.map typ Ts) |
|
390 |
| term (ZAbs (a, T, t)) = |
|
391 |
(ZAbs (a, typ T, Same.commit term t) handle Same.SAME => ZAbs (a, T, term t)) |
|
392 |
| term (ZApp (t, u)) = |
|
393 |
(ZApp (term t, Same.commit term u) handle Same.SAME => ZApp (t, term u)) |
|
394 |
| term (ZClass (T, c)) = ZClass (typ T, c); |
|
395 |
in term end; |
|
396 |
||
79270
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
397 |
fun instantiate_type_same instT = |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
398 |
if ZTVars.is_empty instT then Same.same |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
399 |
else ZTypes.unsynchronized_cache (subst_type_same (Same.function (ZTVars.lookup instT))); |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
400 |
|
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
401 |
fun instantiate_term_same typ inst = |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
402 |
subst_term_same typ (Same.function (ZVars.lookup inst)); |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
403 |
|
79268 | 404 |
|
405 |
(* map types/terms within proof *) |
|
406 |
||
79145 | 407 |
fun map_insts_same typ term (instT, inst) = |
408 |
let |
|
409 |
val changed = Unsynchronized.ref false; |
|
79146
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
410 |
fun apply f x = |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
411 |
(case Same.catch f x of |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
412 |
NONE => NONE |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
413 |
| some => (changed := true; some)); |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
414 |
|
79145 | 415 |
val instT' = |
416 |
(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
|
417 |
(case apply typ T of |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
418 |
NONE => I |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
419 |
| SOME T' => ZTVars.update (v, T'))); |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
420 |
|
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
421 |
val vars' = |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
422 |
(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
|
423 |
(case apply typ T of |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
424 |
NONE => I |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
425 |
| 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
|
426 |
|
79145 | 427 |
val inst' = |
79146
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
428 |
if ZVars.is_empty vars' then |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
429 |
(inst, inst) |-> ZVars.fold (fn (v, t) => |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
430 |
(case apply term t of |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
431 |
NONE => I |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
432 |
| SOME t' => ZVars.update (v, t'))) |
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
433 |
else |
79145 | 434 |
ZVars.dest inst |
79146
feb94ac5df41
more accurate treatment of term variables after instantiation of type variables;
wenzelm
parents:
79145
diff
changeset
|
435 |
|> 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
|
436 |
|> ZVars.make_strict; |
79145 | 437 |
in if ! changed then (instT', inst') else raise Same.SAME end; |
438 |
||
79132 | 439 |
fun map_proof_same typ term = |
440 |
let |
|
441 |
fun proof ZDummy = raise Same.SAME |
|
79212 | 442 |
| proof (ZConstp (a, A, instT, inst)) = |
79148
99201e7b1d94
proper treatment of ZConstP: term represents body of closure;
wenzelm
parents:
79147
diff
changeset
|
443 |
let val (instT', inst') = map_insts_same typ term (instT, inst) |
79212 | 444 |
in ZConstp (a, A, instT', inst') end |
445 |
| proof (ZBoundp _) = raise Same.SAME |
|
79275
8368160d3c65
proper treatment of proof hyps: unchangeable, like bound;
wenzelm
parents:
79273
diff
changeset
|
446 |
| proof (ZHyp _) = raise Same.SAME |
79132 | 447 |
| proof (ZAbst (a, T, p)) = |
448 |
(ZAbst (a, typ T, Same.commit proof p) handle Same.SAME => ZAbst (a, T, proof p)) |
|
79212 | 449 |
| proof (ZAbsp (a, t, p)) = |
450 |
(ZAbsp (a, term t, Same.commit proof p) handle Same.SAME => ZAbsp (a, t, proof p)) |
|
79132 | 451 |
| proof (ZAppt (p, t)) = |
452 |
(ZAppt (proof p, Same.commit term t) handle Same.SAME => ZAppt (p, term t)) |
|
79212 | 453 |
| proof (ZAppp (p, q)) = |
454 |
(ZAppp (proof p, Same.commit proof q) handle Same.SAME => ZAppp (p, proof q)) |
|
455 |
| proof (ZClassp (T, c)) = ZClassp (typ T, c); |
|
79132 | 456 |
in proof end; |
457 |
||
79273 | 458 |
fun map_proof typ term = Same.commit (map_proof_same typ term); |
459 |
fun map_proof_types typ = map_proof typ (subst_term_same typ Same.same); |
|
79144 | 460 |
|
79124 | 461 |
|
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
462 |
(* convert ztyp / zterm vs. regular typ / term *) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
463 |
|
79119 | 464 |
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
|
465 |
| ztyp_of (TVar v) = ZTVar v |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
466 |
| 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
|
467 |
| 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
|
468 |
| 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
|
469 |
| 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
|
470 |
|
79163 | 471 |
fun ztyp_cache () = Typtab.unsynchronized_cache ztyp_of; |
472 |
||
79226 | 473 |
fun zterm_cache thy = |
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
474 |
let |
79226 | 475 |
val typargs = Consts.typargs (Sign.consts_of thy); |
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
476 |
|
79163 | 477 |
val ztyp = ztyp_cache (); |
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
478 |
|
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
479 |
fun zterm (Free (x, T)) = ZVar ((x, ~1), ztyp T) |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
480 |
| zterm (Var (xi, T)) = ZVar (xi, ztyp T) |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
481 |
| zterm (Bound i) = ZBound i |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
482 |
| zterm (Const (c, T)) = |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
483 |
(case typargs (c, T) of |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
484 |
[] => ZConst0 c |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
485 |
| [T] => ZConst1 (c, ztyp T) |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
486 |
| Ts => ZConst (c, map ztyp Ts)) |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
487 |
| zterm (Abs (a, T, b)) = ZAbs (a, ztyp T, zterm b) |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
488 |
| zterm ((t as Const (c, _)) $ (u as Const ("Pure.type", _))) = |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
489 |
if String.isSuffix Logic.class_suffix c then |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
490 |
ZClass (ztyp (Logic.dest_type u), Logic.class_of_const c) |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
491 |
else ZApp (zterm t, zterm u) |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
492 |
| zterm (t $ u) = ZApp (zterm t, zterm u); |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
493 |
in {ztyp = ztyp, zterm = zterm} end; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
494 |
|
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
495 |
val zterm_of = #zterm o zterm_cache; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
496 |
|
79119 | 497 |
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
|
498 |
| typ_of (ZTVar v) = TVar v |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
499 |
| 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
|
500 |
| typ_of ZProp = propT |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
501 |
| typ_of (ZItself T) = Term.itselfT (typ_of T) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
502 |
| typ_of (ZType0 c) = Type (c, []) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
503 |
| typ_of (ZType1 (c, T)) = Type (c, [typ_of T]) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
504 |
| 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
|
505 |
|
79201 | 506 |
fun typ_cache () = ZTypes.unsynchronized_cache typ_of; |
507 |
||
79226 | 508 |
fun term_of thy = |
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
509 |
let |
79226 | 510 |
val instance = Consts.instance (Sign.consts_of thy); |
511 |
||
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
512 |
fun const (c, Ts) = Const (c, instance (c, Ts)); |
79226 | 513 |
|
79119 | 514 |
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
|
515 |
| term (ZVar (xi, T)) = Var (xi, typ_of T) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
516 |
| term (ZBound i) = Bound i |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
517 |
| term (ZConst0 c) = const (c, []) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
518 |
| term (ZConst1 (c, T)) = const (c, [typ_of T]) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
519 |
| term (ZConst (c, Ts)) = const (c, map typ_of Ts) |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
520 |
| 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
|
521 |
| term (ZApp (t, u)) = term t $ term u |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
522 |
| 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
|
523 |
in term end; |
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
524 |
|
79119 | 525 |
|
79200 | 526 |
(* beta normalization wrt. environment *) |
527 |
||
79214 | 528 |
fun could_beta_contract (ZApp (ZAbs _, _)) = true |
529 |
| could_beta_contract (ZApp (t, u)) = could_beta_contract t orelse could_beta_contract u |
|
530 |
| could_beta_contract (ZAbs (_, _, b)) = could_beta_contract b |
|
531 |
| could_beta_contract _ = false; |
|
532 |
||
79271 | 533 |
val beta_norm_same = |
534 |
let |
|
535 |
fun norm (ZApp (ZAbs (_, _, body), t)) = subst_bound t body |
|
536 |
| norm (ZApp (f, t)) = |
|
537 |
((case norm f of |
|
538 |
ZAbs (_, _, body) => subst_bound t body |
|
539 |
| nf => ZApp (nf, Same.commit norm t)) |
|
540 |
handle Same.SAME => ZApp (f, norm t)) |
|
541 |
| norm (ZAbs (a, T, t)) = ZAbs (a, T, Same.commit norm t) |
|
542 |
| norm _ = raise Same.SAME; |
|
543 |
in norm end; |
|
544 |
||
79200 | 545 |
fun norm_type_same ztyp tyenv = |
546 |
if Vartab.is_empty tyenv then Same.same |
|
547 |
else |
|
548 |
let |
|
549 |
fun norm (ZTVar v) = |
|
550 |
(case Type.lookup tyenv v of |
|
551 |
SOME U => Same.commit norm (ztyp U) |
|
552 |
| NONE => raise Same.SAME) |
|
553 |
| norm (ZFun (T, U)) = |
|
554 |
(ZFun (norm T, Same.commit norm U) |
|
555 |
handle Same.SAME => ZFun (T, norm U)) |
|
556 |
| norm ZProp = raise Same.SAME |
|
557 |
| norm (ZItself T) = ZItself (norm T) |
|
558 |
| norm (ZType0 _) = raise Same.SAME |
|
559 |
| norm (ZType1 (a, T)) = ZType1 (a, norm T) |
|
560 |
| norm (ZType (a, Ts)) = ZType (a, Same.map norm Ts); |
|
561 |
in norm end; |
|
562 |
||
79269 | 563 |
fun norm_term_same {ztyp, zterm, typ} (envir as Envir.Envir {tyenv, tenv, ...}) = |
564 |
let |
|
565 |
val lookup = |
|
566 |
if Vartab.is_empty tenv then K NONE |
|
567 |
else ZVars.unsynchronized_cache (apsnd typ #> Envir.lookup envir #> Option.map zterm); |
|
79200 | 568 |
|
79269 | 569 |
val normT = norm_type_same ztyp tyenv; |
79200 | 570 |
|
79269 | 571 |
fun norm (ZVar (xi, T)) = |
572 |
(case lookup (xi, T) of |
|
573 |
SOME u => Same.commit norm u |
|
574 |
| NONE => ZVar (xi, normT T)) |
|
575 |
| norm (ZBound _) = raise Same.SAME |
|
576 |
| norm (ZConst0 _) = raise Same.SAME |
|
577 |
| norm (ZConst1 (a, T)) = ZConst1 (a, normT T) |
|
578 |
| norm (ZConst (a, Ts)) = ZConst (a, Same.map normT Ts) |
|
579 |
| norm (ZAbs (a, T, t)) = |
|
580 |
(ZAbs (a, normT T, Same.commit norm t) |
|
581 |
handle Same.SAME => ZAbs (a, T, norm t)) |
|
582 |
| norm (ZApp (ZAbs (_, _, body), t)) = Same.commit norm (subst_bound t body) |
|
583 |
| norm (ZApp (f, t)) = |
|
584 |
((case norm f of |
|
585 |
ZAbs (_, _, body) => Same.commit norm (subst_bound t body) |
|
586 |
| nf => ZApp (nf, Same.commit norm t)) |
|
587 |
handle Same.SAME => ZApp (f, norm t)) |
|
588 |
| norm _ = raise Same.SAME; |
|
79271 | 589 |
in fn t => if Envir.is_empty envir then beta_norm_same t else norm t end; |
79200 | 590 |
|
79270
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
591 |
fun norm_proof_cache (cache as {ztyp, ...}) (envir as Envir.Envir {tyenv, ...}) = |
79269 | 592 |
let |
79270
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
593 |
val norm_tvar = ZTVar #> Same.commit (norm_type_same ztyp tyenv); |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
594 |
val norm_var = ZVar #> Same.commit (norm_term_same cache envir); |
79269 | 595 |
in |
79270
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
596 |
fn visible => fn prf => |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
597 |
if (Envir.is_empty envir orelse null visible) |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
598 |
andalso not (exists_proof_terms could_beta_contract prf) |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
599 |
then prf |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
600 |
else |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
601 |
let |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
602 |
fun add_tvar v tab = |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
603 |
if ZTVars.defined tab v then tab else ZTVars.update (v, norm_tvar v) tab; |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
604 |
|
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
605 |
val inst_typ = |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
606 |
if Vartab.is_empty tyenv then Same.same |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
607 |
else |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
608 |
ZTVars.build (visible |> (fold o Term.fold_types o Term.fold_atyps) |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
609 |
(fn TVar v => add_tvar v | _ => I)) |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
610 |
|> instantiate_type_same; |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
611 |
|
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
612 |
fun add_var (a, T) tab = |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
613 |
let val v = (a, Same.commit inst_typ (ztyp T)) |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
614 |
in if ZVars.defined tab v then tab else ZVars.update (v, norm_var v) tab end; |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
615 |
|
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
616 |
val inst_term = |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
617 |
ZVars.build (visible |> (fold o Term.fold_aterms) (fn Var v => add_var v | _ => I)) |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
618 |
|> instantiate_term_same inst_typ; |
79272
899f37f6d218
proper beta_norm after instantiation (amending 90c5aadcc4b2);
wenzelm
parents:
79271
diff
changeset
|
619 |
|
899f37f6d218
proper beta_norm after instantiation (amending 90c5aadcc4b2);
wenzelm
parents:
79271
diff
changeset
|
620 |
val norm_term = Same.compose beta_norm_same inst_term; |
79273 | 621 |
in map_proof inst_typ norm_term prf end |
79269 | 622 |
end; |
79210 | 623 |
|
624 |
fun norm_cache thy = |
|
79205 | 625 |
let |
79226 | 626 |
val {ztyp, zterm} = zterm_cache thy; |
79205 | 627 |
val typ = typ_cache (); |
628 |
in {ztyp = ztyp, zterm = zterm, typ = typ} end; |
|
629 |
||
79214 | 630 |
fun norm_type tyenv = Same.commit (norm_type_same (ztyp_cache ()) tyenv); |
631 |
fun norm_term thy envir = Same.commit (norm_term_same (norm_cache thy) envir); |
|
79270
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
632 |
fun norm_proof thy envir = norm_proof_cache (norm_cache thy) envir; |
79200 | 633 |
|
634 |
||
79119 | 635 |
|
636 |
(** proof construction **) |
|
79113
5109e4b2a292
pro-forma support for optional zproof: no proper content yet;
wenzelm
parents:
79098
diff
changeset
|
637 |
|
79161 | 638 |
(* constants *) |
79124 | 639 |
|
79263 | 640 |
type zproof_const = zproof_name * zterm * ztyp ZTVars.table * zterm ZVars.table; |
641 |
||
642 |
fun zproof_const a A : zproof_const = |
|
79119 | 643 |
let |
79154 | 644 |
val instT = |
79263 | 645 |
ZTVars.build (A |> (fold_types o fold_tvars) (fn v => fn tab => |
79154 | 646 |
if ZTVars.defined tab v then tab else ZTVars.update (v, ZTVar v) tab)); |
647 |
val inst = |
|
79263 | 648 |
ZVars.build (A |> fold_aterms (fn t => fn tab => |
649 |
(case t of |
|
650 |
ZVar v => if ZVars.defined tab v then tab else ZVars.update (v, t) tab |
|
79154 | 651 |
| _ => tab))); |
79263 | 652 |
in (a, A, instT, inst) end; |
79126 | 653 |
|
79263 | 654 |
fun make_const_proof (f, g) ((a, A, instT, inst): zproof_const) = |
655 |
let |
|
656 |
val instT' = ZTVars.map (fn ((x, _), _) => fn y => the_default y (try f x)) instT; |
|
657 |
val inst' = ZVars.map (fn ((x, _), _) => fn y => the_default y (try g x)) inst; |
|
658 |
in ZConstp (a, A, instT', inst') end; |
|
79161 | 659 |
|
660 |
||
79265 | 661 |
(* closed proof boxes *) |
662 |
||
663 |
type zboxes = (zterm * zproof future) Inttab.table; |
|
664 |
||
665 |
val empty_zboxes: zboxes = Inttab.empty; |
|
666 |
val union_zboxes: zboxes -> zboxes -> zboxes = curry (Inttab.merge (K true)); |
|
667 |
fun add_zboxes entry : zboxes -> zboxes = Inttab.update_new entry; |
|
668 |
||
669 |
local |
|
670 |
||
671 |
fun close_prop hyps concl = |
|
672 |
fold_rev (fn A => fn B => ZApp (ZApp (ZConst0 "Pure.imp", A), B)) hyps concl; |
|
673 |
||
674 |
fun close_proof hyps prf = |
|
675 |
let |
|
676 |
val m = length hyps - 1; |
|
677 |
val bounds = ZTerms.build (hyps |> fold_index (fn (i, h) => ZTerms.update (h, m - i))); |
|
678 |
||
679 |
fun proof lev (ZHyp t) = |
|
680 |
(case ZTerms.lookup bounds t of |
|
681 |
SOME i => ZBoundp (lev + i) |
|
682 |
| NONE => raise ZTERM ("Unbound proof hypothesis", [], [t], [])) |
|
683 |
| proof lev (ZAbst (x, T, p)) = ZAbst (x, T, proof lev p) |
|
684 |
| proof lev (ZAbsp (x, t, p)) = ZAbsp (x, t, proof (lev + 1) p) |
|
685 |
| proof lev (ZAppt (p, t)) = ZAppt (proof lev p, t) |
|
686 |
| proof lev (ZAppp (p, q)) = |
|
687 |
(ZAppp (proof lev p, Same.commit (proof lev) q) handle Same.SAME => |
|
688 |
ZAppp (p, proof lev q)) |
|
689 |
| proof _ _ = raise Same.SAME; |
|
690 |
in ZAbsps hyps (Same.commit (proof 0) prf) end; |
|
691 |
||
692 |
in |
|
693 |
||
694 |
fun box_proof thy hyps concl (zboxes: zboxes, prf) = |
|
695 |
let |
|
696 |
val {zterm, ...} = zterm_cache thy; |
|
697 |
val hyps' = map zterm hyps; |
|
698 |
val concl' = zterm concl; |
|
699 |
||
700 |
val prop' = close_prop hyps' concl'; |
|
701 |
val prf' = close_proof hyps' prf; |
|
702 |
||
703 |
val i = serial (); |
|
704 |
val zboxes' = add_zboxes (i, (prop', Future.value prf')) zboxes; |
|
705 |
val prf'' = ZAppts (ZConstp (zproof_const (ZBox i) prop'), hyps'); |
|
706 |
in (zboxes', prf'') end; |
|
707 |
||
708 |
end; |
|
709 |
||
710 |
||
79161 | 711 |
(* basic logic *) |
712 |
||
79263 | 713 |
fun axiom_proof thy name A = |
714 |
ZConstp (zproof_const (ZAxiom name) (zterm_of thy A)); |
|
79161 | 715 |
|
79263 | 716 |
fun oracle_proof thy name A = |
717 |
ZConstp (zproof_const (ZOracle name) (zterm_of thy A)); |
|
79119 | 718 |
|
719 |
fun assume_proof thy A = |
|
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
720 |
ZHyp (zterm_of thy A); |
79119 | 721 |
|
722 |
fun trivial_proof thy A = |
|
79212 | 723 |
ZAbsp ("H", zterm_of thy A, ZBoundp 0); |
79119 | 724 |
|
725 |
fun implies_intr_proof thy A prf = |
|
726 |
let |
|
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
727 |
val h = zterm_of thy A; |
79212 | 728 |
fun proof i (ZHyp t) = if aconv_zterm (h, t) then ZBoundp i else raise Same.SAME |
79157 | 729 |
| proof i (ZAbst (x, T, p)) = ZAbst (x, T, proof i p) |
79212 | 730 |
| proof i (ZAbsp (x, t, p)) = ZAbsp (x, t, proof (i + 1) p) |
79157 | 731 |
| proof i (ZAppt (p, t)) = ZAppt (proof i p, t) |
79212 | 732 |
| proof i (ZAppp (p, q)) = |
733 |
(ZAppp (proof i p, Same.commit (proof i) q) handle Same.SAME => |
|
734 |
ZAppp (p, proof i q)) |
|
79157 | 735 |
| proof _ _ = raise Same.SAME; |
79212 | 736 |
in ZAbsp ("H", h, Same.commit (proof 0) prf) end; |
79119 | 737 |
|
79124 | 738 |
fun forall_intr_proof thy T (a, x) prf = |
79119 | 739 |
let |
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
740 |
val {ztyp, zterm} = zterm_cache thy; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
741 |
val Z = ztyp T; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
742 |
val z = zterm x; |
79119 | 743 |
|
79157 | 744 |
fun term i b = |
79119 | 745 |
if aconv_zterm (b, z) then ZBound i |
746 |
else |
|
747 |
(case b of |
|
79157 | 748 |
ZAbs (x, T, t) => ZAbs (x, T, term (i + 1) t) |
79156 | 749 |
| ZApp (t, u) => |
79157 | 750 |
(ZApp (term i t, Same.commit (term i) u) handle Same.SAME => |
751 |
ZApp (t, term i u)) |
|
79156 | 752 |
| _ => raise Same.SAME); |
79119 | 753 |
|
79157 | 754 |
fun proof i (ZAbst (x, T, prf)) = ZAbst (x, T, proof (i + 1) prf) |
79212 | 755 |
| proof i (ZAbsp (x, t, prf)) = |
756 |
(ZAbsp (x, term i t, Same.commit (proof i) prf) handle Same.SAME => |
|
757 |
ZAbsp (x, t, proof i prf)) |
|
79157 | 758 |
| proof i (ZAppt (p, t)) = |
759 |
(ZAppt (proof i p, Same.commit (term i) t) handle Same.SAME => |
|
760 |
ZAppt (p, term i t)) |
|
79212 | 761 |
| proof i (ZAppp (p, q)) = |
762 |
(ZAppp (proof i p, Same.commit (proof i) q) handle Same.SAME => |
|
763 |
ZAppp (p, proof i q)) |
|
79157 | 764 |
| proof _ _ = raise Same.SAME; |
79119 | 765 |
|
79157 | 766 |
in ZAbst (a, Z, Same.commit (proof 0) prf) end; |
79119 | 767 |
|
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
768 |
fun forall_elim_proof thy t p = ZAppt (p, zterm_of thy t); |
79119 | 769 |
|
79212 | 770 |
fun of_class_proof (T, c) = ZClassp (ztyp_of T, c); |
79128 | 771 |
|
79124 | 772 |
|
773 |
(* equality *) |
|
774 |
||
775 |
local |
|
776 |
||
777 |
val thy0 = |
|
778 |
Context.the_global_context () |
|
779 |
|> Sign.add_types_global [(Binding.name "fun", 2, NoSyn), (Binding.name "prop", 0, NoSyn)] |
|
780 |
|> Sign.local_path |
|
781 |
|> Sign.add_consts |
|
782 |
[(Binding.name "all", (Term.aT [] --> propT) --> propT, NoSyn), |
|
783 |
(Binding.name "imp", propT --> propT --> propT, NoSyn), |
|
784 |
(Binding.name "eq", Term.aT [] --> Term.aT [] --> propT, NoSyn)]; |
|
785 |
||
786 |
val [reflexive_axiom, symmetric_axiom, transitive_axiom, equal_intr_axiom, equal_elim_axiom, |
|
787 |
abstract_rule_axiom, combination_axiom] = |
|
79263 | 788 |
Theory.equality_axioms |> map (fn (b, t) => |
789 |
let val ZConstp c = axiom_proof thy0 (Sign.full_name thy0 b) t in c end); |
|
79124 | 790 |
|
791 |
in |
|
792 |
||
793 |
val is_reflexive_proof = |
|
79212 | 794 |
fn ZConstp (ZAxiom "Pure.reflexive", _, _, _) => true | _ => false; |
79124 | 795 |
|
796 |
fun reflexive_proof thy T t = |
|
797 |
let |
|
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
798 |
val {ztyp, zterm} = zterm_cache thy; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
799 |
val A = ztyp T; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
800 |
val x = zterm t; |
79263 | 801 |
in make_const_proof (fn "'a" => A, fn "x" => x) reflexive_axiom end; |
79124 | 802 |
|
803 |
fun symmetric_proof thy T t u prf = |
|
804 |
if is_reflexive_proof prf then prf |
|
805 |
else |
|
806 |
let |
|
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
807 |
val {ztyp, zterm} = zterm_cache thy; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
808 |
val A = ztyp T; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
809 |
val x = zterm t; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
810 |
val y = zterm u; |
79263 | 811 |
val ax = make_const_proof (fn "'a" => A, fn "x" => x | "y" => y) symmetric_axiom; |
79212 | 812 |
in ZAppp (ax, prf) end; |
79124 | 813 |
|
814 |
fun transitive_proof thy T t u v prf1 prf2 = |
|
815 |
if is_reflexive_proof prf1 then prf2 |
|
816 |
else if is_reflexive_proof prf2 then prf1 |
|
817 |
else |
|
818 |
let |
|
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
819 |
val {ztyp, zterm} = zterm_cache thy; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
820 |
val A = ztyp T; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
821 |
val x = zterm t; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
822 |
val y = zterm u; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
823 |
val z = zterm v; |
79263 | 824 |
val ax = make_const_proof (fn "'a" => A, fn "x" => x | "y" => y | "z" => z) transitive_axiom; |
79212 | 825 |
in ZAppp (ZAppp (ax, prf1), prf2) end; |
79124 | 826 |
|
827 |
fun equal_intr_proof thy t u prf1 prf2 = |
|
828 |
let |
|
79160 | 829 |
val {zterm, ...} = zterm_cache thy; |
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
830 |
val A = zterm t; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
831 |
val B = zterm u; |
79263 | 832 |
val ax = make_const_proof (undefined, fn "A" => A | "B" => B) equal_intr_axiom; |
79212 | 833 |
in ZAppp (ZAppp (ax, prf1), prf2) end; |
79124 | 834 |
|
835 |
fun equal_elim_proof thy t u prf1 prf2 = |
|
836 |
let |
|
79160 | 837 |
val {zterm, ...} = zterm_cache thy; |
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
838 |
val A = zterm t; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
839 |
val B = zterm u; |
79263 | 840 |
val ax = make_const_proof (undefined, fn "A" => A | "B" => B) equal_elim_axiom; |
79212 | 841 |
in ZAppp (ZAppp (ax, prf1), prf2) end; |
79124 | 842 |
|
843 |
fun abstract_rule_proof thy T U x t u prf = |
|
844 |
let |
|
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
845 |
val {ztyp, zterm} = zterm_cache thy; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
846 |
val A = ztyp T; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
847 |
val B = ztyp U; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
848 |
val f = zterm t; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
849 |
val g = zterm u; |
79126 | 850 |
val ax = |
79263 | 851 |
make_const_proof (fn "'a" => A | "'b" => B, fn "f" => f | "g" => g) |
79126 | 852 |
abstract_rule_axiom; |
79212 | 853 |
in ZAppp (ax, forall_intr_proof thy T x prf) end; |
79124 | 854 |
|
855 |
fun combination_proof thy T U f g t u prf1 prf2 = |
|
856 |
let |
|
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
857 |
val {ztyp, zterm} = zterm_cache thy; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
858 |
val A = ztyp T; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
859 |
val B = ztyp U; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
860 |
val f' = zterm f; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
861 |
val g' = zterm g; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
862 |
val x = zterm t; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
863 |
val y = zterm u; |
79124 | 864 |
val ax = |
79263 | 865 |
make_const_proof (fn "'a" => A | "'b" => B, fn "f" => f' | "g" => g' | "x" => x | "y" => y) |
79124 | 866 |
combination_axiom; |
79212 | 867 |
in ZAppp (ZAppp (ax, prf1), prf2) end; |
79124 | 868 |
|
79098
d8940e5bbb25
tight representation of types / terms / proof terms (presently unused);
wenzelm
parents:
diff
changeset
|
869 |
end; |
79124 | 870 |
|
79133 | 871 |
|
872 |
(* substitution *) |
|
873 |
||
874 |
fun generalize_proof (tfrees, frees) idx prf = |
|
875 |
let |
|
876 |
val typ = |
|
877 |
if Names.is_empty tfrees then Same.same else |
|
79163 | 878 |
ZTypes.unsynchronized_cache |
879 |
(subst_type_same (fn ((a, i), S) => |
|
880 |
if i = ~1 andalso Names.defined tfrees a then ZTVar ((a, idx), S) |
|
881 |
else raise Same.SAME)); |
|
79136 | 882 |
val term = |
79147 | 883 |
subst_term_same typ (fn ((x, i), T) => |
884 |
if i = ~1 andalso Names.defined frees x then ZVar ((x, idx), T) |
|
885 |
else raise Same.SAME); |
|
79273 | 886 |
in map_proof typ term prf end; |
79133 | 887 |
|
79149 | 888 |
fun instantiate_proof thy (Ts, ts) prf = |
889 |
let |
|
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
890 |
val {ztyp, zterm} = zterm_cache thy; |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
891 |
val instT = ZTVars.build (Ts |> fold (fn (v, T) => ZTVars.add (v, ztyp T))); |
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
892 |
val inst = ZVars.build (ts |> fold (fn ((v, T), t) => ZVars.add ((v, ztyp T), zterm t))); |
79270
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
893 |
val typ = instantiate_type_same instT; |
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
894 |
val term = instantiate_term_same typ inst; |
79273 | 895 |
in map_proof typ term prf end; |
79149 | 896 |
|
79135 | 897 |
fun varifyT_proof names prf = |
898 |
if null names then prf |
|
899 |
else |
|
900 |
let |
|
901 |
val tab = ZTVars.build (names |> fold (fn ((a, S), b) => ZTVars.add (((a, ~1), S), b))); |
|
79136 | 902 |
val typ = |
79163 | 903 |
ZTypes.unsynchronized_cache (subst_type_same (fn v => |
79136 | 904 |
(case ZTVars.lookup tab v of |
905 |
NONE => raise Same.SAME |
|
79163 | 906 |
| SOME w => ZTVar w))); |
79273 | 907 |
in map_proof_types typ prf end; |
79135 | 908 |
|
79152 | 909 |
fun legacy_freezeT_proof t prf = |
910 |
(case Type.legacy_freezeT t of |
|
911 |
NONE => prf |
|
912 |
| SOME f => |
|
913 |
let |
|
914 |
val tvar = ztyp_of o Same.function f; |
|
79163 | 915 |
val typ = ZTypes.unsynchronized_cache (subst_type_same tvar); |
79273 | 916 |
in map_proof_types typ prf end); |
79152 | 917 |
|
79155 | 918 |
|
919 |
(* permutations *) |
|
920 |
||
921 |
fun rotate_proof thy Bs Bi' params asms m prf = |
|
922 |
let |
|
79158
3c7ab17380a8
performance tuning: cache for ztyp_of within zterm_of;
wenzelm
parents:
79157
diff
changeset
|
923 |
val {ztyp, zterm} = zterm_cache thy; |
79155 | 924 |
val i = length asms; |
925 |
val j = length Bs; |
|
926 |
in |
|
79212 | 927 |
ZAbsps (map zterm Bs @ [zterm Bi']) (ZAppps (prf, map ZBoundp |
928 |
(j downto 1) @ [ZAbsts (map (apsnd ztyp) params) (ZAbsps (map zterm asms) |
|
929 |
(ZAppps (ZAppts (ZBoundp i, map ZBound ((length params - 1) downto 0)), |
|
930 |
map ZBoundp (((i-m-1) downto 0) @ ((i-1) downto (i-m))))))])) |
|
79155 | 931 |
end; |
932 |
||
933 |
fun permute_prems_proof thy prems' j k prf = |
|
934 |
let |
|
79160 | 935 |
val {zterm, ...} = zterm_cache thy; |
79155 | 936 |
val n = length prems'; |
937 |
in |
|
79212 | 938 |
ZAbsps (map zterm prems') |
939 |
(ZAppps (prf, map ZBoundp ((n-1 downto n-j) @ (k-1 downto 0) @ (n-j-1 downto k)))) |
|
79155 | 940 |
end; |
941 |
||
79211 | 942 |
|
79234 | 943 |
(* lifting *) |
944 |
||
945 |
fun incr_tvar_same inc = |
|
946 |
if inc = 0 then Same.same |
|
947 |
else |
|
948 |
let fun tvar ((a, i), S) = if i >= 0 then ZTVar ((a, i + inc), S) else raise Same.SAME |
|
949 |
in ZTypes.unsynchronized_cache (subst_type_same tvar) end; |
|
950 |
||
951 |
fun incr_indexes_proof inc prf = |
|
952 |
let |
|
953 |
val typ = incr_tvar_same inc; |
|
954 |
fun var ((x, i), T) = if i >= 0 then ZVar ((x, i + inc), T) else raise Same.SAME; |
|
955 |
val term = subst_term_same typ var; |
|
79273 | 956 |
in map_proof typ term prf end; |
79234 | 957 |
|
958 |
fun lift_proof thy gprop inc prems prf = |
|
959 |
let |
|
960 |
val {ztyp, zterm} = zterm_cache thy; |
|
961 |
||
962 |
val typ = incr_tvar_same inc; |
|
963 |
||
964 |
fun term Ts lev = |
|
965 |
if null Ts andalso inc = 0 then Same.same |
|
966 |
else |
|
967 |
let |
|
968 |
val n = length Ts; |
|
969 |
fun incr lev (ZVar ((x, i), T)) = |
|
970 |
if i >= 0 then combound (ZVar ((x, i + inc), ZFuns (Ts, Same.commit typ T)), lev, n) |
|
971 |
else raise Same.SAME |
|
972 |
| incr _ (ZBound _) = raise Same.SAME |
|
973 |
| incr _ (ZConst0 _) = raise Same.SAME |
|
974 |
| incr _ (ZConst1 (c, T)) = ZConst1 (c, typ T) |
|
975 |
| incr _ (ZConst (c, Ts)) = ZConst (c, Same.map typ Ts) |
|
976 |
| incr lev (ZAbs (x, T, t)) = |
|
977 |
(ZAbs (x, typ T, Same.commit (incr (lev + 1)) t) |
|
978 |
handle Same.SAME => ZAbs (x, T, incr (lev + 1) t)) |
|
979 |
| incr lev (ZApp (t, u)) = |
|
980 |
(ZApp (incr lev t, Same.commit (incr lev) u) |
|
981 |
handle Same.SAME => ZApp (t, incr lev u)) |
|
982 |
| incr _ (ZClass (T, c)) = ZClass (typ T, c); |
|
983 |
in incr lev end; |
|
984 |
||
985 |
fun proof Ts lev (ZAbst (a, T, p)) = |
|
986 |
(ZAbst (a, typ T, Same.commit (proof Ts (lev + 1)) p) |
|
987 |
handle Same.SAME => ZAbst (a, T, proof Ts (lev + 1) p)) |
|
988 |
| proof Ts lev (ZAbsp (a, t, p)) = |
|
989 |
(ZAbsp (a, term Ts lev t, Same.commit (proof Ts lev) p) |
|
990 |
handle Same.SAME => ZAbsp (a, t, proof Ts lev p)) |
|
991 |
| proof Ts lev (ZAppt (p, t)) = |
|
992 |
(ZAppt (proof Ts lev p, Same.commit (term Ts lev) t) |
|
993 |
handle Same.SAME => ZAppt (p, term Ts lev t)) |
|
994 |
| proof Ts lev (ZAppp (p, q)) = |
|
995 |
(ZAppp (proof Ts lev p, Same.commit (proof Ts lev) q) |
|
996 |
handle Same.SAME => ZAppp (p, proof Ts lev q)) |
|
997 |
| proof Ts lev (ZConstp (a, A, instT, inst)) = |
|
998 |
let val (instT', insts') = map_insts_same typ (term Ts lev) (instT, inst) |
|
999 |
in ZConstp (a, A, instT', insts') end |
|
1000 |
| proof _ _ (ZClassp (T, c)) = ZClassp (typ T, c) |
|
1001 |
| proof _ _ _ = raise Same.SAME; |
|
1002 |
||
1003 |
val k = length prems; |
|
1004 |
||
1005 |
fun mk_app b (i, j, p) = |
|
1006 |
if b then (i - 1, j, ZAppp (p, ZBoundp i)) else (i, j - 1, ZAppt (p, ZBound j)); |
|
1007 |
||
1008 |
fun lift Ts bs i j (Const ("Pure.imp", _) $ A $ B) = |
|
1009 |
ZAbsp ("H", Same.commit (term Ts 0) (zterm A), lift Ts (true :: bs) (i + 1) j B) |
|
1010 |
| lift Ts bs i j (Const ("Pure.all", _) $ Abs (a, T, t)) = |
|
1011 |
let val T' = ztyp T |
|
1012 |
in ZAbst (a, T', lift (T' :: Ts) (false :: bs) i (j + 1) t) end |
|
1013 |
| lift Ts bs i j _ = |
|
1014 |
ZAppps (Same.commit (proof (rev Ts) 0) prf, |
|
1015 |
map (fn k => (#3 (fold_rev mk_app bs (i - 1, j - 1, ZBoundp k)))) (i + k - 1 downto i)); |
|
79237 | 1016 |
in ZAbsps (map zterm prems) (lift [] [] 0 0 gprop) end; |
79234 | 1017 |
|
1018 |
||
79211 | 1019 |
(* higher-order resolution *) |
1020 |
||
1021 |
fun mk_asm_prf C i m = |
|
1022 |
let |
|
79212 | 1023 |
fun imp _ i 0 = ZBoundp i |
1024 |
| imp (ZApp (ZApp (ZConst0 "Pure.imp", A), B)) i m = ZAbsp ("H", A, imp B (i + 1) (m - 1)) |
|
1025 |
| imp _ i _ = ZBoundp i; |
|
79211 | 1026 |
fun all (ZApp (ZConst1 ("Pure.all", _), ZAbs (a, T, t))) = ZAbst (a, T, all t) |
1027 |
| all t = imp t (~ i) m |
|
1028 |
in all C end; |
|
1029 |
||
79270
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
1030 |
fun assumption_proof thy envir Bs Bi n visible prf = |
79211 | 1031 |
let |
1032 |
val cache as {zterm, ...} = norm_cache thy; |
|
1033 |
val normt = zterm #> Same.commit (norm_term_same cache envir); |
|
1034 |
in |
|
79212 | 1035 |
ZAbsps (map normt Bs) |
1036 |
(ZAppps (prf, map ZBoundp (length Bs - 1 downto 0) @ [mk_asm_prf (normt Bi) n ~1])) |
|
79270
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
1037 |
|> norm_proof_cache cache envir visible |
79211 | 1038 |
end; |
1039 |
||
79261 | 1040 |
fun flatten_params_proof i j n (ZApp (ZApp (ZConst0 "Pure.imp", A), B), k) = |
1041 |
ZAbsp ("H", A, flatten_params_proof (i + 1) j n (B, k)) |
|
1042 |
| flatten_params_proof i j n (ZApp (ZConst1 ("Pure.all", _), ZAbs (a, T, t)), k) = |
|
1043 |
ZAbst (a, T, flatten_params_proof i (j + 1) n (t, k)) |
|
1044 |
| flatten_params_proof i j n (_, k) = |
|
1045 |
ZAppps (ZAppts (ZBoundp (k + i), |
|
1046 |
map ZBound (j - 1 downto 0)), map ZBoundp (remove (op =) (i - n) (i - 1 downto 0))); |
|
1047 |
||
79270
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
1048 |
fun bicompose_proof thy env smax flatten Bs As A oldAs n m visible rprf sprf = |
79261 | 1049 |
let |
1050 |
val cache as {zterm, ...} = norm_cache thy; |
|
1051 |
val normt = zterm #> Same.commit (norm_term_same cache env); |
|
79270
90c5aadcc4b2
more robust norm_proof: turn env into instantiation, based on visible statement;
wenzelm
parents:
79269
diff
changeset
|
1052 |
val normp = norm_proof_cache cache env visible; |
79261 | 1053 |
|
1054 |
val lb = length Bs; |
|
1055 |
val la = length As; |
|
1056 |
||
1057 |
fun proof p q = |
|
1058 |
ZAbsps (map normt (Bs @ As)) |
|
1059 |
(ZAppp (ZAppps (q, map ZBoundp (lb + la - 1 downto la)), |
|
1060 |
ZAppps (p, (if n > 0 then [mk_asm_prf (normt (the A)) n m] else []) @ |
|
1061 |
map (if flatten then flatten_params_proof 0 0 n else ZBoundp o snd) |
|
1062 |
(map normt oldAs ~~ (la - 1 downto 0))))); |
|
1063 |
in |
|
1064 |
if Envir.is_empty env then proof rprf sprf |
|
1065 |
else proof (normp rprf) (if Envir.above env smax then sprf else normp sprf) |
|
1066 |
end; |
|
1067 |
||
79124 | 1068 |
end; |