ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
Lukasiewicz.h
Go to the documentation of this file.
1/**
2 * @file semiring/Lukasiewicz.h
3 * @brief Łukasiewicz fuzzy m-semiring over @f$[0,1]@f$.
4 *
5 * The Łukasiewicz m-semiring (@f$[0,1]@f$, @f$\max@f$,
6 * @f$\otimes_{\text{Ł}}@f$, 0, 1) is used to model graded-truth
7 * provenance: input gates carry degree-of-evidence values in
8 * @f$[0,1]@f$, @f$\oplus = \max@f$ keeps the strongest alternative,
9 * and @f$\otimes_{\text{Ł}}(a,b) = \max(a + b - 1, 0)@f$ is the
10 * Łukasiewicz t-norm, the bounded-loss conjunction.
11 *
12 * Operations:
13 * - @c zero() → 0
14 * - @c one() → 1
15 * - @c plus() → maximum of all operands (empty list → 0)
16 * - @c times() → @f$\max(\sum_i a_i - (n-1), 0)@f$ for @f$n@f$
17 * operands (empty list → 1)
18 * - @c monus() → 0 if @f$a \le b@f$, @f$a@f$ otherwise
19 * - @c delta() → 1 if @c x is non-zero, else 0
20 *
21 * Absorptivity: `absorptive()` returns `true`. With inputs in
22 * @f$[0,1]@f$, @f$\mathbb{1} \oplus a = \max(1, a) = 1@f$.
23 * The circuit evaluator may exploit the resulting idempotency to
24 * deduplicate operands.
25 *
26 * Compared to Viterbi (which uses @f$a \cdot b@f$ for ⊗): the
27 * Łukasiewicz t-norm preserves crisp truth (@f$0.7 \otimes 1 = 0.7@f$)
28 * and does not collapse long conjunctions to near-zero, making it
29 * the standard fuzzy choice for graded but non-probabilistic
30 * conjunctions.
31 *
32 * @note No bounds checking is performed: it is the caller's
33 * responsibility to supply input values in @f$[0,1]@f$.
34 *
35 * @see https://provsql.org/lean-docs/Provenance/Semirings/Lukasiewicz.html
36 * Lean 4 verified instance: @c instSemiringWithMonusLukasiewicz,
37 * with proofs of @c Lukasiewicz.absorptive,
38 * @c Lukasiewicz.idempotent, and
39 * @c Lukasiewicz.mul_sub_left_distributive.
40 */
41#ifndef LUKASIEWICZ_H
42#define LUKASIEWICZ_H
43
44#include <algorithm>
45#include <numeric>
46#include <vector>
47
48#include "Semiring.h"
49
50namespace semiring {
51/**
52 * @brief The Łukasiewicz fuzzy m-semiring over @c double.
53 *
54 * Each gate evaluates to a degree of evidence in @f$[0,1]@f$ under the
55 * Łukasiewicz t-norm.
56 */
57class Lukasiewicz : public semiring::Semiring<double>
58{
59public:
60virtual value_type zero() const override {
61 return 0.0;
62}
63virtual value_type one() const override {
64 return 1.0;
65}
66virtual value_type plus(const std::vector<value_type> &v) const override {
67 if(v.empty()) return zero();
68 return *std::max_element(v.begin(), v.end());
69}
70virtual value_type times(const std::vector<value_type> &v) const override {
71 if(v.empty()) return one();
72 double s = std::accumulate(v.begin(), v.end(), 0.0);
73 double r = s - static_cast<double>(v.size() - 1);
74 return r > 0.0 ? r : 0.0;
75}
76virtual value_type monus(value_type x, value_type y) const override
77{
78 return x<=y ? zero() : x;
79}
80virtual value_type delta(value_type x) const override
81{
82 return x!=zero() ? one() : zero();
83}
84virtual bool absorptive() const override {
85 return true;
86}
87/**
88 * @brief No semiring homomorphism @c BoolFunc(Y) →+* Lukasiewicz
89 * exists (the Łukasiewicz t-norm is not idempotent), so the
90 * safe-query Boolean rewrite is unsound under this semiring.
91 * Inherits the @c false default from @c Semiring; this
92 * override exists for documentation.
93 *
94 * Lean: @c Provenance.Semirings.Lukasiewicz.no_hom_from_BoolFunc
95 * (provenance-lean/Provenance/Semirings/Lukasiewicz.lean).
96 */
97virtual bool compatibleWithBooleanRewrite() const override {
98 return false;
99}
100value_type parse_leaf(const char *v) const {
101 return atof(v);
102}
103
104};
105}
106
107#endif /* LUKASIEWICZ_H */
Abstract semiring interface for provenance evaluation.
The Łukasiewicz fuzzy m-semiring over double.
Definition Lukasiewicz.h:58
virtual value_type monus(value_type x, value_type y) const override
Apply the monus (m-semiring difference) operation.
Definition Lukasiewicz.h:76
virtual value_type delta(value_type x) const override
Apply the operator.
Definition Lukasiewicz.h:80
virtual value_type plus(const std::vector< value_type > &v) const override
Apply the additive operation to a list of values.
Definition Lukasiewicz.h:66
virtual value_type one() const override
Return the multiplicative identity .
Definition Lukasiewicz.h:63
virtual value_type times(const std::vector< value_type > &v) const override
Apply the multiplicative operation to a list of values.
Definition Lukasiewicz.h:70
virtual bool absorptive() const override
Return true if this semiring is absorptive ( for all ).
Definition Lukasiewicz.h:84
virtual bool compatibleWithBooleanRewrite() const override
No semiring homomorphism BoolFunc(Y) →+* Lukasiewicz exists (the Łukasiewicz t-norm is not idempotent...
Definition Lukasiewicz.h:97
value_type parse_leaf(const char *v) const
virtual value_type zero() const override
Return the additive identity .
Definition Lukasiewicz.h:60
Abstract base class for (m-)semirings.
Definition Semiring.h:93