Theory of Bit-Vectors: extract

examples/api/cpp/extract.cpp

 1/******************************************************************************
 2 * Top contributors (to current version):
 3 *   Mathias Preiner, Aina Niemetz, Clark Barrett
 4 *
 5 * This file is part of the cvc5 project.
 6 *
 7 * Copyright (c) 2009-2022 by the authors listed in the file AUTHORS
 8 * in the top-level source directory and their institutional affiliations.
 9 * All rights reserved.  See the file COPYING in the top-level source
10 * directory for licensing information.
11 * ****************************************************************************
12 *
13 * A simple demonstration of the solving capabilities of the cvc5
14 * bit-vector solver.
15 *
16 */
17
18#include <cvc5/cvc5.h>
19
20#include <iostream>
21
22using namespace std;
23using namespace cvc5;
24
25int main()
26{
27  Solver slv;
28  slv.setLogic("QF_BV"); // Set the logic
29
30  Sort bitvector32 = slv.mkBitVectorSort(32);
31
32  Term x = slv.mkConst(bitvector32, "a");
33
34  Op ext_31_1 = slv.mkOp(Kind::BITVECTOR_EXTRACT, {31, 1});
35  Term x_31_1 = slv.mkTerm(ext_31_1, {x});
36
37  Op ext_30_0 = slv.mkOp(Kind::BITVECTOR_EXTRACT, {30, 0});
38  Term x_30_0 = slv.mkTerm(ext_30_0, {x});
39
40  Op ext_31_31 = slv.mkOp(Kind::BITVECTOR_EXTRACT, {31, 31});
41  Term x_31_31 = slv.mkTerm(ext_31_31, {x});
42
43  Op ext_0_0 = slv.mkOp(Kind::BITVECTOR_EXTRACT, {0, 0});
44  Term x_0_0 = slv.mkTerm(ext_0_0, {x});
45
46  Term eq = slv.mkTerm(Kind::EQUAL, {x_31_1, x_30_0});
47  cout << " Asserting: " << eq << endl;
48  slv.assertFormula(eq);
49
50  Term eq2 = slv.mkTerm(Kind::EQUAL, {x_31_31, x_0_0});
51  cout << " Check sat assuming: " << eq2.notTerm() << endl;
52  cout << " Expect UNSAT. " << endl;
53  cout << " cvc5: " << slv.checkSatAssuming(eq2.notTerm()) << endl;
54
55  return 0;
56}