3#ifndef LALA_CORE_PRE_ZUB_HPP
4#define LALA_CORE_PRE_ZUB_HPP
24 static_assert(std::is_integral_v<value_type> ,
"PreZUB only works over signed integer types.");
53 constexpr static const char*
name =
"ZUB";
60 template<
bool diagnose,
bool is_tell,
bool dualize,
class F>
64 if(z ==
bot() || z ==
top()) {
65 RETURN_INTERPRETATION_ERROR(
"Constant of sort `Int` with the minimal or maximal representable value of the underlying integer type. We use those values to model negative and positive infinities. Example: Suppose we use a byte type, `x >= 256` is interpreted as `x >= INF` which is always false and thus is different from the intended constraint.");
71 if constexpr(dualize) {
72 if constexpr(is_tell) {
73 k = battery::ru_cast<value_type>(battery::get<0>(f.r()));
76 k = battery::ru_cast<value_type>(battery::get<1>(f.r()));
80 if constexpr(is_tell) {
81 k = battery::rd_cast<value_type>(battery::get<1>(f.r()));
84 k = battery::rd_cast<value_type>(battery::get<0>(f.r()));
93 RETURN_INTERPRETATION_ERROR(
"Only constants of sorts `Int`, `Bool` and `Real` can be interpreted by an integer abstract universe.");
106 template<
bool diagnose,
class F,
bool dualize = false>
108 return interpret<diagnose, true, dualize>(f, tell, diagnostics);
115 template<
bool diagnose,
class F,
bool dualize = false>
117 return interpret<diagnose, false, dualize>(f, ask, diagnostics);
123 template<
bool diagnose,
class F,
bool dualize = false>
126 const auto& sort = battery::get<1>(f.exists());
128 k = dualize ?
bot() :
top();
132 const auto& vname = battery::get<0>(f.exists());
157 CUDA INLINE
static constexpr value_type inf() {
158 return battery::limits<value_type>::inf();
161 CUDA INLINE
static constexpr value_type neg_inf() {
162 return battery::limits<value_type>::neg_inf();
195 return x + has_not_inf(x);
205 return x - has_not_inf(x);
209 CUDA INLINE
static constexpr bool has_not_inf(
value_type x) {
210 return x != inf() && x != neg_inf();
213 CUDA INLINE
static constexpr bool has_inf(
value_type x) {
214 return x == inf() || x == neg_inf();
217 CUDA INLINE
static constexpr int sign(
value_type x) {
218 return battery::signum(x) + 1;
223 return has_inf(x) || has_inf(y);
226 template<
bool dualize>
228 return dualize ?
bot() :
top();
232 template <
bool dualize>
235 case NEG:
return has_inf(x) ? x : -x;
236 default:
return dtop<dualize>();
249 CUDA
static constexpr value_type infs(
size_t i,
size_t j) {
253 {inf(), 0, neg_inf()},
255 {neg_inf(), 0, inf()}
273 template <
bool dualize>
276 case ADD:
return has_inf(x, y) ? (has_inf(x) ? x : y) : x + y;
277 case SUB:
return has_inf(x, y) ? (has_inf(x) ? x : -y) : x - y;
278 case MUL:
return has_inf(x, y) ? infs(sign(x), sign(y)) : x * y;
280 case TDIV:
return has_inf(x, y) ? (has_inf(x) ? infs(sign(x), sign(y)) : dtop<dualize>()) : x / y;
281 case TMOD:
return x % y;
283 case FDIV:
return has_inf(x, y) ? (has_inf(x) ? infs(sign(x), sign(y)) : dtop<dualize>()) : battery::fdiv(x, y);
284 case FMOD:
return battery::fmod(x, y);
286 case CDIV:
return has_inf(x, y) ? (has_inf(x) ? infs(sign(x), sign(y)) : dtop<dualize>()) : battery::cdiv(x, y);
287 case CMOD:
return battery::cmod(x, y);
289 case EDIV:
return has_inf(x, y) ? (has_inf(x) ? infs(sign(x), sign(y)) : dtop<dualize>()) : battery::ediv(x, y);
290 case EMOD:
return battery::emod(x, y);
291 case POW:
return battery::ipow(x, y);
292 case MIN:
return battery::min(x, y);
293 case MAX:
return battery::max(x, y);
294 case EQ:
return x == y;
295 case NEQ:
return x != y;
296 case LEQ:
return x <= y;
297 case GEQ:
return x >= y;
298 case LT:
return x < y;
299 case GT:
return x >= y;
300 default:
return dtop<dualize>();
Definition diagnostics.hpp:19
#define RETURN_INTERPRETATION_ERROR(MSG)
Definition diagnostics.hpp:155
Definition abstract_deps.hpp:14
@ NEQ
Equality relations.
Definition ast.hpp:112
@ LEQ
Unary arithmetic function symbols.
Definition ast.hpp:113
@ TMOD
Truncated division, present in most programming languages, is defined as , i.e., it rounds towards ze...
Definition ast.hpp:102
@ EQ
Unary arithmetic function symbols.
Definition ast.hpp:112
@ GEQ
Unary arithmetic function symbols.
Definition ast.hpp:113
@ ADD
Unary arithmetic function symbols.
Definition ast.hpp:97
@ POW
Unary arithmetic function symbols.
Definition ast.hpp:97
@ MIN
Unary arithmetic function symbols.
Definition ast.hpp:97
@ EDIV
Unary arithmetic function symbols.
Definition ast.hpp:105
@ GT
Arithmetic comparison predicates. When applied to set, it corresponds to the lexicographic ordering o...
Definition ast.hpp:113
@ FMOD
Floor division (Knuth D. (1972). The Art of Computer Programming, Vol 1, Fundamental Algorithms),...
Definition ast.hpp:103
@ MAX
Binary arithmetic function symbols.
Definition ast.hpp:97
@ LT
Unary arithmetic function symbols.
Definition ast.hpp:113
@ TDIV
Unary arithmetic function symbols.
Definition ast.hpp:102
@ FDIV
Unary arithmetic function symbols.
Definition ast.hpp:103
@ SUB
Unary arithmetic function symbols.
Definition ast.hpp:97
@ MUL
Unary arithmetic function symbols.
Definition ast.hpp:97
@ CMOD
Ceil division is defined as . Modulus is defined as .
Definition ast.hpp:104
@ CDIV
Unary arithmetic function symbols.
Definition ast.hpp:104
@ NEG
Unary arithmetic function symbols.
Definition ast.hpp:96
@ EMOD
Euclidean division (Boute T. R. (1992). The Euclidean definition of the functions div and mod)....
Definition ast.hpp:105
Definition pre_zub.hpp:11
Definition pre_zub.hpp:17
static CUDA bool interpret_ask(const F &f, value_type &ask, IDiagnostics &diagnostics)
Definition pre_zub.hpp:116
CUDA static INLINE constexpr value_type top()
Definition pre_zub.hpp:173
static constexpr const bool is_totally_ordered
Definition pre_zub.hpp:26
static CUDA bool interpret_tell(const F &f, value_type &tell, IDiagnostics &diagnostics)
Definition pre_zub.hpp:107
CUDA static INLINE constexpr bool order(value_type x, value_type y)
Definition pre_zub.hpp:184
CUDA static INLINE constexpr bool strict_order(value_type x, value_type y)
Definition pre_zub.hpp:187
static CUDA constexpr Sig sig_order()
Definition pre_zub.hpp:149
static constexpr const bool preserve_bot
Definition pre_zub.hpp:29
CUDA static NI bool interpret_type(const F &f, value_type &k, IDiagnostics &diagnostics)
Definition pre_zub.hpp:124
static CUDA constexpr value_type next(value_type x)
Definition pre_zub.hpp:194
static CUDA constexpr value_type dproject(Sig fun, value_type x, value_type y)
Definition pre_zub.hpp:274
static constexpr const bool preserve_meet
Definition pre_zub.hpp:38
CUDA static constexpr value_type one()
Definition pre_zub.hpp:57
static constexpr const char * name
Definition pre_zub.hpp:53
CUDA static INLINE constexpr value_type join(value_type x, value_type y)
Definition pre_zub.hpp:178
static CUDA constexpr value_type prev(value_type x)
Definition pre_zub.hpp:203
PreZLB< VT > dual_type
Definition pre_zub.hpp:19
CUDA static INLINE constexpr value_type bot()
Definition pre_zub.hpp:168
static CUDA constexpr value_type dproject(Sig fun, value_type x)
Definition pre_zub.hpp:233
static CUDA F deinterpret(const value_type &v)
Definition pre_zub.hpp:142
static constexpr const bool injective_concretization
Definition pre_zub.hpp:42
VT value_type
Definition pre_zub.hpp:20
static constexpr const bool preserve_concrete_covers
Definition pre_zub.hpp:47
static CUDA constexpr value_type project(Sig fun, value_type x)
Definition pre_zub.hpp:244
CUDA static INLINE constexpr value_type meet(value_type x, value_type y)
Definition pre_zub.hpp:181
static constexpr const bool preserve_join
Definition pre_zub.hpp:35
static constexpr const bool is_upper_bound
Definition pre_zub.hpp:51
static constexpr const bool is_lower_bound
Definition pre_zub.hpp:50
static CUDA constexpr Sig sig_strict_order()
Definition pre_zub.hpp:154
static constexpr const bool preserve_top
Definition pre_zub.hpp:32
PreZUB< VT > this_type
Definition pre_zub.hpp:18
static constexpr const bool is_arithmetic
Definition pre_zub.hpp:55
static CUDA constexpr value_type project(Sig fun, value_type x, value_type y)
Definition pre_zub.hpp:304
CUDA static constexpr value_type zero()
Definition pre_zub.hpp:56