Search in sources :

Example 1 with DefaultSingleQuantifierEliminationProblem

use of com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem in project aic-expresso by aic-sri-international.

the class SGDPLLTTester method makeProblem.

private static Expression makeProblem(Collection<Expression> indices, Constraint constraint, Expression body, AssociativeCommutativeGroup group, Context context) {
    Expression currentBody = body;
    boolean firstIndex = true;
    for (Expression index : indices) {
        Expression indexType = GrinderUtil.getTypeExpressionOfExpression(index, context);
        Expression constraintOnThisIndex = firstIndex ? constraint : TRUE;
        SingleQuantifierEliminationProblem problem = new DefaultSingleQuantifierEliminationProblem(group, index, indexType, constraintOnThisIndex, currentBody);
        currentBody = problem.toExpression();
        firstIndex = false;
    }
    return currentBody;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression) SingleQuantifierEliminationProblem(com.sri.ai.grinder.api.SingleQuantifierEliminationProblem) DefaultSingleQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem) DefaultSingleQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem)

Example 2 with DefaultSingleQuantifierEliminationProblem

use of com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem in project aic-expresso by aic-sri-international.

the class AbstractTranslationBasedTheory method getSingleVariableConstraintSatisfiabilityStepSolver.

@Override
public ExpressionLiteralSplitterStepSolver getSingleVariableConstraintSatisfiabilityStepSolver(SingleVariableConstraint constraint, Context context) {
    Expression index = constraint.getVariable();
    Expression indexType = context.getTypeExpressionOfRegisteredSymbol(index);
    DefaultSingleQuantifierEliminationProblem problem = new DefaultSingleQuantifierEliminationProblem(new Disjunction(), index, indexType, constraint, TRUE);
    return getSingleQuantifierEliminatorStepSolver(problem, context);
}
Also used : Disjunction(com.sri.ai.grinder.group.Disjunction) Expression(com.sri.ai.expresso.api.Expression) DefaultSingleQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem)

Example 3 with DefaultSingleQuantifierEliminationProblem

use of com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem 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)

Example 4 with DefaultSingleQuantifierEliminationProblem

use of com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem in project aic-expresso by aic-sri-international.

the class LinearRealArithmeticTheoryTest method runSummationTest.

private void runSummationTest(Expression variable, String constraintString, String bodyString, Expression expected, Simplifier simplifier, Context context) {
    Expression typeExpression = context.getTypeExpressionOfRegisteredSymbol(variable);
    runQuantifierTest(variable, constraintString, bodyString, expected, "summation for " + bodyString, (SingleVariableConstraint c, Expression b) -> new SummationOnLinearRealArithmeticAndPolynomialStepSolver(new DefaultSingleQuantifierEliminationProblem(new Sum(), variable, typeExpression, c, b)), context);
}
Also used : SingleVariableConstraint(com.sri.ai.grinder.api.SingleVariableConstraint) Expression(com.sri.ai.expresso.api.Expression) SummationOnLinearRealArithmeticAndPolynomialStepSolver(com.sri.ai.grinder.theory.linearrealarithmetic.SummationOnLinearRealArithmeticAndPolynomialStepSolver) DefaultSingleQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem) Sum(com.sri.ai.grinder.group.Sum)

Example 5 with DefaultSingleQuantifierEliminationProblem

use of com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem in project aic-expresso by aic-sri-international.

the class AbstractTranslationBasedTheory method getSingleVariableConstraintModelCountingStepSolver.

@Override
public ExpressionLiteralSplitterStepSolver getSingleVariableConstraintModelCountingStepSolver(SingleVariableConstraint constraint, Context context) {
    Expression index = constraint.getVariable();
    Expression indexType = context.getTypeExpressionOfRegisteredSymbol(index);
    DefaultSingleQuantifierEliminationProblem problem = new DefaultSingleQuantifierEliminationProblem(new Sum(), index, indexType, constraint, ONE);
    return getSingleQuantifierEliminatorStepSolver(problem, context);
}
Also used : Expression(com.sri.ai.expresso.api.Expression) DefaultSingleQuantifierEliminationProblem(com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem) Sum(com.sri.ai.grinder.group.Sum)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)6 DefaultSingleQuantifierEliminationProblem (com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem)6 Sum (com.sri.ai.grinder.group.Sum)4 SingleQuantifierEliminationProblem (com.sri.ai.grinder.api.SingleQuantifierEliminationProblem)2 Disjunction (com.sri.ai.grinder.group.Disjunction)2 QuantifiedExpression (com.sri.ai.expresso.api.QuantifiedExpression)1 ExpressionStepSolver (com.sri.ai.grinder.api.ExpressionStepSolver)1 MultiQuantifierEliminationProblem (com.sri.ai.grinder.api.MultiQuantifierEliminationProblem)1 SingleVariableConstraint (com.sri.ai.grinder.api.SingleVariableConstraint)1 Theory (com.sri.ai.grinder.api.Theory)1 DefaultMultiQuantifierEliminationProblem (com.sri.ai.grinder.core.solver.DefaultMultiQuantifierEliminationProblem)1 Conjunction (com.sri.ai.grinder.group.Conjunction)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 SummationOnLinearRealArithmeticAndPolynomialStepSolver (com.sri.ai.grinder.theory.linearrealarithmetic.SummationOnLinearRealArithmeticAndPolynomialStepSolver)1 Test (org.junit.Test)1