author | blanchet |
Mon, 02 Jun 2014 17:34:25 +0200 | |
changeset 57156 | 3546a67226ea |
parent 56981 | 3ef45ce002b5 |
child 57157 | 87b4d54b1fbe |
permissions | -rw-r--r-- |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
1 |
(* Title: HOL/Tools/SMT2/smt2_solver.ML |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
2 |
Author: Sascha Boehme, TU Muenchen |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
3 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
4 |
SMT solvers registry and SMT tactic. |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
5 |
*) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
6 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
7 |
signature SMT2_SOLVER = |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
8 |
sig |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
9 |
(*configuration*) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
10 |
datatype outcome = Unsat | Sat | Unknown |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
11 |
type solver_config = { |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
12 |
name: string, |
56090 | 13 |
class: Proof.context -> SMT2_Util.class, |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
14 |
avail: unit -> bool, |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
15 |
command: unit -> string list, |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
16 |
options: Proof.context -> string list, |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
17 |
default_max_relevant: int, |
56125 | 18 |
can_filter: bool, |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
19 |
outcome: string -> string list -> outcome * string list, |
56083
b5d1d9c60341
have Sledgehammer generate Isar proofs from Z3 proofs
blanchet
parents:
56082
diff
changeset
|
20 |
replay: (Proof.context -> SMT2_Translate.replay_data -> string list -> |
56125 | 21 |
((int * (int * thm)) list * Z3_New_Proof.z3_step list) * thm) option} |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
22 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
23 |
(*registry*) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
24 |
val add_solver: solver_config -> theory -> theory |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
25 |
val default_max_relevant: Proof.context -> string -> int |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
26 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
27 |
(*filter*) |
56104
fd6e132ee4fb
correctly reconstruct helper facts (e.g. 'nat_int') in Isar proofs
blanchet
parents:
56099
diff
changeset
|
28 |
val smt2_filter: Proof.context -> thm -> ('a * (int option * thm)) list -> int -> Time.time -> |
56128 | 29 |
{outcome: SMT2_Failure.failure option, rewrite_rules: thm list, conjecture_id: int, |
56981
3ef45ce002b5
honor original format of conjecture or hypotheses in Z3-to-Isar proofs
blanchet
parents:
56132
diff
changeset
|
30 |
prem_ids: int list, helper_ids: (int * thm) list, fact_ids: (int * ('a * thm)) list, |
56128 | 31 |
z3_proof: Z3_New_Proof.z3_step list} |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
32 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
33 |
(*tactic*) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
34 |
val smt2_tac: Proof.context -> thm list -> int -> tactic |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
35 |
val smt2_tac': Proof.context -> thm list -> int -> tactic |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
36 |
end |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
37 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
38 |
structure SMT2_Solver: SMT2_SOLVER = |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
39 |
struct |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
40 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
41 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
42 |
(* interface to external solvers *) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
43 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
44 |
local |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
45 |
|
56132
64eeda68e693
delayed construction of command (and of noncommercial check) + tuning
blanchet
parents:
56131
diff
changeset
|
46 |
fun make_command command options problem_path proof_path = |
64eeda68e693
delayed construction of command (and of noncommercial check) + tuning
blanchet
parents:
56131
diff
changeset
|
47 |
"(exec 2>&1;" :: map File.shell_quote (command () @ options) @ |
64eeda68e693
delayed construction of command (and of noncommercial check) + tuning
blanchet
parents:
56131
diff
changeset
|
48 |
[File.shell_path problem_path, ")", ">", File.shell_path proof_path] |
64eeda68e693
delayed construction of command (and of noncommercial check) + tuning
blanchet
parents:
56131
diff
changeset
|
49 |
|> space_implode " " |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
50 |
|
56132
64eeda68e693
delayed construction of command (and of noncommercial check) + tuning
blanchet
parents:
56131
diff
changeset
|
51 |
fun with_trace ctxt msg f x = |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
52 |
let val _ = SMT2_Config.trace_msg ctxt (fn () => msg) () |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
53 |
in f x end |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
54 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
55 |
fun run ctxt name mk_cmd input = |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
56 |
(case SMT2_Config.certificates_of ctxt of |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
57 |
NONE => |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
58 |
if not (SMT2_Config.is_available ctxt name) then |
56131 | 59 |
error ("The SMT solver " ^ quote name ^ " is not installed") |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
60 |
else if Config.get ctxt SMT2_Config.debug_files = "" then |
56132
64eeda68e693
delayed construction of command (and of noncommercial check) + tuning
blanchet
parents:
56131
diff
changeset
|
61 |
with_trace ctxt ("Invoking SMT solver " ^ quote name ^ " ...") (Cache_IO.run mk_cmd) input |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
62 |
else |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
63 |
let |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
64 |
val base_path = Path.explode (Config.get ctxt SMT2_Config.debug_files) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
65 |
val in_path = Path.ext "smt2_in" base_path |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
66 |
val out_path = Path.ext "smt2_out" base_path |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
67 |
in Cache_IO.raw_run mk_cmd input in_path out_path end |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
68 |
| SOME certs => |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
69 |
(case Cache_IO.lookup certs input of |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
70 |
(NONE, key) => |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
71 |
if Config.get ctxt SMT2_Config.read_only_certificates then |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
72 |
error ("Bad certificate cache: missing certificate") |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
73 |
else |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
74 |
Cache_IO.run_and_cache certs key mk_cmd input |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
75 |
| (SOME output, _) => |
56132
64eeda68e693
delayed construction of command (and of noncommercial check) + tuning
blanchet
parents:
56131
diff
changeset
|
76 |
with_trace ctxt ("Using cached certificate from " ^ |
64eeda68e693
delayed construction of command (and of noncommercial check) + tuning
blanchet
parents:
56131
diff
changeset
|
77 |
File.shell_path (Cache_IO.cache_path_of certs) ^ " ...") I output)) |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
78 |
|
56087 | 79 |
(* Z3 returns 1 if "get-model" or "get-model" fails *) |
80 |
val normal_return_codes = [0, 1] |
|
81 |
||
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
82 |
fun run_solver ctxt name mk_cmd input = |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
83 |
let |
56087 | 84 |
fun pretty tag ls = Pretty.string_of (Pretty.big_list tag (map Pretty.str ls)) |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
85 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
86 |
val _ = SMT2_Config.trace_msg ctxt (pretty "Problem:" o split_lines) input |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
87 |
|
56132
64eeda68e693
delayed construction of command (and of noncommercial check) + tuning
blanchet
parents:
56131
diff
changeset
|
88 |
val {redirected_output = res, output = err, return_code} = |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
89 |
SMT2_Config.with_timeout ctxt (run ctxt name mk_cmd) input |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
90 |
val _ = SMT2_Config.trace_msg ctxt (pretty "Solver:") err |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
91 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
92 |
val output = fst (take_suffix (equal "") res) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
93 |
val _ = SMT2_Config.trace_msg ctxt (pretty "Result:") output |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
94 |
|
56087 | 95 |
val _ = member (op =) normal_return_codes return_code orelse |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
96 |
raise SMT2_Failure.SMT (SMT2_Failure.Abnormal_Termination return_code) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
97 |
in output end |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
98 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
99 |
fun trace_assms ctxt = |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
100 |
SMT2_Config.trace_msg ctxt (Pretty.string_of o |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
101 |
Pretty.big_list "Assertions:" o map (Display.pretty_thm ctxt o snd)) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
102 |
|
56132
64eeda68e693
delayed construction of command (and of noncommercial check) + tuning
blanchet
parents:
56131
diff
changeset
|
103 |
fun trace_replay_data ({context = ctxt, typs, terms, ...} : SMT2_Translate.replay_data) = |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
104 |
let |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
105 |
fun pretty_eq n p = Pretty.block [Pretty.str n, Pretty.str " = ", p] |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
106 |
fun p_typ (n, T) = pretty_eq n (Syntax.pretty_typ ctxt T) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
107 |
fun p_term (n, t) = pretty_eq n (Syntax.pretty_term ctxt t) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
108 |
in |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
109 |
SMT2_Config.trace_msg ctxt (fn () => |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
110 |
Pretty.string_of (Pretty.big_list "Names:" [ |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
111 |
Pretty.big_list "sorts:" (map p_typ (Symtab.dest typs)), |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
112 |
Pretty.big_list "functions:" (map p_term (Symtab.dest terms))])) () |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
113 |
end |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
114 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
115 |
in |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
116 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
117 |
fun invoke name command ithms ctxt = |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
118 |
let |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
119 |
val options = SMT2_Config.solver_options_of ctxt |
56112 | 120 |
val comments = [space_implode " " options] |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
121 |
|
56132
64eeda68e693
delayed construction of command (and of noncommercial check) + tuning
blanchet
parents:
56131
diff
changeset
|
122 |
val (str, replay_data as {context = ctxt', ...}) = |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
123 |
ithms |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
124 |
|> tap (trace_assms ctxt) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
125 |
|> SMT2_Translate.translate ctxt comments |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
126 |
||> tap trace_replay_data |
56132
64eeda68e693
delayed construction of command (and of noncommercial check) + tuning
blanchet
parents:
56131
diff
changeset
|
127 |
in (run_solver ctxt' name (make_command command options) str, replay_data) end |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
128 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
129 |
end |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
130 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
131 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
132 |
(* configuration *) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
133 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
134 |
datatype outcome = Unsat | Sat | Unknown |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
135 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
136 |
type solver_config = { |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
137 |
name: string, |
56090 | 138 |
class: Proof.context -> SMT2_Util.class, |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
139 |
avail: unit -> bool, |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
140 |
command: unit -> string list, |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
141 |
options: Proof.context -> string list, |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
142 |
default_max_relevant: int, |
56125 | 143 |
can_filter: bool, |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
144 |
outcome: string -> string list -> outcome * string list, |
56083
b5d1d9c60341
have Sledgehammer generate Isar proofs from Z3 proofs
blanchet
parents:
56082
diff
changeset
|
145 |
replay: (Proof.context -> SMT2_Translate.replay_data -> string list -> |
56125 | 146 |
((int * (int * thm)) list * Z3_New_Proof.z3_step list) * thm) option} |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
147 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
148 |
|
56106 | 149 |
(* check well-sortedness *) |
150 |
||
151 |
val has_topsort = Term.exists_type (Term.exists_subtype (fn |
|
152 |
TFree (_, []) => true |
|
153 |
| TVar (_, []) => true |
|
154 |
| _ => false)) |
|
155 |
||
156 |
(* top sorts cause problems with atomization *) |
|
157 |
fun check_topsort ctxt thm = |
|
158 |
if has_topsort (Thm.prop_of thm) then (SMT2_Normalize.drop_fact_warning ctxt thm; TrueI) else thm |
|
159 |
||
160 |
||
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
161 |
(* registry *) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
162 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
163 |
type solver_info = { |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
164 |
command: unit -> string list, |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
165 |
default_max_relevant: int, |
56125 | 166 |
can_filter: bool, |
167 |
finish: Proof.context -> SMT2_Translate.replay_data -> string list -> |
|
168 |
((int * (int * thm)) list * Z3_New_Proof.z3_step list) * thm} |
|
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
169 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
170 |
structure Solvers = Generic_Data |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
171 |
( |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
172 |
type T = solver_info Symtab.table |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
173 |
val empty = Symtab.empty |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
174 |
val extend = I |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
175 |
fun merge data = Symtab.merge (K true) data |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
176 |
) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
177 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
178 |
local |
57156
3546a67226ea
removed counterexample parser (obsolete and useless in practice)
blanchet
parents:
56981
diff
changeset
|
179 |
fun finish outcome replay ocl outer_ctxt |
56132
64eeda68e693
delayed construction of command (and of noncommercial check) + tuning
blanchet
parents:
56131
diff
changeset
|
180 |
(replay_data as {context = ctxt, ...} : SMT2_Translate.replay_data) output = |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
181 |
(case outcome output of |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
182 |
(Unsat, ls) => |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
183 |
if not (Config.get ctxt SMT2_Config.oracle) andalso is_some replay |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
184 |
then the replay outer_ctxt replay_data ls |
56083
b5d1d9c60341
have Sledgehammer generate Isar proofs from Z3 proofs
blanchet
parents:
56082
diff
changeset
|
185 |
else (([], []), ocl ()) |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
186 |
| (result, ls) => |
57156
3546a67226ea
removed counterexample parser (obsolete and useless in practice)
blanchet
parents:
56981
diff
changeset
|
187 |
raise SMT2_Failure.SMT (SMT2_Failure.Counterexample { |
3546a67226ea
removed counterexample parser (obsolete and useless in practice)
blanchet
parents:
56981
diff
changeset
|
188 |
is_real_cex = (result = Sat), |
3546a67226ea
removed counterexample parser (obsolete and useless in practice)
blanchet
parents:
56981
diff
changeset
|
189 |
free_constraints = [], |
3546a67226ea
removed counterexample parser (obsolete and useless in practice)
blanchet
parents:
56981
diff
changeset
|
190 |
const_defs = []})) |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
191 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
192 |
val cfalse = Thm.cterm_of @{theory} (@{const Trueprop} $ @{const False}) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
193 |
in |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
194 |
|
56125 | 195 |
fun add_solver ({name, class, avail, command, options, default_max_relevant, can_filter, |
57156
3546a67226ea
removed counterexample parser (obsolete and useless in practice)
blanchet
parents:
56981
diff
changeset
|
196 |
outcome, replay} : solver_config) = |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
197 |
let |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
198 |
fun solver ocl = { |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
199 |
command = command, |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
200 |
default_max_relevant = default_max_relevant, |
56125 | 201 |
can_filter = can_filter, |
57156
3546a67226ea
removed counterexample parser (obsolete and useless in practice)
blanchet
parents:
56981
diff
changeset
|
202 |
finish = finish (outcome name) replay ocl} |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
203 |
|
56132
64eeda68e693
delayed construction of command (and of noncommercial check) + tuning
blanchet
parents:
56131
diff
changeset
|
204 |
val info = {name = name, class = class, avail = avail, options = options} |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
205 |
in |
56125 | 206 |
Thm.add_oracle (Binding.name name, K cfalse) #-> (fn (_, ocl) => |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
207 |
Context.theory_map (Solvers.map (Symtab.update_new (name, solver ocl)))) #> |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
208 |
Context.theory_map (SMT2_Config.add_solver info) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
209 |
end |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
210 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
211 |
end |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
212 |
|
56125 | 213 |
fun get_info ctxt name = the (Symtab.lookup (Solvers.get (Context.Proof ctxt)) name) |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
214 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
215 |
fun name_and_info_of ctxt = |
56132
64eeda68e693
delayed construction of command (and of noncommercial check) + tuning
blanchet
parents:
56131
diff
changeset
|
216 |
let val name = SMT2_Config.solver_of ctxt |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
217 |
in (name, get_info ctxt name) end |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
218 |
|
56106 | 219 |
fun apply_solver ctxt wthms0 = |
56082 | 220 |
let |
56106 | 221 |
val wthms = map (apsnd (check_topsort ctxt)) wthms0 |
56125 | 222 |
val (name, {command, finish, ...}) = name_and_info_of ctxt |
223 |
val (output, replay_data) = invoke name command (SMT2_Normalize.normalize ctxt wthms) ctxt |
|
56128 | 224 |
in (finish ctxt replay_data output, replay_data) end |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
225 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
226 |
val default_max_relevant = #default_max_relevant oo get_info |
56125 | 227 |
val can_filter = #can_filter o snd o name_and_info_of |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
228 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
229 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
230 |
(* filter *) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
231 |
|
56106 | 232 |
val no_id = ~1 |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
233 |
|
56104
fd6e132ee4fb
correctly reconstruct helper facts (e.g. 'nat_int') in Isar proofs
blanchet
parents:
56099
diff
changeset
|
234 |
fun smt2_filter ctxt goal xwfacts i time_limit = |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
235 |
let |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
236 |
val ctxt = |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
237 |
ctxt |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
238 |
|> Config.put SMT2_Config.oracle false |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
239 |
|> Config.put SMT2_Config.filter_only_facts true |
56082 | 240 |
|> Config.put SMT2_Config.timeout (Time.toReal time_limit) |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
241 |
|
56132
64eeda68e693
delayed construction of command (and of noncommercial check) + tuning
blanchet
parents:
56131
diff
changeset
|
242 |
val ({context = ctxt, prems, concl, ...}, _) = Subgoal.focus ctxt i goal |
56106 | 243 |
fun negate ct = Thm.dest_comb ct ||> Thm.apply @{cterm Not} |-> Thm.apply |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
244 |
val cprop = |
56082 | 245 |
(case try negate (Thm.rhs_of (SMT2_Normalize.atomize_conv ctxt concl)) of |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
246 |
SOME ct => ct |
56094 | 247 |
| NONE => raise SMT2_Failure.SMT (SMT2_Failure.Other_Failure "goal is not a HOL term")) |
56082 | 248 |
|
56106 | 249 |
val wconjecture = (NONE, Thm.assume cprop) |
250 |
val wprems = map (pair NONE) prems |
|
251 |
val wfacts = map snd xwfacts |
|
252 |
val wthms = wconjecture :: wprems @ wfacts |
|
253 |
val iwthms = map_index I wthms |
|
56082 | 254 |
|
56106 | 255 |
val conjecture_i = 0 |
56981
3ef45ce002b5
honor original format of conjecture or hypotheses in Z3-to-Isar proofs
blanchet
parents:
56132
diff
changeset
|
256 |
val prems_i = 1 |
3ef45ce002b5
honor original format of conjecture or hypotheses in Z3-to-Isar proofs
blanchet
parents:
56132
diff
changeset
|
257 |
val facts_i = prems_i + length wprems |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
258 |
in |
56106 | 259 |
wthms |
56082 | 260 |
|> apply_solver ctxt |
56128 | 261 |
|> (fn (((iidths0, z3_proof), _), {rewrite_rules, ...}) => |
56981
3ef45ce002b5
honor original format of conjecture or hypotheses in Z3-to-Isar proofs
blanchet
parents:
56132
diff
changeset
|
262 |
let |
3ef45ce002b5
honor original format of conjecture or hypotheses in Z3-to-Isar proofs
blanchet
parents:
56132
diff
changeset
|
263 |
val iidths = if can_filter ctxt then iidths0 else map (apsnd (apfst (K no_id))) iwthms |
3ef45ce002b5
honor original format of conjecture or hypotheses in Z3-to-Isar proofs
blanchet
parents:
56132
diff
changeset
|
264 |
fun id_of_index i = the_default no_id (Option.map fst (AList.lookup (op =) iidths i)) |
56104
fd6e132ee4fb
correctly reconstruct helper facts (e.g. 'nat_int') in Isar proofs
blanchet
parents:
56099
diff
changeset
|
265 |
in |
56128 | 266 |
{outcome = NONE, |
267 |
rewrite_rules = rewrite_rules, |
|
56981
3ef45ce002b5
honor original format of conjecture or hypotheses in Z3-to-Isar proofs
blanchet
parents:
56132
diff
changeset
|
268 |
conjecture_id = id_of_index conjecture_i, |
3ef45ce002b5
honor original format of conjecture or hypotheses in Z3-to-Isar proofs
blanchet
parents:
56132
diff
changeset
|
269 |
prem_ids = map id_of_index (prems_i upto facts_i - 1), |
56106 | 270 |
helper_ids = map_filter (try (fn (~1, idth) => idth)) iidths, |
271 |
fact_ids = map_filter (fn (i, (id, _)) => |
|
272 |
try (apsnd (apsnd snd o nth xwfacts)) (id, i - facts_i)) iidths, |
|
56104
fd6e132ee4fb
correctly reconstruct helper facts (e.g. 'nat_int') in Isar proofs
blanchet
parents:
56099
diff
changeset
|
273 |
z3_proof = z3_proof} |
fd6e132ee4fb
correctly reconstruct helper facts (e.g. 'nat_int') in Isar proofs
blanchet
parents:
56099
diff
changeset
|
274 |
end) |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
275 |
end |
56128 | 276 |
handle SMT2_Failure.SMT fail => {outcome = SOME fail, rewrite_rules = [], conjecture_id = no_id, |
56981
3ef45ce002b5
honor original format of conjecture or hypotheses in Z3-to-Isar proofs
blanchet
parents:
56132
diff
changeset
|
277 |
prem_ids = [], helper_ids = [], fact_ids = [], z3_proof = []} |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
278 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
279 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
280 |
(* SMT tactic *) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
281 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
282 |
local |
56106 | 283 |
fun trace_assumptions ctxt wfacts iidths = |
284 |
let val used = map_filter (try (snd o nth wfacts) o fst) iidths in |
|
56104
fd6e132ee4fb
correctly reconstruct helper facts (e.g. 'nat_int') in Isar proofs
blanchet
parents:
56099
diff
changeset
|
285 |
if Config.get ctxt SMT2_Config.trace_used_facts andalso length wfacts > 0 then |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
286 |
tracing (Pretty.string_of (Pretty.big_list "SMT used facts:" |
56106 | 287 |
(map (Display.pretty_thm ctxt) used))) |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
288 |
else () |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
289 |
end |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
290 |
|
56106 | 291 |
fun solve ctxt wfacts = |
292 |
wfacts |
|
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
293 |
|> apply_solver ctxt |
56128 | 294 |
|> fst |
56106 | 295 |
|>> apfst (trace_assumptions ctxt wfacts) |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
296 |
|> snd |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
297 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
298 |
fun str_of ctxt fail = |
56132
64eeda68e693
delayed construction of command (and of noncommercial check) + tuning
blanchet
parents:
56131
diff
changeset
|
299 |
"Solver " ^ SMT2_Config.solver_of ctxt ^ ": " ^ SMT2_Failure.string_of_failure ctxt fail |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
300 |
|
56106 | 301 |
fun safe_solve ctxt wfacts = SOME (solve ctxt wfacts) |
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
302 |
handle |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
303 |
SMT2_Failure.SMT (fail as SMT2_Failure.Counterexample _) => |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
304 |
(SMT2_Config.verbose_msg ctxt (str_of ctxt) fail; NONE) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
305 |
| SMT2_Failure.SMT (fail as SMT2_Failure.Time_Out) => |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
306 |
error ("SMT: Solver " ^ quote (SMT2_Config.solver_of ctxt) ^ ": " ^ |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
307 |
SMT2_Failure.string_of_failure ctxt fail ^ " (setting the " ^ |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
308 |
"configuration option " ^ quote (Config.name_of SMT2_Config.timeout) ^ " might help)") |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
309 |
| SMT2_Failure.SMT fail => error (str_of ctxt fail) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
310 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
311 |
fun resolve (SOME thm) = rtac thm 1 |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
312 |
| resolve NONE = no_tac |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
313 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
314 |
fun tac prove ctxt rules = |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
315 |
CONVERSION (SMT2_Normalize.atomize_conv ctxt) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
316 |
THEN' rtac @{thm ccontr} |
56106 | 317 |
THEN' SUBPROOF (fn {context = ctxt, prems, ...} => |
318 |
resolve (prove ctxt (map (pair NONE) (rules @ prems)))) ctxt |
|
56078
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
319 |
in |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
320 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
321 |
val smt2_tac = tac safe_solve |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
322 |
val smt2_tac' = tac (SOME oo solve) |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
323 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
324 |
end |
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
325 |
|
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents:
diff
changeset
|
326 |
end |