carl  24.04
Computer ARithmetic Library
UTerm.cpp
Go to the documentation of this file.
1 /**
2  * @file UTerm.cpp
3  * @author Rebecca Haehn <haehn@cs.rwth-aachen.de>
4  * @since 2018-08-28
5  * @version 2018-08-28
6  */
7 
8 
9 #include "UTerm.h"
10 
11 #include <iostream>
12 #include <sstream>
13 
14 namespace carl
15 {
16  Sort UTerm::domain() const {
17  return std::visit(overloaded {
18  [](UVariable var) { return var.domain(); },
19  [](UFInstance ufi) { return ufi.uninterpretedFunction().codomain(); },
20  }, mTerm);
21  }
22 
23  std::size_t UTerm::complexity() const {
24  return std::visit(overloaded {
25  [](UVariable) { return static_cast<std::size_t>(1); },
26  [](UFInstance ufi) { return ufi.complexity(); },
27  }, mTerm);
28  }
29 
31  return std::visit(overloaded {
32  [&vars](UVariable v) { vars.add(v.variable()); },
33  [&vars](UFInstance ufi) { ufi.gatherVariables(vars); },
34  }, mTerm);
35  }
36 
37  void UTerm::gatherUFs(std::set<UninterpretedFunction>& ufs) const {
38  return std::visit(overloaded {
39  [](UVariable) { /* nothing to do here */ },
40  [&ufs](UFInstance ufi) { ufi.gatherUFs(ufs); },
41  }, mTerm);
42  }
43 
44  bool operator==(const UTerm& lhs, const UTerm& rhs) {
45  return std::visit(overloaded {
46  [](UVariable l, UVariable r) { return l == r; },
47  [](UFInstance l, UFInstance r) { return l.id() == r.id(); },
48  [](const auto&, const auto&) { return false; },
49  }, lhs.asVariant(), rhs.asVariant());
50  }
51 
52  bool operator!=(const UTerm& lhs, const UTerm& rhs) {
53  return !(lhs == rhs);
54  }
55 
56  bool operator<(const UTerm& lhs, const UTerm& rhs) {
57  return std::visit(overloaded {
58  [](UVariable l, UVariable r) { return l < r; },
59  [](UFInstance l, UFInstance r) { return l.id() < r.id(); },
60  [](UVariable, UFInstance) { return true; },
61  [](const auto&, const auto&) { return false; },
62  }, lhs.asVariant(), rhs.asVariant());
63  }
64 
65  std::ostream& operator<<(std::ostream& os, const UTerm& ut) {
66  return std::visit(overloaded {
67  [&os](UVariable var) -> auto& { return os << var; },
68  [&os](UFInstance ufi) -> auto& { return os << ufi; },
69  }, ut.asVariant());
70  }
71 }
carl is the main namespace for the library.
bool operator<(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
std::ostream & operator<<(std::ostream &os, const BasicConstraint< Poly > &c)
Prints the given constraint on the given stream.
void visit(const Formula< Pol > &formula, Visitor func)
Recursively calls func on every subformula.
Definition: Visit.h:12
bool operator!=(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
bool operator==(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
void add(Variable v)
Definition: Variables.h:141
Implements a sort (for defining types of variables and functions).
Definition: Sort.h:20
Implements an uninterpreted function instance.
Definition: UFInstance.h:25
Implements an uninterpreted term, that is either an uninterpreted variable or an uninterpreted functi...
Definition: UTerm.h:22
void gatherUFs(std::set< UninterpretedFunction > &ufs) const
Definition: UTerm.cpp:37
Sort domain() const
Definition: UTerm.cpp:16
const auto & asVariant() const
Definition: UTerm.h:41
std::size_t complexity() const
Definition: UTerm.cpp:23
Super mTerm
Definition: UTerm.h:24
void gatherVariables(carlVariables &vars) const
Definition: UTerm.cpp:30
Implements an uninterpreted variable.
Definition: UVariable.h:19