use of com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet in project aic-expresso by aic-sri-international.
the class Sets method expandApplicationOfAssociativeCommutativeFunctionToIntensionalSetWithMultipleIndexExpressionsFrom.
private static Expression expandApplicationOfAssociativeCommutativeFunctionToIntensionalSetWithMultipleIndexExpressionsFrom(int i, Expression functor, IntensionalSet intensionalSet, ExtensionalIndexExpressionsSet indexExpressions) {
Expression result;
int numberOfIndexExpressions = indexExpressions.getList().size();
if (i == numberOfIndexExpressions - 1) {
Expression iThIndexExpression = indexExpressions.getList().get(i);
ExtensionalIndexExpressionsSet indexExpressionsSetWithIthIndexExpressionOnly = new ExtensionalIndexExpressionsSet(iThIndexExpression);
result = apply(functor, intensionalSet.setIndexExpressions(indexExpressionsSetWithIthIndexExpressionOnly));
} else {
Expression iThIndexExpression = indexExpressions.getList().get(i);
ExtensionalIndexExpressionsSet indexExpressionsSetWithIthIndexExpressionOnly = new ExtensionalIndexExpressionsSet(iThIndexExpression);
Expression innerHead = expandApplicationOfAssociativeCommutativeFunctionToIntensionalSetWithMultipleIndexExpressionsFrom(i + 1, functor, intensionalSet, indexExpressions);
IntensionalSet innerSet = intensionalSet.setHeadAndCondition(innerHead, TRUE);
innerSet = innerSet.setIndexExpressions(indexExpressionsSetWithIthIndexExpressionOnly);
result = apply(functor, innerSet);
}
return result;
}
use of com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet in project aic-expresso by aic-sri-international.
the class Sets method expandApplicationOfAssociativeCommutativeFunction.
/**
* Transforms an application of a associative commutative function to an intensional set with one or more indices
* to an equivalent expression in which intensional sets have a single index each.
* An example is <code>sum( {{ (on X in 1..10, Y in 1..10) 3 | X != Y }} )</code>
* being transformed to <code>sum( {{ (on X in 1..10) sum({{ (on Y in 1..10) 3 | X != Y }}) | true }} )</code>
* @param functionApplicationOnIntensionalSet
* @return
*/
public static Expression expandApplicationOfAssociativeCommutativeFunction(Expression functionApplicationOnIntensionalSet) {
IntensionalSet intensionalSet = (IntensionalSet) functionApplicationOnIntensionalSet.get(0);
ExtensionalIndexExpressionsSet indexExpressions = (ExtensionalIndexExpressionsSet) intensionalSet.getIndexExpressions();
myAssert(() -> indexExpressions.getList().size() != 0, () -> "There must be at least one index expression");
Expression result;
if (indexExpressions.getList().size() == 1) {
result = functionApplicationOnIntensionalSet;
} else {
Expression functor = functionApplicationOnIntensionalSet.getFunctor();
result = expandApplicationOfAssociativeCommutativeFunctionToIntensionalSetWithMultipleIndexExpressionsFrom(0, functor, intensionalSet, indexExpressions);
}
return result;
}
use of com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet in project aic-expresso by aic-sri-international.
the class MultiIndexQuantifierEliminator method solve.
default default Expression solve(AssociativeCommutativeGroup group, ExtensionalIndexExpressionsSet indexExpressions, Expression indicesCondition, Expression body, Context context) {
Triple<Context, ExtensionalIndexExpressionsSet, Expression> extension = context.extendWith(indexExpressions, tuple(indicesCondition, body));
context = extension.first;
indexExpressions = extension.second;
indicesCondition = extension.third.get(0);
body = extension.third.get(1);
// context = context.extendWith(indexExpressions);
List<Expression> indices = IndexExpressions.getIndices(indexExpressions);
Expression quantifierFreeExpression = solve(group, indices, indicesCondition, body, context);
return quantifierFreeExpression;
}
use of com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet in project aic-expresso by aic-sri-international.
the class Bounds method isExtremePoint.
/**
* Checks if \phi is a convex combination of the elements in bound
* @param phi
* factor
* @param bound
* @return
*/
public static boolean isExtremePoint(Expression phi, int indexPhi, Expression bound, Theory theory, Context context) {
//TODO
//caro pq recopia a lista toda
Expression boundWithoutPhi = removeNonDestructively(bound, indexPhi);
List<Expression> listOfB = getElements(boundWithoutPhi);
int n = listOfB.size();
Expression[] c = new Expression[n];
for (int i = 0; i < n; i++) {
c[i] = makeSymbol("c" + i);
context = context.extendWithSymbolsAndTypes("c" + i, "Real");
}
// 0<=ci<=1
ArrayList<Expression> listOfC = new ArrayList<>(listOfB.size());
for (int i = 0; i < n; i++) {
Expression cibetwen0And1 = apply(AND, apply(GREATER_THAN_OR_EQUAL_TO, 1, c[i]), apply(GREATER_THAN_OR_EQUAL_TO, c[i], 0));
listOfC.add(cibetwen0And1);
}
Expression allcibetwen0And1 = apply(AND, listOfC);
//sum over ci =1
listOfC = new ArrayList<>(Arrays.asList(c));
Expression sumOverCiEqualsOne = apply(EQUAL, 1, apply(PLUS, listOfC));
//sum of ci*phi1 = phi
ArrayList<Expression> prodciphii = new ArrayList<>(listOfB.size());
int i = 0;
for (Expression phii : listOfB) {
prodciphii.add(apply(TIMES, phii, c[i]));
i++;
}
Expression convexSum = apply(EQUAL, phi, apply(PLUS, prodciphii));
ArrayList<Expression> listOfCiInReal = new ArrayList<>(listOfB.size());
for (i = 0; i < n; i++) {
listOfCiInReal.add(apply(IN, c[i], "Real"));
}
IndexExpressionsSet thereExistsCiInReal = new ExtensionalIndexExpressionsSet(listOfCiInReal);
Expression body = apply(AND, allcibetwen0And1, sumOverCiEqualsOne, convexSum);
Expression isExtreme = new DefaultExistentiallyQuantifiedFormula(thereExistsCiInReal, body);
if (debug)
println(isExtreme);
//Expression result = theory.evaluate(isExtreme, context);
return true;
}
use of com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet in project aic-expresso by aic-sri-international.
the class IndexExpressions method makeExtensionalIndexExpressionsSetFromSymbolsAndTypesStrings.
public static ExtensionalIndexExpressionsSet makeExtensionalIndexExpressionsSetFromSymbolsAndTypesStrings(String... symbolsAndTypes) {
Expression[] symbolsAndTypesExpressions = GrinderUtil.makeListOfSymbolsAndTypesExpressionsFromSymbolsAndTypesStrings(symbolsAndTypes);
List<Expression> indexExpressions = GrinderUtil.makeIndexExpressionsFromSymbolsAndTypes(symbolsAndTypesExpressions);
ExtensionalIndexExpressionsSet result = new ExtensionalIndexExpressionsSet(indexExpressions);
return result;
}
Aggregations