use of com.sri.ai.expresso.api.IntensionalSet in project aic-expresso by aic-sri-international.
the class MeasureTest method measure.
private Rational measure(String testIntensionalSetString) {
Expression testIntensionalSetExpression = parse(testIntensionalSetString);
Expression properlyConditionedIntensionalSetExpression = testIntensionalSetExpression;
if (Sets.isIntensionalSet(testIntensionalSetExpression)) {
IntensionalSet intensionalSet = (IntensionalSet) testIntensionalSetExpression;
List<Expression> indices = IndexExpressions.getIndices(intensionalSet.getIndexExpressions());
if (indices.size() == 1) {
Expression index = indices.get(0);
Context intensionalSetContext = context.extendWith(intensionalSet.getIndexExpressions());
Type type = GrinderUtil.getTypeOfExpression(index, intensionalSetContext);
if (type instanceof RealExpressoType || type instanceof RealInterval) {
SingleVariableLinearRealArithmeticConstraint singleVariableConstraint = new SingleVariableLinearRealArithmeticConstraint(index, true, context.getTheory());
singleVariableConstraint = (SingleVariableLinearRealArithmeticConstraint) singleVariableConstraint.conjoin(intensionalSet.getCondition(), intensionalSetContext);
properlyConditionedIntensionalSetExpression = IntensionalSet.make(Sets.isMultiSet(intensionalSet) ? IntensionalSet.MULTI_SET_LABEL : IntensionalSet.UNI_SET_LABEL, intensionalSet.getIndexExpressions(), intensionalSet.getHead(), singleVariableConstraint);
}
}
}
Rational result = Measure.get(properlyConditionedIntensionalSetExpression, context);
return result;
}
use of com.sri.ai.expresso.api.IntensionalSet in project aic-expresso by aic-sri-international.
the class DefaultIntensionalBound method applyFunctionToBound.
protected DefaultIntensionalBound applyFunctionToBound(Expression f, Expression variableName, Bound bound, Theory theory, Context context) {
if (!bound.isIntensionalBound()) {
return null;
}
IntensionalSet intensionalBound = (IntensionalSet) bound;
IndexExpressionsSet indexExpressions = intensionalBound.getIndexExpressions();
Expression Head = intensionalBound.getHead();
Expression condition = intensionalBound.getCondition();
Expression fOfHead = f.replaceAllOccurrences(variableName, Head, context);
Expression evaluation = theory.evaluate(fOfHead, context);
DefaultIntensionalBound result = new DefaultIntensionalBound(indexExpressions, evaluation, condition);
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;
}
use of com.sri.ai.expresso.api.IntensionalSet in project aic-expresso by aic-sri-international.
the class IntensionalUnionEqualToEmptySetSimplifier method simplify.
public static Expression simplify(Expression expression, Context context) {
Expression result = expression;
if (Equality.isEquality(expression) && expression.numberOfArguments() == 2) {
Expression intensionalUnion = null;
Expression emptySet = null;
for (Expression arg : expression.getArguments()) {
if (Sets.isIntensionalUnion(arg)) {
intensionalUnion = arg;
} else if (Sets.isEmptySet(arg)) {
emptySet = arg;
}
}
// (∪<sub>i ∈ D:C</sub>Φ) = ∅
if (intensionalUnion != null && emptySet != null) {
IntensionalSet intensionalSet = (IntensionalSet) intensionalUnion.get(0);
Expression C = intensionalSet.getCondition();
Expression notC = Not.make(C);
Expression Phi = intensionalSet.getHead();
Expression notCorPhi = Or.make(notC, Phi);
Expression notCorPhiEqualEmptySet = Equality.make(notCorPhi, emptySet);
// ∀ i ∈ D : (¬C ∨ Φ = ∅)
result = ForAll.make(intensionalSet.getIndexExpressions(), notCorPhiEqualEmptySet);
}
}
return result;
}
use of com.sri.ai.expresso.api.IntensionalSet in project aic-expresso by aic-sri-international.
the class IntersectionIntensionalSetsSimplifier method standardizeApartIntensionalSets.
public static IntensionalSet standardizeApartIntensionalSets(IntensionalSet intensionalSet, IntensionalSet fromOtherIntensionalSet, Context context) {
IntensionalSet result = intensionalSet;
IndexExpressionsSet intensionalSetIndexes = intensionalSet.getIndexExpressions();
IndexExpressionsSet fromOtherIntensionalSetIn = fromOtherIntensionalSet.getIndexExpressions();
List<Expression> overlappingIndexNames = new ArrayList<>();
for (Expression intensionalSetIndex : IndexExpressions.getIndices(intensionalSetIndexes)) {
if (IndexExpressions.indexExpressionsContainIndex(fromOtherIntensionalSetIn, intensionalSetIndex)) {
overlappingIndexNames.add(intensionalSetIndex);
}
}
if (overlappingIndexNames.size() > 0) {
Expression combinedExpression = And.make(intensionalSet, fromOtherIntensionalSet);
List<Expression> newIndexNames = new ArrayList<>();
for (Expression overlappingIndex : overlappingIndexNames) {
Expression newIndexName = Expressions.makeUniqueVariable(overlappingIndex.toString(), combinedExpression, context);
newIndexNames.add(newIndexName);
}
SyntaxTree resultSyntaxTree = result.getSyntaxTree();
for (int i = 0; i < newIndexNames.size(); i++) {
Expression replaced = overlappingIndexNames.get(i);
Expression replacement = newIndexNames.get(i);
resultSyntaxTree = resultSyntaxTree.replaceSubTreesAllOccurrences(replaced.getSyntaxTree(), replacement.getSyntaxTree());
}
result = (IntensionalSet) Expressions.makeFromSyntaxTree(resultSyntaxTree);
}
return result;
}
Aggregations