use of com.sri.ai.util.base.NullaryFunction in project aic-expresso by aic-sri-international.
the class AssignmentsIterator method makeMapFromVariablesToIteratorMakersFrom.
private static Map<Expression, NullaryFunction<Iterator<Expression>>> makeMapFromVariablesToIteratorMakersFrom(IndexExpressionsSet indexExpressionsSet, Registry registry) {
Map<Expression, NullaryFunction<Iterator<Expression>>> fromVariableToIteratorMaker = map();
ExtensionalIndexExpressionsSet extensionalIndexExpressionsSet;
try {
extensionalIndexExpressionsSet = (ExtensionalIndexExpressionsSet) indexExpressionsSet;
} catch (ClassCastException e) {
throw new Error("AssignmentsIterator defined for extensional index expressions sets only.");
}
for (Expression indexExpression : extensionalIndexExpressionsSet.getList()) {
Expression variable = IndexExpressions.getIndex(indexExpression);
Expression typeDescription = IndexExpressions.getType(indexExpression);
if (typeDescription == null) {
typeDescription = GrinderUtil.getTypeExpression(variable, registry);
}
putVariableAndIteratorMakerIn(fromVariableToIteratorMaker, variable, typeDescription, registry);
}
return fromVariableToIteratorMaker;
}
use of com.sri.ai.util.base.NullaryFunction in project aic-expresso by aic-sri-international.
the class Bounds method boundProduct.
/**
* Computes the product of each term of a list of bounds
* @param theory
* @param context
* @param listOfBounds
* @return bound resulting from the product of bounds
*/
public static Expression boundProduct(Theory theory, Context context, Expression... listOfBounds) {
ArrayList<NullaryFunction<Iterator<Expression>>> iteratorForBoundList = mapIntoArrayList(listOfBounds, bound -> () -> getElements(bound).iterator());
Iterator<ArrayList<Expression>> cartesianProduct = new CartesianProductIterator<Expression>(iteratorForBoundList);
ArrayList<Expression> resultList = new ArrayList<>();
for (ArrayList<Expression> element : in(cartesianProduct)) {
Expression product = apply("*", element);
Expression evaluation = theory.evaluate(product, context);
resultList.add(evaluation);
}
Expression result = new DefaultExtensionalUniSet(resultList);
// Updating extreme points
result = updateExtremes(result, theory, context);
return result;
}
use of com.sri.ai.util.base.NullaryFunction in project aic-expresso by aic-sri-international.
the class AssignmentMapsIterator method makeMapFromVariablesToIteratorMakers.
private static Map<Expression, NullaryFunction<Iterator<Expression>>> makeMapFromVariablesToIteratorMakers(Collection<Expression> variables, Registry registry) {
Map<Expression, NullaryFunction<Iterator<Expression>>> fromVariableToIteratorMaker = map();
for (Expression variable : variables) {
Expression typeDescription = GrinderUtil.getTypeExpressionOfExpression(variable, registry);
putVariableAndIteratorMakerIn(fromVariableToIteratorMaker, variable, typeDescription, registry);
}
return fromVariableToIteratorMaker;
}
use of com.sri.ai.util.base.NullaryFunction in project aic-expresso by aic-sri-international.
the class AssignmentMapsIterator method makeMapFromVariablesToIteratorMakers.
private static Map<Expression, NullaryFunction<Iterator<Expression>>> makeMapFromVariablesToIteratorMakers(Collection<? extends Expression> variables, Registry registry) {
Map<Expression, NullaryFunction<Iterator<Expression>>> fromVariableToIteratorMaker = map();
for (Expression variable : variables) {
Expression typeDescription = GrinderUtil.getTypeExpressionOfExpression(variable, registry);
putVariableAndIteratorMakerIn(fromVariableToIteratorMaker, variable, typeDescription, registry);
}
return fromVariableToIteratorMaker;
}
use of com.sri.ai.util.base.NullaryFunction in project aic-expresso by aic-sri-international.
the class AssignmentMapsIterator method makeMapFromVariablesToIteratorMakersFrom.
private static Map<Expression, NullaryFunction<Iterator<Expression>>> makeMapFromVariablesToIteratorMakersFrom(IndexExpressionsSet indexExpressionsSet, Registry registry) {
Map<Expression, NullaryFunction<Iterator<Expression>>> fromVariableToIteratorMaker = map();
ExtensionalIndexExpressionsSet extensionalIndexExpressionsSet;
try {
extensionalIndexExpressionsSet = (ExtensionalIndexExpressionsSet) indexExpressionsSet;
} catch (ClassCastException e) {
throw new Error("AssignmentsIterator defined for extensional index expressions sets only.");
}
for (Expression indexExpression : extensionalIndexExpressionsSet.getList()) {
Expression variable = IndexExpressions.getIndex(indexExpression);
Expression typeDescription = IndexExpressions.getType(indexExpression);
if (typeDescription == null) {
typeDescription = GrinderUtil.getTypeExpressionOfExpression(variable, registry);
}
putVariableAndIteratorMakerIn(fromVariableToIteratorMaker, variable, typeDescription, registry);
}
return fromVariableToIteratorMaker;
}
Aggregations