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));
}
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}}"));
}
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;
}
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);
}
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);
}
Aggregations