Theory of Bit-Vectors: extract

examples/api/cpp/extract.cpp

 1/******************************************************************************
 2 * Top contributors (to current version):
 3 *   Aina Niemetz, Clark Barrett, Andrew Reynolds
 4 *
 5 * This file is part of the cvc5 project.
 6 *
 7 * Copyright (c) 2009-2024 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  TermManager tm;
28  Solver slv(tm);
29  slv.setLogic("QF_BV"); // Set the logic
30
31  Sort bitvector32 = tm.mkBitVectorSort(32);
32
33  Term x = tm.mkConst(bitvector32, "a");
34
35  Op ext_31_1 = tm.mkOp(Kind::BITVECTOR_EXTRACT, {31, 1});
36  Term x_31_1 = tm.mkTerm(ext_31_1, {x});
37
38  Op ext_30_0 = tm.mkOp(Kind::BITVECTOR_EXTRACT, {30, 0});
39  Term x_30_0 = tm.mkTerm(ext_30_0, {x});
40
41  Op ext_31_31 = tm.mkOp(Kind::BITVECTOR_EXTRACT, {31, 31});
42  Term x_31_31 = tm.mkTerm(ext_31_31, {x});
43
44  Op ext_0_0 = tm.mkOp(Kind::BITVECTOR_EXTRACT, {0, 0});
45  Term x_0_0 = tm.mkTerm(ext_0_0, {x});
46
47  Term eq = tm.mkTerm(Kind::EQUAL, {x_31_1, x_30_0});
48  cout << " Asserting: " << eq << endl;
49  slv.assertFormula(eq);
50
51  Term eq2 = tm.mkTerm(Kind::EQUAL, {x_31_31, x_0_0});
52  cout << " Check sat assuming: " << eq2.notTerm() << endl;
53  cout << " Expect UNSAT. " << endl;
54  cout << " cvc5: " << slv.checkSatAssuming(eq2.notTerm()) << endl;
55
56  return 0;
57}