]> www.ginac.de Git - ginac.git/blob - check/time_lw_M1.cpp
- cint/*: Revamped the launch-scheme for ginaccint.bin. It must be done
[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-2000 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include "times.h"
25
26 static unsigned test(void)
27 {
28     // Determinant of a sparse matrix that comes up in graph theory:
29     symbol x1("x1"), x2("x2"), x3("x3"), x4("x4"), x5("x5");
30     static ex w[26][11] = {
31         { 1,  1,  1,  7, x4, 12, x3, 17, x2, 22, x1},
32         { 2,  2,  1,  8, x4, 13, x3, 18, x2, 23, x1},
33         { 3,  3,  1,  9, x4, 14, x3, 19, x2, 24, x1},
34         { 4,  4,  1, 10, x4, 15, x3, 20, x2, 25, x1},
35         { 5,  5,  1, 26,  1,  1,  0,  1,  0,  1, 0 },
36         { 6,  2, x5,  6,  1, 12, x3, 17, x2, 22, x1},
37         { 7,  3, x5,  7,  1, 13, x3, 18, x2, 23, x1},
38         { 8,  4, x5,  8,  1, 14, x3, 19, x2, 24, x1},
39         { 9,  5, x5,  9,  1, 15, x3, 20, x2, 25, x1},
40         {10, 10,  1, 26,  1,  1,  0,  1,  0,  1, 0 },
41         {11,  2, x5,  7, x4, 11,  1, 17, x2, 22, x1},
42         {12,  3, x5,  8, x4, 12,  1, 18, x2, 23, x1},
43         {13,  4, x5,  9, x4, 13,  1, 19, x2, 24, x1},
44         {14,  5, x5, 10, x4, 14,  1, 20, x2, 25, x1},
45         {15, 15,  1, 26,  1,  1,  0,  1,  0,  1, 0 },
46         {16,  2, x5,  7, x4, 12, x3, 16,  1, 22, x1},
47         {17,  3, x5,  8, x4, 13, x3, 17,  1, 23, x1},
48         {18,  4, x5,  9, x4, 14, x3, 18,  1, 24, x1},
49         {19,  5, x5, 10, x4, 15, x3, 19,  1, 25, x1},
50         {20, 20,  1, 26,  1,  1,  0,  1,  0,  1, 0 },
51         {21,  2, x5,  7, x4, 12, x3, 17, x2, 21, 1 },
52         {22,  3, x5,  8, x4, 13, x3, 18, x2, 22, 1 },
53         {23,  4, x5,  9, x4, 14, x3, 19, x2, 23, 1 },
54         {24,  5, x5, 10, x4, 15, x3, 20, x2, 24, 1 },
55         {25, 25,  1, 26,  1,  1,  0,  1,  0,  1, 0 },
56         {26,  1, x5,  6, x4, 11, x3, 16, x2, 21, x1}
57     };
58     matrix m(26,26);
59     for (unsigned r=0; r<26; ++r) {
60         for (unsigned c=0; c<5; ++c) {
61             m.set(r,
62                   unsigned(ex_to_numeric(w[r][2*c+1]).to_int()-1),
63                   w[r][2*c+2]);
64         }
65     }
66     ex det = m.determinant();
67     // The result should have been:
68     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^2*x2^2-36*x1*x5*x3^2*x4-36*x2*x5*x3^2*x4-x3^3*x5^2-x3^3*x4^2-2*x3^3*x5*x4-12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3^3-x2^3*x5^2-x2^3*x4^2-x2^3*x3^2-x1^2*x2^3",lst(x1,x2,x3,x4,x5));
69     if (det!=cmp) {
70         clog << "The determinant was miscalculated" << endl;
71         return 1;
72     }
73     return 0;
74 }
75
76 unsigned time_lw_M1(void)
77 {
78     unsigned result = 0;
79     unsigned count = 0;
80     timer rolex;
81     double time = .0;
82     
83     cout << "timing Lewis-Wester test M1 (26x26 sparse, det)" << flush;
84     clog << "-------Lewis-Wester test M1 (26x26 sparse, det)" << endl;
85     
86     rolex.start();
87     // correct for very small times:
88     do {
89         result = test();
90         ++count;
91     } while ((time=rolex.read())<0.1 && !result);
92     cout << '.' << flush;
93     
94     if (!result) {
95         cout << " passed ";
96         clog << "(no output)" << endl;
97     } else {
98         cout << " failed ";
99     }
100     cout << int(1000*(time/count))*0.001 << 's' << endl;
101     
102     return result;
103 }