Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8476667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:14:35+00:00 2026-06-10T18:14:35+00:00

just wondering in z3py , how do I check if a given constant expression

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:14:37+00:00Added an answer on June 10, 2026 at 6:14 pm

    One way to do this for the integers is with is_int and is_int_value:

    x = Int('x')
    print "x types"
    print is_int(x) # true, is of sort int
    print is_int_value(x) # false, not a "value"
    
    x_ = IntVal(7)
    print "x_ types"
    print is_int(x_) # true, is also of sort int
    print is_int_value(x_) # true, is a value
    

    For reals, you can do this using is_real to check the variable sort, and use (the disjunction of) is_algebraic_value and is_rational_value for the values (I didn’t see a function like is_real_value in the API, but I think this disjunct will do it). For bitvectors, you can use is_bv_value for values, and is_bv to 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 Python is_int_value] checks if both Expr.IsNumeral and Expr.IsInt are true): http://research.microsoft.com/en-us/um/redmond/projects/z3/_expr_8cs_source.html

    I 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

    ColorVal = Datatype('ColorVal')
    ColorVal.declare('white')
    ColorVal.declare('black')
    ColorVal = ColorVal.create()
    
    mycolor = Const("mycolor", ColorVal)
    
    print ColorVal.recognizer(0) # is_white
    print ColorVal.recognizer(1) # is_black
    
    print simplify(ColorVal.is_white(mycolor)) # returns is_white(mycolor)
    print simplify(ColorVal.is_black(mycolor)) # returns is_black(mycolor)
    
    mycolorVal = ColorVal.white # set to value white
    print simplify(ColorVal.is_white(mycolorVal)) # true
    print simplify(ColorVal.is_black(mycolorVal)) # false
    
    # compare "variable" versus "value" with return of is_white, is_black, etc.: if it gives a boolean value, it's a value, if not, it's a variable
    print "var vs. value"
    x = simplify(ColorVal.is_white(mycolor))
    print is_true(x) or is_false(x) # returns false, since x is is_white(mycolor)
    y = simplify(ColorVal.is_white(mycolorVal))
    print is_true(y) or is_false(y) # true
    
    ColorValEnum, (whiteEnum,blackEnum)  = EnumSort("ColorValEnum",["whiteEnum","blackEnum"])
    mycolorEnum = Const("mycolorEnum",ColorValEnum)
    
    print ColorValEnum.recognizer(0) # is_whiteEnum
    print ColorValEnum.recognizer(1) # is_blackEnum
    
    # it appears that declaring an enum does not properly create the recognizers in the Python API:
    #print simplify(ColorValEnum.is_whiteEnum(mycolorEnum)) # error: gives DatatypeSortRef instance has no attribute 'is_whiteEnum'
    #print simplify(ColorValEnum.is_blackEnum(mycolorEnum)) # error: gives DatatypeSortRef instance has no attribute 'is_blackEnum'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering the best way to replace in place matches on a string. value.replace(bob,
Just wondering for user permission check, Should you keep the permission in the session
Just wondering how to set a hidden field value so that when I submit
Just wondering, will it be possible we can check whether the page is call
just wondering if there is a way to reduce the amount of code needed
Just wondering: I'm trying to set up an adaptive image handler in Coldfusion8, which
Just wondering, having the following simple code: var object1 = { name: function (){
Just wondering when do you actually use $.get(index); I am a bit confused on
just wondering when I had an iphone I was able to create a web
Just wondering is it possible to build CLI app that can be run from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.