]> www.ginac.de Git - ginac.git/blobdiff - check/exam_inifcns_nstdsums.cpp
New checks for G and Li functions.
[ginac.git] / check / exam_inifcns_nstdsums.cpp
index 0ad9f1a80fc1e34d08285dca689a8c852a277e1e..8434fd1e699d28cd3cd1d69506f03b037bd5ddca 100644 (file)
@@ -4,7 +4,7 @@
  *  functions. */
 
 /*
- *  GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
 #include <fstream>
 
 
-struct point
+////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+//  S exam
+////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+
+
+/*
+ * The data in the following include file has been produced by the following
+ * Mathematica (V4.1) script:
+ *
+ *
+ *    x={2/10,1,14/10,30/10}
+ *    y={0,3/10,-14/10}
+ *    st = OpenAppend["exam_inifcns_nstdsums_data.raw"]
+ *    $NumberMarks = False
+ *    Do[
+ *      Do[
+ *        Do[Write[st, i]; Write[st,j]; Write[st,x[[k]]+I*y[[l]]];
+ *          Write[st,Chop[N[PolyLog[i,j,x[[k]]+I*y[[l]]],25]]],{i,3},{j,3}], {k,4}],{l,3}]
+ *    Do[
+ *      Do[
+ *        Do[Write[st, i]; Write[st,j]; Write[st,-x[[k]]+I*y[[l]]];
+ *          Write[st,Chop[N[PolyLog[i,j,-x[[k]]+I*y[[l]]],25]]],{i,3},{j,3}], {k,4}], {l,3}]
+ *    Close[st]
+ *
+ *    
+ * and postprocessed by the following shell script
+ *
+ *
+ *    #/bin/sh
+ *    IFS=$'\n'
+ *    cat exam_inifcns_nstdsums_data.raw | sed -e 's/\*\^/E/g' > exam_inifcns_nstdsums_data.raw2
+ *    echo 'const char *data[] = {' > exam_inifcns_nstdsums_data.raw3
+ *    for i in `cat exam_inifcns_nstdsums_data.raw2`; do echo \"$i\",; done >> exam_inifcns_nstdsums_data.raw3
+ *    echo '"-999"};' >> exam_inifcns_nstdsums.h
+ *
+ *
+ */
+#include "exam_inifcns_nstdsums.h"
+
+
+// signals end of data
+const int ENDMARK = -999;
+
+
+static unsigned inifcns_test_S()
 {
-       ex x;
-       ex res;
-};
+       int digitsbuf = Digits;
+       // precision of data
+       Digits = 22;
+       ex prec = 5 * pow(10, -(int)Digits);
+       
+       unsigned result = 0;
+       
+       int i = 0;
+       while (true) {
+               ex n(data[i++],symbol());
+               if (n == ENDMARK) {
+                       break;
+               }
+               ex p(data[i++],symbol());
+               ex x(data[i++],symbol());
+               ex res(data[i++],symbol());
+               ex res2 = S(n, p, x).evalf();
+               if (abs(res-res2) > prec) {
+                       clog << "S(" << n << "," << p << "," << x << ") seems to be wrong:" << endl;
+                       clog << "GiNaC           : " << res2 << endl;
+                       clog << "Reference       : " << res << endl;
+                       clog << "Abs. Difference : " << res2-res << endl;
+                       if (res2 != 0) {
+                               ex reldiff = abs((res2-res)/res2);
+                               clog << "Rel. Difference : " << reldiff << endl;
+                       }
+                       result++;
+               }
+               if (i % 80) {
+                       cout << "." << flush;
+               }
+       }
 
+       Digits = digitsbuf;
 
-const int NDIM = 5;
-const int PDIM = 5;
+       return result;
+}
 
-typedef vector<point> vp;
 
-vp pp[NDIM][PDIM];
+////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+//  H/Li exam
+////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
 
 
-static unsigned inifcns_consist_S(void)
+static unsigned inifcns_test_HLi()
 {
+       int digitsbuf = Digits;
+       Digits = 17;
+       ex prec = 5 * pow(10, -(int)Digits);
+       numeric almostone("0.999999999999999999");
        unsigned result = 0;
+
+       lst res;
+       
+       res.append(H(lst(2,1),numeric(1)/2).hold() - (zeta(3)/8 - pow(log(2),3)/6));
+       res.append(H(lst(2,1,3),numeric(1)/3).hold() - Li(lst(2,1,3),lst(numeric(1)/3,1,1)).hold());
+       res.append(H(lst(2,1,3),numeric(98)/100).hold() - Li(lst(2,1,3),lst(numeric(98)/100,1,1)).hold());
+       res.append(H(lst(2,1,3),numeric(245)/100).hold() - Li(lst(2,1,3),lst(numeric(245)/100,1,1)).hold());
+       res.append(H(lst(4,1,1,1),numeric(1)/3).hold() - S(3,4,numeric(1)/3).hold());
+       res.append(H(lst(4,1,1,1),numeric(98)/100).hold() - S(3,4,numeric(98)/100).hold());
+       res.append(H(lst(4,1,1,1),numeric(245)/100).hold() - S(3,4,numeric(245)/100).hold());
+       res.append(H(lst(2,2,3),almostone).hold() - zeta(lst(2,2,3)));
+       res.append(H(lst(-3,-1,2,1),almostone).hold() - zeta(lst(3,1,2,1),lst(-1,1,-1,1)));
+       res.append(H(lst(-2,1,3),numeric(1)/3).hold() - -Li(lst(2,1,3),lst(-numeric(1)/3,-1,1)).hold());
+       res.append(H(lst(-2,1,3),numeric(98)/100).hold() - -Li(lst(2,1,3),lst(-numeric(98)/100,-1,1)).hold());
+       res.append(H(lst(-2,1,3),numeric(245)/100).hold() - -Li(lst(2,1,3),lst(-numeric(245)/100,-1,1)).hold());
+       res.append(H(lst(-3,1,-2,0,0),numeric(3)/10).hold() - convert_H_to_Li(lst(-3,1,-2,0,0),numeric(3)/10).eval());
        
-       ifstream in("exam_inifcns_nstdsums_data");
+       for (lst::const_iterator it = res.begin(); it != res.end(); it++) {
+               ex diff = abs((*it).evalf());
+               if (diff > prec) {
+                       clog << *it << " seems to be wrong: " << diff << endl;
+                       result++;
+               }
+               cout << "." << flush;
+       }
+
+       Digits = digitsbuf;
 
-       if (!in) {
-               clog << "exam_inifcns_nstdsums_data not readable!" << endl;
-               return 666;
+       // conjugate test
+       numeric cdif = ex_to<numeric>(H(lst(2,2,1),5.0-5.0*I) - H(lst(2,2,1),5.0+5.0*I));
+       numeric cadd = ex_to<numeric>(H(lst(2,2,1),5.0-5.0*I) + H(lst(2,2,1),5.0+5.0*I));
+       if ((cdif.real() > prec) || (cadd.imag() > prec)) {
+               clog << "complex conjugation test of H({2,2,1},5.0-5.0*I) seems to be wrong: " << cdif << " " << cadd << endl;
+               result++;
        }
 
-       string str;
-       point ppbuf;
+       return result;
+}
 
-       while (1) {
-               getline(in,str);
-               if (!in)
-                       break;
-               ex en(str,symbol());
-               getline(in,str);
-               if (!in)
-                       break;
-               ex ep(str,symbol());
-               getline(in,str);
-               if (!in)
-                       break;
-               ex x(str,symbol());
-               getline(in,str);
-               if (!in)
-                       break;
-               ex res(str,symbol());
 
-               numeric n = ex_to<numeric>(en);
-               numeric p = ex_to<numeric>(ep);
+////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+//  zeta exam
+////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
 
-               ppbuf.x = x;
-               ppbuf.res = res;
 
-               pp[n.to_int()-1][p.to_int()-1].push_back(ppbuf);
-       }
+static unsigned inifcns_test_zeta()
+{
+       int digitsbuf = Digits;
+       
+       unsigned result = 0;
 
-       in.close();
-
-       vp::iterator it;
-       int error = 0;
-
-       cout << endl << "Calculating ";
-       for (int sum=2; sum<=3; sum++) {
-               for (int nn=1; nn<sum; nn++) {
-                       vp& da = pp[nn-1][sum-nn-1];
-                       for (it = da.begin(); it!=da.end(); it++) {
-                               cout << "S(" << nn << "," << sum-nn << "," << it->x << ") " << flush;
-                               ex res = S(nn,sum-nn,it->x).evalf();
-                               if (!is_a<numeric>(res)) {
-                                       if ((it->x != -1) || ((sum-nn) == 1)) {
-                                               clog << "S(" << nn << "," << sum-nn << "," << it->x << ") didn't give numerical result!" << endl;
-                                               result++;
-                                       }
-                               } 
-                               else {
-                                       ex reldiff = abs((it->res-res)/it->res);
-                                       if ((!is_a<numeric>(res)) || (reldiff > numeric("1E-10"))) {
-                                               clog << "S(" << nn << "," << sum-nn << "," << it->x << ") seems to be wrong:" << endl;
-                                               clog << "GiNaC           : " << res << endl;
-                                               clog << "Reference       : " << it->res << endl;
-                                               clog << "Abs. Difference : " << it->res-res << endl;
-                                               clog << "Rel. Difference : " << reldiff << endl;
-                                               result++;
-                                       }
-                               }
-                       }
+       lst res;
+       
+       res.append(zeta(lst(2,1)) - zeta(3));
+       res.append(zeta(lst(2,1,1,1,1)) - zeta(6));
+       res.append(zeta(lst(6,3)) - (zeta(9)*83/2 - zeta(2)*zeta(7)*21 - zeta(2)*zeta(2)*zeta(5)*12/5));
+       res.append(zeta(lst(4,2,3)) - (-zeta(9)*59 + zeta(2)*zeta(7)*28 + pow(zeta(2),2)*zeta(5)*4 -
+                                      pow(zeta(3),3)/3 + pow(zeta(2),3)*zeta(3)*8/21));
+       res.append(zeta(lst(3,1,3,1,3,1,3,1)) - (2*pow(Pi,16)/factorial(18)));
+       res.append(zeta(lst(2),lst(-1)) - -zeta(2)/2);
+       res.append(zeta(lst(1,2),lst(-1,1)) - (-zeta(3)/4 - zeta(lst(1),lst(-1))*zeta(2)/2));
+       res.append(zeta(lst(2,1,1),lst(-1,-1,1)) - (-pow(zeta(2),2)*23/40 - pow(zeta(lst(1),lst(-1)),2)*zeta(2)*3/4
+                                                   - zeta(lst(3,1),lst(-1,1))*3/2 - zeta(lst(1),lst(-1))*zeta(3)*21/8));
+       
+       for (lst::const_iterator it = res.begin(); it != res.end(); it++) {
+               Digits = 17;
+               ex prec = 5 * pow(10, -(int)Digits);
+               ex diff = abs((*it).evalf());
+               if (diff > prec) {
+                       clog << *it << " seems to be wrong: " << diff << endl;
+                       clog << "Digits: " << Digits << endl;
+                       result++;
+               }
+               cout << "." << flush;
+               Digits = 40;
+               prec = 5 * pow(10, -(int)Digits);
+               diff = abs((*it).evalf());
+               if (diff > prec) {
+                       clog << *it << " seems to be wrong: " << diff << endl;
+                       clog << "Digits: " << Digits << endl;
+                       result++;
                }
+               cout << "." << flush;
+       }
+
+       Digits = digitsbuf;
 
+       return result;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+//  H/Li exam
+////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+
+
+static unsigned inifcns_test_LiG()
+{
+       int digitsbuf = Digits;
+       Digits = 17;
+       ex prec = 5 * pow(10, -(int)Digits);
+       numeric almostone("0.99999999999999999999");
+       unsigned result = 0;
+
+       lst res;
+       
+       res.append(Li(lst(4), lst(6)).hold() - Li(4, 6.0));
+       res.append(G(lst(0,0,5.0,0,2.0,0,0,0,3.0),0.5).hold()
+                  + Li(lst(3,2,4), lst(numeric(1,10), numeric(5,2), numeric(2,3))));
+       res.append(Li(lst(2,1,1), lst(almostone, almostone, almostone)) - zeta(lst(2,1,1)));
+
+       // check Li_{1,1} against known expression
+       symbol x("x"), y("y");
+       ex eps = 1e-30*I;
+       ex s1 = Li(lst(1,1),lst(x,y));
+       ex s2 = log(1-1/x/y-eps)*log((1-1/x-eps)/(1/x/y-1/x)) + Li(2,(1-1/x/y-eps)/(1/x-1/x/y))
+                       - log(-1/x/y-eps)*log((-1/x-eps)/(1/x/y-1/x)) - Li(2,(-1/x/y-eps)/(1/x-1/x/y))
+                       - log(-1/x/y-eps)*log(1-1/x-eps) + log(-1/x/y-eps)*log(-1/x-eps);
+       res.append(s1.subs(lst(x==numeric(1)/2, y==3)) - s2.subs(lst(x==numeric(1)/2, y==3)));
+       res.append(s1.subs(lst(x==numeric(3)/2, y==numeric(1)/2)) - s2.subs(lst(x==numeric(3)/2, y==numeric(1)/2)));
+       res.append(s1.subs(lst(x==2, y==numeric(4)/5)) - s2.subs(lst(x==2, y==numeric(4)/5)));
+
+       // shuffle and quasi-shuffle identities
+       res.append(G(lst(0,0.2),1).hold() * G(lst(0.5),1).hold() - G(lst(0.5,0,0.2),1).hold()
+                       - G(lst(0,0.5,0.2),1).hold() - G(lst(0,0.2,0.5),1).hold());
+       res.append(G(lst(0,0.5),1).hold() * G(lst(0.6),1).hold() - G(lst(0,0.5,0.5*0.6),1).hold()
+                       - G(lst(0.6,0,0.5*0.6),1).hold() + G(lst(0,0,0.5*0.6),1).hold());
+       res.append(Li(lst(2),lst(numeric(1,5))).hold() * Li(lst(3),lst(7)).hold() - Li(lst(2,3),lst(numeric(1,5),7)).hold()
+                       - Li(lst(3,2),lst(7,numeric(1,5))).hold() - Li(lst(5),lst(numeric(7,5))).hold());
+       symbol a1, a2, a3, a4;
+       res.append((G(lst(a1,a2),1) * G(lst(a3,a4),1) - G(lst(a1,a2,a3,a4),1)
+                       - G(lst(a1,a3,a2,a4),1) - G(lst(a3,a1,a2,a4),1)
+                       - G(lst(a1,a3,a4,a2),1) - G(lst(a3,a1,a4,a2),1) - G(lst(a3,a4,a1,a2),1))
+                               .subs(lst(a1==numeric(1)/10, a2==numeric(3)/10, a3==numeric(7)/10, a4==5)));
+       res.append(G(lst(-0.009),1).hold() * G(lst(-8,1.4999),1).hold() - G(lst(-0.009,-8,1.4999),1).hold()
+                       - G(lst(-8,-0.009,1.4999),1).hold() - G(lst(-8,1.4999,-0.009),1).hold());
+       res.append(G(lst(sqrt(numeric(1)/2)+I*sqrt(numeric(1)/2)),1).hold() * G(lst(1.51,-0.999),1).hold()
+                       - G(lst(sqrt(numeric(1)/2)+I*sqrt(numeric(1)/2),1.51,-0.999),1).hold()
+                       - G(lst(1.51,sqrt(numeric(1)/2)+I*sqrt(numeric(1)/2),-0.999),1).hold()
+                       - G(lst(1.51,-0.999,sqrt(numeric(1)/2)+I*sqrt(numeric(1)/2)),1).hold());
+       // checks for hoelder convolution which is used if one argument has a distance to one smaller than 0.01 
+       res.append(G(lst(0, 1.2, 1, 1.01), 1).hold() - G(lst(0, 1.2, 1, numeric("1.009999999999999999")), 1).hold());
+
+       for (lst::const_iterator it = res.begin(); it != res.end(); it++) {
+               ex diff = abs((*it).evalf());
+               if (diff > prec) {
+                       clog << *it << " seems to be wrong: " << diff << endl;
+                       result++;
+               }
+               cout << "." << flush;
        }
-       cout << endl;
 
        return result;
 }
@@ -128,7 +294,10 @@ unsigned exam_inifcns_nstdsums(void)
        cout << "examining consistency of nestedsums functions" << flush;
        clog << "----------consistency of nestedsums functions:" << endl;
        
-       result += inifcns_consist_S();  cout << '.' << flush;
+       result += inifcns_test_zeta();
+       result += inifcns_test_S();
+       result += inifcns_test_HLi();
+       result += inifcns_test_LiG();
        
        if (!result) {
                cout << " passed " << endl;
@@ -139,4 +308,3 @@ unsigned exam_inifcns_nstdsums(void)
        
        return result;
 }
-