-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Undefined arithmetics throws exception instead of ignoring the ground instance. #289
Comments
As for the undefined arithmetics, yes, a better error message is definitely needed. Also, I'd read ... requires input programs to be ... more as Solvers should have a static check rejecting programs that do not fulfill the criteria rather than making this something users get only notified of when it blows up at runtime. I think (although I don't know if Alpha would be smart enough), a variant of the program, say
should work (in the sense that it's valid ASP and should have substitutions), but I see no way of resolving |
This issue seems to be a duplicate of #203 |
Regarding the text of the standard, I think they explicitly cite a program
where for the substitution Regarding the questions whether Regarding the duplicate, yes, this is basically #203 resurfacing again. But this time I have more questions. :-) How to solve the issue: currently, it seems that we have to change all substitutions and subclasses of Basically, we could go two ways: 1) add evaluation abilities to all terms and make them aware that the result of an evaluation of one term may be any number of new terms (so we can also cover interval terms then). 2) add rewriting and put the evaluation safely way into builtin atoms (like we do it now with interval terms). |
Right, I wasnt't thinking the part with the uninterpreted function through, sorry about that.. I tested a bit now and took a closer look at our code. The current
and got the NPE mentioned above. // Check if the groundTerm is an arithmetic expression and evaluate it if so.
if (groundTerm instanceof ArithmeticTerm) {
Integer result = evaluateGroundTerm(groundTerm);
if (result == null) {
return Collections.emptyList();
}
resultTerm = ConstantTerm.getInstance(result);
} else {
...
}
private static Integer evaluateGroundTermHelper(Term term) {
if (term instanceof ConstantTerm
&& ((ConstantTerm<?>) term).getObject() instanceof Integer) {
// Extract integer from the constant.
return (Integer) ((ConstantTerm<?>) term).getObject();
} else if (term instanceof ArithmeticTerm) {
return ((ArithmeticTerm) term).evaluateExpression();
} else {
// ASP Core 2 standard allows non-integer terms in arithmetic expressions, result is to simply ignore the ground instance.
return null;
}
} Note that this is called recursively for every non-constant term making up the initial The reason this does not happen and the NPE happens in this "chaotic" fashion is that, upon substituting the arithmetic term, the new (substituted) term is constructed using public static Term getInstance(Term left, ArithmeticOperator arithmeticOperator, Term right) {
// Evaluate ground arithmetic terms immediately and return result.
if (left.isGround() && right.isGround()) {
Integer result = new ArithmeticTerm(left, arithmeticOperator, right).evaluateExpression();
return ConstantTerm.getInstance(result);
}
return INTERNER.intern(new ArithmeticTerm(left, arithmeticOperator, right));
} Since both Now, I'm not sure about the exact reasons for this |
The following program tries to evaluate
f(1+b)
, which contains an undefined arithmetic. An exception is thrown although the ground instance should be simply ignore.The expected answer is
{ q(1), q(b), r(f(2)) }
but an exception originating in substituting during grounding is thrown.Side note: in a recent version of the standard, Undefined Arithmetics are actually treated differently than in older versions. Now the standard requires input programs to be invariant under substitution of undefined arithmetic expressions with any term from the universe (in other words: programmer has to make sure undefined arithmetics do not occur). We might adopt a similar stance and decide that throwing an exception is actually the right thing (albeit it should be way more telling than the one Alpha produces with the above example). @madmike200590 what is your opinion on that?
The text was updated successfully, but these errors were encountered: