public static Term project(Term formula, int... indexes) throws IndexOutOfBoundsException {
int[] newIndexes = indexes;
if (formula instanceof ProjectT && formula.alias == null) {
/* The below is to avoid emitting {@code project(project(...),...)} - but only
* if the inner projection has no alias */
ProjectT innerProjection = (ProjectT) formula;
formula = innerProjection.getInputTerm();
List<Integer> innerIndexes = innerProjection.getIndexes();
newIndexes = new int[indexes.length];
for (int i = 0; i < indexes.length; ++i) {
newIndexes[i] = innerIndexes.get(indexes[i]-1);
}
}