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

SQL function provsql.rv_analytical_curves(token, samples, prov). More...

#include "postgres.h"
#include "fmgr.h"
#include "utils/jsonb.h"
#include "utils/fmgrprotos.h"
#include "utils/uuid.h"
#include "provsql_utils.h"
#include "provsql_error.h"
#include "AnalyticEvaluator.h"
#include "CircuitFromMMap.h"
#include "GenericCircuit.h"
#include "HybridEvaluator.h"
#include "RandomVariable.h"
#include "RangeCheck.h"
#include "provsql_utils_cpp.h"
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <limits>
#include <optional>
#include <sstream>
#include <type_traits>
#include <utility>
#include <variant>
#include <vector>
Include dependency graph for RvAnalyticalCurves.cpp:

Go to the source code of this file.

Functions

Datum rv_analytical_curves (PG_FUNCTION_ARGS)

Detailed Description

SQL function provsql.rv_analytical_curves(token, samples, prov).

Returns a JSON object with closed-form curves for the (possibly conditional) distribution rooted at token, or NULL when no closed form applies. The payload has up to three fields:

  • pdfsamples evenly-spaced {x, p} points covering the continuous part of the distribution. Absent for pure-discrete shapes (Dirac / categorical).
  • cdf — same x grid as pdf, with cumulative probability.
  • stems — point masses {x, p} produced by Dirac (gate_value wrapped as an as_random) or categorical roots, or by Dirac/ categorical arms inside a Bernoulli mixture. Weights propagate through nested mixtures (each ancestor's p / 1-p applies).

Used by ProvSQL Studio's Distribution profile panel to overlay analytical curves and point-mass discs on the empirical histogram drawn from rv_histogram.

Supported shapes:

  • bare gate_rv root (Normal / Uniform / Exponential / Erlang with integer shape), optionally truncated by an AND-conjunct event extracted via collectRvConstraints;
  • Dirac point (gate_value with finite extra, surfaced by provsql.as_random);
  • categorical-form gate_mixture (one {key, mul_1..n});
  • classic Bernoulli gate_mixture ([p_token, x, y]) over any two recursively-matched shapes; p_token must be a bare gate_input (compound Boolean p bails).

Truncation is honoured only on the bare-RV path; mixtures / categoricals / Diracs are matched only with a trivial event.

See also
provsql::matchClosedFormDistribution in RangeCheck.h

Definition in file RvAnalyticalCurves.cpp.

Function Documentation

◆ rv_analytical_curves()

Datum rv_analytical_curves ( PG_FUNCTION_ARGS )

Definition at line 280 of file RvAnalyticalCurves.cpp.

Here is the call graph for this function: