Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

z3 const declaration

Tags:

python

z3

In Z3 Python, what's the diff between 1) x = Const("x",IntSort()) vs 2) x = Int("x") ? is_const returns true for both and they are both ArithRef. I would thought 1) would be appropriate for defining a const, e.g., x is 3.14 and 2) is to making a variable.

Is there a correct way to create a const variable like x = 3.14 (other than generating a formula x == 3.14)

like image 847
Vu Nguyen Avatar asked Sep 16 '12 16:09

Vu Nguyen


1 Answers

There is no difference between Const("x", IntSort()) and Int("x"). We should view Int("x") as syntax sugar for the former. The function Const is usually used to define constants of user defined sorts. Example:

S, (a, b, c) = EnumSort('S', ('a', 'b', 'c'))
x = Const("x", S)

In Z3, we use the term "variable" for universal and existential variables. Quantifier free formulas do not contain variables, only constants. In the formula, x + 1 > 0, we say x and 1 are constants. We say x is a uninterpreted constant, and 1 is interpreted one. That is, the meaning of 1 is fixed, but Z3 is free to assign an interpretation for x in order to make a formula satisfiable. If you just want to create the interpreted constant 3.14, you can use RealVal('3.14'). In the following example, x is not a Z3 expression, but a Python variable that points to the Z3 expression 3.14. We can use x as shorthand for 3.14 when building Z3 expressions/formulas. The Python variable z is pointing to the Z3 expression y. Finally, z > x returns the Z3 expression y > 3.14. Z3Py beginners usually confuse Python variables with Z3 expressions. After the difference is clear, everything starts to make sense.

x = RealVal('3.14')
z = Real('y')
print z > x
like image 59
Leonardo de Moura Avatar answered Oct 12 '22 23:10

Leonardo de Moura