1 /********************* */
2 /*! \file linear_arith.cpp
4 ** Original author: Tim King
5 ** Major contributors: none
6 ** Minor contributors (to current version): Morgan Deters
7 ** This file is part of the CVC4 project.
8 ** Copyright (c) 2009-2013 New York University and The University of Iowa
9 ** See the file COPYING in the top-level source directory for licensing
10 ** information.\endverbatim
12 ** \brief A simple demonstration of the linear arithmetic capabilities of CVC4
14 ** A simple demonstration of the linear arithmetic solving capabilities and
15 ** the push pop of CVC4. This also gives an example option.
20 //#include <cvc4/cvc4.h> // use this after CVC4 is properly installed
21 #include "smt/smt_engine.h"
29 smt
.setLogic("QF_LIRA"); // Set the logic
31 // Prove that if given x (Integer) and y (Real) then
32 // the maximum value of y - x is 2/3
35 Type real
= em
.realType();
36 Type integer
= em
.integerType();
39 Expr x
= em
.mkVar("x", integer
);
40 Expr y
= em
.mkVar("y", real
);
43 Expr three
= em
.mkConst(Rational(3));
44 Expr neg2
= em
.mkConst(Rational(-2));
45 Expr two_thirds
= em
.mkConst(Rational(2,3));
48 Expr three_y
= em
.mkExpr(kind::MULT
, three
, y
);
49 Expr diff
= em
.mkExpr(kind::MINUS
, y
, x
);
52 Expr x_geq_3y
= em
.mkExpr(kind::GEQ
, x
, three_y
);
53 Expr x_leq_y
= em
.mkExpr(kind::LEQ
, x
, y
);
54 Expr neg2_lt_x
= em
.mkExpr(kind::LT
, neg2
, x
);
57 em
.mkExpr(kind::AND
, x_geq_3y
, x_leq_y
, neg2_lt_x
);
59 cout
<< "Given the assumptions " << assumptions
<< endl
;
60 smt
.assertFormula(assumptions
);
64 Expr diff_leq_two_thirds
= em
.mkExpr(kind::LEQ
, diff
, two_thirds
);
65 cout
<< "Prove that " << diff_leq_two_thirds
<< " with CVC4." << endl
;
66 cout
<< "CVC4 should report VALID." << endl
;
67 cout
<< "Result from CVC4 is: " << smt
.query(diff_leq_two_thirds
) << endl
;
73 Expr diff_is_two_thirds
= em
.mkExpr(kind::EQUAL
, diff
, two_thirds
);
74 smt
.assertFormula(diff_is_two_thirds
);
75 cout
<< "Show that the asserts are consistent with " << endl
;
76 cout
<< diff_is_two_thirds
<< " with CVC4." << endl
;
77 cout
<< "CVC4 should report SAT." << endl
;
78 cout
<< "Result from CVC4 is: " << smt
.checkSat(em
.mkConst(true)) << endl
;
81 cout
<< "Thus the maximum value of (y - x) is 2/3."<< endl
;