![JAR search and dependency download from the Maven repository](/logo.png)
com.sri.ai.grinder.sgdpllt.group.AbstractFunctionBasedGroup Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aic-expresso Show documentation
Show all versions of aic-expresso Show documentation
SRI International's AIC Symbolic Manipulation and Evaluation Library (for Java 1.8+)
The newest version!
package com.sri.ai.grinder.sgdpllt.group;
import static com.sri.ai.expresso.helper.Expressions.apply;
import static com.sri.ai.grinder.sgdpllt.library.indexexpression.IndexExpressions.makeIndexExpression;
import com.sri.ai.expresso.api.Expression;
import com.sri.ai.expresso.api.IndexExpressionsSet;
import com.sri.ai.expresso.api.IntensionalSet;
import com.sri.ai.expresso.core.DefaultIntensionalMultiSet;
import com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet;
import com.sri.ai.grinder.sgdpllt.api.Context;
import com.sri.ai.grinder.sgdpllt.api.QuantifierEliminationProblem;
import com.sri.ai.grinder.sgdpllt.library.controlflow.IfThenElse;
import com.sri.ai.util.Util;
import com.sri.ai.util.base.Pair;
/**
* A group whose related problems are represented as function applications on sets
* (e.g.: sum({{ (on X in Integer) X | X > 0 and X < 5 }})
).
*
* @author braz
*
*/
public abstract class AbstractFunctionBasedGroup extends AbstractNumericGroup implements AssociativeCommutativeGroup {
public AbstractFunctionBasedGroup() {
super();
}
public abstract String getFunctionString();
@Override
public Pair getExpressionAndIndexExpressionsFromProblemExpression(Expression expression, Context context) {
String functorString = getFunctionString();
Util.myAssert(() -> expression.hasFunctor(functorString), () -> "Expression expected to be application of " + functorString + " but is " + expression);
IntensionalSet set = (IntensionalSet) expression.get(0);
Expression body = IfThenElse.make(set.getCondition(), set.getHead(), additiveIdentityElement());
Pair result = Pair.make(body, set.getIndexExpressions());
return result;
}
@Override
public Expression makeProblemExpression(QuantifierEliminationProblem problem) {
Expression result = makeProblemExpression(problem.getIndex(), problem.getIndexType(), problem.getConstraint(), problem.getBody());
return result;
}
//@Override
public Expression makeProblemExpression(Expression index, Expression indexType, Expression constraint, Expression body) {
Expression indexExpression = makeIndexExpression(index, indexType);
IndexExpressionsSet indexExpressionsSet = new ExtensionalIndexExpressionsSet(indexExpression);
DefaultIntensionalMultiSet set = new DefaultIntensionalMultiSet(indexExpressionsSet, body, constraint);
Expression problem = apply(getFunctionString(), set);
return problem;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy