Carsten Rütz
Carsten Rütz

Reputation: 157

Z3Py: randomized results (phase-selection) not random?

I tried to use bit vectors to get randomized results in model values like suggested by de Moura here but then with Z3Py instead of SMTLIB. I translated his example to:

from z3 import *
s = Solver()
x = BitVec('x', 16)
set_option('auto_config', False)
set_option('smt.phase_selection',5)
s.add(ULT(x,100))
s.check()
s.model()
s.check()
s.model()

However, the result seems to always be the same, i.e. - repetitive checking with s.check() does not alter the result. - even after a restart of the python interactive shell the result of the execution will be the same

Adding a change of the random seed did not alter the results: set_option('smt.random_seed', 123)

Does anyone have an idea why is not working as desired?

Thanks in advance!

Carsten

Upvotes: 3

Views: 933

Answers (1)

Christoph Wintersteiger
Christoph Wintersteiger

Reputation: 8392

This case is simply too simple. It's essentially solved by the preprocessor and never gets to a point where it needs to select a phase, so random phase selection has no effect. Leo's answer to the cited post is now a little bit out of date and Z3 has changed, so it doesn't immediately replicate using the latest unstable version because Z3 chooses to use a different solver. We can still get the random behavior if we force it to use the incremental solver by adding a (push) command though; here's an updated example that is seed dependent:

(set-option :auto_config false)
(set-option :smt.phase_selection 5)
(set-option :smt.random_seed 456)
(declare-const x (_ BitVec 16))
(assert (bvult x (_ bv100 16)))
(push)
(check-sat)
(get-model)
;; try again to get a different model
(check-sat)
(get-model)
;; try again to get a different model
(check-sat)
(get-model)

Upvotes: 4

Related Questions