Search in sources :

Example 86 with Type

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

Example 87 with Type

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;
}
Also used : BruteForceFunctionTheoryTestingSupport.getSmallCategoricalTestingType(com.sri.ai.grinder.sgdpllt.theory.function.BruteForceFunctionTheoryTestingSupport.getSmallCategoricalTestingType) Type(com.sri.ai.expresso.api.Type) TupleType(com.sri.ai.expresso.type.TupleType) Expression(com.sri.ai.expresso.api.Expression) ArrayList(java.util.ArrayList)

Example 88 with Type

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;
}
Also used : BruteForceFunctionTheoryTestingSupport.getSmallCategoricalTestingType(com.sri.ai.grinder.sgdpllt.theory.function.BruteForceFunctionTheoryTestingSupport.getSmallCategoricalTestingType) Type(com.sri.ai.expresso.api.Type) TupleType(com.sri.ai.expresso.type.TupleType) Expression(com.sri.ai.expresso.api.Expression) TupleType(com.sri.ai.expresso.type.TupleType)

Example 89 with Type

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;
}
Also used : EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) Type(com.sri.ai.expresso.api.Type) AbstractTheoryTestingSupport(com.sri.ai.grinder.sgdpllt.core.constraint.AbstractTheoryTestingSupport) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) Categorical(com.sri.ai.expresso.type.Categorical) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory)

Example 90 with Type

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

Aggregations

Type (com.sri.ai.expresso.api.Type)123 Expression (com.sri.ai.expresso.api.Expression)93 FunctionType (com.sri.ai.expresso.type.FunctionType)28 Test (org.junit.Test)25 Context (com.sri.ai.grinder.api.Context)24 LinkedHashMap (java.util.LinkedHashMap)22 Categorical (com.sri.ai.expresso.type.Categorical)21 Context (com.sri.ai.grinder.sgdpllt.api.Context)20 RealExpressoType (com.sri.ai.expresso.type.RealExpressoType)19 TupleType (com.sri.ai.expresso.type.TupleType)19 ArrayList (java.util.ArrayList)19 Map (java.util.Map)19 IndexExpressionsSet (com.sri.ai.expresso.api.IndexExpressionsSet)18 IntegerInterval (com.sri.ai.expresso.type.IntegerInterval)18 IntegerExpressoType (com.sri.ai.expresso.type.IntegerExpressoType)15 RealInterval (com.sri.ai.expresso.type.RealInterval)14 Beta (com.google.common.annotations.Beta)13 IntensionalSet (com.sri.ai.expresso.api.IntensionalSet)12 ExtensionalIndexExpressionsSet (com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet)12 List (java.util.List)12