Search in sources :

Example 1 with SummationOnDifferenceArithmeticAndPolynomialStepSolver

use of com.sri.ai.grinder.sgdpllt.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();
    Constraint constraint = new SingleVariableDifferenceArithmeticConstraint(variable, true, theory);
    constraint = constraint.conjoin(parse(constraintString), context);
    ExpressionStepSolver stepSolver = new SummationOnDifferenceArithmeticAndPolynomialStepSolver((SingleVariableDifferenceArithmeticConstraint) constraint, body);
    Expression actual = stepSolver.solve(context);
    expected = simplify(expected, context);
    System.out.println("sum({{ (on " + variable + " in " + GrinderUtil.getTypeExpression(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");
        }
    }
// TODO: correctness test against grounding
}
Also used : SummationOnDifferenceArithmeticAndPolynomialStepSolver(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.SummationOnDifferenceArithmeticAndPolynomialStepSolver) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) Theory(com.sri.ai.grinder.sgdpllt.api.Theory) Constraint(com.sri.ai.grinder.sgdpllt.api.Constraint) SingleVariableDifferenceArithmeticConstraint(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.SingleVariableDifferenceArithmeticConstraint) Expression(com.sri.ai.expresso.api.Expression) ExpressionStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver) SingleVariableDifferenceArithmeticConstraint(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.SingleVariableDifferenceArithmeticConstraint)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)1 Constraint (com.sri.ai.grinder.sgdpllt.api.Constraint)1 ExpressionStepSolver (com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver)1 Theory (com.sri.ai.grinder.sgdpllt.api.Theory)1 DifferenceArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory)1 SingleVariableDifferenceArithmeticConstraint (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.SingleVariableDifferenceArithmeticConstraint)1 SummationOnDifferenceArithmeticAndPolynomialStepSolver (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.SummationOnDifferenceArithmeticAndPolynomialStepSolver)1