+ // construct what we carelessly called the n*log(x) term above
+ const ex coeff = argser.coeff(s, n);
+ // expand the log, but only if coeff is real and > 0, since otherwise
+ // it would make the branch cut run into the wrong direction
+ if (coeff.info(info_flags::positive))
+ seq.push_back(expair(n*log(s-point)+log(coeff), _ex0));
+ else
+ seq.push_back(expair(log(coeff*pow(s-point, n)), _ex0));
+
+ if (!argser.is_terminating() || argser.nops()!=1) {
+ // in this case n more (or less) terms are needed
+ // (sadly, to generate them, we have to start from the beginning)
+ const ex newarg = ex_to<pseries>((arg/coeff).series(rel, order+n, options)).shift_exponents(-n).convert_to_poly(true);
+ if (n == 0 && coeff == 1) {
+ epvector epv;
+ ex acc = (new pseries(rel, epv))->setflag(status_flags::dynallocated);
+ epv.reserve(2);
+ epv.push_back(expair(-1, _ex0));
+ epv.push_back(expair(Order(_ex1), order));
+ ex rest = pseries(rel, epv).add_series(argser);
+ for (int i = order-1; i>0; --i) {
+ epvector cterm;
+ cterm.reserve(1);
+ cterm.push_back(expair(i%2 ? _ex1/i : _ex_1/i, _ex0));
+ acc = pseries(rel, cterm).add_series(ex_to<pseries>(acc));
+ acc = (ex_to<pseries>(rest)).mul_series(ex_to<pseries>(acc));
+ }
+ return acc;
+ }
+ return pseries(rel, seq).add_series(ex_to<pseries>(log(newarg).series(rel, order, options)));
+ } else // it was a monomial
+ return pseries(rel, seq);
+ }
+ if (!(options & series_options::suppress_branchcut) &&
+ arg_pt.info(info_flags::negative)) {
+ // method:
+ // This is the branch cut: assemble the primitive series manually and
+ // then add the corresponding complex step function.
+ const symbol &s = ex_to<symbol>(rel.lhs());
+ const ex &point = rel.rhs();
+ const symbol foo;
+ const ex replarg = series(log(arg), s==foo, order).subs(foo==point, subs_options::no_pattern);
+ epvector seq;
+ seq.push_back(expair(-I*csgn(arg*I)*Pi, _ex0));
+ seq.push_back(expair(Order(_ex1), order));
+ return series(replarg - I*Pi + pseries(rel, seq), rel, order);
+ }
+ throw do_taylor(); // caught by function::series()