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 8365673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:42:48+00:00 2026-06-09T12:42:48+00:00

In Z3Py, how can I check if equation for given constraints have only one

  • 0

In Z3Py, how can I check if equation for given constraints have only one solution?

If more than one solution, how can I enumerate them?

  • 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-09T12:42:50+00:00Added an answer on June 9, 2026 at 12:42 pm

    You can do that by adding a new constraint that blocks the model returned by Z3.
    For example, suppose that in the model returned by Z3 we have that x = 0 and y = 1. Then, we can block this model by adding the constraint Or(x != 0, y != 1).
    The following script does the trick.
    You can try it online at: http://rise4fun.com/Z3Py/4blB

    Note that the following script has a couple of limitations. The input formula cannot include uninterpreted functions, arrays or uninterpreted sorts.

    from z3 import *
    
    # Return the first "M" models of formula list of formulas F 
    def get_models(F, M):
        result = []
        s = Solver()
        s.add(F)
        while len(result) < M and s.check() == sat:
            m = s.model()
            result.append(m)
            # Create a new constraint the blocks the current model
            block = []
            for d in m:
                # d is a declaration
                if d.arity() > 0:
                    raise Z3Exception("uninterpreted functions are not supported")
                # create a constant from declaration
                c = d()
                if is_array(c) or c.sort().kind() == Z3_UNINTERPRETED_SORT:
                    raise Z3Exception("arrays and uninterpreted sorts are not supported")
                block.append(c != m[d])
            s.add(Or(block))
        return result
    
    # Return True if F has exactly one model.
    def exactly_one_model(F):
        return len(get_models(F, 2)) == 1
    
    x, y = Ints('x y')
    s = Solver()
    F = [x >= 0, x <= 1, y >= 0, y <= 2, y == 2*x]
    print get_models(F, 10)
    print exactly_one_model(F)
    print exactly_one_model([x >= 0, x <= 1, y >= 0, y <= 2, 2*y == x])
    
    # Demonstrate unsupported features
    try:
        a = Array('a', IntSort(), IntSort())
        b = Array('b', IntSort(), IntSort())
        print get_models(a==b, 10)
    except Z3Exception as ex:
        print "Error: ", ex
    
    try:
        f = Function('f', IntSort(), IntSort())
        print get_models(f(x) == x, 10)
    except Z3Exception as ex:
        print "Error: ", ex
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whats wrong with the following script http://rise4fun.com/Z3Py/Cbl ? Adding the last two lines gives
I am trying to understand how the bound variables are indexed in z3 .
Is there any limitations in functions declaring? For example, this piece of code returning

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.