Search in sources :

Example 16 with TrueContext

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

the class IntersectionIntensionalSetsSimplifierTest method setUp.

@Before
public void setUp() {
    context = new TrueContext(new CompoundTheory(new DifferenceArithmeticTheory(false, false), new TupleTheory()));
    IntegerInterval nType = new IntegerInterval(1, 10);
    context = (Context) GrinderUtil.extendRegistryWith(map("N", nType.toString()), Arrays.asList(nType), context);
    simplifier = new IntersectionIntensionalSetsSimplifier();
}
Also used : DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) IntersectionIntensionalSetsSimplifier(com.sri.ai.grinder.library.set.invsupport.IntersectionIntensionalSetsSimplifier) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) TupleTheory(com.sri.ai.grinder.theory.tuple.TupleTheory) Before(org.junit.Before)

Example 17 with TrueContext

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

the class ExhaustiveTest method runTest.

private void runTest(Rewriter rewriter, Expression initial, Expression expected, Map<Expression, Expression> symbolsAndTypes) {
    CompoundTheory theory = new CompoundTheory(new PropositionalTheory(), new DifferenceArithmeticTheory(false, true));
    Context context = new TrueContext(theory);
    context = context.makeCloneWithAdditionalRegisteredSymbolsAndTypes(symbolsAndTypes);
    Rewriter exhaustive = new Exhaustive(rewriter);
    Expression solution = exhaustive.apply(initial, context);
    System.out.println("Solution: " + solution);
    assertEquals(expected, solution);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) Expression(com.sri.ai.expresso.api.Expression) Exhaustive(com.sri.ai.grinder.rewriter.core.Exhaustive) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) Rewriter(com.sri.ai.grinder.rewriter.api.Rewriter) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.core.TrueContext)

Example 18 with TrueContext

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

the class BasicTest method debug.

public void debug(Expression problem, Expression expectedSolution) {
    CompoundTheory theory = new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, false), new LinearRealArithmeticTheory(false, false), new TupleTheory(), new PropositionalTheory(), new BruteForceFunctionTheory());
    Context context = new TrueContext(theory);
    context = context.makeNewContextWithAddedType(BOOLEAN_TYPE);
    context = context.makeCloneWithAdditionalRegisteredSymbolsAndTypes(map(makeSymbol("P"), makeSymbol("Boolean")));
    Expression symbolicSolution = theory.evaluate(problem, context);
    println(symbolicSolution);
    Assert.assertEquals(expectedSolution, symbolicSolution);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) BruteForceFunctionTheory(com.sri.ai.grinder.theory.function.BruteForceFunctionTheory) Expression(com.sri.ai.expresso.api.Expression) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TupleTheory(com.sri.ai.grinder.theory.tuple.TupleTheory) TrueContext(com.sri.ai.grinder.core.TrueContext)

Example 19 with TrueContext

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

the class CompoundTheoryWithoutDifferenceArithmeticTest method basicTests.

@Test
public void basicTests() {
    TheoryTestingSupport theoryTestingSupport = makeTheoryTestingSupport();
    Expression condition = parse("X = Y and Y = X and P and not Q and P and X = a and X != b");
    Context context = theoryTestingSupport.extendWithTestingInformation(new TrueContext(theoryTestingSupport.getTheory()));
    Constraint constraint = new CompleteMultiVariableContext(theoryTestingSupport.getTheory(), context);
    constraint = constraint.conjoin(condition, context);
    Expression expected = parse("(Y = a) and not Q and P and (X = Y)");
    assertEquals(expected, constraint);
}
Also used : CompleteMultiVariableContext(com.sri.ai.grinder.core.constraint.CompleteMultiVariableContext) TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CompleteMultiVariableContext(com.sri.ai.grinder.core.constraint.CompleteMultiVariableContext) Expression(com.sri.ai.expresso.api.Expression) Constraint(com.sri.ai.grinder.api.Constraint) AbstractTheoryTestingSupport(com.sri.ai.grinder.core.constraint.AbstractTheoryTestingSupport) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test) AbstractTheoryTest(com.sri.ai.test.grinder.theory.base.AbstractTheoryTest)

Example 20 with TrueContext

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

the class BasicTest method isLiteralTests.

@Test
public void isLiteralTests() {
    Expression expression;
    boolean expected;
    Context context = new TrueContext();
    context = context.makeCloneWithAdditionalRegisteredSymbolsAndTypes(map(parse("X"), parse("Integer"), parse("Y"), parse("Integer"), parse("Z"), parse("Integer"), parse("W"), parse("Real")));
    // Difference arithmetic literals include up to two integer variables with coefficient
    // -1 or +1 (each no more than once) and an optional numeric constant.
    expression = parse("1 >= 0");
    expected = true;
    runIsLiteralTest(expression, expected, context);
    expression = parse("X >= 0");
    expected = true;
    runIsLiteralTest(expression, expected, context);
    expression = parse("-X >= 0");
    expected = true;
    runIsLiteralTest(expression, expected, context);
    expression = parse("X - Y >= 0");
    expected = true;
    runIsLiteralTest(expression, expected, context);
    expression = parse("X + Y >= 0");
    expected = false;
    runIsLiteralTest(expression, expected, context);
    expression = parse("X - Y + 3 >= 0");
    expected = true;
    runIsLiteralTest(expression, expected, context);
    expression = parse("X - Y + 3 + Z >= Z");
    expected = true;
    runIsLiteralTest(expression, expected, context);
    expression = parse("X - X + X - Y + Y - Z + 1 - 5 >= 0");
    expected = true;
    runIsLiteralTest(expression, expected, context);
    // Final variables coefficients must be 1 or -1
    expression = parse("X >= -X");
    expected = false;
    runIsLiteralTest(expression, expected, context);
    expression = parse("X - Y >= -X");
    expected = false;
    runIsLiteralTest(expression, expected, context);
    expression = parse("X + Y >= -X");
    expected = false;
    runIsLiteralTest(expression, expected, context);
    expression = parse("X - Y + 3 >= -X");
    expected = false;
    runIsLiteralTest(expression, expected, context);
    expression = parse("X - Y + 3 + Z >= Z - X");
    expected = false;
    runIsLiteralTest(expression, expected, context);
    expression = parse("X - X + X - Y + Y - Z + 1 - 5 >= -X");
    expected = false;
    runIsLiteralTest(expression, expected, context);
    // Final variables coefficients must be 1 or -1
    // Coefficients may be present in the initial expression
    expression = parse("X*2 >= 0");
    expected = false;
    runIsLiteralTest(expression, expected, context);
    expression = parse("2*X - Y >= 0");
    expected = false;
    runIsLiteralTest(expression, expected, context);
    expression = parse("2*X - Y - X >= 0");
    expected = true;
    runIsLiteralTest(expression, expected, context);
    expression = parse("2*X - Y >= X");
    expected = true;
    runIsLiteralTest(expression, expected, context);
    expression = parse("X + Y >= 2*Y");
    expected = true;
    runIsLiteralTest(expression, expected, context);
    expression = parse("3*X - Y + 3 >= X");
    expected = false;
    runIsLiteralTest(expression, expected, context);
    expression = parse("X - Y + 3 + 2*Z >= 2*Z");
    expected = true;
    runIsLiteralTest(expression, expected, context);
    expression = parse("2*X - 2*X + X - 2*Y + 2*Y - 2*Z + 1 - 5 >= -Z");
    expected = true;
    runIsLiteralTest(expression, expected, context);
    // Variables must be integer
    expression = parse("2*X - 2*X + X - 2*W + 2*W - 2*Z + 1 - 5 >= -Z");
    expected = true;
    runIsLiteralTest(expression, expected, context);
    expression = parse("W - X >= 0");
    expected = false;
    runIsLiteralTest(expression, expected, context);
    // Sides should be polynomials
    expression = parse("f()*2 > 0");
    expected = false;
    runIsLiteralTest(expression, expected, context);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) Expression(com.sri.ai.expresso.api.Expression) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Aggregations

TrueContext (com.sri.ai.grinder.core.TrueContext)39 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)28 CompoundTheory (com.sri.ai.grinder.theory.compound.CompoundTheory)25 Context (com.sri.ai.grinder.api.Context)24 Expression (com.sri.ai.expresso.api.Expression)20 TupleTheory (com.sri.ai.grinder.theory.tuple.TupleTheory)18 PropositionalTheory (com.sri.ai.grinder.theory.propositional.PropositionalTheory)15 Before (org.junit.Before)12 EqualityTheory (com.sri.ai.grinder.theory.equality.EqualityTheory)11 IntegerInterval (com.sri.ai.expresso.type.IntegerInterval)10 Test (org.junit.Test)10 LinearRealArithmeticTheory (com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory)9 Theory (com.sri.ai.grinder.api.Theory)6 Rewriter (com.sri.ai.grinder.rewriter.api.Rewriter)6 Type (com.sri.ai.expresso.api.Type)3 ExtensionalIndexExpressionsSet (com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet)3 CombiningTopRewriter (com.sri.ai.grinder.rewriter.core.CombiningTopRewriter)3 Exhaustive (com.sri.ai.grinder.rewriter.core.Exhaustive)3 Recursive (com.sri.ai.grinder.rewriter.core.Recursive)3 Random (java.util.Random)3