}
return iterator.result();
}
private static Tensor factorSymbolicTerm(Tensor sum) {
TreeIterator iterator = new FromChildToParentIterator(sum);
Tensor c;
while ((c = iterator.next()) != null)
if (c instanceof Sum)
iterator.set(factorOut(c));
iterator = new FromParentToChildIterator(iterator.result());
while ((c = iterator.next()) != null) {
if (!(c instanceof Sum))
continue;
if (needTogether(c)) {
c = TogetherTransformation.together(c, true);
if (c instanceof Product) {
TensorBuilder pb = null;
for (int i = c.size() - 1; i >= 0; --i) {
if (c.get(i) instanceof Sum) {
if (pb == null) {
pb = c.getBuilder();
for (int j = c.size() - 1; j > i; --j)
pb.put(c.get(j));
}
pb.put(JasFactor.factor(c.get(i)));
} else if (pb != null)
pb.put(c.get(i));
}
iterator.set(pb == null ? c : pb.build());
}
} else
iterator.set(JasFactor.factor(c));
}
return iterator.result();
}