105 |
105 |
106 fun simplify_bool ((all as Const (@{const_name All}, _)) $ Abs (s, T, t)) = |
106 fun simplify_bool ((all as Const (@{const_name All}, _)) $ Abs (s, T, t)) = |
107 let val t' = simplify_bool t in |
107 let val t' = simplify_bool t in |
108 if loose_bvar1 (t', 0) then all $ Abs (s, T, t') else t' |
108 if loose_bvar1 (t', 0) then all $ Abs (s, T, t') else t' |
109 end |
109 end |
110 | simplify_bool (@{const Not} $ t) = s_not (simplify_bool t) |
110 | simplify_bool (Const (@{const_name Not}, _) $ t) = s_not (simplify_bool t) |
111 | simplify_bool (@{const conj} $ t $ u) = s_conj (simplify_bool t, simplify_bool u) |
111 | simplify_bool (Const (@{const_name conj}, _) $ t $ u) = |
112 | simplify_bool (@{const disj} $ t $ u) = s_disj (simplify_bool t, simplify_bool u) |
112 s_conj (simplify_bool t, simplify_bool u) |
113 | simplify_bool (@{const implies} $ t $ u) = s_imp (simplify_bool t, simplify_bool u) |
113 | simplify_bool (Const (@{const_name disj}, _) $ t $ u) = |
114 | simplify_bool (@{const HOL.eq (bool)} $ t $ u) = s_iff (simplify_bool t, simplify_bool u) |
114 s_disj (simplify_bool t, simplify_bool u) |
115 | simplify_bool (t as Const (@{const_name HOL.eq}, _) $ u $ v) = |
115 | simplify_bool (Const (@{const_name implies}, _) $ t $ u) = |
116 if u aconv v then @{const True} else t |
116 s_imp (simplify_bool t, simplify_bool u) |
|
117 | simplify_bool ((t as Const (@{const_name HOL.eq}, _)) $ u $ v) = |
|
118 (case (u, v) of |
|
119 (Const (@{const_name True}, _), _) => v |
|
120 | (u, Const (@{const_name True}, _)) => u |
|
121 | (Const (@{const_name False}, _), v) => s_not v |
|
122 | (u, Const (@{const_name False}, _)) => s_not u |
|
123 | _ => if u aconv v then @{const True} else t $ simplify_bool u $ simplify_bool v) |
117 | simplify_bool (t $ u) = simplify_bool t $ simplify_bool u |
124 | simplify_bool (t $ u) = simplify_bool t $ simplify_bool u |
118 | simplify_bool (Abs (s, T, t)) = Abs (s, T, simplify_bool t) |
125 | simplify_bool (Abs (s, T, t)) = Abs (s, T, simplify_bool t) |
119 | simplify_bool t = t |
126 | simplify_bool t = t |
120 |
127 |
121 fun single_letter upper s = |
128 fun single_letter upper s = |
244 | norm_var_types t = t |
251 | norm_var_types t = t |
245 in t |> map_aterms norm_var_types |> fold_rev quant_of (map Var normTs) end |
252 in t |> map_aterms norm_var_types |> fold_rev quant_of (map Var normTs) end |
246 |
253 |
247 |
254 |
248 (* Higher-order translation. Variables are typed (although we don't use that information). Lambdas |
255 (* Higher-order translation. Variables are typed (although we don't use that information). Lambdas |
249 are typed. |
256 are typed. The code is similar to "term_of_atp_fo". *) |
250 |
257 fun term_of_atp_ho ctxt sym_tab = |
251 The code is similar to term_of_atp_fo. *) |
|
252 fun term_of_atp_ho ctxt textual sym_tab = |
|
253 let |
258 let |
254 val thy = Proof_Context.theory_of ctxt |
259 val thy = Proof_Context.theory_of ctxt |
255 val var_index = var_index_of_textual textual |
260 val var_index = var_index_of_textual true |
256 |
261 |
257 fun do_term opt_T u = |
262 fun do_term opt_T u = |
258 (case u of |
263 (case u of |
259 AAbs(((var, ty), term), []) => |
264 AAbs(((var, ty), term), []) => |
260 let |
265 let |
261 val typ = typ_of_atp_type ctxt ty |
266 val typ = typ_of_atp_type ctxt ty |
262 val var_name = repair_var_name textual var |
267 val var_name = repair_var_name true var |
263 val tm = do_term NONE term |
268 val tm = do_term NONE term |
264 in quantify_over_var textual lambda' var_name typ tm end |
269 in quantify_over_var true lambda' var_name typ tm end |
265 | ATerm ((s, tys), us) => |
270 | ATerm ((s, tys), us) => |
266 if s = "" |
271 if s = "" |
267 then error "Isar proof reconstruction failed because the ATP proof \ |
272 then error "Isar proof reconstruction failed because the ATP proof \ |
268 \contains unparsable material." |
273 \contains unparsable material." |
269 else if s = tptp_equal then |
274 else if s = tptp_equal then |
270 let |
275 list_comb (Const (@{const_name HOL.eq}, Type_Infer.anyT @{sort type}), |
271 val ts = map (do_term NONE) us |
276 map (do_term NONE) us) |
272 fun equal_term ts = |
|
273 list_comb (Const (@{const_name HOL.eq}, Type_Infer.anyT @{sort type}), ts) |
|
274 in |
|
275 if textual then |
|
276 (case ts of |
|
277 [t1, t2] => |
|
278 if loose_aconv (t1, t2) then |
|
279 @{const True} |
|
280 else if Term.aconv_untyped (t2, @{const True}) then |
|
281 t1 |
|
282 else if Term.aconv_untyped (t1, @{const True}) then |
|
283 t2 |
|
284 else |
|
285 equal_term ts |
|
286 | _ => equal_term ts) |
|
287 else |
|
288 equal_term ts |
|
289 end |
|
290 else if not (null us) then |
277 else if not (null us) then |
291 let |
278 let |
292 val args = List.map (do_term NONE) us |
279 val args = List.map (do_term NONE) us |
293 val opt_T' = SOME (map slack_fastype_of args ---> the_default dummyT opt_T) |
280 val opt_T' = SOME (map slack_fastype_of args ---> the_default dummyT opt_T) |
294 val func = do_term opt_T' (ATerm ((s, tys), [])) |
281 val func = do_term opt_T' (ATerm ((s, tys), [])) |
295 in foldl1 (op $) (func :: args) end |
282 in foldl1 (op $) (func :: args) end |
296 else if s = tptp_or then HOLogic.disj |
283 else if s = tptp_or then HOLogic.disj |
297 else if s = tptp_and then HOLogic.conj |
284 else if s = tptp_and then HOLogic.conj |
298 else if s = tptp_implies then HOLogic.imp |
285 else if s = tptp_implies then HOLogic.imp |
299 else if s = tptp_iff orelse s = tptp_equal then HOLogic.eq_const dummyT |
286 else if s = tptp_iff orelse s = tptp_equal then HOLogic.eq_const dummyT |
300 else if s = tptp_not_iff orelse s = tptp_not_equal then @{term "% P Q. Q ~= P"} |
287 else if s = tptp_not_iff orelse s = tptp_not_equal then @{term "%P Q. Q ~= P"} |
301 else if s = tptp_if then @{term "% P Q. Q --> P"} |
288 else if s = tptp_if then @{term "%P Q. Q --> P"} |
302 else if s = tptp_not_and then @{term "% P Q. ~ (P & Q)"} |
289 else if s = tptp_not_and then @{term "%P Q. ~ (P & Q)"} |
303 else if s = tptp_not_or then @{term "% P Q. ~ (P | Q)"} |
290 else if s = tptp_not_or then @{term "%P Q. ~ (P | Q)"} |
304 else if s = tptp_not then HOLogic.Not |
291 else if s = tptp_not then HOLogic.Not |
305 else if s = tptp_ho_forall then HOLogic.all_const dummyT |
292 else if s = tptp_ho_forall then HOLogic.all_const dummyT |
306 else if s = tptp_ho_exists then HOLogic.exists_const dummyT |
293 else if s = tptp_ho_exists then HOLogic.exists_const dummyT |
307 else if s = tptp_hilbert_choice then HOLogic.choice_const dummyT |
294 else if s = tptp_hilbert_choice then HOLogic.choice_const dummyT |
308 else if s = tptp_hilbert_the then @{term "The"} |
295 else if s = tptp_hilbert_the then @{term "The"} |
341 | _ => Type_Infer.anyT @{sort type})) |
328 | _ => Type_Infer.anyT @{sort type})) |
342 val t = |
329 val t = |
343 (case unprefix_and_unascii fixed_var_prefix s of |
330 (case unprefix_and_unascii fixed_var_prefix s of |
344 SOME s => Free (s, T) |
331 SOME s => Free (s, T) |
345 | NONE => |
332 | NONE => |
346 if textual andalso not (is_tptp_variable s) then |
333 if not (is_tptp_variable s) then Free (s |> repair_var_name_raw |> fresh_up, T) |
347 Free (s |> textual ? (repair_var_name_raw #> fresh_up), T) |
334 else Var ((repair_var_name true s, var_index), T)) |
348 else |
|
349 Var ((repair_var_name textual s, var_index), T)) |
|
350 in list_comb (t, ts) end)) |
335 in list_comb (t, ts) end)) |
351 in do_term end |
336 in do_term end |
352 |
337 |
353 (* First-order translation. No types are known for variables. "Type_Infer.anyT @{sort type}" |
338 (* First-order translation. No types are known for variables. "Type_Infer.anyT @{sort type}" |
354 should allow them to be inferred. *) |
339 should allow them to be inferred. *) |
367 error "Isar proof reconstruction failed because the ATP proof contains unparsable \ |
352 error "Isar proof reconstruction failed because the ATP proof contains unparsable \ |
368 \material." |
353 \material." |
369 else if String.isPrefix native_type_prefix s then |
354 else if String.isPrefix native_type_prefix s then |
370 @{const True} (* ignore TPTP type information *) |
355 @{const True} (* ignore TPTP type information *) |
371 else if s = tptp_equal then |
356 else if s = tptp_equal then |
372 let val ts = map (do_term [] NONE) us in |
357 list_comb (Const (@{const_name HOL.eq}, Type_Infer.anyT @{sort type}), |
373 if textual andalso length ts = 2 andalso loose_aconv (hd ts, List.last ts) then |
358 map (do_term [] NONE) us) |
374 @{const True} |
|
375 else |
|
376 list_comb (Const (@{const_name HOL.eq}, Type_Infer.anyT @{sort type}), ts) |
|
377 end |
|
378 else |
359 else |
379 (case unprefix_and_unascii const_prefix s of |
360 (case unprefix_and_unascii const_prefix s of |
380 SOME s' => |
361 SOME s' => |
381 let val ((s', s''), mangled_us) = s' |> unmangled_const |>> `invert_const in |
362 let val ((s', s''), mangled_us) = s' |> unmangled_const |>> `invert_const in |
382 if s' = type_tag_name then |
363 if s' = type_tag_name then |
450 Var ((repair_var_name textual s, var_index), T)) |
431 Var ((repair_var_name textual s, var_index), T)) |
451 in list_comb (t, ts) end)) |
432 in list_comb (t, ts) end)) |
452 in do_term [] end |
433 in do_term [] end |
453 |
434 |
454 fun term_of_atp ctxt (ATP_Problem.THF _) type_enc = |
435 fun term_of_atp ctxt (ATP_Problem.THF _) type_enc = |
455 if ATP_Problem_Generate.is_type_enc_higher_order type_enc |
436 if ATP_Problem_Generate.is_type_enc_higher_order type_enc then K (term_of_atp_ho ctxt) |
456 then term_of_atp_ho ctxt |
|
457 else error "Unsupported Isar reconstruction." |
437 else error "Unsupported Isar reconstruction." |
458 | term_of_atp ctxt _ type_enc = |
438 | term_of_atp ctxt _ type_enc = |
459 if not (ATP_Problem_Generate.is_type_enc_higher_order type_enc) |
439 if not (ATP_Problem_Generate.is_type_enc_higher_order type_enc) then term_of_atp_fo ctxt |
460 then term_of_atp_fo ctxt |
|
461 else error "Unsupported Isar reconstruction." |
440 else error "Unsupported Isar reconstruction." |
462 |
441 |
463 fun term_of_atom ctxt format type_enc textual sym_tab pos (u as ATerm ((s, _), _)) = |
442 fun term_of_atom ctxt format type_enc textual sym_tab pos (u as ATerm ((s, _), _)) = |
464 if String.isPrefix class_prefix s then |
443 if String.isPrefix class_prefix s then |
465 add_type_constraint pos (type_constraint_of_term ctxt u) |
444 add_type_constraint pos (type_constraint_of_term ctxt u) |