all API examples now have java versions too; bitvectors gets built; also updated...
[cvc5.git] / examples / simple_vc_cxx.cpp
1 /********************* */
2 /*! \file simple_vc_cxx.cpp
3 ** \verbatim
4 ** Original author: mdeters
5 ** Major contributors: none
6 ** Minor contributors (to current version): dejan
7 ** This file is part of the CVC4 prototype.
8 ** Copyright (c) 2009-2012 New York University and The University of Iowa
9 ** See the file COPYING in the top-level source directory for licensing
10 ** information.\endverbatim
11 **
12 ** \brief A simple demonstration of the C++ interface
13 **
14 ** A simple demonstration of the C++ interface. Compare to the Java
15 ** interface in SimpleVC.java; they are virtually line-by-line
16 ** identical.
17 **/
18
19 #include <iostream>
20
21 //#include <cvc4/cvc4.h> // use this after CVC4 is properly installed
22 #include "smt/smt_engine.h"
23
24 using namespace std;
25 using namespace CVC4;
26
27 int main() {
28 ExprManager em;
29 SmtEngine smt(&em);
30
31 // Prove that for integers x and y:
32 // x > 0 AND y > 0 => 2x + y >= 3
33
34 Type integer = em.integerType();
35
36 Expr x = em.mkVar("x", integer);
37 Expr y = em.mkVar("y", integer);
38 Expr zero = em.mkConst(Rational(0));
39
40 Expr x_positive = em.mkExpr(kind::GT, x, zero);
41 Expr y_positive = em.mkExpr(kind::GT, y, zero);
42
43 Expr two = em.mkConst(Rational(2));
44 Expr twox = em.mkExpr(kind::MULT, two, x);
45 Expr twox_plus_y = em.mkExpr(kind::PLUS, twox, y);
46
47 Expr three = em.mkConst(Rational(3));
48 Expr twox_plus_y_geq_3 = em.mkExpr(kind::GEQ, twox_plus_y, three);
49
50 Expr formula =
51 em.mkExpr(kind::AND, x_positive, y_positive).
52 impExpr(twox_plus_y_geq_3);
53
54 cout << "Checking validity of formula " << formula << " with CVC4." << endl;
55 cout << "CVC4 should report VALID." << endl;
56 cout << "Result from CVC4 is: " << smt.query(formula) << endl;
57
58 return 0;
59 }