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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations