2021-04-12 12:31:43 -07:00
|
|
|
/******************************************************************************
|
|
|
|
|
* Top contributors (to current version):
|
2022-04-05 13:38:57 -07:00
|
|
|
* Aina Niemetz, Kshitij Bansal, 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.
|
|
|
|
|
* ****************************************************************************
|
|
|
|
|
*
|
2021-06-09 13:44:13 -07:00
|
|
|
* A simple demonstration of reasoning about sets with cvc5.
|
2021-04-12 12:31:43 -07:00
|
|
|
*/
|
2014-06-25 19:10:55 -04:00
|
|
|
|
2021-04-05 19:31:28 -07:00
|
|
|
#include <cvc5/cvc5.h>
|
2014-06-25 19:10:55 -04:00
|
|
|
|
2021-04-05 19:31:28 -07:00
|
|
|
#include <iostream>
|
2014-06-25 19:10:55 -04:00
|
|
|
|
|
|
|
|
using namespace std;
|
2022-03-29 16:23:01 -07:00
|
|
|
using namespace cvc5;
|
2014-06-25 19:10:55 -04:00
|
|
|
|
2020-06-23 13:46:02 -07:00
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
Solver slv;
|
2014-06-25 19:10:55 -04:00
|
|
|
|
2014-06-30 10:53:52 -04:00
|
|
|
// Optionally, set the logic. We need at least UF for equality predicate,
|
|
|
|
|
// integers (LIA) and sets (FS).
|
2020-06-23 13:46:02 -07:00
|
|
|
slv.setLogic("QF_UFLIAFS");
|
2014-06-30 10:53:52 -04:00
|
|
|
|
2014-06-25 19:10:55 -04:00
|
|
|
// Produce models
|
2020-06-23 13:46:02 -07:00
|
|
|
slv.setOption("produce-models", "true");
|
|
|
|
|
slv.setOption("output-language", "smt2");
|
2014-06-25 19:10:55 -04:00
|
|
|
|
2020-06-23 13:46:02 -07:00
|
|
|
Sort integer = slv.getIntegerSort();
|
|
|
|
|
Sort set = slv.mkSetSort(integer);
|
2014-06-25 19:10:55 -04:00
|
|
|
|
|
|
|
|
// Verify union distributions over intersection
|
|
|
|
|
// (A union B) intersection C = (A intersection C) union (B intersection C)
|
|
|
|
|
{
|
2020-06-23 13:46:02 -07:00
|
|
|
Term A = slv.mkConst(set, "A");
|
|
|
|
|
Term B = slv.mkConst(set, "B");
|
|
|
|
|
Term C = slv.mkConst(set, "C");
|
2014-06-25 19:10:55 -04:00
|
|
|
|
2022-03-21 17:22:41 -07:00
|
|
|
Term unionAB = slv.mkTerm(SET_UNION, {A, B});
|
|
|
|
|
Term lhs = slv.mkTerm(SET_INTER, {unionAB, C});
|
2014-06-25 19:10:55 -04:00
|
|
|
|
2022-03-21 17:22:41 -07:00
|
|
|
Term intersectionAC = slv.mkTerm(SET_INTER, {A, C});
|
|
|
|
|
Term intersectionBC = slv.mkTerm(SET_INTER, {B, C});
|
|
|
|
|
Term rhs = slv.mkTerm(SET_UNION, {intersectionAC, intersectionBC});
|
2014-06-25 19:10:55 -04:00
|
|
|
|
2022-03-21 17:22:41 -07:00
|
|
|
Term theorem = slv.mkTerm(EQUAL, {lhs, rhs});
|
2014-06-25 19:10:55 -04:00
|
|
|
|
2022-03-14 13:29:30 -05:00
|
|
|
cout << "cvc5 reports: " << theorem << " is "
|
|
|
|
|
<< slv.checkSatAssuming(theorem.notTerm()) << "." << endl;
|
2014-06-25 19:10:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verify emptset is a subset of any set
|
|
|
|
|
{
|
2020-06-23 13:46:02 -07:00
|
|
|
Term A = slv.mkConst(set, "A");
|
|
|
|
|
Term emptyset = slv.mkEmptySet(set);
|
2014-06-25 19:10:55 -04:00
|
|
|
|
2022-03-21 17:22:41 -07:00
|
|
|
Term theorem = slv.mkTerm(SET_SUBSET, {emptyset, A});
|
2014-06-25 19:10:55 -04:00
|
|
|
|
2022-03-14 13:29:30 -05:00
|
|
|
cout << "cvc5 reports: " << theorem << " is "
|
|
|
|
|
<< slv.checkSatAssuming(theorem.notTerm()) << "." << endl;
|
2014-06-25 19:10:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find me an element in {1, 2} intersection {2, 3}, if there is one.
|
|
|
|
|
{
|
2020-10-29 13:26:51 -05:00
|
|
|
Term one = slv.mkInteger(1);
|
|
|
|
|
Term two = slv.mkInteger(2);
|
|
|
|
|
Term three = slv.mkInteger(3);
|
2014-06-25 19:10:55 -04:00
|
|
|
|
2022-03-21 17:22:41 -07:00
|
|
|
Term singleton_one = slv.mkTerm(SET_SINGLETON, {one});
|
|
|
|
|
Term singleton_two = slv.mkTerm(SET_SINGLETON, {two});
|
|
|
|
|
Term singleton_three = slv.mkTerm(SET_SINGLETON, {three});
|
|
|
|
|
Term one_two = slv.mkTerm(SET_UNION, {singleton_one, singleton_two});
|
|
|
|
|
Term two_three = slv.mkTerm(SET_UNION, {singleton_two, singleton_three});
|
|
|
|
|
Term intersection = slv.mkTerm(SET_INTER, {one_two, two_three});
|
2014-06-25 19:10:55 -04:00
|
|
|
|
2020-06-23 13:46:02 -07:00
|
|
|
Term x = slv.mkConst(integer, "x");
|
2014-06-25 19:10:55 -04:00
|
|
|
|
2022-03-21 17:22:41 -07:00
|
|
|
Term e = slv.mkTerm(SET_MEMBER, {x, intersection});
|
2014-06-25 19:10:55 -04:00
|
|
|
|
2020-06-23 13:46:02 -07:00
|
|
|
Result result = slv.checkSatAssuming(e);
|
2021-06-15 15:29:08 -03:00
|
|
|
cout << "cvc5 reports: " << e << " is " << result << "." << endl;
|
2014-06-25 19:10:55 -04:00
|
|
|
|
2020-06-23 13:46:02 -07:00
|
|
|
if (result.isSat())
|
|
|
|
|
{
|
|
|
|
|
cout << "For instance, " << slv.getValue(x) << " is a member." << endl;
|
2014-06-25 19:10:55 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|