]> www.ginac.de Git - ginac.git/blobdiff - check/check_lsolve.cpp
Rewritten heuristic and PRS GCD for univariate polynomials, added benchmark.
[ginac.git] / check / check_lsolve.cpp
index 59264d9d1cb4cf23b173d438a72db6dca27529d5..226b6c2d3a0d8144d126f0f6f83fb584c43767ec 100644 (file)
@@ -1,10 +1,11 @@
 /** @file check_lsolve.cpp
  *
  *  These test routines do some simple checks on solving linear systems of
- *  symbolic equations. */
+ *  symbolic equations.  They are a well-tried resource for cross-checking
+ *  the underlying symbolic manipulations. */
 
 /*
- *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2008 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
  *
  *  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
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include "checks.h"
+#include <iostream>
+#include <sstream>
+#include <cstdlib> // rand()
+#include "ginac.h"
+using namespace std;
+using namespace GiNaC;
 
-#if defined(HAVE_SSTREAM)
-#  include <sstream>
-#else
-#  include <strstream>
-#endif
+extern const ex 
+dense_univariate_poly(const symbol & x, unsigned degree);
 
 static unsigned check_matrix_solve(unsigned m, unsigned n, unsigned p,
                                                                   unsigned degree)
@@ -55,15 +58,9 @@ static unsigned check_matrix_solve(unsigned m, unsigned n, unsigned p,
        matrix X(n,p);
        for (unsigned i=0; i<n; ++i) {
                for (unsigned j=0; j<p; ++j) {
-#if defined(HAVE_SSTREAM)
                        ostringstream buf;
                        buf << "x" << i << j << ends;
                        x.push_back(symbol(buf.str()));
-#else
-                       char buf[4];
-                       ostrstream(buf,sizeof(buf)) << i << j << ends;
-                       x.push_back(symbol(string("x")+buf));
-#endif
                        X.set(i,j,x[p*i+j]);
                }
        }
@@ -107,23 +104,16 @@ static unsigned check_inifcns_lsolve(unsigned n)
 {
        unsigned result = 0;
        
-       for (int repetition=0; repetition<100; ++repetition) {
+       for (int repetition=0; repetition<200; ++repetition) {
                // create two size n vectors of symbols, one for the coefficients
                // a[0],..,a[n], one for indeterminates x[0]..x[n]:
                vector<symbol> a;
                vector<symbol> x;
                for (unsigned i=0; i<n; ++i) {
-#if defined(HAVE_SSTREAM)
                        ostringstream buf;
                        buf << i << ends;
                        a.push_back(symbol(string("a")+buf.str()));
                        x.push_back(symbol(string("x")+buf.str()));
-#else
-                       char buf[3];
-                       ostrstream(buf,sizeof(buf)) << i << ends;
-                       a.push_back(symbol(string("a")+buf));
-                       x.push_back(symbol(string("x")+buf));
-#endif
                }
                lst eqns;  // equation list
                lst vars;  // variable list
@@ -173,31 +163,30 @@ static unsigned check_inifcns_lsolve(unsigned n)
        return result;
 }
 
-unsigned check_lsolve(void)
+unsigned check_lsolve()
 {
        unsigned result = 0;
        
        cout << "checking linear solve" << flush;
-       clog << "---------linear solve:" << endl;
        
        // solve some numeric linear systems
-       for (unsigned n=1; n<12; ++n)
+       for (unsigned n=1; n<14; ++n)
                result += check_matrix_solve(n, n, 1, 0);
        cout << '.' << flush;
        // solve some underdetermined numeric systems
-       for (unsigned n=1; n<12; ++n)
+       for (unsigned n=1; n<14; ++n)
                result += check_matrix_solve(n+1, n, 1, 0);
        cout << '.' << flush;
        // solve some overdetermined numeric systems
-       for (unsigned n=1; n<12; ++n)
+       for (unsigned n=1; n<14; ++n)
                result += check_matrix_solve(n, n+1, 1, 0);
        cout << '.' << flush;
        // solve some multiple numeric systems
-       for (unsigned n=1; n<12; ++n)
+       for (unsigned n=1; n<14; ++n)
                result += check_matrix_solve(n, n, n/3+1, 0);
        cout << '.' << flush;
        // solve some symbolic linear systems
-       for (unsigned n=1; n<7; ++n)
+       for (unsigned n=1; n<8; ++n)
                result += check_matrix_solve(n, n, 1, 2);
        cout << '.' << flush;
        
@@ -208,12 +197,10 @@ unsigned check_lsolve(void)
        result += check_inifcns_lsolve(5);  cout << '.' << flush;
        result += check_inifcns_lsolve(6);  cout << '.' << flush;
                
-       if (!result) {
-               cout << " passed " << endl;
-               clog << "(no output)" << endl;
-       } else {
-               cout << " failed " << endl;
-       }
-       
        return result;
 }
+
+int main(int argc, char** argv)
+{
+       return check_lsolve();
+}