use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class AbstractFunctionBasedGroup method getExpressionAndIndexExpressionsFromProblemExpression.
@Override
public Pair<Expression, IndexExpressionsSet> 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<Expression, IndexExpressionsSet> result = Pair.make(body, set.getIndexExpressions());
return result;
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class AbstractFunctionBasedGroup method makeProblemExpression.
@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;
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class AbstractNumericGroup method addNTimes.
@Override
public Expression addNTimes(Expression valueToBeAdded, Expression n, Context context) {
Expression result;
if (n.equals(ZERO)) {
result = additiveIdentityElement();
} else if (IfThenElse.isIfThenElse(n)) {
// it is important that this condition is tested before the next, because n can be conditional on splitters while valueToBeSummed can be conditioned on conditions in the unconditional solution language (such as | Everything | - 1 > 0), and we want splitters to be over non-splitter conditions
Expression condition = IfThenElse.condition(n);
Expression thenBranch = IfThenElse.thenBranch(n);
Expression elseBranch = IfThenElse.elseBranch(n);
Expression newThenBranch = addNTimes(valueToBeAdded, thenBranch, context);
Expression newElseBranch = addNTimes(valueToBeAdded, elseBranch, context);
// do not simplify to condition so it is a DPLL solution
result = IfThenElse.make(condition, newThenBranch, newElseBranch, false);
} else if (IfThenElse.isIfThenElse(valueToBeAdded)) {
Expression condition = IfThenElse.condition(valueToBeAdded);
Expression thenBranch = IfThenElse.thenBranch(valueToBeAdded);
Expression elseBranch = IfThenElse.elseBranch(valueToBeAdded);
Expression newThenBranch = addNTimes(thenBranch, n, context);
Expression newElseBranch = addNTimes(elseBranch, n, context);
result = IfThenElse.make(condition, newThenBranch, newElseBranch);
} else {
result = addNTimesWithUnconditionalValueAndNDistinctFromZero(valueToBeAdded, n);
}
return result;
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class AbstractQuantifierBasedGroup method makeProblemExpression.
@Override
public Expression makeProblemExpression(Expression index, Expression indexType, Expression constraint, Expression body) {
Expression indexExpression = IndexExpressions.makeIndexExpression(index, indexType);
Expression bodyEncodingConstraint = IfThenElse.make(constraint, body, additiveIdentityElement());
Expression result = makeQuantifiedExpression(indexExpression, bodyEncodingConstraint);
return result;
}
use of com.sri.ai.expresso.api.Expression in project aic-expresso by aic-sri-international.
the class AbstractQuantifierBasedGroup method getExpressionAndIndexExpressionsFromProblemExpression.
@Override
public Pair<Expression, IndexExpressionsSet> getExpressionAndIndexExpressionsFromProblemExpression(Expression expression, Context context) {
QuantifiedExpressionWithABody quantifiedFormula = (QuantifiedExpressionWithABody) expression;
Pair<Expression, IndexExpressionsSet> formulaAndIndices = Pair.make(quantifiedFormula.getBody(), quantifiedFormula.getIndexExpressions());
return formulaAndIndices;
}
Aggregations