use of com.sri.ai.grinder.theory.differencearithmetic.SummationOnDifferenceArithmeticAndPolynomialStepSolver in project aic-expresso by aic-sri-international.
the class SummationOnDifferenceArithmeticAndPolynomialStepSolverTest method runTest.
private void runTest(Expression variable, String constraintString, Expression body, Expression expected, Context context) {
Theory theory = context.getTheory();
SingleVariableDifferenceArithmeticConstraint constraint = new SingleVariableDifferenceArithmeticConstraint(variable, true, theory);
constraint = (SingleVariableDifferenceArithmeticConstraint) constraint.conjoin(parse(constraintString), context);
Expression typeExpression = context.getTypeExpressionOfRegisteredSymbol(variable);
SingleQuantifierEliminationProblem problem = new DefaultSingleQuantifierEliminationProblem(new Sum(), variable, typeExpression, constraint, body);
ExpressionStepSolver stepSolver = new SummationOnDifferenceArithmeticAndPolynomialStepSolver(problem);
Expression actual = stepSolver.solve(context);
expected = simplify(expected, context);
System.out.println("sum({{ (on " + variable + " in " + GrinderUtil.getTypeExpressionOfExpression(variable, context) + ") " + body + " : " + constraintString + " }} = " + actual + "\n");
if (!expected.equals(actual)) {
Expression difference = apply(MINUS, expected, actual);
Expression differenceResult = simplify(difference, context);
if (!differenceResult.equals(ZERO)) {
System.err.println("Expressions are not equal and even difference is not zero");
System.err.println("Expected: " + expected);
System.err.println("Actual: " + actual);
System.err.println("Difference: " + differenceResult);
fail("Expressions are not equal and even difference is not zero. Expected: " + expected + ", actual: " + actual);
}
}
// TODO: correctness test against grounding
}
Aggregations