Skip to content

Incorrect results using fresh_const in >=4.8 #2489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
djrenren opened this issue Aug 13, 2019 · 0 comments
Closed

Incorrect results using fresh_const in >=4.8 #2489

djrenren opened this issue Aug 13, 2019 · 0 comments

Comments

@djrenren
Copy link

djrenren commented Aug 13, 2019

I recently updated to z3 4.8.x and I've been having an issue with Z3_mk_fresh_const.

This example program highlights the issue:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <z3.h>

int main(int argc, char** argv)
{
  Z3_config cfg = Z3_mk_config();
  Z3_context ctx = Z3_mk_context(cfg);

  Z3_ast x = Z3_mk_fresh_const(ctx, "x", Z3_mk_int_sort(ctx));
  //Z3_symbol x_name = Z3_mk_string_symbol(ctx, "x");
  //Z3_ast x = Z3_mk_const(ctx, x_name, Z3_mk_int_sort(ctx));
  Z3_ast zero = Z3_mk_int64(ctx, 0, Z3_mk_int_sort(ctx));

  Z3_solver solver = Z3_mk_solver(ctx);
  Z3_solver_inc_ref(ctx, solver);

  Z3_ast ast = Z3_mk_gt(ctx, x, zero);
  Z3_solver_assert(ctx, solver, ast);

  int result = Z3_solver_check(ctx, solver) == Z3_L_TRUE;
  printf("result: %d\n", result);
  if (!result) { return 127; }

  Z3_model model = Z3_solver_get_model(ctx, solver);
  Z3_model_inc_ref(ctx, model);

  Z3_ast out;
  result = Z3_model_eval(ctx, model, x, 1, &out) == Z3_L_TRUE;
  printf("result: %d\n", result);
  if (!result) { return 127; }

  int64_t tmp;
  result = Z3_get_numeral_int64(ctx, out, &tmp) == Z3_L_TRUE;
  printf("result: %d\n", result);
  if (!result) { return 127; }

  printf("tmp: %lld\n", tmp);

	return 0;
}

We simply create a variable "x" and assert that it's greater than 0. But evaluating the model produces the answer 0. If we comment out the Z3_mk_fresh_const and instead produce our variable through Z3_mk_const we get a correct answer of 1.

This program works fine on 4.7.1, and I can't find a documented reason it would break on 4.8.x.

@djrenren djrenren changed the title Strange fresh_const behavior in >=4.8 Incorrect results using fresh_const behavior in >=4.8 Aug 13, 2019
@djrenren djrenren changed the title Incorrect results using fresh_const behavior in >=4.8 Incorrect results using fresh_const in >=4.8 Aug 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant