use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-expresso by aic-sri-international.
the class TupleQuantifierSimplifier method rewriteLambdaExpression.
private static Expression rewriteLambdaExpression(LambdaExpression lambdaExpression, Map<Expression, Expression> indexToTypeMap, Map<Expression, Expression> indexToTupleOfVars, Context context) {
Pair<IndexExpressionsSet, Expression> updatePair = update(lambdaExpression.getBody(), indexToTypeMap, indexToTupleOfVars, context);
Expression result = new DefaultLambdaExpression(updatePair.first, updatePair.second);
return result;
}
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;
}
use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-expresso by aic-sri-international.
the class Bounds method normalize.
/**
* Assumes that each element of the bound is a factor with the same domain
* Normalizes each factor of the bound. In latex notation:
* {\phi/sum_{var(\phi)}\phi : \phi in bound}
* @param bound
* @param theory
* @param context
* @return bound of normalized factors
*/
public static Expression normalize(Expression bound, Theory theory, Context context) {
List<Expression> listOfBound = ExtensionalSets.getElements(bound);
if (listOfBound.size() == 0) {
return null;
}
Expression phi = makeSymbol("phi");
Expression phi1 = listOfBound.get(0);
IndexExpressionsSet indices = getIndexExpressionsOfFreeVariablesIn(phi1, context);
Expression noCondition = makeSymbol(true);
Expression setOfFactorInstantiations = IntensionalSet.makeMultiSet(indices, //head
phi, noCondition);
Expression sumOnPhi = apply(SUM, setOfFactorInstantiations);
Expression f = apply("/", phi, sumOnPhi);
Expression result = applyFunctionToBound(f, phi, bound, theory, context);
return result;
}
use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-expresso by aic-sri-international.
the class IntersectionIntensionalSetsSimplifier method standardizeApartIntensionalSets.
@SuppressWarnings("deprecation")
public static IntensionalSet standardizeApartIntensionalSets(IntensionalSet intensionalSet, IntensionalSet fromOtherIntensionalSet, Context context) {
IntensionalSet result = intensionalSet;
IndexExpressionsSet intensionalSetIndexes = intensionalSet.getIndexExpressions();
IndexExpressionsSet fromOtherIntensionalSetIn = fromOtherIntensionalSet.getIndexExpressions();
List<Expression> overlappingIndexNames = new ArrayList<>();
for (Expression intensionalSetIndex : IndexExpressions.getIndices(intensionalSetIndexes)) {
if (IndexExpressions.indexExpressionsContainIndex(fromOtherIntensionalSetIn, intensionalSetIndex)) {
overlappingIndexNames.add(intensionalSetIndex);
}
}
if (overlappingIndexNames.size() > 0) {
Expression combinedExpression = And.make(intensionalSet, fromOtherIntensionalSet);
List<Expression> newIndexNames = new ArrayList<>();
for (Expression overlappingIndex : overlappingIndexNames) {
Expression newIndexName = Expressions.makeUniqueVariable(overlappingIndex.toString(), combinedExpression, context);
newIndexNames.add(newIndexName);
}
SyntaxTree resultSyntaxTree = result.getSyntaxTree();
for (int i = 0; i < newIndexNames.size(); i++) {
Expression replaced = overlappingIndexNames.get(i);
Expression replacement = newIndexNames.get(i);
resultSyntaxTree = resultSyntaxTree.replaceSubTreesAllOccurrences(replaced.getSyntaxTree(), replacement.getSyntaxTree());
}
result = (IntensionalSet) Expressions.makeFromSyntaxTree(resultSyntaxTree);
}
return result;
}
use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-expresso by aic-sri-international.
the class InversionSimplifier method isFunctionOnIntensionalSetWithSingleIndex.
private static boolean isFunctionOnIntensionalSetWithSingleIndex(Object functor, Expression expression) {
boolean result = false;
if (((functor == null && Expressions.isFunctionApplicationWithArguments(expression)) || expression.hasFunctor(functor)) && expression.numberOfArguments() == 1) {
Expression expressionArg1 = expression.get(0);
if (Sets.isIntensionalSet(expressionArg1)) {
IntensionalSet intensionalSet = (IntensionalSet) expressionArg1;
IndexExpressionsSet indexExpressionsSet = intensionalSet.getIndexExpressions();
List<Expression> indices = IndexExpressions.getIndices(indexExpressionsSet);
if (indices.size() == 1) {
result = true;
}
}
}
return result;
}
Aggregations