- throw(std::runtime_error("max recursion level reached"));
-
- // Normalize and expand children, chop into summands
- exvector o;
- o.reserve(seq.size()+1);
- epvector::const_iterator it = seq.begin(), itend = seq.end();
- while (it != itend) {
-
- // Normalize and expand child
- ex n = recombine_pair_to_ex(*it).bp->normal(sym_lst, repl_lst, level-1).expand();
-
- // If numerator is a sum, chop into summands
- if (is_ex_exactly_of_type(n.op(0), add)) {
- epvector::const_iterator bit = ex_to_add(n.op(0)).seq.begin(), bitend = ex_to_add(n.op(0)).seq.end();
- while (bit != bitend) {
- o.push_back((new lst(recombine_pair_to_ex(*bit), n.op(1)))->setflag(status_flags::dynallocated));
- bit++;
- }
-
- // The overall_coeff is already normalized (== rational), we just
- // split it into numerator and denominator
- GINAC_ASSERT(ex_to_numeric(ex_to_add(n.op(0)).overall_coeff).is_rational());
- numeric overall = ex_to_numeric(ex_to_add(n.op(0)).overall_coeff);
- o.push_back((new lst(overall.numer(), overall.denom() * n.op(1)))->setflag(status_flags::dynallocated));
- } else
- o.push_back(n);
- it++;
- }
- o.push_back(overall_coeff.bp->normal(sym_lst, repl_lst, level-1));
-
- // o is now a vector of {numerator, denominator} lists
-
- // Determine common denominator
- ex den = _ex1();
- exvector::const_iterator ait = o.begin(), aitend = o.end();
-//std::clog << "add::normal uses the following summands:\n";
- while (ait != aitend) {
-//std::clog << " num = " << ait->op(0) << ", den = " << ait->op(1) << endl;
- den = lcm(ait->op(1), den, false);
- ait++;
- }
-//std::clog << " common denominator = " << den << endl;