pulsatrix
Loading...
Searching...
No Matches
pulsatrix::datalog::WeightedFactDatabase< T > Class Template Reference

A weighted fact database: a map from ground atom to a semiring value type T (bool for the trivial/boolean instantiation, double/float for the real-valued (+, x) instantiation). More...

#include <datalog_weighted_fact_database.hpp>

Public Member Functions

 WeightedFactDatabase ()=default
 
 WeightedFactDatabase (WeightedFactSet< T > facts)
 
void set (Atom fact, T weight)
 Sets (overwrites) a fact's weight.
 
bool contains (const Atom &fact) const
 
T weight_of (const Atom &fact, T default_weight) const
 The fact's current weight, or default_weight (conventionally Semiring::zero()) if the fact is not present – "zero derivation paths" reads as "absent from the map," never as an explicit zero-weight entry.
 
std::size_t size () const
 
bool empty () const
 
const WeightedFactSet< T > & facts () const
 
bool operator== (const WeightedFactDatabase &other) const
 
bool operator!= (const WeightedFactDatabase &other) const
 

Detailed Description

template<typename T>
class pulsatrix::datalog::WeightedFactDatabase< T >

A weighted fact database: a map from ground atom to a semiring value type T (bool for the trivial/boolean instantiation, double/float for the real-valued (+, x) instantiation).

Note
Phase 3 Mission 2 additive extension: T = DualNumber<double> (see datalog_dual_semiring.hpp) is a third instantiation, added alongside the original bool/double/float set – Mission 1's own Decision 3 rationale ("only a closed, known set of Value types is ever needed") is a scoped, revisitable choice, not a permanent ceiling; Mission 2's forward-mode-AD requirement is exactly the kind of genuine new need Mission 1's own notes anticipated as a "contained, mechanical follow-up." No existing instantiation's behavior changes.
Stage 3 design decision 1 (FactDatabase generalization shape): this is a new templated type introduced alongside Mission 0's FactDatabase, not a rewrite of it in place. Verified achievable (not assumed) by direct inspection of Mission 0's shipped FactDatabase: its own public contract (insert/contains/size/empty/ facts()/operator==, all over a set, no weight parameter anywhere) is a strictly narrower shape than a weighted map would need (set(fact, weight)/weight_of(fact)), so "generalize `FactDatabase` in place" would have meant either breaking its existing call sites (naive_evaluate/semi_naive_evaluate/all of datalog_fact_database_test.cpp) or bolting an unused weight parameter onto every boolean-only call site for no benefit. Introducing WeightedFactDatabase<T> alongside it instead makes the campaign doc's own phrasing – "boolean semiring re-expressed as the trivial case" – literally true: Mission 0's FactDatabase/naive_evaluate/semi_naive_evaluate are untouched (zero diff against Mission 0's shipped files), and the "trivial case" is demonstrated by running the new generic naive_evaluate_weighted<BooleanSemiring> against a WeightedFactDatabase<bool> built from the identical toy KB and checking it reproduces Mission 0's own naive_evaluate fixpoint exactly (the regression/equivalence test).

Constructor & Destructor Documentation

◆ WeightedFactDatabase() [1/2]

template<typename T >
pulsatrix::datalog::WeightedFactDatabase< T >::WeightedFactDatabase ( )
default

◆ WeightedFactDatabase() [2/2]

template<typename T >
pulsatrix::datalog::WeightedFactDatabase< T >::WeightedFactDatabase ( WeightedFactSet< T >  facts)
explicit

Member Function Documentation

◆ contains()

template<typename T >
bool pulsatrix::datalog::WeightedFactDatabase< T >::contains ( const Atom &  fact) const
inline

◆ empty()

template<typename T >
bool pulsatrix::datalog::WeightedFactDatabase< T >::empty ( ) const
inline

◆ facts()

template<typename T >
const WeightedFactSet< T > & pulsatrix::datalog::WeightedFactDatabase< T >::facts ( ) const
inline

◆ operator!=()

template<typename T >
bool pulsatrix::datalog::WeightedFactDatabase< T >::operator!= ( const WeightedFactDatabase< T > &  other) const
inline

◆ operator==()

template<typename T >
bool pulsatrix::datalog::WeightedFactDatabase< T >::operator== ( const WeightedFactDatabase< T > &  other) const
inline

◆ set()

template<typename T >
void pulsatrix::datalog::WeightedFactDatabase< T >::set ( Atom  fact,
T  weight 
)

Sets (overwrites) a fact's weight.

Exceptions
std::invalid_argumentif fact is not ground (contains a variable term).

◆ size()

template<typename T >
std::size_t pulsatrix::datalog::WeightedFactDatabase< T >::size ( ) const
inline

◆ weight_of()

template<typename T >
T pulsatrix::datalog::WeightedFactDatabase< T >::weight_of ( const Atom &  fact,
T  default_weight 
) const
inline

The fact's current weight, or default_weight (conventionally Semiring::zero()) if the fact is not present – "zero derivation paths" reads as "absent from the map," never as an explicit zero-weight entry.


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