44 val fold_body_thms: (string * term * proof_body -> 'a -> 'a) -> proof_body list -> 'a -> 'a |
44 val fold_body_thms: (string * term * proof_body -> 'a -> 'a) -> proof_body list -> 'a -> 'a |
45 val status_of: proof_body list -> {failed: bool, oracle: bool, unfinished: bool} |
45 val status_of: proof_body list -> {failed: bool, oracle: bool, unfinished: bool} |
46 |
46 |
47 val oracle_ord: oracle * oracle -> order |
47 val oracle_ord: oracle * oracle -> order |
48 val thm_ord: pthm * pthm -> order |
48 val thm_ord: pthm * pthm -> order |
49 val make_proof_body: proof -> proof_body |
|
50 val merge_oracles: oracle OrdList.T -> oracle OrdList.T -> oracle OrdList.T |
49 val merge_oracles: oracle OrdList.T -> oracle OrdList.T -> oracle OrdList.T |
51 val make_oracles: proof -> oracle OrdList.T |
|
52 val merge_thms: pthm OrdList.T -> pthm OrdList.T -> pthm OrdList.T |
50 val merge_thms: pthm OrdList.T -> pthm OrdList.T -> pthm OrdList.T |
53 val make_thms: proof -> pthm OrdList.T |
51 val all_oracles_of: proof_body -> oracle OrdList.T |
|
52 val approximate_proof_body: proof -> proof_body |
54 |
53 |
55 (** primitive operations **) |
54 (** primitive operations **) |
56 val proof_combt: proof * term list -> proof |
55 val proof_combt: proof * term list -> proof |
57 val proof_combt': proof * term option list -> proof |
56 val proof_combt': proof * term option list -> proof |
58 val proof_combP: proof * proof list -> proof |
57 val proof_combP: proof * proof list -> proof |
105 val abstract_rule: term -> string -> proof -> proof |
104 val abstract_rule: term -> string -> proof -> proof |
106 val combination: term -> term -> term -> term -> typ -> proof -> proof -> proof |
105 val combination: term -> term -> term -> term -> typ -> proof -> proof -> proof |
107 val equal_intr: term -> term -> proof -> proof -> proof |
106 val equal_intr: term -> term -> proof -> proof -> proof |
108 val equal_elim: term -> term -> proof -> proof -> proof |
107 val equal_elim: term -> term -> proof -> proof -> proof |
109 val axm_proof: string -> term -> proof |
108 val axm_proof: string -> term -> proof |
110 val oracle_proof: string -> term -> proof |
109 val oracle_proof: string -> term -> oracle * proof |
111 val promise_proof: theory -> serial -> term -> proof |
110 val promise_proof: theory -> serial -> term -> proof |
112 val fulfill_proof: theory -> (serial * proof) list -> proof_body -> proof_body |
111 val fulfill_proof: theory -> (serial * proof_body) list -> proof_body -> proof_body |
113 val thm_proof: theory -> string -> term list -> term -> |
112 val thm_proof: theory -> string -> term list -> term -> |
114 (serial * proof future) list -> proof_body -> pthm * proof |
113 (serial * proof_body future) list -> proof_body -> pthm * proof |
115 val get_name: term list -> term -> proof -> string |
114 val get_name: term list -> term -> proof -> string |
116 |
115 |
117 (** rewriting on proof terms **) |
116 (** rewriting on proof terms **) |
118 val add_prf_rrule: proof * proof -> theory -> theory |
117 val add_prf_rrule: proof * proof -> theory -> theory |
119 val add_prf_rproc: (typ list -> proof -> proof option) -> theory -> theory |
118 val add_prf_rproc: (typ list -> proof -> proof option) -> theory -> theory |
212 (* proof body *) |
211 (* proof body *) |
213 |
212 |
214 val oracle_ord = prod_ord fast_string_ord TermOrd.fast_term_ord; |
213 val oracle_ord = prod_ord fast_string_ord TermOrd.fast_term_ord; |
215 fun thm_ord ((i, _): pthm, (j, _)) = int_ord (j, i); |
214 fun thm_ord ((i, _): pthm, (j, _)) = int_ord (j, i); |
216 |
215 |
217 fun make_body prf = |
216 val merge_oracles = OrdList.union oracle_ord; |
|
217 val merge_thms = OrdList.union thm_ord; |
|
218 |
|
219 val all_oracles_of = |
|
220 let |
|
221 fun collect (PBody {oracles, thms, ...}) = thms |> fold (fn (i, (_, _, body)) => fn (x, seen) => |
|
222 if Inttab.defined seen i then (x, seen) |
|
223 else |
|
224 let |
|
225 val body' = Future.join body; |
|
226 val (x', seen') = collect body' (x, Inttab.update (i, ()) seen); |
|
227 in (merge_oracles oracles x', seen') end); |
|
228 in fn body => #1 (collect body ([], Inttab.empty)) end; |
|
229 |
|
230 fun approximate_proof_body prf = |
218 let |
231 let |
219 val (oracles, thms) = fold_proof_atoms false |
232 val (oracles, thms) = fold_proof_atoms false |
220 (fn Oracle (s, prop, _) => apfst (cons (s, prop)) |
233 (fn Oracle (s, prop, _) => apfst (cons (s, prop)) |
221 | PThm (i, ((name, prop, _), body)) => apsnd (cons (i, (name, prop, body))) |
234 | PThm (i, ((name, prop, _), body)) => apsnd (cons (i, (name, prop, body))) |
222 | _ => I) [prf] ([], []); |
235 | _ => I) [prf] ([], []); |
223 in (OrdList.make oracle_ord oracles, OrdList.make thm_ord thms) end; |
236 in |
224 |
237 PBody |
225 fun make_proof_body prf = |
238 {oracles = OrdList.make oracle_ord oracles, |
226 let val (oracles, thms) = make_body prf |
239 thms = OrdList.make thm_ord thms, |
227 in PBody {oracles = oracles, thms = thms, proof = prf} end; |
240 proof = prf} |
228 |
241 end; |
229 val make_oracles = #1 o make_body; |
|
230 val make_thms = #2 o make_body; |
|
231 |
|
232 val merge_oracles = OrdList.union oracle_ord; |
|
233 val merge_thms = OrdList.union thm_ord; |
|
234 |
|
235 fun merge_body (oracles1, thms1) (oracles2, thms2) = |
|
236 (merge_oracles oracles1 oracles2, merge_thms thms1 thms2); |
|
237 |
242 |
238 |
243 |
239 (***** proof objects with different levels of detail *****) |
244 (***** proof objects with different levels of detail *****) |
240 |
245 |
241 fun (prf %> t) = prf % SOME t; |
246 fun (prf %> t) = prf % SOME t; |
928 val axm_proof = gen_axm_proof PAxm; |
933 val axm_proof = gen_axm_proof PAxm; |
929 |
934 |
930 val dummy = Const (Term.dummy_patternN, dummyT); |
935 val dummy = Const (Term.dummy_patternN, dummyT); |
931 |
936 |
932 fun oracle_proof name prop = |
937 fun oracle_proof name prop = |
933 if !proofs = 0 then Oracle (name, dummy, NONE) |
938 if ! proofs = 0 then ((name, dummy), Oracle (name, dummy, NONE)) |
934 else gen_axm_proof Oracle name prop; |
939 else ((name, prop), gen_axm_proof Oracle name prop); |
935 |
940 |
936 fun shrink_proof thy = |
941 fun shrink_proof thy = |
937 let |
942 let |
938 fun shrink ls lev (prf as Abst (a, T, body)) = |
943 fun shrink ls lev (prf as Abst (a, T, body)) = |
939 let val (b, is, ch, body') = shrink ls (lev+1) body |
944 let val (b, is, ch, body') = shrink ls (lev+1) body |
1233 (fn TFree (a, _) => error ("promise_proof: illegal type variable " ^ quote a) |
1238 (fn TFree (a, _) => error ("promise_proof: illegal type variable " ^ quote a) |
1234 | _ => false)); |
1239 | _ => false)); |
1235 in Promise (i, prop, map TVar (Term.add_tvars prop [])) end; |
1240 in Promise (i, prop, map TVar (Term.add_tvars prop [])) end; |
1236 |
1241 |
1237 fun fulfill_proof _ [] body0 = body0 |
1242 fun fulfill_proof _ [] body0 = body0 |
1238 | fulfill_proof thy promises body0 = |
1243 | fulfill_proof thy ps body0 = |
1239 let |
1244 let |
1240 val PBody {oracles = oracles0, thms = thms0, proof = proof0} = body0; |
1245 val PBody {oracles = oracles0, thms = thms0, proof = proof0} = body0; |
1241 val (oracles, thms) = fold (merge_body o make_body o #2) promises (oracles0, thms0); |
1246 val oracles = fold (fn (_, PBody {oracles, ...}) => merge_oracles oracles) ps oracles0; |
1242 |
1247 val thms = fold (fn (_, PBody {thms, ...}) => merge_thms thms) ps thms0; |
1243 val tab = Inttab.make promises; |
1248 val proofs = fold (fn (i, PBody {proof, ...}) => Inttab.update (i, proof)) ps Inttab.empty; |
|
1249 |
1244 fun fill (Promise (i, prop, Ts)) = |
1250 fun fill (Promise (i, prop, Ts)) = |
1245 (case Inttab.lookup tab i of |
1251 (case Inttab.lookup proofs i of |
1246 NONE => NONE |
1252 NONE => NONE |
1247 | SOME p => SOME (instantiate (Term.add_tvars prop [] ~~ Ts, []) p)) |
1253 | SOME prf => SOME (instantiate (Term.add_tvars prop [] ~~ Ts, []) prf)) |
1248 | fill _ = NONE; |
1254 | fill _ = NONE; |
1249 val (rules, procs) = get_data thy; |
1255 val (rules, procs) = get_data thy; |
1250 val proof = rewrite_prf fst (rules, K fill :: procs) proof0; |
1256 val proof = rewrite_prf fst (rules, K fill :: procs) proof0; |
1251 in PBody {oracles = oracles, thms = thms, proof = proof} end; |
1257 in PBody {oracles = oracles, thms = thms, proof = proof} end; |
1252 |
1258 |