]> www.ginac.de Git - ginac.git/blob - check/time_lw_IJKL.cpp
indexed::eval: use standard C++ RTTI.
[ginac.git] / check / time_lw_IJKL.cpp
1 /** @file time_lw_IJKL.cpp
2  *
3  *  Tests I, J, K and L from the paper "Comparison of Polynomial-Oriented CAS"
4  *  by Robert H. Lewis and Michael Wester. */
5
6 /*
7  *  GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22  */
23
24 #include <iostream>
25 #include <vector>
26 #include "ginac.h"
27 #include "timer.h"
28 using namespace std;
29 using namespace GiNaC;
30
31 static unsigned test(unsigned n)
32 {
33         unsigned result = 0;
34         timer cartier;
35         char name = (n==40?'I':(n==70?'K':'?'));
36         
37         cout << "timing Lewis-Wester test " << name
38              << " (invert rank " << n << " Hilbert)" << flush;
39         
40         // Create a rank n Hilbert matrix:
41         matrix H(n,n);
42         for (unsigned r=0; r<n; ++r)
43                 for (unsigned c=0; c<n; ++c)
44                         H.set(r,c,numeric(1,r+c+1));
45         // invert it:
46         cartier.start();
47         matrix Hinv(n,n);
48         Hinv = H.inverse();
49         cout << ". passed ";
50         cout << cartier.read() << 's' << endl;
51         
52         // check result:
53         name = (n==40?'J':(n==70?'L':'?'));
54         
55         cout << "timing Lewis-Wester test " << name
56              << " (check rank " << n << " Hilbert)" << flush;
57         
58         cartier.reset();
59         matrix identity = H.mul(Hinv);
60         bool correct = true;
61         for (unsigned r=0; r<n; ++r)
62                 for (unsigned c=0; c<n; ++c) {
63                         if (r==c) {
64                                 if (identity(r,c)!=1)
65                                         correct = false;
66                         } else {
67                                 if (identity(r,c)!=0)
68                                         correct = false;
69                         }
70                 }
71         if (!correct)
72                 ++result;
73         cout << cartier.read() << 's' << endl;
74         return result;
75 }
76
77 unsigned time_lw_IJKL()
78 {
79         unsigned result = 0;
80         
81         // Tests I and J:
82         result += test(40);
83         // Tests K and L:
84         result += test(70);
85         
86         return result;
87 }
88
89 extern void randomify_symbol_serials();
90
91 int main(int argc, char** argv)
92 {
93         randomify_symbol_serials();
94         cout << setprecision(2) << showpoint;
95         return time_lw_IJKL();
96 }