author | blanchet |
Tue, 31 May 2011 16:38:36 +0200 | |
changeset 43092 | 93ec303e1917 |
parent 43091 | b0b30df60056 |
child 43093 | 40e50afbc203 |
permissions | -rw-r--r-- |
39958 | 1 |
(* Title: HOL/Tools/Metis/metis_translate.ML |
38027 | 2 |
Author: Jia Meng, Cambridge University Computer Laboratory and NICTA |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
3 |
Author: Kong W. Susanto, Cambridge University Computer Laboratory |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
4 |
Author: Lawrence C. Paulson, Cambridge University Computer Laboratory |
36393
be73a2b2443b
support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents:
36378
diff
changeset
|
5 |
Author: Jasmin Blanchette, TU Muenchen |
15347 | 6 |
|
39494
bf7dd4902321
rename "Metis_Clauses" to "Metis_Translate" for consistency with "Sledgehammer_Translate"
blanchet
parents:
39355
diff
changeset
|
7 |
Translation of HOL to FOL for Metis. |
15347 | 8 |
*) |
9 |
||
39494
bf7dd4902321
rename "Metis_Clauses" to "Metis_Translate" for consistency with "Sledgehammer_Translate"
blanchet
parents:
39355
diff
changeset
|
10 |
signature METIS_TRANSLATE = |
24310 | 11 |
sig |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43003
diff
changeset
|
12 |
type type_literal = ATP_Translate.type_literal |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
13 |
|
43087
b870759ce0f3
added new metis mode, with no implementation yet
blanchet
parents:
43086
diff
changeset
|
14 |
datatype mode = FO | HO | FT | New |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43003
diff
changeset
|
15 |
|
40157 | 16 |
type metis_problem = |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
17 |
{axioms: (Metis_Thm.thm * thm) list, |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
18 |
tfrees: type_literal list, |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
19 |
old_skolems: (string * term) list} |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
20 |
|
42098
f978caf60bbe
more robust handling of variables in new Skolemizer
blanchet
parents:
41491
diff
changeset
|
21 |
val metis_generated_var_prefix : string |
39896
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
22 |
val new_skolem_const_prefix : string |
37618
fa57a87f92a0
get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents:
37616
diff
changeset
|
23 |
val num_type_args: theory -> string -> int |
40259
c0e34371c2e2
prevent type errors because of inconsistent skolem Var types by giving fresh indices to Skolems
blanchet
parents:
40157
diff
changeset
|
24 |
val new_skolem_var_name_from_const : string -> string |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
25 |
val reveal_old_skolem_terms : (string * term) list -> term -> term |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
26 |
val string_of_mode : mode -> string |
40157 | 27 |
val prepare_metis_problem : |
43092
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
28 |
Proof.context -> mode -> thm list -> thm list -> mode * metis_problem |
24310 | 29 |
end |
15347 | 30 |
|
39494
bf7dd4902321
rename "Metis_Clauses" to "Metis_Translate" for consistency with "Sledgehammer_Translate"
blanchet
parents:
39355
diff
changeset
|
31 |
structure Metis_Translate : METIS_TRANSLATE = |
15347 | 32 |
struct |
33 |
||
43092
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
34 |
open ATP_Problem |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43003
diff
changeset
|
35 |
open ATP_Translate |
15347 | 36 |
|
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43003
diff
changeset
|
37 |
val metis_generated_var_prefix = "_" |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
38 |
|
37618
fa57a87f92a0
get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents:
37616
diff
changeset
|
39 |
(* The number of type arguments of a constant, zero if it's monomorphic. For |
fa57a87f92a0
get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents:
37616
diff
changeset
|
40 |
(instances of) Skolem pseudoconstants, this information is encoded in the |
fa57a87f92a0
get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents:
37616
diff
changeset
|
41 |
constant name. *) |
fa57a87f92a0
get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents:
37616
diff
changeset
|
42 |
fun num_type_args thy s = |
39896
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
43 |
if String.isPrefix skolem_const_prefix s then |
39499 | 44 |
s |> space_explode Long_Name.separator |> List.last |> Int.fromString |> the |
37618
fa57a87f92a0
get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents:
37616
diff
changeset
|
45 |
else |
fa57a87f92a0
get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents:
37616
diff
changeset
|
46 |
(s, Sign.the_const_type thy s) |> Sign.const_typargs thy |> length |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
47 |
|
40259
c0e34371c2e2
prevent type errors because of inconsistent skolem Var types by giving fresh indices to Skolems
blanchet
parents:
40157
diff
changeset
|
48 |
fun new_skolem_var_name_from_const s = |
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
49 |
let val ss = s |> space_explode Long_Name.separator in |
40259
c0e34371c2e2
prevent type errors because of inconsistent skolem Var types by giving fresh indices to Skolems
blanchet
parents:
40157
diff
changeset
|
50 |
nth ss (length ss - 2) |
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
51 |
end |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
52 |
|
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
53 |
fun predicate_of thy ((@{const Not} $ P), pos) = predicate_of thy (P, not pos) |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
54 |
| predicate_of thy (t, pos) = |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
55 |
(combterm_from_term thy [] (Envir.eta_contract t), pos) |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
56 |
|
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
57 |
fun literals_of_term1 args thy (@{const Trueprop} $ P) = |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
58 |
literals_of_term1 args thy P |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
59 |
| literals_of_term1 args thy (@{const HOL.disj} $ P $ Q) = |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
60 |
literals_of_term1 (literals_of_term1 args thy P) thy Q |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
61 |
| literals_of_term1 (lits, ts) thy P = |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
62 |
let val ((pred, ts'), pol) = predicate_of thy (P, true) in |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43003
diff
changeset
|
63 |
((pol, pred) :: lits, union (op =) ts ts') |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
64 |
end |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
65 |
val literals_of_term = literals_of_term1 ([], []) |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
66 |
|
39896
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
67 |
fun old_skolem_const_name i j num_T_args = |
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
68 |
old_skolem_const_prefix ^ Long_Name.separator ^ |
41491 | 69 |
(space_implode Long_Name.separator (map string_of_int [i, j, num_T_args])) |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
70 |
|
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
71 |
fun conceal_old_skolem_terms i old_skolems t = |
39953
aa54f347e5e2
hide uninteresting MESON/Metis constants and facts and remove "meson_" prefix to (now hidden) fact names
blanchet
parents:
39946
diff
changeset
|
72 |
if exists_Const (curry (op =) @{const_name Meson.skolem} o fst) t then |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
73 |
let |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
74 |
fun aux old_skolems |
39953
aa54f347e5e2
hide uninteresting MESON/Metis constants and facts and remove "meson_" prefix to (now hidden) fact names
blanchet
parents:
39946
diff
changeset
|
75 |
(t as (Const (@{const_name Meson.skolem}, Type (_, [_, T])) $ _)) = |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
76 |
let |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
77 |
val (old_skolems, s) = |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
78 |
if i = ~1 then |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
79 |
(old_skolems, @{const_name undefined}) |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
80 |
else case AList.find (op aconv) old_skolems t of |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
81 |
s :: _ => (old_skolems, s) |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
82 |
| [] => |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
83 |
let |
39896
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
84 |
val s = old_skolem_const_name i (length old_skolems) |
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
85 |
(length (Term.add_tvarsT T [])) |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
86 |
in ((s, t) :: old_skolems, s) end |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
87 |
in (old_skolems, Const (s, T)) end |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
88 |
| aux old_skolems (t1 $ t2) = |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
89 |
let |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
90 |
val (old_skolems, t1) = aux old_skolems t1 |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
91 |
val (old_skolems, t2) = aux old_skolems t2 |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
92 |
in (old_skolems, t1 $ t2) end |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
93 |
| aux old_skolems (Abs (s, T, t')) = |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
94 |
let val (old_skolems, t') = aux old_skolems t' in |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
95 |
(old_skolems, Abs (s, T, t')) |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
96 |
end |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
97 |
| aux old_skolems t = (old_skolems, t) |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
98 |
in aux old_skolems t end |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
99 |
else |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
100 |
(old_skolems, t) |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
101 |
|
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
102 |
fun reveal_old_skolem_terms old_skolems = |
37632 | 103 |
map_aterms (fn t as Const (s, _) => |
39896
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
104 |
if String.isPrefix old_skolem_const_prefix s then |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
105 |
AList.lookup (op =) old_skolems s |> the |
37632 | 106 |
|> map_types Type_Infer.paramify_vars |
107 |
else |
|
108 |
t |
|
109 |
| t => t) |
|
110 |
||
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
111 |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
112 |
(* ------------------------------------------------------------------------- *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
113 |
(* HOL to FOL (Isabelle to Metis) *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
114 |
(* ------------------------------------------------------------------------- *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
115 |
|
43087
b870759ce0f3
added new metis mode, with no implementation yet
blanchet
parents:
43086
diff
changeset
|
116 |
(* first-order, higher-order, fully-typed, new *) |
b870759ce0f3
added new metis mode, with no implementation yet
blanchet
parents:
43086
diff
changeset
|
117 |
datatype mode = FO | HO | FT | New |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
118 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
119 |
fun string_of_mode FO = "FO" |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
120 |
| string_of_mode HO = "HO" |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
121 |
| string_of_mode FT = "FT" |
43087
b870759ce0f3
added new metis mode, with no implementation yet
blanchet
parents:
43086
diff
changeset
|
122 |
| string_of_mode New = "New" |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
123 |
|
42745
b817c6f91a98
reenabled equality proxy in Metis for higher-order reasoning
blanchet
parents:
42727
diff
changeset
|
124 |
fun fn_isa_to_met_sublevel "equal" = "c_fequal" |
41139
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
125 |
| fn_isa_to_met_sublevel "c_False" = "c_fFalse" |
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
126 |
| fn_isa_to_met_sublevel "c_True" = "c_fTrue" |
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
127 |
| fn_isa_to_met_sublevel "c_Not" = "c_fNot" |
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
128 |
| fn_isa_to_met_sublevel "c_conj" = "c_fconj" |
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
129 |
| fn_isa_to_met_sublevel "c_disj" = "c_fdisj" |
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
130 |
| fn_isa_to_met_sublevel "c_implies" = "c_fimplies" |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
131 |
| fn_isa_to_met_sublevel x = x |
42758
865ce93ce025
handle equality proxy in a more backward-compatible way
blanchet
parents:
42745
diff
changeset
|
132 |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
133 |
fun fn_isa_to_met_toplevel "equal" = "=" |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
134 |
| fn_isa_to_met_toplevel x = x |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
135 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
136 |
fun metis_lit b c args = (b, (c, args)); |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
137 |
|
42562 | 138 |
fun metis_term_from_typ (Type (s, Ts)) = |
139 |
Metis_Term.Fn (make_fixed_type_const s, map metis_term_from_typ Ts) |
|
140 |
| metis_term_from_typ (TFree (s, _)) = |
|
141 |
Metis_Term.Fn (make_fixed_type_var s, []) |
|
142 |
| metis_term_from_typ (TVar (x, _)) = |
|
143 |
Metis_Term.Var (make_schematic_type_var x) |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
144 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
145 |
(*These two functions insert type literals before the real literals. That is the |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
146 |
opposite order from TPTP linkup, but maybe OK.*) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
147 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
148 |
fun hol_term_to_fol_FO tm = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
149 |
case strip_combterm_comb tm of |
42562 | 150 |
(CombConst ((c, _), _, Ts), tms) => |
151 |
let val tyargs = map metis_term_from_typ Ts |
|
152 |
val args = map hol_term_to_fol_FO tms |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
153 |
in Metis_Term.Fn (c, tyargs @ args) end |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
154 |
| (CombVar ((v, _), _), []) => Metis_Term.Var v |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
155 |
| _ => raise Fail "non-first-order combterm" |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
156 |
|
42562 | 157 |
fun hol_term_to_fol_HO (CombConst ((a, _), _, Ts)) = |
158 |
Metis_Term.Fn (fn_isa_to_met_sublevel a, map metis_term_from_typ Ts) |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
159 |
| hol_term_to_fol_HO (CombVar ((s, _), _)) = Metis_Term.Var s |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
160 |
| hol_term_to_fol_HO (CombApp (tm1, tm2)) = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
161 |
Metis_Term.Fn (".", map hol_term_to_fol_HO [tm1, tm2]); |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
162 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
163 |
(*The fully-typed translation, to avoid type errors*) |
42562 | 164 |
fun tag_with_type tm T = |
165 |
Metis_Term.Fn (type_tag_name, [tm, metis_term_from_typ T]) |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
166 |
|
41138
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
40259
diff
changeset
|
167 |
fun hol_term_to_fol_FT (CombVar ((s, _), ty)) = |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
40259
diff
changeset
|
168 |
tag_with_type (Metis_Term.Var s) ty |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
40259
diff
changeset
|
169 |
| hol_term_to_fol_FT (CombConst ((a, _), ty, _)) = |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
40259
diff
changeset
|
170 |
tag_with_type (Metis_Term.Fn (fn_isa_to_met_sublevel a, [])) ty |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
40259
diff
changeset
|
171 |
| hol_term_to_fol_FT (tm as CombApp (tm1,tm2)) = |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
40259
diff
changeset
|
172 |
tag_with_type (Metis_Term.Fn (".", map hol_term_to_fol_FT [tm1, tm2])) |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
40259
diff
changeset
|
173 |
(combtyp_of tm) |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
174 |
|
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43003
diff
changeset
|
175 |
fun hol_literal_to_fol FO (pos, tm) = |
42562 | 176 |
let |
177 |
val (CombConst((p, _), _, Ts), tms) = strip_combterm_comb tm |
|
178 |
val tylits = if p = "equal" then [] else map metis_term_from_typ Ts |
|
179 |
val lits = map hol_term_to_fol_FO tms |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
180 |
in metis_lit pos (fn_isa_to_met_toplevel p) (tylits @ lits) end |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43003
diff
changeset
|
181 |
| hol_literal_to_fol HO (pos, tm) = |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
182 |
(case strip_combterm_comb tm of |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
183 |
(CombConst(("equal", _), _, _), tms) => |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
184 |
metis_lit pos "=" (map hol_term_to_fol_HO tms) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
185 |
| _ => metis_lit pos "{}" [hol_term_to_fol_HO tm]) (*hBOOL*) |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43003
diff
changeset
|
186 |
| hol_literal_to_fol FT (pos, tm) = |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
187 |
(case strip_combterm_comb tm of |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
188 |
(CombConst(("equal", _), _, _), tms) => |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
189 |
metis_lit pos "=" (map hol_term_to_fol_FT tms) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
190 |
| _ => metis_lit pos "{}" [hol_term_to_fol_FT tm]) (*hBOOL*); |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
191 |
|
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
192 |
fun literals_of_hol_term thy mode t = |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
193 |
let val (lits, types_sorts) = literals_of_term thy t in |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
194 |
(map (hol_literal_to_fol mode) lits, types_sorts) |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
195 |
end |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
196 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
197 |
(*Sign should be "true" for conjecture type constraints, "false" for type lits in clauses.*) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
198 |
fun metis_of_type_literals pos (TyLitVar ((s, _), (s', _))) = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
199 |
metis_lit pos s [Metis_Term.Var s'] |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
200 |
| metis_of_type_literals pos (TyLitFree ((s, _), (s', _))) = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
201 |
metis_lit pos s [Metis_Term.Fn (s',[])] |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
202 |
|
42352 | 203 |
fun has_default_sort _ (TVar _) = false |
204 |
| has_default_sort ctxt (TFree (x, s)) = |
|
205 |
(s = the_default [] (Variable.def_sort ctxt (x, ~1))); |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
206 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
207 |
fun metis_of_tfree tf = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
208 |
Metis_Thm.axiom (Metis_LiteralSet.singleton (metis_of_type_literals true tf)); |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
209 |
|
43090 | 210 |
fun hol_thm_to_fol is_conjecture ctxt mode j old_skolems th = |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
211 |
let |
42361 | 212 |
val thy = Proof_Context.theory_of ctxt |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
213 |
val (old_skolems, (mlits, types_sorts)) = |
39888 | 214 |
th |> prop_of |> Logic.strip_imp_concl |
215 |
|> conceal_old_skolem_terms j old_skolems |
|
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
216 |
||> (HOLogic.dest_Trueprop #> literals_of_hol_term thy mode) |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
217 |
in |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
218 |
if is_conjecture then |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
219 |
(Metis_Thm.axiom (Metis_LiteralSet.fromList mlits), |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43003
diff
changeset
|
220 |
raw_type_literals_for_types types_sorts, old_skolems) |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
221 |
else |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
222 |
let |
42352 | 223 |
val tylits = types_sorts |> filter_out (has_default_sort ctxt) |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43003
diff
changeset
|
224 |
|> raw_type_literals_for_types |
43090 | 225 |
val mtylits = map (metis_of_type_literals false) tylits |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
226 |
in |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
227 |
(Metis_Thm.axiom (Metis_LiteralSet.fromList(mtylits @ mlits)), [], |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
228 |
old_skolems) |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
229 |
end |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
230 |
end; |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
231 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
232 |
(* ------------------------------------------------------------------------- *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
233 |
(* Logic maps manage the interface between HOL and first-order logic. *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
234 |
(* ------------------------------------------------------------------------- *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
235 |
|
40157 | 236 |
type metis_problem = |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
237 |
{axioms: (Metis_Thm.thm * thm) list, |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
238 |
tfrees: type_literal list, |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
239 |
old_skolems: (string * term) list} |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
240 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
241 |
fun is_quasi_fol_clause thy = |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
242 |
Meson.is_fol_term thy o snd o conceal_old_skolem_terms ~1 [] o prop_of |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
243 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
244 |
(*Extract TFree constraints from context to include as conjecture clauses*) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
245 |
fun init_tfrees ctxt = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
246 |
let fun add ((a,i),s) Ts = if i = ~1 then TFree(a,s) :: Ts else Ts in |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
247 |
Vartab.fold add (#2 (Variable.constraints_of ctxt)) [] |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43003
diff
changeset
|
248 |
|> raw_type_literals_for_types |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
249 |
end; |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
250 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
251 |
fun const_in_metis c (pred, tm_list) = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
252 |
let |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
253 |
fun in_mterm (Metis_Term.Var _) = false |
41156 | 254 |
| in_mterm (Metis_Term.Fn (nm, tm_list)) = |
255 |
c = nm orelse exists in_mterm tm_list |
|
256 |
in c = pred orelse exists in_mterm tm_list end |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
257 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
258 |
(* ARITY CLAUSE *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
259 |
fun m_arity_cls (TConsLit ((c, _), (t, _), args)) = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
260 |
metis_lit true c [Metis_Term.Fn(t, map (Metis_Term.Var o fst) args)] |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
261 |
| m_arity_cls (TVarLit ((c, _), (s, _))) = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
262 |
metis_lit false c [Metis_Term.Var s] |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
263 |
(*TrueI is returned as the Isabelle counterpart because there isn't any.*) |
43086 | 264 |
fun arity_cls ({prem_lits, concl_lits, ...} : arity_clause) = |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
265 |
(TrueI, |
42895 | 266 |
Metis_Thm.axiom (Metis_LiteralSet.fromList |
267 |
(map m_arity_cls (concl_lits :: prem_lits)))); |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
268 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
269 |
(* CLASSREL CLAUSE *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
270 |
fun m_class_rel_cls (subclass, _) (superclass, _) = |
43091 | 271 |
[metis_lit false subclass [Metis_Term.Var "T"], |
272 |
metis_lit true superclass [Metis_Term.Var "T"]] |
|
43086 | 273 |
fun class_rel_cls ({subclass, superclass, ...} : class_rel_clause) = |
43091 | 274 |
(TrueI, m_class_rel_cls subclass superclass |
275 |
|> Metis_LiteralSet.fromList |> Metis_Thm.axiom) |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
276 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
277 |
fun type_ext thy tms = |
43091 | 278 |
let |
279 |
val subs = tfree_classes_of_terms tms |
|
280 |
val supers = tvar_classes_of_terms tms |
|
281 |
val tycons = type_consts_of_terms thy tms |
|
282 |
val (supers', arity_clauses) = make_arity_clauses thy tycons supers |
|
283 |
val class_rel_clauses = make_class_rel_clauses thy subs supers' |
|
284 |
in map class_rel_cls class_rel_clauses @ map arity_cls arity_clauses end |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
285 |
|
43092
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
286 |
fun metis_name_from_atp s = |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
287 |
if is_tptp_equal s then "=" |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
288 |
else if s = predicator_name then "{}" |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
289 |
else if s = app_op_name then "." |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
290 |
else s |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
291 |
fun metis_term_from_atp (ATerm (s, tms)) = |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
292 |
if is_tptp_variable s then Metis_Term.Var s |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
293 |
else Metis_Term.Fn (metis_name_from_atp s, map metis_term_from_atp tms) |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
294 |
fun metis_atom_from_atp (AAtom (ATerm (s, tms))) = |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
295 |
(metis_name_from_atp s, map metis_term_from_atp tms) |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
296 |
| metis_atom_from_atp _ = raise Fail "not CNF -- expected atom" |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
297 |
fun metis_literal_from_atp (AConn (ANot, [phi])) = |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
298 |
(false, metis_atom_from_atp phi) |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
299 |
| metis_literal_from_atp phi = (true, metis_atom_from_atp phi) |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
300 |
fun metis_literals_from_atp (AConn (AOr, [phi1, phi2])) = |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
301 |
uncurry (union (op =)) (pairself metis_literals_from_atp (phi1, phi2)) |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
302 |
| metis_literals_from_atp phi = [metis_literal_from_atp phi] |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
303 |
fun metis_axiom_from_atp clauses (Formula (ident, _, phi, _, _)) = |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
304 |
let val j = ident |> unprefix conjecture_prefix |> Int.fromString |> the in |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
305 |
(phi |> metis_literals_from_atp |> Metis_LiteralSet.fromList |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
306 |
|> Metis_Thm.axiom, |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
307 |
Meson.make_meta_clause (nth clauses j)) |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
308 |
end |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
309 |
| metis_axiom_from_atp _ _ = raise Fail "not CNF -- expected formula" |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
310 |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
311 |
(* Function to generate metis clauses, including comb and type clauses *) |
43092
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
312 |
fun prepare_metis_problem ctxt New conj_clauses fact_clauses = |
43091 | 313 |
let |
43092
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
314 |
val type_sys = Preds (Polymorphic, (* Nonmonotonic_Types FIXME ### *) No_Types, Light) |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
315 |
val explicit_apply = NONE |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
316 |
val clauses = conj_clauses @ fact_clauses |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
317 |
val (atp_problem, pool, _, _, _, _, sym_tab) = |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
318 |
prepare_atp_problem ctxt CNF Hypothesis Axiom type_sys |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
319 |
explicit_apply false (map prop_of clauses) |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
320 |
@{prop False} [] |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
321 |
(* val _ = tracing (PolyML.makestring atp_problem) FIXME ### *) |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
322 |
val axioms = |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
323 |
atp_problem |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
324 |
|> maps (map_filter (try (metis_axiom_from_atp clauses)) o snd) |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
325 |
in (New, {axioms = axioms, tfrees = [], old_skolems = [] (* FIXME ### *)}) end |
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
326 |
| prepare_metis_problem ctxt mode conj_clauses fact_clauses = |
43087
b870759ce0f3
added new metis mode, with no implementation yet
blanchet
parents:
43086
diff
changeset
|
327 |
let |
b870759ce0f3
added new metis mode, with no implementation yet
blanchet
parents:
43086
diff
changeset
|
328 |
val thy = Proof_Context.theory_of ctxt |
b870759ce0f3
added new metis mode, with no implementation yet
blanchet
parents:
43086
diff
changeset
|
329 |
(* The modes FO and FT are sticky. HO can be downgraded to FO. *) |
b870759ce0f3
added new metis mode, with no implementation yet
blanchet
parents:
43086
diff
changeset
|
330 |
val mode = |
b870759ce0f3
added new metis mode, with no implementation yet
blanchet
parents:
43086
diff
changeset
|
331 |
if mode = HO andalso |
43091 | 332 |
forall (forall (is_quasi_fol_clause thy)) |
43092
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
333 |
[conj_clauses, fact_clauses] then |
43087
b870759ce0f3
added new metis mode, with no implementation yet
blanchet
parents:
43086
diff
changeset
|
334 |
FO |
b870759ce0f3
added new metis mode, with no implementation yet
blanchet
parents:
43086
diff
changeset
|
335 |
else |
b870759ce0f3
added new metis mode, with no implementation yet
blanchet
parents:
43086
diff
changeset
|
336 |
mode |
41139
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
337 |
fun add_thm is_conjecture (isa_ith, metis_ith) |
40157 | 338 |
{axioms, tfrees, old_skolems} : metis_problem = |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
339 |
let |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
340 |
val (mth, tfree_lits, old_skolems) = |
43090 | 341 |
hol_thm_to_fol is_conjecture ctxt mode (length axioms) old_skolems |
342 |
metis_ith |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
343 |
in |
43091 | 344 |
{axioms = (mth, isa_ith) :: axioms, |
345 |
tfrees = union (op =) tfree_lits tfrees, old_skolems = old_skolems} |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
346 |
end; |
43091 | 347 |
fun add_type_thm (ith, mth) {axioms, tfrees, old_skolems} = |
348 |
{axioms = (mth, ith) :: axioms, tfrees = tfrees, |
|
349 |
old_skolems = old_skolems} |
|
350 |
fun add_tfrees {axioms, tfrees, old_skolems} = |
|
351 |
{axioms = |
|
352 |
map (rpair TrueI o metis_of_tfree) (distinct (op =) tfrees) @ axioms, |
|
353 |
tfrees = tfrees, old_skolems = old_skolems} |
|
354 |
val problem = |
|
355 |
{axioms = [], tfrees = init_tfrees ctxt, old_skolems = []} |
|
356 |
|> fold (add_thm true o `Meson.make_meta_clause) conj_clauses |
|
357 |
|> add_tfrees |
|
43092
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
358 |
|> fold (add_thm false o `Meson.make_meta_clause) fact_clauses |
43091 | 359 |
val clause_lists = map (Metis_Thm.clause o #1) (#axioms problem) |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
360 |
fun is_used c = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
361 |
exists (Metis_LiteralSet.exists (const_in_metis c o #2)) clause_lists |
43091 | 362 |
val problem = |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
363 |
if mode = FO then |
43091 | 364 |
problem |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
365 |
else |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
366 |
let |
41156 | 367 |
val fdefs = @{thms fFalse_def fTrue_def fNot_def fconj_def fdisj_def |
368 |
fimplies_def fequal_def} |
|
41139
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
369 |
val prepare_helper = |
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
370 |
zero_var_indexes |
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
371 |
#> `(Meson.make_meta_clause |
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
372 |
#> rewrite_rule (map safe_mk_meta_eq fdefs)) |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
373 |
val helper_ths = |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43003
diff
changeset
|
374 |
helper_table |
42561
23ddc4e3d19c
have properly type-instantiated helper facts (combinators and If)
blanchet
parents:
42544
diff
changeset
|
375 |
|> filter (is_used o prefix const_prefix o fst) |
42894
ce269ee43800
further improvements to "poly_{preds,tags}_{bang,query}" -- better solution to the combinator problem + make sure type assumptions can be discharged
blanchet
parents:
42893
diff
changeset
|
376 |
|> maps (fn (_, (needs_full_types, thms)) => |
41140
9c68004b8c9d
added Sledgehammer support for higher-order propositional reasoning
blanchet
parents:
41139
diff
changeset
|
377 |
if needs_full_types andalso mode <> FT then [] |
9c68004b8c9d
added Sledgehammer support for higher-order propositional reasoning
blanchet
parents:
41139
diff
changeset
|
378 |
else map prepare_helper thms) |
43091 | 379 |
in problem |> fold (add_thm false) helper_ths end |
43092
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
380 |
val type_ths = type_ext thy (map prop_of (conj_clauses @ fact_clauses)) |
43091 | 381 |
in (mode, fold add_type_thm type_ths problem) end |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
382 |
|
15347 | 383 |
end; |