]> www.ginac.de Git - ginac.git/blob - check/time_fateman_expand.cpp
it is now enforced that indices of a metric tensor are of the same dimension
[ginac.git] / check / time_fateman_expand.cpp
1 /** @file time_fateman_expand.cpp
2  *
3  *  Time for polynomial expansion of (x+y+z+1)^20 * ((x+y+z+1)^20+1).
4  *  This test was suggested by Richard J. Fateman as a benchmark for programs
5  *  to multiply sparse polynomials fast.
6  */
7
8 /*
9  *  GiNaC Copyright (C) 1999-2002 Johannes Gutenberg University Mainz, Germany
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  */
25
26 #include "times.h"
27
28 static unsigned test(void)
29 {
30         unsigned result = 0;
31         const symbol x("x"), y("y"), z("z");
32
33         const ex p = pow(x+y+z+1, 20);
34
35         const ex hugesum = expand(p * (p+1));
36
37         if (hugesum.nops()!=12341) {
38                 clog << "(x+y+z+1)^20 * ((x+y+z+1)^20+1) was miscomputed!" << endl;
39                 ++result;
40         }
41
42         return result;
43 }
44
45 unsigned time_fateman_expand(void)
46 {
47         unsigned result = 0;
48         unsigned count = 0;
49         timer concord;
50         double time = .0;
51
52         cout << "timing Fateman's polynomial expand benchmark" << flush;
53         clog << "-------Fateman's polynomial expand benchmark:" << endl;
54
55         concord.start();
56         // correct for very small times:
57         do {
58                 result = test();
59                 ++count;
60         } while ((time=concord.read())<0.1 && !result);
61         cout << '.' << flush;
62
63         if (!result) {
64                 cout << " passed ";
65                 clog << "(no output)" << endl;
66         } else {
67                 cout << " failed ";
68         }
69         cout << int(1000*(time/count))*0.001 << 's' << endl;
70
71         return result;
72 }