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)
There is no difference between
Const("x", IntSort())andInt("x"). We should viewInt("x")as syntax sugar for the former. The functionConstis usually used to define constants of user defined sorts. Example: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 sayxand1are constants. We sayxis a uninterpreted constant, and1is interpreted one. That is, the meaning of1is fixed, but Z3 is free to assign an interpretation forxin order to make a formula satisfiable. If you just want to create the interpreted constant3.14, you can useRealVal('3.14'). In the following example,xis not a Z3 expression, but a Python variable that points to the Z3 expression3.14. We can usexas shorthand for3.14when building Z3 expressions/formulas. The Python variablezis pointing to the Z3 expressiony. Finally,z > xreturns the Z3 expressiony > 3.14. Z3Py beginners usually confuse Python variables with Z3 expressions. After the difference is clear, everything starts to make sense.