0

Can I get multiple models for a query like the following?

(set-logic LIA)
(set-option :produce-models true)

(declare-const x Int)
(assert (< x 20))
(check-sat)
(get-model)

Instead of just

sat
(
(define-fun x () Int 0)
)

I'd like to get 0, 1, -1, 2, ...

Malte Schwerhoff
  • 12,684
  • 4
  • 41
  • 71
Alex Coleman
  • 607
  • 1
  • 4
  • 11
  • If you want to explore the literature on this topic, the name for this problem is "All-SAT" for propositional satisfiability or "All-SMT" when extended to SMT. You can find many papers on these topics such as: https://sites.cs.ucsb.edu/~nestan/pdf/VLSID14.pdf and https://ieeexplore.ieee.org/document/7299903 . – Tim May 03 '21 at 05:13
  • @Tim this is really interesting. Thank you for the comment. – Alex Coleman May 05 '21 at 15:55

1 Answers1

1

SMTLib language does not have a mechanism to retrieve "all-models." So, if you're bound to be using SMTLib only, you cannot do this; at least not easily.

However, most solvers (definitely including cvc4 and z3) can be scripted from higher-level languages. The idea is to make a check-sat call, and if you get a solution, you add an additional assertion that disallows that model, and query for a new one. See this answer for how to do this in z3, as scripted from Python: Trying to find all solutions to a boolean formula using Z3 in python. You can do the same from C/Java etc.; or use a higher-level binding that provides such a command out-of-the box.

alias
  • 28,120
  • 2
  • 23
  • 40