![]() |
ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
Analytical expectation / variance / moment evaluator over RV circuits. More...


Go to the source code of this file.
Namespaces | |
| namespace | provsql |
Functions | |
| double | provsql::compute_expectation (const GenericCircuit &gc, gate_t root, std::optional< gate_t > event_root=std::nullopt) |
Compute \(E[X]\) (or \(E[X \mid A]\) if event_root is set) over the scalar sub-circuit rooted at root. | |
| double | provsql::compute_variance (const GenericCircuit &gc, gate_t root, std::optional< gate_t > event_root=std::nullopt) |
Compute \(\mathrm{Var}[X]\) (or \(\mathrm{Var}[X \mid A]\) if event_root is set) over the scalar sub-circuit rooted at root. | |
| double | provsql::compute_raw_moment (const GenericCircuit &gc, gate_t root, unsigned k, std::optional< gate_t > event_root=std::nullopt) |
Compute the raw moment \(E[X^k]\) (or \(E[X^k \mid A]\) if event_root is set) for k >= 0. | |
| double | provsql::compute_central_moment (const GenericCircuit &gc, gate_t root, unsigned k, std::optional< gate_t > event_root=std::nullopt) |
Compute the central moment \(E[(X - E[X])^k]\) (or \(E[(X - E[X \mid A])^k \mid A]\) if event_root is set). | |
| double | provsql::evaluateBooleanProbability (const GenericCircuit &gc, gate_t boolRoot) |
Probability that the Boolean subcircuit rooted at boolRoot evaluates to true under the tuple-independent probabilistic-database model. | |
Analytical expectation / variance / moment evaluator over RV circuits.
Computes E[X], Var[X], raw moments E[X^k] and central moments E[(X - E[X])^k] over a sub-circuit rooted at a scalar gate (gate_value, gate_rv, or gate_arith), using closed-form formulas wherever the sub-DAG decomposes structurally and falling back to Monte Carlo (via monteCarloScalarSamples) when structural shortcuts cannot decide a sub-expression.
Decomposition rules:
gate_value: literal, constant moments.gate_rv: closed-form moments per RandomVariable.h.gate_arith PLUS / MINUS / NEG: linearity of expectation always applies; variance and higher moments require structural independence of the children (their reachable gate_rv footprints must be pairwise disjoint).gate_arith TIMES: requires structural independence; otherwise MC fallback.gate_arith DIV: closed form when the divisor is a deterministic constant (gate_value), otherwise MC fallback.MC fallback is governed by the provsql.rv_mc_samples GUC: non-zero values pick the sample count; zero disables the fallback, causing the evaluator to throw rather than sample. This keeps a single knob shared with future RV-MC fallback paths (Priority 7's island decomposer).
Definition in file Expectation.h.