2

I am playing around with z3 and other SMT solvers and want to examine the cases where other solvers like boolector triumph over z3 and vice-versa. For this purpose, I need a way to convert declarations and assertions to the SMT-LIB2 format that other SMT solvers can recognize.

For example, for this example

void print_as_smtlib2_string() {
    context c;
    expr x = c.int_const("x");
    expr y = c.int_const("y");
    solver s(c);

    s.add(x >= 1);
    s.add(y < x + 3);
    std::cout << s.check() << "\n";

    Z3_set_ast_print_mode(c, Z3_PRINT_SMTLIB_COMPLIANT);

    std::cout << "\nSolver is:\n";
    std::cout << s << "\n";
}

I get something like: sat

Solver is: (solver (>= x 1) (< y (+ x 3)))

What I want instead is something like this (rise4fun link: http://rise4fun.com/Z3/aznC8):

(declare-const x Int)
(declare-const y Int)
(assert (>= x 1))
(assert (< y (+ x 3)))
(check-sat)

I have tried C API functions such as Z3_set_ast_print_mode, Z3_ast_to_string but haven't been successful. I looked at Z3_benchmark_to_smtlib_string but this post Input arguments of Z3_benchmark_to_smtlib_string() suggests that it only supports SMTLIB 1.0.

Community
  • 1
  • 1
Tushar
  • 357
  • 1
  • 14

1 Answers1

1

Z3_benchmark_to_smtlib_string is the only function Z3 has for this purpose. Like the post you refer to mentions, it has been extended to SMTLIB2. As Leo says in his reply to that post, it is an old function that is rarely used, and it may not support dumping all the features (e.g., parameters on solvers). Recently, there was also another post relating to this function and problems/bugs in older versions of Z3 (see here).

Community
  • 1
  • 1
Christoph Wintersteiger
  • 8,234
  • 1
  • 16
  • 30