- expair new_factor = split_ex_to_pair(finaladd.op(i).expand());
- factors.push_back(new_factor);
-
- const mul & term = static_cast<const mul &>((new mul(factors, overall_coeff))->setflag(status_flags::dynallocated));
-
- // The new term may have sums in it if e.g. a sqrt() of a sum in
- // the non_adds meets a sqrt() of a sum in the factor from
- // last_expanded. In this case we should re-expand the term.
- if (non_adds_has_sums || is_exactly_a<add>(new_factor.rest))
- distrseq.push_back(ex(term).expand());
- else
- distrseq.push_back(term.setflag(options == 0 ? status_flags::expanded : 0));
+ factors.push_back(split_ex_to_pair(last_expanded.op(i)));
+ ex term = (new mul(factors, overall_coeff))->setflag(status_flags::dynallocated);
+ if (can_be_further_expanded(term))
+ distrseq.push_back(term.expand());
+ else {
+ if (options == 0)
+ ex_to<basic>(term).setflag(status_flags::expanded);
+ distrseq.push_back(term);
+ }