![]() |
ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
Symbolic representation of provenance as a human-readable formula. More...
#include <algorithm>#include <numeric>#include <vector>#include <string>#include <sstream>#include <iomanip>#include <iterator>#include <map>#include <memory>#include "Semiring.h"

Go to the source code of this file.
Classes | |
| class | semiring::Formula |
Symbolic provenance representation over std::string. More... | |
| struct | semiring::Formula::Equations |
| The unknowns named and the equations recorded during one evaluation, shared by the copies of the semiring that evaluation makes. More... | |
Namespaces | |
| namespace | semiring |
Functions | |
| template<typename Range> | |
| static std::string | join (Range const &elements, const char *const delimiter) |
| Concatenate the strings of a range with a delimiter. | |
| static std::pair< std::size_t, std::size_t > | operand_range (const std::string &s, const std::string &op) |
The part of s to write as an operand of op: its inner content if it is wrapped in a single matched outer paren pair whose top-level operator (depth 1, inside that pair) is op, all of it otherwise. | |
| static std::string | join_operands (const std::vector< const std::string * > &v, const std::string &op) |
"(a op b op ā¦)" over the operands v points to, flattened by operand_range, built in place. | |
| static std::vector< const std::string * > | pointers_to (const std::vector< std::string > &v) |
Pointers to the strings of v. | |
| static std::string | format_number (double v) |
| Render a probability for display in a symbolic formula. | |
Symbolic representation of provenance as a human-readable formula.
The Formula pseudo-semiring (std::string, \(\oplus\), \(\otimes\), "š", "š") produces a symbolic representation of provenance using Unicode semiring symbols. It is primarily used for debugging and testing.
Each gate evaluates to a string:
zero() ā "š"one() ā "š"plus() ā "(a ā b ā ā¦)" or just "a" for singletonstimes() ā "(a ā b ā ā¦)" or just "a" for singletonsmonus() ā "(a ā b)"delta() ā "Ī“(a)" or "Ī“a" if a starts with (cmp() ā "[s1 op s2]"semimod()ā "x*s"agg() ā operator-specific notation (e.g., "min(a,b)")value() ā the literal string itselfunmapped_input() ā the leaf's abbreviated UUID ("1361b50eā¦")It also renders the measure-carrier gates that carry no algebraic meaning, and that every proper semiring therefore refuses – being a serialisation of the circuit rather than an evaluation of it, Formula has a faithful rendering for each and refuses nothing:
rv() ā "normal(2.5, 0.5)" (wired parameters substituted)arith() ā ordinary arithmetic notation ("(a + b)", "ln(a)"ā¦), kept visually distinct from the semiring's \(\oplus\) / \(\otimes\)mixture() ā "(p ? x : y)"categorical() ā "categorical(Īŗ; 0.3: a, 0.7: b)"guarded_case()ā "case(g ā v; else d)"observe() ā "observe(x = 2.5)"conditioned() ā "(x | c)" Definition in file Formula.h.
|
static |
Render a probability for display in a symbolic formula.
Enough significant digits that the usual decimal probabilities print back as themselves (0.3, not 0.299999), without the full round-trip verbosity of setprecision(17).
Definition at line 175 of file Formula.h.

|
static |
Concatenate the strings of a range with a delimiter.
Used internally by Formula::agg() and the other n-ary renderings. Built in place, the size reserved first: a formula may be most of the memory in use, and a stream would hold it twice more.
| Range | Any range of std::string. |
| elements | The range to join. |
| delimiter | String to insert between adjacent elements. |
delimiter between them. Definition at line 65 of file Formula.h.

|
static |
|
static |
The part of s to write as an operand of op: its inner content if it is wrapped in a single matched outer paren pair whose top-level operator (depth 1, inside that pair) is op, all of it otherwise.
Used by Formula::plus() and Formula::times() to flatten same-op nested gates by associativity: a child "(a ā b)" feeding into a parent plus is unwrapped to "a ā b" so the join produces "a ā b ā c" instead of "(a ā b) ā c". A different top-level op (e.g., a times child) keeps its parens.
s: no copy is made. Definition at line 99 of file Formula.h.
