92 fun mk_anot phi = AConn (ANot, [phi]) |
92 fun mk_anot phi = AConn (ANot, [phi]) |
93 fun mk_aconn c phi1 phi2 = AConn (c, [phi1, phi2]) |
93 fun mk_aconn c phi1 phi2 = AConn (c, [phi1, phi2]) |
94 fun mk_ahorn [] phi = phi |
94 fun mk_ahorn [] phi = phi |
95 | mk_ahorn (phi :: phis) psi = |
95 | mk_ahorn (phi :: phis) psi = |
96 AConn (AImplies, [fold (mk_aconn AAnd) phis phi, psi]) |
96 AConn (AImplies, [fold (mk_aconn AAnd) phis phi, psi]) |
|
97 |
|
98 fun close_universally phi = |
|
99 let |
|
100 fun term_vars bounds (ATerm (name as (s, _), tms)) = |
|
101 (is_atp_variable s andalso not (member (op =) bounds name)) |
|
102 ? insert (op =) name |
|
103 #> fold (term_vars bounds) tms |
|
104 fun formula_vars bounds (AQuant (_, xs, phi)) = |
|
105 formula_vars (xs @ bounds) phi |
|
106 | formula_vars bounds (AConn (_, phis)) = fold (formula_vars bounds) phis |
|
107 | formula_vars bounds (AAtom tm) = term_vars bounds tm |
|
108 in |
|
109 case formula_vars [] phi [] of [] => phi | xs => AQuant (AForall, xs, phi) |
|
110 end |
97 |
111 |
98 fun combformula_for_prop thy eq_as_iff = |
112 fun combformula_for_prop thy eq_as_iff = |
99 let |
113 let |
100 fun do_term bs t ts = |
114 fun do_term bs t ts = |
101 combterm_from_term thy bs (Envir.eta_contract t) |
115 combterm_from_term thy bs (Envir.eta_contract t) |
262 |
276 |
263 val init_counters = |
277 val init_counters = |
264 metis_helpers |> map fst |> sort_distinct string_ord |> map (rpair 0) |
278 metis_helpers |> map fst |> sort_distinct string_ord |> map (rpair 0) |
265 |> Symtab.make |
279 |> Symtab.make |
266 |
280 |
267 fun get_helper_facts ctxt type_sys formulas = |
281 fun get_helper_facts ctxt explicit_forall type_sys formulas = |
268 let |
282 let |
269 val no_dangerous_types = types_dangerous_types type_sys |
283 val no_dangerous_types = types_dangerous_types type_sys |
270 val ct = init_counters |> fold count_formula formulas |
284 val ct = init_counters |> fold count_formula formulas |
271 fun is_used s = the (Symtab.lookup ct s) > 0 |
285 fun is_used s = the (Symtab.lookup ct s) > 0 |
272 fun dub c needs_full_types (th, j) = |
286 fun dub c needs_full_types (th, j) = |
273 ((c ^ "_" ^ string_of_int j ^ (if needs_full_types then "ft" else ""), |
287 ((c ^ "_" ^ string_of_int j ^ (if needs_full_types then "ft" else ""), |
274 false), th) |
288 false), th) |
275 fun make_facts eq_as_iff = map_filter (make_fact ctxt eq_as_iff false) |
289 fun make_facts eq_as_iff = map_filter (make_fact ctxt eq_as_iff false) |
276 in |
290 in |
277 metis_helpers |
291 (metis_helpers |
278 |> filter (is_used o fst) |
292 |> filter (is_used o fst) |
279 |> maps (fn (c, (needs_full_types, ths)) => |
293 |> maps (fn (c, (needs_full_types, ths)) => |
280 if needs_full_types andalso not no_dangerous_types then |
294 if needs_full_types andalso not no_dangerous_types then |
281 [] |
295 [] |
282 else |
296 else |
283 ths ~~ (1 upto length ths) |
297 ths ~~ (1 upto length ths) |
284 |> map (dub c needs_full_types) |
298 |> map (dub c needs_full_types) |
285 |> make_facts (not needs_full_types)) |
299 |> make_facts (not needs_full_types)), |
|
300 if type_sys = Tags false then |
|
301 let |
|
302 fun var s = ATerm (`I s, []) |
|
303 fun tag tm = ATerm (`I type_tag_name, [var "X", tm]) |
|
304 in |
|
305 [Fof (helper_prefix ^ ascii_of "ti_ti", Axiom, |
|
306 AAtom (ATerm (`I "equal", [tag (tag (var "Y")), tag (var "Y")])) |
|
307 |> explicit_forall ? close_universally)] |
|
308 end |
|
309 else |
|
310 []) |
286 end |
311 end |
287 |
312 |
288 fun translate_atp_fact ctxt = `(make_fact ctxt true true) |
313 fun translate_atp_fact ctxt = `(make_fact ctxt true true) |
289 |
314 |
290 fun translate_formulas ctxt type_sys hyp_ts concl_t rich_facts = |
315 fun translate_formulas ctxt type_sys hyp_ts concl_t rich_facts = |
569 if is_predicate pred_const_tab s' then t' else boolify t |
594 if is_predicate pred_const_tab s' then t' else boolify t |
570 | _ => raise Fail "malformed type tag" |
595 | _ => raise Fail "malformed type tag" |
571 else |
596 else |
572 t |> not (is_predicate pred_const_tab s) ? boolify |
597 t |> not (is_predicate pred_const_tab s) ? boolify |
573 |
598 |
574 fun close_universally phi = |
|
575 let |
|
576 fun term_vars bounds (ATerm (name as (s, _), tms)) = |
|
577 (is_atp_variable s andalso not (member (op =) bounds name)) |
|
578 ? insert (op =) name |
|
579 #> fold (term_vars bounds) tms |
|
580 fun formula_vars bounds (AQuant (_, xs, phi)) = |
|
581 formula_vars (xs @ bounds) phi |
|
582 | formula_vars bounds (AConn (_, phis)) = fold (formula_vars bounds) phis |
|
583 | formula_vars bounds (AAtom tm) = term_vars bounds tm |
|
584 in |
|
585 case formula_vars [] phi [] of [] => phi | xs => AQuant (AForall, xs, phi) |
|
586 end |
|
587 |
|
588 fun repair_formula thy explicit_forall type_sys const_tab = |
599 fun repair_formula thy explicit_forall type_sys const_tab = |
589 let |
600 let |
590 val pred_const_tab = case type_sys of Tags _ => NONE | _ => const_tab |
601 val pred_const_tab = case type_sys of Tags _ => NONE | _ => const_tab |
591 fun aux (AQuant (q, xs, phi)) = AQuant (q, xs, aux phi) |
602 fun aux (AQuant (q, xs, phi)) = AQuant (q, xs, aux phi) |
592 | aux (AConn (c, phis)) = AConn (c, map aux phis) |
603 | aux (AConn (c, phis)) = AConn (c, map aux phis) |
625 ("Conjectures", conjecture_lines), |
636 ("Conjectures", conjecture_lines), |
626 ("Type variables", tfree_lines)] |
637 ("Type variables", tfree_lines)] |
627 val const_tab = const_table_for_problem explicit_apply problem |
638 val const_tab = const_table_for_problem explicit_apply problem |
628 val problem = |
639 val problem = |
629 problem |> repair_problem thy explicit_forall type_sys const_tab |
640 problem |> repair_problem thy explicit_forall type_sys const_tab |
630 val helper_facts = |
641 val (helper_facts, raw_helper_lines) = |
631 get_helper_facts ctxt type_sys (maps (map (#3 o dest_Fof) o snd) problem) |
642 get_helper_facts ctxt explicit_forall type_sys |
|
643 (maps (map (#3 o dest_Fof) o snd) problem) |
632 val helper_lines = |
644 val helper_lines = |
633 helper_facts |
645 (helper_facts |
634 |> map (problem_line_for_fact ctxt helper_prefix type_sys |
646 |> map (problem_line_for_fact ctxt helper_prefix type_sys |
635 #> repair_problem_line thy explicit_forall type_sys const_tab) |
647 #> repair_problem_line thy explicit_forall type_sys const_tab)) @ |
|
648 raw_helper_lines |
636 val (problem, pool) = |
649 val (problem, pool) = |
637 problem |> AList.update (op =) ("Helper facts", helper_lines) |
650 problem |> AList.update (op =) ("Helper facts", helper_lines) |
638 |> nice_atp_problem readable_names |
651 |> nice_atp_problem readable_names |
639 val conjecture_offset = |
652 val conjecture_offset = |
640 length fact_lines + length class_rel_lines + length arity_lines |
653 length fact_lines + length class_rel_lines + length arity_lines |