| author | blanchet | 
| Thu, 10 Jul 2014 18:08:21 +0200 | |
| changeset 57541 | 147e3f1e0459 | 
| parent 57408 | 39b3562e9edc | 
| child 59058 | a78612c67ec0 | 
| permissions | -rw-r--r-- | 
| 46320 | 1 | (* Title: HOL/Tools/Metis/metis_generate.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: 
39494diff
changeset | 3 | Author: Kong W. Susanto, Cambridge University Computer Laboratory | 
| 
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
 blanchet parents: 
39494diff
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: 
36378diff
changeset | 5 | Author: Jasmin Blanchette, TU Muenchen | 
| 15347 | 6 | |
| 39494 
bf7dd4902321
rename "Metis_Clauses" to "Metis_Translate" for consistency with "Sledgehammer_Translate"
 blanchet parents: 
39355diff
changeset | 7 | Translation of HOL to FOL for Metis. | 
| 15347 | 8 | *) | 
| 9 | ||
| 46320 | 10 | signature METIS_GENERATE = | 
| 24310 | 11 | sig | 
| 46320 | 12 | type type_enc = ATP_Problem_Generate.type_enc | 
| 44411 
e3629929b171
change Metis's default settings if type information axioms are generated
 blanchet parents: 
44409diff
changeset | 13 | |
| 43159 
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
 blanchet parents: 
43132diff
changeset | 14 | datatype isa_thm = | 
| 
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
 blanchet parents: 
43132diff
changeset | 15 | Isa_Reflexive_or_Trivial | | 
| 45511 
9b0f8ca4388e
continued implementation of lambda-lifting in Metis
 blanchet parents: 
45510diff
changeset | 16 | Isa_Lambda_Lifted | | 
| 43159 
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
 blanchet parents: 
43132diff
changeset | 17 | Isa_Raw of thm | 
| 
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
 blanchet parents: 
43132diff
changeset | 18 | |
| 43094 | 19 | val metis_equal : string | 
| 20 | val metis_predicator : string | |
| 21 | 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: 
44411diff
changeset | 22 | 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: 
44411diff
changeset | 23 | val metis_ad_hoc_type_tag : string | 
| 42098 
f978caf60bbe
more robust handling of variables in new Skolemizer
 blanchet parents: 
41491diff
changeset | 24 | val metis_generated_var_prefix : string | 
| 43231 
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
 blanchet parents: 
43224diff
changeset | 25 | val trace : bool Config.T | 
| 
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
 blanchet parents: 
43224diff
changeset | 26 | val verbose : bool Config.T | 
| 
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
 blanchet parents: 
43224diff
changeset | 27 | val trace_msg : Proof.context -> (unit -> string) -> unit | 
| 
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
 blanchet parents: 
43224diff
changeset | 28 | 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: 
44411diff
changeset | 29 | 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: 
39720diff
changeset | 30 | val reveal_old_skolem_terms : (string * term) list -> term -> term | 
| 45569 
eb30a5490543
wrap lambdas earlier, to get more control over beta/eta
 blanchet parents: 
45565diff
changeset | 31 | val reveal_lam_lifted : (string * term) list -> term -> term | 
| 57263 | 32 | val generate_metis_problem : Proof.context -> type_enc -> string -> thm list -> thm list -> | 
| 33 | int Symtab.table * (Metis_Thm.thm * isa_thm) list * (unit -> (string * int) list) | |
| 34 | * ((string * term) list * (string * term) list) | |
| 24310 | 35 | end | 
| 15347 | 36 | |
| 46320 | 37 | structure Metis_Generate : METIS_GENERATE = | 
| 15347 | 38 | struct | 
| 39 | ||
| 43092 
93ec303e1917
more work on new metis that exploits the powerful new type encodings
 blanchet parents: 
43091diff
changeset | 40 | open ATP_Problem | 
| 46320 | 41 | open ATP_Problem_Generate | 
| 15347 | 42 | |
| 43094 | 43 | val metis_equal = "=" | 
| 44 | 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: 
44411diff
changeset | 45 | 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: 
44411diff
changeset | 46 | 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: 
44411diff
changeset | 47 | 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: 
44411diff
changeset | 48 | val metis_ad_hoc_type_tag = "**" | 
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: 
43003diff
changeset | 49 | val metis_generated_var_prefix = "_" | 
| 17150 
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
 quigley parents: 
16976diff
changeset | 50 | |
| 43231 
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
 blanchet parents: 
43224diff
changeset | 51 | val trace = Attrib.setup_config_bool @{binding metis_trace} (K false)
 | 
| 
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
 blanchet parents: 
43224diff
changeset | 52 | val verbose = Attrib.setup_config_bool @{binding metis_verbose} (K true)
 | 
| 
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
 blanchet parents: 
43224diff
changeset | 53 | |
| 
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
 blanchet parents: 
43224diff
changeset | 54 | 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: 
43224diff
changeset | 55 | fun verbose_warning ctxt msg = | 
| 
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
 blanchet parents: 
43224diff
changeset | 56 |   if Config.get ctxt verbose then warning ("Metis: " ^ msg) else ()
 | 
| 
69f22ac07395
nicely thread monomorphism verbosity in Metis and Sledgehammer
 blanchet parents: 
43224diff
changeset | 57 | |
| 43094 | 58 | 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: 
44411diff
changeset | 59 | [((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: 
44411diff
changeset | 60 | ((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: 
44411diff
changeset | 61 | ((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: 
44411diff
changeset | 62 | ((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: 
44411diff
changeset | 63 | ((prefixed_type_tag_name, 2), | 
| 44782 | 64 | (fn type_enc => | 
| 65 | if level_of_type_enc type_enc = All_Types then metis_systematic_type_tag | |
| 66 | else metis_ad_hoc_type_tag, true))] | |
| 43094 | 67 | |
| 39896 
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
 blanchet parents: 
39890diff
changeset | 68 | 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: 
39890diff
changeset | 69 | old_skolem_const_prefix ^ Long_Name.separator ^ | 
| 41491 | 70 | (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: 
37575diff
changeset | 71 | |
| 39886 
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
 blanchet parents: 
39720diff
changeset | 72 | 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: 
39946diff
changeset | 73 |   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: 
37575diff
changeset | 74 | let | 
| 39886 
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
 blanchet parents: 
39720diff
changeset | 75 | fun aux old_skolems | 
| 39953 
aa54f347e5e2
hide uninteresting MESON/Metis constants and facts and remove "meson_" prefix to (now hidden) fact names
 blanchet parents: 
39946diff
changeset | 76 |              (t as (Const (@{const_name Meson.skolem}, Type (_, [_, T])) $ _)) =
 | 
| 37577 
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
 blanchet parents: 
37575diff
changeset | 77 | let | 
| 39886 
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
 blanchet parents: 
39720diff
changeset | 78 | val (old_skolems, s) = | 
| 37577 
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
 blanchet parents: 
37575diff
changeset | 79 | if i = ~1 then | 
| 39886 
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
 blanchet parents: 
39720diff
changeset | 80 |                 (old_skolems, @{const_name undefined})
 | 
| 57408 | 81 | else | 
| 82 | (case AList.find (op aconv) old_skolems t of | |
| 83 | s :: _ => (old_skolems, s) | |
| 84 | | [] => | |
| 85 | let | |
| 86 | val s = | |
| 87 | old_skolem_const_name i (length old_skolems) (length (Term.add_tvarsT T [])) | |
| 88 | in ((s, t) :: old_skolems, s) end) | |
| 39886 
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
 blanchet parents: 
39720diff
changeset | 89 | in (old_skolems, Const (s, T)) end | 
| 
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
 blanchet parents: 
39720diff
changeset | 90 | | aux old_skolems (t1 $ t2) = | 
| 37577 
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
 blanchet parents: 
37575diff
changeset | 91 | let | 
| 39886 
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
 blanchet parents: 
39720diff
changeset | 92 | val (old_skolems, t1) = aux old_skolems t1 | 
| 
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
 blanchet parents: 
39720diff
changeset | 93 | val (old_skolems, t2) = aux old_skolems t2 | 
| 
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
 blanchet parents: 
39720diff
changeset | 94 | in (old_skolems, t1 $ t2) end | 
| 
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
 blanchet parents: 
39720diff
changeset | 95 | | aux old_skolems (Abs (s, T, t')) = | 
| 
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
 blanchet parents: 
39720diff
changeset | 96 | let val (old_skolems, t') = aux old_skolems t' in | 
| 
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
 blanchet parents: 
39720diff
changeset | 97 | (old_skolems, Abs (s, T, t')) | 
| 37577 
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
 blanchet parents: 
37575diff
changeset | 98 | end | 
| 39886 
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
 blanchet parents: 
39720diff
changeset | 99 | | aux old_skolems t = (old_skolems, t) | 
| 
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
 blanchet parents: 
39720diff
changeset | 100 | in aux old_skolems t end | 
| 37577 
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
 blanchet parents: 
37575diff
changeset | 101 | else | 
| 39886 
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
 blanchet parents: 
39720diff
changeset | 102 | (old_skolems, t) | 
| 37577 
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
 blanchet parents: 
37575diff
changeset | 103 | |
| 39886 
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
 blanchet parents: 
39720diff
changeset | 104 | fun reveal_old_skolem_terms old_skolems = | 
| 37632 | 105 | map_aterms (fn t as Const (s, _) => | 
| 57408 | 106 | if String.isPrefix old_skolem_const_prefix s then | 
| 107 | AList.lookup (op =) old_skolems s |> the | |
| 108 | |> map_types (map_type_tvar (K dummyT)) | |
| 109 | else | |
| 110 | t | |
| 111 | | t => t) | |
| 37632 | 112 | |
| 52150 
41c885784e04
handle lambda-lifted problems in Isar construction code
 blanchet parents: 
52031diff
changeset | 113 | fun reveal_lam_lifted lifted = | 
| 45511 
9b0f8ca4388e
continued implementation of lambda-lifting in Metis
 blanchet parents: 
45510diff
changeset | 114 | map_aterms (fn t as Const (s, _) => | 
| 57408 | 115 | if String.isPrefix lam_lifted_prefix s then | 
| 116 | (case AList.lookup (op =) lifted s of | |
| 117 | SOME t => | |
| 118 |           Const (@{const_name Metis.lambda}, dummyT)
 | |
| 119 | $ map_types (map_type_tvar (K dummyT)) (reveal_lam_lifted lifted t) | |
| 120 | | NONE => t) | |
| 121 | else | |
| 122 | t | |
| 123 | | t => t) | |
| 45508 | 124 | |
| 37577 
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
 blanchet parents: 
37575diff
changeset | 125 | |
| 39497 
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
 blanchet parents: 
39494diff
changeset | 126 | (* ------------------------------------------------------------------------- *) | 
| 
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
 blanchet parents: 
39494diff
changeset | 127 | (* Logic maps manage the interface between HOL and first-order logic. *) | 
| 
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
 blanchet parents: 
39494diff
changeset | 128 | (* ------------------------------------------------------------------------- *) | 
| 
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
 blanchet parents: 
39494diff
changeset | 129 | |
| 43159 
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
 blanchet parents: 
43132diff
changeset | 130 | datatype isa_thm = | 
| 
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
 blanchet parents: 
43132diff
changeset | 131 | Isa_Reflexive_or_Trivial | | 
| 45511 
9b0f8ca4388e
continued implementation of lambda-lifting in Metis
 blanchet parents: 
45510diff
changeset | 132 | Isa_Lambda_Lifted | | 
| 43159 
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
 blanchet parents: 
43132diff
changeset | 133 | Isa_Raw of thm | 
| 
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
 blanchet parents: 
43132diff
changeset | 134 | |
| 
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
 blanchet parents: 
43132diff
changeset | 135 | val proxy_defs = map (fst o snd o snd) proxy_table | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53479diff
changeset | 136 | fun prepare_helper ctxt = | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53479diff
changeset | 137 | Meson.make_meta_clause #> rewrite_rule ctxt (map safe_mk_meta_eq proxy_defs) | 
| 43159 
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
 blanchet parents: 
43132diff
changeset | 138 | |
| 52031 
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
 blanchet parents: 
51998diff
changeset | 139 | fun metis_term_of_atp type_enc (ATerm ((s, []), tms)) = | 
| 43094 | 140 | if is_tptp_variable s then | 
| 43268 
c0eaa8b9bff5
removed yet another hack in "make_metis" script -- respect opacity of "Metis_Name.name"
 blanchet parents: 
43259diff
changeset | 141 | Metis_Term.Var (Metis_Name.fromString s) | 
| 43094 | 142 | else | 
| 44492 
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
 blanchet parents: 
44411diff
changeset | 143 | (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: 
44411diff
changeset | 144 | 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: 
44411diff
changeset | 145 | | NONE => (s, false)) | 
| 
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
 blanchet parents: 
44411diff
changeset | 146 | |> (fn (s, swap) => | 
| 
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
 blanchet parents: 
44411diff
changeset | 147 | Metis_Term.Fn (Metis_Name.fromString s, | 
| 52031 
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
 blanchet parents: 
51998diff
changeset | 148 | tms |> map (metis_term_of_atp type_enc) | 
| 44492 
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
 blanchet parents: 
44411diff
changeset | 149 | |> swap ? rev)) | 
| 52031 
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
 blanchet parents: 
51998diff
changeset | 150 | fun metis_atom_of_atp type_enc (AAtom tm) = | 
| 
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
 blanchet parents: 
51998diff
changeset | 151 | (case metis_term_of_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: 
43103diff
changeset | 152 | 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: 
43103diff
changeset | 153 | | _ => raise Fail "non CNF -- expected function") | 
| 52031 
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
 blanchet parents: 
51998diff
changeset | 154 | | metis_atom_of_atp _ _ = raise Fail "not CNF -- expected atom" | 
| 
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
 blanchet parents: 
51998diff
changeset | 155 | fun metis_literal_of_atp type_enc (AConn (ANot, [phi])) = | 
| 
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
 blanchet parents: 
51998diff
changeset | 156 | (false, metis_atom_of_atp type_enc phi) | 
| 
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
 blanchet parents: 
51998diff
changeset | 157 | | metis_literal_of_atp type_enc phi = (true, metis_atom_of_atp type_enc phi) | 
| 
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
 blanchet parents: 
51998diff
changeset | 158 | fun metis_literals_of_atp type_enc (AConn (AOr, phis)) = | 
| 
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
 blanchet parents: 
51998diff
changeset | 159 | maps (metis_literals_of_atp type_enc) phis | 
| 
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
 blanchet parents: 
51998diff
changeset | 160 | | metis_literals_of_atp type_enc phi = [metis_literal_of_atp type_enc phi] | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53479diff
changeset | 161 | fun metis_axiom_of_atp ctxt type_enc clauses (Formula ((ident, _), _, phi, _, _)) = | 
| 43173 | 162 | let | 
| 163 | fun some isa = | |
| 52031 
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
 blanchet parents: 
51998diff
changeset | 164 | SOME (phi |> metis_literals_of_atp type_enc | 
| 44492 
a330c0608da8
avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
 blanchet parents: 
44411diff
changeset | 165 | |> Metis_LiteralSet.fromList | 
| 43173 | 166 | |> Metis_Thm.axiom, isa) | 
| 167 | in | |
| 47046 
62ca06cc5a99
remove two options that were found to play hardly any role
 blanchet parents: 
47039diff
changeset | 168 | if String.isPrefix tags_sym_formula_prefix ident then | 
| 43173 | 169 | 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: 
43268diff
changeset | 170 | 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: 
43268diff
changeset | 171 | NONE | 
| 43173 | 172 | else if String.isPrefix helper_prefix ident then | 
| 57408 | 173 | (case (String.isSuffix typed_helper_suffix ident, space_explode "_" ident) of | 
| 43194 | 174 | (needs_fairly_sound, _ :: const :: j :: _) => | 
| 57263 | 175 | nth (AList.lookup (op =) helper_table (const, needs_fairly_sound) |> the) | 
| 176 | (the (Int.fromString j) - 1) | |
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53479diff
changeset | 177 | |> snd |> prepare_helper ctxt | 
| 43194 | 178 | |> Isa_Raw |> some | 
| 57408 | 179 |         | _ => raise Fail ("malformed helper identifier " ^ quote ident))
 | 
| 180 | else | |
| 181 | (case try (unprefix fact_prefix) ident of | |
| 182 | SOME s => | |
| 183 | let val s = s |> space_explode "_" |> tl |> space_implode "_" in | |
| 184 | (case Int.fromString s of | |
| 185 | SOME j => Meson.make_meta_clause (snd (nth clauses j)) |> Isa_Raw |> some | |
| 186 | | NONE => | |
| 187 | if String.isPrefix lam_fact_prefix (unascii_of s) then Isa_Lambda_Lifted |> some | |
| 188 |               else raise Fail ("malformed fact identifier " ^ quote ident))
 | |
| 189 | end | |
| 190 | | NONE => some (Isa_Raw TrueI)) | |
| 43173 | 191 | end | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53479diff
changeset | 192 | | metis_axiom_of_atp _ _ _ _ = raise Fail "not CNF -- expected formula" | 
| 43092 
93ec303e1917
more work on new metis that exploits the powerful new type encodings
 blanchet parents: 
43091diff
changeset | 193 | |
| 57263 | 194 | fun eliminate_lam_wrappers (Const (@{const_name Metis.lambda}, _) $ t) = eliminate_lam_wrappers t
 | 
| 195 | | eliminate_lam_wrappers (t $ u) = eliminate_lam_wrappers t $ eliminate_lam_wrappers u | |
| 196 | | eliminate_lam_wrappers (Abs (s, T, t)) = Abs (s, T, eliminate_lam_wrappers t) | |
| 45569 
eb30a5490543
wrap lambdas earlier, to get more control over beta/eta
 blanchet parents: 
45565diff
changeset | 197 | | eliminate_lam_wrappers t = t | 
| 
eb30a5490543
wrap lambdas earlier, to get more control over beta/eta
 blanchet parents: 
45565diff
changeset | 198 | |
| 39497 
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
 blanchet parents: 
39494diff
changeset | 199 | (* Function to generate metis clauses, including comb and type clauses *) | 
| 57263 | 200 | fun generate_metis_problem ctxt type_enc lam_trans conj_clauses fact_clauses = | 
| 43212 | 201 | 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: 
43268diff
changeset | 202 | val (conj_clauses, fact_clauses) = | 
| 48131 | 203 | if is_type_enc_polymorphic type_enc 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: 
43268diff
changeset | 204 | (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: 
43268diff
changeset | 205 | 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: 
43268diff
changeset | 206 | 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: 
43268diff
changeset | 207 | |> map (pair 0) | 
| 53479 | 208 | |> Monomorph.monomorph atp_schematic_consts_of ctxt | 
| 209 | |> chop (length conj_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: 
43268diff
changeset | 210 | |> 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: 
43268diff
changeset | 211 | val num_conjs = length conj_clauses | 
| 47039 
1b36a05a070d
added "metis_advisory_simp" option to orient as many equations as possible in Metis the right way (cf. "More SPASS with Isabelle")
 blanchet parents: 
46409diff
changeset | 212 | (* Pretend every clause is a "simp" rule, to guide the term ordering. *) | 
| 43212 | 213 | val clauses = | 
| 57263 | 214 | map2 (fn j => pair (Int.toString j, (Local, Simp))) (0 upto num_conjs - 1) conj_clauses @ | 
| 47039 
1b36a05a070d
added "metis_advisory_simp" option to orient as many equations as possible in Metis the right way (cf. "More SPASS with Isabelle")
 blanchet parents: 
46409diff
changeset | 215 | map2 (fn j => pair (Int.toString (num_conjs + j), (Local, Simp))) | 
| 57263 | 216 | (0 upto length fact_clauses - 1) fact_clauses | 
| 43212 | 217 | 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: 
43268diff
changeset | 218 | fold_rev (fn (name, th) => fn (old_skolems, props) => | 
| 57263 | 219 | th |> prop_of |> Logic.strip_imp_concl | 
| 220 | |> conceal_old_skolem_terms (length clauses) old_skolems | |
| 221 | ||> (lam_trans = liftingN orelse lam_trans = lam_liftingN) ? eliminate_lam_wrappers | |
| 222 | ||> (fn prop => (name, prop) :: props)) | |
| 223 | 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: 
43268diff
changeset | 224 | (* | 
| 
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: 
43268diff
changeset | 225 | val _ = | 
| 45042 
89341b897412
better type reconstruction -- prevents ill-instantiations in proof replay
 blanchet parents: 
44782diff
changeset | 226 |       tracing ("PROPS:\n" ^
 | 
| 
89341b897412
better type reconstruction -- prevents ill-instantiations in proof replay
 blanchet parents: 
44782diff
changeset | 227 | cat_lines (map (Syntax.string_of_term ctxt o snd) 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: 
43268diff
changeset | 228 | *) | 
| 46365 | 229 | val lam_trans = if lam_trans = combsN then no_lamsN else lam_trans | 
| 57263 | 230 | val (atp_problem, _, lifted, sym_tab) = | 
| 231 | generate_atp_problem ctxt CNF Hypothesis type_enc Metis lam_trans false false false [] | |
| 232 |         @{prop False} props
 | |
| 45510 | 233 | (* | 
| 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: 
43268diff
changeset | 234 |     val _ = tracing ("ATP PROBLEM: " ^
 | 
| 51998 
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
 blanchet parents: 
51575diff
changeset | 235 | cat_lines (lines_of_atp_problem CNF atp_problem)) | 
| 45510 | 236 | *) | 
| 45508 | 237 | (* "rev" is for compatibility with existing proof scripts. *) | 
| 57263 | 238 | val axioms = atp_problem | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53479diff
changeset | 239 | |> maps (map_filter (metis_axiom_of_atp ctxt type_enc clauses) o snd) |> rev | 
| 47039 
1b36a05a070d
added "metis_advisory_simp" option to orient as many equations as possible in Metis the right way (cf. "More SPASS with Isabelle")
 blanchet parents: 
46409diff
changeset | 240 | fun ord_info () = atp_problem_term_order_info atp_problem | 
| 57408 | 241 | in | 
| 242 | (sym_tab, axioms, ord_info, (lifted, old_skolems)) | |
| 243 | end | |
| 39497 
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
 blanchet parents: 
39494diff
changeset | 244 | |
| 15347 | 245 | end; |