Search in sources :

Example 26 with IntensionalSet

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

the class IntensionalUnionIntersectionEqualToEmptySetSimplifier method intensionalSetToForAllAndPhi.

private static Expression[] intensionalSetToForAllAndPhi(IntensionalSet intensionalSet, List<Expression> forAllsSoFar, Context context) {
    IntensionalSet saIntensionalSet = standardizeApart(intensionalSet, forAllsSoFar, context);
    Expression forAll = ForAll.make(saIntensionalSet.getIndexExpressions(), saIntensionalSet.getCondition());
    Expression phi = saIntensionalSet.getHead();
    Expression[] result = new Expression[] { forAll, phi };
    return result;
}
Also used : IntensionalSet(com.sri.ai.expresso.api.IntensionalSet) Expression(com.sri.ai.expresso.api.Expression)

Example 27 with IntensionalSet

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

the class IntensionalUnionIntersectionEqualToEmptySetSimplifier method standardizeApart.

private static IntensionalSet standardizeApart(IntensionalSet intensionalSet, List<Expression> forAllsSoFar, Context context) {
    IntensionalSet result = intensionalSet;
    if (forAllsSoFar.size() > 0) {
        // May need to standardize apart
        List<Expression> tupleArgs = new ArrayList<>();
        for (Expression forAll : forAllsSoFar) {
            tupleArgs.add(ForAll.getIndexExpression(forAll));
            tupleArgs.add(ForAll.getBody(forAll));
        }
        Expression tupleOfForAlls = Expressions.makeTuple(tupleArgs);
        List<Expression> originalIndexes = IndexExpressions.getIndices(intensionalSet.getIndexExpressions());
        List<Expression> saIndexes = new ArrayList<>();
        for (Expression index : originalIndexes) {
            Expression saIndex = Expressions.primedUntilUnique(index, tupleOfForAlls, context);
            saIndexes.add(saIndex);
        }
        if (!originalIndexes.equals(saIndexes)) {
            // We need to update intensional set with standardized apart indices
            IndexExpressionsSet saIndexExpressionsSet = intensionalSet.getIndexExpressions();
            Expression saHead = intensionalSet.getHead();
            Expression saCondition = intensionalSet.getCondition();
            Context intensionalSetContext = context.extendWith(saIndexExpressionsSet);
            for (int i = 0; i < originalIndexes.size(); i++) {
                Expression originalIndex = originalIndexes.get(i);
                Expression saIndex = saIndexes.get(i);
                if (!originalIndex.equals(saIndex)) {
                    saIndexExpressionsSet = saIndexExpressionsSet.replaceSymbol(originalIndex, saIndex, context);
                    saHead = saHead.replaceAllOccurrences(originalIndex, saIndex, intensionalSetContext);
                    saCondition = saCondition.replaceAllOccurrences(originalIndex, saIndex, intensionalSetContext);
                }
            }
            result = (IntensionalSet) IntensionalSet.intensionalSetOfSameKindAs(intensionalSet, saIndexExpressionsSet, saHead, saCondition);
        }
    }
    return result;
}
Also used : Context(com.sri.ai.grinder.sgdpllt.api.Context) IntensionalSet(com.sri.ai.expresso.api.IntensionalSet) Expression(com.sri.ai.expresso.api.Expression) ArrayList(java.util.ArrayList) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet)

Example 28 with IntensionalSet

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

the class IntensionalUnionToUnionsOfIntensionalSetsOfBaseTypeSimplifier method simplify.

public static Expression simplify(Expression expression, Context context) {
    Expression result = expression;
    if (Sets.isIntensionalUnion(expression)) {
        IntensionalSet intensionalMultiSet = (IntensionalSet) expression.get(0);
        Expression intensionalHead = intensionalMultiSet.getHead();
        // TODO - base case set is an extensional uniset?			
        if (Sets.isExtensionalSet(intensionalHead) && intensionalHead.numberOfArguments() == 1) {
            Expression baseTypeHead = intensionalHead.get(0);
            result = IntensionalSet.intensionalMultiSet(intensionalMultiSet.getIndexExpressions(), baseTypeHead, intensionalMultiSet.getCondition());
        } else // Determine if recursive case
        if (intensionalHead.hasFunctor(FunctorConstants.UNION)) {
            // Union( {{ (on I)   Set1 union ... union Set_m : C }} )
            // --->
            // recurse(Union( {{ (on I) Set1 : C }} )) 
            //         union ... union 
            // recurse(Union( {{ (on I) Set_m : C }} ))
            List<Expression> recursedUnionArgs = new ArrayList<>();
            for (Expression setI : intensionalHead.getArguments()) {
                Expression setIUnionArg = IntensionalSet.intensionalMultiSet(intensionalMultiSet.getIndexExpressions(), setI, intensionalMultiSet.getCondition());
                Expression setIUnion = Expressions.apply(FunctorConstants.INTENSIONAL_UNION, setIUnionArg);
                Expression setIRecurseResult = simplify(setIUnion, context);
                recursedUnionArgs.add(setIRecurseResult);
            }
            result = Sets.makeUnion(recursedUnionArgs.toArray(new Expression[recursedUnionArgs.size()]));
        }
    }
    return result;
}
Also used : IntensionalSet(com.sri.ai.expresso.api.IntensionalSet) Expression(com.sri.ai.expresso.api.Expression) List(java.util.List) ArrayList(java.util.ArrayList)

Example 29 with IntensionalSet

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

the class ElementOfIntensionalUnionSimplifier method simplify.

public static Expression simplify(Expression expression, Context context) {
    Expression result = expression;
    if (Expressions.hasFunctor(expression, FunctorConstants.IN) && expression.numberOfArguments() == 2) {
        Expression t = expression.get(0);
        Expression set = expression.get(1);
        if (Sets.isIntensionalUnion(set)) {
            IntensionalSet intensionalSet = (IntensionalSet) set.get(0);
            Expression tElementOfPhi = Expressions.apply(FunctorConstants.IN, t, intensionalSet.getHead());
            Expression existsBody = And.make(intensionalSet.getCondition(), tElementOfPhi);
            result = ThereExists.make(intensionalSet.getIndexExpressions(), existsBody);
        }
    }
    return result;
}
Also used : IntensionalSet(com.sri.ai.expresso.api.IntensionalSet) Expression(com.sri.ai.expresso.api.Expression)

Example 30 with IntensionalSet

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

the class IntensionalSetToConditionalSimplifier method simplify.

public static Expression simplify(Expression expression, Context context) {
    Expression result = expression;
    if (Sets.isIntensionalSet(expression)) {
        IntensionalSet intensionalSet = (IntensionalSet) expression;
        Expression thereExistsCondition = ThereExists.make(intensionalSet.getIndexExpressions(), intensionalSet.getCondition());
        Expression condition = context.getTheory().evaluate(thereExistsCondition, context);
        Expression thenBranch = expression;
        Expression elseBranch = Sets.EMPTY_SET;
        result = IfThenElse.make(condition, thenBranch, elseBranch, true);
    }
    return result;
}
Also used : IntensionalSet(com.sri.ai.expresso.api.IntensionalSet) Expression(com.sri.ai.expresso.api.Expression)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)46 IntensionalSet (com.sri.ai.expresso.api.IntensionalSet)46 IndexExpressionsSet (com.sri.ai.expresso.api.IndexExpressionsSet)24 ExtensionalIndexExpressionsSet (com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet)15 ArrayList (java.util.ArrayList)12 Type (com.sri.ai.expresso.api.Type)11 Context (com.sri.ai.grinder.api.Context)9 Context (com.sri.ai.grinder.sgdpllt.api.Context)9 RealExpressoType (com.sri.ai.expresso.type.RealExpressoType)8 RealInterval (com.sri.ai.expresso.type.RealInterval)8 Rational (com.sri.ai.util.math.Rational)8 TrueContext (com.sri.ai.grinder.core.TrueContext)5 List (java.util.List)5 CountingFormula (com.sri.ai.expresso.api.CountingFormula)4 FunctionType (com.sri.ai.expresso.type.FunctionType)4 IntegerExpressoType (com.sri.ai.expresso.type.IntegerExpressoType)4 IntegerInterval (com.sri.ai.expresso.type.IntegerInterval)4 TupleType (com.sri.ai.expresso.type.TupleType)4 TrueContext (com.sri.ai.grinder.sgdpllt.core.TrueContext)3 Beta (com.google.common.annotations.Beta)2