Search in sources :

Example 76 with IndexExpressionsSet

use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-expresso by aic-sri-international.

the class DefaultExtensionalBound method summingBound.

private DefaultExtensionalBound summingBound(Expression variablesToBeSummedOut, Bound bound, Context context, Theory theory) {
    List<Expression> listOfBound = getElements(bound);
    ArrayList<Expression> BoundSummedOut = new ArrayList<>(listOfBound.size());
    for (Expression phi : listOfBound) {
        IndexExpressionsSet indices = getIndexExpressionsOfFreeVariablesIn(variablesToBeSummedOut, context);
        Expression setOfFactorInstantiations = IntensionalSet.makeMultiSet(indices, // head
        phi, // No Condition
        makeSymbol(true));
        Expression sumOnPhi = apply(SUM, setOfFactorInstantiations);
        Expression evaluation = theory.evaluate(sumOnPhi, context);
        BoundSummedOut.add(evaluation);
    }
    DefaultExtensionalBound SetOfBoundSummedOut = new DefaultExtensionalBound(BoundSummedOut);
    // Updating extreme points
    DefaultExtensionalBound result = updateExtremes(SetOfBoundSummedOut, theory, context);
    // result = normalize(result, theory, context);
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) Util.mapIntoArrayList(com.sri.ai.util.Util.mapIntoArrayList) ArrayList(java.util.ArrayList) ExtensionalIndexExpressionsSet(com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet)

Example 77 with IndexExpressionsSet

use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-expresso by aic-sri-international.

the class Bounds method normalizeSingleExpression.

/**
 * Does not work for sets or bounds. Aims at normalizing a sing expression phi
 * @param phi
 * @param theory
 * @param context
 * @return
 */
public static Expression normalizeSingleExpression(Expression phi, Theory theory, Context context) {
    IndexExpressionsSet indices = getIndexExpressionsOfFreeVariablesIn(phi, context);
    Expression setOfFactorInstantiations = IntensionalSet.makeMultiSet(indices, // head
    phi, // No Condition
    makeSymbol(true));
    Expression sumOnPhi = apply(SUM, setOfFactorInstantiations);
    Expression f = apply("/", phi, sumOnPhi);
    Expression evaluation = theory.evaluate(f, context);
    return evaluation;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet)

Example 78 with IndexExpressionsSet

use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-expresso by aic-sri-international.

the class DefaultIntensionalBound method applyFunctionToBound.

protected DefaultIntensionalBound applyFunctionToBound(Expression f, Expression variableName, Bound bound, Theory theory, Context context) {
    if (!bound.isIntensionalBound()) {
        return null;
    }
    IntensionalSet intensionalBound = (IntensionalSet) bound;
    IndexExpressionsSet indexExpressions = intensionalBound.getIndexExpressions();
    Expression Head = intensionalBound.getHead();
    Expression condition = intensionalBound.getCondition();
    Expression fOfHead = f.replaceAllOccurrences(variableName, Head, context);
    Expression evaluation = theory.evaluate(fOfHead, context);
    DefaultIntensionalBound result = new DefaultIntensionalBound(indexExpressions, evaluation, condition);
    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)

Example 79 with IndexExpressionsSet

use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-praise by aic-sri-international.

the class HOGMModelValidator method getQuantifiedExpressionScope.

public Map<Expression, HOGMConstantDeclaration> getQuantifiedExpressionScope(Expression quantifiedExpression) {
    Map<Expression, HOGMConstantDeclaration> result = new LinkedHashMap<>();
    IndexExpressionsSet indexExpressionSet = ((QuantifiedExpression) quantifiedExpression).getIndexExpressions();
    IndexExpressions.getIndexToTypeMapWithDefaultNull(indexExpressionSet).forEach((name, type) -> {
        HOGMSortDeclaration localSort = getSort(type);
        if (localSort != null) {
            result.put(name, new HOGMConstantDeclaration(name, Expressions.ZERO, localSort.getName()));
        }
    });
    return result;
}
Also used : QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression) Expression(com.sri.ai.expresso.api.Expression) QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression) HOGMConstantDeclaration(com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMConstantDeclaration) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet) HOGMSortDeclaration(com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMSortDeclaration) LinkedHashMap(java.util.LinkedHashMap)

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