14#if PG_VERSION_NUM >= 160000
17#include "catalog/pg_type.h"
18#include "utils/jsonb.h"
19#include "utils/fmgrprotos.h"
20#include "utils/uuid.h"
51 pg_uuid_t *token = DatumGetUUIDP(PG_GETARG_DATUM(0));
55 weighted = PG_GETARG_BOOL(1);
59 mapping = PG_GETARG_BOOL(2);
65 string cnf = c.
TseytinCNF(root, weighted, mapping);
67 text *result = (text *) palloc(VARHDRSZ + cnf.size());
68 SET_VARSIZE(result, VARHDRSZ + cnf.size());
69 memcpy((
void *) VARDATA(result), cnf.c_str(), cnf.size());
70 PG_RETURN_TEXT_P(result);
71 }
catch(
const std::exception &e) {
79static void json_escape(std::ostringstream &out,
const std::string &s)
83 case '"': out <<
"\\\"";
break;
84 case '\\': out <<
"\\\\";
break;
102 pg_uuid_t *token = DatumGetUUIDP(PG_GETARG_DATUM(0));
104 std::ostringstream out;
113 if(!first) out <<
',';
115 out <<
"{\"variable\":" << m.variable <<
",\"gate\":";
123 out <<
",\"probability\":";
124 if(m.probability != m.probability)
127 out << m.probability;
130 }
catch(
const std::exception &e) {
137 Datum json_datum = DirectFunctionCall1(
138 jsonb_in, CStringGetDatum(pstrdup(out.str().c_str())));
139 PG_RETURN_DATUM(json_datum);
Boolean provenance circuit with support for knowledge compilation.
BooleanCircuit getBooleanCircuit(GenericCircuit &gc, pg_uuid_t token, gate_t &gate, std::unordered_map< gate_t, gate_t > &gc_to_bc)
Build a BooleanCircuit from an already-loaded GenericCircuit.
Build in-memory circuits from the mmap-backed persistent store.
gate_t
Strongly-typed gate identifier.
Fix gettext macro conflicts between PostgreSQL and the C++ STL.
Boolean circuit for provenance formula evaluation.
std::vector< CNFInputMapping > tseytinVariableMapping() const
Map each input gate to its DIMACS variable, UUID, probability.
std::string TseytinCNF(gate_t g, bool display_prob, bool mapping=false) const
Return the Tseytin transformation of the sub-circuit at g as a DIMACS string.
void rewriteMultivaluedGates()
Rewrite all MULVAR/MULIN gate clusters into standard AND/OR/NOT circuits.
#define provsql_error(fmt,...)
Report a fatal ProvSQL error and abort the current transaction.
Shared-memory segment and inter-process pipe management.
Core types, constants, and utilities shared across ProvSQL.
C++ utility functions for UUID manipulation.
Datum tseytin_cnf(PG_FUNCTION_ARGS)
PostgreSQL-callable entry point.
Datum tseytin_cnf_mapping_json(PG_FUNCTION_ARGS)
PostgreSQL-callable entry point: variable mapping as jsonb.
static void json_escape(std::ostringstream &out, const std::string &s)