Search in sources :

Example 6 with LinearRealArithmeticTheory

use of com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory in project aic-expresso by aic-sri-international.

the class ExpressionStepSolverToLiteralSplitterStepSolverAdapterTest method testLinearRealArithmeticTheoryWithRandomDisjunctiveFormulas.

@Ignore("Random generation of linear real arithmetic not yet implemented")
@Test
public void testLinearRealArithmeticTheoryWithRandomDisjunctiveFormulas() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new LinearRealArithmeticTheory(true, true));
    extendTestingVariables("X", theoryTestingSupport, "S", "T", "U", "V", "W");
    runRandomDisjunctiveFormulasTest(theoryTestingSupport);
}
Also used : TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with LinearRealArithmeticTheory

use of com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory in project aic-expresso by aic-sri-international.

the class SampleCommonInterpreterTest method setUp.

@Before
public void setUp() {
    // Make tests repeatable
    random = new Random(1);
    context = new TrueContext(new CompoundTheory(new DifferenceArithmeticTheory(false, false), new LinearRealArithmeticTheory(false, false), new EqualityTheory(false, false), new PropositionalTheory()));
}
Also used : EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) Random(java.util.Random) 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) TrueContext(com.sri.ai.grinder.core.TrueContext) Before(org.junit.Before)

Example 8 with LinearRealArithmeticTheory

use of com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory in project aic-expresso by aic-sri-international.

the class BoundsTest method declareTheoryContextAndSetOfFactors.

private void declareTheoryContextAndSetOfFactors() {
    /* That's how we create a empty bound
		 * It is useful for abstracting the kind of bound we are talking about:
		 * 		if you say to a program that one of his attributes is a bound, you can let the user choose
		 * 		between a extensional or intensional representation just by passing the right object as 
		 * 		argument.
		 * 
		 * 		Example:
		 * 		
		 * 		class foo{
		 * 			Bound b
		 * 			...
		 * 			public foo(Bound b, ...) {
		 *				this.b = b;
		 *				...
		 *			} 	 
		 * 		}
		 * 		
		 * 		Use:
		 * 		foo object = new foo(new DefaultExtensionalBound(),...);
		 * 		
		 * */
    ExpressoConfiguration.setDisplayNumericsExactlyForSymbols(true);
    extensionalBound = new DefaultExtensionalBound();
    intensionalBound = new DefaultIntensionalBound();
    theory = new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, false), new LinearRealArithmeticTheory(false, false), new TupleTheory(), new PropositionalTheory());
    context = new TrueContext(theory);
    context = context.extendWithSymbolsAndTypes("X", "Boolean");
    context = context.extendWithSymbolsAndTypes("Y", "Boolean");
    context = context.extendWithSymbolsAndTypes("A", "Boolean");
    context = context.extendWithSymbolsAndTypes("B", "Boolean");
    context = context.extendWithSymbolsAndTypes("C", "1..5");
    // context = context.extendWithSymbolsAndTypes("D","{1,3,4,8}");
    // Set of functions
    Expression phi1 = parse("if X = true then 1 else if Y = true then 2 else 3");
    Expression phi2 = parse("if A = true then if Y = true then 4 else 5 else 6");
    Expression phi3 = parse("if X = true then 7 else if B = true then 8 else 9");
    Expression phi4 = parse("if B = true then 10 else if A = true then 11 else 12");
    Expression phi5 = parse("if C < 4 then 10 else if C = 4 then 11 else 12");
    /*
		 * This is how we create a non empty extensional bound
		 */
    setOfFactors = new DefaultExtensionalBound(arrayList(phi1, phi2, phi3, phi4, phi5));
    // Set of numbers
    setOFNumbers = new DefaultExtensionalBound(arrayList(ONE, TWO));
    Set<Expression> Factor = new HashSet<Expression>();
    model = new Model(Factor);
    model.context = model.context.extendWithSymbolsAndTypes("A", "Boolean");
    model.context = model.context.extendWithSymbolsAndTypes("B", "Boolean");
    model.context = model.context.extendWithSymbolsAndTypes("Q", "Boolean");
    model.context = model.context.extendWithSymbolsAndTypes("C", "1..4");
    model.context = model.context.extendWithSymbolsAndTypes("D", "6..9");
    intensionalSetOfFactors1 = new DefaultIntensionalBound(arrayList(parse("A' in Boolean"), parse("C' in 1..5")), parse("if C = C' then if A = A' then 1 else 4 else 0"), TRUE);
    intensionalSetOfFactors2 = DefaultIntensionalBound.simplex(arrayList(parse("A")), model);
    intensionalSetOfFactors3 = DefaultIntensionalBound.simplex(arrayList(parse("C"), parse("B")), model);
}
Also used : EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) DefaultIntensionalBound(com.sri.ai.grinder.library.bounds.DefaultIntensionalBound) 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) Expression(com.sri.ai.expresso.api.Expression) DefaultExtensionalBound(com.sri.ai.grinder.library.bounds.DefaultExtensionalBound) Model(com.sri.ai.grinder.anytime.Model) HashSet(java.util.HashSet)

Example 9 with LinearRealArithmeticTheory

use of com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory in project aic-expresso by aic-sri-international.

the class UnificationStepSolverTest method linearRealArithmeticTest.

@Test
public void linearRealArithmeticTest() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(seededRandom, new LinearRealArithmeticTheory(true, true));
    // NOTE: passing explicit FunctionTypes will prevent the general variables' argument types being randomly changed.
    theoryTestingSupport.setVariableNamesAndTypesForTesting(map("X", TESTING_REAL_INTERVAL_TYPE, "Y", TESTING_REAL_INTERVAL_TYPE, "Z", TESTING_REAL_INTERVAL_TYPE, "unary_lra", new FunctionType(TESTING_REAL_INTERVAL_TYPE, TESTING_REAL_INTERVAL_TYPE), "binary_lra", new FunctionType(TESTING_REAL_INTERVAL_TYPE, TESTING_REAL_INTERVAL_TYPE, TESTING_REAL_INTERVAL_TYPE)));
    Context rootContext = theoryTestingSupport.makeContextWithTestingInformation();
    UnificationStepSolver unificationStepSolver = new UnificationStepSolver(parse("unary_lra(X)"), parse("unary_lra(X)"));
    StepSolver.Step<Boolean> step = unificationStepSolver.step(rootContext);
    Assert.assertEquals(false, step.itDepends());
    Assert.assertEquals(true, step.getValue());
    unificationStepSolver = new UnificationStepSolver(parse("unary_lra(X)"), parse("unary_lra(Y)"));
    step = unificationStepSolver.step(rootContext);
    Assert.assertEquals(true, step.itDepends());
    Assert.assertEquals(Expressions.parse("X = Y"), step.getSplitter());
    Assert.assertEquals(false, step.getStepSolverForWhenSplitterIsTrue().step(rootContext).itDepends());
    Assert.assertEquals(true, step.getStepSolverForWhenSplitterIsTrue().step(rootContext).getValue());
    Assert.assertEquals(false, step.getStepSolverForWhenSplitterIsFalse().step(rootContext).itDepends());
    Assert.assertEquals(false, step.getStepSolverForWhenSplitterIsFalse().step(rootContext).getValue());
    Context localTestContext = rootContext.conjoinWithConjunctiveClause(parse("X = 0 and Y = 1"), rootContext);
    step = unificationStepSolver.step(localTestContext);
    Assert.assertEquals(false, step.itDepends());
    Assert.assertEquals(false, step.getValue());
    unificationStepSolver = new UnificationStepSolver(parse("unary_lra(X)"), parse("unary_lra(0)"));
    localTestContext = rootContext.conjoinWithConjunctiveClause(parse("X = 0"), rootContext);
    step = unificationStepSolver.step(localTestContext);
    Assert.assertEquals(false, step.itDepends());
    Assert.assertEquals(true, step.getValue());
    localTestContext = rootContext.conjoinWithConjunctiveClause(parse("X = 1"), rootContext);
    step = unificationStepSolver.step(localTestContext);
    Assert.assertEquals(false, step.itDepends());
    Assert.assertEquals(false, step.getValue());
}
Also used : Context(com.sri.ai.grinder.api.Context) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) FunctionType(com.sri.ai.expresso.type.FunctionType) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) StepSolver(com.sri.ai.grinder.api.StepSolver) UnificationStepSolver(com.sri.ai.grinder.theory.base.UnificationStepSolver) UnificationStepSolver(com.sri.ai.grinder.theory.base.UnificationStepSolver) Test(org.junit.Test)

Example 10 with LinearRealArithmeticTheory

use of com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory in project aic-expresso by aic-sri-international.

the class UnificationStepSolverTest method advancedCompositeTest.

@Ignore("TODO - context implementation currently does not support these more advanced/indirect comparisons")
@Test
public void advancedCompositeTest() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(seededRandom, new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, true), new LinearRealArithmeticTheory(false, true), new PropositionalTheory()));
    // NOTE: passing explicit FunctionTypes will prevent the general variables' argument types being randomly changed.
    theoryTestingSupport.setVariableNamesAndTypesForTesting(map("P", BOOLEAN_TYPE, "Q", BOOLEAN_TYPE, "R", BOOLEAN_TYPE, "unary_prop/1", new FunctionType(BOOLEAN_TYPE, BOOLEAN_TYPE), "binary_prop/2", new FunctionType(BOOLEAN_TYPE, BOOLEAN_TYPE, BOOLEAN_TYPE), "S", TESTING_CATEGORICAL_TYPE, "T", TESTING_CATEGORICAL_TYPE, "U", TESTING_CATEGORICAL_TYPE, "unary_eq/1", new FunctionType(TESTING_CATEGORICAL_TYPE, TESTING_CATEGORICAL_TYPE), "binary_eq/2", new FunctionType(TESTING_CATEGORICAL_TYPE, TESTING_CATEGORICAL_TYPE, TESTING_CATEGORICAL_TYPE), "I", TESTING_INTEGER_INTERVAL_TYPE, "J", TESTING_INTEGER_INTERVAL_TYPE, "K", TESTING_INTEGER_INTERVAL_TYPE, "unary_dar/1", new FunctionType(TESTING_INTEGER_INTERVAL_TYPE, TESTING_INTEGER_INTERVAL_TYPE), "binary_dar/2", new FunctionType(TESTING_INTEGER_INTERVAL_TYPE, TESTING_INTEGER_INTERVAL_TYPE, TESTING_INTEGER_INTERVAL_TYPE), "X", TESTING_REAL_INTERVAL_TYPE, "Y", TESTING_REAL_INTERVAL_TYPE, "Z", TESTING_REAL_INTERVAL_TYPE, "unary_lra/1", new FunctionType(TESTING_REAL_INTERVAL_TYPE, TESTING_REAL_INTERVAL_TYPE), "binary_lra/2", new FunctionType(TESTING_REAL_INTERVAL_TYPE, TESTING_REAL_INTERVAL_TYPE, TESTING_REAL_INTERVAL_TYPE)));
    Context rootContext = theoryTestingSupport.makeContextWithTestingInformation();
    UnificationStepSolver unificationStepSolver = new UnificationStepSolver(parse("binary_prop(P, unary_prop(P))"), parse("binary_prop(unary_prop(Q), Q)"));
    Context localTestContext = rootContext.conjoinWithConjunctiveClause(parse("not P and Q and not unary_prop(Q) and unary_prop(P)"), rootContext);
    StepSolver.Step<Boolean> step = unificationStepSolver.step(localTestContext);
    Assert.assertEquals(false, step.itDepends());
    Assert.assertEquals(true, step.getValue());
    localTestContext = rootContext.conjoinWithConjunctiveClause(parse("P and Q and not unary_prop(Q) and unary_prop(P)"), rootContext);
    step = unificationStepSolver.step(localTestContext);
    Assert.assertEquals(false, step.itDepends());
    Assert.assertEquals(false, step.getValue());
}
Also used : Context(com.sri.ai.grinder.api.Context) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) FunctionType(com.sri.ai.expresso.type.FunctionType) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) StepSolver(com.sri.ai.grinder.api.StepSolver) UnificationStepSolver(com.sri.ai.grinder.theory.base.UnificationStepSolver) UnificationStepSolver(com.sri.ai.grinder.theory.base.UnificationStepSolver) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

LinearRealArithmeticTheory (com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory)21 Context (com.sri.ai.grinder.api.Context)13 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)13 CompoundTheory (com.sri.ai.grinder.theory.compound.CompoundTheory)12 EqualityTheory (com.sri.ai.grinder.theory.equality.EqualityTheory)12 PropositionalTheory (com.sri.ai.grinder.theory.propositional.PropositionalTheory)12 Expression (com.sri.ai.expresso.api.Expression)9 TrueContext (com.sri.ai.grinder.core.TrueContext)9 TheoryTestingSupport (com.sri.ai.grinder.tester.TheoryTestingSupport)9 Test (org.junit.Test)9 TupleTheory (com.sri.ai.grinder.theory.tuple.TupleTheory)8 FunctionType (com.sri.ai.expresso.type.FunctionType)5 Theory (com.sri.ai.grinder.api.Theory)5 StepSolver (com.sri.ai.grinder.api.StepSolver)4 UnificationStepSolver (com.sri.ai.grinder.theory.base.UnificationStepSolver)4 Random (java.util.Random)3 Ignore (org.junit.Ignore)3 IndexExpressionsSet (com.sri.ai.expresso.api.IndexExpressionsSet)2 Type (com.sri.ai.expresso.api.Type)2 ExtensionalIndexExpressionsSet (com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet)2