author | berghofe |
Mon, 30 Sep 2002 16:44:00 +0200 | |
changeset 13610 | d4a2ac255447 |
parent 13342 | 915d4d004643 |
child 13669 | a9f229eafba7 |
permissions | -rw-r--r-- |
11522 | 1 |
(* Title: Pure/Proof/reconstruct.ML |
2 |
ID: $Id$ |
|
11539 | 3 |
Author: Stefan Berghofer, TU Muenchen |
4 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
|
11522 | 5 |
|
6 |
Reconstruction of partial proof terms. |
|
7 |
*) |
|
8 |
||
9 |
signature RECONSTRUCT = |
|
10 |
sig |
|
11 |
val quiet_mode : bool ref |
|
11613 | 12 |
val reconstruct_proof : Sign.sg -> term -> Proofterm.proof -> Proofterm.proof |
13256
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
13 |
val prop_of' : term list -> Proofterm.proof -> term |
13138 | 14 |
val prop_of : Proofterm.proof -> term |
13342
915d4d004643
expand_proof now also takes an optional term describing the proposition
berghofe
parents:
13256
diff
changeset
|
15 |
val expand_proof : Sign.sg -> (string * term option) list -> |
915d4d004643
expand_proof now also takes an optional term describing the proposition
berghofe
parents:
13256
diff
changeset
|
16 |
Proofterm.proof -> Proofterm.proof |
11522 | 17 |
end; |
18 |
||
19 |
structure Reconstruct : RECONSTRUCT = |
|
20 |
struct |
|
21 |
||
22 |
open Proofterm; |
|
23 |
||
24 |
val quiet_mode = ref true; |
|
25 |
fun message s = if !quiet_mode then () else writeln s; |
|
26 |
||
27 |
fun vars_of t = rev (foldl_aterms |
|
28 |
(fn (vs, v as Var _) => v ins vs | (vs, _) => vs) ([], t)); |
|
29 |
||
30 |
fun forall_intr (t, prop) = |
|
31 |
let val (a, T) = (case t of Var ((a, _), T) => (a, T) | Free p => p) |
|
32 |
in all T $ Abs (a, T, abstract_over (t, prop)) end; |
|
33 |
||
34 |
fun forall_intr_vfs prop = foldr forall_intr |
|
35 |
(vars_of prop @ sort (make_ord atless) (term_frees prop), prop); |
|
36 |
||
12001 | 37 |
fun forall_intr_prf (t, prf) = |
38 |
let val (a, T) = (case t of Var ((a, _), T) => (a, T) | Free p => p) |
|
39 |
in Abst (a, Some T, prf_abstract_over t prf) end; |
|
40 |
||
41 |
fun forall_intr_vfs_prf prop prf = foldr forall_intr_prf |
|
42 |
(vars_of prop @ sort (make_ord atless) (term_frees prop), prf); |
|
43 |
||
11522 | 44 |
fun merge_envs (Envir.Envir {asol=asol1, iTs=iTs1, maxidx=maxidx1}) |
45 |
(Envir.Envir {asol=asol2, iTs=iTs2, maxidx=maxidx2}) = |
|
46 |
Envir.Envir {asol=Vartab.merge (op aconv) (asol1, asol2), |
|
47 |
iTs=Vartab.merge (op =) (iTs1, iTs2), |
|
48 |
maxidx=Int.max (maxidx1, maxidx2)}; |
|
49 |
||
50 |
fun strip_abs (_::Ts) (Abs (_, _, t)) = strip_abs Ts t |
|
51 |
| strip_abs _ t = t; |
|
52 |
||
53 |
||
54 |
(******************************************************************************** |
|
55 |
generate constraints for proof term |
|
56 |
*********************************************************************************) |
|
57 |
||
58 |
fun mk_var env Ts T = |
|
59 |
let val (env', v) = Envir.genvar "a" (env, rev Ts ---> T) |
|
60 |
in (env', list_comb (v, map Bound (length Ts - 1 downto 0))) end; |
|
61 |
||
62 |
fun mk_tvar (Envir.Envir {iTs, asol, maxidx}, s) = |
|
63 |
(Envir.Envir {iTs = iTs, asol = asol, maxidx = maxidx+1}, |
|
64 |
TVar (("'t", maxidx+1), s)); |
|
65 |
||
66 |
fun mk_abs Ts t = foldl (fn (u, T) => Abs ("", T, u)) (t, Ts); |
|
67 |
||
68 |
fun make_Tconstraints_cprf maxidx cprf = |
|
69 |
let |
|
70 |
fun mk_Tcnstrts maxidx Ts (Abst (s, Some T, cprf)) = |
|
71 |
let val (cs, cprf', maxidx') = mk_Tcnstrts maxidx (T::Ts) cprf; |
|
72 |
in (cs, Abst (s, Some T, cprf'), maxidx') end |
|
73 |
| mk_Tcnstrts maxidx Ts (Abst (s, None, cprf)) = |
|
74 |
let |
|
75 |
val T' = TVar (("'t", maxidx+1), ["logic"]); |
|
76 |
val (cs, cprf', maxidx') = mk_Tcnstrts (maxidx+1) (T'::Ts) cprf; |
|
77 |
in (cs, Abst (s, Some T', cprf'), maxidx') end |
|
78 |
| mk_Tcnstrts maxidx Ts (AbsP (s, Some t, cprf)) = |
|
79 |
let val (cs, cprf', maxidx') = mk_Tcnstrts maxidx Ts cprf; |
|
80 |
in ((mk_abs Ts t, rev Ts ---> propT)::cs, AbsP (s, Some t, cprf'), maxidx') end |
|
81 |
| mk_Tcnstrts maxidx Ts (AbsP (s, None, cprf)) = |
|
82 |
let val (cs, cprf', maxidx') = mk_Tcnstrts maxidx Ts cprf; |
|
83 |
in (cs, AbsP (s, None, cprf'), maxidx') end |
|
11613 | 84 |
| mk_Tcnstrts maxidx Ts (cprf1 %% cprf2) = |
11522 | 85 |
let |
86 |
val (cs, cprf1', maxidx') = mk_Tcnstrts maxidx Ts cprf1; |
|
87 |
val (cs', cprf2', maxidx'') = mk_Tcnstrts maxidx' Ts cprf2; |
|
11613 | 88 |
in (cs' @ cs, cprf1' %% cprf2', maxidx'') end |
89 |
| mk_Tcnstrts maxidx Ts (cprf % Some t) = |
|
11522 | 90 |
let val (cs, cprf', maxidx') = mk_Tcnstrts maxidx Ts cprf; |
91 |
in ((mk_abs Ts t, rev Ts ---> TypeInfer.logicT)::cs, |
|
11613 | 92 |
cprf' % Some t, maxidx') |
11522 | 93 |
end |
11613 | 94 |
| mk_Tcnstrts maxidx Ts (cprf % None) = |
11522 | 95 |
let val (cs, cprf', maxidx') = mk_Tcnstrts maxidx Ts cprf; |
11613 | 96 |
in (cs, cprf % None, maxidx') end |
11522 | 97 |
| mk_Tcnstrts maxidx _ cprf = ([], cprf, maxidx); |
98 |
in mk_Tcnstrts maxidx [] cprf end; |
|
99 |
||
100 |
fun unifyT sg env T U = |
|
101 |
let |
|
102 |
val Envir.Envir {asol, iTs, maxidx} = env; |
|
12527 | 103 |
val (iTs', maxidx') = Type.unify (Sign.tsig_of sg) (iTs, maxidx) (T, U) |
11660 | 104 |
in Envir.Envir {asol=asol, iTs=iTs', maxidx=maxidx'} end |
105 |
handle Type.TUNIFY => error ("Non-unifiable types:\n" ^ |
|
106 |
Sign.string_of_typ sg T ^ "\n\n" ^ Sign.string_of_typ sg U); |
|
11522 | 107 |
|
12236 | 108 |
fun decompose sg env Ts t u = case (Envir.head_norm env t, Envir.head_norm env u) of |
109 |
(Const ("all", _) $ t, Const ("all", _) $ u) => decompose sg env Ts t u |
|
110 |
| (Const ("==>", _) $ t1 $ t2, Const ("==>", _) $ u1 $ u2) => |
|
11660 | 111 |
let val (env', cs) = decompose sg env Ts t1 u1 |
112 |
in apsnd (curry op @ cs) (decompose sg env' Ts t2 u2) end |
|
12236 | 113 |
| (Abs (_, T, t), Abs (_, U, u)) => |
11660 | 114 |
decompose sg (unifyT sg env T U) (T::Ts) t u |
12236 | 115 |
| (t, u) => (env, [(mk_abs Ts t, mk_abs Ts u)]); |
11522 | 116 |
|
11660 | 117 |
fun cantunify sg t u = error ("Non-unifiable terms:\n" ^ |
11522 | 118 |
Sign.string_of_term sg t ^ "\n\n" ^ Sign.string_of_term sg u); |
119 |
||
120 |
fun make_constraints_cprf sg env ts cprf = |
|
121 |
let |
|
122 |
fun add_cnstrt Ts prop prf cs env ts (t, u) = |
|
123 |
let |
|
124 |
val t' = mk_abs Ts t; |
|
12236 | 125 |
val u' = mk_abs Ts u |
11522 | 126 |
in |
12236 | 127 |
(prop, prf, cs, Pattern.unify (sg, env, [(t', u')]), ts) |
128 |
handle Pattern.Pattern => |
|
129 |
let val (env', cs') = decompose sg env [] t' u' |
|
130 |
in (prop, prf, cs @ cs', env', ts) end |
|
131 |
| Pattern.Unif => |
|
132 |
cantunify sg (Envir.norm_term env t') (Envir.norm_term env u') |
|
11522 | 133 |
end; |
134 |
||
13138 | 135 |
fun mk_cnstrts_atom env ts prop opTs prf = |
11522 | 136 |
let |
137 |
val tvars = term_tvars prop; |
|
138 |
val (env', Ts) = if_none (apsome (pair env) opTs) |
|
139 |
(foldl_map (mk_tvar o apsnd snd) (env, tvars)); |
|
13138 | 140 |
val prop' = subst_TVars (map fst tvars ~~ Ts) (forall_intr_vfs prop) |
141 |
handle LIST _ => error ("Wrong number of type arguments for " ^ |
|
142 |
quote (fst (get_name_tags [] prop prf))) |
|
143 |
in (prop', change_type (Some Ts) prf, [], env', ts) end; |
|
11522 | 144 |
|
145 |
fun mk_cnstrts env _ Hs ts (PBound i) = (nth_elem (i, Hs), PBound i, [], env, ts) |
|
146 |
| mk_cnstrts env Ts Hs ts (Abst (s, Some T, cprf)) = |
|
147 |
let val (t, prf, cnstrts, env', ts') = |
|
148 |
mk_cnstrts env (T::Ts) (map (incr_boundvars 1) Hs) ts cprf; |
|
149 |
in (Const ("all", (T --> propT) --> propT) $ Abs (s, T, t), Abst (s, Some T, prf), |
|
150 |
cnstrts, env', ts') |
|
151 |
end |
|
152 |
| mk_cnstrts env Ts Hs (t::ts) (AbsP (s, Some _, cprf)) = |
|
153 |
let |
|
154 |
val (u, prf, cnstrts, env', ts') = mk_cnstrts env Ts (t::Hs) ts cprf; |
|
155 |
val t' = strip_abs Ts t; |
|
156 |
in (Logic.mk_implies (t', u), AbsP (s, Some t', prf), cnstrts, env', ts') |
|
157 |
end |
|
158 |
| mk_cnstrts env Ts Hs ts (AbsP (s, None, cprf)) = |
|
159 |
let |
|
160 |
val (env', t) = mk_var env Ts propT; |
|
161 |
val (u, prf, cnstrts, env'', ts') = mk_cnstrts env' Ts (t::Hs) ts cprf; |
|
162 |
in (Logic.mk_implies (t, u), AbsP (s, Some t, prf), cnstrts, env'', ts') |
|
163 |
end |
|
11613 | 164 |
| mk_cnstrts env Ts Hs ts (cprf1 %% cprf2) = |
11522 | 165 |
let val (u, prf2, cnstrts, env', ts') = mk_cnstrts env Ts Hs ts cprf2 |
166 |
in (case mk_cnstrts env' Ts Hs ts' cprf1 of |
|
167 |
(Const ("==>", _) $ u' $ t', prf1, cnstrts', env'', ts'') => |
|
11613 | 168 |
add_cnstrt Ts t' (prf1 %% prf2) (cnstrts' @ cnstrts) |
11522 | 169 |
env'' ts'' (u, u') |
170 |
| (t, prf1, cnstrts', env'', ts'') => |
|
171 |
let val (env''', v) = mk_var env'' Ts propT |
|
11613 | 172 |
in add_cnstrt Ts v (prf1 %% prf2) (cnstrts' @ cnstrts) |
11522 | 173 |
env''' ts'' (t, Logic.mk_implies (u, v)) |
174 |
end) |
|
175 |
end |
|
11613 | 176 |
| mk_cnstrts env Ts Hs (t::ts) (cprf % Some _) = |
11522 | 177 |
let val t' = strip_abs Ts t |
178 |
in (case mk_cnstrts env Ts Hs ts cprf of |
|
179 |
(Const ("all", Type ("fun", [Type ("fun", [T, _]), _])) $ f, |
|
180 |
prf, cnstrts, env', ts') => |
|
12236 | 181 |
let val env'' = unifyT sg env' T (Envir.fastype env' Ts t') |
11613 | 182 |
in (betapply (f, t'), prf % Some t', cnstrts, env'', ts') |
11522 | 183 |
end |
184 |
| (u, prf, cnstrts, env', ts') => |
|
185 |
let |
|
12236 | 186 |
val T = Envir.fastype env' Ts t'; |
11522 | 187 |
val (env'', v) = mk_var env' Ts (T --> propT); |
188 |
in |
|
11613 | 189 |
add_cnstrt Ts (v $ t') (prf % Some t') cnstrts env'' ts' |
11522 | 190 |
(u, Const ("all", (T --> propT) --> propT) $ v) |
191 |
end) |
|
192 |
end |
|
11613 | 193 |
| mk_cnstrts env Ts Hs ts (cprf % None) = |
11522 | 194 |
(case mk_cnstrts env Ts Hs ts cprf of |
195 |
(Const ("all", Type ("fun", [Type ("fun", [T, _]), _])) $ f, |
|
196 |
prf, cnstrts, env', ts') => |
|
197 |
let val (env'', t) = mk_var env' Ts T |
|
11613 | 198 |
in (betapply (f, t), prf % Some t, cnstrts, env'', ts') |
11522 | 199 |
end |
200 |
| (u, prf, cnstrts, env', ts') => |
|
201 |
let |
|
202 |
val (env1, T) = mk_tvar (env', ["logic"]); |
|
203 |
val (env2, v) = mk_var env1 Ts (T --> propT); |
|
204 |
val (env3, t) = mk_var env2 Ts T |
|
205 |
in |
|
11613 | 206 |
add_cnstrt Ts (v $ t) (prf % Some t) cnstrts env3 ts' |
11522 | 207 |
(u, Const ("all", (T --> propT) --> propT) $ v) |
208 |
end) |
|
13138 | 209 |
| mk_cnstrts env _ _ ts (prf as PThm (_, _, prop, opTs)) = |
210 |
mk_cnstrts_atom env ts prop opTs prf |
|
211 |
| mk_cnstrts env _ _ ts (prf as PAxm (_, prop, opTs)) = |
|
212 |
mk_cnstrts_atom env ts prop opTs prf |
|
213 |
| mk_cnstrts env _ _ ts (prf as Oracle (_, prop, opTs)) = |
|
214 |
mk_cnstrts_atom env ts prop opTs prf |
|
11522 | 215 |
| mk_cnstrts env _ _ ts (Hyp t) = (t, Hyp t, [], env, ts) |
11613 | 216 |
| mk_cnstrts _ _ _ _ _ = error "reconstruct_proof: minimal proof object" |
11522 | 217 |
in mk_cnstrts env [] [] ts cprf end; |
218 |
||
219 |
fun add_term_ixns (is, Var (i, T)) = add_typ_ixns (i ins is, T) |
|
220 |
| add_term_ixns (is, Free (_, T)) = add_typ_ixns (is, T) |
|
221 |
| add_term_ixns (is, Const (_, T)) = add_typ_ixns (is, T) |
|
222 |
| add_term_ixns (is, t1 $ t2) = add_term_ixns (add_term_ixns (is, t1), t2) |
|
223 |
| add_term_ixns (is, Abs (_, T, t)) = add_term_ixns (add_typ_ixns (is, T), t) |
|
224 |
| add_term_ixns (is, _) = is; |
|
225 |
||
226 |
||
227 |
(******************************************************************************** |
|
228 |
update list of free variables of constraints |
|
229 |
*********************************************************************************) |
|
230 |
||
231 |
fun upd_constrs env cs = |
|
232 |
let |
|
233 |
val Envir.Envir {asol, iTs, ...} = env; |
|
234 |
val dom = Vartab.foldl (uncurry (cons o fst) o Library.swap) |
|
235 |
(Vartab.foldl (uncurry (cons o fst) o Library.swap) ([], asol), iTs); |
|
236 |
val vran = Vartab.foldl (add_typ_ixns o apsnd snd) |
|
237 |
(Vartab.foldl (add_term_ixns o apsnd snd) ([], asol), iTs); |
|
238 |
fun check_cs [] = [] |
|
239 |
| check_cs ((u, p, vs)::ps) = |
|
240 |
let val vs' = vs \\ dom; |
|
241 |
in if vs = vs' then (u, p, vs)::check_cs ps |
|
242 |
else (true, p, vs' union vran)::check_cs ps |
|
243 |
end |
|
244 |
in check_cs cs end; |
|
245 |
||
246 |
(******************************************************************************** |
|
247 |
solution of constraints |
|
248 |
*********************************************************************************) |
|
249 |
||
250 |
fun solve _ [] bigenv = bigenv |
|
251 |
| solve sg cs bigenv = |
|
252 |
let |
|
11660 | 253 |
fun search env [] = error ("Unsolvable constraints:\n" ^ |
254 |
Pretty.string_of (Pretty.chunks (map (fn (_, p, _) => |
|
255 |
Sign.pretty_term sg (Logic.mk_flexpair (pairself |
|
256 |
(Envir.norm_term bigenv) p))) cs))) |
|
11522 | 257 |
| search env ((u, p as (t1, t2), vs)::ps) = |
258 |
if u then |
|
259 |
let |
|
260 |
val tn1 = Envir.norm_term bigenv t1; |
|
261 |
val tn2 = Envir.norm_term bigenv t2 |
|
262 |
in |
|
263 |
if Pattern.pattern tn1 andalso Pattern.pattern tn2 then |
|
264 |
((Pattern.unify (sg, env, [(tn1, tn2)]), ps) handle Pattern.Unif => |
|
265 |
cantunify sg tn1 tn2) |
|
266 |
else |
|
267 |
let val (env', cs') = decompose sg env [] tn1 tn2 |
|
268 |
in if cs' = [(tn1, tn2)] then |
|
269 |
apsnd (cons (false, (tn1, tn2), vs)) (search env ps) |
|
270 |
else search env' (map (fn q => (true, q, vs)) cs' @ ps) |
|
271 |
end |
|
272 |
end |
|
273 |
else apsnd (cons (false, p, vs)) (search env ps); |
|
274 |
val Envir.Envir {maxidx, ...} = bigenv; |
|
275 |
val (env, cs') = search (Envir.empty maxidx) cs; |
|
276 |
in |
|
277 |
solve sg (upd_constrs env cs') (merge_envs bigenv env) |
|
278 |
end; |
|
279 |
||
280 |
||
281 |
(******************************************************************************** |
|
282 |
reconstruction of proofs |
|
283 |
*********************************************************************************) |
|
284 |
||
11613 | 285 |
fun reconstruct_proof sg prop cprf = |
11522 | 286 |
let |
11613 | 287 |
val (cprf' % Some prop', thawf) = freeze_thaw_prf (cprf % Some prop); |
11522 | 288 |
val _ = message "Collecting type constraints..."; |
289 |
val (Tcs, cprf'', maxidx) = make_Tconstraints_cprf 0 cprf'; |
|
290 |
val (ts, Ts) = ListPair.unzip Tcs; |
|
291 |
val tsig = Sign.tsig_of sg; |
|
292 |
val {classrel, arities, ...} = Type.rep_tsig tsig; |
|
293 |
val _ = message "Solving type constraints..."; |
|
294 |
val (ts', _, unifier) = TypeInfer.infer_types (Sign.pretty_term sg) (Sign.pretty_typ sg) |
|
295 |
(Sign.const_type sg) classrel arities [] false (K true) ts Ts; |
|
296 |
val env = Envir.Envir {asol = Vartab.empty, iTs = Vartab.make unifier, maxidx = maxidx}; |
|
297 |
val _ = message "Collecting term constraints..."; |
|
298 |
val (t, prf, cs, env, _) = make_constraints_cprf sg env ts' cprf''; |
|
299 |
val cs' = map (fn p => (true, p, op union |
|
300 |
(pairself (map (fst o dest_Var) o term_vars) p))) (map (pairself (Envir.norm_term env)) ((t, prop')::cs)); |
|
301 |
val _ = message ("Solving remaining constraints (" ^ string_of_int (length cs') ^ ") ..."); |
|
302 |
val env' = solve sg cs' env |
|
303 |
in |
|
304 |
thawf (norm_proof env' prf) |
|
305 |
end; |
|
306 |
||
13256
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
307 |
fun prop_of_atom prop Ts = |
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
308 |
subst_TVars (map fst (term_tvars prop) ~~ Ts) (forall_intr_vfs prop); |
13138 | 309 |
|
13256
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
310 |
fun prop_of' Hs (PBound i) = nth_elem (i, Hs) |
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
311 |
| prop_of' Hs (Abst (s, Some T, prf)) = |
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
312 |
all T $ (Abs (s, T, prop_of' Hs prf)) |
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
313 |
| prop_of' Hs (AbsP (s, Some t, prf)) = |
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
314 |
Logic.mk_implies (t, prop_of' (t :: Hs) prf) |
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
315 |
| prop_of' Hs (prf % Some t) = (case prop_of' Hs prf of |
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
316 |
Const ("all", _) $ f => betapply (f, t) |
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
317 |
| _ => error "prop_of: all expected") |
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
318 |
| prop_of' Hs (prf1 %% prf2) = (case prop_of' Hs prf1 of |
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
319 |
Const ("==>", _) $ P $ Q => Q |
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
320 |
| _ => error "prop_of: ==> expected") |
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
321 |
| prop_of' Hs (Hyp t) = t |
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
322 |
| prop_of' Hs (PThm (_, _, prop, Some Ts)) = prop_of_atom prop Ts |
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
323 |
| prop_of' Hs (PAxm (_, prop, Some Ts)) = prop_of_atom prop Ts |
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
324 |
| prop_of' Hs (Oracle (_, prop, Some Ts)) = prop_of_atom prop Ts |
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
325 |
| prop_of' _ _ = error "prop_of: partial proof object"; |
13138 | 326 |
|
13256
cf85c4f7dcf2
Added function prop_of' taking assumption context as an argument.
berghofe
parents:
13138
diff
changeset
|
327 |
val prop_of = prop_of' []; |
13138 | 328 |
|
11522 | 329 |
|
330 |
(******************************************************************************** |
|
331 |
expand and reconstruct subproofs |
|
332 |
*********************************************************************************) |
|
333 |
||
13342
915d4d004643
expand_proof now also takes an optional term describing the proposition
berghofe
parents:
13256
diff
changeset
|
334 |
fun expand_proof sg thms prf = |
11522 | 335 |
let |
12870
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
336 |
fun expand maxidx prfs (AbsP (s, t, prf)) = |
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
337 |
let val (maxidx', prfs', prf') = expand maxidx prfs prf |
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
338 |
in (maxidx', prfs', AbsP (s, t, prf')) end |
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
339 |
| expand maxidx prfs (Abst (s, T, prf)) = |
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
340 |
let val (maxidx', prfs', prf') = expand maxidx prfs prf |
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
341 |
in (maxidx', prfs', Abst (s, T, prf')) end |
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
342 |
| expand maxidx prfs (prf1 %% prf2) = |
11522 | 343 |
let |
12870
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
344 |
val (maxidx', prfs', prf1') = expand maxidx prfs prf1; |
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
345 |
val (maxidx'', prfs'', prf2') = expand maxidx' prfs' prf2; |
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
346 |
in (maxidx'', prfs'', prf1' %% prf2') end |
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
347 |
| expand maxidx prfs (prf % t) = |
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
348 |
let val (maxidx', prfs', prf') = expand maxidx prfs prf |
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
349 |
in (maxidx', prfs', prf' % t) end |
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
350 |
| expand maxidx prfs (prf as PThm ((a, _), cprf, prop, Some Ts)) = |
13342
915d4d004643
expand_proof now also takes an optional term describing the proposition
berghofe
parents:
13256
diff
changeset
|
351 |
if not (exists |
915d4d004643
expand_proof now also takes an optional term describing the proposition
berghofe
parents:
13256
diff
changeset
|
352 |
(fn (b, None) => a = b |
915d4d004643
expand_proof now also takes an optional term describing the proposition
berghofe
parents:
13256
diff
changeset
|
353 |
| (b, Some prop') => a = b andalso prop = prop') thms) |
915d4d004643
expand_proof now also takes an optional term describing the proposition
berghofe
parents:
13256
diff
changeset
|
354 |
then (maxidx, prfs, prf) else |
11522 | 355 |
let |
13610
d4a2ac255447
Fixed bug in expand_proof which caused indexes to be incremented incorrectly.
berghofe
parents:
13342
diff
changeset
|
356 |
fun inc i = |
d4a2ac255447
Fixed bug in expand_proof which caused indexes to be incremented incorrectly.
berghofe
parents:
13342
diff
changeset
|
357 |
map_proof_terms (Logic.incr_indexes ([], i)) (incr_tvar i); |
d4a2ac255447
Fixed bug in expand_proof which caused indexes to be incremented incorrectly.
berghofe
parents:
13342
diff
changeset
|
358 |
val (maxidx', i, prf, prfs') = (case assoc (prfs, (a, prop)) of |
11522 | 359 |
None => |
360 |
let |
|
361 |
val _ = message ("Reconstructing proof of " ^ a); |
|
362 |
val _ = message (Sign.string_of_term sg prop); |
|
13610
d4a2ac255447
Fixed bug in expand_proof which caused indexes to be incremented incorrectly.
berghofe
parents:
13342
diff
changeset
|
363 |
val prf' = forall_intr_vfs_prf prop |
d4a2ac255447
Fixed bug in expand_proof which caused indexes to be incremented incorrectly.
berghofe
parents:
13342
diff
changeset
|
364 |
(reconstruct_proof sg prop cprf); |
12870
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
365 |
val (maxidx', prfs', prf) = expand |
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
366 |
(maxidx_of_proof prf') prfs prf' |
13610
d4a2ac255447
Fixed bug in expand_proof which caused indexes to be incremented incorrectly.
berghofe
parents:
13342
diff
changeset
|
367 |
in (maxidx' + maxidx + 1, maxidx + 1, inc (maxidx + 1) prf, |
d4a2ac255447
Fixed bug in expand_proof which caused indexes to be incremented incorrectly.
berghofe
parents:
13342
diff
changeset
|
368 |
((a, prop), (maxidx', prf)) :: prfs') |
d4a2ac255447
Fixed bug in expand_proof which caused indexes to be incremented incorrectly.
berghofe
parents:
13342
diff
changeset
|
369 |
end |
d4a2ac255447
Fixed bug in expand_proof which caused indexes to be incremented incorrectly.
berghofe
parents:
13342
diff
changeset
|
370 |
| Some (maxidx', prf) => (maxidx' + maxidx + 1, |
d4a2ac255447
Fixed bug in expand_proof which caused indexes to be incremented incorrectly.
berghofe
parents:
13342
diff
changeset
|
371 |
maxidx + 1, inc (maxidx + 1) prf, prfs)); |
12870
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
372 |
val tye = map (fn ((s, j), _) => (s, i + j)) (term_tvars prop) ~~ Ts |
11522 | 373 |
in |
12870
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
374 |
(maxidx', prfs', |
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
375 |
map_proof_terms (subst_TVars tye) (typ_subst_TVars tye) prf) |
11522 | 376 |
end |
12870
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
377 |
| expand maxidx prfs prf = (maxidx, prfs, prf); |
11522 | 378 |
|
12870
3905bc0e9002
Indexes of variables in expanded proofs are now incremented to avoid clashes.
berghofe
parents:
12527
diff
changeset
|
379 |
in #3 (expand (maxidx_of_proof prf) [] prf) end; |
11522 | 380 |
|
381 |
end; |