Theory of Uninterpreted Functions

examples/api/cpp/uf.cpp

 1/******************************************************************************
 2 * Top contributors (to current version):
 3 *   Yoni Zohar
 4 *
 5 * This file is part of the cvc5 project.
 6 *
 7 * Copyright (c) 2009-2024 by the authors listed in the file AUTHORS
 8 * in the top-level source directory and their institutional affiliations.
 9 * All rights reserved.  See the file COPYING in the top-level source
10 * directory for licensing information.
11 * ****************************************************************************
12 *
13 * A simple demonstration of the capabilities of the cvc5 uf solver.
14 */
15
16#include <cvc5/cvc5.h>
17
18#include <iostream>
19
20using namespace cvc5;
21
22int main()
23{
24  TermManager tm;
25  Solver slv(tm);
26  slv.setLogic("QF_UF");
27
28  // Sorts
29  Sort u = tm.mkUninterpretedSort("U");
30  Sort boolean = tm.getBooleanSort();
31  Sort uTou = tm.mkFunctionSort({u}, u);
32  Sort uPred = tm.mkFunctionSort({u}, boolean);
33
34  // Variables
35  Term x = tm.mkConst(u, "x");
36  Term y = tm.mkConst(u, "y");
37
38  // Functions
39  Term f = tm.mkConst(uTou, "f");
40  Term p = tm.mkConst(uPred, "p");
41
42  // Terms
43  Term f_x = tm.mkTerm(Kind::APPLY_UF, {f, x});
44  Term f_y = tm.mkTerm(Kind::APPLY_UF, {f, y});
45  Term p_f_x = tm.mkTerm(Kind::APPLY_UF, {p, f_x});
46  Term p_f_y = tm.mkTerm(Kind::APPLY_UF, {p, f_y});
47
48  // Construct the assertions
49  Term assertions =
50      tm.mkTerm(Kind::AND,
51                {
52                    tm.mkTerm(Kind::EQUAL, {x, f_x}),  
53                    tm.mkTerm(Kind::EQUAL, {y, f_y}),
54                    p_f_x.notTerm(),
55                    p_f_y
56                });
57  slv.assertFormula(assertions);
58
59  std::cout << slv.checkSat()  << std::endl;
60
61  return 0;
62}