1 /** @file inifcns_nstdsums.cpp
3 * Implementation of some special functions that have a representation as nested sums.
6 * classical polylogarithm Li(n,x)
7 * multiple polylogarithm Li(lst(m_1,...,m_k),lst(x_1,...,x_k))
8 * G(lst(a_1,...,a_k),y) or G(lst(a_1,...,a_k),lst(s_1,...,s_k),y)
9 * Nielsen's generalized polylogarithm S(n,p,x)
10 * harmonic polylogarithm H(m,x) or H(lst(m_1,...,m_k),x)
11 * multiple zeta value zeta(m) or zeta(lst(m_1,...,m_k))
12 * alternating Euler sum zeta(m,s) or zeta(lst(m_1,...,m_k),lst(s_1,...,s_k))
16 * - All formulae used can be looked up in the following publications:
17 * [Kol] Nielsen's Generalized Polylogarithms, K.S.Kolbig, SIAM J.Math.Anal. 17 (1986), pp. 1232-1258.
18 * [Cra] Fast Evaluation of Multiple Zeta Sums, R.E.Crandall, Math.Comp. 67 (1998), pp. 1163-1172.
19 * [ReV] Harmonic Polylogarithms, E.Remiddi, J.A.M.Vermaseren, Int.J.Mod.Phys. A15 (2000), pp. 725-754
20 * [BBB] Special Values of Multiple Polylogarithms, J.Borwein, D.Bradley, D.Broadhurst, P.Lisonek, Trans.Amer.Math.Soc. 353/3 (2001), pp. 907-941
21 * [VSW] Numerical evaluation of multiple polylogarithms, J.Vollinga, S.Weinzierl, hep-ph/0410259
23 * - The order of parameters and arguments of Li and zeta is defined according to the nested sums
24 * representation. The parameters for H are understood as in [ReV]. They can be in expanded --- only
25 * 0, 1 and -1 --- or in compactified --- a string with zeros in front of 1 or -1 is written as a single
26 * number --- notation.
28 * - All functions can be nummerically evaluated with arguments in the whole complex plane. The parameters
29 * for Li, zeta and S must be positive integers. If you want to have an alternating Euler sum, you have
30 * to give the signs of the parameters as a second argument s to zeta(m,s) containing 1 and -1.
32 * - The calculation of classical polylogarithms is speeded up by using Bernoulli numbers and
33 * look-up tables. S uses look-up tables as well. The zeta function applies the algorithms in
34 * [Cra] and [BBB] for speed up. Multiple polylogarithms use Hoelder convolution [BBB].
36 * - The functions have no means to do a series expansion into nested sums. To do this, you have to convert
37 * these functions into the appropriate objects from the nestedsums library, do the expansion and convert
40 * - Numerical testing of this implementation has been performed by doing a comparison of results
41 * between this software and the commercial M.......... 4.1. Multiple zeta values have been checked
42 * by means of evaluations into simple zeta values. Harmonic polylogarithms have been checked by
43 * comparison to S(n,p,x) for corresponding parameter combinations and by continuity checks
44 * around |x|=1 along with comparisons to corresponding zeta functions. Multiple polylogarithms were
45 * checked against H and zeta and by means of shuffle and quasi-shuffle relations.
50 * GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
52 * This program is free software; you can redistribute it and/or modify
53 * it under the terms of the GNU General Public License as published by
54 * the Free Software Foundation; either version 2 of the License, or
55 * (at your option) any later version.
57 * This program is distributed in the hope that it will be useful,
58 * but WITHOUT ANY WARRANTY; without even the implied warranty of
59 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
60 * GNU General Public License for more details.
62 * You should have received a copy of the GNU General Public License
63 * along with this program; if not, write to the Free Software
64 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
79 #include "operators.h"
82 #include "relational.h"
91 //////////////////////////////////////////////////////////////////////
93 // Classical polylogarithm Li(n,x)
97 //////////////////////////////////////////////////////////////////////
100 // anonymous namespace for helper functions
104 // lookup table for factors built from Bernoulli numbers
106 std::vector<std::vector<cln::cl_N> > Xn;
107 // initial size of Xn that should suffice for 32bit machines (must be even)
108 const int xninitsizestep = 26;
109 int xninitsize = xninitsizestep;
113 // This function calculates the X_n. The X_n are needed for speed up of classical polylogarithms.
114 // With these numbers the polylogs can be calculated as follows:
115 // Li_p (x) = \sum_{n=0}^\infty X_{p-2}(n) u^{n+1}/(n+1)! with u = -log(1-x)
116 // X_0(n) = B_n (Bernoulli numbers)
117 // X_p(n) = \sum_{k=0}^n binomial(n,k) B_{n-k} / (k+1) * X_{p-1}(k)
118 // The calculation of Xn depends on X0 and X{n-1}.
119 // X_0 is special, it holds only the non-zero Bernoulli numbers with index 2 or greater.
120 // This results in a slightly more complicated algorithm for the X_n.
121 // The first index in Xn corresponds to the index of the polylog minus 2.
122 // The second index in Xn corresponds to the index from the actual sum.
126 // calculate X_2 and higher (corresponding to Li_4 and higher)
127 std::vector<cln::cl_N> buf(xninitsize);
128 std::vector<cln::cl_N>::iterator it = buf.begin();
130 *it = -(cln::expt(cln::cl_I(2),n+1) - 1) / cln::expt(cln::cl_I(2),n+1); // i == 1
132 for (int i=2; i<=xninitsize; i++) {
134 result = 0; // k == 0
136 result = Xn[0][i/2-1]; // k == 0
138 for (int k=1; k<i-1; k++) {
139 if ( !(((i-k) & 1) && ((i-k) > 1)) ) {
140 result = result + cln::binomial(i,k) * Xn[0][(i-k)/2-1] * Xn[n-1][k-1] / (k+1);
143 result = result - cln::binomial(i,i-1) * Xn[n-1][i-2] / 2 / i; // k == i-1
144 result = result + Xn[n-1][i-1] / (i+1); // k == i
151 // special case to handle the X_0 correct
152 std::vector<cln::cl_N> buf(xninitsize);
153 std::vector<cln::cl_N>::iterator it = buf.begin();
155 *it = cln::cl_I(-3)/cln::cl_I(4); // i == 1
157 *it = cln::cl_I(17)/cln::cl_I(36); // i == 2
159 for (int i=3; i<=xninitsize; i++) {
161 result = -Xn[0][(i-3)/2]/2;
162 *it = (cln::binomial(i,1)/cln::cl_I(2) + cln::binomial(i,i-1)/cln::cl_I(i))*result;
165 result = Xn[0][i/2-1] + Xn[0][i/2-1]/(i+1);
166 for (int k=1; k<i/2; k++) {
167 result = result + cln::binomial(i,k*2) * Xn[0][k-1] * Xn[0][i/2-k-1] / (k*2+1);
176 std::vector<cln::cl_N> buf(xninitsize/2);
177 std::vector<cln::cl_N>::iterator it = buf.begin();
178 for (int i=1; i<=xninitsize/2; i++) {
179 *it = bernoulli(i*2).to_cl_N();
188 // doubles the number of entries in each Xn[]
191 const int pos0 = xninitsize / 2;
193 for (int i=1; i<=xninitsizestep/2; ++i) {
194 Xn[0].push_back(bernoulli((i+pos0)*2).to_cl_N());
197 int xend = xninitsize + xninitsizestep;
200 for (int i=xninitsize+1; i<=xend; ++i) {
202 result = -Xn[0][(i-3)/2]/2;
203 Xn[1].push_back((cln::binomial(i,1)/cln::cl_I(2) + cln::binomial(i,i-1)/cln::cl_I(i))*result);
205 result = Xn[0][i/2-1] + Xn[0][i/2-1]/(i+1);
206 for (int k=1; k<i/2; k++) {
207 result = result + cln::binomial(i,k*2) * Xn[0][k-1] * Xn[0][i/2-k-1] / (k*2+1);
209 Xn[1].push_back(result);
213 for (int n=2; n<Xn.size(); ++n) {
214 for (int i=xninitsize+1; i<=xend; ++i) {
216 result = 0; // k == 0
218 result = Xn[0][i/2-1]; // k == 0
220 for (int k=1; k<i-1; ++k) {
221 if ( !(((i-k) & 1) && ((i-k) > 1)) ) {
222 result = result + cln::binomial(i,k) * Xn[0][(i-k)/2-1] * Xn[n-1][k-1] / (k+1);
225 result = result - cln::binomial(i,i-1) * Xn[n-1][i-2] / 2 / i; // k == i-1
226 result = result + Xn[n-1][i-1] / (i+1); // k == i
227 Xn[n].push_back(result);
231 xninitsize += xninitsizestep;
235 // calculates Li(2,x) without Xn
236 cln::cl_N Li2_do_sum(const cln::cl_N& x)
240 cln::cl_N num = x * cln::cl_float(1, cln::float_format(Digits));
241 cln::cl_I den = 1; // n^2 = 1
246 den = den + i; // n^2 = 4, 9, 16, ...
248 res = res + num / den;
249 } while (res != resbuf);
254 // calculates Li(2,x) with Xn
255 cln::cl_N Li2_do_sum_Xn(const cln::cl_N& x)
257 std::vector<cln::cl_N>::const_iterator it = Xn[0].begin();
258 std::vector<cln::cl_N>::const_iterator xend = Xn[0].end();
259 cln::cl_N u = -cln::log(1-x);
260 cln::cl_N factor = u * cln::cl_float(1, cln::float_format(Digits));
261 cln::cl_N uu = cln::square(u);
262 cln::cl_N res = u - uu/4;
267 factor = factor * uu / (2*i * (2*i+1));
268 res = res + (*it) * factor;
272 it = Xn[0].begin() + (i-1);
275 } while (res != resbuf);
280 // calculates Li(n,x), n>2 without Xn
281 cln::cl_N Lin_do_sum(int n, const cln::cl_N& x)
283 cln::cl_N factor = x * cln::cl_float(1, cln::float_format(Digits));
290 res = res + factor / cln::expt(cln::cl_I(i),n);
292 } while (res != resbuf);
297 // calculates Li(n,x), n>2 with Xn
298 cln::cl_N Lin_do_sum_Xn(int n, const cln::cl_N& x)
300 std::vector<cln::cl_N>::const_iterator it = Xn[n-2].begin();
301 std::vector<cln::cl_N>::const_iterator xend = Xn[n-2].end();
302 cln::cl_N u = -cln::log(1-x);
303 cln::cl_N factor = u * cln::cl_float(1, cln::float_format(Digits));
309 factor = factor * u / i;
310 res = res + (*it) * factor;
314 it = Xn[n-2].begin() + (i-2);
315 xend = Xn[n-2].end();
317 } while (res != resbuf);
322 // forward declaration needed by function Li_projection and C below
323 const cln::cl_N S_num(int n, int p, const cln::cl_N& x);
326 // helper function for classical polylog Li
327 cln::cl_N Li_projection(int n, const cln::cl_N& x, const cln::float_format_t& prec)
329 // treat n=2 as special case
331 // check if precalculated X0 exists
336 if (cln::realpart(x) < 0.5) {
337 // choose the faster algorithm
338 // the switching point was empirically determined. the optimal point
339 // depends on hardware, Digits, ... so an approx value is okay.
340 // it solves also the problem with precision due to the u=-log(1-x) transformation
341 if (cln::abs(cln::realpart(x)) < 0.25) {
343 return Li2_do_sum(x);
345 return Li2_do_sum_Xn(x);
348 // choose the faster algorithm
349 if (cln::abs(cln::realpart(x)) > 0.75) {
350 return -Li2_do_sum(1-x) - cln::log(x) * cln::log(1-x) + cln::zeta(2);
352 return -Li2_do_sum_Xn(1-x) - cln::log(x) * cln::log(1-x) + cln::zeta(2);
356 // check if precalculated Xn exist
358 for (int i=xnsize; i<n-1; i++) {
363 if (cln::realpart(x) < 0.5) {
364 // choose the faster algorithm
365 // with n>=12 the "normal" summation always wins against the method with Xn
366 if ((cln::abs(cln::realpart(x)) < 0.3) || (n >= 12)) {
367 return Lin_do_sum(n, x);
369 return Lin_do_sum_Xn(n, x);
372 cln::cl_N result = -cln::expt(cln::log(x), n-1) * cln::log(1-x) / cln::factorial(n-1);
373 for (int j=0; j<n-1; j++) {
374 result = result + (S_num(n-j-1, 1, 1) - S_num(1, n-j-1, 1-x))
375 * cln::expt(cln::log(x), j) / cln::factorial(j);
383 // helper function for classical polylog Li
384 numeric Lin_numeric(int n, const numeric& x)
388 return -cln::log(1-x.to_cl_N());
399 return -(1-cln::expt(cln::cl_I(2),1-n)) * cln::zeta(n);
401 if (abs(x.real()) < 0.4 && abs(abs(x)-1) < 0.01) {
402 cln::cl_N x_ = ex_to<numeric>(x).to_cl_N();
403 cln::cl_N result = -cln::expt(cln::log(x_), n-1) * cln::log(1-x_) / cln::factorial(n-1);
404 for (int j=0; j<n-1; j++) {
405 result = result + (S_num(n-j-1, 1, 1) - S_num(1, n-j-1, 1-x_))
406 * cln::expt(cln::log(x_), j) / cln::factorial(j);
411 // what is the desired float format?
412 // first guess: default format
413 cln::float_format_t prec = cln::default_float_format;
414 const cln::cl_N value = x.to_cl_N();
415 // second guess: the argument's format
416 if (!x.real().is_rational())
417 prec = cln::float_format(cln::the<cln::cl_F>(cln::realpart(value)));
418 else if (!x.imag().is_rational())
419 prec = cln::float_format(cln::the<cln::cl_F>(cln::imagpart(value)));
422 if (cln::abs(value) > 1) {
423 cln::cl_N result = -cln::expt(cln::log(-value),n) / cln::factorial(n);
424 // check if argument is complex. if it is real, the new polylog has to be conjugated.
425 if (cln::zerop(cln::imagpart(value))) {
427 result = result + conjugate(Li_projection(n, cln::recip(value), prec));
430 result = result - conjugate(Li_projection(n, cln::recip(value), prec));
435 result = result + Li_projection(n, cln::recip(value), prec);
438 result = result - Li_projection(n, cln::recip(value), prec);
442 for (int j=0; j<n-1; j++) {
443 add = add + (1+cln::expt(cln::cl_I(-1),n-j)) * (1-cln::expt(cln::cl_I(2),1-n+j))
444 * Lin_numeric(n-j,1).to_cl_N() * cln::expt(cln::log(-value),j) / cln::factorial(j);
446 result = result - add;
450 return Li_projection(n, value, prec);
455 } // end of anonymous namespace
458 //////////////////////////////////////////////////////////////////////
460 // Multiple polylogarithm Li(n,x)
464 //////////////////////////////////////////////////////////////////////
467 // anonymous namespace for helper function
471 // performs the actual series summation for multiple polylogarithms
472 cln::cl_N multipleLi_do_sum(const std::vector<int>& s, const std::vector<cln::cl_N>& x)
474 // ensure all x <> 0.
475 for (std::vector<cln::cl_N>::const_iterator it = x.begin(); it != x.end(); ++it) {
476 if ( *it == 0 ) return cln::cl_float(0, cln::float_format(Digits));
479 const int j = s.size();
480 bool flag_accidental_zero = false;
482 std::vector<cln::cl_N> t(j);
483 cln::cl_F one = cln::cl_float(1, cln::float_format(Digits));
490 t[j-1] = t[j-1] + cln::expt(x[j-1], q) / cln::expt(cln::cl_I(q),s[j-1]) * one;
491 for (int k=j-2; k>=0; k--) {
492 t[k] = t[k] + t[k+1] * cln::expt(x[k], q+j-1-k) / cln::expt(cln::cl_I(q+j-1-k), s[k]);
495 t[j-1] = t[j-1] + cln::expt(x[j-1], q) / cln::expt(cln::cl_I(q),s[j-1]) * one;
496 for (int k=j-2; k>=0; k--) {
497 flag_accidental_zero = cln::zerop(t[k+1]);
498 t[k] = t[k] + t[k+1] * cln::expt(x[k], q+j-1-k) / cln::expt(cln::cl_I(q+j-1-k), s[k]);
500 } while ( (t[0] != t0buf) || cln::zerop(t[0]) || flag_accidental_zero );
506 // converts parameter types and calls multipleLi_do_sum (convenience function for G_numeric)
507 cln::cl_N mLi_do_summation(const lst& m, const lst& x)
509 std::vector<int> m_int;
510 std::vector<cln::cl_N> x_cln;
511 for (lst::const_iterator itm = m.begin(), itx = x.begin(); itm != m.end(); ++itm, ++itx) {
512 m_int.push_back(ex_to<numeric>(*itm).to_int());
513 x_cln.push_back(ex_to<numeric>(*itx).to_cl_N());
515 return multipleLi_do_sum(m_int, x_cln);
519 // forward declaration for Li_eval()
520 lst convert_parameter_Li_to_H(const lst& m, const lst& x, ex& pf);
523 // holding dummy-symbols for the G/Li transformations
524 std::vector<ex> gsyms;
527 // type used by the transformation functions for G
528 typedef std::vector<int> Gparameter;
531 // G_eval1-function for G transformations
532 ex G_eval1(int a, int scale)
535 const ex& scs = gsyms[std::abs(scale)];
536 const ex& as = gsyms[std::abs(a)];
538 return -log(1 - scs/as);
543 return log(gsyms[std::abs(scale)]);
548 // G_eval-function for G transformations
549 ex G_eval(const Gparameter& a, int scale)
551 // check for properties of G
552 ex sc = gsyms[std::abs(scale)];
554 bool all_zero = true;
555 bool all_ones = true;
557 for (Gparameter::const_iterator it = a.begin(); it != a.end(); ++it) {
559 const ex sym = gsyms[std::abs(*it)];
573 // care about divergent G: shuffle to separate divergencies that will be canceled
574 // later on in the transformation
575 if (newa.nops() > 1 && newa.op(0) == sc && !all_ones && a.front()!=0) {
578 Gparameter::const_iterator it = a.begin();
580 for (; it != a.end(); ++it) {
581 short_a.push_back(*it);
583 ex result = G_eval1(a.front(), scale) * G_eval(short_a, scale);
584 it = short_a.begin();
585 for (int i=1; i<count_ones; ++i) {
588 for (; it != short_a.end(); ++it) {
591 Gparameter::const_iterator it2 = short_a.begin();
592 for (--it2; it2 != it;) {
594 newa.push_back(*it2);
596 newa.push_back(a[0]);
598 for (; it2 != short_a.end(); ++it2) {
599 newa.push_back(*it2);
601 result -= G_eval(newa, scale);
603 return result / count_ones;
606 // G({1,...,1};y) -> G({1};y)^k / k!
607 if (all_ones && a.size() > 1) {
608 return pow(G_eval1(a.front(),scale), count_ones) / factorial(count_ones);
611 // G({0,...,0};y) -> log(y)^k / k!
613 return pow(log(gsyms[std::abs(scale)]), a.size()) / factorial(a.size());
616 // no special cases anymore -> convert it into Li
619 ex argbuf = gsyms[std::abs(scale)];
621 for (Gparameter::const_iterator it=a.begin(); it!=a.end(); ++it) {
623 const ex& sym = gsyms[std::abs(*it)];
624 x.append(argbuf / sym);
632 return pow(-1, x.nops()) * Li(m, x);
636 // converts data for G: pending_integrals -> a
637 Gparameter convert_pending_integrals_G(const Gparameter& pending_integrals)
639 GINAC_ASSERT(pending_integrals.size() != 1);
641 if (pending_integrals.size() > 0) {
642 // get rid of the first element, which would stand for the new upper limit
643 Gparameter new_a(pending_integrals.begin()+1, pending_integrals.end());
646 // just return empty parameter list
653 // check the parameters a and scale for G and return information about convergence, depth, etc.
654 // convergent : true if G(a,scale) is convergent
655 // depth : depth of G(a,scale)
656 // trailing_zeros : number of trailing zeros of a
657 // min_it : iterator of a pointing on the smallest element in a
658 Gparameter::const_iterator check_parameter_G(const Gparameter& a, int scale,
659 bool& convergent, int& depth, int& trailing_zeros, Gparameter::const_iterator& min_it)
665 Gparameter::const_iterator lastnonzero = a.end();
666 for (Gparameter::const_iterator it = a.begin(); it != a.end(); ++it) {
667 if (std::abs(*it) > 0) {
671 if (std::abs(*it) < scale) {
673 if ((min_it == a.end()) || (std::abs(*it) < std::abs(*min_it))) {
681 return ++lastnonzero;
685 // add scale to pending_integrals if pending_integrals is empty
686 Gparameter prepare_pending_integrals(const Gparameter& pending_integrals, int scale)
688 GINAC_ASSERT(pending_integrals.size() != 1);
690 if (pending_integrals.size() > 0) {
691 return pending_integrals;
693 Gparameter new_pending_integrals;
694 new_pending_integrals.push_back(scale);
695 return new_pending_integrals;
700 // handles trailing zeroes for an otherwise convergent integral
701 ex trailing_zeros_G(const Gparameter& a, int scale)
704 int depth, trailing_zeros;
705 Gparameter::const_iterator last, dummyit;
706 last = check_parameter_G(a, scale, convergent, depth, trailing_zeros, dummyit);
708 GINAC_ASSERT(convergent);
710 if ((trailing_zeros > 0) && (depth > 0)) {
712 Gparameter new_a(a.begin(), a.end()-1);
713 result += G_eval1(0, scale) * trailing_zeros_G(new_a, scale);
714 for (Gparameter::const_iterator it = a.begin(); it != last; ++it) {
715 Gparameter new_a(a.begin(), it);
717 new_a.insert(new_a.end(), it, a.end()-1);
718 result -= trailing_zeros_G(new_a, scale);
721 return result / trailing_zeros;
723 return G_eval(a, scale);
728 // G transformation [VSW] (57),(58)
729 ex depth_one_trafo_G(const Gparameter& pending_integrals, const Gparameter& a, int scale)
731 // pendint = ( y1, b1, ..., br )
732 // a = ( 0, ..., 0, amin )
735 // int_0^y1 ds1/(s1-b1) ... int dsr/(sr-br) G(0, ..., 0, sr; y2)
736 // where sr replaces amin
738 GINAC_ASSERT(a.back() != 0);
739 GINAC_ASSERT(a.size() > 0);
742 Gparameter new_pending_integrals = prepare_pending_integrals(pending_integrals, std::abs(a.back()));
743 const int psize = pending_integrals.size();
746 // G(sr_{+-}; y2 ) = G(y2_{-+}; sr) - G(0; sr) + ln(-y2_{-+})
751 result += log(gsyms[ex_to<numeric>(scale).to_int()]);
753 new_pending_integrals.push_back(-scale);
756 new_pending_integrals.push_back(scale);
760 result *= trailing_zeros_G(convert_pending_integrals_G(pending_integrals), pending_integrals.front());
764 result += trailing_zeros_G(convert_pending_integrals_G(new_pending_integrals), new_pending_integrals.front());
767 new_pending_integrals.back() = 0;
768 result -= trailing_zeros_G(convert_pending_integrals_G(new_pending_integrals), new_pending_integrals.front());
774 // G_m(sr_{+-}; y2) = -zeta_m + int_0^y2 dt/t G_{m-1}( (1/y2)_{+-}; 1/t )
775 // - int_0^sr dt/t G_{m-1}( (1/y2)_{+-}; 1/t )
778 result -= zeta(a.size());
780 result *= trailing_zeros_G(convert_pending_integrals_G(pending_integrals), pending_integrals.front());
783 // term int_0^sr dt/t G_{m-1}( (1/y2)_{+-}; 1/t )
784 // = int_0^sr dt/t G_{m-1}( t_{+-}; y2 )
785 Gparameter new_a(a.begin()+1, a.end());
786 new_pending_integrals.push_back(0);
787 result -= depth_one_trafo_G(new_pending_integrals, new_a, scale);
789 // term int_0^y2 dt/t G_{m-1}( (1/y2)_{+-}; 1/t )
790 // = int_0^y2 dt/t G_{m-1}( t_{+-}; y2 )
791 Gparameter new_pending_integrals_2;
792 new_pending_integrals_2.push_back(scale);
793 new_pending_integrals_2.push_back(0);
795 result += trailing_zeros_G(convert_pending_integrals_G(pending_integrals), pending_integrals.front())
796 * depth_one_trafo_G(new_pending_integrals_2, new_a, scale);
798 result += depth_one_trafo_G(new_pending_integrals_2, new_a, scale);
805 // forward declaration
806 ex shuffle_G(const Gparameter & a0, const Gparameter & a1, const Gparameter & a2,
807 const Gparameter& pendint, const Gparameter& a_old, int scale);
810 // G transformation [VSW]
811 ex G_transform(const Gparameter& pendint, const Gparameter& a, int scale)
813 // main recursion routine
815 // pendint = ( y1, b1, ..., br )
816 // a = ( a1, ..., amin, ..., aw )
819 // int_0^y1 ds1/(s1-b1) ... int dsr/(sr-br) G(a1,...,sr,...,aw,y2)
820 // where sr replaces amin
822 // find smallest alpha, determine depth and trailing zeros, and check for convergence
824 int depth, trailing_zeros;
825 Gparameter::const_iterator min_it;
826 Gparameter::const_iterator firstzero =
827 check_parameter_G(a, scale, convergent, depth, trailing_zeros, min_it);
828 int min_it_pos = min_it - a.begin();
830 // special case: all a's are zero
837 result = G_eval(a, scale);
839 if (pendint.size() > 0) {
840 result *= trailing_zeros_G(convert_pending_integrals_G(pendint), pendint.front());
845 // handle trailing zeros
846 if (trailing_zeros > 0) {
848 Gparameter new_a(a.begin(), a.end()-1);
849 result += G_eval1(0, scale) * G_transform(pendint, new_a, scale);
850 for (Gparameter::const_iterator it = a.begin(); it != firstzero; ++it) {
851 Gparameter new_a(a.begin(), it);
853 new_a.insert(new_a.end(), it, a.end()-1);
854 result -= G_transform(pendint, new_a, scale);
856 return result / trailing_zeros;
861 if (pendint.size() > 0) {
862 return G_eval(convert_pending_integrals_G(pendint), pendint.front()) * G_eval(a, scale);
864 return G_eval(a, scale);
868 // call basic transformation for depth equal one
870 return depth_one_trafo_G(pendint, a, scale);
874 // int_0^y1 ds1/(s1-b1) ... int dsr/(sr-br) G(a1,...,sr,...,aw,y2)
875 // = int_0^y1 ds1/(s1-b1) ... int dsr/(sr-br) G(a1,...,0,...,aw,y2)
876 // + int_0^y1 ds1/(s1-b1) ... int dsr/(sr-br) int_0^{sr} ds_{r+1} d/ds_{r+1} G(a1,...,s_{r+1},...,aw,y2)
878 // smallest element in last place
879 if (min_it + 1 == a.end()) {
880 do { --min_it; } while (*min_it == 0);
882 Gparameter a1(a.begin(),min_it+1);
883 Gparameter a2(min_it+1,a.end());
885 ex result = G_transform(pendint,a2,scale)*G_transform(empty,a1,scale);
887 result -= shuffle_G(empty,a1,a2,pendint,a,scale);
892 Gparameter::iterator changeit;
894 // first term G(a_1,..,0,...,a_w;a_0)
895 Gparameter new_pendint = prepare_pending_integrals(pendint, a[min_it_pos]);
896 Gparameter new_a = a;
897 new_a[min_it_pos] = 0;
898 ex result = G_transform(empty, new_a, scale);
899 if (pendint.size() > 0) {
900 result *= trailing_zeros_G(convert_pending_integrals_G(pendint), pendint.front());
904 changeit = new_a.begin() + min_it_pos;
905 changeit = new_a.erase(changeit);
906 if (changeit != new_a.begin()) {
907 // smallest in the middle
908 new_pendint.push_back(*changeit);
909 result -= trailing_zeros_G(convert_pending_integrals_G(new_pendint), new_pendint.front())
910 * G_transform(empty, new_a, scale);
911 int buffer = *changeit;
913 result += G_transform(new_pendint, new_a, scale);
915 new_pendint.pop_back();
917 new_pendint.push_back(*changeit);
918 result += trailing_zeros_G(convert_pending_integrals_G(new_pendint), new_pendint.front())
919 * G_transform(empty, new_a, scale);
921 result -= G_transform(new_pendint, new_a, scale);
923 // smallest at the front
924 new_pendint.push_back(scale);
925 result += trailing_zeros_G(convert_pending_integrals_G(new_pendint), new_pendint.front())
926 * G_transform(empty, new_a, scale);
927 new_pendint.back() = *changeit;
928 result -= trailing_zeros_G(convert_pending_integrals_G(new_pendint), new_pendint.front())
929 * G_transform(empty, new_a, scale);
931 result += G_transform(new_pendint, new_a, scale);
937 // shuffles the two parameter list a1 and a2 and calls G_transform for every term except
938 // for the one that is equal to a_old
939 ex shuffle_G(const Gparameter & a0, const Gparameter & a1, const Gparameter & a2,
940 const Gparameter& pendint, const Gparameter& a_old, int scale)
942 if (a1.size()==0 && a2.size()==0) {
943 // veto the one configuration we don't want
944 if ( a0 == a_old ) return 0;
946 return G_transform(pendint,a0,scale);
952 aa0.insert(aa0.end(),a1.begin(),a1.end());
953 return shuffle_G(aa0,empty,empty,pendint,a_old,scale);
959 aa0.insert(aa0.end(),a2.begin(),a2.end());
960 return shuffle_G(aa0,empty,empty,pendint,a_old,scale);
963 Gparameter a1_removed(a1.begin()+1,a1.end());
964 Gparameter a2_removed(a2.begin()+1,a2.end());
969 a01.push_back( a1[0] );
970 a02.push_back( a2[0] );
972 return shuffle_G(a01,a1_removed,a2,pendint,a_old,scale)
973 + shuffle_G(a02,a1,a2_removed,pendint,a_old,scale);
977 // handles the transformations and the numerical evaluation of G
978 // the parameter x, s and y must only contain numerics
979 ex G_numeric(const lst& x, const lst& s, const ex& y)
981 // check for convergence and necessary accelerations
982 bool need_trafo = false;
983 bool need_hoelder = false;
985 for (lst::const_iterator it = x.begin(); it != x.end(); ++it) {
986 if (!(*it).is_zero()) {
988 if (abs(*it) - y < -pow(10,-Digits+1)) {
991 if (abs((abs(*it) - y)/y) < 0.01) {
996 if (x.op(x.nops()-1).is_zero()) {
999 if (depth == 1 && x.nops() == 2 && !need_trafo) {
1000 return -Li(x.nops(), y / x.op(x.nops()-1)).evalf();
1003 // do acceleration transformation (hoelder convolution [BBB])
1007 const int size = x.nops();
1009 for (lst::const_iterator it = x.begin(); it != x.end(); ++it) {
1010 newx.append(*it / y);
1013 for (int r=0; r<=size; ++r) {
1014 ex buffer = pow(-1, r);
1019 for (lst::const_iterator it = newx.begin(); it != newx.end(); ++it) {
1030 for (int j=r; j>=1; --j) {
1031 qlstx.append(1-newx.op(j-1));
1032 if (newx.op(j-1).info(info_flags::real) && newx.op(j-1) > 1 && newx.op(j-1) <= 2) {
1033 qlsts.append( s.op(j-1));
1035 qlsts.append( -s.op(j-1));
1038 if (qlstx.nops() > 0) {
1039 buffer *= G_numeric(qlstx, qlsts, 1/q);
1043 for (int j=r+1; j<=size; ++j) {
1044 plstx.append(newx.op(j-1));
1045 plsts.append(s.op(j-1));
1047 if (plstx.nops() > 0) {
1048 buffer *= G_numeric(plstx, plsts, 1/p);
1055 // convergence transformation
1058 // sort (|x|<->position) to determine indices
1059 std::multimap<ex,int> sortmap;
1061 for (int i=0; i<x.nops(); ++i) {
1062 if (!x[i].is_zero()) {
1063 sortmap.insert(std::pair<ex,int>(abs(x[i]), i));
1067 // include upper limit (scale)
1068 sortmap.insert(std::pair<ex,int>(abs(y), x.nops()));
1070 // generate missing dummy-symbols
1073 gsyms.push_back(symbol("GSYMS_ERROR"));
1075 for (std::multimap<ex,int>::const_iterator it = sortmap.begin(); it != sortmap.end(); ++it) {
1076 if (it != sortmap.begin()) {
1077 if (it->second < x.nops()) {
1078 if (x[it->second] == lastentry) {
1079 gsyms.push_back(gsyms.back());
1083 if (y == lastentry) {
1084 gsyms.push_back(gsyms.back());
1089 std::ostringstream os;
1091 gsyms.push_back(symbol(os.str()));
1093 if (it->second < x.nops()) {
1094 lastentry = x[it->second];
1100 // fill position data according to sorted indices and prepare substitution list
1101 Gparameter a(x.nops());
1105 for (std::multimap<ex,int>::const_iterator it = sortmap.begin(); it != sortmap.end(); ++it) {
1106 if (it->second < x.nops()) {
1107 if (s[it->second] > 0) {
1108 a[it->second] = pos;
1110 a[it->second] = -pos;
1112 subslst.append(gsyms[pos] == x[it->second]);
1115 subslst.append(gsyms[pos] == y);
1120 // do transformation
1122 ex result = G_transform(pendint, a, scale);
1123 // replace dummy symbols with their values
1124 result = result.eval().expand();
1125 result = result.subs(subslst).evalf();
1136 for (lst::const_iterator it = x.begin(); it != x.end(); ++it) {
1137 if ((*it).is_zero()) {
1140 newx.append(factor / (*it));
1148 return sign * numeric(mLi_do_summation(m, newx));
1152 ex mLi_numeric(const lst& m, const lst& x)
1154 // let G_numeric do the transformation
1158 for (lst::const_iterator itm = m.begin(), itx = x.begin(); itm != m.end(); ++itm, ++itx) {
1159 for (int i = 1; i < *itm; ++i) {
1163 newx.append(factor / *itx);
1167 return pow(-1, m.nops()) * G_numeric(newx, s, _ex1);
1171 } // end of anonymous namespace
1174 //////////////////////////////////////////////////////////////////////
1176 // Generalized multiple polylogarithm G(x, y) and G(x, s, y)
1180 //////////////////////////////////////////////////////////////////////
1183 static ex G2_evalf(const ex& x_, const ex& y)
1185 if (!y.info(info_flags::positive)) {
1186 return G(x_, y).hold();
1188 lst x = is_a<lst>(x_) ? ex_to<lst>(x_) : lst(x_);
1189 if (x.nops() == 0) {
1193 return G(x_, y).hold();
1196 bool all_zero = true;
1197 for (lst::const_iterator it = x.begin(); it != x.end(); ++it) {
1198 if (!(*it).info(info_flags::numeric)) {
1199 return G(x_, y).hold();
1207 return pow(log(y), x.nops()) / factorial(x.nops());
1209 return G_numeric(x, s, y);
1213 static ex G2_eval(const ex& x_, const ex& y)
1215 //TODO eval to MZV or H or S or Lin
1217 if (!y.info(info_flags::positive)) {
1218 return G(x_, y).hold();
1220 lst x = is_a<lst>(x_) ? ex_to<lst>(x_) : lst(x_);
1221 if (x.nops() == 0) {
1225 return G(x_, y).hold();
1228 bool all_zero = true;
1229 bool crational = true;
1230 for (lst::const_iterator it = x.begin(); it != x.end(); ++it) {
1231 if (!(*it).info(info_flags::numeric)) {
1232 return G(x_, y).hold();
1234 if (!(*it).info(info_flags::crational)) {
1243 return pow(log(y), x.nops()) / factorial(x.nops());
1245 if (!y.info(info_flags::crational)) {
1249 return G(x_, y).hold();
1251 return G_numeric(x, s, y);
1255 unsigned G2_SERIAL::serial = function::register_new(function_options("G", 2).
1256 evalf_func(G2_evalf).
1258 do_not_evalf_params().
1261 // derivative_func(G2_deriv).
1262 // print_func<print_latex>(G2_print_latex).
1265 static ex G3_evalf(const ex& x_, const ex& s_, const ex& y)
1267 if (!y.info(info_flags::positive)) {
1268 return G(x_, s_, y).hold();
1270 lst x = is_a<lst>(x_) ? ex_to<lst>(x_) : lst(x_);
1271 lst s = is_a<lst>(s_) ? ex_to<lst>(s_) : lst(s_);
1272 if (x.nops() != s.nops()) {
1273 return G(x_, s_, y).hold();
1275 if (x.nops() == 0) {
1279 return G(x_, s_, y).hold();
1282 bool all_zero = true;
1283 for (lst::const_iterator itx = x.begin(), its = s.begin(); itx != x.end(); ++itx, ++its) {
1284 if (!(*itx).info(info_flags::numeric)) {
1285 return G(x_, y).hold();
1287 if (!(*its).info(info_flags::real)) {
1288 return G(x_, y).hold();
1300 return pow(log(y), x.nops()) / factorial(x.nops());
1302 return G_numeric(x, sn, y);
1306 static ex G3_eval(const ex& x_, const ex& s_, const ex& y)
1308 //TODO eval to MZV or H or S or Lin
1310 if (!y.info(info_flags::positive)) {
1311 return G(x_, s_, y).hold();
1313 lst x = is_a<lst>(x_) ? ex_to<lst>(x_) : lst(x_);
1314 lst s = is_a<lst>(s_) ? ex_to<lst>(s_) : lst(s_);
1315 if (x.nops() != s.nops()) {
1316 return G(x_, s_, y).hold();
1318 if (x.nops() == 0) {
1322 return G(x_, s_, y).hold();
1325 bool all_zero = true;
1326 bool crational = true;
1327 for (lst::const_iterator itx = x.begin(), its = s.begin(); itx != x.end(); ++itx, ++its) {
1328 if (!(*itx).info(info_flags::numeric)) {
1329 return G(x_, s_, y).hold();
1331 if (!(*its).info(info_flags::real)) {
1332 return G(x_, s_, y).hold();
1334 if (!(*itx).info(info_flags::crational)) {
1347 return pow(log(y), x.nops()) / factorial(x.nops());
1349 if (!y.info(info_flags::crational)) {
1353 return G(x_, s_, y).hold();
1355 return G_numeric(x, sn, y);
1359 unsigned G3_SERIAL::serial = function::register_new(function_options("G", 3).
1360 evalf_func(G3_evalf).
1362 do_not_evalf_params().
1365 // derivative_func(G3_deriv).
1366 // print_func<print_latex>(G3_print_latex).
1369 //////////////////////////////////////////////////////////////////////
1371 // Classical polylogarithm and multiple polylogarithm Li(m,x)
1375 //////////////////////////////////////////////////////////////////////
1378 static ex Li_evalf(const ex& m_, const ex& x_)
1380 // classical polylogs
1381 if (m_.info(info_flags::posint)) {
1382 if (x_.info(info_flags::numeric)) {
1383 return Lin_numeric(ex_to<numeric>(m_).to_int(), ex_to<numeric>(x_));
1385 // try to numerically evaluate second argument
1386 ex x_val = x_.evalf();
1387 if (x_val.info(info_flags::numeric)) {
1388 return Lin_numeric(ex_to<numeric>(m_).to_int(), ex_to<numeric>(x_val));
1392 // multiple polylogs
1393 if (is_a<lst>(m_) && is_a<lst>(x_)) {
1395 const lst& m = ex_to<lst>(m_);
1396 const lst& x = ex_to<lst>(x_);
1397 if (m.nops() != x.nops()) {
1398 return Li(m_,x_).hold();
1400 if (x.nops() == 0) {
1403 if ((m.op(0) == _ex1) && (x.op(0) == _ex1)) {
1404 return Li(m_,x_).hold();
1407 for (lst::const_iterator itm = m.begin(), itx = x.begin(); itm != m.end(); ++itm, ++itx) {
1408 if (!(*itm).info(info_flags::posint)) {
1409 return Li(m_, x_).hold();
1411 if (!(*itx).info(info_flags::numeric)) {
1412 return Li(m_, x_).hold();
1419 return mLi_numeric(m, x);
1422 return Li(m_,x_).hold();
1426 static ex Li_eval(const ex& m_, const ex& x_)
1428 if (is_a<lst>(m_)) {
1429 if (is_a<lst>(x_)) {
1430 // multiple polylogs
1431 const lst& m = ex_to<lst>(m_);
1432 const lst& x = ex_to<lst>(x_);
1433 if (m.nops() != x.nops()) {
1434 return Li(m_,x_).hold();
1436 if (x.nops() == 0) {
1440 bool is_zeta = true;
1441 bool do_evalf = true;
1442 bool crational = true;
1443 for (lst::const_iterator itm = m.begin(), itx = x.begin(); itm != m.end(); ++itm, ++itx) {
1444 if (!(*itm).info(info_flags::posint)) {
1445 return Li(m_,x_).hold();
1447 if ((*itx != _ex1) && (*itx != _ex_1)) {
1448 if (itx != x.begin()) {
1456 if (!(*itx).info(info_flags::numeric)) {
1459 if (!(*itx).info(info_flags::crational)) {
1468 lst newm = convert_parameter_Li_to_H(m, x, prefactor);
1469 return prefactor * H(newm, x[0]);
1471 if (do_evalf && !crational) {
1472 return mLi_numeric(m,x);
1475 return Li(m_, x_).hold();
1476 } else if (is_a<lst>(x_)) {
1477 return Li(m_, x_).hold();
1480 // classical polylogs
1488 return (pow(2,1-m_)-1) * zeta(m_);
1494 if (x_.is_equal(I)) {
1495 return power(Pi,_ex2)/_ex_48 + Catalan*I;
1497 if (x_.is_equal(-I)) {
1498 return power(Pi,_ex2)/_ex_48 - Catalan*I;
1501 if (m_.info(info_flags::posint) && x_.info(info_flags::numeric) && !x_.info(info_flags::crational)) {
1502 return Lin_numeric(ex_to<numeric>(m_).to_int(), ex_to<numeric>(x_));
1505 return Li(m_, x_).hold();
1509 static ex Li_series(const ex& m, const ex& x, const relational& rel, int order, unsigned options)
1511 if (is_a<lst>(m) || is_a<lst>(x)) {
1514 seq.push_back(expair(Li(m, x), 0));
1515 return pseries(rel, seq);
1518 // classical polylog
1519 const ex x_pt = x.subs(rel, subs_options::no_pattern);
1520 if (m.info(info_flags::numeric) && x_pt.info(info_flags::numeric)) {
1521 // First special case: x==0 (derivatives have poles)
1522 if (x_pt.is_zero()) {
1525 // manually construct the primitive expansion
1526 for (int i=1; i<order; ++i)
1527 ser += pow(s,i) / pow(numeric(i), m);
1528 // substitute the argument's series expansion
1529 ser = ser.subs(s==x.series(rel, order), subs_options::no_pattern);
1530 // maybe that was terminating, so add a proper order term
1532 nseq.push_back(expair(Order(_ex1), order));
1533 ser += pseries(rel, nseq);
1534 // reexpanding it will collapse the series again
1535 return ser.series(rel, order);
1537 // TODO special cases: x==1 (branch point) and x real, >=1 (branch cut)
1538 throw std::runtime_error("Li_series: don't know how to do the series expansion at this point!");
1540 // all other cases should be safe, by now:
1541 throw do_taylor(); // caught by function::series()
1545 static ex Li_deriv(const ex& m_, const ex& x_, unsigned deriv_param)
1547 GINAC_ASSERT(deriv_param < 2);
1548 if (deriv_param == 0) {
1551 if (m_.nops() > 1) {
1552 throw std::runtime_error("don't know how to derivate multiple polylogarithm!");
1555 if (is_a<lst>(m_)) {
1561 if (is_a<lst>(x_)) {
1567 return Li(m-1, x) / x;
1574 static void Li_print_latex(const ex& m_, const ex& x_, const print_context& c)
1577 if (is_a<lst>(m_)) {
1583 if (is_a<lst>(x_)) {
1588 c.s << "\\mbox{Li}_{";
1589 lst::const_iterator itm = m.begin();
1592 for (; itm != m.end(); itm++) {
1597 lst::const_iterator itx = x.begin();
1600 for (; itx != x.end(); itx++) {
1608 REGISTER_FUNCTION(Li,
1609 evalf_func(Li_evalf).
1611 series_func(Li_series).
1612 derivative_func(Li_deriv).
1613 print_func<print_latex>(Li_print_latex).
1614 do_not_evalf_params());
1617 //////////////////////////////////////////////////////////////////////
1619 // Nielsen's generalized polylogarithm S(n,p,x)
1623 //////////////////////////////////////////////////////////////////////
1626 // anonymous namespace for helper functions
1630 // lookup table for special Euler-Zagier-Sums (used for S_n,p(x))
1632 std::vector<std::vector<cln::cl_N> > Yn;
1633 int ynsize = 0; // number of Yn[]
1634 int ynlength = 100; // initial length of all Yn[i]
1637 // This function calculates the Y_n. The Y_n are needed for the evaluation of S_{n,p}(x).
1638 // The Y_n are basically Euler-Zagier sums with all m_i=1. They are subsums in the Z-sum
1639 // representing S_{n,p}(x).
1640 // The first index in Y_n corresponds to the parameter p minus one, i.e. the depth of the
1641 // equivalent Z-sum.
1642 // The second index in Y_n corresponds to the running index of the outermost sum in the full Z-sum
1643 // representing S_{n,p}(x).
1644 // The calculation of Y_n uses the values from Y_{n-1}.
1645 void fill_Yn(int n, const cln::float_format_t& prec)
1647 const int initsize = ynlength;
1648 //const int initsize = initsize_Yn;
1649 cln::cl_N one = cln::cl_float(1, prec);
1652 std::vector<cln::cl_N> buf(initsize);
1653 std::vector<cln::cl_N>::iterator it = buf.begin();
1654 std::vector<cln::cl_N>::iterator itprev = Yn[n-1].begin();
1655 *it = (*itprev) / cln::cl_N(n+1) * one;
1658 // sums with an index smaller than the depth are zero and need not to be calculated.
1659 // calculation starts with depth, which is n+2)
1660 for (int i=n+2; i<=initsize+n; i++) {
1661 *it = *(it-1) + (*itprev) / cln::cl_N(i) * one;
1667 std::vector<cln::cl_N> buf(initsize);
1668 std::vector<cln::cl_N>::iterator it = buf.begin();
1671 for (int i=2; i<=initsize; i++) {
1672 *it = *(it-1) + 1 / cln::cl_N(i) * one;
1681 // make Yn longer ...
1682 void make_Yn_longer(int newsize, const cln::float_format_t& prec)
1685 cln::cl_N one = cln::cl_float(1, prec);
1687 Yn[0].resize(newsize);
1688 std::vector<cln::cl_N>::iterator it = Yn[0].begin();
1690 for (int i=ynlength+1; i<=newsize; i++) {
1691 *it = *(it-1) + 1 / cln::cl_N(i) * one;
1695 for (int n=1; n<ynsize; n++) {
1696 Yn[n].resize(newsize);
1697 std::vector<cln::cl_N>::iterator it = Yn[n].begin();
1698 std::vector<cln::cl_N>::iterator itprev = Yn[n-1].begin();
1701 for (int i=ynlength+n+1; i<=newsize+n; i++) {
1702 *it = *(it-1) + (*itprev) / cln::cl_N(i) * one;
1712 // helper function for S(n,p,x)
1714 cln::cl_N C(int n, int p)
1718 for (int k=0; k<p; k++) {
1719 for (int j=0; j<=(n+k-1)/2; j++) {
1723 result = result - 2 * cln::expt(cln::pi(),2*j) * S_num(n-2*j,p,1) / cln::factorial(2*j);
1726 result = result + 2 * cln::expt(cln::pi(),2*j) * S_num(n-2*j,p,1) / cln::factorial(2*j);
1733 result = result + cln::factorial(n+k-1)
1734 * cln::expt(cln::pi(),2*j) * S_num(n+k-2*j,p-k,1)
1735 / (cln::factorial(k) * cln::factorial(n-1) * cln::factorial(2*j));
1738 result = result - cln::factorial(n+k-1)
1739 * cln::expt(cln::pi(),2*j) * S_num(n+k-2*j,p-k,1)
1740 / (cln::factorial(k) * cln::factorial(n-1) * cln::factorial(2*j));
1745 result = result - cln::factorial(n+k-1) * cln::expt(cln::pi(),2*j) * S_num(n+k-2*j,p-k,1)
1746 / (cln::factorial(k) * cln::factorial(n-1) * cln::factorial(2*j));
1749 result = result + cln::factorial(n+k-1)
1750 * cln::expt(cln::pi(),2*j) * S_num(n+k-2*j,p-k,1)
1751 / (cln::factorial(k) * cln::factorial(n-1) * cln::factorial(2*j));
1759 if (((np)/2+n) & 1) {
1760 result = -result - cln::expt(cln::pi(),np) / (np * cln::factorial(n-1) * cln::factorial(p));
1763 result = -result + cln::expt(cln::pi(),np) / (np * cln::factorial(n-1) * cln::factorial(p));
1771 // helper function for S(n,p,x)
1772 // [Kol] remark to (9.1)
1773 cln::cl_N a_k(int k)
1782 for (int m=2; m<=k; m++) {
1783 result = result + cln::expt(cln::cl_N(-1),m) * cln::zeta(m) * a_k(k-m);
1790 // helper function for S(n,p,x)
1791 // [Kol] remark to (9.1)
1792 cln::cl_N b_k(int k)
1801 for (int m=2; m<=k; m++) {
1802 result = result + cln::expt(cln::cl_N(-1),m) * cln::zeta(m) * b_k(k-m);
1809 // helper function for S(n,p,x)
1810 cln::cl_N S_do_sum(int n, int p, const cln::cl_N& x, const cln::float_format_t& prec)
1812 static cln::float_format_t oldprec = cln::default_float_format;
1815 return Li_projection(n+1, x, prec);
1818 // precision has changed, we need to clear lookup table Yn
1819 if ( oldprec != prec ) {
1826 // check if precalculated values are sufficient
1828 for (int i=ynsize; i<p-1; i++) {
1833 // should be done otherwise
1834 cln::cl_F one = cln::cl_float(1, cln::float_format(Digits));
1835 cln::cl_N xf = x * one;
1836 //cln::cl_N xf = x * cln::cl_float(1, prec);
1840 cln::cl_N factor = cln::expt(xf, p);
1844 if (i-p >= ynlength) {
1846 make_Yn_longer(ynlength*2, prec);
1848 res = res + factor / cln::expt(cln::cl_I(i),n+1) * Yn[p-2][i-p]; // should we check it? or rely on magic number? ...
1849 //res = res + factor / cln::expt(cln::cl_I(i),n+1) * (*it); // should we check it? or rely on magic number? ...
1850 factor = factor * xf;
1852 } while (res != resbuf);
1858 // helper function for S(n,p,x)
1859 cln::cl_N S_projection(int n, int p, const cln::cl_N& x, const cln::float_format_t& prec)
1862 if (cln::abs(cln::realpart(x)) > cln::cl_F("0.5")) {
1864 cln::cl_N result = cln::expt(cln::cl_I(-1),p) * cln::expt(cln::log(x),n)
1865 * cln::expt(cln::log(1-x),p) / cln::factorial(n) / cln::factorial(p);
1867 for (int s=0; s<n; s++) {
1869 for (int r=0; r<p; r++) {
1870 res2 = res2 + cln::expt(cln::cl_I(-1),r) * cln::expt(cln::log(1-x),r)
1871 * S_do_sum(p-r,n-s,1-x,prec) / cln::factorial(r);
1873 result = result + cln::expt(cln::log(x),s) * (S_num(n-s,p,1) - res2) / cln::factorial(s);
1879 return S_do_sum(n, p, x, prec);
1883 // helper function for S(n,p,x)
1884 const cln::cl_N S_num(int n, int p, const cln::cl_N& x)
1888 // [Kol] (2.22) with (2.21)
1889 return cln::zeta(p+1);
1894 return cln::zeta(n+1);
1899 for (int nu=0; nu<n; nu++) {
1900 for (int rho=0; rho<=p; rho++) {
1901 result = result + b_k(n-nu-1) * b_k(p-rho) * a_k(nu+rho+1)
1902 * cln::factorial(nu+rho+1) / cln::factorial(rho) / cln::factorial(nu+1);
1905 result = result * cln::expt(cln::cl_I(-1),n+p-1);
1912 return -(1-cln::expt(cln::cl_I(2),-n)) * cln::zeta(n+1);
1914 // throw std::runtime_error("don't know how to evaluate this function!");
1917 // what is the desired float format?
1918 // first guess: default format
1919 cln::float_format_t prec = cln::default_float_format;
1920 const cln::cl_N value = x;
1921 // second guess: the argument's format
1922 if (!instanceof(realpart(value), cln::cl_RA_ring))
1923 prec = cln::float_format(cln::the<cln::cl_F>(cln::realpart(value)));
1924 else if (!instanceof(imagpart(value), cln::cl_RA_ring))
1925 prec = cln::float_format(cln::the<cln::cl_F>(cln::imagpart(value)));
1928 if ((cln::realpart(value) < -0.5) || (n == 0) || ((cln::abs(value) <= 1) && (cln::abs(value) > 0.95))) {
1930 cln::cl_N result = cln::expt(cln::cl_I(-1),p) * cln::expt(cln::log(value),n)
1931 * cln::expt(cln::log(1-value),p) / cln::factorial(n) / cln::factorial(p);
1933 for (int s=0; s<n; s++) {
1935 for (int r=0; r<p; r++) {
1936 res2 = res2 + cln::expt(cln::cl_I(-1),r) * cln::expt(cln::log(1-value),r)
1937 * S_num(p-r,n-s,1-value) / cln::factorial(r);
1939 result = result + cln::expt(cln::log(value),s) * (S_num(n-s,p,1) - res2) / cln::factorial(s);
1946 if (cln::abs(value) > 1) {
1950 for (int s=0; s<p; s++) {
1951 for (int r=0; r<=s; r++) {
1952 result = result + cln::expt(cln::cl_I(-1),s) * cln::expt(cln::log(-value),r) * cln::factorial(n+s-r-1)
1953 / cln::factorial(r) / cln::factorial(s-r) / cln::factorial(n-1)
1954 * S_num(n+s-r,p-s,cln::recip(value));
1957 result = result * cln::expt(cln::cl_I(-1),n);
1960 for (int r=0; r<n; r++) {
1961 res2 = res2 + cln::expt(cln::log(-value),r) * C(n-r,p) / cln::factorial(r);
1963 res2 = res2 + cln::expt(cln::log(-value),n+p) / cln::factorial(n+p);
1965 result = result + cln::expt(cln::cl_I(-1),p) * res2;
1970 return S_projection(n, p, value, prec);
1975 } // end of anonymous namespace
1978 //////////////////////////////////////////////////////////////////////
1980 // Nielsen's generalized polylogarithm S(n,p,x)
1984 //////////////////////////////////////////////////////////////////////
1987 static ex S_evalf(const ex& n, const ex& p, const ex& x)
1989 if (n.info(info_flags::posint) && p.info(info_flags::posint)) {
1990 const int n_ = ex_to<numeric>(n).to_int();
1991 const int p_ = ex_to<numeric>(p).to_int();
1992 if (is_a<numeric>(x)) {
1993 const cln::cl_N x_ = ex_to<numeric>(x).to_cl_N();
1994 const cln::cl_N result = S_num(n_, p_, x_);
1995 return numeric(result);
1997 ex x_val = x.evalf();
1998 if (is_a<numeric>(x_val)) {
1999 const cln::cl_N x_val_ = ex_to<numeric>(x_val).to_cl_N();
2000 const cln::cl_N result = S_num(n_, p_, x_val_);
2001 return numeric(result);
2005 return S(n, p, x).hold();
2009 static ex S_eval(const ex& n, const ex& p, const ex& x)
2011 if (n.info(info_flags::posint) && p.info(info_flags::posint)) {
2017 for (int i=ex_to<numeric>(p).to_int()-1; i>0; i--) {
2025 if (x.info(info_flags::numeric) && (!x.info(info_flags::crational))) {
2026 int n_ = ex_to<numeric>(n).to_int();
2027 int p_ = ex_to<numeric>(p).to_int();
2028 const cln::cl_N x_ = ex_to<numeric>(x).to_cl_N();
2029 const cln::cl_N result = S_num(n_, p_, x_);
2030 return numeric(result);
2035 return pow(-log(1-x), p) / factorial(p);
2037 return S(n, p, x).hold();
2041 static ex S_series(const ex& n, const ex& p, const ex& x, const relational& rel, int order, unsigned options)
2044 return Li(n+1, x).series(rel, order, options);
2047 const ex x_pt = x.subs(rel, subs_options::no_pattern);
2048 if (n.info(info_flags::posint) && p.info(info_flags::posint) && x_pt.info(info_flags::numeric)) {
2049 // First special case: x==0 (derivatives have poles)
2050 if (x_pt.is_zero()) {
2053 // manually construct the primitive expansion
2054 // subsum = Euler-Zagier-Sum is needed
2055 // dirty hack (slow ...) calculation of subsum:
2056 std::vector<ex> presubsum, subsum;
2057 subsum.push_back(0);
2058 for (int i=1; i<order-1; ++i) {
2059 subsum.push_back(subsum[i-1] + numeric(1, i));
2061 for (int depth=2; depth<p; ++depth) {
2063 for (int i=1; i<order-1; ++i) {
2064 subsum[i] = subsum[i-1] + numeric(1, i) * presubsum[i-1];
2068 for (int i=1; i<order; ++i) {
2069 ser += pow(s,i) / pow(numeric(i), n+1) * subsum[i-1];
2071 // substitute the argument's series expansion
2072 ser = ser.subs(s==x.series(rel, order), subs_options::no_pattern);
2073 // maybe that was terminating, so add a proper order term
2075 nseq.push_back(expair(Order(_ex1), order));
2076 ser += pseries(rel, nseq);
2077 // reexpanding it will collapse the series again
2078 return ser.series(rel, order);
2080 // TODO special cases: x==1 (branch point) and x real, >=1 (branch cut)
2081 throw std::runtime_error("S_series: don't know how to do the series expansion at this point!");
2083 // all other cases should be safe, by now:
2084 throw do_taylor(); // caught by function::series()
2088 static ex S_deriv(const ex& n, const ex& p, const ex& x, unsigned deriv_param)
2090 GINAC_ASSERT(deriv_param < 3);
2091 if (deriv_param < 2) {
2095 return S(n-1, p, x) / x;
2097 return S(n, p-1, x) / (1-x);
2102 static void S_print_latex(const ex& n, const ex& p, const ex& x, const print_context& c)
2104 c.s << "\\mbox{S}_{";
2114 REGISTER_FUNCTION(S,
2115 evalf_func(S_evalf).
2117 series_func(S_series).
2118 derivative_func(S_deriv).
2119 print_func<print_latex>(S_print_latex).
2120 do_not_evalf_params());
2123 //////////////////////////////////////////////////////////////////////
2125 // Harmonic polylogarithm H(m,x)
2129 //////////////////////////////////////////////////////////////////////
2132 // anonymous namespace for helper functions
2136 // regulates the pole (used by 1/x-transformation)
2137 symbol H_polesign("IMSIGN");
2140 // convert parameters from H to Li representation
2141 // parameters are expected to be in expanded form, i.e. only 0, 1 and -1
2142 // returns true if some parameters are negative
2143 bool convert_parameter_H_to_Li(const lst& l, lst& m, lst& s, ex& pf)
2145 // expand parameter list
2147 for (lst::const_iterator it = l.begin(); it != l.end(); it++) {
2149 for (ex count=*it-1; count > 0; count--) {
2153 } else if (*it < -1) {
2154 for (ex count=*it+1; count < 0; count++) {
2165 bool has_negative_parameters = false;
2167 for (lst::const_iterator it = mexp.begin(); it != mexp.end(); it++) {
2173 m.append((*it+acc-1) * signum);
2175 m.append((*it-acc+1) * signum);
2181 has_negative_parameters = true;
2184 if (has_negative_parameters) {
2185 for (int i=0; i<m.nops(); i++) {
2187 m.let_op(i) = -m.op(i);
2195 return has_negative_parameters;
2199 // recursivly transforms H to corresponding multiple polylogarithms
2200 struct map_trafo_H_convert_to_Li : public map_function
2202 ex operator()(const ex& e)
2204 if (is_a<add>(e) || is_a<mul>(e)) {
2205 return e.map(*this);
2207 if (is_a<function>(e)) {
2208 std::string name = ex_to<function>(e).get_name();
2211 if (is_a<lst>(e.op(0))) {
2212 parameter = ex_to<lst>(e.op(0));
2214 parameter = lst(e.op(0));
2221 if (convert_parameter_H_to_Li(parameter, m, s, pf)) {
2222 s.let_op(0) = s.op(0) * arg;
2223 return pf * Li(m, s).hold();
2225 for (int i=0; i<m.nops(); i++) {
2228 s.let_op(0) = s.op(0) * arg;
2229 return Li(m, s).hold();
2238 // recursivly transforms H to corresponding zetas
2239 struct map_trafo_H_convert_to_zeta : public map_function
2241 ex operator()(const ex& e)
2243 if (is_a<add>(e) || is_a<mul>(e)) {
2244 return e.map(*this);
2246 if (is_a<function>(e)) {
2247 std::string name = ex_to<function>(e).get_name();
2250 if (is_a<lst>(e.op(0))) {
2251 parameter = ex_to<lst>(e.op(0));
2253 parameter = lst(e.op(0));
2259 if (convert_parameter_H_to_Li(parameter, m, s, pf)) {
2260 return pf * zeta(m, s);
2271 // remove trailing zeros from H-parameters
2272 struct map_trafo_H_reduce_trailing_zeros : public map_function
2274 ex operator()(const ex& e)
2276 if (is_a<add>(e) || is_a<mul>(e)) {
2277 return e.map(*this);
2279 if (is_a<function>(e)) {
2280 std::string name = ex_to<function>(e).get_name();
2283 if (is_a<lst>(e.op(0))) {
2284 parameter = ex_to<lst>(e.op(0));
2286 parameter = lst(e.op(0));
2289 if (parameter.op(parameter.nops()-1) == 0) {
2292 if (parameter.nops() == 1) {
2297 lst::const_iterator it = parameter.begin();
2298 while ((it != parameter.end()) && (*it == 0)) {
2301 if (it == parameter.end()) {
2302 return pow(log(arg),parameter.nops()) / factorial(parameter.nops());
2306 parameter.remove_last();
2307 int lastentry = parameter.nops();
2308 while ((lastentry > 0) && (parameter[lastentry-1] == 0)) {
2313 ex result = log(arg) * H(parameter,arg).hold();
2315 for (ex i=0; i<lastentry; i++) {
2316 if (parameter[i] > 0) {
2318 result -= (acc + parameter[i]-1) * H(parameter, arg).hold();
2321 } else if (parameter[i] < 0) {
2323 result -= (acc + abs(parameter[i]+1)) * H(parameter, arg).hold();
2331 if (lastentry < parameter.nops()) {
2332 result = result / (parameter.nops()-lastentry+1);
2333 return result.map(*this);
2345 // returns an expression with zeta functions corresponding to the parameter list for H
2346 ex convert_H_to_zeta(const lst& m)
2348 symbol xtemp("xtemp");
2349 map_trafo_H_reduce_trailing_zeros filter;
2350 map_trafo_H_convert_to_zeta filter2;
2351 return filter2(filter(H(m, xtemp).hold())).subs(xtemp == 1);
2355 // convert signs form Li to H representation
2356 lst convert_parameter_Li_to_H(const lst& m, const lst& x, ex& pf)
2359 lst::const_iterator itm = m.begin();
2360 lst::const_iterator itx = ++x.begin();
2365 while (itx != x.end()) {
2366 signum *= (*itx > 0) ? 1 : -1;
2368 res.append((*itm) * signum);
2376 // multiplies an one-dimensional H with another H
2378 ex trafo_H_mult(const ex& h1, const ex& h2)
2383 ex h1nops = h1.op(0).nops();
2384 ex h2nops = h2.op(0).nops();
2386 hshort = h2.op(0).op(0);
2387 hlong = ex_to<lst>(h1.op(0));
2389 hshort = h1.op(0).op(0);
2391 hlong = ex_to<lst>(h2.op(0));
2393 hlong = h2.op(0).op(0);
2396 for (int i=0; i<=hlong.nops(); i++) {
2400 newparameter.append(hlong[j]);
2402 newparameter.append(hshort);
2403 for (; j<hlong.nops(); j++) {
2404 newparameter.append(hlong[j]);
2406 res += H(newparameter, h1.op(1)).hold();
2412 // applies trafo_H_mult recursively on expressions
2413 struct map_trafo_H_mult : public map_function
2415 ex operator()(const ex& e)
2418 return e.map(*this);
2426 for (int pos=0; pos<e.nops(); pos++) {
2427 if (is_a<power>(e.op(pos)) && is_a<function>(e.op(pos).op(0))) {
2428 std::string name = ex_to<function>(e.op(pos).op(0)).get_name();
2430 for (ex i=0; i<e.op(pos).op(1); i++) {
2431 Hlst.append(e.op(pos).op(0));
2435 } else if (is_a<function>(e.op(pos))) {
2436 std::string name = ex_to<function>(e.op(pos)).get_name();
2438 if (e.op(pos).op(0).nops() > 1) {
2441 Hlst.append(e.op(pos));
2446 result *= e.op(pos);
2449 if (Hlst.nops() > 0) {
2450 firstH = Hlst[Hlst.nops()-1];
2457 if (Hlst.nops() > 0) {
2458 ex buffer = trafo_H_mult(firstH, Hlst.op(0));
2460 for (int i=1; i<Hlst.nops(); i++) {
2461 result *= Hlst.op(i);
2463 result = result.expand();
2464 map_trafo_H_mult recursion;
2465 return recursion(result);
2476 // do integration [ReV] (55)
2477 // put parameter 0 in front of existing parameters
2478 ex trafo_H_1tx_prepend_zero(const ex& e, const ex& arg)
2482 if (is_a<function>(e)) {
2483 name = ex_to<function>(e).get_name();
2488 for (int i=0; i<e.nops(); i++) {
2489 if (is_a<function>(e.op(i))) {
2490 std::string name = ex_to<function>(e.op(i)).get_name();
2498 lst newparameter = ex_to<lst>(h.op(0));
2499 newparameter.prepend(0);
2500 ex addzeta = convert_H_to_zeta(newparameter);
2501 return e.subs(h == (addzeta-H(newparameter, h.op(1)).hold())).expand();
2503 return e * (-H(lst(0),1/arg).hold());
2508 // do integration [ReV] (49)
2509 // put parameter 1 in front of existing parameters
2510 ex trafo_H_prepend_one(const ex& e, const ex& arg)
2514 if (is_a<function>(e)) {
2515 name = ex_to<function>(e).get_name();
2520 for (int i=0; i<e.nops(); i++) {
2521 if (is_a<function>(e.op(i))) {
2522 std::string name = ex_to<function>(e.op(i)).get_name();
2530 lst newparameter = ex_to<lst>(h.op(0));
2531 newparameter.prepend(1);
2532 return e.subs(h == H(newparameter, h.op(1)).hold());
2534 return e * H(lst(1),1-arg).hold();
2539 // do integration [ReV] (55)
2540 // put parameter -1 in front of existing parameters
2541 ex trafo_H_1tx_prepend_minusone(const ex& e, const ex& arg)
2545 if (is_a<function>(e)) {
2546 name = ex_to<function>(e).get_name();
2551 for (int i=0; i<e.nops(); i++) {
2552 if (is_a<function>(e.op(i))) {
2553 std::string name = ex_to<function>(e.op(i)).get_name();
2561 lst newparameter = ex_to<lst>(h.op(0));
2562 newparameter.prepend(-1);
2563 ex addzeta = convert_H_to_zeta(newparameter);
2564 return e.subs(h == (addzeta-H(newparameter, h.op(1)).hold())).expand();
2566 ex addzeta = convert_H_to_zeta(lst(-1));
2567 return (e * (addzeta - H(lst(-1),1/arg).hold())).expand();
2572 // do integration [ReV] (55)
2573 // put parameter -1 in front of existing parameters
2574 ex trafo_H_1mxt1px_prepend_minusone(const ex& e, const ex& arg)
2578 if (is_a<function>(e)) {
2579 name = ex_to<function>(e).get_name();
2584 for (int i=0; i<e.nops(); i++) {
2585 if (is_a<function>(e.op(i))) {
2586 std::string name = ex_to<function>(e.op(i)).get_name();
2594 lst newparameter = ex_to<lst>(h.op(0));
2595 newparameter.prepend(-1);
2596 return e.subs(h == H(newparameter, h.op(1)).hold()).expand();
2598 return (e * H(lst(-1),(1-arg)/(1+arg)).hold()).expand();
2603 // do integration [ReV] (55)
2604 // put parameter 1 in front of existing parameters
2605 ex trafo_H_1mxt1px_prepend_one(const ex& e, const ex& arg)
2609 if (is_a<function>(e)) {
2610 name = ex_to<function>(e).get_name();
2615 for (int i=0; i<e.nops(); i++) {
2616 if (is_a<function>(e.op(i))) {
2617 std::string name = ex_to<function>(e.op(i)).get_name();
2625 lst newparameter = ex_to<lst>(h.op(0));
2626 newparameter.prepend(1);
2627 return e.subs(h == H(newparameter, h.op(1)).hold()).expand();
2629 return (e * H(lst(1),(1-arg)/(1+arg)).hold()).expand();
2634 // do x -> 1-x transformation
2635 struct map_trafo_H_1mx : public map_function
2637 ex operator()(const ex& e)
2639 if (is_a<add>(e) || is_a<mul>(e)) {
2640 return e.map(*this);
2643 if (is_a<function>(e)) {
2644 std::string name = ex_to<function>(e).get_name();
2647 lst parameter = ex_to<lst>(e.op(0));
2650 // special cases if all parameters are either 0, 1 or -1
2651 bool allthesame = true;
2652 if (parameter.op(0) == 0) {
2653 for (int i=1; i<parameter.nops(); i++) {
2654 if (parameter.op(i) != 0) {
2661 for (int i=parameter.nops(); i>0; i--) {
2662 newparameter.append(1);
2664 return pow(-1, parameter.nops()) * H(newparameter, 1-arg).hold();
2666 } else if (parameter.op(0) == -1) {
2667 throw std::runtime_error("map_trafo_H_1mx: cannot handle weights equal -1!");
2669 for (int i=1; i<parameter.nops(); i++) {
2670 if (parameter.op(i) != 1) {
2677 for (int i=parameter.nops(); i>0; i--) {
2678 newparameter.append(0);
2680 return pow(-1, parameter.nops()) * H(newparameter, 1-arg).hold();
2684 lst newparameter = parameter;
2685 newparameter.remove_first();
2687 if (parameter.op(0) == 0) {
2690 ex res = convert_H_to_zeta(parameter);
2691 //ex res = convert_from_RV(parameter, 1).subs(H(wild(1),wild(2))==zeta(wild(1)));
2692 map_trafo_H_1mx recursion;
2693 ex buffer = recursion(H(newparameter, arg).hold());
2694 if (is_a<add>(buffer)) {
2695 for (int i=0; i<buffer.nops(); i++) {
2696 res -= trafo_H_prepend_one(buffer.op(i), arg);
2699 res -= trafo_H_prepend_one(buffer, arg);
2706 map_trafo_H_1mx recursion;
2707 map_trafo_H_mult unify;
2708 ex res = H(lst(1), arg).hold() * H(newparameter, arg).hold();
2710 while (parameter.op(firstzero) == 1) {
2713 for (int i=firstzero-1; i<parameter.nops()-1; i++) {
2717 newparameter.append(parameter[j+1]);
2719 newparameter.append(1);
2720 for (; j<parameter.nops()-1; j++) {
2721 newparameter.append(parameter[j+1]);
2723 res -= H(newparameter, arg).hold();
2725 res = recursion(res).expand() / firstzero;
2735 // do x -> 1/x transformation
2736 struct map_trafo_H_1overx : public map_function
2738 ex operator()(const ex& e)
2740 if (is_a<add>(e) || is_a<mul>(e)) {
2741 return e.map(*this);
2744 if (is_a<function>(e)) {
2745 std::string name = ex_to<function>(e).get_name();
2748 lst parameter = ex_to<lst>(e.op(0));
2751 // special cases if all parameters are either 0, 1 or -1
2752 bool allthesame = true;
2753 if (parameter.op(0) == 0) {
2754 for (int i=1; i<parameter.nops(); i++) {
2755 if (parameter.op(i) != 0) {
2761 return pow(-1, parameter.nops()) * H(parameter, 1/arg).hold();
2763 } else if (parameter.op(0) == -1) {
2764 for (int i=1; i<parameter.nops(); i++) {
2765 if (parameter.op(i) != -1) {
2771 map_trafo_H_mult unify;
2772 return unify((pow(H(lst(-1),1/arg).hold() - H(lst(0),1/arg).hold(), parameter.nops())
2773 / factorial(parameter.nops())).expand());
2776 for (int i=1; i<parameter.nops(); i++) {
2777 if (parameter.op(i) != 1) {
2783 map_trafo_H_mult unify;
2784 return unify((pow(H(lst(1),1/arg).hold() + H(lst(0),1/arg).hold() + H_polesign, parameter.nops())
2785 / factorial(parameter.nops())).expand());
2789 lst newparameter = parameter;
2790 newparameter.remove_first();
2792 if (parameter.op(0) == 0) {
2795 ex res = convert_H_to_zeta(parameter);
2796 map_trafo_H_1overx recursion;
2797 ex buffer = recursion(H(newparameter, arg).hold());
2798 if (is_a<add>(buffer)) {
2799 for (int i=0; i<buffer.nops(); i++) {
2800 res += trafo_H_1tx_prepend_zero(buffer.op(i), arg);
2803 res += trafo_H_1tx_prepend_zero(buffer, arg);
2807 } else if (parameter.op(0) == -1) {
2809 // leading negative one
2810 ex res = convert_H_to_zeta(parameter);
2811 map_trafo_H_1overx recursion;
2812 ex buffer = recursion(H(newparameter, arg).hold());
2813 if (is_a<add>(buffer)) {
2814 for (int i=0; i<buffer.nops(); i++) {
2815 res += trafo_H_1tx_prepend_zero(buffer.op(i), arg) - trafo_H_1tx_prepend_minusone(buffer.op(i), arg);
2818 res += trafo_H_1tx_prepend_zero(buffer, arg) - trafo_H_1tx_prepend_minusone(buffer, arg);
2825 map_trafo_H_1overx recursion;
2826 map_trafo_H_mult unify;
2827 ex res = H(lst(1), arg).hold() * H(newparameter, arg).hold();
2829 while (parameter.op(firstzero) == 1) {
2832 for (int i=firstzero-1; i<parameter.nops()-1; i++) {
2836 newparameter.append(parameter[j+1]);
2838 newparameter.append(1);
2839 for (; j<parameter.nops()-1; j++) {
2840 newparameter.append(parameter[j+1]);
2842 res -= H(newparameter, arg).hold();
2844 res = recursion(res).expand() / firstzero;
2856 // do x -> (1-x)/(1+x) transformation
2857 struct map_trafo_H_1mxt1px : public map_function
2859 ex operator()(const ex& e)
2861 if (is_a<add>(e) || is_a<mul>(e)) {
2862 return e.map(*this);
2865 if (is_a<function>(e)) {
2866 std::string name = ex_to<function>(e).get_name();
2869 lst parameter = ex_to<lst>(e.op(0));
2872 // special cases if all parameters are either 0, 1 or -1
2873 bool allthesame = true;
2874 if (parameter.op(0) == 0) {
2875 for (int i=1; i<parameter.nops(); i++) {
2876 if (parameter.op(i) != 0) {
2882 map_trafo_H_mult unify;
2883 return unify((pow(-H(lst(1),(1-arg)/(1+arg)).hold() - H(lst(-1),(1-arg)/(1+arg)).hold(), parameter.nops())
2884 / factorial(parameter.nops())).expand());
2886 } else if (parameter.op(0) == -1) {
2887 for (int i=1; i<parameter.nops(); i++) {
2888 if (parameter.op(i) != -1) {
2894 map_trafo_H_mult unify;
2895 return unify((pow(log(2) - H(lst(-1),(1-arg)/(1+arg)).hold(), parameter.nops())
2896 / factorial(parameter.nops())).expand());
2899 for (int i=1; i<parameter.nops(); i++) {
2900 if (parameter.op(i) != 1) {
2906 map_trafo_H_mult unify;
2907 return unify((pow(-log(2) - H(lst(0),(1-arg)/(1+arg)).hold() + H(lst(-1),(1-arg)/(1+arg)).hold(), parameter.nops())
2908 / factorial(parameter.nops())).expand());
2912 lst newparameter = parameter;
2913 newparameter.remove_first();
2915 if (parameter.op(0) == 0) {
2918 ex res = convert_H_to_zeta(parameter);
2919 map_trafo_H_1mxt1px recursion;
2920 ex buffer = recursion(H(newparameter, arg).hold());
2921 if (is_a<add>(buffer)) {
2922 for (int i=0; i<buffer.nops(); i++) {
2923 res -= trafo_H_1mxt1px_prepend_one(buffer.op(i), arg) + trafo_H_1mxt1px_prepend_minusone(buffer.op(i), arg);
2926 res -= trafo_H_1mxt1px_prepend_one(buffer, arg) + trafo_H_1mxt1px_prepend_minusone(buffer, arg);
2930 } else if (parameter.op(0) == -1) {
2932 // leading negative one
2933 ex res = convert_H_to_zeta(parameter);
2934 map_trafo_H_1mxt1px recursion;
2935 ex buffer = recursion(H(newparameter, arg).hold());
2936 if (is_a<add>(buffer)) {
2937 for (int i=0; i<buffer.nops(); i++) {
2938 res -= trafo_H_1mxt1px_prepend_minusone(buffer.op(i), arg);
2941 res -= trafo_H_1mxt1px_prepend_minusone(buffer, arg);
2948 map_trafo_H_1mxt1px recursion;
2949 map_trafo_H_mult unify;
2950 ex res = H(lst(1), arg).hold() * H(newparameter, arg).hold();
2952 while (parameter.op(firstzero) == 1) {
2955 for (int i=firstzero-1; i<parameter.nops()-1; i++) {
2959 newparameter.append(parameter[j+1]);
2961 newparameter.append(1);
2962 for (; j<parameter.nops()-1; j++) {
2963 newparameter.append(parameter[j+1]);
2965 res -= H(newparameter, arg).hold();
2967 res = recursion(res).expand() / firstzero;
2979 // do the actual summation.
2980 cln::cl_N H_do_sum(const std::vector<int>& m, const cln::cl_N& x)
2982 const int j = m.size();
2984 std::vector<cln::cl_N> t(j);
2986 cln::cl_F one = cln::cl_float(1, cln::float_format(Digits));
2987 cln::cl_N factor = cln::expt(x, j) * one;
2993 t[j-1] = t[j-1] + 1 / cln::expt(cln::cl_I(q),m[j-1]);
2994 for (int k=j-2; k>=1; k--) {
2995 t[k] = t[k] + t[k+1] / cln::expt(cln::cl_I(q+j-1-k), m[k]);
2997 t[0] = t[0] + t[1] * factor / cln::expt(cln::cl_I(q+j-1), m[0]);
2998 factor = factor * x;
2999 } while (t[0] != t0buf);
3005 } // end of anonymous namespace
3008 //////////////////////////////////////////////////////////////////////
3010 // Harmonic polylogarithm H(m,x)
3014 //////////////////////////////////////////////////////////////////////
3017 static ex H_evalf(const ex& x1, const ex& x2)
3019 if (is_a<lst>(x1)) {
3022 if (is_a<numeric>(x2)) {
3023 x = ex_to<numeric>(x2).to_cl_N();
3025 ex x2_val = x2.evalf();
3026 if (is_a<numeric>(x2_val)) {
3027 x = ex_to<numeric>(x2_val).to_cl_N();
3031 for (int i=0; i<x1.nops(); i++) {
3032 if (!x1.op(i).info(info_flags::integer)) {
3033 return H(x1, x2).hold();
3036 if (x1.nops() < 1) {
3037 return H(x1, x2).hold();
3040 const lst& morg = ex_to<lst>(x1);
3041 // remove trailing zeros ...
3042 if (*(--morg.end()) == 0) {
3043 symbol xtemp("xtemp");
3044 map_trafo_H_reduce_trailing_zeros filter;
3045 return filter(H(x1, xtemp).hold()).subs(xtemp==x2).evalf();
3047 // ... and expand parameter notation
3048 bool has_minus_one = false;
3050 for (lst::const_iterator it = morg.begin(); it != morg.end(); it++) {
3052 for (ex count=*it-1; count > 0; count--) {
3056 } else if (*it <= -1) {
3057 for (ex count=*it+1; count < 0; count++) {
3061 has_minus_one = true;
3068 if (cln::abs(x) < 0.95) {
3072 if (convert_parameter_H_to_Li(m, m_lst, s_lst, pf)) {
3073 // negative parameters -> s_lst is filled
3074 std::vector<int> m_int;
3075 std::vector<cln::cl_N> x_cln;
3076 for (lst::const_iterator it_int = m_lst.begin(), it_cln = s_lst.begin();
3077 it_int != m_lst.end(); it_int++, it_cln++) {
3078 m_int.push_back(ex_to<numeric>(*it_int).to_int());
3079 x_cln.push_back(ex_to<numeric>(*it_cln).to_cl_N());
3081 x_cln.front() = x_cln.front() * x;
3082 return pf * numeric(multipleLi_do_sum(m_int, x_cln));
3084 // only positive parameters
3086 if (m_lst.nops() == 1) {
3087 return Li(m_lst.op(0), x2).evalf();
3089 std::vector<int> m_int;
3090 for (lst::const_iterator it = m_lst.begin(); it != m_lst.end(); it++) {
3091 m_int.push_back(ex_to<numeric>(*it).to_int());
3093 return numeric(H_do_sum(m_int, x));
3097 symbol xtemp("xtemp");
3100 // ensure that the realpart of the argument is positive
3101 if (cln::realpart(x) < 0) {
3103 for (int i=0; i<m.nops(); i++) {
3105 m.let_op(i) = -m.op(i);
3112 if (cln::abs(x) >= 2.0) {
3113 map_trafo_H_1overx trafo;
3114 res *= trafo(H(m, xtemp));
3115 if (cln::imagpart(x) <= 0) {
3116 res = res.subs(H_polesign == -I*Pi);
3118 res = res.subs(H_polesign == I*Pi);
3120 return res.subs(xtemp == numeric(x)).evalf();
3123 // check transformations for 0.95 <= |x| < 2.0
3125 // |(1-x)/(1+x)| < 0.9 -> circular area with center=9.53+0i and radius=9.47
3126 if (cln::abs(x-9.53) <= 9.47) {
3128 map_trafo_H_1mxt1px trafo;
3129 res *= trafo(H(m, xtemp));
3132 if (has_minus_one) {
3133 map_trafo_H_convert_to_Li filter;
3134 return filter(H(m, numeric(x)).hold()).evalf();
3136 map_trafo_H_1mx trafo;
3137 res *= trafo(H(m, xtemp));
3140 return res.subs(xtemp == numeric(x)).evalf();
3143 return H(x1,x2).hold();
3147 static ex H_eval(const ex& m_, const ex& x)
3150 if (is_a<lst>(m_)) {
3155 if (m.nops() == 0) {
3163 if (*m.begin() > _ex1) {
3169 } else if (*m.begin() < _ex_1) {
3175 } else if (*m.begin() == _ex0) {
3182 for (lst::const_iterator it = ++m.begin(); it != m.end(); it++) {
3183 if ((*it).info(info_flags::integer)) {
3194 } else if (*it < _ex_1) {
3214 } else if (step == 1) {
3226 // if some m_i is not an integer
3227 return H(m_, x).hold();
3230 if ((x == _ex1) && (*(--m.end()) != _ex0)) {
3231 return convert_H_to_zeta(m);
3237 return H(m_, x).hold();
3239 return pow(log(x), m.nops()) / factorial(m.nops());
3242 return pow(-pos1*log(1-pos1*x), m.nops()) / factorial(m.nops());
3244 } else if ((step == 1) && (pos1 == _ex0)){
3249 return pow(-1, p) * S(n, p, -x);
3255 if (x.info(info_flags::numeric) && (!x.info(info_flags::crational))) {
3256 return H(m_, x).evalf();
3258 return H(m_, x).hold();
3262 static ex H_series(const ex& m, const ex& x, const relational& rel, int order, unsigned options)
3265 seq.push_back(expair(H(m, x), 0));
3266 return pseries(rel, seq);
3270 static ex H_deriv(const ex& m_, const ex& x, unsigned deriv_param)
3272 GINAC_ASSERT(deriv_param < 2);
3273 if (deriv_param == 0) {
3277 if (is_a<lst>(m_)) {
3293 return 1/(1-x) * H(m, x);
3294 } else if (mb == _ex_1) {
3295 return 1/(1+x) * H(m, x);
3302 static void H_print_latex(const ex& m_, const ex& x, const print_context& c)
3305 if (is_a<lst>(m_)) {
3310 c.s << "\\mbox{H}_{";
3311 lst::const_iterator itm = m.begin();
3314 for (; itm != m.end(); itm++) {
3324 REGISTER_FUNCTION(H,
3325 evalf_func(H_evalf).
3327 series_func(H_series).
3328 derivative_func(H_deriv).
3329 print_func<print_latex>(H_print_latex).
3330 do_not_evalf_params());
3333 // takes a parameter list for H and returns an expression with corresponding multiple polylogarithms
3334 ex convert_H_to_Li(const ex& m, const ex& x)
3336 map_trafo_H_reduce_trailing_zeros filter;
3337 map_trafo_H_convert_to_Li filter2;
3339 return filter2(filter(H(m, x).hold()));
3341 return filter2(filter(H(lst(m), x).hold()));
3346 //////////////////////////////////////////////////////////////////////
3348 // Multiple zeta values zeta(x) and zeta(x,s)
3352 //////////////////////////////////////////////////////////////////////
3355 // anonymous namespace for helper functions
3359 // parameters and data for [Cra] algorithm
3360 const cln::cl_N lambda = cln::cl_N("319/320");
3363 std::vector<std::vector<cln::cl_N> > f_kj;
3364 std::vector<cln::cl_N> crB;
3365 std::vector<std::vector<cln::cl_N> > crG;
3366 std::vector<cln::cl_N> crX;
3369 void halfcyclic_convolute(const std::vector<cln::cl_N>& a, const std::vector<cln::cl_N>& b, std::vector<cln::cl_N>& c)
3371 const int size = a.size();
3372 for (int n=0; n<size; n++) {
3374 for (int m=0; m<=n; m++) {
3375 c[n] = c[n] + a[m]*b[n-m];
3382 void initcX(const std::vector<int>& s)
3384 const int k = s.size();
3390 for (int i=0; i<=L2; i++) {
3391 crB.push_back(bernoulli(i).to_cl_N() / cln::factorial(i));
3396 for (int m=0; m<k-1; m++) {
3397 std::vector<cln::cl_N> crGbuf;
3400 for (int i=0; i<=L2; i++) {
3401 crGbuf.push_back(cln::factorial(i + Sm - m - 2) / cln::factorial(i + Smp1 - m - 2));
3403 crG.push_back(crGbuf);
3408 for (int m=0; m<k-1; m++) {
3409 std::vector<cln::cl_N> Xbuf;
3410 for (int i=0; i<=L2; i++) {
3411 Xbuf.push_back(crX[i] * crG[m][i]);
3413 halfcyclic_convolute(Xbuf, crB, crX);
3419 cln::cl_N crandall_Y_loop(const cln::cl_N& Sqk)
3421 cln::cl_F one = cln::cl_float(1, cln::float_format(Digits));
3422 cln::cl_N factor = cln::expt(lambda, Sqk);
3423 cln::cl_N res = factor / Sqk * crX[0] * one;
3428 factor = factor * lambda;
3430 res = res + crX[N] * factor / (N+Sqk);
3431 } while ((res != resbuf) || cln::zerop(crX[N]));
3437 void calc_f(int maxr)
3442 cln::cl_N t0, t1, t2, t3, t4;
3444 std::vector<std::vector<cln::cl_N> >::iterator it = f_kj.begin();
3445 cln::cl_F one = cln::cl_float(1, cln::float_format(Digits));
3447 t0 = cln::exp(-lambda);
3449 for (k=1; k<=L1; k++) {
3452 for (j=1; j<=maxr; j++) {
3455 for (i=2; i<=j; i++) {
3459 (*it).push_back(t2 * t3 * cln::expt(cln::cl_I(k),-j) * one);
3467 cln::cl_N crandall_Z(const std::vector<int>& s)
3469 const int j = s.size();
3478 t0 = t0 + f_kj[q+j-2][s[0]-1];
3479 } while (t0 != t0buf);
3481 return t0 / cln::factorial(s[0]-1);
3484 std::vector<cln::cl_N> t(j);
3491 t[j-1] = t[j-1] + 1 / cln::expt(cln::cl_I(q),s[j-1]);
3492 for (int k=j-2; k>=1; k--) {
3493 t[k] = t[k] + t[k+1] / cln::expt(cln::cl_I(q+j-1-k), s[k]);
3495 t[0] = t[0] + t[1] * f_kj[q+j-2][s[0]-1];
3496 } while (t[0] != t0buf);
3498 return t[0] / cln::factorial(s[0]-1);
3503 cln::cl_N zeta_do_sum_Crandall(const std::vector<int>& s)
3505 std::vector<int> r = s;
3506 const int j = r.size();
3508 // decide on maximal size of f_kj for crandall_Z
3512 L1 = Digits * 3 + j*2;
3515 // decide on maximal size of crX for crandall_Y
3518 } else if (Digits < 86) {
3520 } else if (Digits < 192) {
3522 } else if (Digits < 394) {
3524 } else if (Digits < 808) {
3534 for (int i=0; i<j; i++) {
3543 const cln::cl_N r0factorial = cln::factorial(r[0]-1);
3545 std::vector<int> rz;
3548 for (int k=r.size()-1; k>0; k--) {
3550 rz.insert(rz.begin(), r.back());
3551 skp1buf = rz.front();
3557 for (int q=0; q<skp1buf; q++) {
3559 cln::cl_N pp1 = crandall_Y_loop(Srun+q-k);
3560 cln::cl_N pp2 = crandall_Z(rz);
3565 res = res - pp1 * pp2 / cln::factorial(q);
3567 res = res + pp1 * pp2 / cln::factorial(q);
3570 rz.front() = skp1buf;
3572 rz.insert(rz.begin(), r.back());
3576 res = (res + crandall_Y_loop(S-j)) / r0factorial + crandall_Z(rz);
3582 cln::cl_N zeta_do_sum_simple(const std::vector<int>& r)
3584 const int j = r.size();
3586 // buffer for subsums
3587 std::vector<cln::cl_N> t(j);
3588 cln::cl_F one = cln::cl_float(1, cln::float_format(Digits));
3595 t[j-1] = t[j-1] + one / cln::expt(cln::cl_I(q),r[j-1]);
3596 for (int k=j-2; k>=0; k--) {
3597 t[k] = t[k] + one * t[k+1] / cln::expt(cln::cl_I(q+j-1-k), r[k]);
3599 } while (t[0] != t0buf);
3605 // does Hoelder convolution. see [BBB] (7.0)
3606 cln::cl_N zeta_do_Hoelder_convolution(const std::vector<int>& m_, const std::vector<int>& s_)
3608 // prepare parameters
3609 // holds Li arguments in [BBB] notation
3610 std::vector<int> s = s_;
3611 std::vector<int> m_p = m_;
3612 std::vector<int> m_q;
3613 // holds Li arguments in nested sums notation
3614 std::vector<cln::cl_N> s_p(s.size(), cln::cl_N(1));
3615 s_p[0] = s_p[0] * cln::cl_N("1/2");
3616 // convert notations
3618 for (int i=0; i<s_.size(); i++) {
3623 s[i] = sig * std::abs(s[i]);
3625 std::vector<cln::cl_N> s_q;
3626 cln::cl_N signum = 1;
3629 cln::cl_N res = multipleLi_do_sum(m_p, s_p);
3634 // change parameters
3635 if (s.front() > 0) {
3636 if (m_p.front() == 1) {
3637 m_p.erase(m_p.begin());
3638 s_p.erase(s_p.begin());
3639 if (s_p.size() > 0) {
3640 s_p.front() = s_p.front() * cln::cl_N("1/2");
3646 m_q.insert(m_q.begin(), 1);
3647 if (s_q.size() > 0) {
3648 s_q.front() = s_q.front() * 2;
3650 s_q.insert(s_q.begin(), cln::cl_N("1/2"));
3653 if (m_p.front() == 1) {
3654 m_p.erase(m_p.begin());
3655 cln::cl_N spbuf = s_p.front();
3656 s_p.erase(s_p.begin());
3657 if (s_p.size() > 0) {
3658 s_p.front() = s_p.front() * spbuf;
3661 m_q.insert(m_q.begin(), 1);
3662 if (s_q.size() > 0) {
3663 s_q.front() = s_q.front() * 4;
3665 s_q.insert(s_q.begin(), cln::cl_N("1/4"));
3669 m_q.insert(m_q.begin(), 1);
3670 if (s_q.size() > 0) {
3671 s_q.front() = s_q.front() * 2;
3673 s_q.insert(s_q.begin(), cln::cl_N("1/2"));
3678 if (m_p.size() == 0) break;
3680 res = res + signum * multipleLi_do_sum(m_p, s_p) * multipleLi_do_sum(m_q, s_q);
3685 res = res + signum * multipleLi_do_sum(m_q, s_q);
3691 } // end of anonymous namespace
3694 //////////////////////////////////////////////////////////////////////
3696 // Multiple zeta values zeta(x)
3700 //////////////////////////////////////////////////////////////////////
3703 static ex zeta1_evalf(const ex& x)
3705 if (is_exactly_a<lst>(x) && (x.nops()>1)) {
3707 // multiple zeta value
3708 const int count = x.nops();
3709 const lst& xlst = ex_to<lst>(x);
3710 std::vector<int> r(count);
3712 // check parameters and convert them
3713 lst::const_iterator it1 = xlst.begin();
3714 std::vector<int>::iterator it2 = r.begin();
3716 if (!(*it1).info(info_flags::posint)) {
3717 return zeta(x).hold();
3719 *it2 = ex_to<numeric>(*it1).to_int();
3722 } while (it2 != r.end());
3724 // check for divergence
3726 return zeta(x).hold();
3729 // decide on summation algorithm
3730 // this is still a bit clumsy
3731 int limit = (Digits>17) ? 10 : 6;
3732 if ((r[0] < limit) || ((count > 3) && (r[1] < limit/2))) {
3733 return numeric(zeta_do_sum_Crandall(r));
3735 return numeric(zeta_do_sum_simple(r));
3739 // single zeta value
3740 if (is_exactly_a<numeric>(x) && (x != 1)) {
3742 return zeta(ex_to<numeric>(x));
3743 } catch (const dunno &e) { }
3746 return zeta(x).hold();
3750 static ex zeta1_eval(const ex& m)
3752 if (is_exactly_a<lst>(m)) {
3753 if (m.nops() == 1) {
3754 return zeta(m.op(0));
3756 return zeta(m).hold();
3759 if (m.info(info_flags::numeric)) {
3760 const numeric& y = ex_to<numeric>(m);
3761 // trap integer arguments:
3762 if (y.is_integer()) {
3766 if (y.is_equal(*_num1_p)) {
3767 return zeta(m).hold();
3769 if (y.info(info_flags::posint)) {
3770 if (y.info(info_flags::odd)) {
3771 return zeta(m).hold();
3773 return abs(bernoulli(y)) * pow(Pi, y) * pow(*_num2_p, y-(*_num1_p)) / factorial(y);
3776 if (y.info(info_flags::odd)) {
3777 return -bernoulli((*_num1_p)-y) / ((*_num1_p)-y);
3784 if (y.info(info_flags::numeric) && !y.info(info_flags::crational)) {
3785 return zeta1_evalf(m);
3788 return zeta(m).hold();
3792 static ex zeta1_deriv(const ex& m, unsigned deriv_param)
3794 GINAC_ASSERT(deriv_param==0);
3796 if (is_exactly_a<lst>(m)) {
3799 return zetaderiv(_ex1, m);
3804 static void zeta1_print_latex(const ex& m_, const print_context& c)
3807 if (is_a<lst>(m_)) {
3808 const lst& m = ex_to<lst>(m_);
3809 lst::const_iterator it = m.begin();
3812 for (; it != m.end(); it++) {
3823 unsigned zeta1_SERIAL::serial = function::register_new(function_options("zeta", 1).
3824 evalf_func(zeta1_evalf).
3825 eval_func(zeta1_eval).
3826 derivative_func(zeta1_deriv).
3827 print_func<print_latex>(zeta1_print_latex).
3828 do_not_evalf_params().
3832 //////////////////////////////////////////////////////////////////////
3834 // Alternating Euler sum zeta(x,s)
3838 //////////////////////////////////////////////////////////////////////
3841 static ex zeta2_evalf(const ex& x, const ex& s)
3843 if (is_exactly_a<lst>(x)) {
3845 // alternating Euler sum
3846 const int count = x.nops();
3847 const lst& xlst = ex_to<lst>(x);
3848 const lst& slst = ex_to<lst>(s);
3849 std::vector<int> xi(count);
3850 std::vector<int> si(count);
3852 // check parameters and convert them
3853 lst::const_iterator it_xread = xlst.begin();
3854 lst::const_iterator it_sread = slst.begin();
3855 std::vector<int>::iterator it_xwrite = xi.begin();
3856 std::vector<int>::iterator it_swrite = si.begin();
3858 if (!(*it_xread).info(info_flags::posint)) {
3859 return zeta(x, s).hold();
3861 *it_xwrite = ex_to<numeric>(*it_xread).to_int();
3862 if (*it_sread > 0) {
3871 } while (it_xwrite != xi.end());
3873 // check for divergence
3874 if ((xi[0] == 1) && (si[0] == 1)) {
3875 return zeta(x, s).hold();
3878 // use Hoelder convolution
3879 return numeric(zeta_do_Hoelder_convolution(xi, si));
3882 return zeta(x, s).hold();
3886 static ex zeta2_eval(const ex& m, const ex& s_)
3888 if (is_exactly_a<lst>(s_)) {
3889 const lst& s = ex_to<lst>(s_);
3890 for (lst::const_iterator it = s.begin(); it != s.end(); it++) {
3891 if ((*it).info(info_flags::positive)) {
3894 return zeta(m, s_).hold();
3897 } else if (s_.info(info_flags::positive)) {
3901 return zeta(m, s_).hold();
3905 static ex zeta2_deriv(const ex& m, const ex& s, unsigned deriv_param)
3907 GINAC_ASSERT(deriv_param==0);
3909 if (is_exactly_a<lst>(m)) {
3912 if ((is_exactly_a<lst>(s) && s.op(0).info(info_flags::positive)) || s.info(info_flags::positive)) {
3913 return zetaderiv(_ex1, m);
3920 static void zeta2_print_latex(const ex& m_, const ex& s_, const print_context& c)
3923 if (is_a<lst>(m_)) {
3929 if (is_a<lst>(s_)) {
3935 lst::const_iterator itm = m.begin();
3936 lst::const_iterator its = s.begin();
3938 c.s << "\\overline{";
3946 for (; itm != m.end(); itm++, its++) {
3949 c.s << "\\overline{";
3960 unsigned zeta2_SERIAL::serial = function::register_new(function_options("zeta", 2).
3961 evalf_func(zeta2_evalf).
3962 eval_func(zeta2_eval).
3963 derivative_func(zeta2_deriv).
3964 print_func<print_latex>(zeta2_print_latex).
3965 do_not_evalf_params().
3969 } // namespace GiNaC