use of com.sri.ai.expresso.helper.SubExpressionsDepthFirstIterator in project aic-expresso by aic-sri-international.
the class TupleQuantifierSimplifier method createTuplesOfVarsForTupleTypes.
private static Map<Expression, Expression> createTuplesOfVarsForTupleTypes(QuantifiedExpression quantifiedExpression, List<Map.Entry<Expression, Expression>> indexesOfTupleType) {
Map<Expression, Expression> result = new HashMap<>();
Set<Expression> allSubExpressions = Util.addAllToSet(new SubExpressionsDepthFirstIterator(quantifiedExpression));
for (Map.Entry<Expression, Expression> entry : indexesOfTupleType) {
List<Expression> tupleVars = new ArrayList<>();
for (int i = 1; i <= entry.getValue().numberOfArguments(); i++) {
Expression proposedVar = Expressions.makeSymbol(entry.getKey().toString() + "_" + i);
Expression actualVar = Expressions.primedUntilUnique(proposedVar, expr -> !allSubExpressions.contains(expr));
tupleVars.add(actualVar);
}
result.put(entry.getKey(), Expressions.makeTuple(tupleVars));
}
return result;
}
use of com.sri.ai.expresso.helper.SubExpressionsDepthFirstIterator in project aic-expresso by aic-sri-international.
the class AbstractSGVET method width.
private int width(Expression expression, Context context) {
Set<Expression> variables = new LinkedHashSet<Expression>();
Iterator<Expression> iterator = new SubExpressionsDepthFirstIterator(expression);
while (iterator.hasNext()) {
Expression subExpression = iterator.next();
if (isVariable(subExpression, context)) {
variables.add(subExpression);
}
}
int result = variables.size();
return result;
}
Aggregations