Python API Documentation
Quickstart
First, create a TermManager
instance that allows us to
create sorts and terms later:
tm = TermManager()
Then, create a bitwuzla.Options
instance:
options = Options()
This instance can be configured via bitwuzla.Options.set()
.
For example, to enable model generation
(SMT-LIB: (set-option :produce-models true)
):
options.set(Option.PRODUCE_MODELS, True)
Some options have modes, which can be configured via the string representation of their modes. For example, to enable CaDiCaL as back end SAT solver (this is for illustration purposes only, CaDiCaL is configured by default):
options.set(Option.SAT_SOLVER, 'cadical')
For more details on available options, see Options.
Then, create a bitwuzla.Bitwuzla
solver instance with a term
manager and configured options(configuration options are now frozen and cannot
be changed for this instance):
bitwuzla = Bitwuzla(tm, options)
Next, you will want to create some expressions via the term manager tm and assert formulas.
Note
Sorts and terms can be shared between multiple solver instances as long as these solvers use the same term manager.
For example, consider the following SMT-LIB input:
(set-logic QF_ABV)
(set-option :produce-models true)
(declare-const x (_ BitVec 8))
(declare-const y (_ BitVec 8))
(declare-fun f ((_ BitVec 8) (_ BitVec 4)) (_ BitVec 8))
(declare-const a (Array (_ BitVec 8) (_ BitVec 8)))
(assert
(distinct
((_ extract 3 0) (bvsdiv x (_ bv2 8)))
((_ extract 3 0) (bvashr y (_ bv1 8)))))
(assert (= (f x ((_ extract 6 3) x)) y))
(assert (= (select a x) y))
(check-sat)
(get-model)
(get-value (x y f a (bvmul x x)))
(exit)
This input is created and asserted as follows:
# First, create a term manager instance.
tm = TermManager()
# Create a Bitwuzla options instance.
options = Options()
# Then, enable model generation.
options.set(Option.PRODUCE_MODELS, True)
# Now, for illustration purposes, we enable CaDiCaL as SAT solver
# (CaDiCaL is already configured by default).
# Note: This will silently fall back to one of the compiled in SAT solvers
# if the selected solver is not compiled in.
options.set(Option.SAT_SOLVER, 'cadical')
# Then, create a Bitwuzla instance.
bitwuzla = Bitwuzla(tm, options)
# Create bit-vector sorts of size 4 and 8.
sortbv4 = tm.mk_bv_sort(4)
sortbv8 = tm.mk_bv_sort(8)
# Create function sort.
sortfun = tm.mk_fun_sort([sortbv8, sortbv4], sortbv8)
# Create array sort.
sortarr = tm.mk_array_sort(sortbv8, sortbv8)
# Create two bit-vector constants of that sort.
x = tm.mk_const(sortbv8, "x")
y = tm.mk_const(sortbv8, "y")
# Create fun const.
f = tm.mk_const(sortfun, "f")
# Create array const.
a = tm.mk_const(sortarr, "a")
# Create bit-vector values one and two of the same sort.
one = tm.mk_bv_one(sortbv8)
# Alternatively, you can create bit-vector value one with:
# one = tm.mk_bv_value(sortbv8, "1", 2)
# one = tm.mk_bv_value(sortbv8, 1)
two = tm.mk_bv_value(sortbv8, 2)
# (bvsdiv x (_ bv2 8))
sdiv = tm.mk_term(Kind.BV_SDIV, [x, two])
# (bvashr y (_ bv1 8))
ashr = tm.mk_term(Kind.BV_ASHR, [y, one])
# ((_ extract 3 0) (bvsdiv x (_ bv2 8)))
sdive = tm.mk_term(Kind.BV_EXTRACT, [sdiv], [3, 0])
# ((_ extract 3 0) (bvashr x (_ bv1 8)))
ashre = tm.mk_term(Kind.BV_EXTRACT, [ashr], [3, 0])
# (assert
# (distinct
# ((_ extract 3 0) (bvsdiv x (_ bv2 8)))
# ((_ extract 3 0) (bvashr y (_ bv1 8)))))
bitwuzla.assert_formula(tm.mk_term(Kind.DISTINCT, [sdive, ashre]))
# (assert (= (f x ((_ extract 6 3) x)) y))
bitwuzla.assert_formula(tm.mk_term(
Kind.EQUAL,
[tm.mk_term(Kind.APPLY, [f, x, tm.mk_term(Kind.BV_EXTRACT, [x], [6, 3])]),
y]))
# (assert (= (select a x) y))
bitwuzla.assert_formula(
tm.mk_term(Kind.EQUAL, [tm.mk_term(Kind.ARRAY_SELECT, [a, x]), y]))
Alternatively, you can parse an input file in BTOR2 format
[NPWB18] or SMT-LIB v2 format [BFT17] by creating a parser
bitwuzla.Parser
and then parsing the input file via
bitwuzla.Parser.parse()
.
Note
The input parser creates a bitwuzla.Bitwuzla
instance, which can be
configured via the bitwuzla.Options
instance passed into the
parser. This Bitwuzla instance can be retrieved via
bitwuzla.Parser.bitwuzla()
.
For example, to parse an example file examples/smt2/quickstart.smt2
in
SMT-LIB format:
tm = TermManager()
options = Options()
# We will parse example file `smt2/quickstart.smt2`.
# Create parser instance.
parser = Parser(tm, options)
res = parser.parse("../smt2/quickstart.smt2")
assert not res
Note
If the input is given in SMT-LIB format, commands like check-sat
or get-value
will be executed while parsing if argument parse_only
is passed into bitwuzla.Parser.parse()
as True
.
After parsing from an input file, the parsed assertions can be retrieved
via bitwuzla.Bitwuzla.get_assertions()
:
# Now we retrieve the set of asserted formulas and print them.
assertions = parser.bitwuzla().get_assertions()
print('Assertions:')
print('{')
for a in assertions:
print(f' {a}')
print('}')
Alternatively, Bitwuzla also supports parsing from strings via
bitwuzla.Parser.parse()
. The quickstart input above can be parsed
as one huge input string, or any its subsets of commands.
Bitwuzla also allows to add onto input parsed from a file.
For example, after parsing in examples/smt2/quickstart.smt2
, which is
satisfiable, we add an assertion (which now makes the input formula
unsatisfiable) via parsing from string as follows:
parser.parse('(assert (distinct (select a x) y))', True, False)
Bitwuzla also supports parsing terms and sorts from strings via
bitwuzla.Parser.parse_term()
and
bitwuzla.Parser.parse_sort()
.
Note
Declarations like declare-const
are commands (not terms) in the
SMT-LIB language. Commands must be parsed in via
bitwuzla.Parser.parse()
.
Function bitwuzla.Parser.parse_term()
and
bitwuzla.Parser.parse_sort()
only support parsing
SMT-LIB terms and sorts, respectively.
For example, to parse a bit-vector sort of size 16 from string and show
that it corresponds to the bit-vector sort of size 16 created via
bitwuzla.mk_bv_sort()
:
# Declare bit-vector sort of size 16.
bv16 = parser.parse_sort('(_ BitVec 16)')
# Create bit-vector sort of size 16 and show that it corresponds to
# its string representation '(_ BitVec16)'.
assert bv16 == tm.mk_bv_sort(16)
Then, to declare Boolean constants c
and d
and a bit-vector
constant b
:
parser.parse("(declare-const c Bool)(declare-const d Bool)", True, False)
parser.parse('(declare-const b (_ BitVec 16))', True, False)
These terms can be retrieved via bitwuzla.Parser.parse_term()
:
# Retrieve term representing 'b'.
b = parser.parse_term('b')
# Retrieve term representing 'c'.
c = parser.parse_term('c')
# Retrieve term representing 'd'.
d = parser.parse_term('d')
Now, to parse in terms using these constants via
bitwuzla.Parser.parse_term()
:
# Create xor over 'c' and 'd' and show that it corresponds to term
# parsed in from its string representation '(xor c d)'.
assert parser.parse_term('(xor c d)') == tm.mk_term(Kind.XOR, [c, d])
# Create bit-vector addition over 'b' and bit-vector value
# '1011111010001010' and show that it corresponds to the term parsed in
# from its string representation '(bvadd b #b1011111010001010)'.
assert parser.parse_term('(bvadd b #b1011111010001010)') \
== tm.mk_term(Kind.BV_ADD,
[b, tm.mk_bv_value(bv16, '1011111010001010', 2)])
After parsing input and asserting formulas, satisfiability can be
determined via bitwuzla.Bitwuzla.check_sat()
.
# (check-sat)
result = bitwuzla.check_sat()
Formulas can also be assumed via passing a vector of assumptions into
bitwuzla.Bitwuzla.check_sat()
.
If the formula is satisfiable and model generation has been enabled, the
resulting model can be printed via bitwuzla.Bitwuzla.get_value()
and bitwuzla.Term.str()
.
An example implementation illustrating how to print
the current model via declared symbols (in this case x
, y
,
f
and a
) is below:
# Print model in SMT-LIBv2 format.
print('Model:\n(')
for term in [x, y, f, a]:
sort = term.sort()
symbol = term.symbol()
print(f' (define-fun {symbol if symbol else "@t" + term.id()} (',
end = '')
if sort.is_fun():
value = bitwuzla.get_value(term)
assert value.kind() == Kind.LAMBDA
assert value.num_children() == 2
while value[1].kind() == Kind.LAMBDA:
assert value[0].is_variable()
print(f'({value[0]} {value[0].sort()}) ',
end = '')
value = value[1]
assert value[0].is_variable()
print(f'({value[0]} {value[0].sort()})) ' \
+ f'{sort.fun_codomain()} {value[1]})')
else:
print(f') {sort} {bitwuzla.get_value(term)})')
print(')')
print()
This will output a possible model, in this case:
(
(define-fun x () (_ BitVec 8) #b10011111)
(define-fun y () (_ BitVec 8) #b11111111)
(define-fun f ((@bzla.var_74 (_ BitVec 8)) (@bzla.var_75 (_ BitVec 4))) (_ BitVec 8) (ite (and (= @bzla.var_74 #b10011111) (= @bzla.var_75 #b0011)) #b11111111 #b00000000))
(define-fun a () (Array (_ BitVec 8) (_ BitVec 8)) (store ((as const (Array (_ BitVec 8) (_ BitVec 8))) #b00000000) #b10011111 #b11111111))
)
Alternatively, it is possible to query the value of terms as a term via
bitwuzla.Bitwuzla.get_value()
; or as assignment via
bitwuzla.Term.value()
, which returns the string representation
of bit-vector and floating-point values, the
bitwuzla.RoundingMode
value for RoundingMode values, and a bool
value for Boolean values.
Additionally, for floating-point values,
bitwuzla.Term.value()
allows to retrieve the assignment
split into assignment strings for the sign bit, the exponent and the
significand.
In our case, we can query the assignments of x
and y
, both
bit-vector terms, as binary strings:
# Both x and y are bit-vector terms and their value is a bit-vector
# value that can be printed via Term.value().
print(f'value of x: {bitwuzla.get_value(x).value(2)}')
print(f'value of y: {bitwuzla.get_value(y).value(2)}')
This will print:
value of x: 10011111
value of y: 11111111
The value of f
(a function term) and a
(an array term), on the
other hand, cannot be represented with a simple type. Thus, function values are
given as bitwuzla.Kind.LAMBDA
, and array values are given as
bitwuzla.Kind.ARRAY_STORE
.
We can retrieve an SMT-LIB2 string representation of the values via
bitwuzla.Term.str()
.
# f and a, on the other hand, are a function and array term, respectively.
# The value of these terms is not a value term: for f, it is a lambda term,
# and the value of a is represented as a store term. Thus we cannot use
# Term.value(), but we can print the value of the terms via Term.str().
print('str() representation of value of f:')
print(bitwuzla.get_value(f))
print()
print('str() representation of value of a:')
print(bitwuzla.get_value(a))
This will print:
str() representation of value of f:
(lambda ((@bzla.var_74 (_ BitVec 8))) (lambda ((@bzla.var_75 (_ BitVec 4))) (ite (and (= @bzla.var_74 #b10011111) (= @bzla.var_75 #b0011)) #b11111111 #b00000000)))
str() representation of value of a:
(store ((as const (Array (_ BitVec 8) (_ BitVec 8))) #b00000000) #b10011111 #b11111111)
Note that the string representation of values representable as simple type
(bit-vectors, boolean, floating-point, rounding mode) are given as pure
value string (in the given number format) via
bitwuzla.Term.value()
.
Their string representation retrieved via bitwuzla.Term.str()
,
however, is given in SMT-LIB2 format. For example,
print(f'str() representation of value of x: {bitwuzla.get_value(x)}')
print(f'str() representation of value of y: {bitwuzla.get_value(y)}')
This will print:
str() representation of value of x: #b10011111
str() representation of value of y: #b11111111
It is also possible to query the model value of expressions that do not occur in the input formula:
print(f'value of v = x * x: {v.value(2)}')
This will print:
value of v = x * x: 11000001
Examples
Quickstart Example
1#
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == "__main__":
14
15 # First, create a term manager instance.
16 tm = TermManager()
17 # Create a Bitwuzla options instance.
18 options = Options()
19 # Then, enable model generation.
20 options.set(Option.PRODUCE_MODELS, True)
21 # Now, for illustration purposes, we enable CaDiCaL as SAT solver
22 # (CaDiCaL is already configured by default).
23 # Note: This will silently fall back to one of the compiled in SAT solvers
24 # if the selected solver is not compiled in.
25 options.set(Option.SAT_SOLVER, 'cadical')
26 # Then, create a Bitwuzla instance.
27 bitwuzla = Bitwuzla(tm, options)
28
29 # Create bit-vector sorts of size 4 and 8.
30 sortbv4 = tm.mk_bv_sort(4)
31 sortbv8 = tm.mk_bv_sort(8)
32 # Create function sort.
33 sortfun = tm.mk_fun_sort([sortbv8, sortbv4], sortbv8)
34 # Create array sort.
35 sortarr = tm.mk_array_sort(sortbv8, sortbv8)
36
37 # Create two bit-vector constants of that sort.
38 x = tm.mk_const(sortbv8, "x")
39 y = tm.mk_const(sortbv8, "y")
40 # Create fun const.
41 f = tm.mk_const(sortfun, "f")
42 # Create array const.
43 a = tm.mk_const(sortarr, "a")
44 # Create bit-vector values one and two of the same sort.
45 one = tm.mk_bv_one(sortbv8)
46 # Alternatively, you can create bit-vector value one with:
47 # one = tm.mk_bv_value(sortbv8, "1", 2)
48 # one = tm.mk_bv_value(sortbv8, 1)
49 two = tm.mk_bv_value(sortbv8, 2)
50
51 # (bvsdiv x (_ bv2 8))
52 sdiv = tm.mk_term(Kind.BV_SDIV, [x, two])
53 # (bvashr y (_ bv1 8))
54 ashr = tm.mk_term(Kind.BV_ASHR, [y, one])
55 # ((_ extract 3 0) (bvsdiv x (_ bv2 8)))
56 sdive = tm.mk_term(Kind.BV_EXTRACT, [sdiv], [3, 0])
57 # ((_ extract 3 0) (bvashr x (_ bv1 8)))
58 ashre = tm.mk_term(Kind.BV_EXTRACT, [ashr], [3, 0])
59
60 # (assert
61 # (distinct
62 # ((_ extract 3 0) (bvsdiv x (_ bv2 8)))
63 # ((_ extract 3 0) (bvashr y (_ bv1 8)))))
64 bitwuzla.assert_formula(tm.mk_term(Kind.DISTINCT, [sdive, ashre]))
65 # (assert (= (f x ((_ extract 6 3) x)) y))
66 bitwuzla.assert_formula(tm.mk_term(
67 Kind.EQUAL,
68 [tm.mk_term(Kind.APPLY, [f, x, tm.mk_term(Kind.BV_EXTRACT, [x], [6, 3])]),
69 y]))
70 # (assert (= (select a x) y))
71 bitwuzla.assert_formula(
72 tm.mk_term(Kind.EQUAL, [tm.mk_term(Kind.ARRAY_SELECT, [a, x]), y]))
73
74 # (check-sat)
75 result = bitwuzla.check_sat()
76 print('Expect: sat')
77 print(f'Bitwuzla: {result}')
78
79 # Print model in SMT-LIBv2 format.
80 print('Model:\n(')
81 for term in [x, y, f, a]:
82 sort = term.sort()
83 symbol = term.symbol()
84 print(f' (define-fun {symbol if symbol else "@t" + term.id()} (',
85 end = '')
86 if sort.is_fun():
87 value = bitwuzla.get_value(term)
88 assert value.kind() == Kind.LAMBDA
89 assert value.num_children() == 2
90 while value[1].kind() == Kind.LAMBDA:
91 assert value[0].is_variable()
92 print(f'({value[0]} {value[0].sort()}) ',
93 end = '')
94 value = value[1]
95 assert value[0].is_variable()
96 print(f'({value[0]} {value[0].sort()})) ' \
97 + f'{sort.fun_codomain()} {value[1]})')
98 else:
99 print(f') {sort} {bitwuzla.get_value(term)})')
100 print(')')
101 print()
102
103 # Print value for x, y, f and a.
104 # Both x and y are bit-vector terms and their value is a bit-vector
105 # value that can be printed via Term.value().
106 print(f'value of x: {bitwuzla.get_value(x).value(2)}')
107 print(f'value of y: {bitwuzla.get_value(y).value(2)}')
108 print()
109 # f and a, on the other hand, are a function and array term, respectively.
110 # The value of these terms is not a value term: for f, it is a lambda term,
111 # and the value of a is represented as a store term. Thus we cannot use
112 # Term.value(), but we can print the value of the terms via Term.str().
113 print('str() representation of value of f:')
114 print(bitwuzla.get_value(f))
115 print()
116 print('str() representation of value of a:')
117 print(bitwuzla.get_value(a))
118 print()
119 # Note that the assignment string of bit-vector terms is given as the
120 # pure assignment string, either in binary, hexadecimal or decimal format,
121 # whereas Term.str() prints the value in SMT-LIB2 format (in the given
122 # bit-vector output number format, binary by default).
123 print(f'str() representation of value of x: {bitwuzla.get_value(x)}')
124 print(f'str() representation of value of y: {bitwuzla.get_value(y)}')
125 print()
126
127 # Query value of bit-vector term that does not occur in the input formula
128 v = bitwuzla.get_value(tm.mk_term(Kind.BV_MUL, [x, x]))
129 print(f'value of v = x * x: {v.value(2)}')
1#
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == "__main__":
14
15 # First, create a term manager instance.
16 tm = TermManager()
17 # Create a Bitwuzla options instance.
18 options = Options()
19 # Then, enable model generation.
20 options.set(Option.PRODUCE_MODELS, True)
21 # Now, for illustration purposes, we enable CaDiCaL as SAT solver
22 # (CaDiCaL is already configured by default).
23 # Note: This will silently fall back to one of the compiled in SAT solvers
24 # if the selected solver is not compiled in.
25 options.set(Option.SAT_SOLVER, 'cadical')
26 # Then, create a Bitwuzla instance.
27 bitwuzla = Bitwuzla(tm, options)
28
29 # Create bit-vector sorts of size 4 and 8.
30 sortbv4 = tm.mk_bv_sort(4)
31 sortbv8 = tm.mk_bv_sort(8)
32 # Create function sort.
33 sortfun = tm.mk_fun_sort([sortbv8, sortbv4], sortbv8)
34 # Create array sort.
35 sortarr = tm.mk_array_sort(sortbv8, sortbv8)
36
37 # Create two bit-vector constants of that sort.
38 x = tm.mk_const(sortbv8, "x")
39 y = tm.mk_const(sortbv8, "y")
40 # Create fun const.
41 f = tm.mk_const(sortfun, "f")
42 # Create array const.
43 a = tm.mk_const(sortarr, "a")
44 # Create bit-vector values one and two of the same sort.
45 one = tm.mk_bv_one(sortbv8)
46 # Alternatively, you can create bit-vector value one with:
47 # one = tm.mk_bv_value(sortbv8, "1", 2)
48 # one = tm.mk_bv_value(sortbv8, 1)
49 two = tm.mk_bv_value(sortbv8, 2)
50
51 # (bvsdiv x (_ bv2 8))
52 sdiv = tm.mk_term(Kind.BV_SDIV, [x, two])
53 # (bvashr y (_ bv1 8))
54 ashr = tm.mk_term(Kind.BV_ASHR, [y, one])
55 # ((_ extract 3 0) (bvsdiv x (_ bv2 8)))
56 sdive = tm.mk_term(Kind.BV_EXTRACT, [sdiv], [3, 0])
57 # ((_ extract 3 0) (bvashr x (_ bv1 8)))
58 ashre = tm.mk_term(Kind.BV_EXTRACT, [ashr], [3, 0])
59
60 # (assert
61 # (distinct
62 # ((_ extract 3 0) (bvsdiv x (_ bv2 8)))
63 # ((_ extract 3 0) (bvashr y (_ bv1 8)))))
64 bitwuzla.assert_formula(tm.mk_term(Kind.DISTINCT, [sdive, ashre]))
65 # (assert (= (f x ((_ extract 6 3) x)) y))
66 bitwuzla.assert_formula(tm.mk_term(
67 Kind.EQUAL,
68 [tm.mk_term(Kind.APPLY, [f, x, tm.mk_term(Kind.BV_EXTRACT, [x], [6, 3])]),
69 y]))
70 # (assert (= (select a x) y))
71 bitwuzla.assert_formula(
72 tm.mk_term(Kind.EQUAL, [tm.mk_term(Kind.ARRAY_SELECT, [a, x]), y]))
73
74 # (check-sat)
75 result = bitwuzla.check_sat()
76 print('Expect: sat')
77 print(f'Bitwuzla: {result}')
78
79 # Print model in SMT-LIBv2 format.
80 print('Model:\n(')
81 for term in [x, y, f, a]:
82 sort = term.sort()
83 symbol = term.symbol()
84 print(f' (define-fun {symbol if symbol else "@t" + term.id()} (',
85 end = '')
86 if sort.is_fun():
87 value = bitwuzla.get_value(term)
88 assert value.kind() == Kind.LAMBDA
89 assert value.num_children() == 2
90 while value[1].kind() == Kind.LAMBDA:
91 assert value[0].is_variable()
92 print(f'({value[0]} {value[0].sort()}) ',
93 end = '')
94 value = value[1]
95 assert value[0].is_variable()
96 print(f'({value[0]} {value[0].sort()})) ' \
97 + f'{sort.fun_codomain()} {value[1]})')
98 else:
99 print(f') {sort} {bitwuzla.get_value(term)})')
100 print(')')
101 print()
102
103 # Print value for x, y, f and a.
104 # Both x and y are bit-vector terms and their value is a bit-vector
105 # value that can be printed via Term.value().
106 print(f'value of x: {bitwuzla.get_value(x).value(2)}')
107 print(f'value of y: {bitwuzla.get_value(y).value(2)}')
108 print()
109 # f and a, on the other hand, are a function and array term, respectively.
110 # The value of these terms is not a value term: for f, it is a lambda term,
111 # and the value of a is represented as a store term. Thus we cannot use
112 # Term.value(), but we can print the value of the terms via Term.str().
113 print('str() representation of value of f:')
114 print(bitwuzla.get_value(f))
115 print()
116 print('str() representation of value of a:')
117 print(bitwuzla.get_value(a))
118 print()
119 # Note that the assignment string of bit-vector terms is given as the
120 # pure assignment string, either in binary, hexadecimal or decimal format,
121 # whereas Term.str() prints the value in SMT-LIB2 format (in the given
122 # bit-vector output number format, binary by default).
123 print(f'str() representation of value of x: {bitwuzla.get_value(x)}')
124 print(f'str() representation of value of y: {bitwuzla.get_value(y)}')
125 print()
126
127 # Query value of bit-vector term that does not occur in the input formula
128 v = bitwuzla.get_value(tm.mk_term(Kind.BV_MUL, [x, x]))
129 print(f'value of v = x * x: {v.value(2)}')
1/***
2 * Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3 *
4 * Copyright (C) 2021 by the authors listed in the AUTHORS file at
5 * https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6 *
7 * This file is part of Bitwuzla under the MIT license. See COPYING for more
8 * information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
9 */
10
11#include <assert.h>
12#include <bitwuzla/c/bitwuzla.h>
13#include <stdio.h>
14
15int
16main()
17{
18 // First, create a term manager instance.
19 //! [docs-c-quickstart-0 start]
20 BitwuzlaTermManager *tm = bitwuzla_term_manager_new();
21 //! [docs-c-quickstart-0 end]
22 // Create a Bitwuzla options instance.
23 //! [docs-c-quickstart-1 start]
24 BitwuzlaOptions *options = bitwuzla_options_new();
25 //! [docs-c-quickstart-1 end]
26 // Then, enable model generation.
27 //! [docs-c-quickstart-2 start]
28 bitwuzla_set_option(options, BITWUZLA_OPT_PRODUCE_MODELS, 1);
29 //! [docs-c-quickstart-2 end]
30 // Now, for illustration purposes, we enable CaDiCaL as SAT solver
31 // (CaDiCaL is already configured by default).
32 // Note: This will silently fall back to one of the compiled in SAT solvers
33 // if the selected solver is not compiled in.
34 //! [docs-c-quickstart-3 start]
35 bitwuzla_set_option_mode(options, BITWUZLA_OPT_SAT_SOLVER, "cadical");
36 //! [docs-c-quickstart-3 end]
37 // Then, create a Bitwuzla instance.
38 //! [docs-c-quickstart-4 start]
39 Bitwuzla *bitwuzla = bitwuzla_new(tm, options);
40 //! [docs-c-quickstart-4 end]
41
42 //! [docs-c-quickstart-5 start]
43 // Create bit-vector sorts of size 4 and 8.
44 BitwuzlaSort sortbv4 = bitwuzla_mk_bv_sort(tm, 4);
45 BitwuzlaSort sortbv8 = bitwuzla_mk_bv_sort(tm, 8);
46 // Create function sort.
47 BitwuzlaSort domain[2] = {sortbv8, sortbv4};
48 BitwuzlaSort sortfun = bitwuzla_mk_fun_sort(tm, 2, domain, sortbv8);
49 // Create array sort.
50 BitwuzlaSort sortarr = bitwuzla_mk_array_sort(tm, sortbv8, sortbv8);
51
52 // Create two bit-vector constants of that sort.
53 BitwuzlaTerm x = bitwuzla_mk_const(tm, sortbv8, "x");
54 BitwuzlaTerm y = bitwuzla_mk_const(tm, sortbv8, "y");
55 // Create fun const.
56 BitwuzlaTerm f = bitwuzla_mk_const(tm, sortfun, "f");
57 // Create array const.
58 BitwuzlaTerm a = bitwuzla_mk_const(tm, sortarr, "a");
59 // Create bit-vector values one and two of the same sort.
60 BitwuzlaTerm one = bitwuzla_mk_bv_one(tm, sortbv8);
61 // Alternatively, you can create bit-vector value one with:
62 // BitwuzlaTerm one = bitwuzla_mk_bv_value(tm, sortbv8, "1", 2);
63 // BitwuzlaTerm one = bitwuzla_mk_bv_value_uint64(tm, sortbv8, 1);
64 BitwuzlaTerm two = bitwuzla_mk_bv_value_uint64(tm, sortbv8, 2);
65
66 // (bvsdiv x (_ bv2 8))
67 BitwuzlaTerm sdiv = bitwuzla_mk_term2(tm, BITWUZLA_KIND_BV_SDIV, x, two);
68 // (bvashr y (_ bv1 8))
69 BitwuzlaTerm ashr = bitwuzla_mk_term2(tm, BITWUZLA_KIND_BV_ASHR, y, one);
70 // ((_ extract 3 0) (bvsdiv x (_ bv2 8)))
71 BitwuzlaTerm sdive =
72 bitwuzla_mk_term1_indexed2(tm, BITWUZLA_KIND_BV_EXTRACT, sdiv, 3, 0);
73 // ((_ extract 3 0) (bvashr x (_ bv1 8)))
74 BitwuzlaTerm ashre =
75 bitwuzla_mk_term1_indexed2(tm, BITWUZLA_KIND_BV_EXTRACT, ashr, 3, 0);
76
77 // (assert
78 // (distinct
79 // ((_ extract 3 0) (bvsdiv x (_ bv2 8)))
80 // ((_ extract 3 0) (bvashr y (_ bv1 8)))))
81 bitwuzla_assert(bitwuzla,
82 bitwuzla_mk_term2(tm, BITWUZLA_KIND_DISTINCT, sdive, ashre));
83 // (assert (= (f x ((_ extract 6 3) x)) y))
84 bitwuzla_assert(
85 bitwuzla,
86 bitwuzla_mk_term2(
87 tm,
88 BITWUZLA_KIND_EQUAL,
89 bitwuzla_mk_term3(tm,
90 BITWUZLA_KIND_APPLY,
91 f,
92 x,
93 bitwuzla_mk_term1_indexed2(
94 tm, BITWUZLA_KIND_BV_EXTRACT, x, 6, 3)),
95 y));
96 // (assert (= (select a x) y))
97 bitwuzla_assert(
98 bitwuzla,
99 bitwuzla_mk_term2(tm,
100 BITWUZLA_KIND_EQUAL,
101 bitwuzla_mk_term2(tm, BITWUZLA_KIND_ARRAY_SELECT, a, x),
102 y));
103 //! [docs-c-quickstart-5 end]
104
105 // (check-sat)
106 //! [docs-c-quickstart-6 start]
107 BitwuzlaResult result = bitwuzla_check_sat(bitwuzla);
108 //! [docs-c-quickstart-6 end]
109
110 printf("Expect: sat\n");
111 printf("Bitwuzla: %s\n\n", bitwuzla_result_to_string(result));
112
113 // Print model in SMT-LIBv2 format.
114 //! [docs-c-quickstart-7 start]
115 printf("Model:\n");
116 BitwuzlaTerm decls[4] = {x, y, f, a};
117 printf("(\n");
118 for (uint32_t i = 0; i < 4; ++i)
119 {
120 BitwuzlaSort sort = bitwuzla_term_get_sort(decls[i]);
121 printf(" (define-fun %s (", bitwuzla_term_get_symbol(decls[i]));
122 if (bitwuzla_sort_is_fun(sort))
123 {
124 BitwuzlaTerm value = bitwuzla_get_value(bitwuzla, decls[i]);
125 size_t size;
126 BitwuzlaTerm *children = bitwuzla_term_get_children(value, &size);
127 assert(size == 2);
128 while (bitwuzla_term_get_kind(children[1]) == BITWUZLA_KIND_LAMBDA)
129 {
130 assert(bitwuzla_term_is_var(children[0]));
131 printf("(%s %s) ",
132 bitwuzla_term_to_string(children[0]),
133 bitwuzla_sort_to_string(bitwuzla_term_get_sort(children[0])));
134 value = children[1];
135 children = bitwuzla_term_get_children(value, &size);
136 }
137 assert(bitwuzla_term_is_var(children[0]));
138 // Note: The returned string of bitwuzla_term_to_string and
139 // bitwuzla_sort_to_string does not have to be freed, but is only
140 // valid until the next call to the respective function. Thus we
141 // split printing into separate printf calls so that none of these
142 // functions is called more than once in one printf call.
143 // Alternatively, we could also first get and copy the strings, use
144 // a single printf call, and then free the copied strings.
145 printf("(%s %s))",
146 bitwuzla_term_to_string(children[0]),
147 bitwuzla_sort_to_string(bitwuzla_term_get_sort(children[0])));
148 printf(" %s",
149 bitwuzla_sort_to_string(bitwuzla_sort_fun_get_codomain(sort)));
150 printf(" %s)\n", bitwuzla_term_to_string(children[1]));
151 }
152 else
153 {
154 printf(") %s %s)\n",
155 bitwuzla_sort_to_string(sort),
156 bitwuzla_term_to_string(bitwuzla_get_value(bitwuzla, decls[i])));
157 }
158 }
159 printf(")\n");
160 printf("\n");
161 //! [docs-c-quickstart-7 end]
162
163 // Print value for x, y, f and a.
164 // Note: The returned string of bitwuzla_term_value_get_str is only valid
165 // until the next call to bitwuzla_term_value_get_str
166 //! [docs-c-quickstart-8 start]
167 // Both x and y are bit-vector terms and their value is a bit-vector
168 // value that can be printed via bitwuzla_term_value_get_str().
169 printf("value of x: %s\n",
170 bitwuzla_term_value_get_str(bitwuzla_get_value(bitwuzla, x)));
171 printf("value of y: %s\n",
172 bitwuzla_term_value_get_str(bitwuzla_get_value(bitwuzla, y)));
173 printf("\n");
174 //! [docs-c-quickstart-8 end]
175 //! [docs-c-quickstart-9 start]
176 // f and a, on the other hand, are a function and array term, respectively.
177 // The value of these terms is not a value term: for f, it is a lambda term,
178 // and the value of a is represented as a store term. Thus we cannot use
179 // bitwuzla_term_value_get_str(), but we can print the value of the terms
180 // via bitwuzla_term_to_string().
181 printf("to_string representation of value of f:\n%s\n\n",
182 bitwuzla_term_to_string(bitwuzla_get_value(bitwuzla, f)));
183 printf("to_string representation of value of a:\n%s\n",
184 bitwuzla_term_to_string(bitwuzla_get_value(bitwuzla, a)));
185 printf("\n");
186 //! [docs-c-quickstart-9 end]
187 // Note that the assignment string of bit-vector terms is given as the
188 // pure assignment string, either in binary, hexadecimal or decimal format,
189 // whereas bitwuzla_term_to_string() prints the value in SMT-LIB2 format
190 // (in binary number format).
191 //! [docs-c-quickstart-10 start]
192 printf("to_string representation of value of x: %s\n",
193 bitwuzla_term_to_string(bitwuzla_get_value(bitwuzla, x)));
194 printf("to_string representation of value of y: %s\n",
195 bitwuzla_term_to_string(bitwuzla_get_value(bitwuzla, y)));
196 printf("\n");
197 //! [docs-c-quickstart-10 end]
198
199 // Query value of bit-vector term that does not occur in the input formula
200 //! [docs-c-quickstart-11 start]
201 BitwuzlaTerm v = bitwuzla_get_value(
202 bitwuzla, bitwuzla_mk_term2(tm, BITWUZLA_KIND_BV_MUL, x, x));
203 printf("value of v = x * x: %s\n",
204 bitwuzla_term_value_get_str(bitwuzla_get_value(bitwuzla, v)));
205 //! [docs-c-quickstart-11 end]
206
207 // Finally, delete the Bitwuzla solver, options, and term manager instances.
208 //! [docs-c-quickstart-12 start]
209 bitwuzla_delete(bitwuzla);
210 bitwuzla_options_delete(options);
211 bitwuzla_term_manager_delete(tm);
212 //! [docs-c-quickstart-12 end]
213
214 return 0;
215}
1(set-logic QF_ABV)
2(set-option :produce-models true)
3(declare-const x (_ BitVec 8))
4(declare-const y (_ BitVec 8))
5(declare-fun f ((_ BitVec 8) (_ BitVec 4)) (_ BitVec 8))
6(declare-const a (Array (_ BitVec 8) (_ BitVec 8)))
7(assert
8 (distinct
9 ((_ extract 3 0) (bvsdiv x (_ bv2 8)))
10 ((_ extract 3 0) (bvashr y (_ bv1 8)))))
11(assert (= (f x ((_ extract 6 3) x)) y))
12(assert (= (select a x) y))
13(check-sat)
14(get-model)
15(get-value (x y f a (bvmul x x)))
16(exit)
Options Example
1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == '__main__':
14
15 # First, create a Bitwuzla options instance.
16 options = Options()
17
18 # Enable model generation, which expects a boolean configuration value.
19 options.set(Option.PRODUCE_MODELS, True)
20
21 # Increase the verbosity level, which expects an integer value.
22 print(f'Previous verbosity level: {options.get(Option.VERBOSITY)}')
23 options.set(Option.VERBOSITY, 2)
24 print(f'Current verbosity level: {options.get(Option.VERBOSITY)}')
25
26 # Now configure an option that has modes (a choice of configuration values).
27 # First, query which bit-vector solver engine is set.
28 print(f'Default bv solver: {options.get(Option.BV_SOLVER)}')
29 # Then, select the propagation-based local search engine as solver engine.
30 options.set(Option.BV_SOLVER, 'prop')
31 print(f'Current engine: {options.get(Option.BV_SOLVER)}')
32
33 # Now, create a Bitwuzla instance.
34 tm = TermManager()
35 bitwuzla = Bitwuzla(tm, options)
36 # Check sat (nothing to solve, input formula is empty).
37 result = bitwuzla.check_sat()
38 print('Expect: sat')
39 print(f'Bitwuzla: {result}')
1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == '__main__':
14
15 # First, create a Bitwuzla options instance.
16 options = Options()
17
18 # Enable model generation, which expects a boolean configuration value.
19 options.set(Option.PRODUCE_MODELS, True)
20
21 # Increase the verbosity level, which expects an integer value.
22 print(f'Previous verbosity level: {options.get(Option.VERBOSITY)}')
23 options.set(Option.VERBOSITY, 2)
24 print(f'Current verbosity level: {options.get(Option.VERBOSITY)}')
25
26 # Now configure an option that has modes (a choice of configuration values).
27 # First, query which bit-vector solver engine is set.
28 print(f'Default bv solver: {options.get(Option.BV_SOLVER)}')
29 # Then, select the propagation-based local search engine as solver engine.
30 options.set(Option.BV_SOLVER, 'prop')
31 print(f'Current engine: {options.get(Option.BV_SOLVER)}')
32
33 # Now, create a Bitwuzla instance.
34 tm = TermManager()
35 bitwuzla = Bitwuzla(tm, options)
36 # Check sat (nothing to solve, input formula is empty).
37 result = bitwuzla.check_sat()
38 print('Expect: sat')
39 print(f'Bitwuzla: {result}')
1/***
2 * Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3 *
4 * Copyright (C) 2021 by the authors listed in the AUTHORS file at
5 * https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6 *
7 * This file is part of Bitwuzla under the MIT license. See COPYING for more
8 * information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
9 */
10
11#include <bitwuzla/c/bitwuzla.h>
12#include <inttypes.h>
13#include <stdio.h>
14
15int
16main()
17{
18 // First, create a term manager instance.
19 BitwuzlaTermManager* tm = bitwuzla_term_manager_new();
20 // Create a Bitwuzla options instance.
21 BitwuzlaOptions* options = bitwuzla_options_new();
22
23 // Enable model generation, which expects a boolean configuration value.
24 bitwuzla_set_option(options, BITWUZLA_OPT_PRODUCE_MODELS, 1);
25
26 // Increase the verbosity level, which expects an integer value.
27 printf("Previous verbosity level: %" PRIu64 "\n",
28 bitwuzla_get_option(options, BITWUZLA_OPT_VERBOSITY));
29 bitwuzla_set_option(options, BITWUZLA_OPT_VERBOSITY, 2);
30 printf("Current verbosity level: %" PRIu64 "\n",
31 bitwuzla_get_option(options, BITWUZLA_OPT_VERBOSITY));
32
33 // Now configure an option that has modes (a choice of configuration values).
34 // First, query which bit-vector solver engine is set.
35 printf("Default bv solver: %s\n",
36 bitwuzla_get_option_mode(options, BITWUZLA_OPT_BV_SOLVER));
37 // Then, select the propagation-based local search engine as solver engine.
38 bitwuzla_set_option_mode(options, BITWUZLA_OPT_BV_SOLVER, "prop");
39 printf("Current engine: %s\n",
40 bitwuzla_get_option_mode(options, BITWUZLA_OPT_BV_SOLVER));
41
42 // Now, create a Bitwuzla instance.
43 Bitwuzla* bitwuzla = bitwuzla_new(tm, options);
44 // Check sat (nothing to solve, input formula is empty).
45 BitwuzlaResult result = bitwuzla_check_sat(bitwuzla);
46 printf("Expect: sat\n");
47 printf("Bitwuzla: %s\n", bitwuzla_result_to_string(result));
48
49 // Finally, delete the Bitwuzla solver, options, and term manager instances.
50 bitwuzla_delete(bitwuzla);
51 bitwuzla_options_delete(options);
52 bitwuzla_term_manager_delete(tm);
53
54 return 0;
55}
1(set-option :verbosity 2)
2(set-option :bv-solver "prop")
3(set-option :produce-models true)
4(set-logic ALL)
5(check-sat)
Option Info Example
BitwuzlaOptionInfo
. 1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == '__main__':
14
15 # First, create a Bitwuzla options instance.
16 options = Options()
17
18 # Set some options to illustrate current vs default value.
19 options.set(Option.PRODUCE_MODELS, True)
20 options.set(Option.VERBOSITY, 2)
21 options.set(Option.BV_SOLVER, 'prop')
22
23 # Then iterate over all available configuration options and extract info.
24 for opt in Option:
25 info = OptionInfo(options, opt)
26 print(f' long name: {info.lng()}')
27 print(f' short name: {info.shrt() if info.shrt() else "-"}')
28 print(' kind: ', end = '')
29 if info.kind() == OptionInfoKind.BOOL:
30 print('bool')
31 print(' values:')
32 print(f' + current: {info.cur()}')
33 print(f' + default: {info.dflt()}')
34 elif info.kind() == OptionInfoKind.NUMERIC:
35 print('numeric')
36 print(' values:')
37 print(f' + current: {info.cur()}')
38 print(f' + default: {info.dflt()}')
39 print(f' + min: {info.min()}')
40 print(f' + max: {info.max()}')
41 else:
42 print('modes')
43 print(' values:')
44 print(f' + current: {info.cur()}')
45 print(f' + default: {info.dflt()}')
46 print(f' + modes: {info.modes()}')
47 print(f' description: {info.description()}\n')
1/***
2 * Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3 *
4 * Copyright (C) 2023 by the authors listed in the AUTHORS file at
5 * https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6 *
7 * This file is part of Bitwuzla under the MIT license. See COPYING for more
8 * information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
9 */
10
11#include <bitwuzla/cpp/bitwuzla.h>
12
13#include <iostream>
14
15using namespace bitwuzla;
16
17int
18main()
19{
20 // First, create a Bitwuzla options instance.
21 Options options;
22 // Set some options to illustrate current vs default value.
23 options.set(Option::PRODUCE_MODELS, true);
24 options.set(Option::VERBOSITY, 2);
25 options.set(Option::BV_SOLVER, "prop");
26
27 // Then iterate over all available configuration options and extract info.
28 for (int32_t i = 0; i < static_cast<int32_t>(Option::NUM_OPTS); ++i)
29 {
30 Option opt = static_cast<Option>(i);
31 OptionInfo info(options, opt);
32 std::cout << "- long name: " << info.lng << std::endl;
33 std::cout << " short name: " << (info.shrt ? info.shrt : "-")
34 << std::endl;
35 std::cout << " kind: ";
36 if (info.kind == OptionInfo::Kind::BOOL)
37 {
38 std::cout << "bool" << std::endl;
39 std::cout << " values:" << std::endl;
40 const auto& values = std::get<OptionInfo::Bool>(info.values);
41 std::cout << " + current: " << (values.cur ? "true" : "false")
42 << std::endl;
43 std::cout << " + default: " << (values.dflt ? "true" : "false")
44 << std::endl;
45 }
46 else if (info.kind == OptionInfo::Kind::NUMERIC)
47 {
48 std::cout << "numeric" << std::endl;
49 std::cout << " values:" << std::endl;
50 const auto& values = std::get<OptionInfo::Numeric>(info.values);
51 std::cout << " + current: " << values.dflt << std::endl;
52 std::cout << " + default: " << values.cur << std::endl;
53 std::cout << " + min: " << values.min << std::endl;
54 std::cout << " + max: " << values.max << std::endl;
55 }
56 else
57 {
58 std::cout << "modes" << std::endl;
59 std::cout << " values:" << std::endl;
60 const auto& values = std::get<OptionInfo::Mode>(info.values);
61 std::cout << " + current: " << values.dflt << std::endl;
62 std::cout << " + default: " << values.cur << std::endl;
63 std::cout << " + modes: {";
64 for (size_t i = 0, n = values.modes.size(); i < n; ++i)
65 {
66 std::cout << (i > 0 ? "," : "") << " " << values.modes[i];
67 }
68 std::cout << " }" << std::endl;
69 }
70 std::cout << " description: " << info.description << std::endl;
71 std::cout << std::endl;
72 }
73}
1/***
2 * Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3 *
4 * Copyright (C) 2023 by the authors listed in the AUTHORS file at
5 * https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6 *
7 * This file is part of Bitwuzla under the MIT license. See COPYING for more
8 * information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
9 */
10
11#include <bitwuzla/c/bitwuzla.h>
12#include <inttypes.h>
13#include <stdio.h>
14
15int
16main()
17{
18 // First, create a Bitwuzla options instance.
19 BitwuzlaOptions* options = bitwuzla_options_new();
20 // Set some options to illustrate current vs default value.
21 bitwuzla_set_option(options, BITWUZLA_OPT_PRODUCE_MODELS, 1);
22 bitwuzla_set_option(options, BITWUZLA_OPT_VERBOSITY, 2);
23 bitwuzla_set_option_mode(options, BITWUZLA_OPT_BV_SOLVER, "prop");
24
25 // Then iterate over all available configuration options and extract info.
26 BitwuzlaOptionInfo info;
27 for (uint32_t i = 0; i < BITWUZLA_OPT_NUM_OPTS; ++i)
28 {
29 BitwuzlaOption opt = (BitwuzlaOption) i;
30 bitwuzla_get_option_info(options, opt, &info);
31 printf("- long name: %s\n", info.lng);
32 printf(" short name: %s\n", (info.shrt ? info.shrt : "-"));
33 printf(" kind: ");
34 if (info.is_numeric)
35 {
36 printf("numeric\n");
37 printf(" values:\n");
38 printf(" + current: %" PRIu64 "\n", info.numeric.cur);
39 printf(" + default: %" PRIu64 "\n", info.numeric.dflt);
40 printf(" + min: %" PRIu64 "\n", info.numeric.min);
41 printf(" + max: %" PRIu64 "\n", info.numeric.max);
42 }
43 else
44 {
45 printf("modes\n");
46 printf(" values:\n");
47 printf(" + current: %s\n", info.mode.cur);
48 printf(" + default: %s\n", info.mode.dflt);
49 printf(" + modes: {");
50 for (size_t i = 0, n = info.mode.num_modes; i < n; ++i)
51 {
52 printf("%s %s", (i > 0 ? "," : ""), info.mode.modes[i]);
53 }
54 printf(" }\n");
55 }
56 printf(" description: %s\n\n", info.description);
57 }
58
59 // Finally, delete options instance.
60 bitwuzla_options_delete(options);
61}
Incremental Example with push and pop
push
and pop
. 1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == "__main__":
14
15 # No options configured, create Bitwuzla instance with default options.
16 tm = TermManager()
17 bitwuzla = Bitwuzla(tm)
18
19 # Create a bit-vector sort of size 1.
20 sortbv1 = tm.mk_bv_sort(1)
21 # Create a bit-vector sort of size 2.
22 sortbv2 = tm.mk_bv_sort(2)
23
24 # Create bit-vector variables.
25 # (declare-const o0 (_ BitVec 1))
26 o0 = tm.mk_const(sortbv1, 'o0')
27 # (declare-const o1 (_ BitVec 1))
28 o1 = tm.mk_const(sortbv1, 'o1')
29 # (declare-const s0 (_ BitVec 2))
30 s0 = tm.mk_const(sortbv2, 's0')
31 # (declare-const s1 (_ BitVec 2))
32 s1 = tm.mk_const(sortbv2, 's1')
33 # (declare-const s2 (_ BitVec 2))
34 s2 = tm.mk_const(sortbv2, 's2')
35 # (declare-const goal (_ BitVec 2))
36 goal = tm.mk_const(sortbv2, 'goal')
37
38 # Create bit-vector values zero, one, three.
39 zero = tm.mk_bv_zero(sortbv2)
40 one1 = tm.mk_bv_one(sortbv1)
41 one2 = tm.mk_bv_one(sortbv2)
42 three = tm.mk_bv_value(sortbv2, 3)
43
44 # Add some assertions.
45 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [s0, zero]))
46 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [goal, three]))
47
48 # Push, assert, check sat and pop.
49 bitwuzla.push(1)
50 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [s0, goal]))
51 result = bitwuzla.check_sat()
52 print('Expect: unsat')
53 print(f'Bitwuzla: {result}')
54 bitwuzla.pop(1)
55
56 # (assert (= s1 (ite (= o0 (_ sortbv1 1)) (bvadd s0 one) s0)))
57 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL,
58 [s1,
59 tm.mk_term(Kind.ITE,
60 [tm.mk_term(Kind.EQUAL, [o0, one1]),
61 tm.mk_term(Kind.BV_ADD, [s0, one2]),
62 s0])]))
63
64 # Push, assert, check sat and pop.
65 bitwuzla.push(1)
66 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [s1, goal]))
67 result = bitwuzla.check_sat()
68 print('Expect: unsat')
69 print(f'Bitwuzla: {result}')
70 bitwuzla.pop(1)
71
72 # (assert (= s2 (ite (= o1 (_ sortbv1 1)) (bvadd s1 one) s1)))
73 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL,
74 [s2,
75 tm.mk_term(Kind.ITE,
76 [tm.mk_term(Kind.EQUAL, [o1, one1]),
77 tm.mk_term(Kind.BV_ADD, [s1, one2]),
78 s1])]))
79
80 # Push, assert, check sat and pop.
81 bitwuzla.push(1)
82 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [s2, goal]))
83 result = bitwuzla.check_sat()
84 print('Expect: unsat')
85 print(f'Bitwuzla: {result}')
86 bitwuzla.pop(1)
1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == "__main__":
14
15 # No options configured, create Bitwuzla instance with default options.
16 tm = TermManager()
17 bitwuzla = Bitwuzla(tm)
18
19 # Create a bit-vector sort of size 1.
20 sortbv1 = tm.mk_bv_sort(1)
21 # Create a bit-vector sort of size 2.
22 sortbv2 = tm.mk_bv_sort(2)
23
24 # Create bit-vector variables.
25 # (declare-const o0 (_ BitVec 1))
26 o0 = tm.mk_const(sortbv1, 'o0')
27 # (declare-const o1 (_ BitVec 1))
28 o1 = tm.mk_const(sortbv1, 'o1')
29 # (declare-const s0 (_ BitVec 2))
30 s0 = tm.mk_const(sortbv2, 's0')
31 # (declare-const s1 (_ BitVec 2))
32 s1 = tm.mk_const(sortbv2, 's1')
33 # (declare-const s2 (_ BitVec 2))
34 s2 = tm.mk_const(sortbv2, 's2')
35 # (declare-const goal (_ BitVec 2))
36 goal = tm.mk_const(sortbv2, 'goal')
37
38 # Create bit-vector values zero, one, three.
39 zero = tm.mk_bv_zero(sortbv2)
40 one1 = tm.mk_bv_one(sortbv1)
41 one2 = tm.mk_bv_one(sortbv2)
42 three = tm.mk_bv_value(sortbv2, 3)
43
44 # Add some assertions.
45 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [s0, zero]))
46 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [goal, three]))
47
48 # Push, assert, check sat and pop.
49 bitwuzla.push(1)
50 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [s0, goal]))
51 result = bitwuzla.check_sat()
52 print('Expect: unsat')
53 print(f'Bitwuzla: {result}')
54 bitwuzla.pop(1)
55
56 # (assert (= s1 (ite (= o0 (_ sortbv1 1)) (bvadd s0 one) s0)))
57 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL,
58 [s1,
59 tm.mk_term(Kind.ITE,
60 [tm.mk_term(Kind.EQUAL, [o0, one1]),
61 tm.mk_term(Kind.BV_ADD, [s0, one2]),
62 s0])]))
63
64 # Push, assert, check sat and pop.
65 bitwuzla.push(1)
66 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [s1, goal]))
67 result = bitwuzla.check_sat()
68 print('Expect: unsat')
69 print(f'Bitwuzla: {result}')
70 bitwuzla.pop(1)
71
72 # (assert (= s2 (ite (= o1 (_ sortbv1 1)) (bvadd s1 one) s1)))
73 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL,
74 [s2,
75 tm.mk_term(Kind.ITE,
76 [tm.mk_term(Kind.EQUAL, [o1, one1]),
77 tm.mk_term(Kind.BV_ADD, [s1, one2]),
78 s1])]))
79
80 # Push, assert, check sat and pop.
81 bitwuzla.push(1)
82 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [s2, goal]))
83 result = bitwuzla.check_sat()
84 print('Expect: unsat')
85 print(f'Bitwuzla: {result}')
86 bitwuzla.pop(1)
1/***
2 * Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3 *
4 * Copyright (C) 2021 by the authors listed in the AUTHORS file at
5 * https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6 *
7 * This file is part of Bitwuzla under the MIT license. See COPYING for more
8 * information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
9 */
10
11#include <bitwuzla/c/bitwuzla.h>
12#include <stdio.h>
13
14int
15main()
16{
17 // First, create a term manager instance.
18 BitwuzlaTermManager* tm = bitwuzla_term_manager_new();
19 // Create a Bitwuzla options instance.
20 BitwuzlaOptions* options = bitwuzla_options_new();
21 // Then, create a Bitwuzla instance.
22 Bitwuzla* bitwuzla = bitwuzla_new(tm, options);
23
24 // Create a bit-vector sort of size 1.
25 BitwuzlaSort sortbv1 = bitwuzla_mk_bv_sort(tm, 1);
26 // Create a bit-vector sort of size 2.
27 BitwuzlaSort sortbv2 = bitwuzla_mk_bv_sort(tm, 2);
28
29 // Create bit-vector variables.
30 // (declare-const o0 (_ BitVec 1))
31 BitwuzlaTerm o0 = bitwuzla_mk_const(tm, sortbv1, "o0");
32 // (declare-const o1 (_ BitVec 1))
33 BitwuzlaTerm o1 = bitwuzla_mk_const(tm, sortbv1, "o1");
34 // (declare-const s0 (_ BitVec 2))
35 BitwuzlaTerm s0 = bitwuzla_mk_const(tm, sortbv2, "s0");
36 // (declare-const s1 (_ BitVec 2))
37 BitwuzlaTerm s1 = bitwuzla_mk_const(tm, sortbv2, "s1");
38 // (declare-const s2 (_ BitVec 2))
39 BitwuzlaTerm s2 = bitwuzla_mk_const(tm, sortbv2, "s2");
40 // (declare-const goal (_ BitVec 2))
41 BitwuzlaTerm goal = bitwuzla_mk_const(tm, sortbv2, "goal");
42
43 // Create bit-vector values zero, one, three.
44 BitwuzlaTerm zero = bitwuzla_mk_bv_zero(tm, sortbv2);
45 BitwuzlaTerm one1 = bitwuzla_mk_bv_one(tm, sortbv1);
46 BitwuzlaTerm one2 = bitwuzla_mk_bv_one(tm, sortbv2);
47 BitwuzlaTerm three = bitwuzla_mk_bv_value_uint64(tm, sortbv2, 3);
48
49 // Add some assertions.
50 bitwuzla_assert(bitwuzla,
51 bitwuzla_mk_term2(tm, BITWUZLA_KIND_EQUAL, s0, zero));
52 bitwuzla_assert(bitwuzla,
53 bitwuzla_mk_term2(tm, BITWUZLA_KIND_EQUAL, goal, three));
54
55 // Push, assert, check sat and pop.
56 bitwuzla_push(bitwuzla, 1);
57 bitwuzla_assert(bitwuzla,
58 bitwuzla_mk_term2(tm, BITWUZLA_KIND_EQUAL, s0, goal));
59 BitwuzlaResult result = bitwuzla_check_sat(bitwuzla);
60 printf("Expect: unsat\n");
61 printf("Bitwuzla: %s\n", bitwuzla_result_to_string(result));
62 bitwuzla_pop(bitwuzla, 1);
63
64 // (assert (= s1 (ite (= o0 (_ sortbv1 1)) (bvadd s0 one) s0)))
65 bitwuzla_assert(bitwuzla,
66 bitwuzla_mk_term2(
67 tm,
68 BITWUZLA_KIND_EQUAL,
69 s1,
70 bitwuzla_mk_term3(
71 tm,
72 BITWUZLA_KIND_ITE,
73 bitwuzla_mk_term2(tm, BITWUZLA_KIND_EQUAL, o0, one1),
74 bitwuzla_mk_term2(tm, BITWUZLA_KIND_BV_ADD, s0, one2),
75 s0)));
76
77 // Push, assert, check sat and pop.
78 bitwuzla_push(bitwuzla, 1);
79 bitwuzla_assert(bitwuzla,
80 bitwuzla_mk_term2(tm, BITWUZLA_KIND_EQUAL, s1, goal));
81 result = bitwuzla_check_sat(bitwuzla);
82 printf("Expect: unsat\n");
83 printf("Bitwuzla: %s\n", bitwuzla_result_to_string(result));
84 bitwuzla_pop(bitwuzla, 1);
85
86 // (assert (= s2 (ite (= o1 (_ sortbv1 1)) (bvadd s1 one) s1)))
87 bitwuzla_assert(bitwuzla,
88 bitwuzla_mk_term2(
89 tm,
90 BITWUZLA_KIND_EQUAL,
91 s2,
92 bitwuzla_mk_term3(
93 tm,
94 BITWUZLA_KIND_ITE,
95 bitwuzla_mk_term2(tm, BITWUZLA_KIND_EQUAL, o1, one1),
96 bitwuzla_mk_term2(tm, BITWUZLA_KIND_BV_ADD, s1, one2),
97 s1)));
98
99 // Push, assert, check sat and pop.
100 bitwuzla_push(bitwuzla, 1);
101 bitwuzla_assert(bitwuzla,
102 bitwuzla_mk_term2(tm, BITWUZLA_KIND_EQUAL, s2, goal));
103 result = bitwuzla_check_sat(bitwuzla);
104 printf("Expect: unsat\n");
105 printf("Bitwuzla: %s\n", bitwuzla_result_to_string(result));
106 bitwuzla_pop(bitwuzla, 1);
107
108 // Finally, delete the Bitwuzla solver, options, and term manager instances.
109 bitwuzla_delete(bitwuzla);
110 bitwuzla_options_delete(options);
111 bitwuzla_term_manager_delete(tm);
112
113 return 0;
114}
1(set-logic QF_BV)
2
3(declare-fun o0 () (_ BitVec 1))
4(declare-fun o1 () (_ BitVec 1))
5(declare-fun s0 () (_ BitVec 2))
6(declare-fun s1 () (_ BitVec 2))
7(declare-fun s2 () (_ BitVec 2))
8(declare-fun goal () (_ BitVec 2))
9
10(assert (= s0 (_ bv0 2)))
11(assert (= goal (_ bv3 2)))
12(push 1)
13(assert (= s0 goal))
14(check-sat)
15(pop 1)
16
17(assert (= s1 (ite (= o0 (_ bv1 1)) (bvadd s0 (_ bv1 2)) s0)))
18(push 1)
19(assert (= s1 goal))
20(check-sat)
21(pop 1)
22
23(assert (= s2 (ite (= o1 (_ bv1 1)) (bvadd s1 (_ bv1 2)) s1)))
24(push 1)
25(assert (= s2 goal))
26(check-sat)
27(pop 1)
Incremental Example with check-sat-assuming
check-sat-assuming
. 1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == "__main__":
14
15 # No options configured, create Bitwuzla instance with default options.
16 tm = TermManager()
17 bitwuzla = Bitwuzla(tm)
18
19 # Create a bit-vector sort of size 1.
20 sortbv1 = tm.mk_bv_sort(1)
21 # Create a bit-vector sort of size 2
22 sortbv2 = tm.mk_bv_sort(2)
23
24 # Create bit-vector variables.
25 # (declare-const o0 (_ BitVec 1))
26 o0 = tm.mk_const(sortbv1, 'o0')
27 # (declare-const o1 (_ BitVec 1))
28 o1 = tm.mk_const(sortbv1, 'o1')
29 # (declare-const s0 (_ BitVec 2))
30 s0 = tm.mk_const(sortbv2, 's0')
31 # (declare-const s1 (_ BitVec 2))
32 s1 = tm.mk_const(sortbv2, 's1')
33 # (declare-const s2 (_ BitVec 2))
34 s2 = tm.mk_const(sortbv2, 's2')
35 # (declare-const goal (_ BitVec 2))
36 goal = tm.mk_const(sortbv2, 'goal')
37
38 # Create bit-vector values zero, one, three.
39 zero = tm.mk_bv_zero(sortbv2)
40 one1 = tm.mk_bv_one(sortbv1)
41 one2 = tm.mk_bv_one(sortbv2)
42 three = tm.mk_bv_value(sortbv2, 3)
43
44 # Add some assertions.
45 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [s0, zero]))
46 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [goal, three]))
47
48 # (check-sat-assuming ((= s0 goal)))
49 result = bitwuzla.check_sat(tm.mk_term(Kind.EQUAL, [s0, goal]))
50 print('Expect: unsat')
51 print(f'Bitwuzla: {result}')
52
53 # (assert (= s1 (ite (= o0 (_ sortbv1 1)) (bvadd s0 one) s0)))
54 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL,
55 [s1,
56 tm.mk_term(Kind.ITE,
57 [tm.mk_term(Kind.EQUAL, [o0, one1]),
58 tm.mk_term(Kind.BV_ADD, [s0, one2]),
59 s0])]))
60
61 # (check-sat-assuming ((= s1 goal)))
62 result = bitwuzla.check_sat(tm.mk_term(Kind.EQUAL, [s1, goal]))
63 print('Expect: unsat')
64 print(f'Bitwuzla: {result}')
65
66 # (assert (= s2 (ite (= o1 (_ sortbv1 1)) (bvadd s1 one) s1)))
67 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL,
68 [s2,
69 tm.mk_term(Kind.ITE,
70 [tm.mk_term(Kind.EQUAL, [o1, one1]),
71 tm.mk_term(Kind.BV_ADD, [s1, one2]),
72 s1])]))
73
74 # (check-sat-assuming ((= s2 goal)))
75 result = bitwuzla.check_sat(tm.mk_term(Kind.EQUAL, [s2, goal]))
76 print('Expect: unsat')
77 print(f'Bitwuzla: {result}')
1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == "__main__":
14
15 # No options configured, create Bitwuzla instance with default options.
16 tm = TermManager()
17 bitwuzla = Bitwuzla(tm)
18
19 # Create a bit-vector sort of size 1.
20 sortbv1 = tm.mk_bv_sort(1)
21 # Create a bit-vector sort of size 2
22 sortbv2 = tm.mk_bv_sort(2)
23
24 # Create bit-vector variables.
25 # (declare-const o0 (_ BitVec 1))
26 o0 = tm.mk_const(sortbv1, 'o0')
27 # (declare-const o1 (_ BitVec 1))
28 o1 = tm.mk_const(sortbv1, 'o1')
29 # (declare-const s0 (_ BitVec 2))
30 s0 = tm.mk_const(sortbv2, 's0')
31 # (declare-const s1 (_ BitVec 2))
32 s1 = tm.mk_const(sortbv2, 's1')
33 # (declare-const s2 (_ BitVec 2))
34 s2 = tm.mk_const(sortbv2, 's2')
35 # (declare-const goal (_ BitVec 2))
36 goal = tm.mk_const(sortbv2, 'goal')
37
38 # Create bit-vector values zero, one, three.
39 zero = tm.mk_bv_zero(sortbv2)
40 one1 = tm.mk_bv_one(sortbv1)
41 one2 = tm.mk_bv_one(sortbv2)
42 three = tm.mk_bv_value(sortbv2, 3)
43
44 # Add some assertions.
45 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [s0, zero]))
46 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [goal, three]))
47
48 # (check-sat-assuming ((= s0 goal)))
49 result = bitwuzla.check_sat(tm.mk_term(Kind.EQUAL, [s0, goal]))
50 print('Expect: unsat')
51 print(f'Bitwuzla: {result}')
52
53 # (assert (= s1 (ite (= o0 (_ sortbv1 1)) (bvadd s0 one) s0)))
54 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL,
55 [s1,
56 tm.mk_term(Kind.ITE,
57 [tm.mk_term(Kind.EQUAL, [o0, one1]),
58 tm.mk_term(Kind.BV_ADD, [s0, one2]),
59 s0])]))
60
61 # (check-sat-assuming ((= s1 goal)))
62 result = bitwuzla.check_sat(tm.mk_term(Kind.EQUAL, [s1, goal]))
63 print('Expect: unsat')
64 print(f'Bitwuzla: {result}')
65
66 # (assert (= s2 (ite (= o1 (_ sortbv1 1)) (bvadd s1 one) s1)))
67 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL,
68 [s2,
69 tm.mk_term(Kind.ITE,
70 [tm.mk_term(Kind.EQUAL, [o1, one1]),
71 tm.mk_term(Kind.BV_ADD, [s1, one2]),
72 s1])]))
73
74 # (check-sat-assuming ((= s2 goal)))
75 result = bitwuzla.check_sat(tm.mk_term(Kind.EQUAL, [s2, goal]))
76 print('Expect: unsat')
77 print(f'Bitwuzla: {result}')
1/***
2 * Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3 *
4 * Copyright (C) 2021 by the authors listed in the AUTHORS file at
5 * https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6 *
7 * This file is part of Bitwuzla under the MIT license. See COPYING for more
8 * information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
9 */
10
11#include <bitwuzla/c/bitwuzla.h>
12#include <stdio.h>
13
14int
15main()
16{
17 BitwuzlaResult result;
18
19 // First, create a term manager instance.
20 BitwuzlaTermManager* tm = bitwuzla_term_manager_new();
21 // Create a Bitwuzla options instance.
22 BitwuzlaOptions* options = bitwuzla_options_new();
23 // Then, create a Bitwuzla instance.
24 Bitwuzla* bitwuzla = bitwuzla_new(tm, options);
25
26 // Create a bit-vector sort of size 1.
27 BitwuzlaSort sortbv1 = bitwuzla_mk_bv_sort(tm, 1);
28 // Create a bit-vector sort of size 2
29 BitwuzlaSort sortbv2 = bitwuzla_mk_bv_sort(tm, 2);
30
31 // Create bit-vector variables.
32 // (declare-const o0 (_ BitVec 1))
33 BitwuzlaTerm o0 = bitwuzla_mk_const(tm, sortbv1, "o0");
34 // (declare-const o1 (_ BitVec 1))
35 BitwuzlaTerm o1 = bitwuzla_mk_const(tm, sortbv1, "o1");
36 // (declare-const s0 (_ BitVec 2))
37 BitwuzlaTerm s0 = bitwuzla_mk_const(tm, sortbv2, "s0");
38 // (declare-const s1 (_ BitVec 2))
39 BitwuzlaTerm s1 = bitwuzla_mk_const(tm, sortbv2, "s1");
40 // (declare-const s2 (_ BitVec 2))
41 BitwuzlaTerm s2 = bitwuzla_mk_const(tm, sortbv2, "s2");
42 // (declare-const goal (_ BitVec 2))
43 BitwuzlaTerm goal = bitwuzla_mk_const(tm, sortbv2, "goal");
44
45 // Create bit-vector values zero, one, three.
46 BitwuzlaTerm zero = bitwuzla_mk_bv_zero(tm, sortbv2);
47 BitwuzlaTerm one1 = bitwuzla_mk_bv_one(tm, sortbv1);
48 BitwuzlaTerm one2 = bitwuzla_mk_bv_one(tm, sortbv2);
49 BitwuzlaTerm three = bitwuzla_mk_bv_value_uint64(tm, sortbv2, 3);
50
51 // Add some assertions.
52 bitwuzla_assert(bitwuzla,
53 bitwuzla_mk_term2(tm, BITWUZLA_KIND_EQUAL, s0, zero));
54 bitwuzla_assert(bitwuzla,
55 bitwuzla_mk_term2(tm, BITWUZLA_KIND_EQUAL, goal, three));
56
57 // (check-sat-assuming ((= s0 goal)))
58 BitwuzlaTerm assumptions[1] = {
59 bitwuzla_mk_term2(tm, BITWUZLA_KIND_EQUAL, s0, goal)};
60 result = bitwuzla_check_sat_assuming(bitwuzla, 1, assumptions);
61 printf("Expect: unsat\n");
62 printf("Bitwuzla: %s\n", bitwuzla_result_to_string(result));
63
64 // (assert (= s1 (ite (= o0 (_ sortbv1 1)) (bvadd s0 one) s0)))
65 bitwuzla_assert(bitwuzla,
66 bitwuzla_mk_term2(
67 tm,
68 BITWUZLA_KIND_EQUAL,
69 s1,
70 bitwuzla_mk_term3(
71 tm,
72 BITWUZLA_KIND_ITE,
73 bitwuzla_mk_term2(tm, BITWUZLA_KIND_EQUAL, o0, one1),
74 bitwuzla_mk_term2(tm, BITWUZLA_KIND_BV_ADD, s0, one2),
75 s0)));
76
77 // (check-sat-assuming ((= s1 goal)))
78 assumptions[0] = bitwuzla_mk_term2(tm, BITWUZLA_KIND_EQUAL, s1, goal);
79 result = bitwuzla_check_sat_assuming(bitwuzla, 1, assumptions);
80 printf("Expect: unsat\n");
81 printf("Bitwuzla: %s\n", bitwuzla_result_to_string(result));
82
83 // (assert (= s2 (ite (= o1 (_ sortbv1 1)) (bvadd s1 one) s1)))
84 bitwuzla_assert(bitwuzla,
85 bitwuzla_mk_term2(
86 tm,
87 BITWUZLA_KIND_EQUAL,
88 s2,
89 bitwuzla_mk_term3(
90 tm,
91 BITWUZLA_KIND_ITE,
92 bitwuzla_mk_term2(tm, BITWUZLA_KIND_EQUAL, o1, one1),
93 bitwuzla_mk_term2(tm, BITWUZLA_KIND_BV_ADD, s1, one2),
94 s1)));
95
96 // (check-sat-assuming ((= s2 goal)))
97 assumptions[0] = bitwuzla_mk_term2(tm, BITWUZLA_KIND_EQUAL, s2, goal);
98 result = bitwuzla_check_sat_assuming(bitwuzla, 1, assumptions);
99 printf("Expect: unsat\n");
100 printf("Bitwuzla: %s\n", bitwuzla_result_to_string(result));
101
102 // Finally, delete the Bitwuzla solver, options, and term manager instances.
103 bitwuzla_delete(bitwuzla);
104 bitwuzla_options_delete(options);
105 bitwuzla_term_manager_delete(tm);
106
107 return 0;
108}
1(set-logic QF_BV)
2
3(declare-fun o0 () (_ BitVec 1))
4(declare-fun o1 () (_ BitVec 1))
5(declare-fun s0 () (_ BitVec 2))
6(declare-fun s1 () (_ BitVec 2))
7(declare-fun s2 () (_ BitVec 2))
8(declare-fun goal () (_ BitVec 2))
9
10(assert (= s0 (_ bv0 2)))
11(assert (= goal (_ bv3 2)))
12(check-sat-assuming ((= s0 goal)))
13
14(assert (= s1 (ite (= o0 (_ bv1 1)) (bvadd s0 (_ bv1 2)) s0)))
15(check-sat-assuming ((= s1 goal)))
16
17(assert (= s2 (ite (= o1 (_ bv1 1)) (bvadd s1 (_ bv1 2)) s1)))
18(check-sat-assuming ((= s2 goal)))
Unsat Core Example
This example shows how to extract an unsat core.
It creates bit-vector and floating-point terms and further illustrates how to
create lambda terms (define-fun
).
1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == '__main__':
14
15 # First, create a term manager instance.
16 tm = TermManager()
17 # Create a Bitwuzla options instance.
18 options = Options()
19 # Then, enable unsat core extraction.
20 # Note: Unsat core extraction is disabled by default.
21 options.set(Option.PRODUCE_UNSAT_CORES, True)
22
23 # Then, create a Bitwuzla instance.
24 bitwuzla = Bitwuzla(tm, options)
25
26 # Create a bit-vector sort of size 2.
27 sortbv2 = tm.mk_bv_sort(2)
28 # Create a bit-vector sort of size 4.
29 sortbv4 = tm.mk_bv_sort(4)
30 # Create Float16 floatinf-point sort.
31 sortfp16 = tm.mk_fp_sort(5, 11)
32
33 # Create bit-vector variables.
34 # (declare-const x0 (_ BitVec 4))
35 x0 = tm.mk_const(sortbv4, 'x0')
36 # (declare-const x1 (_ BitVec 2))
37 x1 = tm.mk_const(sortbv2, 'x1')
38 # (declare-const x2 (_ BitVec 2))
39 x2 = tm.mk_const(sortbv2, 'x2')
40 # (declare-const x3 (_ BitVec 2))
41 x3 = tm.mk_const(sortbv2, 'x3')
42 # (declare-const x4 Float16)
43 x4 = tm.mk_const(sortfp16, 'x4')
44
45 # Create FP positive zero.
46 fpzero = tm.mk_fp_pos_zero(sortfp16)
47 # Create BV zero of size 4.
48 bvzero = tm.mk_bv_zero(sortbv4)
49
50 # (define-fun f0 ((a Float16)) Bool (fp.gt a (_ +zero 5 11)))
51 a_f0 = tm.mk_var(sortfp16, 'a_f0')
52 f0 = tm.mk_term(Kind.LAMBDA, [a_f0, tm.mk_term(Kind.FP_GT, [a_f0, fpzero])])
53
54 # (define-fun f1 ((a Float16)) (_ BitVec 4) (ite (f0 a) x0 #b0000))
55 a_f1 = tm.mk_var(sortfp16, 'a_f1')
56 f1 = tm.mk_term(
57 Kind.LAMBDA,
58 [a_f1,
59 tm.mk_term(Kind.ITE, [tm.mk_term(Kind.APPLY, [f0, a_f1]), x0, bvzero])])
60
61 # (define-fun f2 ((a Float16)) (_ BitVec 2) ((_ extract 1 0) (f1 a)))
62 a_f2 = tm.mk_var(sortfp16, 'a_f2')
63 f2 = tm.mk_term(
64 Kind.LAMBDA,
65 [a_f2,
66 tm.mk_term(Kind.BV_EXTRACT, [tm.mk_term(Kind.APPLY, [f1, a_f2])], [1, 0])])
67
68 # (assert (! (bvult x2 (f2 (_ +zero 5 11))) :named a0))
69 a0 = tm.mk_term(Kind.BV_ULT, [x2, tm.mk_term(Kind.APPLY, [f2, fpzero])])
70 bitwuzla.assert_formula(a0)
71
72 # (assert (! (= x1 x2 x3) :named a1))
73 a1 = tm.mk_term(Kind.EQUAL, [x1, x2, x3])
74 bitwuzla.assert_formula(a1)
75
76 # (assert (!(= x4 ((_ to_fp_unsigned 5 11) RNE x3)) :named a2))
77 a2 = tm.mk_term(Kind.EQUAL,
78 [x4,
79 tm.mk_term(Kind.FP_TO_FP_FROM_UBV,
80 [tm.mk_rm_value(RoundingMode.RNE), x3],
81 [5, 11])])
82 bitwuzla.assert_formula(a2)
83
84 # (check-sat)
85 result = bitwuzla.check_sat()
86 print('Expect: unsat')
87 print(f'Bitwuzla: {result}')
88
89 # (get-unsat-core)
90 unsat_core = bitwuzla.get_unsat_core()
91 print('Unsat Core:')
92 print('{')
93 for t in unsat_core:
94 print(f' {t}')
95 print('}')
1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == '__main__':
14
15 # First, create a term manager instance.
16 tm = TermManager()
17 # Create a Bitwuzla options instance.
18 options = Options()
19 # Then, enable unsat core extraction.
20 # Note: Unsat core extraction is disabled by default.
21 options.set(Option.PRODUCE_UNSAT_CORES, True)
22
23 # Then, create a Bitwuzla instance.
24 bitwuzla = Bitwuzla(tm, options)
25
26 # Create a bit-vector sort of size 2.
27 sortbv2 = tm.mk_bv_sort(2)
28 # Create a bit-vector sort of size 4.
29 sortbv4 = tm.mk_bv_sort(4)
30 # Create Float16 floatinf-point sort.
31 sortfp16 = tm.mk_fp_sort(5, 11)
32
33 # Create bit-vector variables.
34 # (declare-const x0 (_ BitVec 4))
35 x0 = tm.mk_const(sortbv4, 'x0')
36 # (declare-const x1 (_ BitVec 2))
37 x1 = tm.mk_const(sortbv2, 'x1')
38 # (declare-const x2 (_ BitVec 2))
39 x2 = tm.mk_const(sortbv2, 'x2')
40 # (declare-const x3 (_ BitVec 2))
41 x3 = tm.mk_const(sortbv2, 'x3')
42 # (declare-const x4 Float16)
43 x4 = tm.mk_const(sortfp16, 'x4')
44
45 # Create FP positive zero.
46 fpzero = tm.mk_fp_pos_zero(sortfp16)
47 # Create BV zero of size 4.
48 bvzero = tm.mk_bv_zero(sortbv4)
49
50 # (define-fun f0 ((a Float16)) Bool (fp.gt a (_ +zero 5 11)))
51 a_f0 = tm.mk_var(sortfp16, 'a_f0')
52 f0 = tm.mk_term(Kind.LAMBDA, [a_f0, tm.mk_term(Kind.FP_GT, [a_f0, fpzero])])
53
54 # (define-fun f1 ((a Float16)) (_ BitVec 4) (ite (f0 a) x0 #b0000))
55 a_f1 = tm.mk_var(sortfp16, 'a_f1')
56 f1 = tm.mk_term(
57 Kind.LAMBDA,
58 [a_f1,
59 tm.mk_term(Kind.ITE, [tm.mk_term(Kind.APPLY, [f0, a_f1]), x0, bvzero])])
60
61 # (define-fun f2 ((a Float16)) (_ BitVec 2) ((_ extract 1 0) (f1 a)))
62 a_f2 = tm.mk_var(sortfp16, 'a_f2')
63 f2 = tm.mk_term(
64 Kind.LAMBDA,
65 [a_f2,
66 tm.mk_term(Kind.BV_EXTRACT, [tm.mk_term(Kind.APPLY, [f1, a_f2])], [1, 0])])
67
68 # (assert (! (bvult x2 (f2 (_ +zero 5 11))) :named a0))
69 a0 = tm.mk_term(Kind.BV_ULT, [x2, tm.mk_term(Kind.APPLY, [f2, fpzero])])
70 bitwuzla.assert_formula(a0)
71
72 # (assert (! (= x1 x2 x3) :named a1))
73 a1 = tm.mk_term(Kind.EQUAL, [x1, x2, x3])
74 bitwuzla.assert_formula(a1)
75
76 # (assert (!(= x4 ((_ to_fp_unsigned 5 11) RNE x3)) :named a2))
77 a2 = tm.mk_term(Kind.EQUAL,
78 [x4,
79 tm.mk_term(Kind.FP_TO_FP_FROM_UBV,
80 [tm.mk_rm_value(RoundingMode.RNE), x3],
81 [5, 11])])
82 bitwuzla.assert_formula(a2)
83
84 # (check-sat)
85 result = bitwuzla.check_sat()
86 print('Expect: unsat')
87 print(f'Bitwuzla: {result}')
88
89 # (get-unsat-core)
90 unsat_core = bitwuzla.get_unsat_core()
91 print('Unsat Core:')
92 print('{')
93 for t in unsat_core:
94 print(f' {t}')
95 print('}')
1/***
2 * Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3 *
4 * Copyright (C) 2021 by the authors listed in the AUTHORS file at
5 * https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6 *
7 * This file is part of Bitwuzla under the MIT license. See COPYING for more
8 * information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
9 */
10
11#include <bitwuzla/c/bitwuzla.h>
12#include <stdio.h>
13
14int
15main()
16{
17 // First, create a term manager instance.
18 BitwuzlaTermManager *tm = bitwuzla_term_manager_new();
19 // Create a Bitwuzla options instance.
20 BitwuzlaOptions *options = bitwuzla_options_new();
21 // Then, enable unsat core extraction.
22 // Note: Unsat core extraction is disabled by default.
23 bitwuzla_set_option(options, BITWUZLA_OPT_PRODUCE_UNSAT_CORES, 1);
24 // Then, create a Bitwuzla instance.
25 Bitwuzla *bitwuzla = bitwuzla_new(tm, options);
26
27 // Create a bit-vector sort of size 2.
28 BitwuzlaSort sortbv2 = bitwuzla_mk_bv_sort(tm, 2);
29 // Create a bit-vector sort of size 4.
30 BitwuzlaSort sortbv4 = bitwuzla_mk_bv_sort(tm, 4);
31 // Create Float16 floatinf-point sort.
32 BitwuzlaSort sortfp16 = bitwuzla_mk_fp_sort(tm, 5, 11);
33
34 // Create bit-vector variables.
35 // (declare-const x0 (_ BitVec 4))
36 BitwuzlaTerm x0 = bitwuzla_mk_const(tm, sortbv4, "x0");
37 // (declare-const x1 (_ BitVec 2))
38 BitwuzlaTerm x1 = bitwuzla_mk_const(tm, sortbv2, "x1");
39 // (declare-const x2 (_ BitVec 2))
40 BitwuzlaTerm x2 = bitwuzla_mk_const(tm, sortbv2, "x2");
41 // (declare-const x3 (_ BitVec 2))
42 BitwuzlaTerm x3 = bitwuzla_mk_const(tm, sortbv2, "x3");
43 // (declare-const x4 Float16)
44 BitwuzlaTerm x4 = bitwuzla_mk_const(tm, sortfp16, "x4");
45
46 // Create FP positive zero.
47 BitwuzlaTerm fpzero = bitwuzla_mk_fp_pos_zero(tm, sortfp16);
48 // Create BV zero of size 4.
49 BitwuzlaTerm bvzero = bitwuzla_mk_bv_zero(tm, sortbv4);
50
51 // (define-fun f0 ((a Float16)) Bool (fp.gt a (_ +zero 5 11)))
52 BitwuzlaTerm a_f0 = bitwuzla_mk_var(tm, sortfp16, "a_f0");
53 BitwuzlaTerm f0 = bitwuzla_mk_term2(
54 tm,
55 BITWUZLA_KIND_LAMBDA,
56 a_f0,
57 bitwuzla_mk_term2(tm, BITWUZLA_KIND_FP_GT, a_f0, fpzero));
58
59 // (define-fun f1 ((a Float16)) (_ BitVec 4) (ite (f0 a) x0 #b0000))
60 BitwuzlaTerm a_f1 = bitwuzla_mk_var(tm, sortfp16, "a_f1");
61 BitwuzlaTerm f1 = bitwuzla_mk_term2(
62 tm,
63 BITWUZLA_KIND_LAMBDA,
64 a_f1,
65 bitwuzla_mk_term3(tm,
66 BITWUZLA_KIND_ITE,
67 bitwuzla_mk_term2(tm, BITWUZLA_KIND_APPLY, f0, a_f1),
68 x0,
69 bvzero));
70
71 // (define-fun f2 ((a Float16)) (_ BitVec 2) ((_ extract 1 0) (f1 a)))
72 BitwuzlaTerm a_f2 = bitwuzla_mk_var(tm, sortfp16, "a_f2");
73 BitwuzlaTerm f2 = bitwuzla_mk_term2(
74 tm,
75 BITWUZLA_KIND_LAMBDA,
76 a_f2,
77 bitwuzla_mk_term1_indexed2(
78 tm,
79 BITWUZLA_KIND_BV_EXTRACT,
80 bitwuzla_mk_term2(tm, BITWUZLA_KIND_APPLY, f1, a_f2),
81 1,
82 0));
83
84 // (assert (! (bvult x2 (f2 (_ +zero 5 11))) :named a0))
85 BitwuzlaTerm a0 =
86 bitwuzla_mk_term2(tm,
87 BITWUZLA_KIND_BV_ULT,
88 x2,
89 bitwuzla_mk_term2(tm, BITWUZLA_KIND_APPLY, f2, fpzero));
90 bitwuzla_assert(bitwuzla, a0);
91
92 // (assert (! (= x1 x2 x3) :named a1))
93 BitwuzlaTerm a1 = bitwuzla_mk_term3(tm, BITWUZLA_KIND_EQUAL, x1, x2, x3);
94 bitwuzla_assert(bitwuzla, a1);
95
96 // (assert (!(= x4 ((_ to_fp_unsigned 5 11) RNE x3)) :named a2))
97 BitwuzlaTerm a2 = bitwuzla_mk_term2(
98 tm,
99 BITWUZLA_KIND_EQUAL,
100 x4,
101 bitwuzla_mk_term2_indexed2(tm,
102 BITWUZLA_KIND_FP_TO_FP_FROM_UBV,
103 bitwuzla_mk_rm_value(tm, BITWUZLA_RM_RNE),
104 x3,
105 5,
106 11));
107 bitwuzla_assert(bitwuzla, a2);
108
109 // (check-sat)
110 BitwuzlaResult result = bitwuzla_check_sat(bitwuzla);
111 printf("Expect: unsat\n");
112 printf("Bitwuzla: %s\n", bitwuzla_result_to_string(result));
113
114 // (get-unsat-core)
115 size_t unsat_core_size;
116 const BitwuzlaTerm *unsat_core =
117 bitwuzla_get_unsat_core(bitwuzla, &unsat_core_size);
118 printf("Unsat Core:\n{\n");
119 for (uint32_t i = 0; i < unsat_core_size; ++i)
120 {
121 printf(" %s\n", bitwuzla_term_to_string(unsat_core[i]));
122 }
123 printf("}\n");
124
125 // Finally, delete the Bitwuzla solver, options, and term manager instances.
126 bitwuzla_delete(bitwuzla);
127 bitwuzla_options_delete(options);
128 bitwuzla_term_manager_delete(tm);
129
130 return 0;
131}
1(set-logic ALL)
2(set-option :produce-unsat-cores true)
3(declare-const x0 (_ BitVec 4))
4(declare-const x1 (_ BitVec 2))
5(declare-const x2 (_ BitVec 2))
6(declare-const x3 (_ BitVec 2))
7(declare-const x4 Float16)
8(define-fun f0 ((a Float16)) Bool (fp.gt a (_ +zero 5 11)))
9(define-fun f1 ((a Float16)) (_ BitVec 4) (ite (f0 a) x0 #b0000))
10(define-fun f2 ((a Float16)) (_ BitVec 2) ((_ extract 1 0) (f1 a)))
11(assert (! (bvult x2 (f2 (_ +zero 5 11))) :named a0))
12(assert (! (= x1 x2 x3) :named a1))
13(assert (!(= x4 ((_ to_fp_unsigned 5 11) RNE x3)) :named a2))
14(check-sat)
15(get-unsat-core)
Unsat Assumptions Example
get-unsat-assumptions
. 1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == '__main__':
14
15 # First, create a term manager instance.
16 tm = TermManager()
17 # Create a Bitwuzla options instance.
18 options = Options()
19 # (set-option :produce-unsat-assumptions true)
20 options.set(Option.PRODUCE_UNSAT_ASSUMPTIONS, True)
21
22 # Then, create a Bitwuzla instance.
23 bitwuzla = Bitwuzla(tm, options)
24
25 # Create Boolean sort.
26 sortbool = tm.mk_bool_sort()
27 # Create a bit-vector sort of size 2.
28 sortbv2 = tm.mk_bv_sort(2)
29 # Create a bit-vector sort of size 4.
30 sortbv4 = tm.mk_bv_sort(4)
31 # Create Float16 floatinf-point sort.
32 sortfp16 = tm.mk_fp_sort(5, 11)
33 # Create bit-vector variables.
34 # (declare-const x0 (_ BitVec 4))
35 x0 = tm.mk_const(sortbv4, 'x0')
36 # (declare-const x1 (_ BitVec 2))
37 x1 = tm.mk_const(sortbv2, 'x1')
38 # (declare-const x2 (_ BitVec 2))
39 x2 = tm.mk_const(sortbv2, 'x2')
40 # (declare-const x3 (_ BitVec 2))
41 x3 = tm.mk_const(sortbv2, 'x3')
42 # (declare-const x4 Float16)
43 x4 = tm.mk_const(sortfp16, 'x4')
44
45 # Create FP positive zero.
46 fpzero = tm.mk_fp_pos_zero(sortfp16)
47 # Create BV zero of size 4.
48 bvzero = tm.mk_bv_zero(sortbv4)
49
50 # (define-fun f0 ((a Float16)) Bool (fp.gt a (_ +zero 5 11)))
51 a_f0 = tm.mk_var(sortfp16, 'a_f0')
52 f0 = tm.mk_term(Kind.LAMBDA, [a_f0, tm.mk_term(Kind.FP_GT, [a_f0, fpzero])])
53
54 # (define-fun f1 ((a Float16)) (_ BitVec 4) (ite (f0 a) x0 #b0000))
55 a_f1 = tm.mk_var(sortfp16, 'a_f1')
56 f1 = tm.mk_term(
57 Kind.LAMBDA,
58 [a_f1,
59 tm.mk_term(Kind.ITE, [tm.mk_term(Kind.APPLY, [f0, a_f1]), x0, bvzero])])
60
61 # (define-fun f2 ((a Float16)) (_ BitVec 2) ((_ extract 1 0) (f1 a)))
62 a_f2 = tm.mk_var(sortfp16, 'a_f2')
63 f2 = tm.mk_term(
64 Kind.LAMBDA,
65 [a_f2,
66 tm.mk_term(Kind.BV_EXTRACT, [tm.mk_term(Kind.APPLY, [f1, a_f2])], [1, 0])])
67
68 # (assert (! (bvult x2 (f2 (_ +zero 5 11))) :named a0))
69 a0 = tm.mk_const(sortbool, 'a0')
70 assumption0 = tm.mk_term(Kind.BV_ULT, [x2, tm.mk_term(Kind.APPLY, [f2, fpzero])])
71 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [a0, assumption0]))
72 # (assert (! (= x1 x2 x3) :named a1))
73 a1 = tm.mk_const(sortbool, 'a1')
74 assumption1 = tm.mk_term(Kind.EQUAL, [x1, x2, x3])
75 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [a1, assumption1]))
76 # (assert (!(= x4 ((_ to_fp_unsigned 5 11) RNE x3)) :named a2))
77 a2 = tm.mk_const(sortbool, 'a2')
78 assumption2 = tm.mk_term(Kind.EQUAL,
79 [x4,
80 tm.mk_term(Kind.FP_TO_FP_FROM_UBV,
81 [tm.mk_rm_value(RoundingMode.RNE), x3],
82 [5, 11])])
83 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [a2, assumption2]))
84
85 # (check-sat-assuming (assumption0 assumption1 assumption2))
86 result = bitwuzla.check_sat(a0, a1, a2)
87 print('Expect: unsat')
88 print(f'Bitwuzla: {result}')
89
90 # (get-unsat-assumptions)
91 unsat_assumptions = bitwuzla.get_unsat_assumptions()
92 print('Unsat Assumptions: {', end = '')
93 for a in unsat_assumptions:
94 print(f' {a}', end = '')
95 print(' }')
1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == '__main__':
14
15 # First, create a term manager instance.
16 tm = TermManager()
17 # Create a Bitwuzla options instance.
18 options = Options()
19 # (set-option :produce-unsat-assumptions true)
20 options.set(Option.PRODUCE_UNSAT_ASSUMPTIONS, True)
21
22 # Then, create a Bitwuzla instance.
23 bitwuzla = Bitwuzla(tm, options)
24
25 # Create Boolean sort.
26 sortbool = tm.mk_bool_sort()
27 # Create a bit-vector sort of size 2.
28 sortbv2 = tm.mk_bv_sort(2)
29 # Create a bit-vector sort of size 4.
30 sortbv4 = tm.mk_bv_sort(4)
31 # Create Float16 floatinf-point sort.
32 sortfp16 = tm.mk_fp_sort(5, 11)
33 # Create bit-vector variables.
34 # (declare-const x0 (_ BitVec 4))
35 x0 = tm.mk_const(sortbv4, 'x0')
36 # (declare-const x1 (_ BitVec 2))
37 x1 = tm.mk_const(sortbv2, 'x1')
38 # (declare-const x2 (_ BitVec 2))
39 x2 = tm.mk_const(sortbv2, 'x2')
40 # (declare-const x3 (_ BitVec 2))
41 x3 = tm.mk_const(sortbv2, 'x3')
42 # (declare-const x4 Float16)
43 x4 = tm.mk_const(sortfp16, 'x4')
44
45 # Create FP positive zero.
46 fpzero = tm.mk_fp_pos_zero(sortfp16)
47 # Create BV zero of size 4.
48 bvzero = tm.mk_bv_zero(sortbv4)
49
50 # (define-fun f0 ((a Float16)) Bool (fp.gt a (_ +zero 5 11)))
51 a_f0 = tm.mk_var(sortfp16, 'a_f0')
52 f0 = tm.mk_term(Kind.LAMBDA, [a_f0, tm.mk_term(Kind.FP_GT, [a_f0, fpzero])])
53
54 # (define-fun f1 ((a Float16)) (_ BitVec 4) (ite (f0 a) x0 #b0000))
55 a_f1 = tm.mk_var(sortfp16, 'a_f1')
56 f1 = tm.mk_term(
57 Kind.LAMBDA,
58 [a_f1,
59 tm.mk_term(Kind.ITE, [tm.mk_term(Kind.APPLY, [f0, a_f1]), x0, bvzero])])
60
61 # (define-fun f2 ((a Float16)) (_ BitVec 2) ((_ extract 1 0) (f1 a)))
62 a_f2 = tm.mk_var(sortfp16, 'a_f2')
63 f2 = tm.mk_term(
64 Kind.LAMBDA,
65 [a_f2,
66 tm.mk_term(Kind.BV_EXTRACT, [tm.mk_term(Kind.APPLY, [f1, a_f2])], [1, 0])])
67
68 # (assert (! (bvult x2 (f2 (_ +zero 5 11))) :named a0))
69 a0 = tm.mk_const(sortbool, 'a0')
70 assumption0 = tm.mk_term(Kind.BV_ULT, [x2, tm.mk_term(Kind.APPLY, [f2, fpzero])])
71 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [a0, assumption0]))
72 # (assert (! (= x1 x2 x3) :named a1))
73 a1 = tm.mk_const(sortbool, 'a1')
74 assumption1 = tm.mk_term(Kind.EQUAL, [x1, x2, x3])
75 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [a1, assumption1]))
76 # (assert (!(= x4 ((_ to_fp_unsigned 5 11) RNE x3)) :named a2))
77 a2 = tm.mk_const(sortbool, 'a2')
78 assumption2 = tm.mk_term(Kind.EQUAL,
79 [x4,
80 tm.mk_term(Kind.FP_TO_FP_FROM_UBV,
81 [tm.mk_rm_value(RoundingMode.RNE), x3],
82 [5, 11])])
83 bitwuzla.assert_formula(tm.mk_term(Kind.EQUAL, [a2, assumption2]))
84
85 # (check-sat-assuming (assumption0 assumption1 assumption2))
86 result = bitwuzla.check_sat(a0, a1, a2)
87 print('Expect: unsat')
88 print(f'Bitwuzla: {result}')
89
90 # (get-unsat-assumptions)
91 unsat_assumptions = bitwuzla.get_unsat_assumptions()
92 print('Unsat Assumptions: {', end = '')
93 for a in unsat_assumptions:
94 print(f' {a}', end = '')
95 print(' }')
1/***
2 * Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3 *
4 * Copyright (C) 2021 by the authors listed in the AUTHORS file at
5 * https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6 *
7 * This file is part of Bitwuzla under the MIT license. See COPYING for more
8 * information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
9 */
10
11#include <bitwuzla/c/bitwuzla.h>
12#include <stdio.h>
13
14int
15main()
16{
17 // First, create a term manager instance.
18 BitwuzlaTermManager *tm = bitwuzla_term_manager_new();
19 // Create a Bitwuzla options instance.
20 BitwuzlaOptions *options = bitwuzla_options_new();
21 // (set-option :produce-unsat-assumptions true)
22 bitwuzla_set_option(options, BITWUZLA_OPT_PRODUCE_UNSAT_ASSUMPTIONS, 1);
23 // Then, create a Bitwuzla instance.
24 Bitwuzla *bitwuzla = bitwuzla_new(tm, options);
25
26 // Create Boolean sort.
27 BitwuzlaSort sortbool = bitwuzla_mk_bool_sort(tm);
28 // Create a bit-vector sort of size 2.
29 BitwuzlaSort sortbv2 = bitwuzla_mk_bv_sort(tm, 2);
30 // Create a bit-vector sort of size 4.
31 BitwuzlaSort sortbv4 = bitwuzla_mk_bv_sort(tm, 4);
32 // Create Float16 floatinf-point sort.
33 BitwuzlaSort sortfp16 = bitwuzla_mk_fp_sort(tm, 5, 11);
34 // Create bit-vector variables.
35 // (declare-const x0 (_ BitVec 4))
36 BitwuzlaTerm x0 = bitwuzla_mk_const(tm, sortbv4, "x0");
37 // (declare-const x1 (_ BitVec 2))
38 BitwuzlaTerm x1 = bitwuzla_mk_const(tm, sortbv2, "x1");
39 // (declare-const x2 (_ BitVec 2))
40 BitwuzlaTerm x2 = bitwuzla_mk_const(tm, sortbv2, "x2");
41 // (declare-const x3 (_ BitVec 2))
42 BitwuzlaTerm x3 = bitwuzla_mk_const(tm, sortbv2, "x3");
43 // (declare-const x4 Float16)
44 BitwuzlaTerm x4 = bitwuzla_mk_const(tm, sortfp16, "x4");
45
46 // Create FP positive zero.
47 BitwuzlaTerm fpzero = bitwuzla_mk_fp_pos_zero(tm, sortfp16);
48 // Create BV zero of size 4.
49 BitwuzlaTerm bvzero = bitwuzla_mk_bv_zero(tm, sortbv4);
50
51 // (define-fun f0 ((a Float16)) Bool (fp.gt a (_ +zero 5 11)))
52 BitwuzlaTerm a_f0 = bitwuzla_mk_var(tm, sortfp16, "a_f0");
53 BitwuzlaTerm f0 = bitwuzla_mk_term2(
54 tm,
55 BITWUZLA_KIND_LAMBDA,
56 a_f0,
57 bitwuzla_mk_term2(tm, BITWUZLA_KIND_FP_GT, a_f0, fpzero));
58
59 // (define-fun f1 ((a Float16)) (_ BitVec 4) (ite (f0 a) x0 #b0000))
60 BitwuzlaTerm a_f1 = bitwuzla_mk_var(tm, sortfp16, "a_f1");
61 BitwuzlaTerm f1 = bitwuzla_mk_term2(
62 tm,
63 BITWUZLA_KIND_LAMBDA,
64 a_f1,
65 bitwuzla_mk_term3(tm,
66 BITWUZLA_KIND_ITE,
67 bitwuzla_mk_term2(tm, BITWUZLA_KIND_APPLY, f0, a_f1),
68 x0,
69 bvzero));
70
71 // (define-fun f2 ((a Float16)) (_ BitVec 2) ((_ extract 1 0) (f1 a)))
72 BitwuzlaTerm a_f2 = bitwuzla_mk_var(tm, sortfp16, "a_f2");
73 BitwuzlaTerm f2 = bitwuzla_mk_term2(
74 tm,
75 BITWUZLA_KIND_LAMBDA,
76 a_f2,
77 bitwuzla_mk_term1_indexed2(
78 tm,
79 BITWUZLA_KIND_BV_EXTRACT,
80 bitwuzla_mk_term2(tm, BITWUZLA_KIND_APPLY, f1, a_f2),
81 1,
82 0));
83
84 // (assert (! (bvult x2 (f2 (_ +zero 5 11))) :named a0))
85 BitwuzlaTerm a0 = bitwuzla_mk_const(tm, sortbool, "a0");
86 BitwuzlaTerm assumption0 =
87 bitwuzla_mk_term2(tm,
88 BITWUZLA_KIND_BV_ULT,
89 x2,
90 bitwuzla_mk_term2(tm, BITWUZLA_KIND_APPLY, f2, fpzero));
91 bitwuzla_assert(bitwuzla,
92 bitwuzla_mk_term2(tm, BITWUZLA_KIND_EQUAL, a0, assumption0));
93 // (assert (! (= x1 x2 x3) :named a1))
94 BitwuzlaTerm a1 = bitwuzla_mk_const(tm, sortbool, "a1");
95 BitwuzlaTerm assumption1 =
96 bitwuzla_mk_term3(tm, BITWUZLA_KIND_EQUAL, x1, x2, x3);
97 bitwuzla_assert(bitwuzla,
98 bitwuzla_mk_term2(tm, BITWUZLA_KIND_EQUAL, a1, assumption1));
99 // (assert (!(= x4 ((_ to_fp_unsigned 5 11) RNE x3)) :named a2))
100 BitwuzlaTerm a2 = bitwuzla_mk_const(tm, sortbool, "a2");
101 BitwuzlaTerm assumption2 = bitwuzla_mk_term2(
102 tm,
103 BITWUZLA_KIND_EQUAL,
104 x4,
105 bitwuzla_mk_term2_indexed2(tm,
106 BITWUZLA_KIND_FP_TO_FP_FROM_UBV,
107 bitwuzla_mk_rm_value(tm, BITWUZLA_RM_RNE),
108 x3,
109 5,
110 11));
111 bitwuzla_assert(bitwuzla,
112 bitwuzla_mk_term2(tm, BITWUZLA_KIND_EQUAL, a2, assumption2));
113
114 BitwuzlaTerm assumptions[3] = {a0, a1, a2};
115 // (check-sat-assuming (assumption0 assumption1 assumption2))
116 BitwuzlaResult result = bitwuzla_check_sat_assuming(bitwuzla, 3, assumptions);
117 printf("Expect: unsat\n");
118 printf("Bitwuzla: %s\n", bitwuzla_result_to_string(result));
119
120 // (get-unsat-assumptions)
121 size_t unsat_assumptions_size;
122 const BitwuzlaTerm *unsat_assumptions =
123 bitwuzla_get_unsat_assumptions(bitwuzla, &unsat_assumptions_size);
124 printf("Unsat Assumptions: {");
125 for (uint32_t i = 0; i < unsat_assumptions_size; ++i)
126 {
127 printf(" %s", bitwuzla_term_to_string(unsat_assumptions[i]));
128 }
129 printf(" }\n");
130
131 // Finally, delete the Bitwuzla solver, options, and term manager instances.
132 bitwuzla_delete(bitwuzla);
133 bitwuzla_options_delete(options);
134 bitwuzla_term_manager_delete(tm);
135
136 return 0;
137}
1(set-logic ALL)
2(set-option :produce-unsat-assumptions true)
3(declare-const x0 (_ BitVec 4))
4(declare-const x1 (_ BitVec 2))
5(declare-const x2 (_ BitVec 2))
6(declare-const x3 (_ BitVec 2))
7(declare-const x4 Float16)
8(define-fun f0 ((a Float16)) Bool (fp.gt a (_ +zero 5 11)))
9(define-fun f1 ((a Float16)) (_ BitVec 4) (ite (f0 a) x0 #b0000))
10(define-fun f2 ((a Float16)) (_ BitVec 2) ((_ extract 1 0) (f1 a)))
11(check-sat-assuming
12 (
13 (! (bvult x2 (f2 (_ +zero 5 11))) :named a0)
14 (! (= x1 x2 x3) :named a1)
15 (! (= x4 ((_ to_fp_unsigned 5 11) RNE x3)) :named a2)
16 )
17)
18(get-unsat-assumptions)
Reset Example
reset
). 1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == '__main__':
14
15 # First, create a term manager instance.
16 tm = TermManager()
17 # Create a Bitwuzla options instance.
18 options = Options()
19 # (set-option :produce-models true)
20 options.set(Option.PRODUCE_MODELS, False)
21
22 # Then, create a Bitwuzla instance.
23 bitwuzla = Bitwuzla(tm, options)
24
25 # Create a bit-vector sort of size 3.
26 sortbv3 = tm.mk_bv_sort(3)
27
28 # (declare-const x (_ BitVec 3))
29 x = tm.mk_const(sortbv3, 'x')
30
31 # (assert (= x #b010))
32 bitwuzla.assert_formula(
33 tm.mk_term(Kind.EQUAL, [x, tm.mk_bv_value(sortbv3, 2)]))
34 # (check-sat)
35 result = bitwuzla.check_sat()
36 print('Expect: sat')
37 print(f'Bitwuzla: {result}')
38
39 # (set-option :produce-models true)
40 options.set(Option.PRODUCE_MODELS, True)
41
42 # (reset)
43 # Note: Bitwuzla does not provide an explicit API function for reset since
44 # this is achieved by simply discarding the current Bitwuzla instance
45 # and creating a new one.
46 bitwuzla = Bitwuzla(tm, options)
47
48 # (declare-const a ( Array (_ BitVec 2) (_ BitVec 3)))
49 sortbv2 = tm.mk_bv_sort(2)
50 a = tm.mk_const(tm.mk_array_sort(sortbv2, sortbv3), 'a')
51
52 # (assert (= x #b011))
53 bitwuzla.assert_formula(
54 tm.mk_term(Kind.EQUAL, [x, tm.mk_bv_value(sortbv3, 3)]))
55 # (assert (= x (select a #b01)))
56 bitwuzla.assert_formula(tm.mk_term(
57 Kind.EQUAL,
58 [x, tm.mk_term(Kind.ARRAY_SELECT, [a, tm.mk_bv_value(sortbv2, 1)])]))
59 # (check-sat)
60 result = bitwuzla.check_sat()
61 print('Expect: sat')
62 print(f'Bitwuzla: {result}')
63 # (get-model)
64 print('(')
65 print(f' (define-fun {x.symbol()} () {x.sort()} {bitwuzla.get_value(x)} )')
66 print(f' (define-fun {a.symbol()} () {a.sort()} {bitwuzla.get_value(a)} )')
67 print(')')
1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == '__main__':
14
15 # First, create a term manager instance.
16 tm = TermManager()
17 # Create a Bitwuzla options instance.
18 options = Options()
19 # (set-option :produce-models true)
20 options.set(Option.PRODUCE_MODELS, False)
21
22 # Then, create a Bitwuzla instance.
23 bitwuzla = Bitwuzla(tm, options)
24
25 # Create a bit-vector sort of size 3.
26 sortbv3 = tm.mk_bv_sort(3)
27
28 # (declare-const x (_ BitVec 3))
29 x = tm.mk_const(sortbv3, 'x')
30
31 # (assert (= x #b010))
32 bitwuzla.assert_formula(
33 tm.mk_term(Kind.EQUAL, [x, tm.mk_bv_value(sortbv3, 2)]))
34 # (check-sat)
35 result = bitwuzla.check_sat()
36 print('Expect: sat')
37 print(f'Bitwuzla: {result}')
38
39 # (set-option :produce-models true)
40 options.set(Option.PRODUCE_MODELS, True)
41
42 # (reset)
43 # Note: Bitwuzla does not provide an explicit API function for reset since
44 # this is achieved by simply discarding the current Bitwuzla instance
45 # and creating a new one.
46 bitwuzla = Bitwuzla(tm, options)
47
48 # (declare-const a ( Array (_ BitVec 2) (_ BitVec 3)))
49 sortbv2 = tm.mk_bv_sort(2)
50 a = tm.mk_const(tm.mk_array_sort(sortbv2, sortbv3), 'a')
51
52 # (assert (= x #b011))
53 bitwuzla.assert_formula(
54 tm.mk_term(Kind.EQUAL, [x, tm.mk_bv_value(sortbv3, 3)]))
55 # (assert (= x (select a #b01)))
56 bitwuzla.assert_formula(tm.mk_term(
57 Kind.EQUAL,
58 [x, tm.mk_term(Kind.ARRAY_SELECT, [a, tm.mk_bv_value(sortbv2, 1)])]))
59 # (check-sat)
60 result = bitwuzla.check_sat()
61 print('Expect: sat')
62 print(f'Bitwuzla: {result}')
63 # (get-model)
64 print('(')
65 print(f' (define-fun {x.symbol()} () {x.sort()} {bitwuzla.get_value(x)} )')
66 print(f' (define-fun {a.symbol()} () {a.sort()} {bitwuzla.get_value(a)} )')
67 print(')')
1/***
2 * Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3 *
4 * Copyright (C) 2023 by the authors listed in the AUTHORS file at
5 * https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6 *
7 * This file is part of Bitwuzla under the MIT license. See COPYING for more
8 * information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
9 */
10
11#include <bitwuzla/c/bitwuzla.h>
12#include <stdio.h>
13
14int
15main()
16{
17 BitwuzlaResult result;
18
19 // First, create a term manager instance.
20 BitwuzlaTermManager* tm = bitwuzla_term_manager_new();
21 // Create a Bitwuzla options instance.
22 BitwuzlaOptions* options = bitwuzla_options_new();
23 // (set-option :produce-models false)
24 bitwuzla_set_option(options, BITWUZLA_OPT_PRODUCE_MODELS, 0);
25
26 // Then, create a Bitwuzla instance.
27 Bitwuzla* bitwuzla = bitwuzla_new(tm, options);
28
29 // Create a bit-vector sort of size 3.
30 BitwuzlaSort sortbv3 = bitwuzla_mk_bv_sort(tm, 3);
31
32 // (declare-const x (_ BitVec 3))
33 BitwuzlaTerm x = bitwuzla_mk_const(tm, sortbv3, "x");
34
35 // (assert (= x #b010))
36 bitwuzla_assert(
37 bitwuzla,
38 bitwuzla_mk_term2(tm,
39 BITWUZLA_KIND_EQUAL,
40 x,
41 bitwuzla_mk_bv_value_uint64(tm, sortbv3, 2)));
42 // (check-sat)
43 result = bitwuzla_check_sat(bitwuzla);
44 printf("Expect: sat\n");
45 printf("Bitwuzla: %s\n", bitwuzla_result_to_string(result));
46
47 bitwuzla_delete(bitwuzla);
48
49 // (set-option :produce-models true)
50 bitwuzla_set_option(options, BITWUZLA_OPT_PRODUCE_MODELS, true);
51
52 // (reset)
53 // Note: Bitwuzla does not provide an explicit API function for reset since
54 // this is achieved by simply discarding the current Bitwuzla instance
55 // and creating a new one.
56 bitwuzla = bitwuzla_new(tm, options);
57
58 // (declare-const a ( Array (_ BitVec 2) (_ BitVec 3)))
59 BitwuzlaSort sortbv2 = bitwuzla_mk_bv_sort(tm, 2);
60 BitwuzlaTerm a =
61 bitwuzla_mk_const(tm, bitwuzla_mk_array_sort(tm, sortbv2, sortbv3), "a");
62
63 // (assert (= x #b011))
64 bitwuzla_assert(
65 bitwuzla,
66 bitwuzla_mk_term2(tm,
67 BITWUZLA_KIND_EQUAL,
68 x,
69 bitwuzla_mk_bv_value_uint64(tm, sortbv3, 3)));
70 // (assert (= x (select a #b01)))
71 bitwuzla_assert(
72 bitwuzla,
73 bitwuzla_mk_term2(
74 tm,
75 BITWUZLA_KIND_EQUAL,
76 x,
77 bitwuzla_mk_term2(tm,
78 BITWUZLA_KIND_ARRAY_SELECT,
79 a,
80 bitwuzla_mk_bv_value_uint64(tm, sortbv2, 1))));
81 // (check-sat)
82 result = bitwuzla_check_sat(bitwuzla);
83 printf("Expect: sat\n");
84 printf("Bitwuzla: %s\n", bitwuzla_result_to_string(result));
85 // (get-model)
86 printf("(\n");
87 printf(" (define-fun %s () ", bitwuzla_term_get_symbol(x));
88 printf("%s ", bitwuzla_sort_to_string(bitwuzla_term_get_sort(x)));
89 printf("%s)\n", bitwuzla_term_to_string(bitwuzla_get_value(bitwuzla, x)));
90 printf(" (define-fun %s () ", bitwuzla_term_get_symbol(a));
91 printf("%s ", bitwuzla_sort_to_string(bitwuzla_term_get_sort(a)));
92 printf("%s)\n", bitwuzla_term_to_string(bitwuzla_get_value(bitwuzla, a)));
93 printf(")\n");
94
95 // Finally, delete the Bitwuzla solver, options, and term manager instances.
96 bitwuzla_delete(bitwuzla);
97 bitwuzla_options_delete(options);
98 bitwuzla_term_manager_delete(tm);
99
100 return 0;
101}
1(set-logic QF_BV)
2(set-option :produce-models false)
3(declare-const x (_ BitVec 3))
4(assert (= x #b010))
5(check-sat) ; expect sat
6
7(reset)
8
9(set-logic QF_ABV)
10(set-option :produce-models true)
11(declare-const x (_ BitVec 3))
12(declare-const a ( Array (_ BitVec 2) (_ BitVec 3)))
13(assert (= x #b011))
14(assert (= x (select a #b01)))
15(check-sat) ; expect sat
16(get-model)
Reset Assertions Example
reset-assertions
). 1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == '__main__':
14
15 # First, create a term manager instance.
16 tm = TermManager()
17 # Create a Bitwuzla options instance.
18 options = Options()
19 # (set-option :produce-models true)
20 options.set(Option.PRODUCE_MODELS, True)
21
22 # Then, create a Bitwuzla instance.
23 bitwuzla = Bitwuzla(tm, options)
24
25 # Create a bit-vector sort of size 3.
26 sortbv3 = tm.mk_bv_sort(3)
27
28 # (declare-const x (_ BitVec 3))
29 x = tm.mk_const(sortbv3, 'x')
30
31 # (assert (= x #b010))
32 bitwuzla.assert_formula(
33 tm.mk_term(Kind.EQUAL, [x, tm.mk_bv_value(sortbv3, 2)]))
34 # (check-sat)
35 result = bitwuzla.check_sat()
36 print('Expect: sat')
37 print(f'Bitwuzla: {result}')
38
39 # (assert (= x #b001))
40 bitwuzla.assert_formula(
41 tm.mk_term(Kind.EQUAL, [x, tm.mk_bv_value(sortbv3, 1)]))
42 # (check-sat)
43 result = bitwuzla.check_sat()
44 print('Expect: unsat')
45 print(f'Bitwuzla: {result}')
46
47 # (reset-assertions)
48 # Note: Bitwuzla does not provide an explicit API function for
49 # reset-assertions since this is achieved by simply discarding
50 # the current Bitwuzla instance and creating a new one.
51 bitwuzla = Bitwuzla(tm, options)
52
53 # (assert (= x #b011))
54 bitwuzla.assert_formula(
55 tm.mk_term(Kind.EQUAL, [x, tm.mk_bv_value(sortbv3, 3)]))
56 # (check-sat)
57 result = bitwuzla.check_sat()
58 print('Expect: sat')
59 print(f'Bitwuzla: {result}')
60
61 # (get-model)
62 print(f'(\n (define-fun {x.symbol()} () {x.sort()} {bitwuzla.get_value(x)} )\n)')
63
1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == '__main__':
14
15 # First, create a term manager instance.
16 tm = TermManager()
17 # Create a Bitwuzla options instance.
18 options = Options()
19 # (set-option :produce-models true)
20 options.set(Option.PRODUCE_MODELS, True)
21
22 # Then, create a Bitwuzla instance.
23 bitwuzla = Bitwuzla(tm, options)
24
25 # Create a bit-vector sort of size 3.
26 sortbv3 = tm.mk_bv_sort(3)
27
28 # (declare-const x (_ BitVec 3))
29 x = tm.mk_const(sortbv3, 'x')
30
31 # (assert (= x #b010))
32 bitwuzla.assert_formula(
33 tm.mk_term(Kind.EQUAL, [x, tm.mk_bv_value(sortbv3, 2)]))
34 # (check-sat)
35 result = bitwuzla.check_sat()
36 print('Expect: sat')
37 print(f'Bitwuzla: {result}')
38
39 # (assert (= x #b001))
40 bitwuzla.assert_formula(
41 tm.mk_term(Kind.EQUAL, [x, tm.mk_bv_value(sortbv3, 1)]))
42 # (check-sat)
43 result = bitwuzla.check_sat()
44 print('Expect: unsat')
45 print(f'Bitwuzla: {result}')
46
47 # (reset-assertions)
48 # Note: Bitwuzla does not provide an explicit API function for
49 # reset-assertions since this is achieved by simply discarding
50 # the current Bitwuzla instance and creating a new one.
51 bitwuzla = Bitwuzla(tm, options)
52
53 # (assert (= x #b011))
54 bitwuzla.assert_formula(
55 tm.mk_term(Kind.EQUAL, [x, tm.mk_bv_value(sortbv3, 3)]))
56 # (check-sat)
57 result = bitwuzla.check_sat()
58 print('Expect: sat')
59 print(f'Bitwuzla: {result}')
60
61 # (get-model)
62 print(f'(\n (define-fun {x.symbol()} () {x.sort()} {bitwuzla.get_value(x)} )\n)')
63
1/***
2 * Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3 *
4 * Copyright (C) 2023 by the authors listed in the AUTHORS file at
5 * https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6 *
7 * This file is part of Bitwuzla under the MIT license. See COPYING for more
8 * information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
9 */
10
11#include <bitwuzla/c/bitwuzla.h>
12#include <stdio.h>
13
14int
15main()
16{
17 BitwuzlaResult result;
18
19 // First, create a term manager instance.
20 BitwuzlaTermManager* tm = bitwuzla_term_manager_new();
21 // Create a Bitwuzla options instance.
22 BitwuzlaOptions* options = bitwuzla_options_new();
23 // (set-option :produce-models true)
24 bitwuzla_set_option(options, BITWUZLA_OPT_PRODUCE_MODELS, 1);
25
26 // Then, create a Bitwuzla instance.
27 Bitwuzla* bitwuzla = bitwuzla_new(tm, options);
28
29 // Create a bit-vector sort of size 3.
30 BitwuzlaSort sortbv3 = bitwuzla_mk_bv_sort(tm, 3);
31
32 // (declare-const x (_ BitVec 3))
33 BitwuzlaTerm x = bitwuzla_mk_const(tm, sortbv3, "x");
34
35 // (assert (= x #b010))
36 bitwuzla_assert(
37 bitwuzla,
38 bitwuzla_mk_term2(tm,
39 BITWUZLA_KIND_EQUAL,
40 x,
41 bitwuzla_mk_bv_value_uint64(tm, sortbv3, 2)));
42 // (check-sat)
43 result = bitwuzla_check_sat(bitwuzla);
44 printf("Expect: sat\n");
45 printf("Bitwuzla: %s\n", bitwuzla_result_to_string(result));
46 // (assert (= x #b001))
47 bitwuzla_assert(
48 bitwuzla,
49 bitwuzla_mk_term2(tm,
50 BITWUZLA_KIND_EQUAL,
51 x,
52 bitwuzla_mk_bv_value_uint64(tm, sortbv3, 1)));
53 // (check-sat)
54 result = bitwuzla_check_sat(bitwuzla);
55 printf("Expect: unsat\n");
56 printf("Bitwuzla: %s\n", bitwuzla_result_to_string(result));
57
58 // (reset-assertions)
59 // Note: Bitwuzla does not provide an explicit API function for
60 // reset-assertions since this is achieved by simply discarding
61 // the current Bitwuzla instance and creating a new one.
62 bitwuzla_delete(bitwuzla);
63 bitwuzla = bitwuzla_new(tm, options);
64
65 // (assert (= x #b011))
66 bitwuzla_assert(
67 bitwuzla,
68 bitwuzla_mk_term2(tm,
69 BITWUZLA_KIND_EQUAL,
70 x,
71 bitwuzla_mk_bv_value_uint64(tm, sortbv3, 3)));
72 // (check-sat)
73 result = bitwuzla_check_sat(bitwuzla);
74 printf("Expect: sat\n");
75 printf("Bitwuzla: %s\n", bitwuzla_result_to_string(result));
76 // (get-model)
77 printf("(\n");
78 printf(" (define-fun %s", bitwuzla_term_get_symbol(x));
79 printf(" () %s", bitwuzla_sort_to_string(bitwuzla_term_get_sort(x)));
80 printf(" %s)\n", bitwuzla_term_to_string(bitwuzla_get_value(bitwuzla, x)));
81 printf(")\n");
82
83 // Finally, delete the Bitwuzla solver, options, and term manager instances.
84 bitwuzla_delete(bitwuzla);
85 bitwuzla_options_delete(options);
86 bitwuzla_term_manager_delete(tm);
87
88 return 0;
89}
1(set-logic QF_BV)
2(set-option :global-declarations true)
3(set-option :produce-models true)
4(declare-const x (_ BitVec 3))
5(assert (= x #b010))
6(check-sat) ; expect sat
7(assert (= x #b001))
8(check-sat) ; expect unsat
9
10(reset-assertions)
11
12(assert (= x #b011))
13(check-sat) ; expect sat
14(get-model)
Parsing Example
1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11import sys
12
13from bitwuzla import *
14
15if __name__ == '__main__':
16
17 # First, create a term manager instance.
18 tm = TermManager()
19 # Create a Bitwuzla options instance.
20 options = Options()
21
22 # We will parse example file `smt2/quickstart.smt2`.
23 # Create parser instance.
24 parser = Parser(tm, options)
25
26 # Now parse the input file.
27 print('Expect: sat')
28 print('Bitwuzla: ', end='')
29 sys.stdout.flush()
30 res = parser.parse("../smt2/quickstart.smt2")
31 # We expect no error to occur.
32 assert not res
33
34 # Now we retrieve the set of asserted formulas and print them.
35 assertions = parser.bitwuzla().get_assertions()
36 print('Assertions:')
37 print('{')
38 for a in assertions:
39 print(f' {a}')
40 print('}')
41
42 # Now we add an assertion via parsing from string.
43 parser.parse('(assert (distinct (select a x) y))', True, False)
44 # Now the formula is unsat.
45 print('Expect: unsat')
46 print(f'Bitwuzla: {parser.bitwuzla().check_sat()}')
47
48 # For illustration purposes, we now parse in some declarations and terms
49 # and sorts from string.
50
51 # Declare bit-vector sort of size 16.
52 bv16 = parser.parse_sort('(_ BitVec 16)')
53 # Create bit-vector sort of size 16 and show that it corresponds to
54 # its string representation '(_ BitVec16)'.
55 assert bv16 == tm.mk_bv_sort(16)
56
57 # Declare Boolean constants 'c' and 'd'.
58 # Note: Declarations are commands (not terms) in the SMT-LIB language.
59 # Commands must be parsed in via Parser.parse(),
60 # Parser::parse_term() only supports parsing SMT-LIB terms.
61 parser.parse("(declare-const c Bool)(declare-const d Bool)", True, False)
62 # Declare bit-vector constant 'b'.
63 parser.parse('(declare-const b (_ BitVec 16))', True, False)
64 # Retrieve term representing 'b'.
65 b = parser.parse_term('b')
66 # Retrieve term representing 'c'.
67 c = parser.parse_term('c')
68 # Retrieve term representing 'd'.
69 d = parser.parse_term('d')
70 # Create xor over 'c' and 'd' and show that it corresponds to term
71 # parsed in from its string representation '(xor c d)'.
72 assert parser.parse_term('(xor c d)') == tm.mk_term(Kind.XOR, [c, d])
73 # Create bit-vector addition over 'b' and bit-vector value
74 # '1011111010001010' and show that it corresponds to the term parsed in
75 # from its string representation '(bvadd b #b1011111010001010)'.
76 assert parser.parse_term('(bvadd b #b1011111010001010)') \
77 == tm.mk_term(Kind.BV_ADD,
78 [b, tm.mk_bv_value(bv16, '1011111010001010', 2)])
1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11import sys
12
13from bitwuzla import *
14
15if __name__ == '__main__':
16
17 # First, create a term manager instance.
18 tm = TermManager()
19 # Create a Bitwuzla options instance.
20 options = Options()
21
22 # We will parse example file `smt2/quickstart.smt2`.
23 # Create parser instance.
24 parser = Parser(tm, options)
25
26 # Now parse the input file.
27 print('Expect: sat')
28 print('Bitwuzla: ', end='')
29 sys.stdout.flush()
30 res = parser.parse("../smt2/quickstart.smt2")
31 # We expect no error to occur.
32 assert not res
33
34 # Now we retrieve the set of asserted formulas and print them.
35 assertions = parser.bitwuzla().get_assertions()
36 print('Assertions:')
37 print('{')
38 for a in assertions:
39 print(f' {a}')
40 print('}')
41
42 # Now we add an assertion via parsing from string.
43 parser.parse('(assert (distinct (select a x) y))', True, False)
44 # Now the formula is unsat.
45 print('Expect: unsat')
46 print(f'Bitwuzla: {parser.bitwuzla().check_sat()}')
47
48 # For illustration purposes, we now parse in some declarations and terms
49 # and sorts from string.
50
51 # Declare bit-vector sort of size 16.
52 bv16 = parser.parse_sort('(_ BitVec 16)')
53 # Create bit-vector sort of size 16 and show that it corresponds to
54 # its string representation '(_ BitVec16)'.
55 assert bv16 == tm.mk_bv_sort(16)
56
57 # Declare Boolean constants 'c' and 'd'.
58 # Note: Declarations are commands (not terms) in the SMT-LIB language.
59 # Commands must be parsed in via Parser.parse(),
60 # Parser::parse_term() only supports parsing SMT-LIB terms.
61 parser.parse("(declare-const c Bool)(declare-const d Bool)", True, False)
62 # Declare bit-vector constant 'b'.
63 parser.parse('(declare-const b (_ BitVec 16))', True, False)
64 # Retrieve term representing 'b'.
65 b = parser.parse_term('b')
66 # Retrieve term representing 'c'.
67 c = parser.parse_term('c')
68 # Retrieve term representing 'd'.
69 d = parser.parse_term('d')
70 # Create xor over 'c' and 'd' and show that it corresponds to term
71 # parsed in from its string representation '(xor c d)'.
72 assert parser.parse_term('(xor c d)') == tm.mk_term(Kind.XOR, [c, d])
73 # Create bit-vector addition over 'b' and bit-vector value
74 # '1011111010001010' and show that it corresponds to the term parsed in
75 # from its string representation '(bvadd b #b1011111010001010)'.
76 assert parser.parse_term('(bvadd b #b1011111010001010)') \
77 == tm.mk_term(Kind.BV_ADD,
78 [b, tm.mk_bv_value(bv16, '1011111010001010', 2)])
1/***
2 * Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3 *
4 * Copyright (C) 2023 by the authors listed in the AUTHORS file at
5 * https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6 *
7 * This file is part of Bitwuzla under the MIT license. See COPYING for more
8 * information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
9 */
10
11#include <assert.h>
12#include <bitwuzla/c/bitwuzla.h>
13#include <bitwuzla/c/parser.h>
14#include <stdlib.h>
15
16int
17main()
18{
19 // First, create a term manager instance.
20 BitwuzlaTermManager* tm = bitwuzla_term_manager_new();
21 // Create a Bitwuzla options instance.
22 BitwuzlaOptions* options = bitwuzla_options_new();
23
24 // We will parse example file `smt2/quickstart.smt2`.
25 // Create parser instance.
26 const char* infile_name = "../smt2/quickstart.smt2";
27 BitwuzlaParser* parser =
28 bitwuzla_parser_new(tm, options, "smt2", 2, "<stdout>");
29
30 // Now parse the input file.
31 const char* error_msg;
32 printf("Expect: sat\n");
33 printf("Bitwuzla: ");
34 bitwuzla_parser_parse(parser, infile_name, false, true, &error_msg);
35 // We expect no error to occur.
36 assert(!error_msg);
37
38 // Now we retrieve the set of asserted formulas and print them.
39 size_t size;
40 const BitwuzlaTerm* assertions =
41 bitwuzla_get_assertions(bitwuzla_parser_get_bitwuzla(parser), &size);
42 printf("Assertions:\n");
43 printf("{\n");
44 for (size_t i = 0; i < size; ++i)
45 {
46 printf(" %s\n", bitwuzla_term_to_string(assertions[i]));
47 }
48 printf("}\n");
49
50 // Now we add an assertion via parsing from string.
51 bitwuzla_parser_parse(
52 parser, "(assert (distinct (select a x) y))", true, false, &error_msg);
53 // We expect no error to occur.
54 assert(!error_msg);
55 // Now the formula is unsat.
56 BitwuzlaResult result =
57 bitwuzla_check_sat(bitwuzla_parser_get_bitwuzla(parser));
58
59 printf("Expect: unsat\n");
60 printf("Bitwuzla: %s\n\n", bitwuzla_result_to_string(result));
61
62 // For illustration purposes, we now parse in some declarations and terms
63 // and sorts from string.
64
65 // Declare bit-vector sort of size 16.
66 BitwuzlaSort bv16 =
67 bitwuzla_parser_parse_sort(parser, "(_ BitVec 16)", &error_msg);
68 // We expect no error to occur.
69 assert(!error_msg);
70 // Create bit-vector sort of size 16 and show that it corresponds to
71 // its string representation '(_ BitVec16)'.
72 assert(bv16 == bitwuzla_mk_bv_sort(tm, 16));
73
74 // Declare Boolean constants 'c' and 'd'.
75 // Note: Declarations are commands (not terms) in the SMT-LIB language.
76 // Commands must be parsed in via bitwuzla_parser_parse(),
77 // bitwuzla_parser_parse_term() only supports parsing SMT-LIB terms.
78 bitwuzla_parser_parse(parser,
79 "(declare-const c Bool)(declare-const d Bool)",
80 true,
81 false,
82 &error_msg);
83 // Declare bit-vector constant 'b'.
84 bitwuzla_parser_parse(
85 parser, "(declare-const b (_ BitVec 16))", true, false, &error_msg);
86 // We expect no error to occur.
87 assert(!error_msg);
88 // Retrieve term representing 'b'.
89 BitwuzlaTerm b = bitwuzla_parser_parse_term(parser, "b", &error_msg);
90 // We expect no error to occur.
91 assert(!error_msg);
92 // Retrieve term representing 'c'.
93 BitwuzlaTerm c = bitwuzla_parser_parse_term(parser, "c", &error_msg);
94 // We expect no error to occur.
95 assert(!error_msg);
96 // Retrieve term representing 'd'.
97 BitwuzlaTerm d = bitwuzla_parser_parse_term(parser, "d", &error_msg);
98 // We expect no error to occur.
99 assert(!error_msg);
100 // Create xor over 'a' and 'c' and show that it corresponds to term
101 // parsed in from its string representation '(xor c d)'.
102 assert(bitwuzla_parser_parse_term(parser, "(xor c d)", &error_msg)
103 == bitwuzla_mk_term2(tm, BITWUZLA_KIND_XOR, c, d));
104 // Create bit-vector addition over 'b' and bit-vector value
105 // '1011111010001010' and show that it corresponds to the term parsed in
106 // from its string representation '(bvadd b #b1011111010001010)'.
107 assert(bitwuzla_parser_parse_term(
108 parser, "(bvadd b #b1011111010001010)", &error_msg)
109 == bitwuzla_mk_term2(
110 tm,
111 BITWUZLA_KIND_BV_ADD,
112 b,
113 bitwuzla_mk_bv_value(tm, bv16, "1011111010001010", 2)));
114 // Finally, delete Bitwuzla parser, options, and term manager instance.
115 bitwuzla_parser_delete(parser);
116 bitwuzla_options_delete(options);
117 bitwuzla_term_manager_delete(tm);
118
119 return 0;
120}
Printing Example
1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == "__main__":
14
15 # First, create a term manager instance.
16 tm = TermManager()
17 # Create a Bitwuzla options instance.
18 options = Options()
19 options.set(Option.PRODUCE_MODELS, True)
20 # Then, create a Bitwuzla instance.
21 bitwuzla = Bitwuzla(tm, options)
22 # Create some sorts.
23 bv8 = tm.mk_bv_sort(8)
24 bv32 = tm.mk_bv_sort(32)
25 fp16 = tm.mk_fp_sort(5, 11)
26 # Create terms.
27 b = tm.mk_const(tm.mk_bool_sort(), "b")
28 bv = tm.mk_const(bv8, "bv")
29 fp = tm.mk_const(fp16, "fp")
30 rm = tm.mk_const(tm.mk_rm_sort(), "rm")
31 fun = tm.mk_const(tm.mk_fun_sort([bv8, fp16, bv32], fp16), "fun")
32 zero = tm.mk_bv_zero(bv8)
33 ones = tm.mk_bv_ones(tm.mk_bv_sort(23))
34 z = tm.mk_var(bv8, "z")
35 q = tm.mk_var(bv8, "q")
36 lambd = tm.mk_term(Kind.LAMBDA, [z, tm.mk_term(Kind.BV_ADD, [z, bv])])
37 fpleq = tm.mk_term(
38 Kind.FP_LEQ,
39 [tm.mk_term(Kind.APPLY,
40 [fun, bv, fp, tm.mk_term(Kind.BV_ZERO_EXTEND, [ones], [9])]),
41 fp])
42 exists = tm.mk_term(
43 Kind.EXISTS,
44 [q, tm.mk_term(Kind.EQUAL, [zero, tm.mk_term(Kind.BV_MUL, [bv, q])])])
45 # Assert formulas.
46 bitwuzla.assert_formula(b)
47 bitwuzla.assert_formula(
48 tm.mk_term(Kind.EQUAL, [tm.mk_term(Kind.APPLY, [lambd, bv]), zero]))
49 bitwuzla.assert_formula(exists)
50 bitwuzla.assert_formula(fpleq)
51
52 # Print sort.
53 print('Print bit-vector sort of size 32:')
54 print('---------------------------------')
55 print(f'str(): {bv32}')
56 print()
57
58 # Print terms.
59 # Note: Hexadecimal bv output format is ignored if the value is not of size
60 # divisible by 4.
61 print('Print term:')
62 print('-----------')
63 print(f'str() [default]: {rm}')
64 print(f'str() [bin (ignored)]: {rm.str(2)}')
65 print(f'str() [dec (ignored)]: {rm.str(10)}')
66 print(f'str(16) [hex (ignored)]: {rm.str(16)}')
67 print()
68 print(f'str() [default]: {zero}')
69 print(f'str() [bin]: {zero.str(2)}')
70 print(f'str(10) [dec]: {zero.str(10)}')
71 print(f'str(16) [hex]: {zero.str(16)}')
72 print()
73 print(f'str() [default]: {fpleq}')
74 print(f'str() [bin]: {fpleq.str()}')
75 print(f'str(10) [dec]: {fpleq.str(10)}')
76 print(f'str(16) [hex (ignored)]: {fpleq.str(16)}')
77 print()
78
79 # Print asserted formulas.
80 # Note: This uses the default bit-vector output format (binary).
81 expected_smt2 = \
82 '(set-logic UFBVFP)\n' \
83 + '(declare-const b Bool)\n' \
84 + '(declare-const bv (_ BitVec 8))\n' \
85 + '(declare-const fp (_ FloatingPoint 5 11))\n' \
86 + '(declare-fun fun ((_ BitVec 8) (_ FloatingPoint 5 11) ' \
87 + '(_ BitVec 32)) (_ FloatingPoint 5 11))\n' \
88 + '(assert b)\n' \
89 + '(assert (= ((lambda ((z (_ BitVec 8))) (bvadd z bv)) bv) ' \
90 + '#b00000000))\n' \
91 + '(assert (exists ((q (_ BitVec 8))) (= #b00000000 ' \
92 + '(bvmul bv q))))\n' \
93 + '(assert (fp.leq (fun bv fp ((_ zero_extend 9) ' \
94 + '#b11111111111111111111111)) fp))\n' \
95 + '(check-sat)\n' \
96 + '(exit)\n'
97 res = bitwuzla.print_formula()
98 assert res == expected_smt2
99 print('Print formula [default (binary) bv output format]:')
100 print('--------------------------------------------------')
101 print(res)
102
103 # Print asserted formulas using hexadecimal bit-vector output format.
104 expected_smt2 = \
105 '(set-logic UFBVFP)\n' \
106 + '(declare-const b Bool)\n' \
107 + '(declare-const bv (_ BitVec 8))\n' \
108 + '(declare-const fp (_ FloatingPoint 5 11))\n' \
109 + '(declare-fun fun ((_ BitVec 8) (_ FloatingPoint 5 11) ' \
110 + '(_ BitVec 32)) (_ FloatingPoint 5 11))\n' \
111 + '(assert b)\n' \
112 + '(assert (= ((lambda ((z (_ BitVec 8))) (bvadd z bv)) bv) ' \
113 + '#x00))\n' \
114 + '(assert (exists ((q (_ BitVec 8))) (= #x00 (bvmul bv q))))\n' \
115 + '(assert (fp.leq (fun bv fp ((_ zero_extend 9) ' \
116 + '#b11111111111111111111111)) fp))\n' \
117 + '(check-sat)\n' \
118 + '(exit)\n'
119 res = bitwuzla.print_formula("smt2", 16)
120 assert res == expected_smt2
121 print('Print formula [hexadecimal bv output format]:')
122 print('--------------------------------------------------')
123 print(res)
124
125 # Print asserted formulas using decimal bit-vector output format.
126 expected_smt2 = \
127 '(set-logic UFBVFP)\n' \
128 + '(declare-const b Bool)\n' \
129 + '(declare-const bv (_ BitVec 8))\n' \
130 + '(declare-const fp (_ FloatingPoint 5 11))\n' \
131 + '(declare-fun fun ((_ BitVec 8) (_ FloatingPoint 5 11) ' \
132 + '(_ BitVec 32)) (_ FloatingPoint 5 11))\n' \
133 + '(assert b)\n' \
134 + '(assert (= ((lambda ((z (_ BitVec 8))) (bvadd z bv)) bv) ' \
135 + '(_ bv0 8)))\n' \
136 + '(assert (exists ((q (_ BitVec 8))) (= (_ bv0 8) ' \
137 + '(bvmul bv q))))\n' \
138 + '(assert (fp.leq (fun bv fp ((_ zero_extend 9) ' \
139 + '(_ bv8388607 23))) fp))\n' \
140 + '(check-sat)\n' \
141 + '(exit)\n'
142 res = bitwuzla.print_formula("smt2", 10)
143 assert res == expected_smt2
144 print('Print formula [decimal bv output format]:')
145 print('---------------------------------------------')
146 print(res)
147
148 bitwuzla.check_sat()
149
150 # Print values.
151 print('Print value of Boolean predicate:')
152 print('---------------------------------')
153 fpleq_val = bitwuzla.get_value(fpleq).value()
154 print(f'{fpleq}: {fpleq_val} [bool]')
155 print()
156
157 print('Print value of bv const:')
158 print('------------------------')
159 print(f'{bv}: {bitwuzla.get_value(bv).value():>8} [str] (bin)')
160 print(f'{bv}: {bitwuzla.get_value(bv).value(10):>8} [str] (dec)')
161 print(f'{bv}: {bitwuzla.get_value(bv).value(16):>8} [str] (hex)')
162 print()
163
164 print('Print value of RoundingMode const:')
165 print('----------------------------------')
166 print(f'{rm}: {bitwuzla.get_value(rm).value()} [RoundingMode]')
167 print()
168
169 fp_val = bitwuzla.get_value(fp)
170
171 print('Print value of fp const as single bit-vector (base ignored):')
172 print('------------------------------------------------------------')
173 assert fp_val.value(2, False) == fp_val.value(10, False)
174 assert fp_val.value(2, False) == fp_val.value(16, False)
175 print(f'{fp}: {fp_val.value(2, False):>16} [str] (bin)')
176 print(f'{fp}: {fp_val.value(10, False):>16} [str] (dec [ignored])')
177 print(f'{fp}: {fp_val.value(16, False):>16} [str] (hex [ignored])')
178 print()
179
180 print('Print value of fp const as list of component bit-vectors:')
181 print('---------------------------------------------------------')
182 val = fp_val.value(2)
183 print(f'{fp}: [{val[0]}, {val[1]:>5}, {val[2]:>11}] [str] (bin)')
184 val = fp_val.value(10)
185 print(f'{fp}: [{val[0]}, {val[1]:>5}, {val[2]:>11}] [str] (dec)')
186 val = fp_val.value(16)
187 print(f'{fp}: [{val[0]}, {val[1]:>5}, {val[2]:>11}] [str] (hex)')
188 print()
1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11from bitwuzla import *
12
13if __name__ == "__main__":
14
15 # First, create a term manager instance.
16 tm = TermManager()
17 # Create a Bitwuzla options instance.
18 options = Options()
19 options.set(Option.PRODUCE_MODELS, True)
20 # Then, create a Bitwuzla instance.
21 bitwuzla = Bitwuzla(tm, options)
22 # Create some sorts.
23 bv8 = tm.mk_bv_sort(8)
24 bv32 = tm.mk_bv_sort(32)
25 fp16 = tm.mk_fp_sort(5, 11)
26 # Create terms.
27 b = tm.mk_const(tm.mk_bool_sort(), "b")
28 bv = tm.mk_const(bv8, "bv")
29 fp = tm.mk_const(fp16, "fp")
30 rm = tm.mk_const(tm.mk_rm_sort(), "rm")
31 fun = tm.mk_const(tm.mk_fun_sort([bv8, fp16, bv32], fp16), "fun")
32 zero = tm.mk_bv_zero(bv8)
33 ones = tm.mk_bv_ones(tm.mk_bv_sort(23))
34 z = tm.mk_var(bv8, "z")
35 q = tm.mk_var(bv8, "q")
36 lambd = tm.mk_term(Kind.LAMBDA, [z, tm.mk_term(Kind.BV_ADD, [z, bv])])
37 fpleq = tm.mk_term(
38 Kind.FP_LEQ,
39 [tm.mk_term(Kind.APPLY,
40 [fun, bv, fp, tm.mk_term(Kind.BV_ZERO_EXTEND, [ones], [9])]),
41 fp])
42 exists = tm.mk_term(
43 Kind.EXISTS,
44 [q, tm.mk_term(Kind.EQUAL, [zero, tm.mk_term(Kind.BV_MUL, [bv, q])])])
45 # Assert formulas.
46 bitwuzla.assert_formula(b)
47 bitwuzla.assert_formula(
48 tm.mk_term(Kind.EQUAL, [tm.mk_term(Kind.APPLY, [lambd, bv]), zero]))
49 bitwuzla.assert_formula(exists)
50 bitwuzla.assert_formula(fpleq)
51
52 # Print sort.
53 print('Print bit-vector sort of size 32:')
54 print('---------------------------------')
55 print(f'str(): {bv32}')
56 print()
57
58 # Print terms.
59 # Note: Hexadecimal bv output format is ignored if the value is not of size
60 # divisible by 4.
61 print('Print term:')
62 print('-----------')
63 print(f'str() [default]: {rm}')
64 print(f'str() [bin (ignored)]: {rm.str(2)}')
65 print(f'str() [dec (ignored)]: {rm.str(10)}')
66 print(f'str(16) [hex (ignored)]: {rm.str(16)}')
67 print()
68 print(f'str() [default]: {zero}')
69 print(f'str() [bin]: {zero.str(2)}')
70 print(f'str(10) [dec]: {zero.str(10)}')
71 print(f'str(16) [hex]: {zero.str(16)}')
72 print()
73 print(f'str() [default]: {fpleq}')
74 print(f'str() [bin]: {fpleq.str()}')
75 print(f'str(10) [dec]: {fpleq.str(10)}')
76 print(f'str(16) [hex (ignored)]: {fpleq.str(16)}')
77 print()
78
79 # Print asserted formulas.
80 # Note: This uses the default bit-vector output format (binary).
81 expected_smt2 = \
82 '(set-logic UFBVFP)\n' \
83 + '(declare-const b Bool)\n' \
84 + '(declare-const bv (_ BitVec 8))\n' \
85 + '(declare-const fp (_ FloatingPoint 5 11))\n' \
86 + '(declare-fun fun ((_ BitVec 8) (_ FloatingPoint 5 11) ' \
87 + '(_ BitVec 32)) (_ FloatingPoint 5 11))\n' \
88 + '(assert b)\n' \
89 + '(assert (= ((lambda ((z (_ BitVec 8))) (bvadd z bv)) bv) ' \
90 + '#b00000000))\n' \
91 + '(assert (exists ((q (_ BitVec 8))) (= #b00000000 ' \
92 + '(bvmul bv q))))\n' \
93 + '(assert (fp.leq (fun bv fp ((_ zero_extend 9) ' \
94 + '#b11111111111111111111111)) fp))\n' \
95 + '(check-sat)\n' \
96 + '(exit)\n'
97 res = bitwuzla.print_formula()
98 assert res == expected_smt2
99 print('Print formula [default (binary) bv output format]:')
100 print('--------------------------------------------------')
101 print(res)
102
103 # Print asserted formulas using hexadecimal bit-vector output format.
104 expected_smt2 = \
105 '(set-logic UFBVFP)\n' \
106 + '(declare-const b Bool)\n' \
107 + '(declare-const bv (_ BitVec 8))\n' \
108 + '(declare-const fp (_ FloatingPoint 5 11))\n' \
109 + '(declare-fun fun ((_ BitVec 8) (_ FloatingPoint 5 11) ' \
110 + '(_ BitVec 32)) (_ FloatingPoint 5 11))\n' \
111 + '(assert b)\n' \
112 + '(assert (= ((lambda ((z (_ BitVec 8))) (bvadd z bv)) bv) ' \
113 + '#x00))\n' \
114 + '(assert (exists ((q (_ BitVec 8))) (= #x00 (bvmul bv q))))\n' \
115 + '(assert (fp.leq (fun bv fp ((_ zero_extend 9) ' \
116 + '#b11111111111111111111111)) fp))\n' \
117 + '(check-sat)\n' \
118 + '(exit)\n'
119 res = bitwuzla.print_formula("smt2", 16)
120 assert res == expected_smt2
121 print('Print formula [hexadecimal bv output format]:')
122 print('--------------------------------------------------')
123 print(res)
124
125 # Print asserted formulas using decimal bit-vector output format.
126 expected_smt2 = \
127 '(set-logic UFBVFP)\n' \
128 + '(declare-const b Bool)\n' \
129 + '(declare-const bv (_ BitVec 8))\n' \
130 + '(declare-const fp (_ FloatingPoint 5 11))\n' \
131 + '(declare-fun fun ((_ BitVec 8) (_ FloatingPoint 5 11) ' \
132 + '(_ BitVec 32)) (_ FloatingPoint 5 11))\n' \
133 + '(assert b)\n' \
134 + '(assert (= ((lambda ((z (_ BitVec 8))) (bvadd z bv)) bv) ' \
135 + '(_ bv0 8)))\n' \
136 + '(assert (exists ((q (_ BitVec 8))) (= (_ bv0 8) ' \
137 + '(bvmul bv q))))\n' \
138 + '(assert (fp.leq (fun bv fp ((_ zero_extend 9) ' \
139 + '(_ bv8388607 23))) fp))\n' \
140 + '(check-sat)\n' \
141 + '(exit)\n'
142 res = bitwuzla.print_formula("smt2", 10)
143 assert res == expected_smt2
144 print('Print formula [decimal bv output format]:')
145 print('---------------------------------------------')
146 print(res)
147
148 bitwuzla.check_sat()
149
150 # Print values.
151 print('Print value of Boolean predicate:')
152 print('---------------------------------')
153 fpleq_val = bitwuzla.get_value(fpleq).value()
154 print(f'{fpleq}: {fpleq_val} [bool]')
155 print()
156
157 print('Print value of bv const:')
158 print('------------------------')
159 print(f'{bv}: {bitwuzla.get_value(bv).value():>8} [str] (bin)')
160 print(f'{bv}: {bitwuzla.get_value(bv).value(10):>8} [str] (dec)')
161 print(f'{bv}: {bitwuzla.get_value(bv).value(16):>8} [str] (hex)')
162 print()
163
164 print('Print value of RoundingMode const:')
165 print('----------------------------------')
166 print(f'{rm}: {bitwuzla.get_value(rm).value()} [RoundingMode]')
167 print()
168
169 fp_val = bitwuzla.get_value(fp)
170
171 print('Print value of fp const as single bit-vector (base ignored):')
172 print('------------------------------------------------------------')
173 assert fp_val.value(2, False) == fp_val.value(10, False)
174 assert fp_val.value(2, False) == fp_val.value(16, False)
175 print(f'{fp}: {fp_val.value(2, False):>16} [str] (bin)')
176 print(f'{fp}: {fp_val.value(10, False):>16} [str] (dec [ignored])')
177 print(f'{fp}: {fp_val.value(16, False):>16} [str] (hex [ignored])')
178 print()
179
180 print('Print value of fp const as list of component bit-vectors:')
181 print('---------------------------------------------------------')
182 val = fp_val.value(2)
183 print(f'{fp}: [{val[0]}, {val[1]:>5}, {val[2]:>11}] [str] (bin)')
184 val = fp_val.value(10)
185 print(f'{fp}: [{val[0]}, {val[1]:>5}, {val[2]:>11}] [str] (dec)')
186 val = fp_val.value(16)
187 print(f'{fp}: [{val[0]}, {val[1]:>5}, {val[2]:>11}] [str] (hex)')
188 print()
1/***
2 * Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3 *
4 * Copyright (C) 2023 by the authors listed in the AUTHORS file at
5 * https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6 *
7 * This file is part of Bitwuzla under the MIT license. See COPYING for more
8 * information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
9 */
10
11#include <assert.h>
12#include <bitwuzla/c/bitwuzla.h>
13#include <stdio.h>
14
15int
16main()
17{
18 // First, create a term manager instance.
19 BitwuzlaTermManager* tm = bitwuzla_term_manager_new();
20 // Create a Bitwuzla options instance.
21 BitwuzlaOptions* options = bitwuzla_options_new();
22 bitwuzla_set_option(options, BITWUZLA_OPT_PRODUCE_MODELS, 1);
23 // Then, create a Bitwuzla instance.
24 Bitwuzla* bitwuzla = bitwuzla_new(tm, options);
25 // Create some sorts.
26 BitwuzlaSort bv8 = bitwuzla_mk_bv_sort(tm, 8);
27 BitwuzlaSort bv32 = bitwuzla_mk_bv_sort(tm, 32);
28 BitwuzlaSort fp16 = bitwuzla_mk_fp_sort(tm, 5, 11);
29 BitwuzlaSort fun_domain[3] = {bv8, fp16, bv32};
30 BitwuzlaSort fun_sort = bitwuzla_mk_fun_sort(tm, 3, fun_domain, fp16);
31 // Create terms.
32 BitwuzlaTerm b = bitwuzla_mk_const(tm, bitwuzla_mk_bool_sort(tm), "b");
33 BitwuzlaTerm bv = bitwuzla_mk_const(tm, bv8, "bv");
34 BitwuzlaTerm fp = bitwuzla_mk_const(tm, fp16, "fp");
35 BitwuzlaTerm rm = bitwuzla_mk_const(tm, bitwuzla_mk_rm_sort(tm), "rm");
36 BitwuzlaTerm fun = bitwuzla_mk_const(tm, fun_sort, "fun");
37 BitwuzlaTerm zero = bitwuzla_mk_bv_zero(tm, bv8);
38 BitwuzlaTerm ones = bitwuzla_mk_bv_ones(tm, bitwuzla_mk_bv_sort(tm, 23));
39 BitwuzlaTerm z = bitwuzla_mk_var(tm, bv8, "z");
40 BitwuzlaTerm q = bitwuzla_mk_var(tm, bv8, "q");
41 BitwuzlaTerm lambda =
42 bitwuzla_mk_term2(tm,
43 BITWUZLA_KIND_LAMBDA,
44 z,
45 bitwuzla_mk_term2(tm, BITWUZLA_KIND_BV_ADD, z, bv));
46 BitwuzlaTerm args[4] = {
47 fun,
48 bv,
49 fp,
50 bitwuzla_mk_term1_indexed1(tm, BITWUZLA_KIND_BV_ZERO_EXTEND, ones, 9)};
51 BitwuzlaTerm fpleq =
52 bitwuzla_mk_term2(tm,
53 BITWUZLA_KIND_FP_LEQ,
54 bitwuzla_mk_term(tm, BITWUZLA_KIND_APPLY, 4, args),
55 fp);
56 BitwuzlaTerm exists = bitwuzla_mk_term2(
57 tm,
58 BITWUZLA_KIND_EXISTS,
59 q,
60 bitwuzla_mk_term2(tm,
61 BITWUZLA_KIND_EQUAL,
62 zero,
63 bitwuzla_mk_term2(tm, BITWUZLA_KIND_BV_MUL, bv, q)));
64 // Assert formulas.
65 bitwuzla_assert(bitwuzla, b);
66 bitwuzla_assert(
67 bitwuzla,
68 bitwuzla_mk_term2(tm,
69 BITWUZLA_KIND_EQUAL,
70 bitwuzla_mk_term2(tm, BITWUZLA_KIND_APPLY, lambda, bv),
71 zero));
72 bitwuzla_assert(bitwuzla, exists);
73 bitwuzla_assert(bitwuzla, fpleq);
74
75 // Print sort.
76 printf("Print bit-vector sort of size 32:\n");
77 printf("---------------------------------\n");
78 printf("bitwuzla_sort_print(): ");
79 bitwuzla_sort_print(bv32, stdout);
80 printf("\n");
81 printf("bitwuzla_sort_to_string(): %s\n\n", bitwuzla_sort_to_string(bv32));
82
83 // Print terms.
84 // Note: Hexadecimal bv output format is ignored if the value is not of size
85 // divisible by 4.
86 printf("Print term:\n");
87 printf("-----------\n");
88 printf("bitwuzla_term_print(): ");
89 bitwuzla_term_print(rm, stdout);
90 printf("\n");
91 printf("bitwuzla_term_print_fmt() [dec (ignored)]: ");
92 bitwuzla_term_print_fmt(rm, stdout, 10);
93 printf("\n");
94 printf("bitwuzla_term_to_string(): %s\n",
95 bitwuzla_term_to_string(rm));
96 printf("bitwuzla_term_to_string_fmt() [hex (ignored)]: %s\n",
97 bitwuzla_term_to_string_fmt(rm, 10));
98 printf("\n");
99 printf("bitwuzla_term_print() [bin]: ");
100 bitwuzla_term_print(zero, stdout);
101 printf("\n");
102 printf("bitwuzla_term_print_fmt() [dec]: ");
103 bitwuzla_term_print_fmt(zero, stdout, 10);
104 printf("\n");
105 printf("bitwuzla_term_print_fmt() [hex]: ");
106 bitwuzla_term_print_fmt(zero, stdout, 16);
107 printf("\n");
108 printf("bitwuzla_term_to_string() [bin]: %s\n",
109 bitwuzla_term_to_string(zero));
110 printf("bitwuzla_term_to_string_fmt() [dec]: %s\n",
111 bitwuzla_term_to_string_fmt(zero, 10));
112 printf("bitwuzla_term_to_string_fmt() [hex]: %s\n",
113 bitwuzla_term_to_string_fmt(zero, 16));
114 printf("\n");
115 printf("bitwuzla_term_print_fmt() [bin]: ");
116 bitwuzla_term_print_fmt(fpleq, stdout, 2);
117 printf("\n");
118 printf("bitwuzla_term_print_fmt() [dec]: ");
119 bitwuzla_term_print_fmt(fpleq, stdout, 10);
120 printf("\n");
121 printf("bitwuzla_term_print_fmt() [hex (ignored)]: ");
122 bitwuzla_term_print_fmt(fpleq, stdout, 16);
123 printf("\n");
124 printf("bitwuzla_term_to_string_fmt() [bin]: %s\n",
125 bitwuzla_term_to_string_fmt(fpleq, 2));
126 printf("bitwuzla_term_to_string_fmt() [dec]: %s\n",
127 bitwuzla_term_to_string_fmt(fpleq, 10));
128 printf("bitwuzla_term_to_string_fmt() [hex (ignored)]: %s\n",
129 bitwuzla_term_to_string_fmt(fpleq, 16));
130 printf("\n");
131
132 // Print asserted formulas using binary bit-vector output format.
133 {
134 printf("Print formula [binary bv output format]:\n");
135 printf("----------------------------------------\n");
136 bitwuzla_print_formula(bitwuzla, "smt2", stdout, 2);
137 printf("\n");
138 }
139
140 // Print asserted formulas using hexadecimal bit-vector output format.
141 {
142 printf("Print formula [hexadecimal bv output format]:\n");
143 printf("----------------------------------------\n");
144 bitwuzla_print_formula(bitwuzla, "smt2", stdout, 16);
145 printf("\n");
146 }
147
148 // Print asserted formulas using decimal bit-vector output format.
149 {
150 printf("Print formula [decimal bv output format]:\n");
151 printf("----------------------------------------\n");
152 bitwuzla_print_formula(bitwuzla, "smt2", stdout, 10);
153 printf("\n");
154 }
155
156 bitwuzla_check_sat(bitwuzla);
157
158 // Print values.
159 printf("Print value of Boolean predicate:\n");
160 printf("---------------------------------\n");
161 BitwuzlaTerm fpleq_val = bitwuzla_get_value(bitwuzla, fpleq);
162 bool fpleq_val_bool = bitwuzla_term_value_get_bool(fpleq_val);
163 const char* fpleq_val_str = bitwuzla_term_value_get_str(fpleq_val);
164 printf("%s: %*u [bool]\n", bitwuzla_term_to_string(fpleq), 4, fpleq_val_bool);
165 printf("%s: %*s [const char*]\n\n",
166 bitwuzla_term_to_string(fpleq),
167 4,
168 fpleq_val_str);
169
170 printf("Print value of bv const:\n");
171 printf("------------------------\n");
172 BitwuzlaTerm bv_val = bitwuzla_get_value(bitwuzla, bv);
173 printf("%s: %*s [const char*] (bin)\n",
174 bitwuzla_term_to_string(bv),
175 8,
176 bitwuzla_term_value_get_str(bv_val));
177 printf("%s: %*s [const char*] (dec)\n",
178 bitwuzla_term_to_string(bv),
179 8,
180 bitwuzla_term_value_get_str_fmt(bv_val, 10));
181 printf("%s: %*s [const char*] (hex)\n\n",
182 bitwuzla_term_to_string(bv),
183 8,
184 bitwuzla_term_value_get_str_fmt(bv_val, 16));
185
186 printf("Print value of RoundingMode const:\n");
187 printf("----------------------------------\n");
188 BitwuzlaTerm rm_val = bitwuzla_get_value(bitwuzla, rm);
189 BitwuzlaRoundingMode rm_val_rm = bitwuzla_term_value_get_rm(rm_val);
190 const char* rm_val_str = bitwuzla_term_value_get_str(rm_val);
191 printf("%s: %s [BitwuzlaRoundingMode]\n",
192 bitwuzla_term_to_string(rm),
193 bitwuzla_rm_to_string(rm_val_rm));
194 printf("%s: %s [const char*]\n\n", bitwuzla_term_to_string(rm), rm_val_str);
195
196 BitwuzlaTerm fp_val = bitwuzla_get_value(bitwuzla, fp);
197
198 printf("Print value of fp const via bitwuzla_term_value_get_str(_fmt):\n");
199 printf("--------------------------------------------------------------\n");
200 printf("%s: %*s [const char*] (bin) \n",
201 bitwuzla_term_to_string(fp),
202 16,
203 bitwuzla_term_value_get_str(fp_val));
204 printf("%s: %*s [const char*] (dec [ignored]) \n",
205 bitwuzla_term_to_string(fp),
206 16,
207 bitwuzla_term_value_get_str_fmt(fp_val, 10));
208 printf("%s: %*s [const char*] (hex [ignored]) \n\n",
209 bitwuzla_term_to_string(fp),
210 16,
211 bitwuzla_term_value_get_str_fmt(fp_val, 16));
212
213 printf("Print value of fp const via bitwuzla_term_value_get_fp_ieee():\n");
214 printf("--------------------------------------------------------------\n");
215 const char* sign;
216 const char* exponent;
217 const char* significand;
218 bitwuzla_term_value_get_fp_ieee(fp_val, &sign, &exponent, &significand, 2);
219 printf("%s: (%s %*s %*s) (bin)\n",
220 bitwuzla_term_to_string(fp),
221 sign,
222 5,
223 exponent,
224 11,
225 significand);
226 bitwuzla_term_value_get_fp_ieee(fp_val, &sign, &exponent, &significand, 10);
227 printf("%s: (%s %*s %*s) (dec)\n",
228 bitwuzla_term_to_string(fp),
229 sign,
230 5,
231 exponent,
232 11,
233 significand);
234 bitwuzla_term_value_get_fp_ieee(fp_val, &sign, &exponent, &significand, 16);
235 printf("%s: (%s %*s %*s) (hex)\n",
236 bitwuzla_term_to_string(fp),
237 sign,
238 5,
239 exponent,
240 11,
241 significand);
242
243 // Finally, delete the Bitwuzla solver, options, and term manager instances.
244 bitwuzla_delete(bitwuzla);
245 bitwuzla_options_delete(options);
246 bitwuzla_term_manager_delete(tm);
247 return 0;
248}
Termination Callback Example
1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11import time
12
13from bitwuzla import *
14
15class TestTerminator:
16 def __init__(self, time_limit):
17 self.start_time = time.time()
18 self.time_limit = time_limit
19
20 def __call__(self):
21 # Terminate after self.time_limit ms passed
22 return (time.time() - self.start_time) * 1000 > self.time_limit
23
24if __name__ == '__main__':
25
26 # First, create a term manager instance.
27 tm = TermManager()
28 # No options configured, create Bitwuzla instance with default options.
29 bitwuzla = Bitwuzla(tm)
30
31 bv = tm.mk_bv_sort(32)
32
33 x = tm.mk_const(bv)
34 s = tm.mk_const(bv)
35 t = tm.mk_const(bv)
36
37 a = tm.mk_term(Kind.DISTINCT,
38 [tm.mk_term(Kind.BV_MUL, [s, tm.mk_term(Kind.BV_MUL, [x, t])]),
39 tm.mk_term(Kind.BV_MUL, [tm.mk_term(Kind.BV_MUL, [s, x]), t])])
40
41 # Now, we check that the following formula is unsat.
42 # (assert (distinct (bvmul s (bvmul x t)) (bvmul (bvmul s x) t)))
43 print('> Without terminator (with preprocessing):')
44 print('Expect: unsat')
45 print(f'Bitwuzla: {bitwuzla.check_sat(a)}')
46
47 # Now, for illustration purposes, we disable preprocessing, which will
48 # significantly increase solving time, and connect a terminator instance
49 # that terminates after a certain time limit.
50 options = Options()
51 options.set(Option.PREPROCESS, False)
52 # Create new Bitwuzla instance with reconfigured options.
53 bitwuzla2 = Bitwuzla(tm, options)
54 # Configure and connect terminator.
55 tt = TestTerminator(1)
56 bitwuzla2.configure_terminator(tt)
57
58 # Now, we expect Bitwuzla to be terminated during the check-sat call.
59 print('> With terminator (no preprocessing):')
60 print('Expect: unsat')
61 print(f'Bitwuzla: {bitwuzla2.check_sat(a)}')
1###
2# Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3#
4# Copyright (C) 2023 by the authors listed in the AUTHORS file at
5# https:#github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6#
7# This file is part of Bitwuzla under the MIT license. See COPYING for more
8# information at https:#github.com/bitwuzla/bitwuzla/blob/main/COPYING
9##
10
11import time
12
13from bitwuzla import *
14
15class TestTerminator:
16 def __init__(self, time_limit):
17 self.start_time = time.time()
18 self.time_limit = time_limit
19
20 def __call__(self):
21 # Terminate after self.time_limit ms passed
22 return (time.time() - self.start_time) * 1000 > self.time_limit
23
24if __name__ == '__main__':
25
26 # First, create a term manager instance.
27 tm = TermManager()
28 # No options configured, create Bitwuzla instance with default options.
29 bitwuzla = Bitwuzla(tm)
30
31 bv = tm.mk_bv_sort(32)
32
33 x = tm.mk_const(bv)
34 s = tm.mk_const(bv)
35 t = tm.mk_const(bv)
36
37 a = tm.mk_term(Kind.DISTINCT,
38 [tm.mk_term(Kind.BV_MUL, [s, tm.mk_term(Kind.BV_MUL, [x, t])]),
39 tm.mk_term(Kind.BV_MUL, [tm.mk_term(Kind.BV_MUL, [s, x]), t])])
40
41 # Now, we check that the following formula is unsat.
42 # (assert (distinct (bvmul s (bvmul x t)) (bvmul (bvmul s x) t)))
43 print('> Without terminator (with preprocessing):')
44 print('Expect: unsat')
45 print(f'Bitwuzla: {bitwuzla.check_sat(a)}')
46
47 # Now, for illustration purposes, we disable preprocessing, which will
48 # significantly increase solving time, and connect a terminator instance
49 # that terminates after a certain time limit.
50 options = Options()
51 options.set(Option.PREPROCESS, False)
52 # Create new Bitwuzla instance with reconfigured options.
53 bitwuzla2 = Bitwuzla(tm, options)
54 # Configure and connect terminator.
55 tt = TestTerminator(1)
56 bitwuzla2.configure_terminator(tt)
57
58 # Now, we expect Bitwuzla to be terminated during the check-sat call.
59 print('> With terminator (no preprocessing):')
60 print('Expect: unsat')
61 print(f'Bitwuzla: {bitwuzla2.check_sat(a)}')
1/***
2 * Bitwuzla: Satisfiability Modulo Theories (SMT) solver.
3 *
4 * Copyright (C) 2023 by the authors listed in the AUTHORS file at
5 * https://github.com/bitwuzla/bitwuzla/blob/main/AUTHORS
6 *
7 * This file is part of Bitwuzla under the MIT license. See COPYING for more
8 * information at https://github.com/bitwuzla/bitwuzla/blob/main/COPYING
9 */
10
11#include <bitwuzla/c/bitwuzla.h>
12#include <stdint.h>
13#include <stdio.h>
14#include <sys/time.h>
15
16struct terminator_state
17{
18 struct timeval start;
19 uint32_t time_limit_ms;
20};
21
22static int32_t
23test_terminate(void* state)
24{
25 struct terminator_state* tstate = (struct terminator_state*) state;
26 struct timeval now;
27 gettimeofday(&now, NULL);
28 if (((now.tv_sec - tstate->start.tv_sec) * 1000
29 + (now.tv_usec - tstate->start.tv_usec) / 1000)
30 >= tstate->time_limit_ms)
31 {
32 return 1;
33 }
34 return 0;
35}
36
37int
38main()
39{
40 // First, create a term manager instance.
41 BitwuzlaTermManager* tm = bitwuzla_term_manager_new();
42 // Create a Bitwuzla options instance.
43 BitwuzlaOptions* options = bitwuzla_options_new();
44 // Then, create a Bitwuzla instance.
45 Bitwuzla* bitwuzla = bitwuzla_new(tm, options);
46
47 BitwuzlaSort bv = bitwuzla_mk_bv_sort(tm, 32);
48
49 BitwuzlaTerm x = bitwuzla_mk_const(tm, bv, "x");
50 BitwuzlaTerm s = bitwuzla_mk_const(tm, bv, "s");
51 BitwuzlaTerm t = bitwuzla_mk_const(tm, bv, "t");
52
53 BitwuzlaTerm a = bitwuzla_mk_term2(
54 tm,
55 BITWUZLA_KIND_DISTINCT,
56 bitwuzla_mk_term2(tm,
57 BITWUZLA_KIND_BV_MUL,
58 s,
59 bitwuzla_mk_term2(tm, BITWUZLA_KIND_BV_MUL, x, t)),
60 bitwuzla_mk_term2(tm,
61 BITWUZLA_KIND_BV_MUL,
62 bitwuzla_mk_term2(tm, BITWUZLA_KIND_BV_MUL, s, x),
63 t));
64
65 // Now, we check that the following formula is unsat.
66 // (assert (distinct (bvmul s (bvmul x t)) (bvmul (bvmul s x) t)))
67 BitwuzlaTerm assumptions[1] = {a};
68 printf("> Without terminator (with preprocessing):\n");
69 printf("Expect: unsat\n");
70 printf("Result: %s\n",
71 bitwuzla_result_to_string(
72 bitwuzla_check_sat_assuming(bitwuzla, 1, assumptions)));
73
74 // Now, for illustration purposes, we disable preprocessing, which will
75 // significantly increase solving time, and connect a terminator instance
76 // that terminates after a certain time limit.
77 bitwuzla_set_option(options, BITWUZLA_OPT_PREPROCESS, 0);
78 // Create new Bitwuzla instance with reconfigured options.
79 Bitwuzla* bitwuzla2 = bitwuzla_new(tm, options);
80 // Configure termination callback.
81 struct terminator_state state;
82 gettimeofday(&state.start, NULL);
83 state.time_limit_ms = 1000;
84 bitwuzla_set_termination_callback(bitwuzla2, test_terminate, &state);
85
86 // Now, we expect Bitwuzla to be terminated during the check-sat call.
87 printf("> With terminator (no preprocessing):\n");
88 printf("Expect: unknown\n");
89 printf("Result: %s\n",
90 bitwuzla_result_to_string(
91 bitwuzla_check_sat_assuming(bitwuzla2, 1, assumptions)));
92
93 // Finally, delete the Bitwuzla solver, options, and term manager instances.
94 bitwuzla_delete(bitwuzla);
95 bitwuzla_delete(bitwuzla2);
96 bitwuzla_options_delete(options);
97 bitwuzla_term_manager_delete(tm);
98
99 return 0;
100}