]> www.ginac.de Git - ginac.git/blob - check/time_lw_M1.cpp
[bugfix] chinrem_gcd: handle polynomials over rationals properly.
[ginac.git] / check / time_lw_M1.cpp
1 /** @file time_lw_M1.cpp
2  *
3  *  Test M1 from the paper "Comparison of Polynomial-Oriented CAS" by Robert H.
4  *  Lewis and Michael Wester. */
5
6 /*
7  *  GiNaC Copyright (C) 1999-2010 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 using namespace std;
30
31 static unsigned test()
32 {
33         // Determinant of a sparse matrix that comes up in graph theory:
34         symbol x1("x1"), x2("x2"), x3("x3"), x4("x4"), x5("x5");
35         ex w[26][11] = {
36                 { 1,  1,  1,  7, x4, 12, x3, 17, x2, 22, x1},
37                 { 2,  2,  1,  8, x4, 13, x3, 18, x2, 23, x1},
38                 { 3,  3,  1,  9, x4, 14, x3, 19, x2, 24, x1},
39                 { 4,  4,  1, 10, x4, 15, x3, 20, x2, 25, x1},
40                 { 5,  5,  1, 26,  1,  1,  0,  1,  0,  1, 0 },
41                 { 6,  2, x5,  6,  1, 12, x3, 17, x2, 22, x1},
42                 { 7,  3, x5,  7,  1, 13, x3, 18, x2, 23, x1},
43                 { 8,  4, x5,  8,  1, 14, x3, 19, x2, 24, x1},
44                 { 9,  5, x5,  9,  1, 15, x3, 20, x2, 25, x1},
45                 {10, 10,  1, 26,  1,  1,  0,  1,  0,  1, 0 },
46                 {11,  2, x5,  7, x4, 11,  1, 17, x2, 22, x1},
47                 {12,  3, x5,  8, x4, 12,  1, 18, x2, 23, x1},
48                 {13,  4, x5,  9, x4, 13,  1, 19, x2, 24, x1},
49                 {14,  5, x5, 10, x4, 14,  1, 20, x2, 25, x1},
50                 {15, 15,  1, 26,  1,  1,  0,  1,  0,  1, 0 },
51                 {16,  2, x5,  7, x4, 12, x3, 16,  1, 22, x1},
52                 {17,  3, x5,  8, x4, 13, x3, 17,  1, 23, x1},
53                 {18,  4, x5,  9, x4, 14, x3, 18,  1, 24, x1},
54                 {19,  5, x5, 10, x4, 15, x3, 19,  1, 25, x1},
55                 {20, 20,  1, 26,  1,  1,  0,  1,  0,  1, 0 },
56                 {21,  2, x5,  7, x4, 12, x3, 17, x2, 21, 1 },
57                 {22,  3, x5,  8, x4, 13, x3, 18, x2, 22, 1 },
58                 {23,  4, x5,  9, x4, 14, x3, 19, x2, 23, 1 },
59                 {24,  5, x5, 10, x4, 15, x3, 20, x2, 24, 1 },
60                 {25, 25,  1, 26,  1,  1,  0,  1,  0,  1, 0 },
61                 {26,  1, x5,  6, x4, 11, x3, 16, x2, 21, x1}
62         };
63         matrix m(26,26);
64         for (unsigned r=0; r<26; ++r) {
65                 for (unsigned c=0; c<5; ++c) {
66                         m.set(r,
67                               unsigned(ex_to<numeric>(w[r][2*c+1]).to_int()-1),
68                               w[r][2*c+2]);
69                 }
70         }
71         ex det = m.determinant();
72         // The result should have been:
73         ex cmp("-12*x2^2*x5^2*x4-12*x1*x5^2*x3^2-x5^3*x4^2-12*x1*x5^2*x4^2-12*x2*x5^2*x4^2-12*x3*x5^2*x4^2-x4^3*x5^2-36*x3*x1*x5^2*x4-36*x3*x1*x4^2*x5-36*x3*x2*x5^2*x4-36*x3*x2*x4^2*x5-2*x5^3*x4*x2-12*x3^2*x5^2*x4-12*x3^2*x4^2*x5-2*x5^3*x4*x3-2*x4^3*x5*x3-12*x1*x5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36*x1*x5*x2^2*x4-36*x1*x5*x2^2*x3-36*x1*x4*x2^2*x3-x1^2*x5^3-x1^2*x4^3-x1^2*x3^3-x2^3*x5^2-x2^3*x4^2-x2^3*x3^2-x1^2*x2^3",lst(x1,x2,x3,x4,x5));
74         if (det!=cmp) {
75                 clog << "The determinant was miscalculated" << endl;
76                 return 1;
77         }
78         return 0;
79 }
80
81 unsigned time_lw_M1()
82 {
83         unsigned result = 0;
84         unsigned count = 0;
85         timer rolex;
86         double time = .0;
87         
88         cout << "timing Lewis-Wester test M1 (26x26 sparse, det)" << flush;
89         
90         rolex.start();
91         // correct for very small times:
92         do {
93                 result = test();
94                 ++count;
95         } while ((time=rolex.read())<0.1 && !result);
96         cout << '.' << flush;
97         cout << time/count << 's' << endl;
98         
99         return result;
100 }
101
102 extern void randomify_symbol_serials();
103
104 int main(int argc, char** argv)
105 {
106         randomify_symbol_serials();
107         cout << setprecision(2) << showpoint;
108         return time_lw_M1();
109 }