Search in sources :

Example 6 with ExpressionStepSolver

use of com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver in project aic-expresso by aic-sri-international.

the class LinearRealArithmeticTheoryTest method runQuantifierTest.

private void runQuantifierTest(Expression variable, String constraintString, String bodyString, Expression expected, String computedFunction, BinaryFunction<Constraint, Expression, ExpressionStepSolver> stepSolverMaker, Context context) {
    Expression body = parse(bodyString);
    Function<Constraint, ExpressionStepSolver> stepSolverMakerFromConstraint = c -> stepSolverMaker.apply(c, body);
    runTest(variable, constraintString, expected, computedFunction, stepSolverMakerFromConstraint, context);
}
Also used : IntervalWithMeasureEquivalentToSingleVariableLinearRealArithmeticConstraintStepSolver(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.IntervalWithMeasureEquivalentToSingleVariableLinearRealArithmeticConstraintStepSolver) BinaryFunction(com.sri.ai.util.base.BinaryFunction) ExpressionStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver) Function(com.google.common.base.Function) Simplifier(com.sri.ai.grinder.sgdpllt.rewriter.api.Simplifier) Random(java.util.Random) Test(org.junit.Test) Expression(com.sri.ai.expresso.api.Expression) Constraint(com.sri.ai.grinder.sgdpllt.api.Constraint) Context(com.sri.ai.grinder.sgdpllt.api.Context) LinearRealArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory) Beta(com.google.common.annotations.Beta) Expressions.parse(com.sri.ai.expresso.helper.Expressions.parse) SingleVariableLinearRealArithmeticConstraint(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.SingleVariableLinearRealArithmeticConstraint) MeasureOfSingleVariableLinearRealArithmeticConstraintStepSolver(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.MeasureOfSingleVariableLinearRealArithmeticConstraintStepSolver) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) SummationOnLinearRealArithmeticAndPolynomialStepSolver(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.SummationOnLinearRealArithmeticAndPolynomialStepSolver) Assert.assertEquals(org.junit.Assert.assertEquals) SatisfiabilityOfSingleVariableLinearRealArithmeticConstraintStepSolver(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.SatisfiabilityOfSingleVariableLinearRealArithmeticConstraintStepSolver) Expression(com.sri.ai.expresso.api.Expression) Constraint(com.sri.ai.grinder.sgdpllt.api.Constraint) SingleVariableLinearRealArithmeticConstraint(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.SingleVariableLinearRealArithmeticConstraint) ExpressionStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver)

Example 7 with ExpressionStepSolver

use of com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver in project aic-expresso by aic-sri-international.

the class LinearRealArithmeticTheoryTest method runTest.

/**
	 * @param variable
	 * @param constraintString
	 * @param expected
	 * @param computedFunction
	 * @param stepSolverMaker
	 * @param context
	 */
private void runTest(Expression variable, String constraintString, Expression expected, String computedFunction, Function<Constraint, ExpressionStepSolver> stepSolverMaker, Context context) {
    System.out.println("Solving " + computedFunction + " for " + variable + " in " + constraintString);
    Constraint constraint = new SingleVariableLinearRealArithmeticConstraint(variable, true, context.getTheory());
    constraint = constraint.conjoin(parse(constraintString), context);
    ExpressionStepSolver stepSolver = stepSolverMaker.apply(constraint);
    Expression actual = stepSolver.solve(context);
    System.out.println("Variable " + variable + "\nhas " + computedFunction + ":\n" + actual + "\nfor constraint:\n" + constraintString + "\n");
    assertEquals(expected, actual);
}
Also used : Constraint(com.sri.ai.grinder.sgdpllt.api.Constraint) SingleVariableLinearRealArithmeticConstraint(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.SingleVariableLinearRealArithmeticConstraint) Expression(com.sri.ai.expresso.api.Expression) ExpressionStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver) SingleVariableLinearRealArithmeticConstraint(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.SingleVariableLinearRealArithmeticConstraint)

Example 8 with ExpressionStepSolver

use of com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver in project aic-expresso by aic-sri-international.

the class LinearRealArithmeticTheory method getSingleVariableConstraintQuantifierEliminatorStepSolver.

@Override
public ExpressionLiteralSplitterStepSolver getSingleVariableConstraintQuantifierEliminatorStepSolver(AssociativeCommutativeGroup group, SingleVariableConstraint constraint, Expression body, Context context) {
    ExpressionStepSolver formulaSplitterStepSolver;
    if (group instanceof Sum) {
        formulaSplitterStepSolver = new SummationOnLinearRealArithmeticAndPolynomialStepSolver(constraint, body);
    } else {
        formulaSplitterStepSolver = new QuantifierEliminationOnBodyInWhichIndexOnlyOccursInsideLiteralsStepSolver(group, constraint, body);
    }
    ExpressionLiteralSplitterStepSolver result = new ExpressionStepSolverToLiteralSplitterStepSolverAdapter(formulaSplitterStepSolver);
    return result;
}
Also used : ExpressionLiteralSplitterStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver) ExpressionStepSolver(com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver) QuantifierEliminationOnBodyInWhichIndexOnlyOccursInsideLiteralsStepSolver(com.sri.ai.grinder.sgdpllt.core.solver.QuantifierEliminationOnBodyInWhichIndexOnlyOccursInsideLiteralsStepSolver) Sum(com.sri.ai.grinder.sgdpllt.group.Sum) ExpressionStepSolverToLiteralSplitterStepSolverAdapter(com.sri.ai.grinder.sgdpllt.core.solver.ExpressionStepSolverToLiteralSplitterStepSolverAdapter)

Aggregations

ExpressionStepSolver (com.sri.ai.grinder.sgdpllt.api.ExpressionStepSolver)8 ExpressionLiteralSplitterStepSolver (com.sri.ai.grinder.sgdpllt.api.ExpressionLiteralSplitterStepSolver)4 ExpressionStepSolverToLiteralSplitterStepSolverAdapter (com.sri.ai.grinder.sgdpllt.core.solver.ExpressionStepSolverToLiteralSplitterStepSolverAdapter)4 QuantifierEliminationOnBodyInWhichIndexOnlyOccursInsideLiteralsStepSolver (com.sri.ai.grinder.sgdpllt.core.solver.QuantifierEliminationOnBodyInWhichIndexOnlyOccursInsideLiteralsStepSolver)4 Expression (com.sri.ai.expresso.api.Expression)3 Constraint (com.sri.ai.grinder.sgdpllt.api.Constraint)3 Theory (com.sri.ai.grinder.sgdpllt.api.Theory)2 Sum (com.sri.ai.grinder.sgdpllt.group.Sum)2 SingleVariableLinearRealArithmeticConstraint (com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.SingleVariableLinearRealArithmeticConstraint)2 Beta (com.google.common.annotations.Beta)1 Function (com.google.common.base.Function)1 Expressions.parse (com.sri.ai.expresso.helper.Expressions.parse)1 Context (com.sri.ai.grinder.sgdpllt.api.Context)1 Simplifier (com.sri.ai.grinder.sgdpllt.rewriter.api.Simplifier)1 TheoryTestingSupport (com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport)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 IntervalWithMeasureEquivalentToSingleVariableLinearRealArithmeticConstraintStepSolver (com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.IntervalWithMeasureEquivalentToSingleVariableLinearRealArithmeticConstraintStepSolver)1 LinearRealArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory)1