Search in sources :

Example 1 with ExtensionalSet

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

the class AbstractExtensionalSet method setElementDefinition.

@Override
public Expression setElementDefinition(int i, Expression newIthElement) {
    ExtensionalSet result;
    if (get(i) == newIthElement) {
        result = this;
    } else {
        ArrayList<Expression> newElements = new ArrayList<Expression>(elementsDefinitions);
        newElements.set(i, newIthElement);
        result = make(newElements);
    }
    return result;
}
Also used : AbstractNonQuantifiedExpression(com.sri.ai.grinder.core.AbstractNonQuantifiedExpression) Expression(com.sri.ai.expresso.api.Expression) ArrayList(java.util.ArrayList) ExtensionalSet(com.sri.ai.expresso.api.ExtensionalSet)

Example 2 with ExtensionalSet

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

the class Bounds method applyFunctionToBound.

/*public static Expression boundProduct(Theory theory, Context context, Expression...listOfBounds){
		if(listOfBounds.length == 0){ 
			return null;
		}
		
		Expression result= boundProduct (0, theory, context, listOfBounds);
		return result;
	}

	private static Expression boundProduct(int i,  Theory theory, Context context, Expression...listOfBounds){
		if(listOfBounds.length - 1 == i){
			return listOfBounds[i];
		}
		
		Expression productOfOthers = boundProduct(i + 1, theory, context, listOfBounds);
		Expression b = listOfBounds[i];

		List<Expression> listOfb = ExtensionalSet.getElements(b);
		List<Expression> listOfProductOfOthers = ExtensionalSet.getElements(productOfOthers);
		
		ArrayList<Expression> elements = new ArrayList<>(listOfb.size()*listOfProductOfOthers.size());
		
		for (Expression phi1 : listOfb){
			for (Expression phi2 : listOfProductOfOthers){
				Expression product = apply("*",phi1,phi2);
				Expression evaluation = theory.evaluate(product,context);
				elements.add(evaluation);
			}
		}
		
		DefaultExtensionalUniSet productBound = new DefaultExtensionalUniSet(elements);
		//Updating extreme points
		Expression result = updateExtremes(productBound,theory,context);
		return result;
	}*/
/**
	 * apply a function (f) to each term of a bound (b) 
	 * @param f 
	 * 			function to be applied to the factors
	 * @param variableName
	 * 			The variable in f to be replaced by phi (for each phi in b). 
	 * 			If if is a function of the variable v, VariableName is v
	 * @param b
	 * 			Bound
	 * @param theory
	 * @param context
	 * @return {f(\phi) : \phi \in b}
	 */
public static Expression applyFunctionToBound(Expression f, Expression variableName, Expression b, Theory theory, Context context) {
    ExtensionalSet bAsExtensionalSet = (ExtensionalSet) b;
    int numberOfExtremes = bAsExtensionalSet.getArguments().size();
    ArrayList<Expression> elements = new ArrayList<>(numberOfExtremes);
    for (Expression phi : ExtensionalSets.getElements(bAsExtensionalSet)) {
        Expression substitution = f.replaceAllOccurrences(variableName, phi, context);
        //debuging
        if (debug)
            println("evaluating: " + substitution);
        // problem in evaluation method...
        Expression evaluation = theory.evaluate(substitution, context);
        //debuging
        if (debug)
            println("result: " + evaluation);
        elements.add(evaluation);
    }
    DefaultExtensionalUniSet fOfb = new DefaultExtensionalUniSet(elements);
    //Updating extreme points
    Expression result = updateExtremes(fOfb, 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) ExtensionalSet(com.sri.ai.expresso.api.ExtensionalSet) DefaultExtensionalUniSet(com.sri.ai.expresso.core.DefaultExtensionalUniSet)

Example 3 with ExtensionalSet

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

the class DefaultExtensionalBound method applyFunctionToBound.

protected DefaultExtensionalBound applyFunctionToBound(Expression f, Expression variableName, Bound bound, Theory theory, Context context) {
    ExtensionalSet bAsExtensionalSet = (ExtensionalSet) bound;
    int numberOfExtremes = bAsExtensionalSet.getArguments().size();
    ArrayList<Expression> elements = new ArrayList<>(numberOfExtremes);
    for (Expression phi : ExtensionalSets.getElements(bAsExtensionalSet)) {
        Expression substitution = f.replaceAllOccurrences(variableName, phi, context);
        if (debug)
            println("evaluating: " + substitution);
        Expression evaluation = theory.evaluate(substitution, context);
        if (debug)
            println("result: " + evaluation);
        elements.add(evaluation);
    }
    DefaultExtensionalBound fOfb = new DefaultExtensionalBound(elements);
    // Updating extreme points
    DefaultExtensionalBound result = updateExtremes(fOfb, 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) ExtensionalSet(com.sri.ai.expresso.api.ExtensionalSet)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)3 ExtensionalSet (com.sri.ai.expresso.api.ExtensionalSet)3 ArrayList (java.util.ArrayList)3 Util.mapIntoArrayList (com.sri.ai.util.Util.mapIntoArrayList)2 DefaultExtensionalUniSet (com.sri.ai.expresso.core.DefaultExtensionalUniSet)1 AbstractNonQuantifiedExpression (com.sri.ai.grinder.core.AbstractNonQuantifiedExpression)1