Clingo
Loading...
Searching...
No Matches
core.hh
1#pragma once
2
3#include <clingo/core/symbol.hh>
4
5#include <clingo/util/algorithm.hh>
6
7#include <cstdint>
8#include <ostream>
9
10namespace CppClingo {
11
14
16enum class Sign : uint8_t {
17 none,
18 once,
19 twice,
20};
21
23auto operator-(Sign a) -> Sign;
25auto operator+(Sign a, Sign b) -> Sign;
27auto operator+=(Sign &a, Sign b) -> Sign &;
28
30auto operator<<(std::ostream &out, Sign sign) -> std::ostream &;
33
35enum class Relation : uint8_t {
36 equal,
37 not_equal,
38 less,
40 greater,
42};
43
45[[nodiscard]] auto flip(Relation rel) -> Relation;
47[[nodiscard]] auto complement(Relation rel) -> Relation;
48
50auto evaluate(auto const &lhs, Relation rel, auto const &rhs) -> bool {
51 switch (rel) {
52 case Relation::equal: {
53 return lhs == rhs;
54 }
56 return lhs != rhs;
57 }
58 case Relation::less: {
59 return lhs < rhs;
60 }
62 return lhs <= rhs;
63 }
64 case Relation::greater: {
65 return lhs > rhs;
66 }
68 return lhs >= rhs;
69 }
70 }
72}
73
75auto operator<<(std::ostream &out, Relation rel) -> std::ostream &;
78
80enum class TruthValue : uint8_t {
81 top,
82 bot,
83 unknown,
84};
85
87enum class AggregateFunction : uint8_t {
88 count,
89 sum,
90 sump,
91 min,
92 max,
93};
94
96auto operator<<(std::ostream &out, AggregateFunction fun) -> std::ostream &;
99
102 switch (fun) {
105 return SymbolStore::num_ref(0);
106 }
108 return SymbolStore::sup();
109 }
111 return SymbolStore::inf();
112 }
113 case AggregateFunction::count: {
114 throw std::invalid_argument("count function has no neutral value");
115 }
116 }
118}
119
121inline auto neutral_num(AggregateFunction fun) -> std::variant<Number, Symbol> {
122 switch (fun) {
125 return Number(0);
126 }
128 return SymbolStore::sup();
129 }
131 return SymbolStore::inf();
132 }
133 case AggregateFunction::count: {
134 throw std::invalid_argument("count function has no neutral value");
135 }
136 }
138}
139
141inline auto relevant_val(AggregateFunction fun, Symbol sym) -> bool {
142 switch (fun) {
144 return sym.type() != SymbolType::sup;
145 }
147 return sym.type() != SymbolType::inf;
148 }
150 return sym.type() == SymbolType::number && sym.num() != 0;
151 }
153 return sym.type() == SymbolType::number && sym.num() > 0;
154 }
155 case AggregateFunction::count: {
156 return true;
157 }
158 }
160}
161
165enum class TheoryTermTupleType : uint8_t {
166 tuple,
167 set,
168 list
169};
170
172enum class HeuristicType : uint8_t { level = 0, sign = 1, factor = 2, init = 3, true_ = 4, false_ = 5 };
175
177enum class ExternalType : uint8_t { free = 0, true_ = 1, false_ = 2, release = 3 };
180
182using TheorySig = std::tuple<String, size_t>;
184using TheorySigVec = std::vector<TheorySig>;
185
187
188} // namespace CppClingo
An arbitrary precision integer.
Definition number.hh:27
static auto inf() noexcept -> Symbol
Construct the supremum constant (#sup).
auto num_ref(Number num) noexcept -> Symbol
Construct a number (e.g., 42).
static auto sup() noexcept -> Symbol
Construct the infimum constant (#inf).
Variant-like class to store symbols stored in a symbol store.
Definition symbol.hh:225
Create an output buffer that bears some similarities with C++'s iostreams.
Definition print.hh:24
auto neutral_num(AggregateFunction fun) -> std::variant< Number, Symbol >
Get the neutral value or number for the given aggregate function.
Definition core.hh:121
auto complement(Relation rel) -> Relation
Return the complement of the given relation.
std::tuple< String, size_t > TheorySig
A signature of a theory atom.
Definition core.hh:182
auto evaluate(auto const &lhs, Relation rel, auto const &rhs) -> bool
Evaluate the comparison.
Definition core.hh:50
auto operator<<(std::ostream &out, Sign sign) -> std::ostream &
Output the given sign.
auto relevant_val(AggregateFunction fun, Symbol sym) -> bool
Check if the symbol is relevant for the given aggregate function.
Definition core.hh:141
TheoryTermTupleType
Enumeration of theory term tuple types.
Definition core.hh:165
HeuristicType
Available heuristic types.
Definition core.hh:172
auto flip(Relation rel) -> Relation
Return the equivalent relation when arguments are flipped.
Relation
Enumeration of supported relations.
Definition core.hh:35
auto neutral_val(AggregateFunction fun) -> Symbol
Get the neutral value for the given aggregate function.
Definition core.hh:101
ExternalType
Available external types.
Definition core.hh:177
Sign
Enumeration of signs (default negation).
Definition core.hh:16
auto operator+(Sign a, Sign b) -> Sign
Combine two signs.
auto operator+=(Sign &a, Sign b) -> Sign &
Combine two signs.
std::vector< TheorySig > TheorySigVec
A vector of theory atom signatures.
Definition core.hh:184
TruthValue
Truth values for expressions.
Definition core.hh:80
AggregateFunction
Enumeration of aggregate functions.
Definition core.hh:87
auto operator-(Sign a) -> Sign
Negate the sign.
@ equal
The equal to symbol (=).
@ greater_equal
The greater than or equal to symbol (>=).
@ less_equal
The less than or equal to symbol (<=).
@ greater
The greater than symbol (>).
@ not_equal
The not equal to symbol (!=).
@ less
The less than symbol (<).
@ none
No sign.
@ twice
Two signs (not not).
@ once
One sign (not).
@ unknown
Indicate an expression with an unknown truth value.
@ top
Indicate a true expression.
@ bot
Indicate a false expression.
@ sum
The #count function.
@ max
The #min function.
@ min
The #sum+ function.
@ sump
The #sum function.
void unreachable()
C++23's std::unreachable.
Definition algorithm.hh:96