Lattice Land Core Library
Loading...
Searching...
No Matches
pre_zdec.hpp
Go to the documentation of this file.
1// Copyright 2023 Pierre Talbot
2
3#ifndef LALA_CORE_PRE_ZDEC_HPP
4#define LALA_CORE_PRE_ZDEC_HPP
5
6#include "../logic/logic.hpp"
7#include "pre_zinc.hpp"
8
9namespace lala {
10
11template <class VT>
12struct PreZInc;
13
14/** `PreZDec` is a pre-abstract universe \f$ \langle \{\infty, \ldots, 2, 1, 0, -1, -2, \ldots, -\infty\}, \leq \rangle \f$ totally ordered by the reversed natural arithmetic comparison operator.
15 It is used to represent constraints of the form \f$ x \leq k \f$ where \f$ k \f$ is an integer.
16*/
17template <class VT>
18struct PreZDec {
21 using value_type = VT;
23
24 static_assert(std::is_integral_v<value_type>, "PreZDec only works over integer types.");
25
26 constexpr static const bool is_totally_ordered = true;
27 constexpr static const bool preserve_bot = true;
28 constexpr static const bool preserve_top = true;
29 constexpr static const bool preserve_join = true;
30 constexpr static const bool preserve_meet = true;
31 constexpr static const bool injective_concretization = true;
32 constexpr static const bool preserve_concrete_covers = true;
33 constexpr static const bool complemented = false;
34 constexpr static const bool increasing = false;
35 constexpr static const char *name = "ZDec";
36 constexpr static const bool is_arithmetic = true;
37 CUDA constexpr static value_type zero() { return 0; }
38 CUDA constexpr static value_type one() { return 1; }
39
40 template <bool diagnose, class F>
41 CUDA static bool interpret_tell(const F &f, value_type& tell, IDiagnostics& diagnostics) {
42 return dual_type::template interpret_ask<diagnose>(f, tell, diagnostics);
43 }
44
45 template <bool diagnose, class F>
46 CUDA static bool interpret_ask(const F &f, value_type& ask, IDiagnostics& diagnostics) {
47 return dual_type::template interpret_tell<diagnose>(f, ask, diagnostics);
48 }
49
50 template <bool diagnose, class F>
51 CUDA static bool interpret_type(const F &f, value_type& k, IDiagnostics& diagnostics) {
52 bool res = dual_type::template interpret_type<diagnose>(f, k, diagnostics);
53 // We reverse top and bottom due to the dual interpretation.
54 if (res && k == dual_type::bot()) {
55 k = bot();
56 }
57 return res;
58 }
59
60 template<class F>
61 CUDA static F deinterpret(const value_type& v) {
62 return dual_type::template deinterpret<F>(v);
63 }
64
65 CUDA static constexpr Sig sig_order() { return GEQ; }
66 CUDA static constexpr Sig sig_strict_order() { return GT; }
67 CUDA static constexpr value_type bot() { return dual_type::top(); }
68 CUDA static constexpr value_type top() { return dual_type::bot(); }
69 CUDA static constexpr value_type join(value_type x, value_type y) { return dual_type::meet(x, y); }
70 CUDA static constexpr value_type meet(value_type x, value_type y) { return dual_type::join(x, y); }
71 CUDA static constexpr bool order(value_type x, value_type y) { return dual_type::order(y, x); }
72 CUDA static constexpr bool strict_order(value_type x, value_type y) { return dual_type::strict_order(y, x); }
73 CUDA static constexpr value_type next(value_type x) { return dual_type::prev(x); }
74 CUDA static constexpr value_type prev(value_type x) { return dual_type::next(x); }
75 CUDA static constexpr bool is_supported_fun(Sig sig) { return sig != ABS && dual_type::is_supported_fun(sig); }
76 template <Sig sig> CUDA static constexpr value_type fun(value_type x) {
77 static_assert(is_supported_fun(sig), "Unsupported unary function.");
78 return dual_type::template fun<sig>(x);
79 }
80 template <Sig sig> CUDA static constexpr value_type fun(value_type x, value_type y) { return dual_type::template fun<sig>(x, y); }
81};
82
83} // namespace lala
84
85#endif
Definition diagnostics.hpp:19
Definition abstract_deps.hpp:14
Sig
Definition ast.hpp:94
@ GEQ
Unary arithmetic function symbols.
Definition ast.hpp:113
@ GT
Arithmetic comparison predicates. When applied to set, it corresponds to the lexicographic ordering o...
Definition ast.hpp:113
@ ABS
Unary arithmetic function symbols.
Definition ast.hpp:96
Definition pre_zdec.hpp:18
static CUDA constexpr Sig sig_strict_order()
Definition pre_zdec.hpp:66
static constexpr const bool preserve_join
Definition pre_zdec.hpp:29
static CUDA F deinterpret(const value_type &v)
Definition pre_zdec.hpp:61
static CUDA constexpr value_type next(value_type x)
Definition pre_zdec.hpp:73
static constexpr const char * name
Definition pre_zdec.hpp:35
static constexpr const bool injective_concretization
Definition pre_zdec.hpp:31
static constexpr const bool preserve_bot
Definition pre_zdec.hpp:27
static CUDA bool interpret_type(const F &f, value_type &k, IDiagnostics &diagnostics)
Definition pre_zdec.hpp:51
static constexpr const bool is_totally_ordered
Definition pre_zdec.hpp:26
static CUDA constexpr value_type top()
Definition pre_zdec.hpp:68
static constexpr const bool is_arithmetic
Definition pre_zdec.hpp:36
static CUDA constexpr bool is_supported_fun(Sig sig)
Definition pre_zdec.hpp:75
static constexpr const bool preserve_concrete_covers
Definition pre_zdec.hpp:32
static CUDA constexpr value_type prev(value_type x)
Definition pre_zdec.hpp:74
PreZInc< VT > dual_type
Definition pre_zdec.hpp:20
static CUDA constexpr bool strict_order(value_type x, value_type y)
Definition pre_zdec.hpp:72
static CUDA constexpr Sig sig_order()
Definition pre_zdec.hpp:65
CUDA static constexpr value_type zero()
Definition pre_zdec.hpp:37
static CUDA constexpr value_type meet(value_type x, value_type y)
Definition pre_zdec.hpp:70
static CUDA constexpr value_type join(value_type x, value_type y)
Definition pre_zdec.hpp:69
static CUDA constexpr value_type bot()
Definition pre_zdec.hpp:67
VT value_type
Definition pre_zdec.hpp:21
static CUDA constexpr value_type fun(value_type x)
Definition pre_zdec.hpp:76
static CUDA bool interpret_ask(const F &f, value_type &ask, IDiagnostics &diagnostics)
Definition pre_zdec.hpp:46
CUDA static constexpr value_type one()
Definition pre_zdec.hpp:38
static CUDA constexpr value_type fun(value_type x, value_type y)
Definition pre_zdec.hpp:80
static constexpr const bool preserve_top
Definition pre_zdec.hpp:28
static constexpr const bool increasing
Definition pre_zdec.hpp:34
static constexpr const bool complemented
Definition pre_zdec.hpp:33
static CUDA bool interpret_tell(const F &f, value_type &tell, IDiagnostics &diagnostics)
Definition pre_zdec.hpp:41
static CUDA constexpr bool order(value_type x, value_type y)
Definition pre_zdec.hpp:71
static constexpr const bool preserve_meet
Definition pre_zdec.hpp:30
Definition pre_zinc.hpp:17
static CUDA constexpr bool order(value_type x, value_type y)
Definition pre_zinc.hpp:162
CUDA static NI constexpr bool is_supported_fun(Sig sig)
Definition pre_zinc.hpp:186
static CUDA constexpr value_type top()
Definition pre_zinc.hpp:151
static CUDA constexpr value_type bot()
Definition pre_zinc.hpp:146
static CUDA constexpr value_type prev(value_type x)
Definition pre_zinc.hpp:181
static CUDA constexpr value_type next(value_type x)
Definition pre_zinc.hpp:172
static CUDA constexpr value_type join(value_type x, value_type y)
Definition pre_zinc.hpp:156
static CUDA constexpr value_type meet(value_type x, value_type y)
Definition pre_zinc.hpp:159
static CUDA constexpr bool strict_order(value_type x, value_type y)
Definition pre_zinc.hpp:165