refining the tuple calculations

This commit is contained in:
Felix Dilke 2026-02-10 16:39:10 +00:00
parent 6848663caf
commit 591a24d755

View File

@ -18,6 +18,9 @@ import Datalog.DatalogParser
import Control.Exception import Control.Exception
import Data.Maybe import Data.Maybe
import Utility.Utility import Utility.Utility
import Control.Monad(guard)
import Data.Set (Set)
import Data.Set qualified as Set
data (DatalogDB db) => NaiveQE db = NaiveQE data (DatalogDB db) => NaiveQE db = NaiveQE
{ {
@ -64,7 +67,13 @@ computeHerbrand db =
amalgamateRelationSub newFacts relation = amalgamateRelationSub newFacts relation =
foldr amalgamateRule newFacts (_rules relation) where foldr amalgamateRule newFacts (_rules relation) where
amalgamateRule :: RelationRule -> NewFacts -> NewFacts amalgamateRule :: RelationRule -> NewFacts -> NewFacts
amalgamateRule (RelationRule headVars body) newFacts = amalgamateRule (RelationRule headVars body) newFacts =
-- allMaps headVars (allConstants db) newFacts where
newFacts (facts, changed) = newFacts
knownTuples :: Set [Constant] = _tuples $ facts Map.! (_name relation)
extraTuples = do
varmap <- allMaps headVars (Set.toList $ allConstants db)
let tuple = (\name -> varmap Map.! name) <$> headVars
guard $ not $ Set.member tuple knownTuples
return varmap