use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class BruteForceFunctionTheoryTestingSupport method getSmallCategoricalTestingType.
public static Categorical getSmallCategoricalTestingType() {
if (_someType == null) {
ArrayList<Expression> knownConstants = mapIntoArrayList(list("a", "b", "c"), s -> makeSymbol(s));
_someType = new Categorical("SmallSomeType", 3, knownConstants);
}
return _someType;
}
use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.
the class GrinderUtil method getCategoricalTypes.
/**
* @param mapFromSymbolNameToTypeName
* @param mapFromCategoricalTypeNameToSizeString
* @param isUniquelyNamedConstantPredicate
* @param registry
* @return
*/
public static Collection<Type> getCategoricalTypes(Map<String, String> mapFromSymbolNameToTypeName, Map<String, String> mapFromCategoricalTypeNameToSizeString, Predicate<Expression> isUniquelyNamedConstantPredicate, Registry registry) {
Collection<Type> categoricalTypes = new LinkedList<Type>();
for (Map.Entry<String, String> typeNameAndSizeString : mapFromCategoricalTypeNameToSizeString.entrySet()) {
String typeExpressionString = typeNameAndSizeString.getKey();
String sizeString = typeNameAndSizeString.getValue();
// check if already present and, if not, make it
Categorical type = (Categorical) registry.getType(typeExpressionString);
if (type == null) {
if (typeExpressionString.equals("Boolean")) {
type = BOOLEAN_TYPE;
} else {
ArrayList<Expression> knownConstants = getKnownUniquelyNamedConstantsOf(typeExpressionString, mapFromSymbolNameToTypeName, isUniquelyNamedConstantPredicate, registry);
type = new Categorical(typeExpressionString, parseInt(sizeString), knownConstants);
}
}
categoricalTypes.add(type);
}
return categoricalTypes;
}
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 AbstractTheoryTestingSupport method getDefaultTestingType.
/**
* Returns the type used for the default testing variables.
* @return
*/
public static Categorical getDefaultTestingType() {
if (_someType == null) {
ArrayList<Expression> knownConstants = mapIntoArrayList(list("a", "b", "c", "d"), s -> makeSymbol(s));
_someType = new Categorical("SomeType", 5, knownConstants);
}
return _someType;
}
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