]> www.ginac.de Git - ginac.git/blob - check/time_lw_IJKL.cpp
[BUGFIX] Fix crash in parser.
[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-2019 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 "ginac.h"
25 #include "timer.h"
26 using namespace GiNaC;
27
28 #include <iostream>
29 #include <vector>
30 using namespace std;
31
32 static unsigned test(unsigned n)
33 {
34         unsigned result = 0;
35         timer cartier;
36         char name = (n==40?'I':(n==70?'K':'?'));
37         
38         cout << "timing Lewis-Wester test " << name
39              << " (invert rank " << n << " Hilbert)" << flush;
40         
41         // Create a rank n Hilbert matrix:
42         matrix H(n,n);
43         for (unsigned r=0; r<n; ++r)
44                 for (unsigned c=0; c<n; ++c)
45                         H.set(r,c,numeric(1,r+c+1));
46         // invert it:
47         cartier.start();
48         matrix Hinv(n,n);
49         Hinv = H.inverse();
50         cout << ". passed ";
51         cout << cartier.read() << 's' << endl;
52         
53         // check result:
54         name = (n==40?'J':(n==70?'L':'?'));
55         
56         cout << "timing Lewis-Wester test " << name
57              << " (check rank " << n << " Hilbert)" << flush;
58         
59         cartier.reset();
60         matrix identity = H.mul(Hinv);
61         bool correct = true;
62         for (unsigned r=0; r<n; ++r)
63                 for (unsigned c=0; c<n; ++c) {
64                         if (r==c) {
65                                 if (identity(r,c)!=1)
66                                         correct = false;
67                         } else {
68                                 if (identity(r,c)!=0)
69                                         correct = false;
70                         }
71                 }
72         if (!correct)
73                 ++result;
74         cout << cartier.read() << 's' << endl;
75         return result;
76 }
77
78 unsigned time_lw_IJKL()
79 {
80         unsigned result = 0;
81         
82         // Tests I and J:
83         result += test(40);
84         // Tests K and L:
85         result += test(70);
86         
87         return result;
88 }
89
90 extern void randomify_symbol_serials();
91
92 int main(int argc, char** argv)
93 {
94         randomify_symbol_serials();
95         cout << setprecision(2) << showpoint;
96         return time_lw_IJKL();
97 }