Lattice Land Core Library
Loading...
Searching...
No Matches
pre_flb.hpp
Go to the documentation of this file.
1// Copyright 2023 Pierre Talbot
2
3#ifndef LALA_CORE_PRE_FLB_HPP
4#define LALA_CORE_PRE_FLB_HPP
5
6#include "../logic/logic.hpp"
7#include "pre_fub.hpp"
8
9namespace lala {
10
11template<class VT>
12struct PreFUB;
13
14/** `PreFLB` is a pre-abstract universe \f$ \langle \mathbb{F}\setminus\{NaN\}, \geq \rangle \f$ totally ordered by the reversed floating-point arithmetic comparison operator.
15 We work on a subset of floating-point numbers without NaN.
16 It is used to represent (and possibly approximate) constraints of the form \f$ x \geq k \f$ where \f$ k \f$ is a real number.
17*/
18template<class VT>
19struct PreFLB {
22 using value_type = VT;
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 /** Note that -0 and +0 are treated as the same element. */
32 constexpr static const bool injective_concretization = true;
33 constexpr static const bool preserve_concrete_covers = false;
34 constexpr static const bool is_lower_bound = true;
35 constexpr static const bool is_upper_bound = false;
36 constexpr static const char* name = "FLB";
37 constexpr static const bool is_arithmetic = true;
38 CUDA constexpr static value_type zero() { return 0.0; }
39 CUDA constexpr static value_type one() { return 1.0; }
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, 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, 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
72 CUDA static constexpr value_type project(Sig fun, value_type x) {
73 if(fun == ABS) { return x >= 0 ? x : 0; }
74 else {
75 return dual_type::project(fun, x);
76 }
77 }
78
79 CUDA static constexpr value_type project(Sig fun, value_type x, value_type y) {
80 switch(fun) {
81 case ADD: return battery::add_down(x, y);
82 case SUB: return battery::sub_down(x, y);
83 case MUL: return battery::mul_down(x, y);
84 case DIV: return battery::div_down(x, y);
85 default: return dual_type::project(fun, x, y);
86 }
87 }
88};
89
90} // namespace lala
91
92#endif
Definition diagnostics.hpp:19
Definition abstract_deps.hpp:14
Sig
Definition ast.hpp:94
@ GEQ
Unary arithmetic function symbols.
Definition ast.hpp:113
@ ADD
Unary arithmetic function symbols.
Definition ast.hpp:97
@ DIV
Unary arithmetic function symbols.
Definition ast.hpp:101
@ 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
@ SUB
Unary arithmetic function symbols.
Definition ast.hpp:97
@ MUL
Unary arithmetic function symbols.
Definition ast.hpp:97
Definition pre_fub.hpp:11
CUDA static constexpr value_type zero()
Definition pre_flb.hpp:38
static CUDA constexpr value_type meet(value_type x, value_type y)
Definition pre_flb.hpp:66
static constexpr const bool preserve_join
Definition pre_flb.hpp:29
static CUDA constexpr value_type bot()
Definition pre_flb.hpp:63
static CUDA constexpr value_type project(Sig fun, value_type x)
Definition pre_flb.hpp:72
static constexpr const bool is_totally_ordered
Definition pre_flb.hpp:26
static CUDA constexpr value_type next(value_type x)
Definition pre_flb.hpp:69
static constexpr const bool is_lower_bound
Definition pre_flb.hpp:34
static constexpr const bool injective_concretization
Definition pre_flb.hpp:32
static constexpr const bool preserve_bot
Definition pre_flb.hpp:27
PreFLB< VT > this_type
Definition pre_flb.hpp:20
static CUDA constexpr bool strict_order(value_type x, value_type y)
Definition pre_flb.hpp:68
static CUDA constexpr value_type top()
Definition pre_flb.hpp:64
static constexpr const bool is_upper_bound
Definition pre_flb.hpp:35
static CUDA constexpr value_type project(Sig fun, value_type x, value_type y)
Definition pre_flb.hpp:79
static CUDA bool interpret_ask(const F &f, value_type &ask, IDiagnostics &diagnostics)
Definition pre_flb.hpp:47
static constexpr const bool preserve_top
Definition pre_flb.hpp:28
static CUDA F deinterpret(const value_type &v)
Definition pre_flb.hpp:57
static constexpr const bool preserve_meet
Definition pre_flb.hpp:30
static constexpr const char * name
Definition pre_flb.hpp:36
static CUDA constexpr Sig sig_strict_order()
Definition pre_flb.hpp:62
static CUDA constexpr bool order(value_type x, value_type y)
Definition pre_flb.hpp:67
static CUDA constexpr Sig sig_order()
Definition pre_flb.hpp:61
CUDA static constexpr value_type one()
Definition pre_flb.hpp:39
static CUDA constexpr value_type join(value_type x, value_type y)
Definition pre_flb.hpp:65
VT value_type
Definition pre_flb.hpp:22
PreFUB< VT > dual_type
Definition pre_flb.hpp:21
static CUDA bool interpret_type(const F &f, value_type &k, IDiagnostics &diagnostics)
Definition pre_flb.hpp:52
static constexpr const bool preserve_concrete_covers
Definition pre_flb.hpp:33
static constexpr const bool is_arithmetic
Definition pre_flb.hpp:37
static CUDA bool interpret_tell(const F &f, value_type &tell, IDiagnostics &diagnostics)
Definition pre_flb.hpp:42
static CUDA constexpr value_type prev(value_type x)
Definition pre_flb.hpp:70
Definition pre_fub.hpp:18
static CUDA constexpr value_type project(Sig fun, value_type x)
Definition pre_fub.hpp:175
static CUDA constexpr value_type next(value_type x)
Definition pre_fub.hpp:151
static CUDA constexpr value_type join(value_type x, value_type y)
Definition pre_fub.hpp:136
static CUDA constexpr value_type prev(value_type x)
Definition pre_fub.hpp:165
static CUDA constexpr bool order(value_type x, value_type y)
Definition pre_fub.hpp:142
static CUDA constexpr value_type top()
Definition pre_fub.hpp:131
static CUDA constexpr value_type bot()
Definition pre_fub.hpp:126
static CUDA constexpr bool strict_order(value_type x, value_type y)
Definition pre_fub.hpp:145
static CUDA constexpr value_type meet(value_type x, value_type y)
Definition pre_fub.hpp:139