20template <
typename Pred>
21static double qprod(
const std::vector<double> &p,
22 const std::vector<long> &m,
26 for (std::size_t i = 0; i < p.size(); ++i)
27 if (pred(m[i])) q *= (1.0 - p[i]);
35 const std::vector<double> &p,
36 const std::vector<long> &m,
int C)
39 double no_above = qprod(p, m, [&](
long v) {
return v > C; });
40 double some_equal = 1.0 - qprod(p, m, [&](
long v) {
return v == C; });
41 return no_above * some_equal;
43 double no_below = qprod(p, m, [&](
long v) {
return v < C; });
44 double some_equal = 1.0 - qprod(p, m, [&](
long v) {
return v == C; });
45 return no_below * some_equal;
54 const std::vector<double> &p,
55 const std::vector<long> &m,
58 auto atLeastOne = [&](
auto pred) {
return 1.0 - qprod(p, m, pred); };
63 return atLeastOne([&](
long v) {
return v >= C; });
65 return atLeastOne([&](
long v) {
return v > C; });
67 return qprod(p, m, [&](
long v) {
return v > C; })
68 * atLeastOne([&](
long v) {
return v <= C; });
70 return qprod(p, m, [&](
long v) {
return v >= C; })
71 * atLeastOne([&](
long v) {
return v < C; });
73 return probEqual(agg, p, m, C);
75 return (1.0 - qprod(p, m, [](
long) {
return true; }))
76 - probEqual(agg, p, m, C);
81 return atLeastOne([&](
long v) {
return v <= C; });
83 return atLeastOne([&](
long v) {
return v < C; });
85 return qprod(p, m, [&](
long v) {
return v < C; })
86 * atLeastOne([&](
long v) {
return v >= C; });
88 return qprod(p, m, [&](
long v) {
return v <= C; })
89 * atLeastOne([&](
long v) {
return v > C; });
91 return probEqual(agg, p, m, C);
93 return (1.0 - qprod(p, m, [](
long) {
return true; }))
94 - probEqual(agg, p, m, C);
104 unsigned resolved = 0;
109 std::vector<gate_t> cmps;
110 for (std::size_t i = 0; i < nb; ++i) {
111 auto g =
static_cast<gate_t>(i);
115 if (cmps.empty())
return 0;
138 if (ref[
static_cast<std::size_t
>(match.
agg)] != 1)
continue;
140 std::vector<double> p;
141 p.reserve(match.
ks.size());
142 for (std::size_t i = 0; i < match.
ks.size(); ++i) {
143 if (ref[
static_cast<std::size_t
>(match.
semimods[i])] != 1) { sound =
false;
break; }
148 if (!sound)
continue;
150 double pr = cdfForOperator(match.
agg_kind, match.
op, p, match.
ms, match.
C);
153 if (pr < 0.0) pr = 0.0;
154 if (pr > 1.0) pr = 1.0;
Typed aggregation value, operator, and aggregator abstractions.
AggregationOperator
SQL aggregation functions tracked by ProvSQL.
ComparisonOperator
SQL comparison operators used in gate_cmp circuit gates.
@ LE
Less than or equal (<=).
@ GE
Greater than or equal (>=).
gate_t
Strongly-typed gate identifier.
Shared machinery for the closed-form HAVING gate_cmp probability evaluators (Poisson-binomial COUNT,...
Closed-form probability resolution for HAVING MIN(a) op C and MAX(a) op C gate_cmps.
gateType getGateType(gate_t g) const
Return the type of gate g.
std::vector< gate_t >::size_type getNbGates() const
Return the total number of gates in the circuit.
In-memory provenance circuit with semiring-generic evaluation.
void resolveCmpToBernoulli(gate_t g, double p)
Replace a gate_cmp by a constant Boolean leaf (gate_one for p == 1, gate_zero for p == 0) or by a Ber...
std::vector< unsigned > computeRefCounts(const GenericCircuit &gc)
Reference count of every gate as a wire-target across the whole circuit.
bool matchAggCmp(GenericCircuit &gc, gate_t cmp, AggCmpMatch &out)
Try to match cmp against gate_cmp(gate_agg(α, semimod_i(K_i, m_i)*), gate_value(C)).
unsigned runMinMaxCmpEvaluator(GenericCircuit &gc)
Run the MIN / MAX closed-form pre-pass over gc.
double contributorProb(const GenericCircuit &gc, gate_t g, const std::vector< unsigned > &ref, bool &ok)
Read-once marginal probability of a count/aggregate contributor (the K side of a semimod).
Result of matching a gate_cmp against the canonical HAVING aggregate-comparison shape.
gate_t agg
the gate_agg operand of the cmp
long C
the constant threshold, on the same integer grid as ms
std::vector< gate_t > ks
the K side of each semimod (contributor root)
std::vector< gate_t > semimods
the per-child gate_semimod parents
std::vector< long > ms
the M side of each semimod (per-row value), scaled to a common integer grid (numeric / decimal-float ...
AggregationOperator agg_kind
effective aggregate (SUM-of-1s remapped to COUNT)
ComparisonOperator op
comparator, flipped if the agg sits on the right