Search in sources :

Example 16 with TrueContext

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

the class LambdaBetaReductionSimplifierTest method testNoReduction.

@Test
public void testNoReduction() {
    Type peopleType = new Categorical("People", 4, arrayList(makeSymbol("ann"), makeSymbol("bob"), makeSymbol("tom")));
    Context context = new TrueContext();
    context = context.add(peopleType);
    Assert.assertEquals(parse("(lambda X in People : if X = ann then 0 else if X = bob then 0 else 0)()"), simplifier.apply(parse("(lambda X in People : if X = ann then 0 else if X = bob then 0 else 0)()"), context));
    Assert.assertEquals(parse("(lambda X in People, Y in People : if X = ann then 0 else if Y = bob then 0 else 0)(ann)"), simplifier.apply(parse("(lambda X in People, Y in People : if X = ann then 0 else if Y = bob then 0 else 0)(ann)"), context));
    Assert.assertEquals(parse("(lambda X in People, Y in People : if X = ann then 0 else if Y = bob then 0 else 0)(ann, bob, tom)"), simplifier.apply(parse("(lambda X in People, Y in People : if X = ann then 0 else if Y = bob then 0 else 0)(ann, bob, tom)"), context));
}
Also used : TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) Context(com.sri.ai.grinder.sgdpllt.api.Context) Type(com.sri.ai.expresso.api.Type) Categorical(com.sri.ai.expresso.type.Categorical) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) Test(org.junit.Test)

Example 17 with TrueContext

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

the class AbstractSingleVariableNumericConstraintFeasibilityRegionStepSolver method applyAndSimplifyWithoutConsideringContextualConstraint.

/**
	 * A method for simplifying an expression according to the context's theory, types and global objects,
	 * but <i>without</i> considering the contextual constraint,
	 * for the purpose of computing information about the step solver that is constant across contexts
	 * (that share the same basic information).
	 * Note that the context is still an argument, for the sake of providing the basic information,
	 * but the contextual constraint is ignored.
	 * @param comparison
	 * @param arguments
	 * @param context
	 * @return
	 */
protected Expression applyAndSimplifyWithoutConsideringContextualConstraint(String comparison, ArrayList<Expression> arguments, Context context) {
    Expression unsimplifiedAtom = apply(comparison, arguments);
    TrueContext typeContext = new TrueContext(context);
    Expression result = constraint.getTheory().simplify(unsimplifiedAtom, typeContext);
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext)

Example 18 with TrueContext

use of com.sri.ai.grinder.sgdpllt.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 : Context(com.sri.ai.grinder.sgdpllt.api.Context) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) CompleteMultiVariableContext(com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext) Expression(com.sri.ai.expresso.api.Expression) Constraint(com.sri.ai.grinder.sgdpllt.api.Constraint) AbstractTheoryTestingSupport(com.sri.ai.grinder.sgdpllt.core.constraint.AbstractTheoryTestingSupport) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) AbstractTheoryTest(com.sri.ai.test.grinder.sgdpllt.theory.base.AbstractTheoryTest) Test(org.junit.Test)

Example 19 with TrueContext

use of com.sri.ai.grinder.sgdpllt.core.TrueContext 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.sgdpllt.theory.equality.EqualityTheory) Random(java.util.Random) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) LinearRealArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) Before(org.junit.Before)

Example 20 with TrueContext

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

the class BoundTest method testNormalize.

@Test
public void testNormalize() {
    Theory theory = new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, false), new LinearRealArithmeticTheory(false, false), new TupleTheory(), new PropositionalTheory());
    Context context = new TrueContext(theory);
    context = context.extendWithSymbolsAndTypes("X", "Boolean");
    context = context.extendWithSymbolsAndTypes("Y", "Boolean");
    //Set of numbers
    Expression one = DefaultSymbol.createSymbol(1);
    Expression two = DefaultSymbol.createSymbol(2);
    Expression three = DefaultSymbol.createSymbol(3);
    Expression setOFNumbers = ExtensionalSets.makeUniSet(one, two, three);
    //Set of functions
    Expression phi1 = parse("if X = true then 1 else if Y = true then 2 else 3");
    Expression phi2 = parse("if X = true then if Y = true then 4 else 5 else 6");
    Expression phi3 = parse("if X = true then 7 else if Y = true then 8 else 9");
    Expression phi4 = parse("if X = true then 10 else if Y = true then 11 else 12");
    Expression setOfFactors = ExtensionalSets.makeUniSet(phi1, phi2, phi3, phi4);
    assertEquals(parse("{if X then 1/7 else if Y then 2/7 else 3/7," + " if X then if Y then 4/21 else 5/21 else 2/7, " + "if X then 7/31 else if Y then 8/31 else 9/31, " + "if X then 10/43 else if Y then 11/43 else 12/43 }"), Bounds.normalize(setOfFactors, theory, context));
    assertEquals(parse("{ 1, 1, 1 }"), Bounds.normalize(setOFNumbers, theory, context));
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) LinearRealArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory) Theory(com.sri.ai.grinder.sgdpllt.api.Theory) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) TupleTheory(com.sri.ai.grinder.sgdpllt.theory.tuple.TupleTheory) Expression(com.sri.ai.expresso.api.Expression) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) LinearRealArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory) TupleTheory(com.sri.ai.grinder.sgdpllt.theory.tuple.TupleTheory) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) Test(org.junit.Test)

Aggregations

TrueContext (com.sri.ai.grinder.sgdpllt.core.TrueContext)31 CompoundTheory (com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory)22 DifferenceArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory)22 Expression (com.sri.ai.expresso.api.Expression)18 Context (com.sri.ai.grinder.sgdpllt.api.Context)16 TupleTheory (com.sri.ai.grinder.sgdpllt.theory.tuple.TupleTheory)16 PropositionalTheory (com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory)12 IntegerInterval (com.sri.ai.expresso.type.IntegerInterval)11 Before (org.junit.Before)11 Test (org.junit.Test)9 EqualityTheory (com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory)8 LinearRealArithmeticTheory (com.sri.ai.grinder.sgdpllt.theory.linearrealarithmetic.LinearRealArithmeticTheory)6 Theory (com.sri.ai.grinder.sgdpllt.api.Theory)5 Rewriter (com.sri.ai.grinder.sgdpllt.rewriter.api.Rewriter)4 Categorical (com.sri.ai.expresso.type.Categorical)3 Type (com.sri.ai.expresso.api.Type)2 Constraint (com.sri.ai.grinder.sgdpllt.api.Constraint)2 AbstractTheoryTestingSupport (com.sri.ai.grinder.sgdpllt.core.constraint.AbstractTheoryTestingSupport)2 CompleteMultiVariableContext (com.sri.ai.grinder.sgdpllt.core.constraint.CompleteMultiVariableContext)2 Beta (com.google.common.annotations.Beta)1