ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
GenericCircuit Class Reference

In-memory provenance circuit with semiring-generic evaluation. More...

#include "GenericCircuit.h"

Inheritance diagram for GenericCircuit:
Collaboration diagram for GenericCircuit:

Public Member Functions

virtual std::string toString (gate_t g) const override
 Return a placeholder debug string (not intended for display).
void setInfos (gate_t g, unsigned info1, unsigned info2)
 Set the integer annotation pair for gate g.
std::pair< unsigned, unsigned > getInfos (gate_t g) const
 Return the integer annotation pair for gate g.
void setExtra (gate_t g, const std::string &ex)
 Attach a string extra to gate g.
std::string getExtra (gate_t g) const
 Return the string extra for gate g.
gate_t addGate () override
 Allocate a new gate with a default-initialised type.
gate_t setGate (gate_type type) override
 Allocate a new gate with type type and no UUID.
gate_t setGate (const uuid &u, gate_type type) override
 Create or update the gate associated with UUID u.
const std::set< gate_t > & getInputs () const
 Return the set of input (leaf) gates.
void setProb (gate_t g, double p)
 Set the probability for gate g.
double getProb (gate_t g) const
 Return the probability for gate g.
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 Bernoulli gate_input for any other p.
void resolveCmpToPlusOfKGates (gate_t g, const std::vector< gate_t > &ks)
 Replace a gate_cmp by a gate_plus over the given per-row K-gates (the OR of the agg's row-presence indicators).
void resolveGateToZero (gate_t g)
 Replace an arbitrary gate (typically gate_times) by gate_zero.
void resolveToValue (gate_t g, const std::string &s)
 Rewrite an arbitrary gate as a gate_value carrying the textual extra s.
void resolveToRv (gate_t g, const std::string &s)
 Rewrite an arbitrary gate as a gate_rv carrying the distribution-spec extra s.
void liftConditionedToTarget (gate_t g, gate_t target)
 Replace a gate_conditioned g by a transparent passthrough to its target child (a single-child gate_arith PLUS, i.e.
bool foldSemiringIdentities ()
 Drop semiring identity wires and collapse single-wire gate_times / gate_plus to their lone non-identity child; collapse a gate_times containing a gate_zero wire to that absorber.
void foldBooleanIdentities ()
 Apply the Boolean-only AND the absorptive simplification rules to gate_plus and gate_times, to a joint fixpoint with foldSemiringIdentities.
void foldAbsorptiveIdentities ()
 Absorptive-rules-only variant of foldBooleanIdentities(): the joint fixpoint of the absorptive fold rules with foldSemiringIdentities, leaving the Boolean-only rules (times-idempotence, times-absorbs-plus) unapplied.
bool applyFoldRuleSweep (bool boolean_level)
 One pass of the fold rules over every gate_plus / gate_times.
void markBooleanAssumed (gate_t g)
 Mark gate g as Boolean-assumed (in-memory side band).
bool isBooleanAssumed (gate_t g) const
 Report whether g carries the Boolean-assumption flag.
void markAbsorptiveAssumed (gate_t g)
 Mark gate g as absorptive-assumed (in-memory side band).
bool isAbsorptiveAssumed (gate_t g) const
 Report whether g carries the absorptive-assumption flag.
void setWires (gate_t g, std::vector< gate_t > w)
 Replace the wires of g with w.
void resolveToPlus (gate_t g, std::vector< gate_t > w)
 Rewrite an arbitrary gate as a gate_plus over w.
gate_t addAnonymousInputGate (double p)
 Allocate a fresh gate_input gate carrying probability p, with a unique synthetic UUID so subsequent BooleanCircuit conversion does not collide multiple no-UUID inputs onto the same gate.
gate_t addAnonymousMulinputGate (gate_t key, double p, unsigned value_index)
 Allocate a fresh gate_mulinput gate with key key, probability p, and value index value_index.
gate_t addAnonymousArithGate (provsql_arith_op op, std::vector< gate_t > wires_)
 Allocate a fresh gate_arith gate with operator tag op and the given wires.
gate_t addAnonymousValueGate (const std::string &text)
 Allocate a fresh gate_value gate carrying the textual scalar text.
void resolveToMixture (gate_t g, gate_t p_token, gate_t x_token, gate_t y_token)
 Rewrite g in place as a gate_mixture over the wires [p_token, x_token, y_token].
gate_t addAnonymousMulinputGateWithValue (gate_t key, double p, unsigned value_index, const std::string &value_text)
 Allocate a fresh gate_mulinput labelled with a numeric outcome value carried in extra.
void resolveToCategoricalMixture (gate_t g, std::vector< gate_t > wires_)
 Rewrite g in place as a categorical-form gate_mixture over wires ([key, mul_1, ..., mul_n]).
bool isCategoricalMixture (gate_t g) const
 Test whether g is a categorical-form gate_mixture (the explicit provsql.categorical output).
template<class Archive>
void serialize (Archive &ar, const unsigned int version)
 Boost serialisation support.
template<typename S, std::enable_if_t< std::is_base_of_v< semiring::Semiring< typename S::value_type >, S >, int > = 0>
S::value_type evaluate (gate_t g, std::unordered_map< gate_t, typename S::value_type > &provenance_mapping, S semiring) const
 Evaluate the sub-circuit rooted at gate g over semiring semiring.
Public Member Functions inherited from Circuit< gate_type >
virtual ~Circuit ()
std::vector< gate_t >::size_type getNbGates () const
 Return the total number of gates in the circuit.
gate_t getGate (const uuid &u)
 Return (or create) the gate associated with UUID u.
uuid getUUID (gate_t g) const
 Return the UUID string associated with gate g.
gate_type getGateType (gate_t g) const
 Return the type of gate g.
std::vector< gate_t > & getWires (gate_t g)
 Return a mutable reference to the child-wire list of gate g.
virtual gate_t setGate (const uuid &u, gate_type type)
 Create or update the gate associated with UUID u.
bool hasGate (const uuid &u) const
 Test whether a gate with UUID u exists.
void addWire (gate_t f, gate_t t)
 Add a directed wire from gate f (parent) to gate t (child).

Private Attributes

std::map< gate_t, std::pair< unsigned, unsigned > > infos
 Per-gate (info1, info2) annotations.
std::map< gate_t, std::string > extra
 Per-gate string extras.
std::set< gate_tinputs
 Set of input (leaf) gate IDs.
std::vector< double > prob
 Per-gate probability values.
std::set< gate_tboolean_assumed_gates
 Side-band Boolean-assumption marker set by the Boolean-only fold rules ; an evaluator visiting a gate in this set refuses to proceed under a semiring that does not admit a homomorphism from Boolean functions. In-memory only ; never persisted to mmap. Distinct from the gate_assumed enum (used by the safe-query rewriter to encode the same restriction at the persistent layer).
std::set< gate_tabsorptive_assumed_gates
 Side-band absorptive-assumption marker set by the absorptive fold rules (plus-idempotence, plus-with-one absorber, plus-absorbs-times – sound in every absorptive semiring) ; an evaluator visiting a gate in this set refuses unless the semiring is absorptive or tolerates the (stronger) Boolean rewrite. In-memory only.

Friends

class dDNNFTreeDecompositionBuilder
class boost::serialization::access

Additional Inherited Members

Public Types inherited from Circuit< gate_type >
using uuid
 UUID type used in this circuit (always std::string).
Protected Member Functions inherited from Circuit< gate_type >
void setGateType (gate_t g, gate_type t)
 Update the type of an existing gate.
Protected Attributes inherited from Circuit< gate_type >
std::unordered_map< uuid, gate_tuuid2id
 UUID string → gate index.
std::unordered_map< gate_t, uuidid2uuid
 Gate index → UUID string.
std::vector< gate_typegates
 Gate type for each gate.
std::vector< std::vector< gate_t > > wires
 Child wire lists for each gate.

Detailed Description

In-memory provenance circuit with semiring-generic evaluation.

Gate types are the PostgreSQL gate_type values. The circuit is constructed from the persistent mmap store and then evaluated in-memory.

Definition at line 48 of file GenericCircuit.h.

Member Function Documentation

◆ addAnonymousArithGate()

gate_t GenericCircuit::addAnonymousArithGate ( provsql_arith_op op,
std::vector< gate_t > wires_ )
inline

Allocate a fresh gate_arith gate with operator tag op and the given wires.

Used by the HybridEvaluator simplifier's mixture-lift rule when pushing a PLUS / TIMES inside a mixture's two scalar branches: each branch needs a fresh gate_arith child carrying the lifted operation, and those children must round-trip through downstream id2uuid / uuid2id lookups (Studio's simplified subgraph, to_provxml). A unique synthetic UUID is minted for the same reason as addAnonymousInputGate.

Definition at line 517 of file GenericCircuit.h.

Here is the call graph for this function:

◆ addAnonymousInputGate()

gate_t GenericCircuit::addAnonymousInputGate ( double p)
inline

Allocate a fresh gate_input gate carrying probability p, with a unique synthetic UUID so subsequent BooleanCircuit conversion does not collide multiple no-UUID inputs onto the same gate.

The synthetic UUID is derived from the freshly-assigned gate id; it is not a real v4 UUID (does not match the xxxxxxxx-... format) and exists only for in-memory uniqueness during the probability_evaluate pipeline. The gate is added to inputs so the conversion's first loop maps it into BooleanCircuit's gc_to_bc.

Parameters
pProbability for the new input.
Returns
The id of the new gate.

Definition at line 468 of file GenericCircuit.h.

Here is the call graph for this function:

◆ addAnonymousMulinputGate()

gate_t GenericCircuit::addAnonymousMulinputGate ( gate_t key,
double p,
unsigned value_index )
inline

Allocate a fresh gate_mulinput gate with key key, probability p, and value index value_index.

Used by the joint-table decomposer to materialise one Bernoulli outcome of a 2^k-way categorical distribution over a shared continuous island. All mulinputs in one joint table share the same key (the block anchor returned by addAnonymousInputGate); value_index is stored in info1 so BooleanCircuit::independentEvaluation can group / dedup MULIN references at OR sites. A unique synthetic UUID is minted for the same reason as addAnonymousInputGate.

Definition at line 492 of file GenericCircuit.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addAnonymousMulinputGateWithValue()

gate_t GenericCircuit::addAnonymousMulinputGateWithValue ( gate_t key,
double p,
unsigned value_index,
const std::string & value_text )
inline

Allocate a fresh gate_mulinput labelled with a numeric outcome value carried in extra.

Variant of addAnonymousMulinputGate used by the categorical mixture lowering: the mulinput's info1 still holds the ordinal value_index for independentEvaluation's dedup, and the outcome's numeric label is stored in extra so the evaluator-side categorical-mixture handlers can read it as a float8.

Definition at line 589 of file GenericCircuit.h.

Here is the call graph for this function:

◆ addAnonymousValueGate()

gate_t GenericCircuit::addAnonymousValueGate ( const std::string & text)
inline

Allocate a fresh gate_value gate carrying the textual scalar text.

Used by the HybridEvaluator simplifier's PLUS coefficient aggregation rule: when same-RV terms in a PLUS gate are merged into arith(TIMES, value:a_total, Z) per RV, each coefficient a_total needs a fresh gate_value to feed the synthetic TIMES. text must be a canonical text form that round-trips through parseDoubleStrict (the simplifier already formats with precision 17). A unique synthetic UUID is minted for the same reason as addAnonymousInputGate.

Definition at line 542 of file GenericCircuit.h.

Here is the call graph for this function:

◆ addGate()

gate_t GenericCircuit::addGate ( )
overridevirtual

Allocate a new gate with a default-initialised type.

Derived classes override this to perform additional initialisation (e.g. resizing auxiliary vectors).

Returns
The gate_t identifier of the newly created gate.

Reimplemented from Circuit< gate_type >.

Definition at line 36 of file GenericCircuit.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ applyFoldRuleSweep()

bool GenericCircuit::applyFoldRuleSweep ( bool boolean_level)

One pass of the fold rules over every gate_plus / gate_times.

Helper for the joint-fixpoint loops : applies each enabled rule in place, marking touched gates absorptive- or Boolean-assumed according to which rule fired, and reports whether any rule fired so the caller knows whether to iterate. Not a fixpoint on its own (it does a single sweep).

Parameters
boolean_levelAlso apply the Boolean-only rules.
Returns
true if any rule fired during the sweep.

Definition at line 194 of file GenericCircuit.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ evaluate()

template<typename S, std::enable_if_t< std::is_base_of_v< semiring::Semiring< typename S::value_type >, S >, int >>
S::value_type GenericCircuit::evaluate ( gate_t g,
std::unordered_map< gate_t, typename S::value_type > & provenance_mapping,
S semiring ) const

Evaluate the sub-circuit rooted at gate g over semiring semiring.

Performs a post-order traversal from g, mapping each input gate to its semiring value via provenance_mapping, and combining the results using the semiring operations.

Every computed gate is memoised into provenance_mapping (a gate's semiring value is a pure function of the gate, so reuse is always sound): shared sub-DAGs are evaluated once, and gate-creating semirings (BoolExpr, formula) preserve the sharing structurally. After the call the mapping therefore covers every visited gate, not only the pre-seeded inputs.

Template Parameters
SA concrete semiring::Semiring subclass.
Parameters
gRoot gate of the sub-circuit to evaluate.
provenance_mappingMap from input gate IDs to semiring values; also serves as the memoisation table.
semiringSemiring instance providing zero(), one(), plus(), times(), etc.
Returns
The semiring value of the circuit at gate g.

Definition at line 36 of file GenericCircuit.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ foldAbsorptiveIdentities()

void GenericCircuit::foldAbsorptiveIdentities ( )

Absorptive-rules-only variant of foldBooleanIdentities(): the joint fixpoint of the absorptive fold rules with foldSemiringIdentities, leaving the Boolean-only rules (times-idempotence, times-absorbs-plus) unapplied.

Used at circuit-load time under the 'absorptive' provenance class.

Definition at line 337 of file GenericCircuit.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ foldBooleanIdentities()

void GenericCircuit::foldBooleanIdentities ( )

Apply the Boolean-only AND the absorptive simplification rules to gate_plus and gate_times, to a joint fixpoint with foldSemiringIdentities.

The rule set splits by the semiring class that justifies each rule:

  • Absorptive rules (sound in every absorptive semiring, i.e. whenever \(1 \oplus a = 1\); gates marked absorptive-assumed): plus-idempotence gate_plus(a, a, b)gate_plus(a, b) ( \(a \oplus a = a \oplus a \cdot 1 = a\)); plus-with-one absorber gate_plus(…, gate_one, …) → gate_one; plus-absorbs-times gate_plus(x, gate_times(x, y, …), …) → gate_plus(x, …) ( \(a \oplus a b = a\), the defining identity).
  • Boolean-only rules (gates marked Boolean-assumed): times-idempotence gate_times(a, a, b)gate_times(a, b) (fails in tropical: \(a + a = 2a\)); times-absorbs-plus gate_times(x, gate_plus(x, y, …), …) → gate_times(x, …) (the lattice dual, also unsound in tropical).

Operates on the in-memory GenericCircuit only ; the persistent mmap store is never mutated, and the gate's UUID-to-gate_t mapping survives so callers indexing by the original UUID still find it. Interleaves the rule sweep (applyFoldRuleSweep) with foldSemiringIdentities to a JOINT fixpoint, so an absorption whose dominating literal is only exposed by a single-wire collapse still fires; the result is a circuit on which no enabled rule applies.

Definition at line 312 of file GenericCircuit.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ foldSemiringIdentities()

bool GenericCircuit::foldSemiringIdentities ( )

Drop semiring identity wires and collapse single-wire gate_times / gate_plus to their lone non-identity child; collapse a gate_times containing a gate_zero wire to that absorber.

Universal rewrite: the multiplicative identity (gate_one), the additive identity (gate_zero), and the multiplicative absorber (gate_zero) hold across every provsql semiring, so a single pass after RangeCheck is sound for every downstream consumer (probability_evaluate, to_provxml, view_circuit, Studio's simplified subgraph). Does NOT apply the additive absorber rewrite (plus-with-one): gate_one only absorbs in idempotent semirings (Boolean, MinMax), so applying it unconditionally would silently change the semantics for Counting / Formula / etc.

A collapsed gate is not mutated to carry its target's content; instead every parent wire is rewired straight to the target and the UUID-to-gate_t map is re-pointed so a gate resolved by UUID (notably the caller-supplied root) follows the collapse. This keeps a shared leaf a single gate: copying a shared gate_input's content into the collapsed gate under a fresh UUID would mint an independent duplicate of that Bernoulli variable and over-count the probability of any non-read-once circuit.

Operates on the in-memory circuit only; the persistent mmap store is never touched. Gated alongside RangeCheck by provsql.simplify_on_load.

Returns
true if any phase mutated the circuit (so callers, notably foldBooleanIdentities, can drive a joint fixpoint).

< Whether any phase mutated the circuit.

Definition at line 45 of file GenericCircuit.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getExtra()

std::string GenericCircuit::getExtra ( gate_t g) const
inline

Return the string extra for gate g.

Parameters
gGate identifier.
Returns
The stored string, or empty if not set.

Definition at line 107 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ getInfos()

std::pair< unsigned, unsigned > GenericCircuit::getInfos ( gate_t g) const
inline

Return the integer annotation pair for gate g.

Parameters
gGate identifier.
Returns
{info1, info2}, or {-1,-1} if not set.

Definition at line 84 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ getInputs()

const std::set< gate_t > & GenericCircuit::getInputs ( ) const
inline

Return the set of input (leaf) gates.

Returns
Const reference to the set of input gate identifiers.

Definition at line 127 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ getProb()

double GenericCircuit::getProb ( gate_t g) const
inline

Return the probability for gate g.

Parameters
gGate identifier.
Returns
The stored probability.

Definition at line 145 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ isAbsorptiveAssumed()

bool GenericCircuit::isAbsorptiveAssumed ( gate_t g) const
inline

Report whether g carries the absorptive-assumption flag.

Definition at line 421 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ isBooleanAssumed()

bool GenericCircuit::isBooleanAssumed ( gate_t g) const
inline

Report whether g carries the Boolean-assumption flag.

Definition at line 406 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ isCategoricalMixture()

bool GenericCircuit::isCategoricalMixture ( gate_t g) const
inline

Test whether g is a categorical-form gate_mixture (the explicit provsql.categorical output).

Returns true iff g is a gate_mixture whose wires are [key, mul_1, ..., mul_n] with n ≥ 1: wires[0] a gate_input key anchor, and every subsequent wire a gate_mulinput. The classic mixture shape [p_token, x_token, y_token] returns false (one or both of wires[1..2] are not gate_mulinput).

Definition at line 630 of file GenericCircuit.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ liftConditionedToTarget()

void GenericCircuit::liftConditionedToTarget ( gate_t g,
gate_t target )
inline

Replace a gate_conditioned g by a transparent passthrough to its target child (a single-child gate_arith PLUS, i.e.

the sum of one operand = the operand itself).

Used by the conditional-moment evaluator to lift conditioning out of a scalar arithmetic expression: "f(X|A, Y|B)" becomes "f(X, Y)" with the evidence A, B collected separately and conjoined into the root conditioning event. The passthrough REFERENCES target (it does not copy it), so a shared gate_rv keeps a single sampled draw. Operates on the in-memory circuit only.

Definition at line 296 of file GenericCircuit.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ markAbsorptiveAssumed()

void GenericCircuit::markAbsorptiveAssumed ( gate_t g)
inline

Mark gate g as absorptive-assumed (in-memory side band).

Visited by every evaluate<S> traversal : if g is in the set, the visit requires S::absorptive() or S::compatibleWithBooleanRewrite() (a semiring tolerating the stronger Boolean rewrite tolerates the weaker absorptive one) and throws a CircuitException otherwise.

Definition at line 418 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ markBooleanAssumed()

void GenericCircuit::markBooleanAssumed ( gate_t g)
inline

Mark gate g as Boolean-assumed (in-memory side band).

Visited by every evaluate<S> traversal : if g is in the set, the visit checks S::compatibleWithBooleanRewrite and throws a CircuitException otherwise.

Definition at line 403 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ resolveCmpToBernoulli()

void GenericCircuit::resolveCmpToBernoulli ( gate_t g,
double p )
inline

Replace a gate_cmp by a constant Boolean leaf (gate_one for p == 1, gate_zero for p == 0) or by a Bernoulli gate_input for any other p.

Used by peephole pruning passes when a comparator's probability is provably 0, 1, or a closed-form value. Distinguishing the 0 / 1 case from the fractional case matters because non-probabilistic semirings (e.g. sr_formula, sr_counting) have well-defined zero() / one() values but no notion of "Bernoulli with probability @c p" – an unknown gate_input would default to semiring.one() in every semiring (per GenericCircuit::evaluate), which is wrong for an always-false comparator. Using gate_zero / gate_one directly is universally correct: every semiring knows its identities.

Fractional probabilities are still encoded as gate_input + a probability so probability evaluators (MC, independent, treedec, d-DNNF, d4) can consume them, but only those evaluators handle non-trivial probabilities meaningfully. Such resolutions should therefore be confined to passes invoked from a probability context (not the universal getGenericCircuit-time pass).

Operates on the in-memory circuit only; the persistent mmap store is never mutated. Children that become orphaned are not reaped here.

Definition at line 177 of file GenericCircuit.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resolveCmpToPlusOfKGates()

void GenericCircuit::resolveCmpToPlusOfKGates ( gate_t g,
const std::vector< gate_t > & ks )
inline

Replace a gate_cmp by a gate_plus over the given per-row K-gates (the OR of the agg's row-presence indicators).

Used by the probability-side always-true HAVING rewriter (runHavingAlwaysTrueRewriter): when a HAVING predicate is provably true on the agg's value-interval, the cmp value equals "the group is non-empty" – the OR over the agg's K-gates – not gate_one, which would over-credit the empty world (see decideAggVsConstCmp's doc comment).

Sound for absorptive semirings where gate_plus is idempotent OR (probability, Boolean, formula, why, which, max-min, max-max); the call site lives in the probability-evaluate pre-pass for that reason, mirroring resolveCmpToBernoulli with a fractional probability.

Same wire/info/extra clearing as resolveCmpToBernoulli. No special-casing for ks of size 1: a single-child gate_plus is structurally redundant but semantically equivalent to that child in every semiring.

Definition at line 215 of file GenericCircuit.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resolveGateToZero()

void GenericCircuit::resolveGateToZero ( gate_t g)
inline

Replace an arbitrary gate (typically gate_times) by gate_zero.

Used by RangeCheck's joint-conjunction pass when an AND of cmps over a shared RV constrains its support to an empty interval: since gate_zero is the multiplicative absorber in every semiring, replacing a gate_times with it is universally sound, and orphans the conjuncts (their effects are now unreachable from the root, regardless of what each individual cmp would resolve to).

The wires, infos and extra fields are cleared so the gate is a proper leaf. Operates on the in-memory circuit only.

Definition at line 240 of file GenericCircuit.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resolveToCategoricalMixture()

void GenericCircuit::resolveToCategoricalMixture ( gate_t g,
std::vector< gate_t > wires_ )
inline

Rewrite g in place as a categorical-form gate_mixture over wires ([key, mul_1, ..., mul_n]).

Used by the explicit provsql.categorical constructor (built at SQL-call time, not by the simplifier): the gate_mixture type is reused with N > 3 wires, where wires[0] is a fresh gate_input "key" anchor (its own probability is irrelevant: the categorical mass is on the mulinputs) and wires[1..n] are gate_mulinput leaves sharing that key. Every gate_mixture handler downstream branches on wires.size() == 3 for the classic [p_token, x_token, y_token] shape vs the categorical shape; the latter is what unlocks closed-form CDF / cmp evaluation via AnalyticEvaluator.

Definition at line 612 of file GenericCircuit.h.

Here is the call graph for this function:

◆ resolveToMixture()

void GenericCircuit::resolveToMixture ( gate_t g,
gate_t p_token,
gate_t x_token,
gate_t y_token )
inline

Rewrite g in place as a gate_mixture over the wires [p_token, x_token, y_token].

Used by the HybridEvaluator simplifier's mixture-lift rule when a gate_arith containing a single gate_mixture child is pushed inside the mixture's branches: the outer arith gate is rewritten in place as the lifted mixture, preserving its UUID and the non-mixture-aware code paths that already hold references to it. The p_token is reused verbatim so Bernoulli identity is preserved across the rewrite; the x_token and y_token are the freshly-minted arith children built via addAnonymousArithGate.

Definition at line 566 of file GenericCircuit.h.

Here is the call graph for this function:

◆ resolveToPlus()

void GenericCircuit::resolveToPlus ( gate_t g,
std::vector< gate_t > w )
inline

Rewrite an arbitrary gate as a gate_plus over w.

Used by the HybridEvaluator multi-cmp island decomposer when a comparator from a shared-island group is rewritten as the OR of the joint-table gate_mulinput leaves where the comparator's bit is set. Clears infos and extra and installs the new wires.

Definition at line 445 of file GenericCircuit.h.

Here is the call graph for this function:

◆ resolveToRv()

void GenericCircuit::resolveToRv ( gate_t g,
const std::string & s )
inline

Rewrite an arbitrary gate as a gate_rv carrying the distribution-spec extra s.

Used by the HybridEvaluator simplifier when a linear combination of independent normals (or i.i.d. exponentials with the same rate) collapses to a single closed-form distribution. s must be a textual encoding parseable by parse_distribution_spec. Same wire/info clearing as resolveCmpToBernoulli. Operates on the in-memory circuit only.

Definition at line 277 of file GenericCircuit.h.

Here is the call graph for this function:

◆ resolveToValue()

void GenericCircuit::resolveToValue ( gate_t g,
const std::string & s )
inline

Rewrite an arbitrary gate as a gate_value carrying the textual extra s.

Used by the HybridEvaluator simplifier when a gate_arith subtree constant-folds to a scalar. Same wire/info/extra clearing as resolveCmpToBernoulli – the old children become orphans relative to g. s is interpreted by the consumer via parseDoubleStrict (or analogous routines), so it must be a canonical textual representation that round-trips through std::stod. Operates on the in-memory circuit only.

Definition at line 259 of file GenericCircuit.h.

Here is the call graph for this function:

◆ serialize()

template<class Archive>
void GenericCircuit::serialize ( Archive & ar,
const unsigned int version )
inline

Boost serialisation support.

Parameters
arBoost archive (input or output).
versionArchive version (unused).

Definition at line 648 of file GenericCircuit.h.

◆ setExtra()

void GenericCircuit::setExtra ( gate_t g,
const std::string & ex )
inline

Attach a string extra to gate g.

Parameters
gGate identifier.
exString to store.

Definition at line 97 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ setGate() [1/2]

gate_t GenericCircuit::setGate ( const uuid & u,
gate_type type )
override

Create or update the gate associated with UUID u.

If the UUID is already mapped the existing gate's type is updated. Otherwise a new gate is allocated.

Parameters
uUUID string to associate with the gate.
typeGate type.
Returns
Gate identifier.

Definition at line 27 of file GenericCircuit.cpp.

Here is the call graph for this function:

◆ setGate() [2/2]

gate_t GenericCircuit::setGate ( gate_type type)
override

Allocate a new gate with type type and no UUID.

Parameters
typeGate type.
Returns
Gate identifier.

Definition at line 18 of file GenericCircuit.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setInfos()

void GenericCircuit::setInfos ( gate_t g,
unsigned info1,
unsigned info2 )
inline

Set the integer annotation pair for gate g.

Parameters
gGate identifier.
info1First annotation integer.
info2Second annotation integer.

Definition at line 74 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ setProb()

void GenericCircuit::setProb ( gate_t g,
double p )
inline

Set the probability for gate g.

Parameters
gGate identifier.
pProbability in [0, 1].

Definition at line 136 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ setWires()

void GenericCircuit::setWires ( gate_t g,
std::vector< gate_t > w )
inline

Replace the wires of g with w.

Used by the HybridEvaluator simplifier's identity-element drop to remove constant-zero wires from a PLUS gate (or constant-one wires from a TIMES gate) without changing the gate's type. Dropped children become orphans relative to g.

Definition at line 433 of file GenericCircuit.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

virtual std::string GenericCircuit::toString ( gate_t g) const
inlineoverridevirtual

Return a placeholder debug string (not intended for display).

Parameters
gGate identifier (unused).
Returns
Fixed placeholder string "<GenericCircuit>".

Implements Circuit< gate_type >.

Definition at line 64 of file GenericCircuit.h.

◆ boost::serialization::access

friend class boost::serialization::access
friend

Definition at line 661 of file GenericCircuit.h.

◆ dDNNFTreeDecompositionBuilder

friend class dDNNFTreeDecompositionBuilder
friend

Definition at line 660 of file GenericCircuit.h.

Member Data Documentation

◆ absorptive_assumed_gates

std::set<gate_t> GenericCircuit::absorptive_assumed_gates
private

Side-band absorptive-assumption marker set by the absorptive fold rules (plus-idempotence, plus-with-one absorber, plus-absorbs-times – sound in every absorptive semiring) ; an evaluator visiting a gate in this set refuses unless the semiring is absorptive or tolerates the (stronger) Boolean rewrite. In-memory only.

Definition at line 56 of file GenericCircuit.h.

◆ boolean_assumed_gates

std::set<gate_t> GenericCircuit::boolean_assumed_gates
private

Side-band Boolean-assumption marker set by the Boolean-only fold rules ; an evaluator visiting a gate in this set refuses to proceed under a semiring that does not admit a homomorphism from Boolean functions. In-memory only ; never persisted to mmap. Distinct from the gate_assumed enum (used by the safe-query rewriter to encode the same restriction at the persistent layer).

Definition at line 55 of file GenericCircuit.h.

◆ extra

std::map<gate_t, std::string> GenericCircuit::extra
private

Per-gate string extras.

Definition at line 52 of file GenericCircuit.h.

◆ infos

std::map<gate_t, std::pair<unsigned,unsigned> > GenericCircuit::infos
private

Per-gate (info1, info2) annotations.

Definition at line 51 of file GenericCircuit.h.

◆ inputs

std::set<gate_t> GenericCircuit::inputs
private

Set of input (leaf) gate IDs.

Definition at line 53 of file GenericCircuit.h.

◆ prob

std::vector<double> GenericCircuit::prob
private

Per-gate probability values.

Definition at line 54 of file GenericCircuit.h.


The documentation for this class was generated from the following files: