Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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 <code>x = 0</code> and <code>y = 1</code>. Then, we can block this model by adding the constraint <code>Or(x != 0, y != 1)</code>. The following script does the trick. You can try it online at: <a href="http://rise4fun.com/Z3Py/4blB" rel="noreferrer">http://rise4fun.com/Z3Py/4blB</a> </p> <p>Note that the following script has a couple of limitations. The input formula cannot include uninterpreted functions, arrays or uninterpreted sorts. </p> <pre><code>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) &lt; 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() &gt; 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 &gt;= 0, x &lt;= 1, y &gt;= 0, y &lt;= 2, y == 2*x] print get_models(F, 10) print exactly_one_model(F) print exactly_one_model([x &gt;= 0, x &lt;= 1, y &gt;= 0, y &lt;= 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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload