Search in sources :

Example 31 with IndexExpressionsSet

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

the class InversionPerformanceEvaluationTest method computeSize.

private Rational computeSize(Expression functionOnIntensionalSet, Rational resultSoFar, Context context) {
    IntensionalSet intensionalSet = (IntensionalSet) functionOnIntensionalSet.get(0);
    IndexExpressionsSet indexExpressionsSet = intensionalSet.getIndexExpressions();
    List<Expression> indices = IndexExpressions.getIndices(indexExpressionsSet);
    if (indices.size() != 1) {
        throw new UnsupportedOperationException("Currently only support singular indices");
    }
    Expression index = indices.get(0);
    Context intensionalSetContext = context.extendWith(indexExpressionsSet);
    Type type = GrinderUtil.getTypeOfExpression(index, intensionalSetContext);
    Rational result = resultSoFar.multiply(type.cardinality().rationalValue());
    Expression head = intensionalSet.getHead();
    if (Expressions.isFunctionApplicationWithArguments(head) && Sets.isIntensionalSet(head.get(0))) {
        result = computeSize(head, result, intensionalSetContext);
    }
    return result;
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) Type(com.sri.ai.expresso.api.Type) IntensionalSet(com.sri.ai.expresso.api.IntensionalSet) Rational(com.sri.ai.util.math.Rational) Expression(com.sri.ai.expresso.api.Expression) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet)

Example 32 with IndexExpressionsSet

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

the class GrinderUtil method getIndexExpressionsOfFreeVariablesIn.

/**
 * Returns a list of index expressions corresponding to the free variables in an expressions and their types per the registry, if any.
 */
public static IndexExpressionsSet getIndexExpressionsOfFreeVariablesIn(Expression expression, Registry registry) {
    Set<Expression> freeVariables = Expressions.freeVariables(expression, registry);
    IndexExpressionsSet result = getIndexExpressionsForIndicesInListAndTypesInRegistry(freeVariables, registry);
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) LambdaExpression(com.sri.ai.expresso.api.LambdaExpression) ExtensionalIndexExpressionsSet(com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet)

Example 33 with IndexExpressionsSet

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

the class MeasurableMultiQuantifierEliminationProblem method getIntensionalSet.

private static Expression getIntensionalSet(MultiQuantifierEliminationProblem problem) {
    IndexExpressionsSet indexExpressionsSet = new ExtensionalIndexExpressionsSet(IndexExpressions.makeIndexExpression(problem.getIndices().get(0), problem.getIndicesTypes().get(0)));
    Expression intensionalSet = intensionalMultiSet(indexExpressionsSet, problem.getIndices().get(0), problem.getConstraint());
    return intensionalSet;
}
Also used : ExtensionalIndexExpressionsSet(com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet) Expression(com.sri.ai.expresso.api.Expression) ExtensionalIndexExpressionsSet(com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet)

Example 34 with IndexExpressionsSet

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

the class AbstractQuantifierBasedGroup method getExpressionAndIndexExpressionsFromProblemExpression.

@Override
public Pair<Expression, IndexExpressionsSet> getExpressionAndIndexExpressionsFromProblemExpression(Expression expression, Context context) {
    QuantifiedExpressionWithABody quantifiedFormula = (QuantifiedExpressionWithABody) expression;
    Pair<Expression, IndexExpressionsSet> formulaAndIndices = Pair.make(quantifiedFormula.getBody(), quantifiedFormula.getIndexExpressions());
    return formulaAndIndices;
}
Also used : QuantifiedExpressionWithABody(com.sri.ai.expresso.api.QuantifiedExpressionWithABody) Expression(com.sri.ai.expresso.api.Expression) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet)

Example 35 with IndexExpressionsSet

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

the class TupleQuantifierSimplifier method rewriteIntensionalSet.

private static Expression rewriteIntensionalSet(IntensionalSet intensionalSet, Map<Expression, Expression> indexToTypeMap, Map<Expression, Expression> indexToTupleOfVars, Context context) {
    Expression headAndConditionPair = Expressions.makeTuple(intensionalSet.getHead(), intensionalSet.getCondition());
    Pair<IndexExpressionsSet, Expression> updatePair = update(headAndConditionPair, indexToTypeMap, indexToTupleOfVars, context);
    Expression updatedHead = updatePair.second.get(0);
    Expression updatedCondition = updatePair.second.get(1);
    Expression result;
    if (intensionalSet.isUniSet()) {
        result = IntensionalSet.intensionalUniSet(updatePair.first, updatedHead, updatedCondition);
    } else {
        result = IntensionalSet.intensionalMultiSet(updatePair.first, updatedHead, updatedCondition);
    }
    return result;
}
Also used : DefaultLambdaExpression(com.sri.ai.expresso.core.DefaultLambdaExpression) Expression(com.sri.ai.expresso.api.Expression) LambdaExpression(com.sri.ai.expresso.api.LambdaExpression) QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression) ExtensionalIndexExpressionsSet(com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet)

Aggregations

IndexExpressionsSet (com.sri.ai.expresso.api.IndexExpressionsSet)79 Expression (com.sri.ai.expresso.api.Expression)78 ExtensionalIndexExpressionsSet (com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet)49 IntensionalSet (com.sri.ai.expresso.api.IntensionalSet)24 LambdaExpression (com.sri.ai.expresso.api.LambdaExpression)23 ArrayList (java.util.ArrayList)20 DefaultLambdaExpression (com.sri.ai.expresso.core.DefaultLambdaExpression)17 Type (com.sri.ai.expresso.api.Type)15 QuantifiedExpression (com.sri.ai.expresso.api.QuantifiedExpression)14 Context (com.sri.ai.grinder.api.Context)13 IndexExpressions (com.sri.ai.grinder.library.indexexpression.IndexExpressions)9 Context (com.sri.ai.grinder.sgdpllt.api.Context)9 List (java.util.List)9 FunctionType (com.sri.ai.expresso.type.FunctionType)8 Util.mapIntoArrayList (com.sri.ai.util.Util.mapIntoArrayList)8 Rational (com.sri.ai.util.math.Rational)7 SyntaxTree (com.sri.ai.expresso.api.SyntaxTree)6 DefaultIntensionalMultiSet (com.sri.ai.expresso.core.DefaultIntensionalMultiSet)6 QuantifiedExpressionWithABody (com.sri.ai.expresso.api.QuantifiedExpressionWithABody)5 DefaultCountingFormula (com.sri.ai.expresso.core.DefaultCountingFormula)5