just wondering in z3py , how do I check if a given constant expression is a variable or value ? For example
x = Int('x')
x_ = IntVal(7)
ColorVal, (White,Black) = EnumSort("ColorVal",["While","Black"])
mycolor = Const("mycolor",ColorVal)
So x,mycolor would all be variables and x_,True,False,White,Black would be values and not variables .
z3py has is_var predicate but for different purpose. This is useful if I want to rename all variables in a formula to something else.
One way to do this for the integers is with
is_intandis_int_value:For reals, you can do this using
is_realto check the variable sort, and use (the disjunction of)is_algebraic_valueandis_rational_valuefor the values (I didn’t see a function likeis_real_valuein the API, but I think this disjunct will do it). For bitvectors, you can useis_bv_valuefor values, andis_bvto check the variable sort.The .NET API has
Expr.IsNumeral, and you can see how these are implemented in the API here (e.g.,Expr.IsIntNum[the equivalent of the Pythonis_int_value] checks if bothExpr.IsNumeralandExpr.IsIntare true): http://research.microsoft.com/en-us/um/redmond/projects/z3/_expr_8cs_source.htmlI did not immediately see a way to do this for custom-defined enumeration sorts. As one alternative, you could encode your enum using bitvectors and compare variables / values using
is_bv_value. As a better workaround though, you appear to need to use the more general algebraic datatypes and their automatically created “recognizers”. The Python API does not seem to properly create the recognizers if you declare them as enum sorts. Here’s one way to do it for what’s effectively an enum sort (but declared as the more general datatype).Z3Py encoding of the following: http://rise4fun.com/Z3Py/ELtn