ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
CertifiedDDMaterialize.h
Go to the documentation of this file.
1/**
2 * @file CertifiedDDMaterialize.h
3 * @brief Content-addressed materialisation of a certified d-D into the
4 * mmap provenance store.
5 *
6 * A decomposition-aligned compiler (the reachability compiler, the
7 * joint-width UCQ compiler) builds a circuit that is **deterministic and
8 * decomposable by construction** -- a certified d-D. Rather than reading
9 * the probability off that circuit in C++, the certified d-D can be
10 * *materialised* as ordinary provenance gates (@c plus / @c times /
11 * @c monus, carrying the @c DNNF_CERT_INFO mark), so that the answer --
12 * probability, Shapley, expectation, any provenance-store evaluation --
13 * is obtained through the **single** standard entry point
14 * @c probability_evaluate() (etc.) on the materialised token. This keeps
15 * one evaluation path for the whole system and exploits the certificate
16 * (linear-time @c independentEvaluation / @c interpretAsDD).
17 *
18 * Gate UUIDs are content-addressed with the standard v5 recipes, so
19 * identical sub-circuits dedup in the store and re-materialising the same
20 * circuit is a no-op.
21 */
22#ifndef CERTIFIED_DD_MATERIALIZE_H
23#define CERTIFIED_DD_MATERIALIZE_H
24
25extern "C" {
26#include "postgres.h"
27#include "utils/uuid.h"
28
29#include "provsql_utils.h"
30}
31
32#include "dDNNF.h"
33
34#include <unordered_map>
35#include <vector>
36
37/**
38 * @brief RFC 4122 version-5 UUID in the ProvSQL namespace.
39 *
40 * Same value as the SQL @c uuid_generate_v5(uuid_ns_provsql(), name), so
41 * gates content-address identically to those the query rewriter mints.
42 *
43 * @param name Name within the namespace.
44 * @return The version-5 UUID.
45 */
46pg_uuid_t provsqlUuidV5(const std::string &name);
47
48/**
49 * @brief Materialise (the reachable part of) a certified d-D into the
50 * mmap store.
51 *
52 * Bottom-up over the gates reachable from @p roots: input gates keep
53 * their existing tokens (the leaf provenance, not touched), @c NOT @c x
54 * is stored as @c monus(one, x), AND as @c times, OR as @c plus. Gates
55 * carrying the d-D certificate get it persisted.
56 *
57 * @param dd The certified circuit.
58 * @param roots Gates whose closure to materialise.
59 * @param route Producing route, stamped in @c info2 of each materialised
60 * root (its @c info1 being the d-D certificate); read back by
61 * the probability dispatcher to name the evaluation method.
62 * @c PROVSQL_ROUTE_NONE leaves the roots untagged. A route
63 * that wraps its roots (see @c wrapAssumedAbsorptive) tags the
64 * wrapper instead and passes @c PROVSQL_ROUTE_NONE here.
65 * @return Map from @p dd gates to their store UUIDs.
66 */
67std::unordered_map<gate_t, pg_uuid_t, hash_gate_t> materializeCertifiedDD(
68 const dDNNF &dd, const std::vector<gate_t> &roots,
70
71/**
72 * @brief Wrap a materialised root in the @c 'absorptive' assumption
73 * marker and return the wrapper's UUID.
74 *
75 * Used by the reachability route, whose compiled circuit is the
76 * absorptive quotient of a genuinely infinite recursive provenance. The
77 * joint-width UCQ compiler does NOT use this: its d-D is the exact
78 * Boolean provenance of the (non-recursive) UCQ, sound for every
79 * absorptive-or-not probability evaluation.
80 *
81 * The wrapper carries @c PROVSQL_ROUTE_REACHABILITY in @c info1: the
82 * assumption kind alone does not identify the route (the truncated-fixpoint
83 * path in @c sql/provsql.common.sql also mints @c 'absorptive' wrappers), and
84 * the probability dispatcher reads the tag back to report @c reachability
85 * rather than the generic @c independent.
86 *
87 * @param child UUID of the materialised root to wrap.
88 * @return UUID of the @c gate_assumed wrapper.
89 */
91
92#endif /* CERTIFIED_DD_MATERIALIZE_H */
std::unordered_map< gate_t, pg_uuid_t, hash_gate_t > materializeCertifiedDD(const dDNNF &dd, const std::vector< gate_t > &roots, provsql_route route=PROVSQL_ROUTE_NONE)
Materialise (the reachable part of) a certified d-D into the mmap store.
pg_uuid_t wrapAssumedAbsorptive(const pg_uuid_t &child)
Wrap a materialised root in the 'absorptive' assumption marker and return the wrapper's UUID.
pg_uuid_t provsqlUuidV5(const std::string &name)
RFC 4122 version-5 UUID in the ProvSQL namespace.
A d-DNNF circuit supporting exact probabilistic and game-theoretic evaluation.
Definition dDNNF.h:71
Decomposable Deterministic Negation Normal Form circuit.
Core types, constants, and utilities shared across ProvSQL.
provsql_route
Tags identifying the planner-time route that produced a circuit.
@ PROVSQL_ROUTE_NONE
No route rewrite: ordinary lineage.
UUID structure.