Search in sources :

Example 66 with Type

use of com.sri.ai.expresso.api.Type in project aic-expresso by aic-sri-international.

the class AbstractTheoryTestingSupport method getTypesForTesting.

@Override
public Collection<Type> getTypesForTesting() {
    if (cachedTypesForTesting == null) {
        Set<Type> topTypesForTesting = new LinkedHashSet<>(getVariableNamesAndTypesForTesting().values());
        topTypesForTesting.addAll(getTheory().getNativeTypes());
        // Ensure we include embedded types (e.g. in a function or tuple type) as well
        Set<Type> embeddedTypes = new LinkedHashSet<>();
        for (Type topType : topTypesForTesting) {
            embeddedTypes.addAll(topType.getEmbeddedTypes());
        }
        topTypesForTesting.addAll(embeddedTypes);
        cachedTypesForTesting = Collections.unmodifiableCollection(topTypesForTesting);
    }
    return cachedTypesForTesting;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Type(com.sri.ai.expresso.api.Type)

Example 67 with Type

use of com.sri.ai.expresso.api.Type in project aic-expresso by aic-sri-international.

the class AbstractTheoryTestingSupport method extendWithTestingInformation.

@Override
public Context extendWithTestingInformation(Context context) {
    // we only need to provide the variables types, and not the known constant types, because the latter will be extracted from the already registered types.
    Map<String, String> mapFromSymbolNamesToTypeNames = new LinkedHashMap<String, String>();
    for (Map.Entry<String, Type> symbolAndType : getVariableNamesAndTypesForTesting().entrySet()) {
        mapFromSymbolNamesToTypeNames.put(symbolAndType.getKey(), symbolAndType.getValue().toString());
    }
    for (Map.Entry<String, Type> symbolAndType : getExtendedVariableNamesAndTypesForTesting().entrySet()) {
        mapFromSymbolNamesToTypeNames.put(symbolAndType.getKey(), symbolAndType.getValue().toString());
    }
    Context result = (Context) GrinderUtil.extendRegistryWith(mapFromSymbolNamesToTypeNames, getTypesForTesting(), context);
    return result;
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) Type(com.sri.ai.expresso.api.Type) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 68 with Type

use of com.sri.ai.expresso.api.Type in project aic-expresso by aic-sri-international.

the class CompoundTheoryTestingSupport method setVariableNamesAndTypesForTesting.

/**
	 * This is overridden so that given variables and types for testing are distributed to their
	 * respective theories according to {@link #isSuitableFor(Expression, Type)}.
	 */
@Override
public void setVariableNamesAndTypesForTesting(Map<String, Type> variableNamesAndTypesForTesting) {
    // First ensure the compound set of variables names and type information is setup correctly
    super.setVariableNamesAndTypesForTesting(variableNamesAndTypesForTesting);
    // Then update the sub-theories so that they share appropriate subsets of this information
    Map<Theory, Map<String, Type>> mapForSubTheory = map();
    for (Theory subTheory : getTheory().getSubTheories()) {
        mapForSubTheory.put(subTheory, map());
    }
    for (Map.Entry<String, Type> variableNameAndType : getVariableNamesAndTypesForTesting().entrySet()) {
        String variableName = variableNameAndType.getKey();
        Expression variable = Expressions.parse(variableName);
        Type type = variableNameAndType.getValue();
        for (Theory subTheory : getTheory().getSubTheories()) {
            if (subTheory.isSuitableFor(variable, type) || (type instanceof FunctionType && subTheory.isSuitableFor(variable, ((FunctionType) type).getCodomain()))) {
                mapForSubTheory.get(subTheory).put(variableName, type);
            }
        }
    }
    for (Map.Entry<Theory, TheoryTestingSupport> entry : getTheoryToTestingSupport().entrySet()) {
        Map<String, Type> forThisSubTheory = mapForSubTheory.get(entry.getKey());
        entry.getValue().setVariableNamesAndTypesForTesting(forThisSubTheory);
    }
}
Also used : Type(com.sri.ai.expresso.api.Type) FunctionType(com.sri.ai.expresso.type.FunctionType) Theory(com.sri.ai.grinder.sgdpllt.api.Theory) Expression(com.sri.ai.expresso.api.Expression) AbstractTheoryTestingSupport(com.sri.ai.grinder.sgdpllt.core.constraint.AbstractTheoryTestingSupport) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) FunctionType(com.sri.ai.expresso.type.FunctionType) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 69 with Type

use of com.sri.ai.expresso.api.Type in project aic-expresso by aic-sri-international.

the class CompoundTheoryTestingSupport method getTheoryTestingSupport.

private TheoryTestingSupport getTheoryTestingSupport(String variable) {
    Type variableType = getTestingVariableType(variable);
    Theory subConstraintTheory = getTheory().getTheory(parse(variable), variableType);
    check(() -> subConstraintTheory != null, () -> "There is no sub-theory suitable for " + variable + ", which has type " + variableType);
    TheoryTestingSupport result = getTheoryToTestingSupport().get(subConstraintTheory);
    return result;
}
Also used : Type(com.sri.ai.expresso.api.Type) FunctionType(com.sri.ai.expresso.type.FunctionType) Theory(com.sri.ai.grinder.sgdpllt.api.Theory) AbstractTheoryTestingSupport(com.sri.ai.grinder.sgdpllt.core.constraint.AbstractTheoryTestingSupport) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport)

Example 70 with Type

use of com.sri.ai.expresso.api.Type in project aic-expresso by aic-sri-international.

the class SGDPLLTTester method isSatisfiableByBruteForce.

/**
	 * Determines whether a formula is satisfiable by adding existential quantifiers for each of its variables
	 * (according to the theory provided) and evaluating it.
	 * @param formula
	 * @param theoryTestingSupport
	 * @param context
	 * @return whether the formula is satisfiable.
	 */
public static boolean isSatisfiableByBruteForce(Expression formula, TheoryTestingSupport theoryTestingSupport, Context context) {
    Map<String, Type> variableNamesAndTypesForTesting = theoryTestingSupport.getVariableNamesAndTypesForTesting();
    Expression quantifiedFormula = formula;
    Collection<Expression> variables = theoryTestingSupport.getTheory().getVariablesIn(formula, context);
    for (Expression variable : variables) {
        Expression typeNameExpression = parse(variableNamesAndTypesForTesting.get(variable).toString());
        quantifiedFormula = ThereExists.make(IndexExpressions.makeIndexExpression(variable, typeNameExpression), quantifiedFormula);
    }
    Expression evaluation = new BruteForceCommonInterpreter().apply(quantifiedFormula, context);
    boolean result = evaluation.equals(TRUE);
    return result;
}
Also used : BruteForceCommonInterpreter(com.sri.ai.grinder.sgdpllt.interpreter.BruteForceCommonInterpreter) Type(com.sri.ai.expresso.api.Type) Expression(com.sri.ai.expresso.api.Expression) QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression)

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