Skip to content

Commit ad3b9bf

Browse files
committed
Experiments with Z3.
1 parent 14a1e69 commit ad3b9bf

File tree

5 files changed

+532
-51
lines changed

5 files changed

+532
-51
lines changed

mmpp.pro

+4-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ SOURCES += \
149149
mm/setmm.cpp \
150150
test/test_wff.cpp \
151151
mm/mmutils.cpp \
152-
provers/tstp/tstp_parser.cpp
152+
provers/tstp/tstp_parser.cpp \
153+
provers/z3prover3.cpp
153154

154155
HEADERS += \
155156
pch.h \
@@ -204,7 +205,8 @@ HEADERS += \
204205
mm/setmm.h \
205206
test/test.h \
206207
mm/mmutils.h \
207-
provers/tstp/tstp_parser.h
208+
provers/tstp/tstp_parser.h \
209+
provers/z3prover3.h
208210

209211
DISTFILES += \
210212
README.md \

provers/tstp/tstp_parser.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <giolib/containers.h>
1111
#include <giolib/memory.h>
12+
#include <giolib/utils.h>
1213

1314
#include "parsing/parser.h"
1415
#include "utils/utils.h"
@@ -229,13 +230,6 @@ class Clause : public gio::virtual_enable_create<Clause> {
229230
std::set<std::shared_ptr<const Literal>, gio::star_less<std::shared_ptr<const Literal>>> literals;
230231
};
231232

232-
// See https://stackoverflow.com/q/53022868/807307
233-
template<typename T, typename = decltype(std::declval<T>().print_to(std::declval<std::ostream&>()))>
234-
std::ostream &operator<<(std::ostream &s, const T &t) {
235-
t.print_to(s);
236-
return s;
237-
}
238-
239233
class Inference {
240234
public:
241235
virtual ~Inference();

provers/z3prover2.cpp

+8-42
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,10 @@
77
#include "utils/utils.h"
88
#include "mm/toolbox.h"
99
#include "mm/setmm.h"
10+
#include "z3prover3.h"
1011

1112
//#define VERBOSE_Z3
1213

13-
unsigned expr_get_num_bound(const z3::expr &e) {
14-
assert(e.is_quantifier());
15-
unsigned num = Z3_get_quantifier_num_bound(e.ctx(), e);
16-
e.check_error();
17-
return num;
18-
}
19-
20-
z3::symbol expr_get_quantifier_bound_name(const z3::expr &e, unsigned i) {
21-
assert(e.is_quantifier());
22-
Z3_symbol sym = Z3_get_quantifier_bound_name(e.ctx(), e, i);
23-
e.check_error();
24-
return z3::symbol(e.ctx(), sym);
25-
}
26-
27-
z3::sort expr_get_quantifier_bound_sort(const z3::expr &e, unsigned i) {
28-
assert(e.is_quantifier());
29-
Z3_sort sort = Z3_get_quantifier_bound_sort(e.ctx(), e, i);
30-
e.check_error();
31-
return z3::sort(e.ctx(), sort);
32-
}
33-
34-
bool expr_is_quantifier_forall(const z3::expr &e) {
35-
assert(e.is_quantifier());
36-
Z3_bool is_forall = Z3_is_quantifier_forall(e.ctx(), e);
37-
e.check_error();
38-
return static_cast< bool >(is_forall);
39-
}
40-
41-
unsigned expr_get_var_index(const z3::expr &e) {
42-
assert(e.is_var());
43-
unsigned idx = Z3_get_index_value(e.ctx(), e);
44-
e.check_error();
45-
return idx;
46-
}
47-
4814
/* So far this procedure is not correct, because it does not address very important
4915
* mismatches between the two languages of Z3 and Metamath: in Z3 function applications,
5016
* variable binding is explicit and position-based, while in Metamath it is implicit
@@ -171,18 +137,18 @@ ParsingTree< SymTok, LabTok > expr_to_pt(const z3::expr &e, const LibraryToolbox
171137
throw "Cannot handle this formula";
172138
}
173139
} else if (e.is_quantifier()) {
174-
for (unsigned i = 0; i < expr_get_num_bound(e); i++) {
175-
bound_var_stack.push_back(expr_get_quantifier_bound_name(e, i));
140+
for (unsigned i = 0; i < gio::mmpp::z3prover::expr_get_num_bound(e); i++) {
141+
bound_var_stack.push_back(gio::mmpp::z3prover::expr_get_quantifier_bound_name(e, i));
176142
}
177143
ParsingTree< SymTok, LabTok > ret = expr_to_pt(e.body(), tb, bound_var_stack);
178144
ParsingTree< SymTok, LabTok > templ;
179-
if (expr_is_quantifier_forall(e)) {
145+
if (gio::mmpp::z3prover::expr_is_quantifier_forall(e)) {
180146
templ = tb.parse_sentence(tb.read_sentence("wff A. x ph"));
181147
} else {
182148
templ = tb.parse_sentence(tb.read_sentence("wff E. x ph"));
183149
}
184150
assert(templ.label != LabTok{});
185-
for (unsigned i = 0; i < expr_get_num_bound(e); i++) {
151+
for (unsigned i = 0; i < gio::mmpp::z3prover::expr_get_num_bound(e); i++) {
186152
SubstMap< SymTok, LabTok > subst;
187153
subst[tb.get_var_sym_to_lab(tb.get_symbol("x"))].type = tb.get_symbol("set");
188154
auto sym = tb.get_symbol(bound_var_stack.back().str());
@@ -196,7 +162,7 @@ ParsingTree< SymTok, LabTok > expr_to_pt(const z3::expr &e, const LibraryToolbox
196162
} else if (e.is_var()) {
197163
ParsingTree< SymTok, LabTok > ret;
198164
SubstMap< SymTok, LabTok > subst;
199-
unsigned idx = expr_get_var_index(e);
165+
unsigned idx = gio::mmpp::z3prover::expr_get_var_index(e);
200166
auto z3sym = bound_var_stack.at(bound_var_stack.size() - 1 - idx);
201167
ret = tb.parse_sentence(tb.read_sentence("class x"));
202168
assert(ret.label != LabTok{});
@@ -389,8 +355,8 @@ int test_z3_2_main(int argc, char *argv[]) {
389355
}
390356

391357
auto proof = s.proof();
392-
//std::cout << "Proof:" << std::endl << proof << std::endl;
393-
scan_proof(proof, tb);
358+
std::cout << "Proof:" << std::endl << proof << std::endl;
359+
//scan_proof(proof, tb);
394360

395361
std::cout << std::endl;
396362
} catch (z3::exception &e) {

0 commit comments

Comments
 (0)