+ if (is_ex_exactly_of_type(last_expanded,add)) {
+ // expand adds
+ const add & add1 = ex_to_add(last_expanded);
+ const add & add2 = ex_to_add((*cit).rest);
+ int n1 = add1.nops();
+ int n2 = add2.nops();
+ exvector distrseq;
+ distrseq.reserve(n1*n2);
+ for (int i1=0; i1<n1; ++i1) {
+ for (int i2=0; i2<n2; ++i2) {
+ distrseq.push_back(add1.op(i1)*add2.op(i2));
+ }
+ }
+ last_expanded = (new add(distrseq))->setflag(status_flags::dynallocated | status_flags::expanded);
+ } else {
+ non_adds.push_back(split_ex_to_pair(last_expanded));
+ last_expanded = (*cit).rest;
+ }
+ } else {
+ non_adds.push_back(*cit);