Quickstart Guide

The primary input language for cvc5 is SMT-LIB v2 . We give a short explanation of the SMT-LIB v2 quickstart example here.

First, we set the logic. The simplest way to set a logic for the solver is to choose “ALL”. This enables all logics in the solver. Alternatively, "QF_ALL" enables all logics without quantifiers. To optimize the solver’s behavior for a more specific logic, use the logic name, e.g. "QF_BV" or "QF_AUFBV" .

(set-logic ALL)

We will ask the solver to produce models and unsat cores in the following, and for this we have to enable the following options. Furthermore, we enable incremental solving so that we can use the (reset-assertions) command later on.

(set-option :produce-models true)
(set-option :incremental true)
; print unsat cores, include assertions in the unsat core that have not been named
(set-option :produce-unsat-cores true)
(set-option :dump-unsat-cores-full true)

Now, we create two constants x and y of sort Real . Notice that these are symbolic constants, but not actual values.

; Declare real constants x,y
(declare-const x Real)
(declare-const y Real)

We define the following constraints regarding x and y :

\[(0 < x) \wedge (0 < y) \wedge (x + y < 1) \wedge (x \leq y)\]

We assert them as follows. Notice that in SMT-LIB v2, terms are written in prefix notation, e.g., we write (+ x y) instead of (x + y) .

; Our constraints regarding x and y will be:
;
;   (1)  0 < x
;   (2)  0 < y
;   (3)  x + y < 1
;   (4)  x <= y

(assert (< 0 x))
(assert (< 0 y))
(assert (< (+ x y) 1))
(assert (<= x y))

Now we check if the asserted formula is satisfiable, that is, we check if there exist values of sort Real for x and y that satisfy all the constraints.

(check-sat)

The result we get from this satisfiability check is either sat , unsat or unknown , and it is printed to standard output. In this case, it will print sat .

Now, we query the solver for the values for x and y that satisfy the constraints. It is also possible to get values for terms that do not appear in the original formula.

(echo "Values of declared real constants and of compound terms built with them.")
(get-value (x y (- x y)))

This will print the values of x , y , and x-y , in a key-value format (<term> <value>) one after the other:

((x (/ 1 6)) (y (/ 1 6)) ((- x y) 0.0))

Next, we will check satisfiability of the same formula, only this time over integer variables a and b . For this, we first reset the assertions added to the solver and declare fresh integer variables a and b .

(echo "We will reset the solver with the (reset-assertions) command and check satisfiability of the same assertions but with the integers constants rather than with the real ones.")
(reset-assertions)
; Declare integer constants a,b
(declare-const a Int)
(declare-const b Int)

Next, we assert the same assertions as above, but with integers.

(assert (< 0 a))
(assert (< 0 b))
(assert (< (+ a b) 1))
(assert (<= a b))

Now, we check whether the revised query is satisfiable.

(check-sat)

This time the asserted formula is unsatisfiable and unsat is printed.

We can query the solver for an unsatisfiable core, that is, a subset of the assertions that is already unsatisfiable.

(get-unsat-core)

This will print:

(
(< 0 a)
(< 0 b)
(< (+ a b) 1)
)

Example

examples/api/smtlib/quickstart.smt2

 1 (set-logic ALL)
 2 (set-option :produce-models true)
 3 (set-option :incremental true)
 4 ; print unsat cores, include assertions in the unsat core that have not been named
 5 (set-option :produce-unsat-cores true)
 6 (set-option :dump-unsat-cores-full true)
 7 
 8 ; Declare real constants x,y
 9 (declare-const x Real)
10 (declare-const y Real)
11 
12 ; Our constraints regarding x and y will be:
13 ;
14 ;   (1)  0 < x
15 ;   (2)  0 < y
16 ;   (3)  x + y < 1
17 ;   (4)  x <= y
18 
19 (assert (< 0 x))
20 (assert (< 0 y))
21 (assert (< (+ x y) 1))
22 (assert (<= x y))
23 
24 (check-sat)
25 (echo "Values of declared real constants and of compound terms built with them.")
26 (get-value (x y (- x y)))
27 
28 (echo "We will reset the solver with the (reset-assertions) command and check satisfiability of the same assertions but with the integers constants rather than with the real ones.")
29 (reset-assertions)
30 ; Declare integer constants a,b
31 (declare-const a Int)
32 (declare-const b Int)
33 (assert (< 0 a))
34 (assert (< 0 b))
35 (assert (< (+ a b) 1))
36 (assert (<= a b))
37 
38 (check-sat)
39 (get-unsat-core)