2021-04-12 12:31:43 -07:00
|
|
|
/******************************************************************************
|
|
|
|
|
* Top contributors (to current version):
|
2022-04-05 13:38:57 -07:00
|
|
|
* Aina Niemetz, Tim King, Mathias Preiner
|
2021-04-12 12:31:43 -07:00
|
|
|
*
|
|
|
|
|
* This file is part of the cvc5 project.
|
|
|
|
|
*
|
2022-04-05 13:38:57 -07:00
|
|
|
* Copyright (c) 2009-2022 by the authors listed in the file AUTHORS
|
2021-04-12 12:31:43 -07:00
|
|
|
* in the top-level source directory and their institutional affiliations.
|
|
|
|
|
* All rights reserved. See the file COPYING in the top-level source
|
|
|
|
|
* directory for licensing information.
|
|
|
|
|
* ****************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* A simple demonstration of the linear arithmetic solving capabilities and
|
2021-06-15 15:29:08 -03:00
|
|
|
* the push pop of cvc5. This also gives an example option.
|
2021-04-12 12:31:43 -07:00
|
|
|
*/
|
2012-11-27 01:39:58 +00:00
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
2021-04-05 19:31:28 -07:00
|
|
|
#include <cvc5/cvc5.h>
|
2012-11-27 01:39:58 +00:00
|
|
|
|
|
|
|
|
using namespace std;
|
2022-03-29 16:23:01 -07:00
|
|
|
using namespace cvc5;
|
2012-11-27 01:39:58 +00:00
|
|
|
|
2020-06-23 13:46:02 -07:00
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
Solver slv;
|
|
|
|
|
slv.setLogic("QF_LIRA"); // Set the logic
|
2012-11-27 01:39:58 +00:00
|
|
|
|
|
|
|
|
// Prove that if given x (Integer) and y (Real) then
|
|
|
|
|
// the maximum value of y - x is 2/3
|
|
|
|
|
|
2020-06-23 13:46:02 -07:00
|
|
|
// Sorts
|
|
|
|
|
Sort real = slv.getRealSort();
|
|
|
|
|
Sort integer = slv.getIntegerSort();
|
2012-11-27 01:39:58 +00:00
|
|
|
|
|
|
|
|
// Variables
|
2020-06-23 13:46:02 -07:00
|
|
|
Term x = slv.mkConst(integer, "x");
|
|
|
|
|
Term y = slv.mkConst(real, "y");
|
2012-11-27 01:39:58 +00:00
|
|
|
|
|
|
|
|
// Constants
|
2020-10-29 13:26:51 -05:00
|
|
|
Term three = slv.mkInteger(3);
|
|
|
|
|
Term neg2 = slv.mkInteger(-2);
|
2020-06-23 13:46:02 -07:00
|
|
|
Term two_thirds = slv.mkReal(2, 3);
|
2012-11-27 01:39:58 +00:00
|
|
|
|
|
|
|
|
// Terms
|
2022-03-21 17:22:41 -07:00
|
|
|
Term three_y = slv.mkTerm(MULT, {three, y});
|
|
|
|
|
Term diff = slv.mkTerm(SUB, {y, x});
|
2012-11-27 01:39:58 +00:00
|
|
|
|
|
|
|
|
// Formulas
|
2022-03-21 17:22:41 -07:00
|
|
|
Term x_geq_3y = slv.mkTerm(GEQ, {x, three_y});
|
|
|
|
|
Term x_leq_y = slv.mkTerm(LEQ, {x, y});
|
|
|
|
|
Term neg2_lt_x = slv.mkTerm(LT, {neg2, x});
|
2012-11-27 01:39:58 +00:00
|
|
|
|
2022-03-21 17:22:41 -07:00
|
|
|
Term assertions = slv.mkTerm(AND, {x_geq_3y, x_leq_y, neg2_lt_x});
|
2012-11-27 01:39:58 +00:00
|
|
|
|
2020-06-23 13:46:02 -07:00
|
|
|
cout << "Given the assertions " << assertions << endl;
|
|
|
|
|
slv.assertFormula(assertions);
|
2012-11-27 01:39:58 +00:00
|
|
|
|
|
|
|
|
|
2020-06-23 13:46:02 -07:00
|
|
|
slv.push();
|
2022-03-21 17:22:41 -07:00
|
|
|
Term diff_leq_two_thirds = slv.mkTerm(LEQ, {diff, two_thirds});
|
2021-06-15 15:29:08 -03:00
|
|
|
cout << "Prove that " << diff_leq_two_thirds << " with cvc5." << endl;
|
2022-03-14 13:29:30 -05:00
|
|
|
cout << "cvc5 should report UNSAT." << endl;
|
|
|
|
|
cout << "Result from cvc5 is: "
|
|
|
|
|
<< slv.checkSatAssuming(diff_leq_two_thirds.notTerm()) << endl;
|
2020-06-23 13:46:02 -07:00
|
|
|
slv.pop();
|
2012-11-27 01:39:58 +00:00
|
|
|
|
|
|
|
|
cout << endl;
|
|
|
|
|
|
2020-06-23 13:46:02 -07:00
|
|
|
slv.push();
|
2022-03-21 17:22:41 -07:00
|
|
|
Term diff_is_two_thirds = slv.mkTerm(EQUAL, {diff, two_thirds});
|
2020-06-23 13:46:02 -07:00
|
|
|
slv.assertFormula(diff_is_two_thirds);
|
|
|
|
|
cout << "Show that the assertions are consistent with " << endl;
|
2021-06-15 15:29:08 -03:00
|
|
|
cout << diff_is_two_thirds << " with cvc5." << endl;
|
|
|
|
|
cout << "cvc5 should report SAT." << endl;
|
|
|
|
|
cout << "Result from cvc5 is: " << slv.checkSat() << endl;
|
2020-06-23 13:46:02 -07:00
|
|
|
slv.pop();
|
2012-11-27 01:39:58 +00:00
|
|
|
|
|
|
|
|
cout << "Thus the maximum value of (y - x) is 2/3."<< endl;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|