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-2009 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
74 #include "operators.h"
77 #include "relational.h"
90 //////////////////////////////////////////////////////////////////////
92 // Classical polylogarithm Li(n,x)
96 //////////////////////////////////////////////////////////////////////
99 // anonymous namespace for helper functions
103 // lookup table for factors built from Bernoulli numbers
105 std::vector<std::vector<cln::cl_N> > Xn;
106 // initial size of Xn that should suffice for 32bit machines (must be even)
107 const int xninitsizestep = 26;
108 int xninitsize = xninitsizestep;
112 // This function calculates the X_n. The X_n are needed for speed up of classical polylogarithms.
113 // With these numbers the polylogs can be calculated as follows:
114 // Li_p (x) = \sum_{n=0}^\infty X_{p-2}(n) u^{n+1}/(n+1)! with u = -log(1-x)
115 // X_0(n) = B_n (Bernoulli numbers)
116 // X_p(n) = \sum_{k=0}^n binomial(n,k) B_{n-k} / (k+1) * X_{p-1}(k)
117 // The calculation of Xn depends on X0 and X{n-1}.
118 // X_0 is special, it holds only the non-zero Bernoulli numbers with index 2 or greater.
119 // This results in a slightly more complicated algorithm for the X_n.
120 // The first index in Xn corresponds to the index of the polylog minus 2.
121 // The second index in Xn corresponds to the index from the actual sum.
125 // calculate X_2 and higher (corresponding to Li_4 and higher)
126 std::vector<cln::cl_N> buf(xninitsize);
127 std::vector<cln::cl_N>::iterator it = buf.begin();
129 *it = -(cln::expt(cln::cl_I(2),n+1) - 1) / cln::expt(cln::cl_I(2),n+1); // i == 1
131 for (int i=2; i<=xninitsize; i++) {
133 result = 0; // k == 0
135 result = Xn[0][i/2-1]; // k == 0
137 for (int k=1; k<i-1; k++) {
138 if ( !(((i-k) & 1) && ((i-k) > 1)) ) {
139 result = result + cln::binomial(i,k) * Xn[0][(i-k)/2-1] * Xn[n-1][k-1] / (k+1);
142 result = result - cln::binomial(i,i-1) * Xn[n-1][i-2] / 2 / i; // k == i-1
143 result = result + Xn[n-1][i-1] / (i+1); // k == i
150 // special case to handle the X_0 correct
151 std::vector<cln::cl_N> buf(xninitsize);
152 std::vector<cln::cl_N>::iterator it = buf.begin();
154 *it = cln::cl_I(-3)/cln::cl_I(4); // i == 1
156 *it = cln::cl_I(17)/cln::cl_I(36); // i == 2
158 for (int i=3; i<=xninitsize; i++) {
160 result = -Xn[0][(i-3)/2]/2;
161 *it = (cln::binomial(i,1)/cln::cl_I(2) + cln::binomial(i,i-1)/cln::cl_I(i))*result;
164 result = Xn[0][i/2-1] + Xn[0][i/2-1]/(i+1);
165 for (int k=1; k<i/2; k++) {
166 result = result + cln::binomial(i,k*2) * Xn[0][k-1] * Xn[0][i/2-k-1] / (k*2+1);
175 std::vector<cln::cl_N> buf(xninitsize/2);
176 std::vector<cln::cl_N>::iterator it = buf.begin();
177 for (int i=1; i<=xninitsize/2; i++) {
178 *it = bernoulli(i*2).to_cl_N();
187 // doubles the number of entries in each Xn[]
190 const int pos0 = xninitsize / 2;
192 for (int i=1; i<=xninitsizestep/2; ++i) {
193 Xn[0].push_back(bernoulli((i+pos0)*2).to_cl_N());
196 int xend = xninitsize + xninitsizestep;
199 for (int i=xninitsize+1; i<=xend; ++i) {
201 result = -Xn[0][(i-3)/2]/2;
202 Xn[1].push_back((cln::binomial(i,1)/cln::cl_I(2) + cln::binomial(i,i-1)/cln::cl_I(i))*result);
204 result = Xn[0][i/2-1] + Xn[0][i/2-1]/(i+1);
205 for (int k=1; k<i/2; k++) {
206 result = result + cln::binomial(i,k*2) * Xn[0][k-1] * Xn[0][i/2-k-1] / (k*2+1);
208 Xn[1].push_back(result);
212 for (size_t n=2; n<Xn.size(); ++n) {
213 for (int i=xninitsize+1; i<=xend; ++i) {
215 result = 0; // k == 0
217 result = Xn[0][i/2-1]; // k == 0
219 for (int k=1; k<i-1; ++k) {
220 if ( !(((i-k) & 1) && ((i-k) > 1)) ) {
221 result = result + cln::binomial(i,k) * Xn[0][(i-k)/2-1] * Xn[n-1][k-1] / (k+1);
224 result = result - cln::binomial(i,i-1) * Xn[n-1][i-2] / 2 / i; // k == i-1
225 result = result + Xn[n-1][i-1] / (i+1); // k == i
226 Xn[n].push_back(result);
230 xninitsize += xninitsizestep;
234 // calculates Li(2,x) without Xn
235 cln::cl_N Li2_do_sum(const cln::cl_N& x)
239 cln::cl_N num = x * cln::cl_float(1, cln::float_format(Digits));
240 cln::cl_I den = 1; // n^2 = 1
245 den = den + i; // n^2 = 4, 9, 16, ...
247 res = res + num / den;
248 } while (res != resbuf);
253 // calculates Li(2,x) with Xn
254 cln::cl_N Li2_do_sum_Xn(const cln::cl_N& x)
256 std::vector<cln::cl_N>::const_iterator it = Xn[0].begin();
257 std::vector<cln::cl_N>::const_iterator xend = Xn[0].end();
258 cln::cl_N u = -cln::log(1-x);
259 cln::cl_N factor = u * cln::cl_float(1, cln::float_format(Digits));
260 cln::cl_N uu = cln::square(u);
261 cln::cl_N res = u - uu/4;
266 factor = factor * uu / (2*i * (2*i+1));
267 res = res + (*it) * factor;
271 it = Xn[0].begin() + (i-1);
274 } while (res != resbuf);
279 // calculates Li(n,x), n>2 without Xn
280 cln::cl_N Lin_do_sum(int n, const cln::cl_N& x)
282 cln::cl_N factor = x * cln::cl_float(1, cln::float_format(Digits));
289 res = res + factor / cln::expt(cln::cl_I(i),n);
291 } while (res != resbuf);
296 // calculates Li(n,x), n>2 with Xn
297 cln::cl_N Lin_do_sum_Xn(int n, const cln::cl_N& x)
299 std::vector<cln::cl_N>::const_iterator it = Xn[n-2].begin();
300 std::vector<cln::cl_N>::const_iterator xend = Xn[n-2].end();
301 cln::cl_N u = -cln::log(1-x);
302 cln::cl_N factor = u * cln::cl_float(1, cln::float_format(Digits));
308 factor = factor * u / i;
309 res = res + (*it) * factor;
313 it = Xn[n-2].begin() + (i-2);
314 xend = Xn[n-2].end();
316 } while (res != resbuf);
321 // forward declaration needed by function Li_projection and C below
322 const cln::cl_N S_num(int n, int p, const cln::cl_N& x);
325 // helper function for classical polylog Li
326 cln::cl_N Li_projection(int n, const cln::cl_N& x, const cln::float_format_t& prec)
328 // treat n=2 as special case
330 // check if precalculated X0 exists
335 if (cln::realpart(x) < 0.5) {
336 // choose the faster algorithm
337 // the switching point was empirically determined. the optimal point
338 // depends on hardware, Digits, ... so an approx value is okay.
339 // it solves also the problem with precision due to the u=-log(1-x) transformation
340 if (cln::abs(cln::realpart(x)) < 0.25) {
342 return Li2_do_sum(x);
344 return Li2_do_sum_Xn(x);
347 // choose the faster algorithm
348 if (cln::abs(cln::realpart(x)) > 0.75) {
349 return -Li2_do_sum(1-x) - cln::log(x) * cln::log(1-x) + cln::zeta(2);
351 return -Li2_do_sum_Xn(1-x) - cln::log(x) * cln::log(1-x) + cln::zeta(2);
355 // check if precalculated Xn exist
357 for (int i=xnsize; i<n-1; i++) {
362 if (cln::realpart(x) < 0.5) {
363 // choose the faster algorithm
364 // with n>=12 the "normal" summation always wins against the method with Xn
365 if ((cln::abs(cln::realpart(x)) < 0.3) || (n >= 12)) {
366 return Lin_do_sum(n, x);
368 return Lin_do_sum_Xn(n, x);
371 cln::cl_N result = -cln::expt(cln::log(x), n-1) * cln::log(1-x) / cln::factorial(n-1);
372 for (int j=0; j<n-1; j++) {
373 result = result + (S_num(n-j-1, 1, 1) - S_num(1, n-j-1, 1-x))
374 * cln::expt(cln::log(x), j) / cln::factorial(j);
381 // helper function for classical polylog Li
382 const cln::cl_N Lin_numeric(const int n, const cln::cl_N& x)
386 return -cln::log(1-x);
397 return -(1-cln::expt(cln::cl_I(2),1-n)) * cln::zeta(n);
399 if (cln::abs(realpart(x)) < 0.4 && cln::abs(cln::abs(x)-1) < 0.01) {
400 cln::cl_N result = -cln::expt(cln::log(x), n-1) * cln::log(1-x) / cln::factorial(n-1);
401 for (int j=0; j<n-1; j++) {
402 result = result + (S_num(n-j-1, 1, 1) - S_num(1, n-j-1, 1-x))
403 * cln::expt(cln::log(x), j) / cln::factorial(j);
408 // what is the desired float format?
409 // first guess: default format
410 cln::float_format_t prec = cln::default_float_format;
411 const cln::cl_N value = x;
412 // second guess: the argument's format
413 if (!instanceof(realpart(x), cln::cl_RA_ring))
414 prec = cln::float_format(cln::the<cln::cl_F>(cln::realpart(value)));
415 else if (!instanceof(imagpart(x), cln::cl_RA_ring))
416 prec = cln::float_format(cln::the<cln::cl_F>(cln::imagpart(value)));
419 if (cln::abs(value) > 1) {
420 cln::cl_N result = -cln::expt(cln::log(-value),n) / cln::factorial(n);
421 // check if argument is complex. if it is real, the new polylog has to be conjugated.
422 if (cln::zerop(cln::imagpart(value))) {
424 result = result + conjugate(Li_projection(n, cln::recip(value), prec));
427 result = result - conjugate(Li_projection(n, cln::recip(value), prec));
432 result = result + Li_projection(n, cln::recip(value), prec);
435 result = result - Li_projection(n, cln::recip(value), prec);
439 for (int j=0; j<n-1; j++) {
440 add = add + (1+cln::expt(cln::cl_I(-1),n-j)) * (1-cln::expt(cln::cl_I(2),1-n+j))
441 * Lin_numeric(n-j,1) * cln::expt(cln::log(-value),j) / cln::factorial(j);
443 result = result - add;
447 return Li_projection(n, value, prec);
452 } // end of anonymous namespace
455 //////////////////////////////////////////////////////////////////////
457 // Multiple polylogarithm Li(n,x)
461 //////////////////////////////////////////////////////////////////////
464 // anonymous namespace for helper function
468 // performs the actual series summation for multiple polylogarithms
469 cln::cl_N multipleLi_do_sum(const std::vector<int>& s, const std::vector<cln::cl_N>& x)
471 // ensure all x <> 0.
472 for (std::vector<cln::cl_N>::const_iterator it = x.begin(); it != x.end(); ++it) {
473 if ( *it == 0 ) return cln::cl_float(0, cln::float_format(Digits));
476 const int j = s.size();
477 bool flag_accidental_zero = false;
479 std::vector<cln::cl_N> t(j);
480 cln::cl_F one = cln::cl_float(1, cln::float_format(Digits));
487 t[j-1] = t[j-1] + cln::expt(x[j-1], q) / cln::expt(cln::cl_I(q),s[j-1]) * one;
488 for (int k=j-2; k>=0; k--) {
489 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]);
492 t[j-1] = t[j-1] + cln::expt(x[j-1], q) / cln::expt(cln::cl_I(q),s[j-1]) * one;
493 for (int k=j-2; k>=0; k--) {
494 flag_accidental_zero = cln::zerop(t[k+1]);
495 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]);
497 } while ( (t[0] != t0buf) || cln::zerop(t[0]) || flag_accidental_zero );
503 // forward declaration for Li_eval()
504 lst convert_parameter_Li_to_H(const lst& m, const lst& x, ex& pf);
507 // type used by the transformation functions for G
508 typedef std::vector<int> Gparameter;
511 // G_eval1-function for G transformations
512 ex G_eval1(int a, int scale, const exvector& gsyms)
515 const ex& scs = gsyms[std::abs(scale)];
516 const ex& as = gsyms[std::abs(a)];
518 return -log(1 - scs/as);
523 return log(gsyms[std::abs(scale)]);
528 // G_eval-function for G transformations
529 ex G_eval(const Gparameter& a, int scale, const exvector& gsyms)
531 // check for properties of G
532 ex sc = gsyms[std::abs(scale)];
534 bool all_zero = true;
535 bool all_ones = true;
537 for (Gparameter::const_iterator it = a.begin(); it != a.end(); ++it) {
539 const ex sym = gsyms[std::abs(*it)];
553 // care about divergent G: shuffle to separate divergencies that will be canceled
554 // later on in the transformation
555 if (newa.nops() > 1 && newa.op(0) == sc && !all_ones && a.front()!=0) {
558 Gparameter::const_iterator it = a.begin();
560 for (; it != a.end(); ++it) {
561 short_a.push_back(*it);
563 ex result = G_eval1(a.front(), scale, gsyms) * G_eval(short_a, scale, gsyms);
564 it = short_a.begin();
565 for (int i=1; i<count_ones; ++i) {
568 for (; it != short_a.end(); ++it) {
571 Gparameter::const_iterator it2 = short_a.begin();
572 for (; it2 != it; ++it2) {
573 newa.push_back(*it2);
576 newa.push_back(a[0]);
579 for (; it2 != short_a.end(); ++it2) {
580 newa.push_back(*it2);
582 result -= G_eval(newa, scale, gsyms);
584 return result / count_ones;
587 // G({1,...,1};y) -> G({1};y)^k / k!
588 if (all_ones && a.size() > 1) {
589 return pow(G_eval1(a.front(),scale, gsyms), count_ones) / factorial(count_ones);
592 // G({0,...,0};y) -> log(y)^k / k!
594 return pow(log(gsyms[std::abs(scale)]), a.size()) / factorial(a.size());
597 // no special cases anymore -> convert it into Li
600 ex argbuf = gsyms[std::abs(scale)];
602 for (Gparameter::const_iterator it=a.begin(); it!=a.end(); ++it) {
604 const ex& sym = gsyms[std::abs(*it)];
605 x.append(argbuf / sym);
613 return pow(-1, x.nops()) * Li(m, x);
617 // converts data for G: pending_integrals -> a
618 Gparameter convert_pending_integrals_G(const Gparameter& pending_integrals)
620 GINAC_ASSERT(pending_integrals.size() != 1);
622 if (pending_integrals.size() > 0) {
623 // get rid of the first element, which would stand for the new upper limit
624 Gparameter new_a(pending_integrals.begin()+1, pending_integrals.end());
627 // just return empty parameter list
634 // check the parameters a and scale for G and return information about convergence, depth, etc.
635 // convergent : true if G(a,scale) is convergent
636 // depth : depth of G(a,scale)
637 // trailing_zeros : number of trailing zeros of a
638 // min_it : iterator of a pointing on the smallest element in a
639 Gparameter::const_iterator check_parameter_G(const Gparameter& a, int scale,
640 bool& convergent, int& depth, int& trailing_zeros, Gparameter::const_iterator& min_it)
646 Gparameter::const_iterator lastnonzero = a.end();
647 for (Gparameter::const_iterator it = a.begin(); it != a.end(); ++it) {
648 if (std::abs(*it) > 0) {
652 if (std::abs(*it) < scale) {
654 if ((min_it == a.end()) || (std::abs(*it) < std::abs(*min_it))) {
662 if (lastnonzero == a.end())
664 return ++lastnonzero;
668 // add scale to pending_integrals if pending_integrals is empty
669 Gparameter prepare_pending_integrals(const Gparameter& pending_integrals, int scale)
671 GINAC_ASSERT(pending_integrals.size() != 1);
673 if (pending_integrals.size() > 0) {
674 return pending_integrals;
676 Gparameter new_pending_integrals;
677 new_pending_integrals.push_back(scale);
678 return new_pending_integrals;
683 // handles trailing zeroes for an otherwise convergent integral
684 ex trailing_zeros_G(const Gparameter& a, int scale, const exvector& gsyms)
687 int depth, trailing_zeros;
688 Gparameter::const_iterator last, dummyit;
689 last = check_parameter_G(a, scale, convergent, depth, trailing_zeros, dummyit);
691 GINAC_ASSERT(convergent);
693 if ((trailing_zeros > 0) && (depth > 0)) {
695 Gparameter new_a(a.begin(), a.end()-1);
696 result += G_eval1(0, scale, gsyms) * trailing_zeros_G(new_a, scale, gsyms);
697 for (Gparameter::const_iterator it = a.begin(); it != last; ++it) {
698 Gparameter new_a(a.begin(), it);
700 new_a.insert(new_a.end(), it, a.end()-1);
701 result -= trailing_zeros_G(new_a, scale, gsyms);
704 return result / trailing_zeros;
706 return G_eval(a, scale, gsyms);
711 // G transformation [VSW] (57),(58)
712 ex depth_one_trafo_G(const Gparameter& pending_integrals, const Gparameter& a, int scale, const exvector& gsyms)
714 // pendint = ( y1, b1, ..., br )
715 // a = ( 0, ..., 0, amin )
718 // int_0^y1 ds1/(s1-b1) ... int dsr/(sr-br) G(0, ..., 0, sr; y2)
719 // where sr replaces amin
721 GINAC_ASSERT(a.back() != 0);
722 GINAC_ASSERT(a.size() > 0);
725 Gparameter new_pending_integrals = prepare_pending_integrals(pending_integrals, std::abs(a.back()));
726 const int psize = pending_integrals.size();
729 // G(sr_{+-}; y2 ) = G(y2_{-+}; sr) - G(0; sr) + ln(-y2_{-+})
734 result += log(gsyms[ex_to<numeric>(scale).to_int()]);
736 new_pending_integrals.push_back(-scale);
739 new_pending_integrals.push_back(scale);
743 result *= trailing_zeros_G(convert_pending_integrals_G(pending_integrals),
744 pending_integrals.front(),
749 result += trailing_zeros_G(convert_pending_integrals_G(new_pending_integrals),
750 new_pending_integrals.front(),
754 new_pending_integrals.back() = 0;
755 result -= trailing_zeros_G(convert_pending_integrals_G(new_pending_integrals),
756 new_pending_integrals.front(),
763 // G_m(sr_{+-}; y2) = -zeta_m + int_0^y2 dt/t G_{m-1}( (1/y2)_{+-}; 1/t )
764 // - int_0^sr dt/t G_{m-1}( (1/y2)_{+-}; 1/t )
767 result -= zeta(a.size());
769 result *= trailing_zeros_G(convert_pending_integrals_G(pending_integrals),
770 pending_integrals.front(),
774 // term int_0^sr dt/t G_{m-1}( (1/y2)_{+-}; 1/t )
775 // = int_0^sr dt/t G_{m-1}( t_{+-}; y2 )
776 Gparameter new_a(a.begin()+1, a.end());
777 new_pending_integrals.push_back(0);
778 result -= depth_one_trafo_G(new_pending_integrals, new_a, scale, gsyms);
780 // term int_0^y2 dt/t G_{m-1}( (1/y2)_{+-}; 1/t )
781 // = int_0^y2 dt/t G_{m-1}( t_{+-}; y2 )
782 Gparameter new_pending_integrals_2;
783 new_pending_integrals_2.push_back(scale);
784 new_pending_integrals_2.push_back(0);
786 result += trailing_zeros_G(convert_pending_integrals_G(pending_integrals),
787 pending_integrals.front(),
789 * depth_one_trafo_G(new_pending_integrals_2, new_a, scale, gsyms);
791 result += depth_one_trafo_G(new_pending_integrals_2, new_a, scale, gsyms);
798 // forward declaration
799 ex shuffle_G(const Gparameter & a0, const Gparameter & a1, const Gparameter & a2,
800 const Gparameter& pendint, const Gparameter& a_old, int scale,
801 const exvector& gsyms);
804 // G transformation [VSW]
805 ex G_transform(const Gparameter& pendint, const Gparameter& a, int scale,
806 const exvector& gsyms)
808 // main recursion routine
810 // pendint = ( y1, b1, ..., br )
811 // a = ( a1, ..., amin, ..., aw )
814 // int_0^y1 ds1/(s1-b1) ... int dsr/(sr-br) G(a1,...,sr,...,aw,y2)
815 // where sr replaces amin
817 // find smallest alpha, determine depth and trailing zeros, and check for convergence
819 int depth, trailing_zeros;
820 Gparameter::const_iterator min_it;
821 Gparameter::const_iterator firstzero =
822 check_parameter_G(a, scale, convergent, depth, trailing_zeros, min_it);
823 int min_it_pos = min_it - a.begin();
825 // special case: all a's are zero
832 result = G_eval(a, scale, gsyms);
834 if (pendint.size() > 0) {
835 result *= trailing_zeros_G(convert_pending_integrals_G(pendint),
842 // handle trailing zeros
843 if (trailing_zeros > 0) {
845 Gparameter new_a(a.begin(), a.end()-1);
846 result += G_eval1(0, scale, gsyms) * G_transform(pendint, new_a, scale, gsyms);
847 for (Gparameter::const_iterator it = a.begin(); it != firstzero; ++it) {
848 Gparameter new_a(a.begin(), it);
850 new_a.insert(new_a.end(), it, a.end()-1);
851 result -= G_transform(pendint, new_a, scale, gsyms);
853 return result / trailing_zeros;
858 if (pendint.size() > 0) {
859 return G_eval(convert_pending_integrals_G(pendint),
860 pendint.front(), gsyms)*
861 G_eval(a, scale, gsyms);
863 return G_eval(a, scale, gsyms);
867 // call basic transformation for depth equal one
869 return depth_one_trafo_G(pendint, a, scale, gsyms);
873 // int_0^y1 ds1/(s1-b1) ... int dsr/(sr-br) G(a1,...,sr,...,aw,y2)
874 // = int_0^y1 ds1/(s1-b1) ... int dsr/(sr-br) G(a1,...,0,...,aw,y2)
875 // + 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)
877 // smallest element in last place
878 if (min_it + 1 == a.end()) {
879 do { --min_it; } while (*min_it == 0);
881 Gparameter a1(a.begin(),min_it+1);
882 Gparameter a2(min_it+1,a.end());
884 ex result = G_transform(pendint, a2, scale, gsyms)*
885 G_transform(empty, a1, scale, gsyms);
887 result -= shuffle_G(empty, a1, a2, pendint, a, scale, gsyms);
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, gsyms);
899 if (pendint.size() > 0) {
900 result *= trailing_zeros_G(convert_pending_integrals_G(pendint),
901 pendint.front(), gsyms);
905 changeit = new_a.begin() + min_it_pos;
906 changeit = new_a.erase(changeit);
907 if (changeit != new_a.begin()) {
908 // smallest in the middle
909 new_pendint.push_back(*changeit);
910 result -= trailing_zeros_G(convert_pending_integrals_G(new_pendint),
911 new_pendint.front(), gsyms)*
912 G_transform(empty, new_a, scale, gsyms);
913 int buffer = *changeit;
915 result += G_transform(new_pendint, new_a, scale, gsyms);
917 new_pendint.pop_back();
919 new_pendint.push_back(*changeit);
920 result += trailing_zeros_G(convert_pending_integrals_G(new_pendint),
921 new_pendint.front(), gsyms)*
922 G_transform(empty, new_a, scale, gsyms);
924 result -= G_transform(new_pendint, new_a, scale, gsyms);
926 // smallest at the front
927 new_pendint.push_back(scale);
928 result += trailing_zeros_G(convert_pending_integrals_G(new_pendint),
929 new_pendint.front(), gsyms)*
930 G_transform(empty, new_a, scale, gsyms);
931 new_pendint.back() = *changeit;
932 result -= trailing_zeros_G(convert_pending_integrals_G(new_pendint),
933 new_pendint.front(), gsyms)*
934 G_transform(empty, new_a, scale, gsyms);
936 result += G_transform(new_pendint, new_a, scale, gsyms);
942 // shuffles the two parameter list a1 and a2 and calls G_transform for every term except
943 // for the one that is equal to a_old
944 ex shuffle_G(const Gparameter & a0, const Gparameter & a1, const Gparameter & a2,
945 const Gparameter& pendint, const Gparameter& a_old, int scale,
946 const exvector& gsyms)
948 if (a1.size()==0 && a2.size()==0) {
949 // veto the one configuration we don't want
950 if ( a0 == a_old ) return 0;
952 return G_transform(pendint, a0, scale, gsyms);
958 aa0.insert(aa0.end(),a1.begin(),a1.end());
959 return shuffle_G(aa0, empty, empty, pendint, a_old, scale, gsyms);
965 aa0.insert(aa0.end(),a2.begin(),a2.end());
966 return shuffle_G(aa0, empty, empty, pendint, a_old, scale, gsyms);
969 Gparameter a1_removed(a1.begin()+1,a1.end());
970 Gparameter a2_removed(a2.begin()+1,a2.end());
975 a01.push_back( a1[0] );
976 a02.push_back( a2[0] );
978 return shuffle_G(a01, a1_removed, a2, pendint, a_old, scale, gsyms)
979 + shuffle_G(a02, a1, a2_removed, pendint, a_old, scale, gsyms);
982 // handles the transformations and the numerical evaluation of G
983 // the parameter x, s and y must only contain numerics
985 G_numeric(const std::vector<cln::cl_N>& x, const std::vector<int>& s,
988 // do acceleration transformation (hoelder convolution [BBB])
989 // the parameter x, s and y must only contain numerics
991 G_do_hoelder(std::vector<cln::cl_N> x, /* yes, it's passed by value */
992 const std::vector<int>& s, const cln::cl_N& y)
995 const std::size_t size = x.size();
996 for (std::size_t i = 0; i < size; ++i)
999 for (std::size_t r = 0; r <= size; ++r) {
1000 cln::cl_N buffer(1 & r ? -1 : 1);
1005 for (std::size_t i = 0; i < size; ++i) {
1006 if (x[i] == cln::cl_RA(1)/p) {
1007 p = p/2 + cln::cl_RA(3)/2;
1013 cln::cl_RA q = p/(p-1);
1014 std::vector<cln::cl_N> qlstx;
1015 std::vector<int> qlsts;
1016 for (std::size_t j = r; j >= 1; --j) {
1017 qlstx.push_back(cln::cl_N(1) - x[j-1]);
1018 if (instanceof(x[j-1], cln::cl_R_ring) &&
1019 realpart(x[j-1]) > 1 && realpart(x[j-1]) <= 2) {
1020 qlsts.push_back(s[j-1]);
1022 qlsts.push_back(-s[j-1]);
1025 if (qlstx.size() > 0) {
1026 buffer = buffer*G_numeric(qlstx, qlsts, 1/q);
1028 std::vector<cln::cl_N> plstx;
1029 std::vector<int> plsts;
1030 for (std::size_t j = r+1; j <= size; ++j) {
1031 plstx.push_back(x[j-1]);
1032 plsts.push_back(s[j-1]);
1034 if (plstx.size() > 0) {
1035 buffer = buffer*G_numeric(plstx, plsts, 1/p);
1037 result = result + buffer;
1042 // convergence transformation, used for numerical evaluation of G function.
1043 // the parameter x, s and y must only contain numerics
1045 G_do_trafo(const std::vector<cln::cl_N>& x, const std::vector<int>& s,
1048 // sort (|x|<->position) to determine indices
1049 typedef std::multimap<cln::cl_R, std::size_t> sortmap_t;
1051 std::size_t size = 0;
1052 for (std::size_t i = 0; i < x.size(); ++i) {
1054 sortmap.insert(std::make_pair(abs(x[i]), i));
1058 // include upper limit (scale)
1059 sortmap.insert(std::make_pair(abs(y), x.size()));
1061 // generate missing dummy-symbols
1063 // holding dummy-symbols for the G/Li transformations
1065 gsyms.push_back(symbol("GSYMS_ERROR"));
1066 cln::cl_N lastentry(0);
1067 for (sortmap_t::const_iterator it = sortmap.begin(); it != sortmap.end(); ++it) {
1068 if (it != sortmap.begin()) {
1069 if (it->second < x.size()) {
1070 if (x[it->second] == lastentry) {
1071 gsyms.push_back(gsyms.back());
1075 if (y == lastentry) {
1076 gsyms.push_back(gsyms.back());
1081 std::ostringstream os;
1083 gsyms.push_back(symbol(os.str()));
1085 if (it->second < x.size()) {
1086 lastentry = x[it->second];
1092 // fill position data according to sorted indices and prepare substitution list
1093 Gparameter a(x.size());
1095 std::size_t pos = 1;
1097 for (sortmap_t::const_iterator it = sortmap.begin(); it != sortmap.end(); ++it) {
1098 if (it->second < x.size()) {
1099 if (s[it->second] > 0) {
1100 a[it->second] = pos;
1102 a[it->second] = -int(pos);
1104 subslst[gsyms[pos]] = numeric(x[it->second]);
1107 subslst[gsyms[pos]] = numeric(y);
1112 // do transformation
1114 ex result = G_transform(pendint, a, scale, gsyms);
1115 // replace dummy symbols with their values
1116 result = result.eval().expand();
1117 result = result.subs(subslst).evalf();
1118 if (!is_a<numeric>(result))
1119 throw std::logic_error("G_do_trafo: G_transform returned non-numeric result");
1121 cln::cl_N ret = ex_to<numeric>(result).to_cl_N();
1125 // handles the transformations and the numerical evaluation of G
1126 // the parameter x, s and y must only contain numerics
1128 G_numeric(const std::vector<cln::cl_N>& x, const std::vector<int>& s,
1131 // check for convergence and necessary accelerations
1132 bool need_trafo = false;
1133 bool need_hoelder = false;
1134 std::size_t depth = 0;
1135 for (std::size_t i = 0; i < x.size(); ++i) {
1138 const cln::cl_N x_y = abs(x[i]) - y;
1139 if (instanceof(x_y, cln::cl_R_ring) &&
1140 realpart(x_y) < cln::least_negative_float(cln::float_format(Digits - 2)))
1143 if (abs(abs(x[i]/y) - 1) < 0.01)
1144 need_hoelder = true;
1147 if (zerop(x[x.size() - 1]))
1150 if (depth == 1 && x.size() == 2 && !need_trafo)
1151 return - Li_projection(2, y/x[1], cln::float_format(Digits));
1153 // do acceleration transformation (hoelder convolution [BBB])
1155 return G_do_hoelder(x, s, y);
1157 // convergence transformation
1159 return G_do_trafo(x, s, y);
1162 std::vector<cln::cl_N> newx;
1163 newx.reserve(x.size());
1165 m.reserve(x.size());
1168 cln::cl_N factor = y;
1169 for (std::size_t i = 0; i < x.size(); ++i) {
1173 newx.push_back(factor/x[i]);
1175 m.push_back(mcount);
1181 return sign*multipleLi_do_sum(m, newx);
1185 ex mLi_numeric(const lst& m, const lst& x)
1187 // let G_numeric do the transformation
1188 std::vector<cln::cl_N> newx;
1189 newx.reserve(x.nops());
1191 s.reserve(x.nops());
1192 cln::cl_N factor(1);
1193 for (lst::const_iterator itm = m.begin(), itx = x.begin(); itm != m.end(); ++itm, ++itx) {
1194 for (int i = 1; i < *itm; ++i) {
1195 newx.push_back(cln::cl_N(0));
1198 const cln::cl_N xi = ex_to<numeric>(*itx).to_cl_N();
1199 newx.push_back(factor/xi);
1203 return numeric(cln::cl_N(1 & m.nops() ? - 1 : 1)*G_numeric(newx, s, cln::cl_N(1)));
1207 } // end of anonymous namespace
1210 //////////////////////////////////////////////////////////////////////
1212 // Generalized multiple polylogarithm G(x, y) and G(x, s, y)
1216 //////////////////////////////////////////////////////////////////////
1219 static ex G2_evalf(const ex& x_, const ex& y)
1221 if (!y.info(info_flags::positive)) {
1222 return G(x_, y).hold();
1224 lst x = is_a<lst>(x_) ? ex_to<lst>(x_) : lst(x_);
1225 if (x.nops() == 0) {
1229 return G(x_, y).hold();
1232 s.reserve(x.nops());
1233 bool all_zero = true;
1234 for (lst::const_iterator it = x.begin(); it != x.end(); ++it) {
1235 if (!(*it).info(info_flags::numeric)) {
1236 return G(x_, y).hold();
1241 if ( !ex_to<numeric>(*it).is_real() && ex_to<numeric>(*it).imag() < 0 ) {
1249 return pow(log(y), x.nops()) / factorial(x.nops());
1251 std::vector<cln::cl_N> xv;
1252 xv.reserve(x.nops());
1253 for (lst::const_iterator it = x.begin(); it != x.end(); ++it)
1254 xv.push_back(ex_to<numeric>(*it).to_cl_N());
1255 cln::cl_N result = G_numeric(xv, s, ex_to<numeric>(y).to_cl_N());
1256 return numeric(result);
1260 static ex G2_eval(const ex& x_, const ex& y)
1262 //TODO eval to MZV or H or S or Lin
1264 if (!y.info(info_flags::positive)) {
1265 return G(x_, y).hold();
1267 lst x = is_a<lst>(x_) ? ex_to<lst>(x_) : lst(x_);
1268 if (x.nops() == 0) {
1272 return G(x_, y).hold();
1275 s.reserve(x.nops());
1276 bool all_zero = true;
1277 bool crational = true;
1278 for (lst::const_iterator it = x.begin(); it != x.end(); ++it) {
1279 if (!(*it).info(info_flags::numeric)) {
1280 return G(x_, y).hold();
1282 if (!(*it).info(info_flags::crational)) {
1288 if ( !ex_to<numeric>(*it).is_real() && ex_to<numeric>(*it).imag() < 0 ) {
1296 return pow(log(y), x.nops()) / factorial(x.nops());
1298 if (!y.info(info_flags::crational)) {
1302 return G(x_, y).hold();
1304 std::vector<cln::cl_N> xv;
1305 xv.reserve(x.nops());
1306 for (lst::const_iterator it = x.begin(); it != x.end(); ++it)
1307 xv.push_back(ex_to<numeric>(*it).to_cl_N());
1308 cln::cl_N result = G_numeric(xv, s, ex_to<numeric>(y).to_cl_N());
1309 return numeric(result);
1313 unsigned G2_SERIAL::serial = function::register_new(function_options("G", 2).
1314 evalf_func(G2_evalf).
1316 do_not_evalf_params().
1319 // derivative_func(G2_deriv).
1320 // print_func<print_latex>(G2_print_latex).
1323 static ex G3_evalf(const ex& x_, const ex& s_, const ex& y)
1325 if (!y.info(info_flags::positive)) {
1326 return G(x_, s_, y).hold();
1328 lst x = is_a<lst>(x_) ? ex_to<lst>(x_) : lst(x_);
1329 lst s = is_a<lst>(s_) ? ex_to<lst>(s_) : lst(s_);
1330 if (x.nops() != s.nops()) {
1331 return G(x_, s_, y).hold();
1333 if (x.nops() == 0) {
1337 return G(x_, s_, y).hold();
1339 std::vector<int> sn;
1340 sn.reserve(s.nops());
1341 bool all_zero = true;
1342 for (lst::const_iterator itx = x.begin(), its = s.begin(); itx != x.end(); ++itx, ++its) {
1343 if (!(*itx).info(info_flags::numeric)) {
1344 return G(x_, y).hold();
1346 if (!(*its).info(info_flags::real)) {
1347 return G(x_, y).hold();
1352 if ( ex_to<numeric>(*itx).is_real() ) {
1361 if ( ex_to<numeric>(*itx).imag() > 0 ) {
1370 return pow(log(y), x.nops()) / factorial(x.nops());
1372 std::vector<cln::cl_N> xn;
1373 xn.reserve(x.nops());
1374 for (lst::const_iterator it = x.begin(); it != x.end(); ++it)
1375 xn.push_back(ex_to<numeric>(*it).to_cl_N());
1376 cln::cl_N result = G_numeric(xn, sn, ex_to<numeric>(y).to_cl_N());
1377 return numeric(result);
1381 static ex G3_eval(const ex& x_, const ex& s_, const ex& y)
1383 //TODO eval to MZV or H or S or Lin
1385 if (!y.info(info_flags::positive)) {
1386 return G(x_, s_, y).hold();
1388 lst x = is_a<lst>(x_) ? ex_to<lst>(x_) : lst(x_);
1389 lst s = is_a<lst>(s_) ? ex_to<lst>(s_) : lst(s_);
1390 if (x.nops() != s.nops()) {
1391 return G(x_, s_, y).hold();
1393 if (x.nops() == 0) {
1397 return G(x_, s_, y).hold();
1399 std::vector<int> sn;
1400 sn.reserve(s.nops());
1401 bool all_zero = true;
1402 bool crational = true;
1403 for (lst::const_iterator itx = x.begin(), its = s.begin(); itx != x.end(); ++itx, ++its) {
1404 if (!(*itx).info(info_flags::numeric)) {
1405 return G(x_, s_, y).hold();
1407 if (!(*its).info(info_flags::real)) {
1408 return G(x_, s_, y).hold();
1410 if (!(*itx).info(info_flags::crational)) {
1416 if ( ex_to<numeric>(*itx).is_real() ) {
1425 if ( ex_to<numeric>(*itx).imag() > 0 ) {
1434 return pow(log(y), x.nops()) / factorial(x.nops());
1436 if (!y.info(info_flags::crational)) {
1440 return G(x_, s_, y).hold();
1442 std::vector<cln::cl_N> xn;
1443 xn.reserve(x.nops());
1444 for (lst::const_iterator it = x.begin(); it != x.end(); ++it)
1445 xn.push_back(ex_to<numeric>(*it).to_cl_N());
1446 cln::cl_N result = G_numeric(xn, sn, ex_to<numeric>(y).to_cl_N());
1447 return numeric(result);
1451 unsigned G3_SERIAL::serial = function::register_new(function_options("G", 3).
1452 evalf_func(G3_evalf).
1454 do_not_evalf_params().
1457 // derivative_func(G3_deriv).
1458 // print_func<print_latex>(G3_print_latex).
1461 //////////////////////////////////////////////////////////////////////
1463 // Classical polylogarithm and multiple polylogarithm Li(m,x)
1467 //////////////////////////////////////////////////////////////////////
1470 static ex Li_evalf(const ex& m_, const ex& x_)
1472 // classical polylogs
1473 if (m_.info(info_flags::posint)) {
1474 if (x_.info(info_flags::numeric)) {
1475 int m__ = ex_to<numeric>(m_).to_int();
1476 const cln::cl_N x__ = ex_to<numeric>(x_).to_cl_N();
1477 const cln::cl_N result = Lin_numeric(m__, x__);
1478 return numeric(result);
1480 // try to numerically evaluate second argument
1481 ex x_val = x_.evalf();
1482 if (x_val.info(info_flags::numeric)) {
1483 int m__ = ex_to<numeric>(m_).to_int();
1484 const cln::cl_N x__ = ex_to<numeric>(x_val).to_cl_N();
1485 const cln::cl_N result = Lin_numeric(m__, x__);
1486 return numeric(result);
1490 // multiple polylogs
1491 if (is_a<lst>(m_) && is_a<lst>(x_)) {
1493 const lst& m = ex_to<lst>(m_);
1494 const lst& x = ex_to<lst>(x_);
1495 if (m.nops() != x.nops()) {
1496 return Li(m_,x_).hold();
1498 if (x.nops() == 0) {
1501 if ((m.op(0) == _ex1) && (x.op(0) == _ex1)) {
1502 return Li(m_,x_).hold();
1505 for (lst::const_iterator itm = m.begin(), itx = x.begin(); itm != m.end(); ++itm, ++itx) {
1506 if (!(*itm).info(info_flags::posint)) {
1507 return Li(m_, x_).hold();
1509 if (!(*itx).info(info_flags::numeric)) {
1510 return Li(m_, x_).hold();
1517 return mLi_numeric(m, x);
1520 return Li(m_,x_).hold();
1524 static ex Li_eval(const ex& m_, const ex& x_)
1526 if (is_a<lst>(m_)) {
1527 if (is_a<lst>(x_)) {
1528 // multiple polylogs
1529 const lst& m = ex_to<lst>(m_);
1530 const lst& x = ex_to<lst>(x_);
1531 if (m.nops() != x.nops()) {
1532 return Li(m_,x_).hold();
1534 if (x.nops() == 0) {
1538 bool is_zeta = true;
1539 bool do_evalf = true;
1540 bool crational = true;
1541 for (lst::const_iterator itm = m.begin(), itx = x.begin(); itm != m.end(); ++itm, ++itx) {
1542 if (!(*itm).info(info_flags::posint)) {
1543 return Li(m_,x_).hold();
1545 if ((*itx != _ex1) && (*itx != _ex_1)) {
1546 if (itx != x.begin()) {
1554 if (!(*itx).info(info_flags::numeric)) {
1557 if (!(*itx).info(info_flags::crational)) {
1566 lst newm = convert_parameter_Li_to_H(m, x, prefactor);
1567 return prefactor * H(newm, x[0]);
1569 if (do_evalf && !crational) {
1570 return mLi_numeric(m,x);
1573 return Li(m_, x_).hold();
1574 } else if (is_a<lst>(x_)) {
1575 return Li(m_, x_).hold();
1578 // classical polylogs
1586 return (pow(2,1-m_)-1) * zeta(m_);
1592 if (x_.is_equal(I)) {
1593 return power(Pi,_ex2)/_ex_48 + Catalan*I;
1595 if (x_.is_equal(-I)) {
1596 return power(Pi,_ex2)/_ex_48 - Catalan*I;
1599 if (m_.info(info_flags::posint) && x_.info(info_flags::numeric) && !x_.info(info_flags::crational)) {
1600 int m__ = ex_to<numeric>(m_).to_int();
1601 const cln::cl_N x__ = ex_to<numeric>(x_).to_cl_N();
1602 const cln::cl_N result = Lin_numeric(m__, x__);
1603 return numeric(result);
1606 return Li(m_, x_).hold();
1610 static ex Li_series(const ex& m, const ex& x, const relational& rel, int order, unsigned options)
1612 if (is_a<lst>(m) || is_a<lst>(x)) {
1615 seq.push_back(expair(Li(m, x), 0));
1616 return pseries(rel, seq);
1619 // classical polylog
1620 const ex x_pt = x.subs(rel, subs_options::no_pattern);
1621 if (m.info(info_flags::numeric) && x_pt.info(info_flags::numeric)) {
1622 // First special case: x==0 (derivatives have poles)
1623 if (x_pt.is_zero()) {
1626 // manually construct the primitive expansion
1627 for (int i=1; i<order; ++i)
1628 ser += pow(s,i) / pow(numeric(i), m);
1629 // substitute the argument's series expansion
1630 ser = ser.subs(s==x.series(rel, order), subs_options::no_pattern);
1631 // maybe that was terminating, so add a proper order term
1633 nseq.push_back(expair(Order(_ex1), order));
1634 ser += pseries(rel, nseq);
1635 // reexpanding it will collapse the series again
1636 return ser.series(rel, order);
1638 // TODO special cases: x==1 (branch point) and x real, >=1 (branch cut)
1639 throw std::runtime_error("Li_series: don't know how to do the series expansion at this point!");
1641 // all other cases should be safe, by now:
1642 throw do_taylor(); // caught by function::series()
1646 static ex Li_deriv(const ex& m_, const ex& x_, unsigned deriv_param)
1648 GINAC_ASSERT(deriv_param < 2);
1649 if (deriv_param == 0) {
1652 if (m_.nops() > 1) {
1653 throw std::runtime_error("don't know how to derivate multiple polylogarithm!");
1656 if (is_a<lst>(m_)) {
1662 if (is_a<lst>(x_)) {
1668 return Li(m-1, x) / x;
1675 static void Li_print_latex(const ex& m_, const ex& x_, const print_context& c)
1678 if (is_a<lst>(m_)) {
1684 if (is_a<lst>(x_)) {
1689 c.s << "\\mbox{Li}_{";
1690 lst::const_iterator itm = m.begin();
1693 for (; itm != m.end(); itm++) {
1698 lst::const_iterator itx = x.begin();
1701 for (; itx != x.end(); itx++) {
1709 REGISTER_FUNCTION(Li,
1710 evalf_func(Li_evalf).
1712 series_func(Li_series).
1713 derivative_func(Li_deriv).
1714 print_func<print_latex>(Li_print_latex).
1715 do_not_evalf_params());
1718 //////////////////////////////////////////////////////////////////////
1720 // Nielsen's generalized polylogarithm S(n,p,x)
1724 //////////////////////////////////////////////////////////////////////
1727 // anonymous namespace for helper functions
1731 // lookup table for special Euler-Zagier-Sums (used for S_n,p(x))
1733 std::vector<std::vector<cln::cl_N> > Yn;
1734 int ynsize = 0; // number of Yn[]
1735 int ynlength = 100; // initial length of all Yn[i]
1738 // This function calculates the Y_n. The Y_n are needed for the evaluation of S_{n,p}(x).
1739 // The Y_n are basically Euler-Zagier sums with all m_i=1. They are subsums in the Z-sum
1740 // representing S_{n,p}(x).
1741 // The first index in Y_n corresponds to the parameter p minus one, i.e. the depth of the
1742 // equivalent Z-sum.
1743 // The second index in Y_n corresponds to the running index of the outermost sum in the full Z-sum
1744 // representing S_{n,p}(x).
1745 // The calculation of Y_n uses the values from Y_{n-1}.
1746 void fill_Yn(int n, const cln::float_format_t& prec)
1748 const int initsize = ynlength;
1749 //const int initsize = initsize_Yn;
1750 cln::cl_N one = cln::cl_float(1, prec);
1753 std::vector<cln::cl_N> buf(initsize);
1754 std::vector<cln::cl_N>::iterator it = buf.begin();
1755 std::vector<cln::cl_N>::iterator itprev = Yn[n-1].begin();
1756 *it = (*itprev) / cln::cl_N(n+1) * one;
1759 // sums with an index smaller than the depth are zero and need not to be calculated.
1760 // calculation starts with depth, which is n+2)
1761 for (int i=n+2; i<=initsize+n; i++) {
1762 *it = *(it-1) + (*itprev) / cln::cl_N(i) * one;
1768 std::vector<cln::cl_N> buf(initsize);
1769 std::vector<cln::cl_N>::iterator it = buf.begin();
1772 for (int i=2; i<=initsize; i++) {
1773 *it = *(it-1) + 1 / cln::cl_N(i) * one;
1782 // make Yn longer ...
1783 void make_Yn_longer(int newsize, const cln::float_format_t& prec)
1786 cln::cl_N one = cln::cl_float(1, prec);
1788 Yn[0].resize(newsize);
1789 std::vector<cln::cl_N>::iterator it = Yn[0].begin();
1791 for (int i=ynlength+1; i<=newsize; i++) {
1792 *it = *(it-1) + 1 / cln::cl_N(i) * one;
1796 for (int n=1; n<ynsize; n++) {
1797 Yn[n].resize(newsize);
1798 std::vector<cln::cl_N>::iterator it = Yn[n].begin();
1799 std::vector<cln::cl_N>::iterator itprev = Yn[n-1].begin();
1802 for (int i=ynlength+n+1; i<=newsize+n; i++) {
1803 *it = *(it-1) + (*itprev) / cln::cl_N(i) * one;
1813 // helper function for S(n,p,x)
1815 cln::cl_N C(int n, int p)
1819 for (int k=0; k<p; k++) {
1820 for (int j=0; j<=(n+k-1)/2; j++) {
1824 result = result - 2 * cln::expt(cln::pi(),2*j) * S_num(n-2*j,p,1) / cln::factorial(2*j);
1827 result = result + 2 * cln::expt(cln::pi(),2*j) * S_num(n-2*j,p,1) / cln::factorial(2*j);
1834 result = result + cln::factorial(n+k-1)
1835 * cln::expt(cln::pi(),2*j) * S_num(n+k-2*j,p-k,1)
1836 / (cln::factorial(k) * cln::factorial(n-1) * cln::factorial(2*j));
1839 result = result - cln::factorial(n+k-1)
1840 * cln::expt(cln::pi(),2*j) * S_num(n+k-2*j,p-k,1)
1841 / (cln::factorial(k) * cln::factorial(n-1) * cln::factorial(2*j));
1846 result = result - cln::factorial(n+k-1) * cln::expt(cln::pi(),2*j) * S_num(n+k-2*j,p-k,1)
1847 / (cln::factorial(k) * cln::factorial(n-1) * cln::factorial(2*j));
1850 result = result + cln::factorial(n+k-1)
1851 * cln::expt(cln::pi(),2*j) * S_num(n+k-2*j,p-k,1)
1852 / (cln::factorial(k) * cln::factorial(n-1) * cln::factorial(2*j));
1860 if (((np)/2+n) & 1) {
1861 result = -result - cln::expt(cln::pi(),np) / (np * cln::factorial(n-1) * cln::factorial(p));
1864 result = -result + cln::expt(cln::pi(),np) / (np * cln::factorial(n-1) * cln::factorial(p));
1872 // helper function for S(n,p,x)
1873 // [Kol] remark to (9.1)
1874 cln::cl_N a_k(int k)
1883 for (int m=2; m<=k; m++) {
1884 result = result + cln::expt(cln::cl_N(-1),m) * cln::zeta(m) * a_k(k-m);
1891 // helper function for S(n,p,x)
1892 // [Kol] remark to (9.1)
1893 cln::cl_N b_k(int k)
1902 for (int m=2; m<=k; m++) {
1903 result = result + cln::expt(cln::cl_N(-1),m) * cln::zeta(m) * b_k(k-m);
1910 // helper function for S(n,p,x)
1911 cln::cl_N S_do_sum(int n, int p, const cln::cl_N& x, const cln::float_format_t& prec)
1913 static cln::float_format_t oldprec = cln::default_float_format;
1916 return Li_projection(n+1, x, prec);
1919 // precision has changed, we need to clear lookup table Yn
1920 if ( oldprec != prec ) {
1927 // check if precalculated values are sufficient
1929 for (int i=ynsize; i<p-1; i++) {
1934 // should be done otherwise
1935 cln::cl_F one = cln::cl_float(1, cln::float_format(Digits));
1936 cln::cl_N xf = x * one;
1937 //cln::cl_N xf = x * cln::cl_float(1, prec);
1941 cln::cl_N factor = cln::expt(xf, p);
1945 if (i-p >= ynlength) {
1947 make_Yn_longer(ynlength*2, prec);
1949 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? ...
1950 //res = res + factor / cln::expt(cln::cl_I(i),n+1) * (*it); // should we check it? or rely on magic number? ...
1951 factor = factor * xf;
1953 } while (res != resbuf);
1959 // helper function for S(n,p,x)
1960 cln::cl_N S_projection(int n, int p, const cln::cl_N& x, const cln::float_format_t& prec)
1963 if (cln::abs(cln::realpart(x)) > cln::cl_F("0.5")) {
1965 cln::cl_N result = cln::expt(cln::cl_I(-1),p) * cln::expt(cln::log(x),n)
1966 * cln::expt(cln::log(1-x),p) / cln::factorial(n) / cln::factorial(p);
1968 for (int s=0; s<n; s++) {
1970 for (int r=0; r<p; r++) {
1971 res2 = res2 + cln::expt(cln::cl_I(-1),r) * cln::expt(cln::log(1-x),r)
1972 * S_do_sum(p-r,n-s,1-x,prec) / cln::factorial(r);
1974 result = result + cln::expt(cln::log(x),s) * (S_num(n-s,p,1) - res2) / cln::factorial(s);
1980 return S_do_sum(n, p, x, prec);
1984 // helper function for S(n,p,x)
1985 const cln::cl_N S_num(int n, int p, const cln::cl_N& x)
1989 // [Kol] (2.22) with (2.21)
1990 return cln::zeta(p+1);
1995 return cln::zeta(n+1);
2000 for (int nu=0; nu<n; nu++) {
2001 for (int rho=0; rho<=p; rho++) {
2002 result = result + b_k(n-nu-1) * b_k(p-rho) * a_k(nu+rho+1)
2003 * cln::factorial(nu+rho+1) / cln::factorial(rho) / cln::factorial(nu+1);
2006 result = result * cln::expt(cln::cl_I(-1),n+p-1);
2013 return -(1-cln::expt(cln::cl_I(2),-n)) * cln::zeta(n+1);
2015 // throw std::runtime_error("don't know how to evaluate this function!");
2018 // what is the desired float format?
2019 // first guess: default format
2020 cln::float_format_t prec = cln::default_float_format;
2021 const cln::cl_N value = x;
2022 // second guess: the argument's format
2023 if (!instanceof(realpart(value), cln::cl_RA_ring))
2024 prec = cln::float_format(cln::the<cln::cl_F>(cln::realpart(value)));
2025 else if (!instanceof(imagpart(value), cln::cl_RA_ring))
2026 prec = cln::float_format(cln::the<cln::cl_F>(cln::imagpart(value)));
2029 if ((cln::realpart(value) < -0.5) || (n == 0) || ((cln::abs(value) <= 1) && (cln::abs(value) > 0.95))) {
2031 cln::cl_N result = cln::expt(cln::cl_I(-1),p) * cln::expt(cln::log(value),n)
2032 * cln::expt(cln::log(1-value),p) / cln::factorial(n) / cln::factorial(p);
2034 for (int s=0; s<n; s++) {
2036 for (int r=0; r<p; r++) {
2037 res2 = res2 + cln::expt(cln::cl_I(-1),r) * cln::expt(cln::log(1-value),r)
2038 * S_num(p-r,n-s,1-value) / cln::factorial(r);
2040 result = result + cln::expt(cln::log(value),s) * (S_num(n-s,p,1) - res2) / cln::factorial(s);
2047 if (cln::abs(value) > 1) {
2051 for (int s=0; s<p; s++) {
2052 for (int r=0; r<=s; r++) {
2053 result = result + cln::expt(cln::cl_I(-1),s) * cln::expt(cln::log(-value),r) * cln::factorial(n+s-r-1)
2054 / cln::factorial(r) / cln::factorial(s-r) / cln::factorial(n-1)
2055 * S_num(n+s-r,p-s,cln::recip(value));
2058 result = result * cln::expt(cln::cl_I(-1),n);
2061 for (int r=0; r<n; r++) {
2062 res2 = res2 + cln::expt(cln::log(-value),r) * C(n-r,p) / cln::factorial(r);
2064 res2 = res2 + cln::expt(cln::log(-value),n+p) / cln::factorial(n+p);
2066 result = result + cln::expt(cln::cl_I(-1),p) * res2;
2071 return S_projection(n, p, value, prec);
2076 } // end of anonymous namespace
2079 //////////////////////////////////////////////////////////////////////
2081 // Nielsen's generalized polylogarithm S(n,p,x)
2085 //////////////////////////////////////////////////////////////////////
2088 static ex S_evalf(const ex& n, const ex& p, const ex& x)
2090 if (n.info(info_flags::posint) && p.info(info_flags::posint)) {
2091 const int n_ = ex_to<numeric>(n).to_int();
2092 const int p_ = ex_to<numeric>(p).to_int();
2093 if (is_a<numeric>(x)) {
2094 const cln::cl_N x_ = ex_to<numeric>(x).to_cl_N();
2095 const cln::cl_N result = S_num(n_, p_, x_);
2096 return numeric(result);
2098 ex x_val = x.evalf();
2099 if (is_a<numeric>(x_val)) {
2100 const cln::cl_N x_val_ = ex_to<numeric>(x_val).to_cl_N();
2101 const cln::cl_N result = S_num(n_, p_, x_val_);
2102 return numeric(result);
2106 return S(n, p, x).hold();
2110 static ex S_eval(const ex& n, const ex& p, const ex& x)
2112 if (n.info(info_flags::posint) && p.info(info_flags::posint)) {
2118 for (int i=ex_to<numeric>(p).to_int()-1; i>0; i--) {
2126 if (x.info(info_flags::numeric) && (!x.info(info_flags::crational))) {
2127 int n_ = ex_to<numeric>(n).to_int();
2128 int p_ = ex_to<numeric>(p).to_int();
2129 const cln::cl_N x_ = ex_to<numeric>(x).to_cl_N();
2130 const cln::cl_N result = S_num(n_, p_, x_);
2131 return numeric(result);
2136 return pow(-log(1-x), p) / factorial(p);
2138 return S(n, p, x).hold();
2142 static ex S_series(const ex& n, const ex& p, const ex& x, const relational& rel, int order, unsigned options)
2145 return Li(n+1, x).series(rel, order, options);
2148 const ex x_pt = x.subs(rel, subs_options::no_pattern);
2149 if (n.info(info_flags::posint) && p.info(info_flags::posint) && x_pt.info(info_flags::numeric)) {
2150 // First special case: x==0 (derivatives have poles)
2151 if (x_pt.is_zero()) {
2154 // manually construct the primitive expansion
2155 // subsum = Euler-Zagier-Sum is needed
2156 // dirty hack (slow ...) calculation of subsum:
2157 std::vector<ex> presubsum, subsum;
2158 subsum.push_back(0);
2159 for (int i=1; i<order-1; ++i) {
2160 subsum.push_back(subsum[i-1] + numeric(1, i));
2162 for (int depth=2; depth<p; ++depth) {
2164 for (int i=1; i<order-1; ++i) {
2165 subsum[i] = subsum[i-1] + numeric(1, i) * presubsum[i-1];
2169 for (int i=1; i<order; ++i) {
2170 ser += pow(s,i) / pow(numeric(i), n+1) * subsum[i-1];
2172 // substitute the argument's series expansion
2173 ser = ser.subs(s==x.series(rel, order), subs_options::no_pattern);
2174 // maybe that was terminating, so add a proper order term
2176 nseq.push_back(expair(Order(_ex1), order));
2177 ser += pseries(rel, nseq);
2178 // reexpanding it will collapse the series again
2179 return ser.series(rel, order);
2181 // TODO special cases: x==1 (branch point) and x real, >=1 (branch cut)
2182 throw std::runtime_error("S_series: don't know how to do the series expansion at this point!");
2184 // all other cases should be safe, by now:
2185 throw do_taylor(); // caught by function::series()
2189 static ex S_deriv(const ex& n, const ex& p, const ex& x, unsigned deriv_param)
2191 GINAC_ASSERT(deriv_param < 3);
2192 if (deriv_param < 2) {
2196 return S(n-1, p, x) / x;
2198 return S(n, p-1, x) / (1-x);
2203 static void S_print_latex(const ex& n, const ex& p, const ex& x, const print_context& c)
2205 c.s << "\\mbox{S}_{";
2215 REGISTER_FUNCTION(S,
2216 evalf_func(S_evalf).
2218 series_func(S_series).
2219 derivative_func(S_deriv).
2220 print_func<print_latex>(S_print_latex).
2221 do_not_evalf_params());
2224 //////////////////////////////////////////////////////////////////////
2226 // Harmonic polylogarithm H(m,x)
2230 //////////////////////////////////////////////////////////////////////
2233 // anonymous namespace for helper functions
2237 // regulates the pole (used by 1/x-transformation)
2238 symbol H_polesign("IMSIGN");
2241 // convert parameters from H to Li representation
2242 // parameters are expected to be in expanded form, i.e. only 0, 1 and -1
2243 // returns true if some parameters are negative
2244 bool convert_parameter_H_to_Li(const lst& l, lst& m, lst& s, ex& pf)
2246 // expand parameter list
2248 for (lst::const_iterator it = l.begin(); it != l.end(); it++) {
2250 for (ex count=*it-1; count > 0; count--) {
2254 } else if (*it < -1) {
2255 for (ex count=*it+1; count < 0; count++) {
2266 bool has_negative_parameters = false;
2268 for (lst::const_iterator it = mexp.begin(); it != mexp.end(); it++) {
2274 m.append((*it+acc-1) * signum);
2276 m.append((*it-acc+1) * signum);
2282 has_negative_parameters = true;
2285 if (has_negative_parameters) {
2286 for (std::size_t i=0; i<m.nops(); i++) {
2288 m.let_op(i) = -m.op(i);
2296 return has_negative_parameters;
2300 // recursivly transforms H to corresponding multiple polylogarithms
2301 struct map_trafo_H_convert_to_Li : public map_function
2303 ex operator()(const ex& e)
2305 if (is_a<add>(e) || is_a<mul>(e)) {
2306 return e.map(*this);
2308 if (is_a<function>(e)) {
2309 std::string name = ex_to<function>(e).get_name();
2312 if (is_a<lst>(e.op(0))) {
2313 parameter = ex_to<lst>(e.op(0));
2315 parameter = lst(e.op(0));
2322 if (convert_parameter_H_to_Li(parameter, m, s, pf)) {
2323 s.let_op(0) = s.op(0) * arg;
2324 return pf * Li(m, s).hold();
2326 for (std::size_t i=0; i<m.nops(); i++) {
2329 s.let_op(0) = s.op(0) * arg;
2330 return Li(m, s).hold();
2339 // recursivly transforms H to corresponding zetas
2340 struct map_trafo_H_convert_to_zeta : public map_function
2342 ex operator()(const ex& e)
2344 if (is_a<add>(e) || is_a<mul>(e)) {
2345 return e.map(*this);
2347 if (is_a<function>(e)) {
2348 std::string name = ex_to<function>(e).get_name();
2351 if (is_a<lst>(e.op(0))) {
2352 parameter = ex_to<lst>(e.op(0));
2354 parameter = lst(e.op(0));
2360 if (convert_parameter_H_to_Li(parameter, m, s, pf)) {
2361 return pf * zeta(m, s);
2372 // remove trailing zeros from H-parameters
2373 struct map_trafo_H_reduce_trailing_zeros : public map_function
2375 ex operator()(const ex& e)
2377 if (is_a<add>(e) || is_a<mul>(e)) {
2378 return e.map(*this);
2380 if (is_a<function>(e)) {
2381 std::string name = ex_to<function>(e).get_name();
2384 if (is_a<lst>(e.op(0))) {
2385 parameter = ex_to<lst>(e.op(0));
2387 parameter = lst(e.op(0));
2390 if (parameter.op(parameter.nops()-1) == 0) {
2393 if (parameter.nops() == 1) {
2398 lst::const_iterator it = parameter.begin();
2399 while ((it != parameter.end()) && (*it == 0)) {
2402 if (it == parameter.end()) {
2403 return pow(log(arg),parameter.nops()) / factorial(parameter.nops());
2407 parameter.remove_last();
2408 std::size_t lastentry = parameter.nops();
2409 while ((lastentry > 0) && (parameter[lastentry-1] == 0)) {
2414 ex result = log(arg) * H(parameter,arg).hold();
2416 for (ex i=0; i<lastentry; i++) {
2417 if (parameter[i] > 0) {
2419 result -= (acc + parameter[i]-1) * H(parameter, arg).hold();
2422 } else if (parameter[i] < 0) {
2424 result -= (acc + abs(parameter[i]+1)) * H(parameter, arg).hold();
2432 if (lastentry < parameter.nops()) {
2433 result = result / (parameter.nops()-lastentry+1);
2434 return result.map(*this);
2446 // returns an expression with zeta functions corresponding to the parameter list for H
2447 ex convert_H_to_zeta(const lst& m)
2449 symbol xtemp("xtemp");
2450 map_trafo_H_reduce_trailing_zeros filter;
2451 map_trafo_H_convert_to_zeta filter2;
2452 return filter2(filter(H(m, xtemp).hold())).subs(xtemp == 1);
2456 // convert signs form Li to H representation
2457 lst convert_parameter_Li_to_H(const lst& m, const lst& x, ex& pf)
2460 lst::const_iterator itm = m.begin();
2461 lst::const_iterator itx = ++x.begin();
2466 while (itx != x.end()) {
2467 signum *= (*itx > 0) ? 1 : -1;
2469 res.append((*itm) * signum);
2477 // multiplies an one-dimensional H with another H
2479 ex trafo_H_mult(const ex& h1, const ex& h2)
2484 ex h1nops = h1.op(0).nops();
2485 ex h2nops = h2.op(0).nops();
2487 hshort = h2.op(0).op(0);
2488 hlong = ex_to<lst>(h1.op(0));
2490 hshort = h1.op(0).op(0);
2492 hlong = ex_to<lst>(h2.op(0));
2494 hlong = h2.op(0).op(0);
2497 for (std::size_t i=0; i<=hlong.nops(); i++) {
2501 newparameter.append(hlong[j]);
2503 newparameter.append(hshort);
2504 for (; j<hlong.nops(); j++) {
2505 newparameter.append(hlong[j]);
2507 res += H(newparameter, h1.op(1)).hold();
2513 // applies trafo_H_mult recursively on expressions
2514 struct map_trafo_H_mult : public map_function
2516 ex operator()(const ex& e)
2519 return e.map(*this);
2527 for (std::size_t pos=0; pos<e.nops(); pos++) {
2528 if (is_a<power>(e.op(pos)) && is_a<function>(e.op(pos).op(0))) {
2529 std::string name = ex_to<function>(e.op(pos).op(0)).get_name();
2531 for (ex i=0; i<e.op(pos).op(1); i++) {
2532 Hlst.append(e.op(pos).op(0));
2536 } else if (is_a<function>(e.op(pos))) {
2537 std::string name = ex_to<function>(e.op(pos)).get_name();
2539 if (e.op(pos).op(0).nops() > 1) {
2542 Hlst.append(e.op(pos));
2547 result *= e.op(pos);
2550 if (Hlst.nops() > 0) {
2551 firstH = Hlst[Hlst.nops()-1];
2558 if (Hlst.nops() > 0) {
2559 ex buffer = trafo_H_mult(firstH, Hlst.op(0));
2561 for (std::size_t i=1; i<Hlst.nops(); i++) {
2562 result *= Hlst.op(i);
2564 result = result.expand();
2565 map_trafo_H_mult recursion;
2566 return recursion(result);
2577 // do integration [ReV] (55)
2578 // put parameter 0 in front of existing parameters
2579 ex trafo_H_1tx_prepend_zero(const ex& e, const ex& arg)
2583 if (is_a<function>(e)) {
2584 name = ex_to<function>(e).get_name();
2589 for (std::size_t i=0; i<e.nops(); i++) {
2590 if (is_a<function>(e.op(i))) {
2591 std::string name = ex_to<function>(e.op(i)).get_name();
2599 lst newparameter = ex_to<lst>(h.op(0));
2600 newparameter.prepend(0);
2601 ex addzeta = convert_H_to_zeta(newparameter);
2602 return e.subs(h == (addzeta-H(newparameter, h.op(1)).hold())).expand();
2604 return e * (-H(lst(0),1/arg).hold());
2609 // do integration [ReV] (49)
2610 // put parameter 1 in front of existing parameters
2611 ex trafo_H_prepend_one(const ex& e, const ex& arg)
2615 if (is_a<function>(e)) {
2616 name = ex_to<function>(e).get_name();
2621 for (std::size_t i=0; i<e.nops(); i++) {
2622 if (is_a<function>(e.op(i))) {
2623 std::string name = ex_to<function>(e.op(i)).get_name();
2631 lst newparameter = ex_to<lst>(h.op(0));
2632 newparameter.prepend(1);
2633 return e.subs(h == H(newparameter, h.op(1)).hold());
2635 return e * H(lst(1),1-arg).hold();
2640 // do integration [ReV] (55)
2641 // put parameter -1 in front of existing parameters
2642 ex trafo_H_1tx_prepend_minusone(const ex& e, const ex& arg)
2646 if (is_a<function>(e)) {
2647 name = ex_to<function>(e).get_name();
2652 for (std::size_t i=0; i<e.nops(); i++) {
2653 if (is_a<function>(e.op(i))) {
2654 std::string name = ex_to<function>(e.op(i)).get_name();
2662 lst newparameter = ex_to<lst>(h.op(0));
2663 newparameter.prepend(-1);
2664 ex addzeta = convert_H_to_zeta(newparameter);
2665 return e.subs(h == (addzeta-H(newparameter, h.op(1)).hold())).expand();
2667 ex addzeta = convert_H_to_zeta(lst(-1));
2668 return (e * (addzeta - H(lst(-1),1/arg).hold())).expand();
2673 // do integration [ReV] (55)
2674 // put parameter -1 in front of existing parameters
2675 ex trafo_H_1mxt1px_prepend_minusone(const ex& e, const ex& arg)
2679 if (is_a<function>(e)) {
2680 name = ex_to<function>(e).get_name();
2685 for (std::size_t i = 0; i < e.nops(); i++) {
2686 if (is_a<function>(e.op(i))) {
2687 std::string name = ex_to<function>(e.op(i)).get_name();
2695 lst newparameter = ex_to<lst>(h.op(0));
2696 newparameter.prepend(-1);
2697 return e.subs(h == H(newparameter, h.op(1)).hold()).expand();
2699 return (e * H(lst(-1),(1-arg)/(1+arg)).hold()).expand();
2704 // do integration [ReV] (55)
2705 // put parameter 1 in front of existing parameters
2706 ex trafo_H_1mxt1px_prepend_one(const ex& e, const ex& arg)
2710 if (is_a<function>(e)) {
2711 name = ex_to<function>(e).get_name();
2716 for (std::size_t i = 0; i < e.nops(); i++) {
2717 if (is_a<function>(e.op(i))) {
2718 std::string name = ex_to<function>(e.op(i)).get_name();
2726 lst newparameter = ex_to<lst>(h.op(0));
2727 newparameter.prepend(1);
2728 return e.subs(h == H(newparameter, h.op(1)).hold()).expand();
2730 return (e * H(lst(1),(1-arg)/(1+arg)).hold()).expand();
2735 // do x -> 1-x transformation
2736 struct map_trafo_H_1mx : 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 (std::size_t i = 1; i < parameter.nops(); i++) {
2755 if (parameter.op(i) != 0) {
2762 for (int i=parameter.nops(); i>0; i--) {
2763 newparameter.append(1);
2765 return pow(-1, parameter.nops()) * H(newparameter, 1-arg).hold();
2767 } else if (parameter.op(0) == -1) {
2768 throw std::runtime_error("map_trafo_H_1mx: cannot handle weights equal -1!");
2770 for (std::size_t i = 1; i < parameter.nops(); i++) {
2771 if (parameter.op(i) != 1) {
2778 for (int i=parameter.nops(); i>0; i--) {
2779 newparameter.append(0);
2781 return pow(-1, parameter.nops()) * H(newparameter, 1-arg).hold();
2785 lst newparameter = parameter;
2786 newparameter.remove_first();
2788 if (parameter.op(0) == 0) {
2791 ex res = convert_H_to_zeta(parameter);
2792 //ex res = convert_from_RV(parameter, 1).subs(H(wild(1),wild(2))==zeta(wild(1)));
2793 map_trafo_H_1mx recursion;
2794 ex buffer = recursion(H(newparameter, arg).hold());
2795 if (is_a<add>(buffer)) {
2796 for (std::size_t i = 0; i < buffer.nops(); i++) {
2797 res -= trafo_H_prepend_one(buffer.op(i), arg);
2800 res -= trafo_H_prepend_one(buffer, arg);
2807 map_trafo_H_1mx recursion;
2808 map_trafo_H_mult unify;
2809 ex res = H(lst(1), arg).hold() * H(newparameter, arg).hold();
2810 std::size_t firstzero = 0;
2811 while (parameter.op(firstzero) == 1) {
2814 for (std::size_t i = firstzero-1; i < parameter.nops()-1; i++) {
2818 newparameter.append(parameter[j+1]);
2820 newparameter.append(1);
2821 for (; j<parameter.nops()-1; j++) {
2822 newparameter.append(parameter[j+1]);
2824 res -= H(newparameter, arg).hold();
2826 res = recursion(res).expand() / firstzero;
2836 // do x -> 1/x transformation
2837 struct map_trafo_H_1overx : public map_function
2839 ex operator()(const ex& e)
2841 if (is_a<add>(e) || is_a<mul>(e)) {
2842 return e.map(*this);
2845 if (is_a<function>(e)) {
2846 std::string name = ex_to<function>(e).get_name();
2849 lst parameter = ex_to<lst>(e.op(0));
2852 // special cases if all parameters are either 0, 1 or -1
2853 bool allthesame = true;
2854 if (parameter.op(0) == 0) {
2855 for (std::size_t i = 1; i < parameter.nops(); i++) {
2856 if (parameter.op(i) != 0) {
2862 return pow(-1, parameter.nops()) * H(parameter, 1/arg).hold();
2864 } else if (parameter.op(0) == -1) {
2865 for (std::size_t i = 1; i < parameter.nops(); i++) {
2866 if (parameter.op(i) != -1) {
2872 map_trafo_H_mult unify;
2873 return unify((pow(H(lst(-1),1/arg).hold() - H(lst(0),1/arg).hold(), parameter.nops())
2874 / factorial(parameter.nops())).expand());
2877 for (std::size_t i = 1; i < parameter.nops(); i++) {
2878 if (parameter.op(i) != 1) {
2884 map_trafo_H_mult unify;
2885 return unify((pow(H(lst(1),1/arg).hold() + H(lst(0),1/arg).hold() + H_polesign, parameter.nops())
2886 / factorial(parameter.nops())).expand());
2890 lst newparameter = parameter;
2891 newparameter.remove_first();
2893 if (parameter.op(0) == 0) {
2896 ex res = convert_H_to_zeta(parameter);
2897 map_trafo_H_1overx recursion;
2898 ex buffer = recursion(H(newparameter, arg).hold());
2899 if (is_a<add>(buffer)) {
2900 for (std::size_t i = 0; i < buffer.nops(); i++) {
2901 res += trafo_H_1tx_prepend_zero(buffer.op(i), arg);
2904 res += trafo_H_1tx_prepend_zero(buffer, arg);
2908 } else if (parameter.op(0) == -1) {
2910 // leading negative one
2911 ex res = convert_H_to_zeta(parameter);
2912 map_trafo_H_1overx recursion;
2913 ex buffer = recursion(H(newparameter, arg).hold());
2914 if (is_a<add>(buffer)) {
2915 for (std::size_t i = 0; i < buffer.nops(); i++) {
2916 res += trafo_H_1tx_prepend_zero(buffer.op(i), arg) - trafo_H_1tx_prepend_minusone(buffer.op(i), arg);
2919 res += trafo_H_1tx_prepend_zero(buffer, arg) - trafo_H_1tx_prepend_minusone(buffer, arg);
2926 map_trafo_H_1overx recursion;
2927 map_trafo_H_mult unify;
2928 ex res = H(lst(1), arg).hold() * H(newparameter, arg).hold();
2929 std::size_t firstzero = 0;
2930 while (parameter.op(firstzero) == 1) {
2933 for (std::size_t i = firstzero-1; i < parameter.nops() - 1; i++) {
2937 newparameter.append(parameter[j+1]);
2939 newparameter.append(1);
2940 for (; j<parameter.nops()-1; j++) {
2941 newparameter.append(parameter[j+1]);
2943 res -= H(newparameter, arg).hold();
2945 res = recursion(res).expand() / firstzero;
2957 // do x -> (1-x)/(1+x) transformation
2958 struct map_trafo_H_1mxt1px : public map_function
2960 ex operator()(const ex& e)
2962 if (is_a<add>(e) || is_a<mul>(e)) {
2963 return e.map(*this);
2966 if (is_a<function>(e)) {
2967 std::string name = ex_to<function>(e).get_name();
2970 lst parameter = ex_to<lst>(e.op(0));
2973 // special cases if all parameters are either 0, 1 or -1
2974 bool allthesame = true;
2975 if (parameter.op(0) == 0) {
2976 for (std::size_t i = 1; i < parameter.nops(); i++) {
2977 if (parameter.op(i) != 0) {