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