Search in sources :

Example 11 with Categorical

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;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) Categorical(com.sri.ai.expresso.type.Categorical)

Example 12 with Categorical

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;
}
Also used : IntegerExpressoType(com.sri.ai.expresso.type.IntegerExpressoType) TupleType(com.sri.ai.expresso.type.TupleType) Type(com.sri.ai.expresso.api.Type) RealExpressoType(com.sri.ai.expresso.type.RealExpressoType) FunctionType(com.sri.ai.expresso.type.FunctionType) Expression(com.sri.ai.expresso.api.Expression) LambdaExpression(com.sri.ai.expresso.api.LambdaExpression) Categorical(com.sri.ai.expresso.type.Categorical) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 13 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) AbstractTheoryTest(com.sri.ai.test.grinder.sgdpllt.theory.base.AbstractTheoryTest) Test(org.junit.Test)

Example 14 with Categorical

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;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) Categorical(com.sri.ai.expresso.type.Categorical)

Example 15 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.sgdpllt.tester.TheoryTestingSupport) Categorical(com.sri.ai.expresso.type.Categorical) Test(org.junit.Test) AbstractTheoryIncludingEqualityTest(com.sri.ai.test.grinder.sgdpllt.theory.base.AbstractTheoryIncludingEqualityTest)

Aggregations

Categorical (com.sri.ai.expresso.type.Categorical)25 Test (org.junit.Test)19 Type (com.sri.ai.expresso.api.Type)12 Expression (com.sri.ai.expresso.api.Expression)8 IntegerInterval (com.sri.ai.expresso.type.IntegerInterval)8 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.sgdpllt.api.Context)4 AssignmentsIterator (com.sri.ai.grinder.helper.AssignmentsIterator)3 DefaultRegistry (com.sri.ai.grinder.sgdpllt.core.DefaultRegistry)3 TrueContext (com.sri.ai.grinder.sgdpllt.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