+static ex log_expand(const ex & arg, unsigned options)
+{
+ if ((options & expand_options::expand_transcendental)
+ && is_exactly_a<mul>(arg) && !arg.info(info_flags::indefinite)) {
+ exvector sumseq;
+ exvector prodseq;
+ sumseq.reserve(arg.nops());
+ prodseq.reserve(arg.nops());
+ bool possign=true;
+
+ // searching for positive/negative factors
+ for (const_iterator i = arg.begin(); i != arg.end(); ++i) {
+ ex e;
+ if (options & expand_options::expand_function_args)
+ e=i->expand(options);
+ else
+ e=*i;
+ if (e.info(info_flags::positive))
+ sumseq.push_back(log(e));
+ else if (e.info(info_flags::negative)) {
+ sumseq.push_back(log(-e));
+ possign = !possign;
+ } else
+ prodseq.push_back(e);
+ }
+
+ if (sumseq.size() > 0) {
+ ex newarg;
+ if (options & expand_options::expand_function_args)
+ newarg=((possign?_ex1:_ex_1)*mul(prodseq)).expand(options);
+ else {
+ newarg=(possign?_ex1:_ex_1)*mul(prodseq);
+ ex_to<basic>(newarg).setflag(status_flags::purely_indefinite);
+ }
+ return add(sumseq)+log(newarg);
+ } else {
+ if (!(options & expand_options::expand_function_args))
+ ex_to<basic>(arg).setflag(status_flags::purely_indefinite);
+ }
+ }
+
+ if (options & expand_options::expand_function_args)
+ return log(arg.expand(options)).hold();
+ else
+ return log(arg).hold();
+}
+
+static ex log_conjugate(const ex & x)
+{
+ // conjugate(log(x))==log(conjugate(x)) unless on the branch cut which
+ // runs along the negative real axis.
+ if (x.info(info_flags::positive)) {
+ return log(x);
+ }
+ if (is_exactly_a<numeric>(x) &&
+ !x.imag_part().is_zero()) {
+ return log(x.conjugate());
+ }
+ return conjugate_function(log(x)).hold();
+}
+