use of com.sri.ai.expresso.api.Type in project aic-expresso by aic-sri-international.
the class BruteForceFunctionTheoryTestingSupport method makeRandomAtomOn.
@Override
public Expression makeRandomAtomOn(String mainVariable, Context context) {
Expression result;
Type mainType = getTestingVariableType(mainVariable);
FunctionType mainFunctionType = ensureFunctionType(mainType);
Expression mainFunctionApplication = makeFunctionApplication(mainVariable, mainFunctionType);
// it as the atom.
if (mainFunctionType.getCodomain().equals(BOOLEAN_TYPE)) {
result = mainFunctionApplication;
} else {
// If it is of some other type, pick another (or the same) function
// with the same co-domain.
String otherVariable = pickTestingVariableAtRandom(mainFunctionType.getCodomain(), variableName -> true);
// Generate another function application
Type otherType = getTestingVariableType(otherVariable);
FunctionType otherFunctionType = ensureFunctionType(otherType);
Expression otherFunctionApplication = makeFunctionApplication(otherVariable, otherFunctionType);
// With it, form an equality or an inequality
if (getRandom().nextBoolean()) {
result = Equality.make(mainFunctionApplication, otherFunctionApplication);
} else {
result = Disequality.make(mainFunctionApplication, otherFunctionApplication);
}
}
return result;
}
use of com.sri.ai.expresso.api.Type in project aic-expresso by aic-sri-international.
the class TupleTheoryTestingSupport method makeTuple.
protected Expression makeTuple(TupleType tupleType) {
// Generate elements for the tuple
List<Expression> elements = new ArrayList<>();
for (Type elementType : tupleType.getElementTypes()) {
// If constants supported, use at random
if (elementType.isSampleUniquelyNamedConstantSupported() && getRandom().nextBoolean()) {
elements.add(elementType.sampleUniquelyNamedConstant(getRandom()));
} else {
String elementVariable = pickTestingVariableAtRandom(getElementVariableNamesAndTypesForTesting(), elementType, variableName -> true);
elements.add(parse(elementVariable));
}
}
Expression result = Expressions.makeTuple(elements.toArray(new Expression[elements.size()]));
return result;
}
use of com.sri.ai.expresso.api.Type in project aic-expresso by aic-sri-international.
the class TupleTheoryTestingSupport method makeRandomAtomOn.
@Override
public Expression makeRandomAtomOn(String mainVariable, Context context) {
Expression result;
// Construct an instance of the main tuple
Expression mainTuple;
Type mainType = getTestingVariableType(mainVariable);
if (mainType instanceof TupleType) {
mainTuple = makeSymbol(mainVariable);
} else {
TupleType mainTupleType = ensureTupleType(mainType);
mainTuple = makeTuple(mainTupleType);
}
// Pick another (or the same) variable having a compatible tuple type
String otherVariable = pickTestingVariableAtRandom(mainType, variableName -> true);
// Construct an instance of the other tuple
Type otherType = getTestingVariableType(otherVariable);
TupleType otherTupleType = ensureTupleType(otherType);
Expression otherTuple = makeTuple(otherTupleType);
// With it, form an equality or an inequality
if (getRandom().nextBoolean()) {
result = Equality.make(mainTuple, otherTuple);
} else {
result = Disequality.make(mainTuple, otherTuple);
}
return result;
}
use of com.sri.ai.expresso.api.Type 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.api.Type in project aic-expresso by aic-sri-international.
the class CompoundTheoryWithDifferenceArithmeticTest 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);
}
Aggregations