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