2021-04-12 12:31:43 -07:00
|
|
|
/******************************************************************************
|
|
|
|
|
* Top contributors (to current version):
|
2025-01-23 09:54:20 -08:00
|
|
|
* Aina Niemetz, Andres Noetzli, Mathias Preiner
|
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 C++ interface for quantifiers.
|
|
|
|
|
*/
|
2017-09-27 06:50:47 -05:00
|
|
|
|
2021-04-05 19:31:28 -07:00
|
|
|
#include <cvc5/cvc5.h>
|
2020-06-29 15:35:44 -07:00
|
|
|
|
2017-09-27 06:50:47 -05:00
|
|
|
#include <iostream>
|
|
|
|
|
|
2022-03-29 16:23:01 -07:00
|
|
|
using namespace cvc5;
|
2017-09-27 06:50:47 -05:00
|
|
|
|
2024-03-14 12:16:39 -07:00
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
TermManager tm;
|
|
|
|
|
Solver slv(tm);
|
2017-09-27 06:50:47 -05:00
|
|
|
|
|
|
|
|
// Prove that the following is unsatisfiable:
|
|
|
|
|
// forall x. P( x ) ^ ~P( 5 )
|
|
|
|
|
|
2024-03-14 12:16:39 -07:00
|
|
|
Sort integer = tm.getIntegerSort();
|
|
|
|
|
Sort boolean = tm.getBooleanSort();
|
|
|
|
|
Sort integerPredicate = tm.mkFunctionSort({integer}, boolean);
|
2020-06-29 15:35:44 -07:00
|
|
|
|
2024-03-14 12:16:39 -07:00
|
|
|
Term p = tm.mkConst(integerPredicate, "P");
|
|
|
|
|
Term x = tm.mkVar(integer, "x");
|
2020-06-29 15:35:44 -07:00
|
|
|
|
2017-09-27 06:50:47 -05:00
|
|
|
// make forall x. P( x )
|
2024-03-14 12:16:39 -07:00
|
|
|
Term var_list = tm.mkTerm(Kind::VARIABLE_LIST, {x});
|
|
|
|
|
Term px = tm.mkTerm(Kind::APPLY_UF, {p, x});
|
|
|
|
|
Term quantpospx = tm.mkTerm(Kind::FORALL, {var_list, px});
|
2020-06-29 15:35:44 -07:00
|
|
|
std::cout << "Made expression : " << quantpospx << std::endl;
|
|
|
|
|
|
2017-09-27 06:50:47 -05:00
|
|
|
//make ~P( 5 )
|
2024-03-14 12:16:39 -07:00
|
|
|
Term five = tm.mkInteger(5);
|
|
|
|
|
Term pfive = tm.mkTerm(Kind::APPLY_UF, {p, five});
|
|
|
|
|
Term negpfive = tm.mkTerm(Kind::NOT, {pfive});
|
2020-06-29 15:35:44 -07:00
|
|
|
std::cout << "Made expression : " << negpfive << std::endl;
|
2017-09-27 06:50:47 -05:00
|
|
|
|
2024-03-14 12:16:39 -07:00
|
|
|
Term formula = tm.mkTerm(Kind::AND, {quantpospx, negpfive});
|
2017-09-27 06:50:47 -05:00
|
|
|
|
2020-06-29 15:35:44 -07:00
|
|
|
slv.assertFormula(formula);
|
2017-09-27 06:50:47 -05:00
|
|
|
|
2021-04-21 10:21:34 -07:00
|
|
|
std::cout << "Checking SAT after asserting " << formula << " to cvc5."
|
2020-06-29 15:35:44 -07:00
|
|
|
<< std::endl;
|
2021-04-21 10:21:34 -07:00
|
|
|
std::cout << "cvc5 should report unsat." << std::endl;
|
|
|
|
|
std::cout << "Result from cvc5 is: " << slv.checkSat() << std::endl;
|
2020-06-29 15:35:44 -07:00
|
|
|
|
|
|
|
|
slv.resetAssertions();
|
2017-09-27 06:50:47 -05:00
|
|
|
|
|
|
|
|
// this version has a pattern e.g. in smt2 syntax (forall ((x Int)) (! (P x ) :pattern ((P x))))
|
2024-03-14 12:16:39 -07:00
|
|
|
Term pattern = tm.mkTerm(Kind::INST_PATTERN, {px});
|
|
|
|
|
Term pattern_list = tm.mkTerm(Kind::INST_PATTERN_LIST, {pattern});
|
2020-06-29 15:35:44 -07:00
|
|
|
Term quantpospx_pattern =
|
2024-03-14 12:16:39 -07:00
|
|
|
tm.mkTerm(Kind::FORALL, {var_list, px, pattern_list});
|
2020-06-29 15:35:44 -07:00
|
|
|
std::cout << "Made expression : " << quantpospx_pattern << std::endl;
|
2017-09-27 06:50:47 -05:00
|
|
|
|
2024-03-14 12:16:39 -07:00
|
|
|
Term formula_pattern = tm.mkTerm(Kind::AND, {quantpospx_pattern, negpfive});
|
2017-09-27 06:50:47 -05:00
|
|
|
|
2020-06-29 15:35:44 -07:00
|
|
|
slv.assertFormula(formula_pattern);
|
2017-09-27 06:50:47 -05:00
|
|
|
|
2021-04-21 10:21:34 -07:00
|
|
|
std::cout << "Checking SAT after asserting " << formula_pattern << " to cvc5."
|
2020-06-29 15:35:44 -07:00
|
|
|
<< std::endl;
|
2021-04-21 10:21:34 -07:00
|
|
|
std::cout << "cvc5 should report unsat." << std::endl;
|
|
|
|
|
std::cout << "Result from cvc5 is: " << slv.checkSat() << std::endl;
|
2017-09-27 06:50:47 -05:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|