ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
Boolean.h
Go to the documentation of this file.
1/**
2 * @file semiring/Boolean.h
3 * @brief Boolean semiring ({false, true}, ∨, ∧, false, true).
4 *
5 * The Boolean semiring is the simplest semiring supported by ProvSQL.
6 * Provenance evaluates to @c true if at least one derivation of the
7 * tuple exists in the current database instance (i.e., the query answer
8 * is "certain"), and @c false otherwise.
9 *
10 * The semiring is absorptive (∨ is idempotent), so the circuit evaluator
11 * can safely deduplicate children of OR gates.
12 *
13 * Operations:
14 * - @c zero() → @c false
15 * - @c one() → @c true
16 * - @c plus() → logical OR (any_of)
17 * - @c times() → logical AND (all_of)
18 * - @c monus() → @f$x \;\&\; \lnot y@f$
19 * - @c delta() → identity
20 */
21#ifndef BOOLEAN_H
22#define BOOLEAN_H
23
24#include <algorithm>
25#include <vector>
26
27#include "Semiring.h"
28
29namespace semiring {
30/**
31 * @brief The Boolean semiring over @c bool.
32 *
33 * Provides the standard Boolean interpretation of provenance circuits.
34 */
35class Boolean : public semiring::Semiring<bool>
36{
37public:
38virtual value_type zero() const override {
39 return false;
40}
41virtual value_type one() const override {
42 return true;
43}
44virtual value_type plus(const std::vector<value_type> &v) const override {
45 return std::any_of(v.begin(), v.end(), [](bool x) {
46 return x;
47 });
48}
49virtual value_type times(const std::vector<value_type> &v) const override {
50 return std::all_of(v.begin(), v.end(), [](bool x) {
51 return x;
52 });
53}
54virtual value_type monus(value_type x, value_type y) const override
55{
56 return x & !y;
57}
58virtual value_type delta(value_type x) const override
59{
60 return x;
61}
62virtual bool absorptive() const override {
63 return true;
64}
65};
66}
67
68#endif /* BOOLEAN_H */
Abstract semiring interface for provenance evaluation.
The Boolean semiring over bool.
Definition Boolean.h:36
virtual value_type zero() const override
Return the additive identity .
Definition Boolean.h:38
virtual value_type times(const std::vector< value_type > &v) const override
Apply the multiplicative operation to a list of values.
Definition Boolean.h:49
virtual value_type plus(const std::vector< value_type > &v) const override
Apply the additive operation to a list of values.
Definition Boolean.h:44
virtual value_type one() const override
Return the multiplicative identity .
Definition Boolean.h:41
virtual bool absorptive() const override
Return true if this semiring is absorptive ( ).
Definition Boolean.h:62
virtual value_type delta(value_type x) const override
Apply the operator.
Definition Boolean.h:58
virtual value_type monus(value_type x, value_type y) const override
Apply the monus (m-semiring difference) operation.
Definition Boolean.h:54
Abstract base class for (m-)semirings.
Definition Semiring.h:84
bool value_type
The carrier type of this semiring.
Definition Semiring.h:87