]> www.ginac.de Git - ginac.git/blob - check/time_fateman_expand.cpp
Implicit conversion from cl_N to numeric considered harmful.
[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-2008 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24  */
25
26 #include <iostream>
27 #include "ginac.h"
28 #include "timer.h"
29 using namespace std;
30 using namespace GiNaC;
31
32 static unsigned test()
33 {
34         unsigned result = 0;
35         const symbol x("x"), y("y"), z("z");
36
37         const ex p = pow(x+y+z+1, 20);
38
39         const ex hugesum = expand(p * (p+1));
40
41         if (hugesum.nops()!=12341) {
42                 clog << "(x+y+z+1)^20 * ((x+y+z+1)^20+1) was miscomputed!" << endl;
43                 ++result;
44         }
45
46         return result;
47 }
48
49 unsigned time_fateman_expand()
50 {
51         unsigned result = 0;
52         unsigned count = 0;
53         timer concord;
54         double time = .0;
55
56         cout << "timing Fateman's polynomial expand benchmark" << flush;
57
58         concord.start();
59         // correct for very small times:
60         do {
61                 result = test();
62                 ++count;
63         } while ((time=concord.read())<0.1 && !result);
64         cout << '.' << flush;
65
66         cout << time/count << 's' << endl;
67
68         return result;
69 }
70
71 extern void randomify_symbol_serials();
72
73 int main(int argc, char** argv)
74 {
75         randomify_symbol_serials();
76         cout << setprecision(2) << showpoint;
77         return time_fateman_expand();
78 }