Search in sources :

Example 1 with SummationOnDifferenceArithmeticAndPolynomialStepSolver

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
}
Also used : SummationOnDifferenceArithmeticAndPolynomialStepSolver(com.sri.ai.grinder.theory.differencearithmetic.SummationOnDifferenceArithmeticAndPolynomialStepSolver) Theory(com.sri.ai.grinder.api.Theory) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) Expression(com.sri.ai.expresso.api.Expression) ExpressionStepSolver(com.sri.ai.grinder.api.ExpressionStepSolver) DefaultSingleQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem) SingleQuantifierEliminationProblem(com.sri.ai.grinder.api.SingleQuantifierEliminationProblem) DefaultSingleQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem) Sum(com.sri.ai.grinder.group.Sum) SingleVariableDifferenceArithmeticConstraint(com.sri.ai.grinder.theory.differencearithmetic.SingleVariableDifferenceArithmeticConstraint)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)1 ExpressionStepSolver (com.sri.ai.grinder.api.ExpressionStepSolver)1 SingleQuantifierEliminationProblem (com.sri.ai.grinder.api.SingleQuantifierEliminationProblem)1 Theory (com.sri.ai.grinder.api.Theory)1 DefaultSingleQuantifierEliminationProblem (com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem)1 Sum (com.sri.ai.grinder.group.Sum)1 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)1 SingleVariableDifferenceArithmeticConstraint (com.sri.ai.grinder.theory.differencearithmetic.SingleVariableDifferenceArithmeticConstraint)1 SummationOnDifferenceArithmeticAndPolynomialStepSolver (com.sri.ai.grinder.theory.differencearithmetic.SummationOnDifferenceArithmeticAndPolynomialStepSolver)1