author | blanchet |
Wed, 07 Sep 2011 09:10:41 +0200 | |
changeset 44768 | a7bc1bdb8bb4 |
parent 44492 | a330c0608da8 |
child 44782 | ba4c0205267f |
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 |
44411
e3629929b171
change Metis's default settings if type information axioms are generated
blanchet
parents:
44409
diff
changeset
|
12 |
type type_enc = ATP_Translate.type_enc |
e3629929b171
change Metis's default settings if type information axioms are generated
blanchet
parents:
44409
diff
changeset
|
13 |
|
43159
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents:
43132
diff
changeset
|
14 |
datatype isa_thm = |
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents:
43132
diff
changeset
|
15 |
Isa_Reflexive_or_Trivial | |
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents:
43132
diff
changeset
|
16 |
Isa_Raw of thm |
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents:
43132
diff
changeset
|
17 |
|
43094 | 18 |
val metis_equal : string |
19 |
val metis_predicator : string |
|
20 |
val metis_app_op : string |
|
44492
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
21 |
val metis_systematic_type_tag : string |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
22 |
val metis_ad_hoc_type_tag : string |
42098
f978caf60bbe
more robust handling of variables in new Skolemizer
blanchet
parents:
41491
diff
changeset
|
23 |
val metis_generated_var_prefix : string |
43231
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
blanchet
parents:
43224
diff
changeset
|
24 |
val trace : bool Config.T |
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
blanchet
parents:
43224
diff
changeset
|
25 |
val verbose : bool Config.T |
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
blanchet
parents:
43224
diff
changeset
|
26 |
val trace_msg : Proof.context -> (unit -> string) -> unit |
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
blanchet
parents:
43224
diff
changeset
|
27 |
val verbose_warning : Proof.context -> string -> unit |
44492
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
28 |
val metis_name_table : ((string * int) * ((type_enc -> string) * bool)) list |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
29 |
val reveal_old_skolem_terms : (string * term) list -> term -> term |
40157 | 30 |
val prepare_metis_problem : |
44411
e3629929b171
change Metis's default settings if type information axioms are generated
blanchet
parents:
44409
diff
changeset
|
31 |
Proof.context -> type_enc -> thm list -> thm list |
43212 | 32 |
-> int Symtab.table * (Metis_Thm.thm * isa_thm) list * (string * term) list |
24310 | 33 |
end |
15347 | 34 |
|
39494
bf7dd4902321
rename "Metis_Clauses" to "Metis_Translate" for consistency with "Sledgehammer_Translate"
blanchet
parents:
39355
diff
changeset
|
35 |
structure Metis_Translate : METIS_TRANSLATE = |
15347 | 36 |
struct |
37 |
||
43092
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
38 |
open ATP_Problem |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43003
diff
changeset
|
39 |
open ATP_Translate |
15347 | 40 |
|
43094 | 41 |
val metis_equal = "=" |
42 |
val metis_predicator = "{}" |
|
44492
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
43 |
val metis_app_op = Metis_Name.toString Metis_Term.appName |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
44 |
val metis_systematic_type_tag = |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
45 |
Metis_Name.toString Metis_Term.hasTypeFunctionName |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
46 |
val metis_ad_hoc_type_tag = "**" |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43003
diff
changeset
|
47 |
val metis_generated_var_prefix = "_" |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
48 |
|
43231
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
blanchet
parents:
43224
diff
changeset
|
49 |
val trace = Attrib.setup_config_bool @{binding metis_trace} (K false) |
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
blanchet
parents:
43224
diff
changeset
|
50 |
val verbose = Attrib.setup_config_bool @{binding metis_verbose} (K true) |
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
blanchet
parents:
43224
diff
changeset
|
51 |
|
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
blanchet
parents:
43224
diff
changeset
|
52 |
fun trace_msg ctxt msg = if Config.get ctxt trace then tracing (msg ()) else () |
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
blanchet
parents:
43224
diff
changeset
|
53 |
fun verbose_warning ctxt msg = |
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
blanchet
parents:
43224
diff
changeset
|
54 |
if Config.get ctxt verbose then warning ("Metis: " ^ msg) else () |
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
blanchet
parents:
43224
diff
changeset
|
55 |
|
43094 | 56 |
val metis_name_table = |
44492
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
57 |
[((tptp_equal, 2), (K metis_equal, false)), |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
58 |
((tptp_old_equal, 2), (K metis_equal, false)), |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
59 |
((prefixed_predicator_name, 1), (K metis_predicator, false)), |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
60 |
((prefixed_app_op_name, 2), (K metis_app_op, false)), |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
61 |
((prefixed_type_tag_name, 2), |
44768 | 62 |
(fn Tags (_, All_Types) => metis_systematic_type_tag |
44492
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
63 |
| _ => metis_ad_hoc_type_tag, true))] |
43094 | 64 |
|
39896
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
65 |
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
|
66 |
old_skolem_const_prefix ^ Long_Name.separator ^ |
41491 | 67 |
(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
|
68 |
|
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
let |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
72 |
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
|
73 |
(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
|
74 |
let |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
75 |
val (old_skolems, s) = |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
76 |
if i = ~1 then |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
77 |
(old_skolems, @{const_name undefined}) |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
78 |
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
|
79 |
s :: _ => (old_skolems, s) |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
80 |
| [] => |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
81 |
let |
39896
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
82 |
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
|
83 |
(length (Term.add_tvarsT T [])) |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
84 |
in ((s, t) :: old_skolems, s) end |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
85 |
in (old_skolems, Const (s, T)) end |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
86 |
| aux old_skolems (t1 $ t2) = |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
87 |
let |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
88 |
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
|
89 |
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
|
90 |
in (old_skolems, t1 $ t2) end |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
91 |
| aux old_skolems (Abs (s, T, t')) = |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
92 |
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
|
93 |
(old_skolems, Abs (s, T, t')) |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
94 |
end |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
95 |
| aux old_skolems t = (old_skolems, t) |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
96 |
in aux old_skolems t end |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
97 |
else |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
98 |
(old_skolems, t) |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
99 |
|
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
100 |
fun reveal_old_skolem_terms old_skolems = |
37632 | 101 |
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
|
102 |
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
|
103 |
AList.lookup (op =) old_skolems s |> the |
43826
2b094d17f432
fix subtle type inference bug in Metis -- different occurrences of the same Skolem might need to be typed differently, using paramify_vars overconstraints the typing problem
blanchet
parents:
43626
diff
changeset
|
104 |
|> map_types (map_type_tvar (K dummyT)) |
37632 | 105 |
else |
106 |
t |
|
107 |
| t => t) |
|
108 |
||
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
109 |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
110 |
(* ------------------------------------------------------------------------- *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
111 |
(* 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
|
112 |
(* ------------------------------------------------------------------------- *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
113 |
|
43159
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents:
43132
diff
changeset
|
114 |
datatype isa_thm = |
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents:
43132
diff
changeset
|
115 |
Isa_Reflexive_or_Trivial | |
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents:
43132
diff
changeset
|
116 |
Isa_Raw of thm |
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents:
43132
diff
changeset
|
117 |
|
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents:
43132
diff
changeset
|
118 |
val proxy_defs = map (fst o snd o snd) proxy_table |
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents:
43132
diff
changeset
|
119 |
val prepare_helper = |
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents:
43132
diff
changeset
|
120 |
Meson.make_meta_clause #> rewrite_rule (map safe_mk_meta_eq proxy_defs) |
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents:
43132
diff
changeset
|
121 |
|
44492
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
122 |
fun metis_term_from_atp type_enc (ATerm (s, tms)) = |
43094 | 123 |
if is_tptp_variable s then |
43268
c0eaa8b9bff5
removed yet another hack in "make_metis" script -- respect opacity of "Metis_Name.name"
blanchet
parents:
43259
diff
changeset
|
124 |
Metis_Term.Var (Metis_Name.fromString s) |
43094 | 125 |
else |
44492
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
126 |
(case AList.lookup (op =) metis_name_table (s, length tms) of |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
127 |
SOME (f, swap) => (f type_enc, swap) |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
128 |
| NONE => (s, false)) |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
129 |
|> (fn (s, swap) => |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
130 |
Metis_Term.Fn (Metis_Name.fromString s, |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
131 |
tms |> map (metis_term_from_atp type_enc) |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
132 |
|> swap ? rev)) |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
133 |
fun metis_atom_from_atp type_enc (AAtom tm) = |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
134 |
(case metis_term_from_atp type_enc tm of |
43104
81d1b15aa0ae
use ":" for type information (looks good in Metis's output) and handle it in new path finder
blanchet
parents:
43103
diff
changeset
|
135 |
Metis_Term.Fn x => x |
81d1b15aa0ae
use ":" for type information (looks good in Metis's output) and handle it in new path finder
blanchet
parents:
43103
diff
changeset
|
136 |
| _ => raise Fail "non CNF -- expected function") |
44492
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
137 |
| metis_atom_from_atp _ _ = raise Fail "not CNF -- expected atom" |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
138 |
fun metis_literal_from_atp type_enc (AConn (ANot, [phi])) = |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
139 |
(false, metis_atom_from_atp type_enc phi) |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
140 |
| metis_literal_from_atp type_enc phi = |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
141 |
(true, metis_atom_from_atp type_enc phi) |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
142 |
fun metis_literals_from_atp type_enc (AConn (AOr, phis)) = |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
143 |
maps (metis_literals_from_atp type_enc) phis |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
144 |
| metis_literals_from_atp type_enc phi = [metis_literal_from_atp type_enc phi] |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
145 |
fun metis_axiom_from_atp type_enc clauses (Formula (ident, _, phi, _, _)) = |
43173 | 146 |
let |
147 |
fun some isa = |
|
44492
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
148 |
SOME (phi |> metis_literals_from_atp type_enc |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
149 |
|> Metis_LiteralSet.fromList |
43173 | 150 |
|> Metis_Thm.axiom, isa) |
151 |
in |
|
152 |
if ident = type_tag_idempotence_helper_name orelse |
|
44396
66b9b3fcd608
started cleaning up polymorphic monotonicity-based encodings, based on discussions with Nick Smallbone
blanchet
parents:
44394
diff
changeset
|
153 |
String.isPrefix tags_sym_formula_prefix ident then |
43173 | 154 |
Isa_Reflexive_or_Trivial |> some |
43295
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
155 |
else if String.isPrefix conjecture_prefix ident then |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
156 |
NONE |
43173 | 157 |
else if String.isPrefix helper_prefix ident then |
43194 | 158 |
case (String.isSuffix typed_helper_suffix ident, |
159 |
space_explode "_" ident) of |
|
160 |
(needs_fairly_sound, _ :: const :: j :: _) => |
|
161 |
nth ((const, needs_fairly_sound) |
|
162 |
|> AList.lookup (op =) helper_table |> the) |
|
43173 | 163 |
(the (Int.fromString j) - 1) |
43194 | 164 |
|> prepare_helper |
165 |
|> Isa_Raw |> some |
|
43173 | 166 |
| _ => raise Fail ("malformed helper identifier " ^ quote ident) |
43295
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
167 |
else case try (unprefix fact_prefix) ident of |
43173 | 168 |
SOME s => |
43295
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
169 |
let |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
170 |
val j = s |> space_explode "_" |> List.last |> Int.fromString |> the |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
171 |
in Meson.make_meta_clause (snd (nth clauses j)) |> Isa_Raw |> some end |
43173 | 172 |
| NONE => TrueI |> Isa_Raw |> some |
173 |
end |
|
44492
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
174 |
| metis_axiom_from_atp _ _ _ = raise Fail "not CNF -- expected formula" |
43092
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
175 |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
176 |
(* Function to generate metis clauses, including comb and type clauses *) |
43626
a867ebb12209
renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents:
43572
diff
changeset
|
177 |
fun prepare_metis_problem ctxt type_enc conj_clauses fact_clauses = |
43212 | 178 |
let |
43295
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
179 |
val (conj_clauses, fact_clauses) = |
43626
a867ebb12209
renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents:
43572
diff
changeset
|
180 |
if polymorphism_of_type_enc type_enc = Polymorphic then |
43295
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
181 |
(conj_clauses, fact_clauses) |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
182 |
else |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
183 |
conj_clauses @ fact_clauses |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
184 |
|> map (pair 0) |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
185 |
|> rpair ctxt |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
186 |
|-> Monomorph.monomorph atp_schematic_consts_of |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
187 |
|> fst |> chop (length conj_clauses) |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
188 |
|> pairself (maps (map (zero_var_indexes o snd))) |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
189 |
val num_conjs = length conj_clauses |
43212 | 190 |
val clauses = |
43295
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
191 |
map2 (fn j => pair (Int.toString j, Local)) |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
192 |
(0 upto num_conjs - 1) conj_clauses @ |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
193 |
(* "General" below isn't quite correct; the fact could be local. *) |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
194 |
map2 (fn j => pair (Int.toString (num_conjs + j), General)) |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
195 |
(0 upto length fact_clauses - 1) fact_clauses |
43212 | 196 |
val (old_skolems, props) = |
43295
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
197 |
fold_rev (fn (name, th) => fn (old_skolems, props) => |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
198 |
th |> prop_of |> Logic.strip_imp_concl |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
199 |
|> conceal_old_skolem_terms (length clauses) old_skolems |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
200 |
||> (fn prop => (name, prop) :: props)) |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
201 |
clauses ([], []) |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
202 |
(* |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
203 |
val _ = |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
204 |
tracing ("PROPS:\n" ^ cat_lines (map (Syntax.string_of_term ctxt) props)) |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
205 |
*) |
43212 | 206 |
val (atp_problem, _, _, _, _, _, sym_tab) = |
44397
06375952f1fa
cleaner handling of polymorphic monotonicity inference
blanchet
parents:
44396
diff
changeset
|
207 |
prepare_atp_problem ctxt CNF Hypothesis Axiom type_enc false no_lambdasN |
06375952f1fa
cleaner handling of polymorphic monotonicity inference
blanchet
parents:
44396
diff
changeset
|
208 |
false false [] @{prop False} props |
43295
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
209 |
(* |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
210 |
val _ = tracing ("ATP PROBLEM: " ^ |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
211 |
cat_lines (tptp_lines_for_atp_problem CNF atp_problem)) |
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
blanchet
parents:
43268
diff
changeset
|
212 |
*) |
44409
b529d9501d64
prefer the lighter, slightly unsound monotonicity-based encodings for Metis
blanchet
parents:
44397
diff
changeset
|
213 |
(* "rev" is for compatibility. *) |
43212 | 214 |
val axioms = |
44492
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
215 |
atp_problem |
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents:
44411
diff
changeset
|
216 |
|> maps (map_filter (metis_axiom_from_atp type_enc clauses) o snd) |> rev |
43212 | 217 |
in (sym_tab, axioms, old_skolems) end |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
218 |
|
15347 | 219 |
end; |