Fixes lost signs with negated 0-ary predicates.

This commit is contained in:
Patrick Lühne 2017-05-04 15:44:37 +02:00
parent a1793e2dff
commit d056fabb8b
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
3 changed files with 22 additions and 3 deletions

View File

@ -2,6 +2,10 @@
## (unreleased) ## (unreleased)
Bug Fixes:
* fixes lost signs with negated 0-ary predicates
## 0.1.4 (2017-04-12) ## 0.1.4 (2017-04-12)
Features: Features:

View File

@ -58,7 +58,14 @@ struct BodyTermTranslateVisitor
throwErrorAtLocation(literal.location, "double-negated literals currently unsupported", context); throwErrorAtLocation(literal.location, "double-negated literals currently unsupported", context);
if (function.arguments.empty()) 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; std::vector<ast::Variable> variables;
variables.reserve(function.arguments.size()); variables.reserve(function.arguments.size());
@ -82,7 +89,7 @@ struct BodyTermTranslateVisitor
if (literal.sign == Clingo::AST::Sign::None) if (literal.sign == Clingo::AST::Sign::None)
conjunction.arguments.emplace_back(std::move(predicate)); 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))); conjunction.arguments.emplace_back(ast::Formula::make<ast::Not>(std::move(predicate)));
context.auxiliaryBodyVariableID += function.arguments.size(); context.auxiliaryBodyVariableID += function.arguments.size();

View File

@ -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"); 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)."; input << "not p(X, 1) :- not q(X, 2).";
anthem::translate("input", input, context); anthem::translate("input", input, context);