20 if (cw.size() != 2)
return false;
24 if (!okop)
return false;
28 gate_t agg_side, const_side;
30 agg_side = cw[0]; const_side = cw[1];
32 agg_side = cw[1]; const_side = cw[0];
46 const unsigned aggtype =
53 long c_mant = 0;
int c_scale = 0;
57 const auto &agg_children = gc.
getWires(agg_side);
58 if (agg_children.empty())
return false;
60 std::vector<gate_t> semimods, ks;
61 std::vector<long> m_mant;
62 std::vector<int> m_scale;
63 semimods.reserve(agg_children.size());
64 ks.reserve(agg_children.size());
65 m_mant.reserve(agg_children.size());
66 m_scale.reserve(agg_children.size());
68 for (
gate_t ch : agg_children) {
74 long mm = 0;
int sc = 0;
77 semimods.push_back(ch);
80 m_scale.push_back(sc);
90 for (std::size_t i = 0; i < m_mant.size(); ++i)
91 if (!(m_mant[i] == 1 && m_scale[i] == 0)) { all_one =
false;
break; }
97 for (
int s : m_scale) target = std::max(target, s);
100 std::vector<long> ms(m_mant.size());
101 for (std::size_t i = 0; i < m_mant.size(); ++i)
107 out.
ks = std::move(ks);
108 out.
ms = std::move(ms);
118 std::vector<unsigned> ref(nb, 0);
119 for (std::size_t i = 0; i < nb; ++i) {
120 auto g =
static_cast<gate_t>(i);
122 const auto idx =
static_cast<std::size_t
>(w);
123 if (idx < ref.size()) ++ref[idx];
130 const std::vector<unsigned> &ref,
bool &ok)
136 if (ref[
static_cast<std::size_t
>(g)] != 1) { ok =
false;
return 0.0; }
139 if (ref[
static_cast<std::size_t
>(g)] != 1) { ok =
false;
return 0.0; }
148 if (ref[
static_cast<std::size_t
>(g)] != 1) { ok =
false;
return 0.0; }
160 if (ref[
static_cast<std::size_t
>(g)] != 1) { ok =
false;
return 0.0; }
162 if (w.size() != 2) { ok =
false;
return 0.0; }
167 return pa * (1.0 - pb);
AggregationOperator getAggregationOperator(Oid oid)
Map a PostgreSQL aggregate function OID to an AggregationOperator.
AggregationOperator
SQL aggregation functions tracked by ProvSQL.
@ COUNT
COUNT(*) or COUNT(expr) → integer.
@ SUM
SUM → integer or float.
ComparisonOperator
SQL comparison operators used in gate_cmp circuit gates.
gate_t
Strongly-typed gate identifier.
Shared machinery for the closed-form HAVING gate_cmp probability evaluators (Poisson-binomial COUNT,...
std::vector< gate_t > & getWires(gate_t g)
Return a mutable reference to the child-wire list of gate g.
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.
double getProb(gate_t g) const
Return the probability for gate g.
std::pair< unsigned, unsigned > getInfos(gate_t g) const
Return the integer annotation pair for gate g.
Provenance evaluation helper for HAVING-clause circuits.
bool rescale_to(long mantissa, int scale, int target_scale, long &out)
bool aggtype_is_text(unsigned oid)
ComparisonOperator flip_op(ComparisonOperator op)
bool parse_decimal_scaled(const std::string &s, long &mantissa, int &scale)
ComparisonOperator map_cmp_op(GenericCircuit &c, gate_t cmp_gate, bool &ok)
bool semimod_extract_string_and_K(GenericCircuit &c, gate_t semimod_gate, std::string &m_out, gate_t &k_gate_out)
bool extract_constant_string(GenericCircuit &c, gate_t x, std::string &C_out)
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)).
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).
Core types, constants, and utilities shared across ProvSQL.
#define PROVSQL_AGG_TYPE_MASK
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