Search in sources :

Example 6 with IndexExpressionsSet

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;
}
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) DefaultLambdaExpression(com.sri.ai.expresso.core.DefaultLambdaExpression) ExtensionalIndexExpressionsSet(com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet)

Example 7 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)

Example 8 with IndexExpressionsSet

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;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) ExtensionalIndexExpressionsSet(com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet)

Example 9 with IndexExpressionsSet

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;
}
Also used : IntensionalSet(com.sri.ai.expresso.api.IntensionalSet) SyntaxTree(com.sri.ai.expresso.api.SyntaxTree) Expression(com.sri.ai.expresso.api.Expression) ArrayList(java.util.ArrayList) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet)

Example 10 with IndexExpressionsSet

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;
}
Also used : IntensionalSet(com.sri.ai.expresso.api.IntensionalSet) Expression(com.sri.ai.expresso.api.Expression) 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