Fixes lost signs with negated 0-ary predicates.
This commit is contained in:
parent
a1793e2dff
commit
d056fabb8b
@ -2,6 +2,10 @@
|
||||
|
||||
## (unreleased)
|
||||
|
||||
Bug Fixes:
|
||||
|
||||
* fixes lost signs with negated 0-ary predicates
|
||||
|
||||
## 0.1.4 (2017-04-12)
|
||||
|
||||
Features:
|
||||
|
@ -58,7 +58,14 @@ struct BodyTermTranslateVisitor
|
||||
throwErrorAtLocation(literal.location, "double-negated literals currently unsupported", context);
|
||||
|
||||
if (function.arguments.empty())
|
||||
return ast::Formula::make<ast::Predicate>(std::string(function.name));
|
||||
{
|
||||
auto predicate = ast::Formula::make<ast::Predicate>(std::string(function.name));
|
||||
|
||||
if (literal.sign == Clingo::AST::Sign::None)
|
||||
return std::move(predicate);
|
||||
else if (literal.sign == Clingo::AST::Sign::Negation)
|
||||
return ast::Formula::make<ast::Not>(std::move(predicate));
|
||||
}
|
||||
|
||||
std::vector<ast::Variable> variables;
|
||||
variables.reserve(function.arguments.size());
|
||||
@ -82,7 +89,7 @@ struct BodyTermTranslateVisitor
|
||||
|
||||
if (literal.sign == Clingo::AST::Sign::None)
|
||||
conjunction.arguments.emplace_back(std::move(predicate));
|
||||
else
|
||||
else if (literal.sign == Clingo::AST::Sign::Negation)
|
||||
conjunction.arguments.emplace_back(ast::Formula::make<ast::Not>(std::move(predicate)));
|
||||
|
||||
context.auxiliaryBodyVariableID += function.arguments.size();
|
||||
|
@ -188,7 +188,15 @@ TEST_CASE("[translation] Rules are translated correctly", "[translation]")
|
||||
CHECK(output.str() == "((V1 in M and V2 in N and V3 in O and V4 in P and exists X1, X2 (X1 in M and X2 in N and X1 < X2) and exists X3, X4 (X3 in P and X4 in O and X3 != X4)) -> p(V1, V2, V3, V4))\n");
|
||||
}
|
||||
|
||||
SECTION("single negation")
|
||||
SECTION("single negation with 0-ary predicates")
|
||||
{
|
||||
input << "not p :- not q.";
|
||||
anthem::translate("input", input, context);
|
||||
|
||||
CHECK(output.str() == "(not q -> not p)\n");
|
||||
}
|
||||
|
||||
SECTION("single negation with n-ary predicates")
|
||||
{
|
||||
input << "not p(X, 1) :- not q(X, 2).";
|
||||
anthem::translate("input", input, context);
|
||||
|
Loading…
Reference in New Issue
Block a user