Search in sources :

Example 61 with Context

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

the class LinearRealArithmeticTheoryTest method testSummation.

@Test
public void testSummation() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new LinearRealArithmeticTheory(true, true));
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    Simplifier simplifier = (e, c) -> theoryTestingSupport.getTheory().simplify(e, c);
    Expression variable;
    String constraintString;
    String bodyString;
    Expression expected;
    variable = parse("X");
    constraintString = "true";
    bodyString = "1";
    expected = parse("4");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
    variable = parse("X");
    constraintString = "X < 3 and X != 2";
    bodyString = "1";
    expected = parse("3");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
    variable = parse("X");
    constraintString = "X < Y and X != 2";
    bodyString = "1";
    expected = parse("if Y > 0 then Y else 0");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
    variable = parse("X");
    constraintString = "X < 3 and X != 2";
    bodyString = "Y";
    expected = parse("3*Y");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
    variable = parse("X");
    constraintString = "X < 3 and X != 2";
    bodyString = "X";
    expected = parse("4.5");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
    variable = parse("X");
    constraintString = "X < 3 and X != 2 and X = 2";
    bodyString = "Y";
    expected = parse("0");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
    variable = parse("X");
    constraintString = "X < Y and X != 2";
    bodyString = "X";
    expected = parse("if Y > 0 then 0.5*Y^2 else 0");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
    variable = parse("X");
    constraintString = "X < Y and X != 2";
    bodyString = "Y";
    expected = parse("if Y > 0 then Y^2 else 0");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
    variable = parse("X");
    constraintString = "X < Y and X != 2";
    bodyString = "X + Y";
    expected = parse("if Y > 0 then 1.5*Y^2 else 0");
    runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
//		variable = parse("X");
//		constraintString = "X < Y and X != 2";
//		bodyString = "X^2 + Y";
//		expected = parse("if Y > 0 then 0.333333333*Y^3 + Y^2 else 0");
//		runSummationTest(variable, constraintString, bodyString, expected, simplifier, context);
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) 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) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) LinearRealArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory) Simplifier(com.sri.ai.grinder.sgdpllt.rewriter.api.Simplifier) Test(org.junit.Test)

Example 62 with Context

use of com.sri.ai.grinder.sgdpllt.api.Context 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 63 with Context

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

the class LinearRealArithmeticTheoryTest method testSatisfiability.

@Test
public void testSatisfiability() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new LinearRealArithmeticTheory(true, true));
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    Expression variable;
    String constraintString;
    Expression expected;
    variable = parse("X");
    constraintString = "true";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < 3";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X <= 3";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X < 4";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4 and X != 3.2";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2 and X = 3.2";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.2";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 8";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7 and X = 8";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7 and X = 8";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < Y";
    expected = parse("Y > 0");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X < Y + 1";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < Y - 4";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < 2 - Y";
    expected = parse("Y < 2");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > Y";
    expected = parse("Y < 4");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X > Y + 1";
    expected = parse("Y < 3");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y + 4";
    expected = parse("Y <= 0");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y + 2";
    expected = parse("Y <= 2");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X >= Y + 1";
    expected = parse("Y <= 3");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X <= 3";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4 and X != 3.2";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2 and X = 3.2";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.2";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.6";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7";
    expected = parse("true");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 8";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7 and X = 8";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7 and X = 8";
    expected = parse("false");
    runSatisfiabilityTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > Z and X >= Y";
    expected = parse("if Z < Y then Y <= 3.4 else Z < 3.4");
    runSatisfiabilityTest(variable, constraintString, expected, context);
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) Expression(com.sri.ai.expresso.api.Expression) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) LinearRealArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory) Test(org.junit.Test)

Example 64 with Context

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

the class LinearRealArithmeticTheoryTest method testMeasure.

@Test
public void testMeasure() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new LinearRealArithmeticTheory(true, true));
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    Expression variable;
    String constraintString;
    Expression expected;
    variable = parse("X");
    constraintString = "true";
    expected = parse("4");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < 3";
    expected = parse("3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X <= 3";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X < 4";
    expected = parse("1");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4 and X != 3.2";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2 and X = 3.2";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.2";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < Y";
    expected = parse("if Y > 0 then Y else 0");
    runMeasureTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X < Y + 1";
    expected = parse("if Y > 3 then 4 else Y + 1");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < Y - 4";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X < 2 - Y";
    expected = parse("if Y < 2 then -1*Y + 2 else 0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > Y";
    expected = parse("if Y < 4 then 4 - Y else 0");
    runMeasureTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X > Y + 1";
    expected = parse("if Y < 3 then 4 - (Y + 1) else 0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y + 4";
    expected = parse("if Y <= 0 then 4 - (Y + 4) else 0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y + 2";
    expected = parse("if Y <= 2 then 4 - (Y + 2) else 0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X >= Y";
    expected = parse("4 - Y");
    runMeasureTest(variable, constraintString, expected, context);
    // keep these tests together
    variable = parse("X");
    constraintString = "X >= Y + 1";
    expected = parse("if Y <= 3 then 4 - (Y + 1) else 0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3 and X <= 3";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X > 3.1 and X <= 3.4 and X != 3.2";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 3.2 and X = 3.2";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.2";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 3.6";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7";
    expected = parse("0.3");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X != 7 and X = 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > 3.1 and X = 7 and X = 8";
    expected = parse("0");
    runMeasureTest(variable, constraintString, expected, context);
    variable = parse("X");
    constraintString = "X <= 3.4 and X > Z and X >= Y";
    expected = parse("if Z < Y then if Y <= 3.4 then 3.4 - Y else 0 else if Z < 3.4 then 3.4 - Z else 0");
    runMeasureTest(variable, constraintString, expected, context);
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) Expression(com.sri.ai.expresso.api.Expression) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) LinearRealArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory) Test(org.junit.Test)

Example 65 with Context

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

the class SGDPLLTTester method testCompleteMultiVariableConstraints.

/**
	 * Given a theory and a number <code>n</code> of multi-variable constraint tests,
	 * generates <code>n</code> formulas in the theory
	 * and see if those detected as unsatisfiable by the corresponding solver
	 * are indeed unsatisfiable (checked by brute force).
	 * Throws an {@link Error} with the failure description if a test fails.
	 * @param theoryTestingSupport
	 * @param numberOfTests
	 * @param maxNumberOfLiterals
	 * @param outputCount
	 */
public static void testCompleteMultiVariableConstraints(boolean testAgainstBruteForce, TheoryTestingSupport theoryTestingSupport, long numberOfTests, int maxNumberOfLiterals, boolean outputCount) {
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    NullaryFunction<Constraint> makeInitialConstraint = () -> new CompleteMultiVariableContext(theoryTestingSupport.getTheory(), context);
    Function<Constraint, Expression> makeRandomLiteral = c -> theoryTestingSupport.makeRandomLiteral(context);
    // CompleteMultiVariableContext is complete
    TestRunner tester = SGDPLLTTester::testCompleteSatisfiability;
    runTesterGivenOnSuccessiveConjunctionsOfLiterals("complete satisfiability", tester, numberOfTests, maxNumberOfLiterals, testAgainstBruteForce, theoryTestingSupport, makeInitialConstraint, makeRandomLiteral, outputCount, context);
}
Also used : CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) Context(com.sri.ai.grinder.sgdpllt.api.Context) CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) BinaryFunction(com.sri.ai.util.base.BinaryFunction) Util.removeFromSetNonDestructively(com.sri.ai.util.Util.removeFromSetNonDestructively) SubExpressionsDepthFirstIterator(com.sri.ai.expresso.helper.SubExpressionsDepthFirstIterator) Expression(com.sri.ai.expresso.api.Expression) Constraint(com.sri.ai.grinder.sgdpllt.api.Constraint) Function(java.util.function.Function) GrinderUtil(com.sri.ai.grinder.helper.GrinderUtil) Util.in(com.sri.ai.util.Util.in) ThereExists(com.sri.ai.grinder.sgdpllt.library.boole.ThereExists) AbstractIterativeMultiIndexQuantifierElimination(com.sri.ai.grinder.sgdpllt.interpreter.AbstractIterativeMultiIndexQuantifierElimination) Expressions.parse(com.sri.ai.expresso.helper.Expressions.parse) Map(java.util.Map) CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) And(com.sri.ai.grinder.sgdpllt.library.boole.And) DefaultMultiVariableConstraint(com.sri.ai.grinder.sgdpllt.core.constraint.DefaultMultiVariableConstraint) ZERO(com.sri.ai.expresso.helper.Expressions.ZERO) LinkedHashSet(java.util.LinkedHashSet) Sets(com.sri.ai.grinder.sgdpllt.library.set.Sets) Type(com.sri.ai.expresso.api.Type) NullaryFunction(com.sri.ai.util.base.NullaryFunction) Util.join(com.sri.ai.util.Util.join) SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint) Simplifier(com.sri.ai.grinder.sgdpllt.rewriter.api.Simplifier) Collection(java.util.Collection) Util.list(com.sri.ai.util.Util.list) Set(java.util.Set) Expressions.getVariableReferences(com.sri.ai.expresso.helper.Expressions.getVariableReferences) Context(com.sri.ai.grinder.sgdpllt.api.Context) QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression) Theory(com.sri.ai.grinder.sgdpllt.api.Theory) Beta(com.google.common.annotations.Beta) IndexExpressions(com.sri.ai.grinder.sgdpllt.library.indexexpression.IndexExpressions) Expressions.makeSymbol(com.sri.ai.expresso.helper.Expressions.makeSymbol) Util(com.sri.ai.util.Util) AssociativeCommutativeGroup(com.sri.ai.grinder.sgdpllt.group.AssociativeCommutativeGroup) Util.pickKElementsWithoutReplacement(com.sri.ai.util.Util.pickKElementsWithoutReplacement) TRUE(com.sri.ai.expresso.helper.Expressions.TRUE) BruteForceCommonInterpreter(com.sri.ai.grinder.sgdpllt.interpreter.BruteForceCommonInterpreter) AssignmentsIterator(com.sri.ai.grinder.helper.AssignmentsIterator) Constraint(com.sri.ai.grinder.sgdpllt.api.Constraint) DefaultMultiVariableConstraint(com.sri.ai.grinder.sgdpllt.core.constraint.DefaultMultiVariableConstraint) SingleVariableConstraint(com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint) Expression(com.sri.ai.expresso.api.Expression) QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression)

Aggregations

Context (com.sri.ai.grinder.sgdpllt.api.Context)105 Expression (com.sri.ai.expresso.api.Expression)80 Test (org.junit.Test)48 TheoryTestingSupport (com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport)36 TrueContext (com.sri.ai.grinder.sgdpllt.core.TrueContext)30 Type (com.sri.ai.expresso.api.Type)28 DifferenceArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory)28 PropositionalTheory (com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory)22 EqualityTheory (com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory)20 CompoundTheory (com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory)18 Constraint (com.sri.ai.grinder.sgdpllt.api.Constraint)17 Map (java.util.Map)17 Beta (com.google.common.annotations.Beta)16 CompleteMultiVariableContext (com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext)16 Expressions.parse (com.sri.ai.expresso.helper.Expressions.parse)14 Theory (com.sri.ai.grinder.sgdpllt.api.Theory)14 LinearRealArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory)14 FunctionType (com.sri.ai.expresso.type.FunctionType)13 Util (com.sri.ai.util.Util)13 SingleVariableConstraint (com.sri.ai.grinder.sgdpllt.api.SingleVariableConstraint)12