3#ifndef LALA_CORE_ARITH_BOUND_HPP
4#define LALA_CORE_ARITH_BOUND_HPP
16#include "battery/memory.hpp"
43template<
class PreUniverse,
class Mem>
46template<
class PreUniverse,
class Mem>
50template<
class VT,
class Mem>
54template<
class VT,
class Mem>
58template<
class VT,
class Mem>
62template<
class VT,
class Mem>
76 struct is_arith_bound {
77 static constexpr bool value =
false;
80 template<
class PreUniverse,
class Mem>
81 struct is_arith_bound<ArithBound<PreUniverse, Mem>> {
82 static constexpr bool value =
true;
86 inline constexpr bool is_arith_bound_v = is_arith_bound<T>::value;
90template <
class A,
class R = A>
97template <
class A,
class R = A>
109template <
class LDual,
class L>
110CUDA
constexpr LDual
dual(
const L& x) {
111 if(x.is_bot())
return LDual::bot();
112 if(x.is_top())
return LDual::top();
113 return LDual(x.value());
116template<
class PreUniverse,
class Mem>
119 using U = PreUniverse;
147 constexpr static const char*
name = pre_universe::name;
151 static_assert(
is_totally_ordered,
"The underlying pre-universe must be totally ordered.");
152 static_assert(
is_arithmetic,
"The underlying pre-universe must be arithmetic (e.g. integers, floating-point numbers).");
162 "The pre-interpreted formula x >= k is only available over abstract universe modelling lower bounds.");
172 "The pre-interpreted formula x <= k is only available over abstract universe modelling upper bounds.");
200 memory_type::store(val, other.
value());
205 memory_type::store(val, other.
value());
220 return value() == U::top();
227 return value() == U::bot();
231 memory_type::store(val, U::top());
238 if(U::strict_order(r1, r2)) {
239 memory_type::store(val, r2);
246 memory_type::store(val, U::bot());
253 if(U::strict_order(r2, r1)) {
254 memory_type::store(val, r2);
264 template<
class Env,
class Allocator =
typename Env::allocator_type>
268 return F::make_true();
271 return F::make_false();
273 return F::make_binary(
308 template<
bool diagnose = false,
class F,
class M2>
313 if(f.sig() ==
EQ || f.sig() == U::sig_order()) {
316 else if(f.sig() == U::sig_strict_order()) {
332 template<
bool diagnose = false,
class F,
class M2>
333 CUDA NI
static bool interpret_ask_x_op_k(
const F& f,
this_type2<M2>& tell, IDiagnostics& diagnostics) {
337 if(f.sig() == U::sig_order()) {
340 else if(f.sig() ==
NEQ || f.sig() == U::sig_strict_order()) {
352 template<
bool diagnose = false,
class F,
class M2>
353 CUDA NI
static bool interpret_tell_set(
const F& f,
this_type2<M2>& tell, IDiagnostics& diagnostics) {
354 if(!f.seq(1).is(F::S)) {
357 const auto& set = f.seq(1).s();
358 if(set.size() == 0) {
365 for(
int i = 0; i < set.size(); ++i) {
366 auto bound = battery::get<bound_index>(set[i]);
372 join_s = pre_universe::join(join_s, set_element);
383 template<
bool diagnose = false,
class F,
class Env,
class M2>
386 typename U::value_type val;
387 bool res = pre_universe::template interpret_type<diagnose>(f, val, diagnostics);
394 if(f.is_binary() && f.seq(0).is_variable() && f.seq(1).is_constant()) {
397 return interpret_tell_set<diagnose>(f, tell, diagnostics);
400 return interpret_tell_x_op_k<diagnose>(f, tell, diagnostics);
404 RETURN_INTERPRETATION_ERROR(
"Only binary formulas of the form `x <sig> k` where if x is a variable and k is a constant are supported.");
412 template<
bool diagnose = false,
class F,
class Env,
class M2>
414 if(f.is_binary() && f.seq(0).is_variable() && f.seq(1).is_constant()) {
415 return interpret_ask_x_op_k<diagnose>(f, ask, diagnostics);
418 RETURN_INTERPRETATION_ERROR(
"Only binary formulas of the form `x <sig> k` where if x is a variable and k is a constant are supported.");
422 template<IKind kind,
bool diagnose = false,
class F,
class Env,
class M2>
478 if(fun ==
MIN || fun ==
MAX || fun ==
ADD) {
490 template<
class Pre2,
class Mem2>
496template<
class Pre,
class M1,
class M2>
501template<
class Pre,
class M1,
class M2>
506template<
class Pre,
class M1,
class M2>
507CUDA
constexpr bool operator<=(
const ArithBound<Pre, M1>& a,
const ArithBound<Pre, M2>& b) {
508 return Pre::order(a.value(), b.value());
511template<
class Pre,
class M1,
class M2>
513 return Pre::strict_order(a.
value(), b.
value());
516template<
class Pre,
class M1,
class M2>
517CUDA
constexpr bool operator>=(
const ArithBound<Pre, M1>& a,
const ArithBound<Pre, M2>& b) {
518 return Pre::order(b.value(), a.value());
521template<
class Pre,
class M1,
class M2>
523 return Pre::strict_order(b.
value(), a.
value());
526template<
class Pre,
class M1,
class M2>
531template<
class Pre,
class M1,
class M2>
532CUDA
constexpr bool operator!=(
const ArithBound<Pre, M1>& a,
const ArithBound<Pre, M2>& b) {
533 return a.value() != b.value();
536template<
class Pre,
class M>
Definition arith_bound.hpp:118
CUDA NI F deinterpret() const
Definition arith_bound.hpp:282
static CUDA constexpr local_type next(const this_type2< Mem > &a)
Definition arith_bound.hpp:433
static CUDA constexpr bool is_order_preserving_fun(Sig fun)
Definition arith_bound.hpp:472
CUDA constexpr bool join(const this_type2< M1 > &other)
Definition arith_bound.hpp:235
CUDA constexpr local::B is_top() const
Definition arith_bound.hpp:219
static constexpr const bool is_totally_ordered
Definition arith_bound.hpp:138
this_type2< battery::local_memory > local_type
Definition arith_bound.hpp:130
static CUDA constexpr bool is_trivial_fun(Sig fun)
Definition arith_bound.hpp:467
CUDA constexpr bool meet(const this_type2< M1 > &other)
Definition arith_bound.hpp:250
static constexpr const bool preserve_top
Definition arith_bound.hpp:140
CUDA constexpr ArithBound(const this_type2< M > &other)
Definition arith_bound.hpp:194
CUDA constexpr bool extract(local_type &ua) const
Definition arith_bound.hpp:288
Mem memory_type
Definition arith_bound.hpp:123
static CUDA constexpr this_type leq_k(value_type k)
Definition arith_bound.hpp:166
static constexpr const bool is_abstract_universe
Definition arith_bound.hpp:136
static constexpr const char * name
Definition arith_bound.hpp:147
memory_type::template atomic_type< value_type > atomic_type
Definition arith_bound.hpp:176
CUDA constexpr value_type value() const
Definition arith_bound.hpp:209
static constexpr const bool is_lower_bound
Definition arith_bound.hpp:145
CUDA constexpr ArithBound(value_type x)
Definition arith_bound.hpp:189
static constexpr const bool preserve_bot
Definition arith_bound.hpp:139
CUDA static NI bool interpret_tell(const F &f, const Env &, this_type2< M2 > &tell, IDiagnostics &diagnostics)
Definition arith_bound.hpp:384
static constexpr const bool preserve_concrete_covers
Definition arith_bound.hpp:144
CUDA NI TFormula< Allocator > deinterpret(AVar avar, const Env &env, const Allocator &allocator=Allocator()) const
Definition arith_bound.hpp:265
CUDA constexpr this_type & operator=(const this_type &other)
Definition arith_bound.hpp:204
constexpr ArithBound(this_type &&other)=default
static CUDA constexpr local_type bot()
Definition arith_bound.hpp:182
static constexpr const bool sequential
Definition arith_bound.hpp:137
static constexpr const bool injective_concretization
Definition arith_bound.hpp:143
ArithBound< pre_universe, memory_type > this_type
Definition arith_bound.hpp:124
CUDA constexpr void project(Sig fun, const local_flat_type &a)
Definition arith_bound.hpp:446
CUDA constexpr atomic_type & atomic()
Definition arith_bound.hpp:211
CUDA constexpr ArithBound()
Definition arith_bound.hpp:187
static CUDA constexpr local_type prev(const this_type2< Mem > &a)
Definition arith_bound.hpp:437
PreUniverse pre_universe
Definition arith_bound.hpp:121
CUDA constexpr void join_top()
Definition arith_bound.hpp:230
CUDA static NI bool interpret_ask(const F &f, const Env &, this_type2< M2 > &ask, IDiagnostics &diagnostics)
Definition arith_bound.hpp:413
CUDA NI void print() const
Definition arith_bound.hpp:294
static constexpr const bool preserve_join
Definition arith_bound.hpp:141
ArithBound< pre_universe, M > this_type2
Definition arith_bound.hpp:128
CUDA static NI bool interpret(const F &f, const Env &env, this_type2< M2 > &value, IDiagnostics &diagnostics)
Definition arith_bound.hpp:423
static CUDA constexpr this_type geq_k(value_type k)
Definition arith_bound.hpp:156
static constexpr const bool preserve_meet
Definition arith_bound.hpp:142
CUDA constexpr void project(Sig fun, const local_type &a)
Definition arith_bound.hpp:483
CUDA constexpr void project(Sig fun, const local_type &a, const local_type &b)
Definition arith_bound.hpp:476
CUDA constexpr void project(Sig fun, const local_flat_type &a, const local_flat_type &b)
Definition arith_bound.hpp:459
CUDA constexpr void meet_bot()
Definition arith_bound.hpp:245
typename pre_universe::value_type value_type
Definition arith_bound.hpp:122
CUDA constexpr local::B is_bot() const
Definition arith_bound.hpp:226
static CUDA constexpr local_type top()
Definition arith_bound.hpp:185
CUDA constexpr this_type & operator=(const this_type2< M > &other)
Definition arith_bound.hpp:199
CUDA constexpr ArithBound(const this_type &other)
Definition arith_bound.hpp:190
static constexpr const bool is_arithmetic
Definition arith_bound.hpp:149
static constexpr const bool is_upper_bound
Definition arith_bound.hpp:146
Definition flat_universe.hpp:30
CUDA constexpr local::B is_top() const
Definition flat_universe.hpp:115
CUDA constexpr value_type value() const
Definition flat_universe.hpp:108
CUDA constexpr local::B is_bot() const
Definition flat_universe.hpp:122
Definition diagnostics.hpp:19
#define RETURN_INTERPRETATION_ERROR(MSG)
Definition diagnostics.hpp:155
CUDA NI void print(const lala::Sig &sig)
Definition ast.hpp:212
Definition abstract_deps.hpp:14
std::ostream & operator<<(std::ostream &s, const CartesianProduct< A, As... > &cp)
Definition cartesian_product.hpp:530
CUDA constexpr LDual dual(const L &x)
Definition arith_bound.hpp:110
CUDA constexpr auto fjoin(const CartesianProduct< As... > &a, const CartesianProduct< Bs... > &b)
Definition cartesian_product.hpp:463
CUDA constexpr bool operator==(const CartesianProduct< As... > &a, const CartesianProduct< Bs... > &b)
Definition cartesian_product.hpp:503
R project_fun(Sig fun, const A &a, const A &b)
Definition arith_bound.hpp:91
@ NEQ
Equality relations.
Definition ast.hpp:112
@ EQ
Unary arithmetic function symbols.
Definition ast.hpp:112
@ ADD
Unary arithmetic function symbols.
Definition ast.hpp:97
@ IN
Set membership predicate.
Definition ast.hpp:108
@ MIN
Unary arithmetic function symbols.
Definition ast.hpp:97
@ MAX
Binary arithmetic function symbols.
Definition ast.hpp:97
@ ABS
Unary arithmetic function symbols.
Definition ast.hpp:96
battery::string< Allocator > LVar
Definition ast.hpp:25
CUDA constexpr bool operator<(const CartesianProduct< As... > &a, const CartesianProduct< Bs... > &b)
Definition cartesian_product.hpp:484
CUDA NI const char * string_of_sig(Sig sig)
Definition ast.hpp:121
CUDA constexpr auto fmeet(const CartesianProduct< As... > &a, const CartesianProduct< Bs... > &b)
Definition cartesian_product.hpp:470
CUDA constexpr bool operator>(const CartesianProduct< As... > &a, const CartesianProduct< Bs... > &b)
Definition cartesian_product.hpp:497
#define UNTYPED
Definition sort.hpp:21