24 fun message s = if !quiet_mode then () else writeln s; |
24 fun message s = if !quiet_mode then () else writeln s; |
25 |
25 |
26 fun vars_of t = rev (fold_aterms |
26 fun vars_of t = rev (fold_aterms |
27 (fn v as Var _ => insert (op =) v | _ => I) t []); |
27 (fn v as Var _ => insert (op =) v | _ => I) t []); |
28 |
28 |
29 fun forall_intr (t, prop) = |
29 fun forall_intr t prop = |
30 let val (a, T) = (case t of Var ((a, _), T) => (a, T) | Free p => p) |
30 let val (a, T) = (case t of Var ((a, _), T) => (a, T) | Free p => p) |
31 in all T $ Abs (a, T, abstract_over (t, prop)) end; |
31 in all T $ Abs (a, T, abstract_over (t, prop)) end; |
32 |
32 |
33 fun forall_intr_vfs prop = foldr forall_intr prop |
33 fun forall_intr_vfs prop = fold_rev forall_intr |
34 (vars_of prop @ sort Term.term_ord (term_frees prop)); |
34 (vars_of prop @ sort Term.term_ord (term_frees prop)) prop; |
35 |
35 |
36 fun forall_intr_prf (t, prf) = |
36 fun forall_intr_prf t prf = |
37 let val (a, T) = (case t of Var ((a, _), T) => (a, T) | Free p => p) |
37 let val (a, T) = (case t of Var ((a, _), T) => (a, T) | Free p => p) |
38 in Abst (a, SOME T, prf_abstract_over t prf) end; |
38 in Abst (a, SOME T, prf_abstract_over t prf) end; |
39 |
39 |
40 fun forall_intr_vfs_prf prop prf = foldr forall_intr_prf prf |
40 fun forall_intr_vfs_prf prop prf = fold_rev forall_intr_prf |
41 (vars_of prop @ sort Term.term_ord (term_frees prop)); |
41 (vars_of prop @ sort Term.term_ord (term_frees prop)) prf; |
42 |
42 |
43 fun merge_envs (Envir.Envir {asol=asol1, iTs=iTs1, maxidx=maxidx1}) |
43 fun merge_envs (Envir.Envir {asol=asol1, iTs=iTs1, maxidx=maxidx1}) |
44 (Envir.Envir {asol=asol2, iTs=iTs2, maxidx=maxidx2}) = |
44 (Envir.Envir {asol=asol2, iTs=iTs2, maxidx=maxidx2}) = |
45 Envir.Envir {asol=Vartab.merge (op =) (asol1, asol2), |
45 Envir.Envir {asol=Vartab.merge (op =) (asol1, asol2), |
46 iTs=Vartab.merge (op =) (iTs1, iTs2), |
46 iTs=Vartab.merge (op =) (iTs1, iTs2), |
47 maxidx=Int.max (maxidx1, maxidx2)}; |
47 maxidx=Int.max (maxidx1, maxidx2)}; |
48 |
48 |
49 |
49 |
50 (**** generate constraints for proof term ****) |
50 (**** generate constraints for proof term ****) |
51 |
51 |
52 fun mk_var env Ts T = |
52 fun mk_var env Ts T = |
53 let val (env', v) = Envir.genvar "a" (env, rev Ts ---> T) |
53 let val (env', v) = Envir.genvar "a" (env, rev Ts ---> T) |
54 in (env', list_comb (v, map Bound (length Ts - 1 downto 0))) end; |
54 in (env', list_comb (v, map Bound (length Ts - 1 downto 0))) end; |
55 |
55 |
56 fun mk_tvar (Envir.Envir {iTs, asol, maxidx}, s) = |
56 fun mk_tvar (Envir.Envir {iTs, asol, maxidx}, s) = |
57 (Envir.Envir {iTs = iTs, asol = asol, maxidx = maxidx+1}, |
57 (Envir.Envir {iTs = iTs, asol = asol, maxidx = maxidx+1}, |
72 | chaseT _ T = T; |
72 | chaseT _ T = T; |
73 |
73 |
74 fun infer_type thy (env as Envir.Envir {maxidx, asol, iTs}) Ts vTs |
74 fun infer_type thy (env as Envir.Envir {maxidx, asol, iTs}) Ts vTs |
75 (t as Const (s, T)) = if T = dummyT then (case Sign.const_type thy s of |
75 (t as Const (s, T)) = if T = dummyT then (case Sign.const_type thy s of |
76 NONE => error ("reconstruct_proof: No such constant: " ^ quote s) |
76 NONE => error ("reconstruct_proof: No such constant: " ^ quote s) |
77 | SOME T => |
77 | SOME T => |
78 let val T' = Type.strip_sorts (Logic.incr_tvar (maxidx + 1) T) |
78 let val T' = Type.strip_sorts (Logic.incr_tvar (maxidx + 1) T) |
79 in (Const (s, T'), T', vTs, |
79 in (Const (s, T'), T', vTs, |
80 Envir.Envir {maxidx = maxidx + 1, asol = asol, iTs = iTs}) |
80 Envir.Envir {maxidx = maxidx + 1, asol = asol, iTs = iTs}) |
81 end) |
81 end) |
82 else (t, T, vTs, env) |
82 else (t, T, vTs, env) |
154 quote (get_name [] prop prf)) |
154 quote (get_name [] prop prf)) |
155 in (prop'', change_type (SOME Ts) prf, [], env', vTs) end; |
155 in (prop'', change_type (SOME Ts) prf, [], env', vTs) end; |
156 |
156 |
157 fun head_norm (prop, prf, cnstrts, env, vTs) = |
157 fun head_norm (prop, prf, cnstrts, env, vTs) = |
158 (Envir.head_norm env prop, prf, cnstrts, env, vTs); |
158 (Envir.head_norm env prop, prf, cnstrts, env, vTs); |
159 |
159 |
160 fun mk_cnstrts env _ Hs vTs (PBound i) = (List.nth (Hs, i), PBound i, [], env, vTs) |
160 fun mk_cnstrts env _ Hs vTs (PBound i) = (List.nth (Hs, i), PBound i, [], env, vTs) |
161 | mk_cnstrts env Ts Hs vTs (Abst (s, opT, cprf)) = |
161 | mk_cnstrts env Ts Hs vTs (Abst (s, opT, cprf)) = |
162 let |
162 let |
163 val (env', T) = (case opT of |
163 val (env', T) = (case opT of |
164 NONE => mk_tvar (env, []) | SOME T => (env, T)); |
164 NONE => mk_tvar (env, []) | SOME T => (env, T)); |
336 |
336 |
337 (**** expand and reconstruct subproofs ****) |
337 (**** expand and reconstruct subproofs ****) |
338 |
338 |
339 fun expand_proof thy thms prf = |
339 fun expand_proof thy thms prf = |
340 let |
340 let |
341 fun expand maxidx prfs (AbsP (s, t, prf)) = |
341 fun expand maxidx prfs (AbsP (s, t, prf)) = |
342 let val (maxidx', prfs', prf') = expand maxidx prfs prf |
342 let val (maxidx', prfs', prf') = expand maxidx prfs prf |
343 in (maxidx', prfs', AbsP (s, t, prf')) end |
343 in (maxidx', prfs', AbsP (s, t, prf')) end |
344 | expand maxidx prfs (Abst (s, T, prf)) = |
344 | expand maxidx prfs (Abst (s, T, prf)) = |
345 let val (maxidx', prfs', prf') = expand maxidx prfs prf |
345 let val (maxidx', prfs', prf') = expand maxidx prfs prf |
346 in (maxidx', prfs', Abst (s, T, prf')) end |
346 in (maxidx', prfs', Abst (s, T, prf')) end |
347 | expand maxidx prfs (prf1 %% prf2) = |
347 | expand maxidx prfs (prf1 %% prf2) = |
348 let |
348 let |
349 val (maxidx', prfs', prf1') = expand maxidx prfs prf1; |
349 val (maxidx', prfs', prf1') = expand maxidx prfs prf1; |