#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<17; ++size) {
+
+ 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:
}
for (int c=0; c<size; ++c) {
// 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()) {
+ clog << "Determinant of " << size << "x" << size << " matrix "
+ << endl << A << endl
+ << "was not found to vanish!" << endl;
+ ++result;
+ }
+ }
+
+ return result;
+}
+
+/* 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) {
+ // 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()) {
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;