ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
MinMaxCmpEvaluator.h
Go to the documentation of this file.
1/**
2 * @file MinMaxCmpEvaluator.h
3 * @brief Closed-form probability resolution for HAVING
4 * @c MIN(a) @c op @c C and @c MAX(a) @c op @c C @c gate_cmps.
5 *
6 * For comparators that reduce to
7 * @c gate_cmp(gate_agg(MIN|MAX, semimod_i(K_i, m_i)*), gate_value(C))
8 * where the contributors are mutually independent Bernoulli trials
9 * (each K_i a private read-once sub-circuit, the same soundness contract
10 * as @c CountCmpEvaluator), the comparator's probability has a trivial
11 * closed form -- products of @c (1 - p_i) over the children partitioned
12 * on @c m_i vs @c C, with no DP and no DNF.
13 *
14 * SQL HAVING semantics exclude the empty group (a group with no present
15 * row never appears in the answer), exactly as @c CountCmpEvaluator and
16 * @c count_enum do. Writing @c m_i for the per-row value of the
17 * aggregated column, @c G for "good" children and @c B for "bad"
18 * children, and @c qprod(S) = ∏_{i∈S}(1 - p_i), the twelve cases are:
19 *
20 * MAX ≥ C : G={m_i≥C} 1 − qprod(G)
21 * MAX > C : G={m_i>C} 1 − qprod(G)
22 * MAX ≤ C : B={m_i>C}, G={m_i≤C} qprod(B)·(1 − qprod(G))
23 * MAX < C : B={m_i≥C}, G={m_i<C} qprod(B)·(1 − qprod(G))
24 * MAX = C : B={m_i>C}, E={m_i=C} qprod(B)·(1 − qprod(E))
25 * MAX ≠ C : (1 − qprod(all)) − Pr(MAX = C)
26 * MIN ≤ C : G={m_i≤C} 1 − qprod(G)
27 * MIN < C : G={m_i<C} 1 − qprod(G)
28 * MIN ≥ C : B={m_i<C}, G={m_i≥C} qprod(B)·(1 − qprod(G))
29 * MIN > C : B={m_i≤C}, G={m_i>C} qprod(B)·(1 − qprod(G))
30 * MIN = C : B={m_i<C}, E={m_i=C} qprod(B)·(1 − qprod(E))
31 * MIN ≠ C : (1 − qprod(all)) − Pr(MIN = C)
32 *
33 * (The two "good" and "bad" sets are disjoint and independent, so the
34 * two factors multiply; the @c (1 − qprod(G)) factor enforces group
35 * non-emptiness.)
36 *
37 * After replacement the cmp is a Bernoulli @c gate_input carrying the
38 * numeric probability, semantically meaningful only on the probability
39 * path. Like @c runCountCmpEvaluator and @c runAnalyticEvaluator, the
40 * pass runs inside @c probability_evaluate.cpp, gated on
41 * @c provsql.cmp_probability_evaluation, not at load time.
42 */
43#ifndef PROVSQL_MIN_MAX_CMP_EVALUATOR_H
44#define PROVSQL_MIN_MAX_CMP_EVALUATOR_H
45
46#include "GenericCircuit.h"
47
48namespace provsql {
49
50/**
51 * @brief Run the MIN / MAX closed-form pre-pass over @p gc.
52 *
53 * For every @c gate_cmp whose shape matches a MIN(a)/MAX(a) op C HAVING
54 * predicate over independent private contributors, computes the
55 * comparator's probability in closed form and replaces the cmp by a
56 * Bernoulli @c gate_input via @c GenericCircuit::resolveCmpToBernoulli.
57 *
58 * @param gc Circuit to mutate in place.
59 * @return Number of comparators resolved by this pass.
60 */
61unsigned runMinMaxCmpEvaluator(GenericCircuit &gc);
62
63} // namespace provsql
64
65#endif // PROVSQL_MIN_MAX_CMP_EVALUATOR_H
Semiring-agnostic in-memory provenance circuit.
unsigned runMinMaxCmpEvaluator(GenericCircuit &gc)
Run the MIN / MAX closed-form pre-pass over gc.