pulsatrix
Loading...
Searching...
No Matches
datalog_semiring.hpp
Go to the documentation of this file.
1
7#pragma once
8
9#include <type_traits>
10
11namespace pulsatrix::datalog {
12
54 using Value = bool;
55
56 [[nodiscard]] static constexpr Value zero() { return false; }
57 [[nodiscard]] static constexpr Value one() { return true; }
58 [[nodiscard]] static constexpr Value add(Value a, Value b) { return a || b; }
59 [[nodiscard]] static constexpr Value mul(Value a, Value b) { return a && b; }
60};
61
70template <typename T>
72 static_assert(std::is_floating_point_v<T>, "RealSemiring<T> requires a floating-point T (double or float)");
73
74 using Value = T;
75
76 [[nodiscard]] static constexpr Value zero() { return static_cast<T>(0); }
77 [[nodiscard]] static constexpr Value one() { return static_cast<T>(1); }
78 [[nodiscard]] static constexpr Value add(Value a, Value b) { return a + b; }
79 [[nodiscard]] static constexpr Value mul(Value a, Value b) { return a * b; }
80};
81
82} // namespace pulsatrix::datalog
Definition datalog_atom.hpp:14
A "Semiring" here is not a base class – it is a compile-time trait shape a type must satisfy to be us...
Definition datalog_semiring.hpp:53
static constexpr Value zero()
Definition datalog_semiring.hpp:56
bool Value
Definition datalog_semiring.hpp:54
static constexpr Value add(Value a, Value b)
Definition datalog_semiring.hpp:58
static constexpr Value one()
Definition datalog_semiring.hpp:57
static constexpr Value mul(Value a, Value b)
Definition datalog_semiring.hpp:59
The real-valued (+, x) semiring: ⊕ = floating-point addition, ⊗ = floating-point multiplication,...
Definition datalog_semiring.hpp:71
T Value
Definition datalog_semiring.hpp:74
static constexpr Value one()
Definition datalog_semiring.hpp:77
static constexpr Value zero()
Definition datalog_semiring.hpp:76
static constexpr Value mul(Value a, Value b)
Definition datalog_semiring.hpp:79
static constexpr Value add(Value a, Value b)
Definition datalog_semiring.hpp:78