Theory of Uninterpreted Functions

examples/api/cpp/uf.cpp

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