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

  • SEARCH
  • Home
  • 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 9075081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:47:13+00:00 2026-06-16T18:47:13+00:00

In Z3Py, I need to check if something is a term using the standard

  • 0

In Z3Py, I need to check if something is a term using the standard grammar term := const | var | f(t1,...,tn)). I have written the following function to determine that but my method to check if for n-ary function doesn’t seem very optimal.

Is there a better way to do so? These utility functions is_term, is_atom, is_literal, etc would be useful to be included in Z3. I will put them in the contrib section

CONNECTIVE_OPS = [Z3_OP_NOT,Z3_OP_AND,Z3_OP_OR,Z3_OP_IMPLIES,Z3_OP_IFF,Z3_OP_ITE]
REL_OPS = [Z3_OP_EQ,Z3_OP_LE,Z3_OP_LT,Z3_OP_GE,Z3_OP_GT]

def is_term(a):
    """
    term := const | var | f(t1,...,tn)
    """
    if is_const(a):
        return True
    else:
        r = (is_app(a) and \
                 a.decl().kind() not in CONNECTIVE_OPS + REL_OPS and \
                 all(is_term(c) for c in a.children()))
        return r
  • 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-16T18:47:14+00:00Added an answer on June 16, 2026 at 6:47 pm

    The function is reasonable, a few comments:

    1. It depends on what you mean by “var” in your specification. Z3 has variables as de-Brujin indices. There is a function in z3py “is_var(a)” to check if “a” is a variable index.

    2. There is another Boolean connective Z3_OP_XOR.

    3. There are additional relational operations, such as operations that compare bit-vectors.
      It depends on your intent and usage of the code, but you could alternatively check if the
      sort of the expression is Boolean, and if it is ensure that the head function symbol is
      uninterpreted.

    4. is_const(a) is defined as return is_app(a) and a.num_args() == 0. So is_const is really handled by the default case.

    5. Expressions that Z3 creates as a result of simplification, parsing or other transformations may have many shared sub-expressions. So a straight-forward recursive descent can take exponential time in the DAG size of the expression. You can deal with this by maintaining a hash table of visited nodes. From Python you can use Z3_get_ast_id to retrieve a unique number for the expression and maintain this in a set. The identifiers are unique as long as terms are not garbage collected, so
      you should just maintain such a set as a local variable.

    So, something along the lines of:

     def get_expr_id(e):
         return Z3_get_ast_id(e.ctx.ref(), e.ast)
    
     def is_term_aux(a, seen):
        if get_expr_id(a) in seen:
            return True
        else:
            seen[get_expr_id(a)] = True
            r = (is_app(a) and \
                 a.decl().kind() not in CONNECTIVE_OPS + REL_OPS and \
                 all(is_term_aux(c, seen) for c in a.children()))
            return r
    
     def is_term(a):
         return is_term_aux(a, {})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Z3Py, how can I check if equation for given constraints have only one
See the PyZ3 program at http://rise4fun.com/Z3Py/GTYu . The first call to check() works fine,
It seems that the substitute(f,t) function in Z3Py performs simplification on f first before
z3py snippet: x = Int('x') s = Solver() s.add(x <= x) print s.check() print
I'm trying to make z3 (I'm using z3py) to simplify some formulas for me
I'm going through Z3py and have a question with how to use the API
I would like to use Z3Py and I am trying to install Z3 following
Whats wrong with the following script http://rise4fun.com/Z3Py/Cbl ? Adding the last two lines gives
Given an expression in Z3py, can I convert that to SMT-LIB2 language? (So I
When I enable the explanation generation option in fixedpoints Z3Py, I am getting a

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.