From c69d2c6f95cd62f1bbf2ff665551b1d1b693466c Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Wed, 28 Feb 2001 15:53:26 +0000 Subject: [PATCH] * some longish timings are now disabled by default. * check/time_lw_M2.cpp: new timing (defaults to disabled) * check/time_lw_N.cpp: new timing (defaults to disabled) --- check/Makefile.am | 6 +- check/check_numeric.cpp | 4 - check/checks.h | 3 - check/exam_noncommut.cpp | 13 +-- check/exams.h | 3 - check/genex.cpp | 3 - check/time_dennyfliegner.cpp | 2 +- check/time_lw_G.cpp | 2 +- check/time_lw_M2.cpp | 184 +++++++++++++++++++++++++++++++++++ check/time_lw_N.cpp | 87 +++++++++++++++++ check/time_lw_O.cpp | 31 +++--- check/time_lw_Q.cpp | 33 ++++--- check/time_lw_Qprime.cpp | 33 ++++--- check/times.cpp | 14 +++ check/times.h | 12 ++- check/times.ref | 4 + 16 files changed, 366 insertions(+), 68 deletions(-) create mode 100644 check/time_lw_M2.cpp create mode 100644 check/time_lw_N.cpp diff --git a/check/Makefile.am b/check/Makefile.am index 301fb269..7932f1c6 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -12,9 +12,9 @@ checks_LDADD = ../ginac/libginac.la times_SOURCES = time_dennyfliegner.cpp time_gammaseries.cpp \ time_vandermonde.cpp time_toeplitz.cpp time_lw_A.cpp time_lw_B.cpp \ time_lw_C.cpp time_lw_D.cpp time_lw_E.cpp time_lw_F.cpp time_lw_G.cpp \ - time_lw_H.cpp time_lw_IJKL.cpp time_lw_M1.cpp time_lw_O.cpp time_lw_P.cpp \ - time_lw_Pprime.cpp time_lw_Q.cpp time_lw_Qprime.cpp \ - timer.cpp times.cpp times.h + time_lw_H.cpp time_lw_IJKL.cpp time_lw_M1.cpp time_lw_M2.cpp time_lw_N.cpp \ + time_lw_O.cpp time_lw_P.cpp time_lw_Pprime.cpp time_lw_Q.cpp \ + time_lw_Qprime.cpp timer.cpp times.cpp times.h times_LDADD = ../ginac/libginac.la INCLUDES = -I$(srcdir)/../ginac -I../ginac CLEANFILES = exams.out checks.out times.out diff --git a/check/check_numeric.cpp b/check/check_numeric.cpp index 85417eb8..46b78d32 100644 --- a/check/check_numeric.cpp +++ b/check/check_numeric.cpp @@ -23,10 +23,6 @@ #include "checks.h" -#ifndef NO_NAMESPACE_GINAC -using namespace GiNaC; -#endif // ndef NO_NAMESPACE_GINAC - /* Simple and maybe somewhat pointless consistency tests of assorted tests and * conversions. */ static unsigned check_numeric1(void) diff --git a/check/checks.h b/check/checks.h index b5a6adf8..2beca6d3 100644 --- a/check/checks.h +++ b/check/checks.h @@ -28,10 +28,7 @@ #include "ginac.h" using namespace std; - -#ifndef NO_NAMESPACE_GINAC using namespace GiNaC; -#endif // ndef NO_NAMESPACE_GINAC // prototypes for the expression generating functions in: const ex dense_univariate_poly(const symbol & x, unsigned degree); diff --git a/check/exam_noncommut.cpp b/check/exam_noncommut.cpp index 03ae6ff9..a6137aa0 100644 --- a/check/exam_noncommut.cpp +++ b/check/exam_noncommut.cpp @@ -22,8 +22,6 @@ #include "exams.h" -#if 0 // this will change - static unsigned lortensor_check1(void) { // checks simple identities of the metric tensor! @@ -47,10 +45,11 @@ static unsigned lortensor_check1(void) << e6 << " instead of 0" << endl; ++result; } - + return result; } +#if 0 // this will change static unsigned lortensor_check2(void) { // checks simple contraction properties of an arbitrary (symmetric!) rankn lortensor! @@ -83,10 +82,9 @@ static unsigned lortensor_check2(void) << e10 << " instead of 0" << endl; ++result; } - + return result; } - #endif unsigned exam_noncommut(void) @@ -95,12 +93,11 @@ unsigned exam_noncommut(void) cout << "examining behaviour of noncommutative objects" << flush; clog << "----------behaviour of noncommutative objects:" << endl; - -#if 0 + result += lortensor_check1(); cout << '.' << flush; +#if 0 result += lortensor_check2(); cout << '.' << flush; #endif - if (!result) { cout << " passed " << endl; clog << "(no output)" << endl; diff --git a/check/exams.h b/check/exams.h index a3d8c196..259b54d2 100644 --- a/check/exams.h +++ b/check/exams.h @@ -25,10 +25,7 @@ #include "ginac.h" using namespace std; - -#ifndef NO_NAMESPACE_GINAC using namespace GiNaC; -#endif // ndef NO_NAMESPACE_GINAC // prototypes for all individual checks should be unsigned fcn(): unsigned exam_paranoia(); diff --git a/check/genex.cpp b/check/genex.cpp index 2a552913..f4bffb15 100644 --- a/check/genex.cpp +++ b/check/genex.cpp @@ -25,10 +25,7 @@ #include #include "ginac.h" - -#ifndef NO_NAMESPACE_GINAC using namespace GiNaC; -#endif // ndef NO_NAMESPACE_GINAC /* Create a dense univariate random polynomial in x. * (of the form 9 - 22*a - 17*a^2 + 14*a^3 + 7*a^4 + 7a^5 if degree==5) */ diff --git a/check/time_dennyfliegner.cpp b/check/time_dennyfliegner.cpp index d81ba919..4f6b7dc3 100644 --- a/check/time_dennyfliegner.cpp +++ b/check/time_dennyfliegner.cpp @@ -38,7 +38,7 @@ static unsigned expand_subs(unsigned size) buf << "a" << i << ends; a.push_back(symbol(buf.str())); #else - char buf[4]; + char buf[5]; // 'a' + 3 decimal digits + '\n' ostrstream(buf,sizeof(buf)) << "a" << i << ends; a.push_back(symbol(buf)); #endif diff --git a/check/time_lw_G.cpp b/check/time_lw_G.cpp index 2eb20380..f7f0273d 100644 --- a/check/time_lw_G.cpp +++ b/check/time_lw_G.cpp @@ -28,7 +28,7 @@ static unsigned test(void) symbol x("x"); symbol y("y"); symbol z("z"); - + ex p = expand(pow(7*y*pow(x*z,2)-3*x*y*z+11*(x+1)*pow(y,2)+5*z+1,4) *pow(3*x-7*y+2*z-3,5)); ex q = expand(pow(7*y*pow(x*z,2)-3*x*y*z+11*(x+1)*pow(y,2)+5*z+1,3) diff --git a/check/time_lw_M2.cpp b/check/time_lw_M2.cpp new file mode 100644 index 00000000..fcd587fc --- /dev/null +++ b/check/time_lw_M2.cpp @@ -0,0 +1,184 @@ +/** @file time_lw_M2.cpp + * + * Test M2 from the paper "Comparison of Polynomial-Oriented CAS" by Robert H. + * Lewis and Michael Wester. */ + +/* + * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "times.h" + +static const bool do_test = false; // set to true in order to run this beast + +static unsigned test(void) +{ + // Determinant of a sparse matrix that comes up in graph theory: + symbol x1("x1"), x2("x2"), x3("x3"), x4("x4"), x5("x5"); + symbol x6("x6"), x7("x7"), x8("x8"), x9("x9"), xA("xA"); + static ex w[101][21] = { + { 1, 1, 1, 12, x9, 22, x8, 32, x7, 42, x6, 52, x5, 62, x4, 72, x3, 82, x2, 92, x1 }, + { 2, 2, 1, 13, x9, 23, x8, 33, x7, 43, x6, 53, x5, 63, x4, 73, x3, 83, x2, 93, x1 }, + { 3, 3, 1, 14, x9, 24, x8, 34, x7, 44, x6, 54, x5, 64, x4, 74, x3, 84, x2, 94, x1 }, + { 4, 4, 1, 15, x9, 25, x8, 35, x7, 45, x6, 55, x5, 65, x4, 75, x3, 85, x2, 95, x1 }, + { 5, 5, 1, 16, x9, 26, x8, 36, x7, 46, x6, 56, x5, 66, x4, 76, x3, 86, x2, 96, x1 }, + { 6, 6, 1, 17, x9, 27, x8, 37, x7, 47, x6, 57, x5, 67, x4, 77, x3, 87, x2, 97, x1 }, + { 7, 7, 1, 18, x9, 28, x8, 38, x7, 48, x6, 58, x5, 68, x4, 78, x3, 88, x2, 98, x1 }, + { 8, 8, 1, 19, x9, 29, x8, 39, x7, 49, x6, 59, x5, 69, x4, 79, x3, 89, x2, 99, x1 }, + { 9, 9, 1, 20, x9, 30, x8, 40, x7, 50, x6, 60, x5, 70, x4, 80, x3, 90, x2, 100, x1 }, + {10, 10, 1, 101, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 }, + {11, 2, xA, 11, 1, 22, x8, 32, x7, 42, x6, 52, x5, 62, x4, 72, x3, 82, x2, 92, x1 }, + {12, 3, xA, 12, 1, 23, x8, 33, x7, 43, x6, 53, x5, 63, x4, 73, x3, 83, x2, 93, x1 }, + {13, 4, xA, 13, 1, 24, x8, 34, x7, 44, x6, 54, x5, 64, x4, 74, x3, 84, x2, 94, x1 }, + {14, 5, xA, 14, 1, 25, x8, 35, x7, 45, x6, 55, x5, 65, x4, 75, x3, 85, x2, 95, x1 }, + {15, 6, xA, 15, 1, 26, x8, 36, x7, 46, x6, 56, x5, 66, x4, 76, x3, 86, x2, 96, x1 }, + {16, 7, xA, 16, 1, 27, x8, 37, x7, 47, x6, 57, x5, 67, x4, 77, x3, 87, x2, 97, x1 }, + {17, 8, xA, 17, 1, 28, x8, 38, x7, 48, x6, 58, x5, 68, x4, 78, x3, 88, x2, 98, x1 }, + {18, 9, xA, 18, 1, 29, x8, 39, x7, 49, x6, 59, x5, 69, x4, 79, x3, 89, x2, 99, x1 }, + {19, 10, xA, 19, 1, 30, x8, 40, x7, 50, x6, 60, x5, 70, x4, 80, x3, 90, x2, 100, x1 }, + {20, 20, 1, 101, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 }, + {21, 2, xA, 12, x9, 21, 1, 32, x7, 42, x6, 52, x5, 62, x4, 72, x3, 82, x2, 92, x1 }, + {22, 3, xA, 13, x9, 22, 1, 33, x7, 43, x6, 53, x5, 63, x4, 73, x3, 83, x2, 93, x1 }, + {23, 4, xA, 14, x9, 23, 1, 34, x7, 44, x6, 54, x5, 64, x4, 74, x3, 84, x2, 94, x1 }, + {24, 5, xA, 15, x9, 24, 1, 35, x7, 45, x6, 55, x5, 65, x4, 75, x3, 85, x2, 95, x1 }, + {25, 6, xA, 16, x9, 25, 1, 36, x7, 46, x6, 56, x5, 66, x4, 76, x3, 86, x2, 96, x1 }, + {26, 7, xA, 17, x9, 26, 1, 37, x7, 47, x6, 57, x5, 67, x4, 77, x3, 87, x2, 97, x1 }, + {27, 8, xA, 18, x9, 27, 1, 38, x7, 48, x6, 58, x5, 68, x4, 78, x3, 88, x2, 98, x1 }, + {28, 9, xA, 19, x9, 28, 1, 39, x7, 49, x6, 59, x5, 69, x4, 79, x3, 89, x2, 99, x1 }, + {29, 10, xA, 20, x9, 29, 1, 40, x7, 50, x6, 60, x5, 70, x4, 80, x3, 90, x2, 100, x1 }, + {30, 30, 1, 101, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 }, + {31, 2, xA, 12, x9, 22, x8, 31, 1, 42, x6, 52, x5, 62, x4, 72, x3, 82, x2, 92, x1 }, + {32, 3, xA, 13, x9, 23, x8, 32, 1, 43, x6, 53, x5, 63, x4, 73, x3, 83, x2, 93, x1 }, + {33, 4, xA, 14, x9, 24, x8, 33, 1, 44, x6, 54, x5, 64, x4, 74, x3, 84, x2, 94, x1 }, + {34, 5, xA, 15, x9, 25, x8, 34, 1, 45, x6, 55, x5, 65, x4, 75, x3, 85, x2, 95, x1 }, + {35, 6, xA, 16, x9, 26, x8, 35, 1, 46, x6, 56, x5, 66, x4, 76, x3, 86, x2, 96, x1 }, + {36, 7, xA, 17, x9, 27, x8, 36, 1, 47, x6, 57, x5, 67, x4, 77, x3, 87, x2, 97, x1 }, + {37, 8, xA, 18, x9, 28, x8, 37, 1, 48, x6, 58, x5, 68, x4, 78, x3, 88, x2, 98, x1 }, + {38, 9, xA, 19, x9, 29, x8, 38, 1, 49, x6, 59, x5, 69, x4, 79, x3, 89, x2, 99, x1 }, + {39, 10, xA, 20, x9, 30, x8, 39, 1, 50, x6, 60, x5, 70, x4, 80, x3, 90, x2, 100, x1 }, + {40, 40, 1, 101, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 }, + {41, 2, xA, 12, x9, 22, x8, 32, x7, 41, 1, 52, x5, 62, x4, 72, x3, 82, x2, 92, x1 }, + {42, 3, xA, 13, x9, 23, x8, 33, x7, 42, 1, 53, x5, 63, x4, 73, x3, 83, x2, 93, x1 }, + {43, 4, xA, 14, x9, 24, x8, 34, x7, 43, 1, 54, x5, 64, x4, 74, x3, 84, x2, 94, x1 }, + {44, 5, xA, 15, x9, 25, x8, 35, x7, 44, 1, 55, x5, 65, x4, 75, x3, 85, x2, 95, x1 }, + {45, 6, xA, 16, x9, 26, x8, 36, x7, 45, 1, 56, x5, 66, x4, 76, x3, 86, x2, 96, x1 }, + {46, 7, xA, 17, x9, 27, x8, 37, x7, 46, 1, 57, x5, 67, x4, 77, x3, 87, x2, 97, x1 }, + {47, 8, xA, 18, x9, 28, x8, 38, x7, 47, 1, 58, x5, 68, x4, 78, x3, 88, x2, 98, x1 }, + {48, 9, xA, 19, x9, 29, x8, 39, x7, 48, 1, 59, x5, 69, x4, 79, x3, 89, x2, 99, x1 }, + {49, 10, xA, 20, x9, 30, x8, 40, x7, 49, 1, 60, x5, 70, x4, 80, x3, 90, x2, 100, x1 }, + {50, 50, 1, 101, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 }, + {51, 2, xA, 12, x9, 22, x8, 32, x7, 42, x6, 51, 1, 62, x4, 72, x3, 82, x2, 92, x1 }, + {52, 3, xA, 13, x9, 23, x8, 33, x7, 43, x6, 52, 1, 63, x4, 73, x3, 83, x2, 93, x1 }, + {53, 4, xA, 14, x9, 24, x8, 34, x7, 44, x6, 53, 1, 64, x4, 74, x3, 84, x2, 94, x1 }, + {54, 5, xA, 15, x9, 25, x8, 35, x7, 45, x6, 54, 1, 65, x4, 75, x3, 85, x2, 95, x1 }, + {55, 6, xA, 16, x9, 26, x8, 36, x7, 46, x6, 55, 1, 66, x4, 76, x3, 86, x2, 96, x1 }, + {56, 7, xA, 17, x9, 27, x8, 37, x7, 47, x6, 56, 1, 67, x4, 77, x3, 87, x2, 97, x1 }, + {57, 8, xA, 18, x9, 28, x8, 38, x7, 48, x6, 57, 1, 68, x4, 78, x3, 88, x2, 98, x1 }, + {58, 9, xA, 19, x9, 29, x8, 39, x7, 49, x6, 58, 1, 69, x4, 79, x3, 89, x2, 99, x1 }, + {59, 10, xA, 20, x9, 30, x8, 40, x7, 50, x6, 59, 1, 70, x4, 80, x3, 90, x2, 100, x1 }, + {60, 60, 1, 101, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 }, + {61, 2, xA, 12, x9, 22, x8, 32, x7, 42, x6, 52, x5, 61, 1, 72, x3, 82, x2, 92, x1 }, + {62, 3, xA, 13, x9, 23, x8, 33, x7, 43, x6, 53, x5, 62, 1, 73, x3, 83, x2, 93, x1 }, + {63, 4, xA, 14, x9, 24, x8, 34, x7, 44, x6, 54, x5, 63, 1, 74, x3, 84, x2, 94, x1 }, + {64, 5, xA, 15, x9, 25, x8, 35, x7, 45, x6, 55, x5, 64, 1, 75, x3, 85, x2, 95, x1 }, + {65, 6, xA, 16, x9, 26, x8, 36, x7, 46, x6, 56, x5, 65, 1, 76, x3, 86, x2, 96, x1 }, + {66, 7, xA, 17, x9, 27, x8, 37, x7, 47, x6, 57, x5, 66, 1, 77, x3, 87, x2, 97, x1 }, + {67, 8, xA, 18, x9, 28, x8, 38, x7, 48, x6, 58, x5, 67, 1, 78, x3, 88, x2, 98, x1 }, + {68, 9, xA, 19, x9, 29, x8, 39, x7, 49, x6, 59, x5, 68, 1, 79, x3, 89, x2, 99, x1 }, + {69, 10, xA, 20, x9, 30, x8, 40, x7, 50, x6, 60, x5, 69, 1, 80, x3, 90, x2, 100, x1 }, + {70, 70, 1, 101, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 }, + {71, 2, xA, 12, x9, 22, x8, 32, x7, 42, x6, 52, x5, 62, x4, 71, 1, 82, x2, 92, x1 }, + {72, 3, xA, 13, x9, 23, x8, 33, x7, 43, x6, 53, x5, 63, x4, 72, 1, 83, x2, 93, x1 }, + {73, 4, xA, 14, x9, 24, x8, 34, x7, 44, x6, 54, x5, 64, x4, 73, 1, 84, x2, 94, x1 }, + {74, 5, xA, 15, x9, 25, x8, 35, x7, 45, x6, 55, x5, 65, x4, 74, 1, 85, x2, 95, x1 }, + {75, 6, xA, 16, x9, 26, x8, 36, x7, 46, x6, 56, x5, 66, x4, 75, 1, 86, x2, 96, x1 }, + {76, 7, xA, 17, x9, 27, x8, 37, x7, 47, x6, 57, x5, 67, x4, 76, 1, 87, x2, 97, x1 }, + {77, 8, xA, 18, x9, 28, x8, 38, x7, 48, x6, 58, x5, 68, x4, 77, 1, 88, x2, 98, x1 }, + {78, 9, xA, 19, x9, 29, x8, 39, x7, 49, x6, 59, x5, 69, x4, 78, 1, 89, x2, 99, x1 }, + {79, 10, xA, 20, x9, 30, x8, 40, x7, 50, x6, 60, x5, 70, x4, 79, 1, 90, x2, 100, x1 }, + {80, 80, 1, 101, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 }, + {81, 2, xA, 12, x9, 22, x8, 32, x7, 42, x6, 52, x5, 62, x4, 72, x3, 81, 1, 92, x1 }, + {82, 3, xA, 13, x9, 23, x8, 33, x7, 43, x6, 53, x5, 63, x4, 73, x3, 82, 1, 93, x1 }, + {83, 4, xA, 14, x9, 24, x8, 34, x7, 44, x6, 54, x5, 64, x4, 74, x3, 83, 1, 94, x1 }, + {84, 5, xA, 15, x9, 25, x8, 35, x7, 45, x6, 55, x5, 65, x4, 75, x3, 84, 1, 95, x1 }, + {85, 6, xA, 16, x9, 26, x8, 36, x7, 46, x6, 56, x5, 66, x4, 76, x3, 85, 1, 96, x1 }, + {86, 7, xA, 17, x9, 27, x8, 37, x7, 47, x6, 57, x5, 67, x4, 77, x3, 86, 1, 97, x1 }, + {87, 8, xA, 18, x9, 28, x8, 38, x7, 48, x6, 58, x5, 68, x4, 78, x3, 87, 1, 98, x1 }, + {88, 9, xA, 19, x9, 29, x8, 39, x7, 49, x6, 59, x5, 69, x4, 79, x3, 88, 1, 99, x1 }, + {89, 10, xA, 20, x9, 30, x8, 40, x7, 50, x6, 60, x5, 70, x4, 80, x3, 89, 1, 100, x1 }, + {90, 90, 1, 101, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 }, + {91, 2, xA, 12, x9, 22, x8, 32, x7, 42, x6, 52, x5, 62, x4, 72, x3, 82, x2, 91, 1 }, + {92, 3, xA, 13, x9, 23, x8, 33, x7, 43, x6, 53, x5, 63, x4, 73, x3, 83, x2, 92, 1 }, + {93, 4, xA, 14, x9, 24, x8, 34, x7, 44, x6, 54, x5, 64, x4, 74, x3, 84, x2, 93, 1 }, + {94, 5, xA, 15, x9, 25, x8, 35, x7, 45, x6, 55, x5, 65, x4, 75, x3, 85, x2, 94, 1 }, + {95, 6, xA, 16, x9, 26, x8, 36, x7, 46, x6, 56, x5, 66, x4, 76, x3, 86, x2, 95, 1 }, + {96, 7, xA, 17, x9, 27, x8, 37, x7, 47, x6, 57, x5, 67, x4, 77, x3, 87, x2, 96, 1 }, + {97, 8, xA, 18, x9, 28, x8, 38, x7, 48, x6, 58, x5, 68, x4, 78, x3, 88, x2, 97, 1 }, + {98, 9, xA, 19, x9, 29, x8, 39, x7, 49, x6, 59, x5, 69, x4, 79, x3, 89, x2, 98, 1 }, + {99, 10, xA, 20, x9, 30, x8, 40, x7, 50, x6, 60, x5, 70, x4, 80, x3, 90, x2, 99, 1 }, + {100, 100, 1, 101, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 }, + {101, 1, xA, 11, x9, 21, x8, 31, x7, 41, x6, 51, x5, 61, x4, 71, x3, 81, x2, 91, x1} + }; + matrix m(101,101); + for (unsigned r=0; r<101; ++r) { + for (unsigned c=0; c<10; ++c) { + m.set(r, + unsigned(ex_to_numeric(w[r][2*c+1]).to_int()-1), + w[r][2*c+2]); + } + } + ex det = m.determinant(); + if (det.nops()!=85228) { + clog << "The determinant was miscalculated." << endl; + return 1; + } + return 0; +} + +unsigned time_lw_M2(void) +{ + unsigned result = 0; + unsigned count = 0; + timer piaget; + double time = .0; + + cout << "timing Lewis-Wester test M2 (101x101 sparse, det)" << flush; + clog << "-------Lewis-Wester test M2 (101x101 sparse, det)" << endl; + + if (do_test) { + piaget.start(); + // correct for very small times: + do { + result = test(); + ++count; + } while ((time=piaget.read())<0.1 && !result); + cout << '.' << flush; + + if (!result) { + cout << " passed "; + clog << "(no output)" << endl; + } else { + cout << " failed "; + } + cout << int(1000*(time/count))*0.001 << 's' << endl; + } else { + cout << " disabled" << endl; + clog << "(no output)" << endl; + } + + return result; +} diff --git a/check/time_lw_N.cpp b/check/time_lw_N.cpp new file mode 100644 index 00000000..8b7d889c --- /dev/null +++ b/check/time_lw_N.cpp @@ -0,0 +1,87 @@ +/** @file time_lw_N.cpp + * + * Test N from the paper "Comparison of Polynomial-Oriented CAS" by Robert H. + * Lewis and Michael Wester (also known as the smaller version of the first + * Fermat-test). */ + +/* + * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "times.h" + +static const bool do_test = false; // set to true in order to run this beast + +static unsigned test(void) +{ + symbol p11("p11"), p12("p12"), p21("p21"), p22("p22"); + symbol a12("a12"), a21("a21"), a22("a22"); + symbol n11("n11"), n22("n22"); + symbol g("g"); + symbol q1("q1"), q2("q2"), q3("q3"), q4("q4"); + + ex ss1 = ex("(4*g*a22^3-g*a12*a21*a22^2-4*n22*a21*a22^2+4*n11*a21*a22^2+7*g*a12*a22^2+4*g^2*a22^2-4*n11*n22*a22^2+4*n11*a22^2+n22*a12*a21^2*a22-n11*a12*a21^2*a22-4*g*a21^2*a22-g*a12^2*a21*a22-5*g^2*a12*a21*a22+5*n11*n22*a12*a21*a22-7*n22*a12*a21*a22+2*n11*a12*a21*a22-4*g*a21*a22+3*g*a12^2*a22+3*g^2*a12*a22-3*n11*n22*a12*a22+3*n11*a12*a22+g*a12*a21^3+g^2*a12^2*a21^2-n11*n22*a12^2*a21^2+n22*a12^2*a21^2-2*g*a12*a21^2-3*g^2*a12^2*a21+3*n11*n22*a12^2*a21-3*n22*a12^2*a21-3*g*a12*a21)/(3*g*a12*a21*a22^2-3*n22*a21*a22^2+g*a12*a22^2-n22*a22^2+3*n11*a12*a21^2*a22-3*g*a21^2*a22+5*g*a12^2*a21*a22-5*n22*a12*a21*a22+4*n11*a12*a21*a22-4*g*a21*a22+g*a12^2*a22-n22*a12*a22+n11*a12*a22-g*a22+2*n11*a12^2*a21^2-2*g*a12*a21^2+2*g*a12^3*a21-2*n22*a12^2*a21+2*n11*a12^2*a21-2*g*a12*a21)",lst(g,a12,a21,a22,n11,n22)); + + ex ss2 = ex("(4*g*a12*a22^2-4*n22*a22^2+4*a22^2-g*a12^2*a21*a22+n22*a12*a21*a22+4*n11*a12*a21*a22-5*a12*a21*a22-4*g*a21*a22+3*g*a12^2*a22-3*n22*a12*a22+3*a12*a22-n11*a12^2*a21^2+a12^2*a21^2+g*a12*a21^2+3*n11*a12^2*a21-3*a12^2*a21-3*g*a12*a21)/(2*g*a12*a22^2-2*n22*a22^2+g*a12^2*a21*a22-n22*a12*a21*a22+2*n11*a12*a21*a22-2*g*a21*a22+2*g*a12^2*a22-2*n22*a12*a22+2*n11*a12*a22-2*g*a22+n11*a12^2*a21^2-g*a12*a21^2+g*a12^3*a21-n22*a12^2*a21+n11*a12^2*a21-g*a12*a21)",lst(g,a12,a21,a22,n11,n22)); + + ex ss3 = ex("(4*p21*a22^3-p21*a12*a21*a22^2-4*p22*a21*a22^2+4*p11*a21*a22^2+7*p21*a12*a22^2-4*p11*p22*a22^2+4*p12*p21*a22^2+4*p11*a22^2+p22*a12*a21^2*a22-p11*a12*a21^2*a22-4*p12*a21^2*a22-p21*a12^2*a21*a22+5*p11*p22*a12*a21*a22-7*p22*a12*a21*a22-5*p12*p21*a12*a21*a22+2*p11*a12*a21*a22-4*p12*a21*a22+3*p21*a12^2*a22-3*p11*p22*a12*a22+3*p12*p21*a12*a22+3*p11*a12*a22+p12*a12*a21^3-p11*p22*a12^2*a21^2+p22*a12^2*a21^2+p12*p21*a12^2*a21^2-2*p12*a12*a21^2+3*p11*p22*a12^2*a21-3*p22*a12^2*a21-3*p12*p21*a12^2*a21-3*p12*a12*a21)/(3*p21*a12*a21*a22^2-3*p22*a21*a22^2+p21*a12*a22^2-p22*a22^2+3*p11*a12*a21^2*a22-3*p12*a21^2*a22+5*p21*a12^2*a21*a22-5*p22*a12*a21*a22+4*p11*a12*a21*a22-4*p12*a21*a22+p21*a12^2*a22-p22*a12*a22+p11*a12*a22-p12*a22+2*p11*a12^2*a21^2-2*p12*a12*a21^2+2*p21*a12^3*a21-2*p22*a12^2*a21+2*p11*a12^2*a21-2*p12*a12*a21)",lst(a12,a21,a22,p11,p12,p21,p22)); + + ex ss4 = ex("(4*p21*a12*a22^2-4*p22*a22^2+4*a22^2-p21*a12^2*a21*a22+p22*a12*a21*a22+4*p11*a12*a21*a22-5*a12*a21*a22-4*p12*a21*a22+3*p21*a12^2*a22-3*p22*a12*a22+3*a12*a22-p11*a12^2*a21^2+a12^2*a21^2+p12*a12*a21^2+3*p11*a12^2*a21-3*a12^2*a21-3*p12*a12*a21)/(2*p21*a12*a22^2-2*p22*a22^2+p21*a12^2*a21*a22-p22*a12*a21*a22+2*p11*a12*a21*a22-2*p12*a21*a22+2*p21*a12^2*a22-2*p22*a12*a22+2*p11*a12*a22-2*p12*a22+p11*a12^2*a21^2-p12*a12*a21^2+p21*a12^3*a21-p22*a12^2*a21+p11*a12^2*a21-p12*a12*a21)",lst(p11,p12,p21,p22,a12,a21,a22)); + + ex res1 = ex("p11*p22*q1^2*q4^2-p12*p21*q1^2*q4^2-n22*p11*p22*q1*q4^2+2*n11*p11*p22*q1*q4^2-p11*p22*q1*q4^2+n22*p12*p21*q1*q4^2-2*n11*p12*p21*q1*q4^2+p12*p21*q1*q4^2+2*g^2*p11*p22*q4^2-2*n11*n22*p11*p22*q4^2+2*n22*p11*p22*q4^2+2*n11*p11*p22*q4^2-2*p11*p22*q4^2-2*g^2*p12*p21*q4^2+2*n11*n22*p12*p21*q4^2-2*n22*p12*p21*q4^2-2*n11*p12*p21*q4^2+2*p12*p21*q4^2-n11*p22*q1*q2*q3*q4+g*p21*q1*q2*q3*q4+g*p12*q1*q2*q3*q4-n22*p11*q1*q2*q3*q4-g^2*p22*q2*q3*q4+n11*n22*p22*q2*q3*q4-n11*p22*q2*q3*q4-2*g*p21*q2*q3*q4+g*p12*q2*q3*q4+2*g^2*p11*q2*q3*q4-2*n11*n22*p11*q2*q3*q4+2*n22*p11*q2*q3*q4-n11*p22*q1*q3*q4+p22*q1*q3*q4+g*p21*q1*q3*q4-2*g*p12*q1*q3*q4+2*n22*p11*q1*q3*q4-2*p11*q1*q3*q4-g^2*p22*q3*q4+n11*n22*p22*q3*q4-n22*p22*q3*q4-n11*p22*q3*q4+p22*q3*q4-4*g^2*p11*q3*q4+4*n11*n22*p11*q3*q4-4*n22*p11*q3*q4-4*n11*p11*q3*q4+4*p11*q3*q4+n22*p11*p22*q1*q2*q4-2*n11*p11*p22*q1*q2*q4+2*n11*p22*q1*q2*q4-n22*p12*p21*q1*q2*q4+2*n11*p12*p21*q1*q2*q4+g*p21*q1*q2*q4-2*g*p12*q1*q2*q4-n22*p11*q1*q2*q4-4*g^2*p11*p22*q2*q4+4*n11*n22*p11*p22*q2*q4-2*n22*p11*p22*q2*q4-2*n11*p11*p22*q2*q4+2*g^2*p22*q2*q4-2*n11*n22*p22*q2*q4+2*n11*p22*q2*q4+4*g^2*p12*p21*q2*q4-4*n11*n22*p12*p21*q2*q4+2*n22*p12*p21*q2*q4+2*n11*p12*p21*q2*q4-2*g*p21*q2*q4-2*g*p12*q2*q4+2*g^2*p11*q2*q4-2*n11*n22*p11*q2*q4+2*n22*p11*q2*q4-p11*p22*q1^2*q4-p22*q1^2*q4+p12*p21*q1^2*q4+2*p11*q1^2*q4-n22*p11*p22*q1*q4-4*n11*p11*p22*q1*q4+5*p11*p22*q1*q4+n22*p22*q1*q4-p22*q1*q4+n22*p12*p21*q1*q4+4*n11*p12*p21*q1*q4-5*p12*p21*q1*q4+g*p21*q1*q4+4*g*p12*q1*q4+4*n11*p11*q1*q4-4*p11*q1*q4-g^2*q2^2*q3^2+n11*n22*q2^2*q3^2+g^2*q2*q3^2-n11*n22*q2*q3^2-n22*q2*q3^2+2*n11*q2*q3^2+2*g^2*q3^2-2*n11*n22*q3^2+2*n22*q3^2+2*n11*q3^2-2*q3^2+g^2*p22*q2^2*q3-n11*n22*p22*q2^2*q3-2*g^2*p11*q2^2*q3+2*n11*n22*p11*q2^2*q3+g^2*q2^2*q3-n11*n22*q2^2*q3+2*n11*p22*q1*q2*q3-2*g*p21*q1*q2*q3+g*p12*q1*q2*q3-n22*p11*q1*q2*q3+n22*q1*q2*q3-2*n11*q1*q2*q3+g^2*p22*q2*q3-n11*n22*p22*q2*q3+n22*p22*q2*q3+4*g*p21*q2*q3+g*p12*q2*q3+4*g^2*p11*q2*q3-4*n11*n22*p11*q2*q3+4*n11*p11*q2*q3-5*g^2*q2*q3+5*n11*n22*q2*q3-n22*q2*q3-4*n11*q2*q3+2*n11*p22*q1*q3-2*p22*q1*q3-2*g*p21*q1*q3-2*g*p12*q1*q3+2*n22*p11*q1*q3-2*p11*q1*q3-2*n22*q1*q3-2*n11*q1*q3+4*q1*q3+2*g^2*p11*p22*q2^2-2*n11*n22*p11*p22*q2^2-2*g^2*p22*q2^2+2*n11*n22*p22*q2^2-2*g^2*p12*p21*q2^2+2*n11*n22*p12*p21*q2^2-2*g^2*p11*q2^2+2*n11*n22*p11*q2^2+2*g^2*q2^2-2*n11*n22*q2^2+n22*p11*p22*q1*q2+4*n11*p11*p22*q1*q2-n22*p22*q1*q2-4*n11*p22*q1*q2-n22*p12*p21*q1*q2-4*n11*p12*p21*q1*q2-n22*p11*q1*q2-4*n11*p11*q1*q2+n22*q1*q2+4*n11*q1*q2-2*p11*p22*q1^2+2*p22*q1^2+2*p12*p21*q1^2+2*p11*q1^2-2*q1^2",lst(p11,p12,p21,p22,n11,n22,g,q1,q2,q3,q4)); + ex result = res1.subs(lst(q1==ss1, q2==ss2, q3==ss3, q4==ss4)); + ex normalresult = normal(result); + if (!normalresult.is_zero()) { + clog << "Normalization should have returned 0." << endl; + return 1; + } + return 0; +} + +unsigned time_lw_N(void) +{ + unsigned result = 0; + unsigned count = 0; + timer tag_heuer; + double time = .0; + + cout << "timing Lewis-Wester test N (poly at rational fcns)" << flush; + clog << "-------Lewis-Wester test N (poly at rational fcns)" << endl; + + if (do_test) { + tag_heuer.start(); + // correct for very small times: + do { + result = test(); + ++count; + } while ((time=tag_heuer.read())<0.1 && !result); + cout << '.' << flush; + + if (!result) { + cout << " passed "; + clog << "(no output)" << endl; + } else { + cout << " failed "; + } + cout << int(1000*(time/count))*0.001 << 's' << endl; + } else { + cout << " disabled" << endl; + clog << "(no output)" << endl; + } + + return result; +} diff --git a/check/time_lw_O.cpp b/check/time_lw_O.cpp index d3677104..fd2667cc 100644 --- a/check/time_lw_O.cpp +++ b/check/time_lw_O.cpp @@ -23,6 +23,8 @@ #include "times.h" +static const bool do_test = false; // set to true in order to run this beast + static unsigned test1(void) { symbol a1("a1"), a2("a2"), a3("a3"), a4("a4"), a5("a5"), a6("a6"); @@ -108,20 +110,25 @@ unsigned time_lw_O(void) cout << "timing Lewis-Wester test O1 (three 15x15 dets)" << flush; clog << "-------Lewis-Wester test O1 (three 15x15 dets)" << endl; - rolex.start(); - // correct for very small times: - do { - result = test1(); - ++count; - } while ((time=rolex.read())<0.1 && !result); - - if (!result) { - cout << " passed "; - clog << "(no output)" << endl; + if (do_test) { + rolex.start(); + // correct for very small times: + do { + result = test1(); + ++count; + } while ((time=rolex.read())<0.1 && !result); + + if (!result) { + cout << " passed "; + clog << "(no output)" << endl; + } else { + cout << " failed "; + } + cout << int(1000*(time/(3*count)))*0.001 << "s (average)" << endl; } else { - cout << " failed "; + cout << " disabled" << endl; + clog << "(no output)" << endl; } - cout << int(1000*(time/(3*count)))*0.001 << "s (average)" << endl; return result; } diff --git a/check/time_lw_Q.cpp b/check/time_lw_Q.cpp index 01ce6ecd..cc63946a 100644 --- a/check/time_lw_Q.cpp +++ b/check/time_lw_Q.cpp @@ -23,6 +23,8 @@ #include "times.h" +static const bool do_test = false; // set to true in order to run this beast + static unsigned test(void) { // same matrix as in test P: @@ -62,21 +64,26 @@ unsigned time_lw_Q(void) cout << "timing Lewis-Wester test Q (charpoly(P))" << flush; clog << "-------Lewis-Wester test Q (charpoly(P))" << endl; - rolex.start(); - // correct for very small times: - do { - result = test(); - ++count; - } while ((time=rolex.read())<0.1 && !result); - cout << '.' << flush; - - if (!result) { - cout << " passed "; - clog << "(no output)" << endl; + if (do_test) { + rolex.start(); + // correct for very small times: + do { + result = test(); + ++count; + } while ((time=rolex.read())<0.1 && !result); + cout << '.' << flush; + + if (!result) { + cout << " passed "; + clog << "(no output)" << endl; + } else { + cout << " failed "; + } + cout << int(1000*(time/count))*0.001 << 's' << endl; } else { - cout << " failed "; + cout << " disabled" << endl; + clog << "(no output)" << endl; } - cout << int(1000*(time/count))*0.001 << 's' << endl; return result; } diff --git a/check/time_lw_Qprime.cpp b/check/time_lw_Qprime.cpp index 6bbf6d11..c1306adc 100644 --- a/check/time_lw_Qprime.cpp +++ b/check/time_lw_Qprime.cpp @@ -23,6 +23,8 @@ #include "times.h" +static const bool do_test = false; // set to true in order to run this beast + static unsigned test(void) { // same matrix as in test P': @@ -74,21 +76,26 @@ unsigned time_lw_Qprime(void) cout << "timing Lewis-Wester test Q' (charpoly(P'))" << flush; clog << "-------Lewis-Wester test Q' (charpoly(P'))" << endl; - rolex.start(); - // correct for very small times: - do { - result = test(); - ++count; - } while ((time=rolex.read())<0.1 && !result); - cout << '.' << flush; - - if (!result) { - cout << " passed "; - clog << "(no output)" << endl; + if (do_test) { + rolex.start(); + // correct for very small times: + do { + result = test(); + ++count; + } while ((time=rolex.read())<0.1 && !result); + cout << '.' << flush; + + if (!result) { + cout << " passed "; + clog << "(no output)" << endl; + } else { + cout << " failed "; + } + cout << int(1000*(time/count))*0.001 << 's' << endl; } else { - cout << " failed "; + cout << " disabled" << endl; + clog << "(no output)" << endl; } - cout << int(1000*(time/count))*0.001 << 's' << endl; return result; } diff --git a/check/times.cpp b/check/times.cpp index 8f4200b7..1e7475c7 100644 --- a/check/times.cpp +++ b/check/times.cpp @@ -127,6 +127,20 @@ int main() ++result; } + try { + result += time_lw_M2(); + } catch (const exception &e) { + cout << "Error: caught exception " << e.what() << endl; + ++result; + } + + try { + result += time_lw_N(); + } catch (const exception &e) { + cout << "Error: caught exception " << e.what() << endl; + ++result; + } + try { result += time_lw_O(); } catch (const exception &e) { diff --git a/check/times.h b/check/times.h index 7dfe217d..28ce4a75 100644 --- a/check/times.h +++ b/check/times.h @@ -25,15 +25,17 @@ #include #include -#include +#include "config.h" +#if defined(HAVE_SSTREAM) +# include +#else +# include +#endif #include using namespace std; #include "ginac.h" - -#ifndef NO_NAMESPACE_GINAC using namespace GiNaC; -#endif // ndef NO_NAMESPACE_GINAC class timer { public: @@ -63,6 +65,8 @@ unsigned time_lw_G(); unsigned time_lw_H(); unsigned time_lw_IJKL(); unsigned time_lw_M1(); +unsigned time_lw_M2(); +unsigned time_lw_N(); unsigned time_lw_O(); unsigned time_lw_P(); unsigned time_lw_Pprime(); diff --git a/check/times.ref b/check/times.ref index 1e77419b..d5196fb2 100644 --- a/check/times.ref +++ b/check/times.ref @@ -32,6 +32,10 @@ (no output) -------Lewis-Wester test M1 (26x26 sparse, det) (no output) +-------Lewis-Wester test M2 (101x101 sparse, det) +(no output) +-------Lewis-Wester test N (poly at rational fcns) +(no output) -------Lewis-Wester test O1 (three 15x15 dets) (no output) -------Lewis-Wester test P (det of sparse rank 101) -- 2.44.0