Search in sources :

Example 36 with Expression

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;
}
Also used : IntensionalSet(com.sri.ai.expresso.api.IntensionalSet) IndexExpressions.makeIndexExpression(com.sri.ai.grinder.sgdpllt.library.indexexpression.IndexExpressions.makeIndexExpression) Expression(com.sri.ai.expresso.api.Expression) ExtensionalIndexExpressionsSet(com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet)

Example 37 with Expression

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;
}
Also used : ExtensionalIndexExpressionsSet(com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet) IndexExpressions.makeIndexExpression(com.sri.ai.grinder.sgdpllt.library.indexexpression.IndexExpressions.makeIndexExpression) Expression(com.sri.ai.expresso.api.Expression) ExtensionalIndexExpressionsSet(com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet) DefaultIntensionalMultiSet(com.sri.ai.expresso.core.DefaultIntensionalMultiSet)

Example 38 with Expression

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

Example 39 with Expression

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

Example 40 with Expression

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

Aggregations

Expression (com.sri.ai.expresso.api.Expression)1392 Test (org.junit.Test)259 ArrayList (java.util.ArrayList)196 Context (com.sri.ai.grinder.api.Context)187 Type (com.sri.ai.expresso.api.Type)124 TrueContext (com.sri.ai.grinder.core.TrueContext)113 IndexExpressionsSet (com.sri.ai.expresso.api.IndexExpressionsSet)100 ExtensionalIndexExpressionsSet (com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet)91 QuantifiedExpression (com.sri.ai.expresso.api.QuantifiedExpression)90 Context (com.sri.ai.grinder.sgdpllt.api.Context)87 Theory (com.sri.ai.grinder.api.Theory)78 Map (java.util.Map)78 LambdaExpression (com.sri.ai.expresso.api.LambdaExpression)71 IntensionalSet (com.sri.ai.expresso.api.IntensionalSet)68 List (java.util.List)68 DefaultLambdaExpression (com.sri.ai.expresso.core.DefaultLambdaExpression)63 CommonTheory (com.sri.ai.grinder.application.CommonTheory)55 LinkedHashMap (java.util.LinkedHashMap)55 LinkedHashSet (java.util.LinkedHashSet)54 Pair (com.sri.ai.util.base.Pair)52