ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
semiring::Formula Class Reference

Symbolic provenance representation over std::string. More...

#include "Formula.h"

Inheritance diagram for semiring::Formula:
Collaboration diagram for semiring::Formula:

Public Member Functions

virtual value_type zero () const override
 Return the additive identity \(\mathbb{0}\).
virtual value_type one () const override
 Return the multiplicative identity \(\mathbb{1}\).
virtual value_type plus (const std::vector< value_type > &v) const override
 Apply the additive operation to a list of values.
virtual value_type times (const std::vector< value_type > &v) const override
 Apply the multiplicative operation to a list of values.
virtual value_type monus (value_type x, value_type y) const override
 Apply the monus (m-semiring difference) operation.
virtual value_type delta (value_type x) const override
 Apply the \(\delta\) operator.
virtual value_type cmp (value_type s1, ComparisonOperator op, value_type s2) const override
 Evaluate a comparison gate.
virtual value_type semimod (value_type x, value_type s) const override
 Apply a semimodule scalar multiplication.
virtual value_type agg (AggregationOperator op, const std::vector< std::string > &s) override
 Evaluate an aggregation gate.
virtual value_type value (const std::string &s) const override
 Interpret a literal string as a semiring value.
value_type parse_leaf (const char *v) const
virtual bool compatibleWithBooleanRewrite () const override
 Special case: Formula serialises the circuit structure as a string rather than computing a semantic value, so a safe-query-rewritten circuit renders to its (rewritten) structural formula and remains a faithful description.
std::string to_text (const value_type &s) const
 Serialise a Formula evaluation as text.
Public Member Functions inherited from semiring::Semiring< std::string >
virtual ~Semiring ()=default
virtual bool absorptive () const
 Return true if this semiring is absorptive ( \(\mathbb{1} \oplus a = \mathbb{1}\) for all \(a\)).
virtual bool certifying () const
 Whether this semiring builds certified exclusive enumerations (see the three hooks below).
virtual bool independent_literal (const value_type &) const
 Whether v is an independent literal for certification purposes: a base Bernoulli variable (or a constant), so that distinct literals have disjoint supports and an AND over them is decomposable.
virtual value_type certified_world_term (const std::vector< value_type > &, const std::vector< value_type > &) const
 Build one complete world term: the conjunction of the present literals and the negations of the missing literals, certified decomposable.
virtual value_type certified_exclusive_plus (const std::vector< value_type > &) const
 Build the disjunction of pairwise-exclusive disjuncts, certified deterministic.

Additional Inherited Members

Public Types inherited from semiring::Semiring< std::string >
typedef std::string value_type
 The carrier type of this semiring.

Detailed Description

Symbolic provenance representation over std::string.

Evaluates circuits to human-readable Unicode formulas. Supports all optional operations (cmp, semimod, agg, value) in addition to the mandatory ones.

Definition at line 110 of file Formula.h.

Member Function Documentation

◆ agg()

virtual value_type semiring::Formula::agg ( AggregationOperator op,
const std::vector< std::string > & s )
inlineoverridevirtual

Evaluate an aggregation gate.

Parameters
opThe aggregation function (COUNT, SUM, MIN…).
sList of child semiring values to aggregate.
Returns
The aggregated value.
Exceptions
SemiringExceptionif not overridden.

Reimplemented from semiring::Semiring< std::string >.

Definition at line 183 of file Formula.h.

◆ cmp()

virtual value_type semiring::Formula::cmp ( value_type s1,
ComparisonOperator op,
value_type s2 ) const
inlineoverridevirtual

Evaluate a comparison gate.

Parameters
s1Left operand.
opComparison operator.
s2Right operand.
Returns
Result of the comparison in this semiring.
Exceptions
SemiringExceptionif not overridden.

Reimplemented from semiring::Semiring< std::string >.

Definition at line 156 of file Formula.h.

◆ compatibleWithBooleanRewrite()

virtual bool semiring::Formula::compatibleWithBooleanRewrite ( ) const
inlineoverridevirtual

Special case: Formula serialises the circuit structure as a string rather than computing a semantic value, so a safe-query-rewritten circuit renders to its (rewritten) structural formula and remains a faithful description.

The homomorphism question does not arise.

Reimplemented from semiring::Semiring< std::string >.

Definition at line 279 of file Formula.h.

◆ delta()

virtual value_type semiring::Formula::delta ( value_type x) const
inlineoverridevirtual

Apply the \(\delta\) operator.

Parameters
xInput value.
Returns
\(\delta(x)\).

Implements semiring::Semiring< std::string >.

Definition at line 149 of file Formula.h.

◆ monus()

virtual value_type semiring::Formula::monus ( value_type x,
value_type y ) const
inlineoverridevirtual

Apply the monus (m-semiring difference) operation.

Parameters
xMinuend.
ySubtrahend.
Returns
\(x \ominus y\).

Implements semiring::Semiring< std::string >.

Definition at line 145 of file Formula.h.

◆ one()

virtual value_type semiring::Formula::one ( ) const
inlineoverridevirtual

Return the multiplicative identity \(\mathbb{1}\).

Returns
The one element of the semiring.

Implements semiring::Semiring< std::string >.

Definition at line 116 of file Formula.h.

Here is the caller graph for this function:

◆ parse_leaf()

value_type semiring::Formula::parse_leaf ( const char * v) const
inline

Definition at line 269 of file Formula.h.

◆ plus()

virtual value_type semiring::Formula::plus ( const std::vector< value_type > & v) const
inlineoverridevirtual

Apply the additive operation to a list of values.

Parameters
vOrdered list of operands (empty list should return zero()).
Returns
\(v_0 \oplus v_1 \oplus \cdots\).

Implements semiring::Semiring< std::string >.

Definition at line 119 of file Formula.h.

Here is the call graph for this function:

◆ semimod()

virtual value_type semiring::Formula::semimod ( value_type x,
value_type s ) const
inlineoverridevirtual

Apply a semimodule scalar multiplication.

Parameters
xProvenance value.
sScalar value.
Returns
\(x * s\) in the semimodule.
Exceptions
SemiringExceptionif not overridden.

Reimplemented from semiring::Semiring< std::string >.

Definition at line 180 of file Formula.h.

◆ times()

virtual value_type semiring::Formula::times ( const std::vector< value_type > & v) const
inlineoverridevirtual

Apply the multiplicative operation to a list of values.

Parameters
vOrdered list of operands (empty list should return one()).
Returns
\(v_0 \otimes v_1 \otimes \cdots\).

Implements semiring::Semiring< std::string >.

Definition at line 134 of file Formula.h.

Here is the call graph for this function:

◆ to_text()

std::string semiring::Formula::to_text ( const value_type & s) const
inline

Serialise a Formula evaluation as text.

Drops the cosmetic outer paren pair that plus / times / monus always produce: at the root there is no enclosing context, so the outer parens carry no disambiguation value.

Definition at line 289 of file Formula.h.

◆ value()

virtual value_type semiring::Formula::value ( const std::string & s) const
inlineoverridevirtual

Interpret a literal string as a semiring value.

Used for gate_value gates whose payload is a string.

Parameters
sLiteral string.
Returns
The corresponding semiring value.
Exceptions
SemiringExceptionif not overridden.

Reimplemented from semiring::Semiring< std::string >.

Definition at line 266 of file Formula.h.

◆ zero()

virtual value_type semiring::Formula::zero ( ) const
inlineoverridevirtual

Return the additive identity \(\mathbb{0}\).

Returns
The zero element of the semiring.

Implements semiring::Semiring< std::string >.

Definition at line 113 of file Formula.h.

Here is the caller graph for this function:

The documentation for this class was generated from the following file:
  • /home/senellar/git/software/provsql/src/semiring/Formula.h