Search in sources :

Example 21 with Categorical

use of com.sri.ai.expresso.type.Categorical 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.makeNewContextWithAddedType(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.core.TrueContext) Context(com.sri.ai.grinder.api.Context) Type(com.sri.ai.expresso.api.Type) Categorical(com.sri.ai.expresso.type.Categorical) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 22 with Categorical

use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.

the class MeasureTest method testCategoricalTypeDomain.

@Test
public void testCategoricalTypeDomain() {
    updateContextWithIndexAndType("N", new Categorical("People", 5, parse("p1"), parse("p2"), parse("p3"), parse("p4"), parse("p5")));
    Assert.assertEquals(new Rational(5), measure("{{(on I in People) I : true}}"));
    Assert.assertEquals(new Rational(4), measure("{{(on I in People) I : I != p1}}"));
    Assert.assertEquals(new Rational(3), measure("{{(on I in People) I : I != p1 and I != p5}}"));
}
Also used : Rational(com.sri.ai.util.math.Rational) Categorical(com.sri.ai.expresso.type.Categorical) Test(org.junit.Test)

Example 23 with Categorical

use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.

the class CompoundTheoryWithDifferenceArithmeticTest method makeTheoryTestingSupport.

@Override
protected TheoryTestingSupport makeTheoryTestingSupport() {
    TheoryTestingSupport result = TheoryTestingSupport.make(makeRandom(), new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, true), new PropositionalTheory()));
    // using different testing variables and types to test distribution of testing information
    // to sub constraint theories.
    Categorical booleanType = BOOLEAN_TYPE;
    Categorical dogsType = new Categorical("Dogs", 4, arrayList(parse("fido"), parse("rex")));
    IntegerInterval oneTwoThree = new IntegerInterval(1, 3);
    Map<String, Type> variablesAndTypes = map("F", booleanType, "G", booleanType, "R", dogsType, "S", dogsType, "T", oneTwoThree, "U", oneTwoThree);
    result.setVariableNamesAndTypesForTesting(variablesAndTypes);
    return result;
}
Also used : EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) Type(com.sri.ai.expresso.api.Type) AbstractTheoryTestingSupport(com.sri.ai.grinder.core.constraint.AbstractTheoryTestingSupport) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) Categorical(com.sri.ai.expresso.type.Categorical) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory)

Example 24 with Categorical

use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.

the class CompoundTheoryWithoutDifferenceArithmeticTest method testCompleteSatisfiabilitySpecialCases.

@Test
public void testCompleteSatisfiabilitySpecialCases() {
    // This test is to make sure that some more tricky cases are indeed tested,
    // even though hopefully the large amount of generated random problems include them.
    // These are copied from the equality theory test,
    // so it is really just to check whether things hold up
    // if equality theory is embedded in a compound theory.
    String conjunction;
    Expression expected;
    Categorical someType = AbstractTheoryTestingSupport.getDefaultTestingType();
    // need W besides the other defaults -- somehow not doing this in equality theory alone does not cause a problem, probably because the type for W is never needed when we have only equality theory
    Map<String, Type> variableNamesAndTypesForTesting = map("X", someType, "Y", someType, "Z", someType, "W", someType);
    conjunction = "X != a and X != b and X != sometype5 and X != Z and X != W and Z = c and W = d";
    expected = FALSE;
    runCompleteSatisfiabilityTest(conjunction, expected, variableNamesAndTypesForTesting);
    conjunction = "X = Y and X != a and X != b and X != sometype5 and X != Z and X != W and Z = c and W = d";
    expected = FALSE;
    runCompleteSatisfiabilityTest(conjunction, expected, variableNamesAndTypesForTesting);
    conjunction = "X = a and X != b and X != sometype5 and X != Z and X != W and Z = c and W = d";
    expected = parse("(W = d) and (Z = c) and (X = a)");
    runCompleteSatisfiabilityTest(conjunction, expected, variableNamesAndTypesForTesting);
}
Also used : Type(com.sri.ai.expresso.api.Type) Expression(com.sri.ai.expresso.api.Expression) Categorical(com.sri.ai.expresso.type.Categorical) Test(org.junit.Test) AbstractTheoryTest(com.sri.ai.test.grinder.theory.base.AbstractTheoryTest)

Example 25 with Categorical

use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.

the class AbstractEqualityConstraintTest method testCompleteSatisfiabilitySpecialCases.

@Test
public void testCompleteSatisfiabilitySpecialCases() {
    // This test is to make sure that some more tricky cases are indeed tested,
    // even though hopefully the large amount of generated random problems include them or their variants.
    String conjunction;
    Expression expected;
    TheoryTestingSupport theoryTestingSupport = makeTheoryTestingSupport();
    Map<String, Type> variableNamesAndTypes = new HashMap<>(theoryTestingSupport.getVariableNamesAndTypesForTesting());
    variableNamesAndTypes.put("W", variableNamesAndTypes.get("X"));
    theoryTestingSupport.setVariableNamesAndTypesForTesting(variableNamesAndTypes);
    if (theoryTestingSupport.getTheory().singleVariableConstraintIsCompleteWithRespectToItsVariable()) {
        conjunction = "X != a and X != b and X != sometype5 and X != Z and X != W and Z = c and W = d";
        expected = null;
        runCompleteSatisfiabilityTest(conjunction, expected, theoryTestingSupport);
        conjunction = "X = Y and X != a and X != b and X != sometype5 and X != Z and X != W and Z = c and W = d";
        expected = null;
        runCompleteSatisfiabilityTest(conjunction, expected, theoryTestingSupport);
    }
    TheoryTestingSupport theoryTestingSupport2 = makeTheoryTestingSupport();
    Categorical type = new Categorical("Type", 1, arrayList(parse("a")));
    theoryTestingSupport2.setVariableNamesAndTypesForTesting(map("X", type, "Y", type, "Z", type, "W", type));
    conjunction = "X != Y";
    expected = null;
    runCompleteSatisfiabilityTest(conjunction, expected, theoryTestingSupport2);
    TheoryTestingSupport theoryTestingSupport3 = makeTheoryTestingSupport();
    type = new Categorical("Type", 2, arrayList(parse("a"), parse("b")));
    theoryTestingSupport3.setVariableNamesAndTypesForTesting(map("X", type, "Y", type, "Z", type, "W", type));
    conjunction = "X != Y and X != a";
    expected = parse("Y != b and X != a and X != Y");
    runCompleteSatisfiabilityTest(conjunction, expected, theoryTestingSupport3);
    conjunction = "X != a and X != b and X != c and X != sometype5 and X != Y";
    expected = parse("Y != d and X != a and X != b and X != c and X != sometype5 and X != Y and X != Y");
    runCompleteSatisfiabilityTest(conjunction, expected, theoryTestingSupport);
    conjunction = "X = a and X != b and X != sometype5 and X != Z and X != W and Z = c and W = d";
    expected = parse("(W = d) and (Z = c) and (X = a) and (X != Z) and (X != W)");
    runCompleteSatisfiabilityTest(conjunction, expected, theoryTestingSupport);
}
Also used : Type(com.sri.ai.expresso.api.Type) Expression(com.sri.ai.expresso.api.Expression) HashMap(java.util.HashMap) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) Categorical(com.sri.ai.expresso.type.Categorical) AbstractTheoryIncludingEqualityTest(com.sri.ai.test.grinder.theory.base.AbstractTheoryIncludingEqualityTest) Test(org.junit.Test)

Aggregations

Categorical (com.sri.ai.expresso.type.Categorical)39 Test (org.junit.Test)30 Type (com.sri.ai.expresso.api.Type)19 Expression (com.sri.ai.expresso.api.Expression)13 IntegerInterval (com.sri.ai.expresso.type.IntegerInterval)10 FunctionType (com.sri.ai.expresso.type.FunctionType)6 Expressions.makeSymbol (com.sri.ai.expresso.helper.Expressions.makeSymbol)5 RealInterval (com.sri.ai.expresso.type.RealInterval)5 TupleType (com.sri.ai.expresso.type.TupleType)5 Symbol (com.sri.ai.expresso.api.Symbol)4 IntegerExpressoType (com.sri.ai.expresso.type.IntegerExpressoType)4 RealExpressoType (com.sri.ai.expresso.type.RealExpressoType)4 Registry (com.sri.ai.grinder.api.Registry)4 Context (com.sri.ai.grinder.api.Context)3 DefaultRegistry (com.sri.ai.grinder.core.DefaultRegistry)3 TrueContext (com.sri.ai.grinder.core.TrueContext)3 Beta (com.google.common.annotations.Beta)2 LambdaExpression (com.sri.ai.expresso.api.LambdaExpression)2 Expressions.parse (com.sri.ai.expresso.helper.Expressions.parse)2 AssignmentMapsIterator (com.sri.ai.grinder.helper.AssignmentMapsIterator)2