Lattice Land Core Library
Loading...
Searching...
No Matches
pre_fdec.hpp
Go to the documentation of this file.
1// Copyright 2023 Pierre Talbot
2
3#ifndef LALA_CORE_PRE_FDEC_HPP
4#define LALA_CORE_PRE_FDEC_HPP
5
6#include "../logic/logic.hpp"
7#include "pre_finc.hpp"
8
9namespace lala {
10
11template<class VT>
12struct PreFInc;
13
14/** `PreFDec` is a pre-abstract universe \f$ \langle \mathbb{F}\setminus\{NaN\}, \leq \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 \leq k \f$ where \f$ k \f$ is a real number.
17*/
18template<class VT>
19struct PreFDec {
22 using value_type = VT;
24
25 constexpr static const bool is_totally_ordered = true;
26 constexpr static const bool preserve_bot = true;
27 constexpr static const bool preserve_top = true;
28 constexpr static const bool preserve_join = true;
29 constexpr static const bool preserve_meet = true;
30 /** Note that -0 and +0 are treated as the same element. */
31 constexpr static const bool injective_concretization = true;
32 constexpr static const bool preserve_concrete_covers = false;
33 constexpr static const bool complemented = false;
34 constexpr static const bool increasing = false;
35 constexpr static const char* name = "FDec";
36 constexpr static const bool is_arithmetic = true;
37 CUDA constexpr static value_type zero() { return 0.0; }
38 CUDA constexpr static value_type one() { return 1.0; }
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 if (res && k == dual_type::bot()) {
54 k = bot();
55 }
56 return res;
57 }
58
59 template<class F>
60 CUDA static F deinterpret(const value_type& v) {
61 return dual_type::template deinterpret<F>(v);
62 }
63
64 CUDA static constexpr Sig sig_order() { return GEQ; }
65 CUDA static constexpr Sig sig_strict_order() { return GT; }
66 CUDA static constexpr value_type bot() { return dual_type::top(); }
67 CUDA static constexpr value_type top() { return dual_type::bot(); }
68 CUDA static constexpr value_type join(value_type x, value_type y) { return dual_type::meet(x, y); }
69 CUDA static constexpr value_type meet(value_type x, value_type y) { return dual_type::join(x, y); }
70 CUDA static constexpr bool order(value_type x, value_type y) { return dual_type::order(y, x); }
71 CUDA static constexpr bool strict_order(value_type x, value_type y) { return dual_type::strict_order(y, x); }
72 CUDA static constexpr value_type next(value_type x) { return dual_type::prev(x); }
73 CUDA static constexpr value_type prev(value_type x) { return dual_type::next(x); }
74 CUDA static constexpr bool is_supported_fun(Sig sig) { return sig != ABS && dual_type::is_supported_fun(sig); }
75
76 template<Sig sig>
77 CUDA static constexpr value_type fun(value_type x) {
78 static_assert(is_supported_fun(sig), "Unsupported unary function.");
79 return dual_type::template fun<sig>(x);
80 }
81
82 template<Sig sig>
83 CUDA static constexpr value_type fun(value_type x, value_type y) {
84 static_assert(is_supported_fun(sig), "Unsupported binary function.");
85 switch(sig) {
86 case ADD: return battery::add_up(x, y);
87 case SUB: return battery::sub_up(x, y);
88 case MUL: return battery::mul_up(x, y);
89 case DIV: return battery::div_up(x, y);
90 default: return dual_type::template fun<sig>(x, y);
91 }
92 }
93};
94
95} // namespace lala
96
97#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_fdec.hpp:19
static constexpr const bool is_totally_ordered
Definition pre_fdec.hpp:25
static CUDA constexpr value_type meet(value_type x, value_type y)
Definition pre_fdec.hpp:69
static CUDA bool interpret_type(const F &f, value_type &k, IDiagnostics &diagnostics)
Definition pre_fdec.hpp:51
static CUDA constexpr Sig sig_strict_order()
Definition pre_fdec.hpp:65
static CUDA constexpr value_type top()
Definition pre_fdec.hpp:67
static constexpr const bool complemented
Definition pre_fdec.hpp:33
static constexpr const bool preserve_top
Definition pre_fdec.hpp:27
static CUDA F deinterpret(const value_type &v)
Definition pre_fdec.hpp:60
static CUDA constexpr value_type join(value_type x, value_type y)
Definition pre_fdec.hpp:68
static constexpr const bool injective_concretization
Definition pre_fdec.hpp:31
static CUDA constexpr value_type next(value_type x)
Definition pre_fdec.hpp:72
static CUDA bool interpret_ask(const F &f, value_type &ask, IDiagnostics &diagnostics)
Definition pre_fdec.hpp:46
static constexpr const bool preserve_join
Definition pre_fdec.hpp:28
static CUDA bool interpret_tell(const F &f, value_type &tell, IDiagnostics &diagnostics)
Definition pre_fdec.hpp:41
static CUDA constexpr bool order(value_type x, value_type y)
Definition pre_fdec.hpp:70
VT value_type
Definition pre_fdec.hpp:22
PreFInc< VT > dual_type
Definition pre_fdec.hpp:21
static CUDA constexpr bool is_supported_fun(Sig sig)
Definition pre_fdec.hpp:74
static CUDA constexpr value_type bot()
Definition pre_fdec.hpp:66
static CUDA constexpr bool strict_order(value_type x, value_type y)
Definition pre_fdec.hpp:71
static constexpr const char * name
Definition pre_fdec.hpp:35
static constexpr const bool increasing
Definition pre_fdec.hpp:34
static CUDA constexpr Sig sig_order()
Definition pre_fdec.hpp:64
static CUDA constexpr value_type fun(value_type x, value_type y)
Definition pre_fdec.hpp:83
CUDA static constexpr value_type one()
Definition pre_fdec.hpp:38
static CUDA constexpr value_type prev(value_type x)
Definition pre_fdec.hpp:73
static constexpr const bool preserve_bot
Definition pre_fdec.hpp:26
CUDA static constexpr value_type zero()
Definition pre_fdec.hpp:37
static constexpr const bool preserve_meet
Definition pre_fdec.hpp:29
static constexpr const bool is_arithmetic
Definition pre_fdec.hpp:36
static CUDA constexpr value_type fun(value_type x)
Definition pre_fdec.hpp:77
static constexpr const bool preserve_concrete_covers
Definition pre_fdec.hpp:32
Definition pre_finc.hpp:18
static CUDA constexpr value_type prev(value_type x)
Definition pre_finc.hpp:164
static CUDA constexpr value_type top()
Definition pre_finc.hpp:130
static CUDA constexpr bool order(value_type x, value_type y)
Definition pre_finc.hpp:141
static CUDA constexpr value_type join(value_type x, value_type y)
Definition pre_finc.hpp:135
static CUDA constexpr value_type bot()
Definition pre_finc.hpp:125
CUDA static NI constexpr bool is_supported_fun(Sig sig)
Definition pre_finc.hpp:174
static CUDA constexpr value_type next(value_type x)
Definition pre_finc.hpp:150
static CUDA constexpr value_type meet(value_type x, value_type y)
Definition pre_finc.hpp:138
static CUDA constexpr bool strict_order(value_type x, value_type y)
Definition pre_finc.hpp:144