Lattice Land Core Library
pre_zlb.hpp
Go to the documentation of this file.
1 // Copyright 2023 Pierre Talbot
2 
3 #ifndef LALA_CORE_PRE_ZLB_HPP
4 #define LALA_CORE_PRE_ZLB_HPP
5 
6 #include "../logic/logic.hpp"
7 #include "pre_zub.hpp"
8 
9 namespace lala {
10 
11 template <class VT>
12 struct PreZUB;
13 
14 /** `PreZLB` is a pre-abstract universe \f$ \langle \{\infty, \ldots, 2, 1, 0, -1, -2, \ldots, -\infty\}, \geq \rangle \f$ totally ordered by the reversed natural arithmetic comparison operator.
15  It is used to represent constraints of the form \f$ x \geq k \f$ where \f$ k \f$ is an integer.
16 */
17 template <class VT>
18 struct PreZLB {
21  using value_type = VT;
24 
25  static_assert(std::is_integral_v<value_type>, "PreZLB only works over integer types.");
26 
27  constexpr static const bool is_totally_ordered = true;
28  constexpr static const bool preserve_bot = true;
29  constexpr static const bool preserve_top = true;
30  constexpr static const bool preserve_join = true;
31  constexpr static const bool preserve_meet = true;
32  constexpr static const bool injective_concretization = true;
33  constexpr static const bool preserve_concrete_covers = true;
34  constexpr static const bool is_lower_bound = true;
35  constexpr static const bool is_upper_bound = false;
36  constexpr static const char *name = "ZLB";
37  constexpr static const bool is_arithmetic = true;
38  CUDA constexpr static value_type zero() { return 0; }
39  CUDA constexpr static value_type one() { return 1; }
40 
41  template <bool diagnose, class F>
42  CUDA static bool interpret_tell(const F &f, value_type& tell, IDiagnostics& diagnostics) {
43  return dual_type::template interpret_ask<diagnose, F, true>(f, tell, diagnostics);
44  }
45 
46  template <bool diagnose, class F>
47  CUDA static bool interpret_ask(const F &f, value_type& ask, IDiagnostics& diagnostics) {
48  return dual_type::template interpret_tell<diagnose, F, true>(f, ask, diagnostics);
49  }
50 
51  template <bool diagnose, class F>
52  CUDA static bool interpret_type(const F &f, value_type& k, IDiagnostics& diagnostics) {
53  return dual_type::template interpret_type<diagnose, F, true>(f, k, diagnostics);
54  }
55 
56  template<class F>
57  CUDA static F deinterpret(const value_type& v) {
58  return dual_type::template deinterpret<F>(v);
59  }
60 
61  CUDA static constexpr Sig sig_order() { return GEQ; }
62  CUDA static constexpr Sig sig_strict_order() { return GT; }
63  CUDA static constexpr value_type bot() { return dual_type::top(); }
64  CUDA static constexpr value_type top() { return dual_type::bot(); }
65  CUDA static constexpr value_type join(value_type x, value_type y) { return dual_type::meet(x, y); }
66  CUDA static constexpr value_type meet(value_type x, value_type y) { return dual_type::join(x, y); }
67  CUDA static constexpr bool order(value_type x, value_type y) { return dual_type::order(y, x); }
68  CUDA static constexpr bool strict_order(value_type x, value_type y) { return dual_type::strict_order(y, x); }
69  CUDA static constexpr value_type next(value_type x) { return dual_type::prev(x); }
70  CUDA static constexpr value_type prev(value_type x) { return dual_type::next(x); }
71  CUDA static constexpr value_type project(Sig fun, value_type x) {
72  if(fun == ABS) { return x >= 0 ? x : 0; }
73  else {
74  return dual_type::template dproject<true>(fun, x);
75  }
76  }
77  CUDA static constexpr value_type project(Sig fun, value_type x, value_type y) {
78  return dual_type::template dproject<true>(fun, x, y);
79  }
80 };
81 
82 } // namespace lala
83 
84 #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_zlb.hpp:18
static CUDA bool interpret_ask(const F &f, value_type &ask, IDiagnostics &diagnostics)
Definition: pre_zlb.hpp:47
constexpr static const bool preserve_bot
Definition: pre_zlb.hpp:28
constexpr static const bool preserve_top
Definition: pre_zlb.hpp:29
constexpr static const bool preserve_join
Definition: pre_zlb.hpp:30
constexpr static CUDA value_type one()
Definition: pre_zlb.hpp:39
static constexpr CUDA Sig sig_strict_order()
Definition: pre_zlb.hpp:62
constexpr static const bool is_lower_bound
Definition: pre_zlb.hpp:34
static constexpr CUDA value_type project(Sig fun, value_type x, value_type y)
Definition: pre_zlb.hpp:77
PreZLB< VT > this_type
Definition: pre_zlb.hpp:19
VT value_type
Definition: pre_zlb.hpp:21
static CUDA F deinterpret(const value_type &v)
Definition: pre_zlb.hpp:57
constexpr static const bool is_totally_ordered
Definition: pre_zlb.hpp:27
static constexpr CUDA bool order(value_type x, value_type y)
Definition: pre_zlb.hpp:67
static constexpr CUDA bool strict_order(value_type x, value_type y)
Definition: pre_zlb.hpp:68
constexpr static const bool is_arithmetic
Definition: pre_zlb.hpp:37
static constexpr CUDA value_type prev(value_type x)
Definition: pre_zlb.hpp:70
constexpr static const bool injective_concretization
Definition: pre_zlb.hpp:32
static constexpr CUDA value_type top()
Definition: pre_zlb.hpp:64
static constexpr CUDA value_type next(value_type x)
Definition: pre_zlb.hpp:69
static constexpr CUDA value_type meet(value_type x, value_type y)
Definition: pre_zlb.hpp:66
static CUDA bool interpret_tell(const F &f, value_type &tell, IDiagnostics &diagnostics)
Definition: pre_zlb.hpp:42
static constexpr CUDA value_type project(Sig fun, value_type x)
Definition: pre_zlb.hpp:71
PreZUB< VT > dual_type
Definition: pre_zlb.hpp:20
static constexpr CUDA value_type join(value_type x, value_type y)
Definition: pre_zlb.hpp:65
static constexpr CUDA value_type bot()
Definition: pre_zlb.hpp:63
static CUDA bool interpret_type(const F &f, value_type &k, IDiagnostics &diagnostics)
Definition: pre_zlb.hpp:52
static constexpr CUDA Sig sig_order()
Definition: pre_zlb.hpp:61
constexpr static const bool is_upper_bound
Definition: pre_zlb.hpp:35
constexpr static const bool preserve_concrete_covers
Definition: pre_zlb.hpp:33
constexpr static CUDA value_type zero()
Definition: pre_zlb.hpp:38
constexpr static const bool preserve_meet
Definition: pre_zlb.hpp:31
constexpr static const char * name
Definition: pre_zlb.hpp:36
Definition: pre_zub.hpp:17
CUDA static constexpr INLINE value_type join(value_type x, value_type y)
Definition: pre_zub.hpp:178
CUDA static constexpr INLINE value_type top()
Definition: pre_zub.hpp:173
static constexpr CUDA value_type next(value_type x)
Definition: pre_zub.hpp:194
CUDA static constexpr INLINE bool order(value_type x, value_type y)
Definition: pre_zub.hpp:184
CUDA static constexpr INLINE value_type meet(value_type x, value_type y)
Definition: pre_zub.hpp:181
static constexpr CUDA value_type prev(value_type x)
Definition: pre_zub.hpp:203
CUDA static constexpr INLINE value_type bot()
Definition: pre_zub.hpp:168
CUDA static constexpr INLINE bool strict_order(value_type x, value_type y)
Definition: pre_zub.hpp:187