}
private static Tensor factorSymbolicTerm(Tensor sum, FactorizationEngine factorizationEngine) {
Tensor c;
if (factorizationEngine instanceof JasFactor) {
TreeIterator iterator = new FromChildToParentIterator(sum);
while ((c = iterator.next()) != null)
if (c instanceof Sum)
iterator.set(factorOut(c, factorizationEngine));
sum = iterator.result();
}
TreeIterator iterator = new FromParentToChildIterator(sum);
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(factorSum1(c.get(i), factorizationEngine));
} else if (pb != null)
pb.put(c.get(i));
}
iterator.set(pb == null ? c : pb.build());
} else iterator.set(c);
} else
iterator.set(factorSum1(c, factorizationEngine));
}
return iterator.result();
}