1

When using a model object, I call func_decl get_func_decl (unsigned i) to get the value assigned to a certain function (variable). The problem I am having is taking the output of that (which is a func_decl) and converting it to int.

For example, if the model is {x |-> 4, y |-> 12, z |-> 6}, I would like to get the actual int values of those 3 variables (4, 12 and 6).

Rynx
  • 13
  • 2
  • 1
    You can see this question: http://stackoverflow.com/questions/11652069/casting-a-z3-integer-expression-to-a-c-c-int – Dingbao Xie Jul 03 '13 at 05:47

1 Answers1

2

Z3 provides the function Z3_get_numeral_int for this purpose:

Z3_bool Z3_API Z3_get_numeral_int(__in Z3_context c, __in Z3_ast v, __out int* i);

Note that the last parameter is a point to an integer that will be filled with the right value if the call succeeds (it will fail for non-numerals or numerals which are not representable as an int).

There are also other functions called Z3_get_numeral_* to obtain values of different types, e.g., uint64 etc.

This method works for constants (i.e., func_decls of arity 0). To get the entries of a (non-zero arity) function definition, the following function should be used:

Z3_func_entry Z3_API Z3_func_interp_get_entry(__in Z3_context c, __in Z3_func_interp f, unsigned i);
Christoph Wintersteiger
  • 8,234
  • 1
  • 16
  • 30