Fix a bug in projectTuple where it wasn't ensuring that variables that appeared multiple times were bound to the same thing in the resulting set of tuples.

This commit is contained in:
Cale Gibbard 2026-01-26 12:18:29 -05:00
parent c09e07042b
commit a775f753e0

View File

@ -145,10 +145,16 @@ evalConjunction db atoms = do
return (foldr (><) (Set.singleton Map.empty) rs)
projectTuple :: Set ConId -> Map VarId ConId -> [Term] -> Set [ConId]
projectTuple univ m = Set.fromList . mapM proj
projectTuple univ m0 ts0 = Set.fromList $ proj m0 ts0
where
proj (Con c) = [c]
proj (Var v) = Map.findWithDefault (Set.toList univ) v (fmap (:[]) m)
proj _ [] = [[]]
proj m (Con c : ts) = map (c:) (proj m ts)
proj m (Var v : ts) = case Map.lookup v m of
Just c -> map (c:) (proj m ts)
Nothing -> do
c <- Set.toList univ
s <- proj (Map.insert v c m) ts
return (c : s)
immediateConsequences :: Database -> Rule -> Either EvalError (Set [ConId])
immediateConsequences db (Atom _ ts :- bodyAtoms) = do