]> www.ginac.de Git - ginac.git/blobdiff - check/check_matrices.cpp
friend void ginsh_get_ginac_functions(void) is now removed from
[ginac.git] / check / check_matrices.cpp
index ec7efefc523132fae8b701c2864a674d26c3927e..c1fa6257599938bc57c015e363a6822bf876a9c2 100644 (file)
 
 #include "checks.h"
 
-// determinants of some sparse symbolic size x size matrices
-static unsigned matrix_determinants(void)
+/* determinants of some sparse symbolic matrices with coefficients in
+ * an integral domain. */
+static unsigned integdom_matrix_determinants(void)
 {
     unsigned result = 0;
     symbol a("a");
+    
+    for (int size=3; size<20; ++size) {
+        matrix A(size,size);
+        for (int r=0; r<size-1; ++r) {
+            // populate one element in each row:
+            A.set(r,unsigned(rand()%size),dense_univariate_poly(a,5));
+        }
+        for (int c=0; c<size; ++c) {
+            // set the last line to a linear combination of two other lines
+            // to guarantee that the determinant is zero:
+            A.set(size-1,c,A(0,c)-A(size-2,c));
+        }
+        if (!A.determinant().is_zero()) {
+            clog << "Determinant of " << size << "x" << size << " matrix "
+                 << endl << A << endl
+                 << "was not found to vanish!" << endl;
+            ++result;
+        }
+    }
+    
+    return result;
+}
 
-    for (int size=3; size<16; ++size) {
+/* determinants of some sparse symbolic matrices with multivariate rational
+ * function coefficients. */
+static unsigned rational_matrix_determinants(void)
+{
+    unsigned result = 0;
+    symbol a("a"), b("b"), c("c");
+
+    for (int size=3; size<8; ++size) {
         matrix A(size,size);
+        for (int r=0; r<size-1; ++r) {
+            // populate one element in each row:
+            ex numer = sparse_tree(a, b, c, 4, false, false, false);
+            ex denom;
+            do {
+                denom = sparse_tree(a, b, c, 1, false, false, false);
+            } while (denom.is_zero());
+            A.set(r,unsigned(rand()%size),numer/denom);
+        }
+        for (int c=0; c<size; ++c) {
+            // set the last line to a linear combination of two other lines
+            // to guarantee that the determinant is zero:
+            A.set(size-1,c,A(0,c)-A(size-2,c));
+        }
+        if (!A.determinant().is_zero()) {
+            clog << "Determinant of " << size << "x" << size << " matrix "
+                 << endl << A << endl
+                 << "was not found to vanish!" << endl;
+            ++result;
+        }
+    }
+    
+    return result;
+}
+
+/* Some quite wild determinants with functions and stuff like that. */
+static unsigned wild_matrix_determinants(void)
+{
+    unsigned result = 0;
+    symbol a("a"), b("b"), c("c");
+    
+    for (int size=3; size<6; ++size) {
+        matrix A(size,size);
+        for (int r=0; r<size-1; ++r) {
+            // populate one element in each row:
+            ex numer = sparse_tree(a, b, c, 3, true, true, false);
+            ex denom;
+            do {
+                denom = sparse_tree(a, b, c, 1, false, true, false);
+            } while (denom.is_zero());
+            A.set(r,unsigned(rand()%size),numer/denom);
+        }
         for (int c=0; c<size; ++c) {
-            for (int r=0;r<size-1; ++r)
-                // populate 10 percent of the entries, the rest remains 0:
-                if (!(int)(10.0*rand()/(RAND_MAX+1.0)))
-                    A.set(r,c,dense_univariate_poly(a,5));
             // set the last line to a linear combination of two other lines
-            // to guarantee that the determinant vanishes:
+            // to guarantee that the determinant is zero:
             A.set(size-1,c,A(0,c)-A(size-2,c));
         }
         if (!A.determinant().is_zero()) {
@@ -57,7 +125,9 @@ unsigned check_matrices(void)
     cout << "checking symbolic matrix manipulations" << flush;
     clog << "---------symbolic matrix manipulations:" << endl;
     
-    result += matrix_determinants();  cout << '.' << flush;
+    result += integdom_matrix_determinants();  cout << '.' << flush;
+    result += rational_matrix_determinants();  cout << '.' << flush;
+    result += wild_matrix_determinants();  cout << '.' << flush;
     
     if (!result) {
         cout << " passed " << endl;