2021-04-12 12:31:43 -07:00
|
|
|
/******************************************************************************
|
|
|
|
|
* Top contributors (to current version):
|
2024-03-12 09:35:09 -07:00
|
|
|
* Aina Niemetz, Tim King, Haniel Barbosa
|
2021-04-12 12:31:43 -07:00
|
|
|
*
|
|
|
|
|
* This file is part of the cvc5 project.
|
|
|
|
|
*
|
2025-01-23 09:54:20 -08:00
|
|
|
* Copyright (c) 2009-2025 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()
|
|
|
|
|
{
|
2024-03-08 11:39:13 -08:00
|
|
|
TermManager tm;
|
|
|
|
|
Solver slv(tm);
|
2020-06-23 13:46:02 -07:00
|
|
|
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
|
2024-03-08 11:39:13 -08:00
|
|
|
Sort real = tm.getRealSort();
|
|
|
|
|
Sort integer = tm.getIntegerSort();
|
2012-11-27 01:39:58 +00:00
|
|
|
|
|
|
|
|
// Variables
|
2024-03-08 11:39:13 -08:00
|
|
|
Term x = tm.mkConst(integer, "x");
|
|
|
|
|
Term y = tm.mkConst(real, "y");
|
2012-11-27 01:39:58 +00:00
|
|
|
|
|
|
|
|
// Constants
|
2024-03-08 11:39:13 -08:00
|
|
|
Term three = tm.mkInteger(3);
|
|
|
|
|
Term neg2 = tm.mkInteger(-2);
|
|
|
|
|
Term two_thirds = tm.mkReal(2, 3);
|
2012-11-27 01:39:58 +00:00
|
|
|
|
|
|
|
|
// Terms
|
2024-03-08 11:39:13 -08:00
|
|
|
Term three_y = tm.mkTerm(Kind::MULT, {three, y});
|
|
|
|
|
Term diff = tm.mkTerm(Kind::SUB, {y, x});
|
2012-11-27 01:39:58 +00:00
|
|
|
|
|
|
|
|
// Formulas
|
2024-03-08 11:39:13 -08:00
|
|
|
Term x_geq_3y = tm.mkTerm(Kind::GEQ, {x, three_y});
|
|
|
|
|
Term x_leq_y = tm.mkTerm(Kind::LEQ, {x, y});
|
|
|
|
|
Term neg2_lt_x = tm.mkTerm(Kind::LT, {neg2, x});
|
2012-11-27 01:39:58 +00:00
|
|
|
|
2024-03-08 11:39:13 -08:00
|
|
|
Term assertions = tm.mkTerm(Kind::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();
|
2024-03-08 11:39:13 -08:00
|
|
|
Term diff_leq_two_thirds = tm.mkTerm(Kind::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();
|
2024-03-08 11:39:13 -08:00
|
|
|
Term diff_is_two_thirds = tm.mkTerm(Kind::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;
|
|
|
|
|
}
|