+static unsigned matrix_rank()
+{
+ unsigned result = 0;
+ symbol x("x"), y("y");
+ matrix m(3,3);
+
+ // the zero matrix always has rank 0
+ if (m.rank() != 0) {
+ clog << "The rank of " << m << " was not computed correctly." << endl;
+ ++result;
+ }
+
+ // a trivial rank one example
+ m = {{1, 0, 0},
+ {2, 0, 0},
+ {3, 0, 0}};
+ if (m.rank() != 1) {
+ clog << "The rank of " << m << " was not computed correctly." << endl;
+ ++result;
+ }
+
+ // an example from Maple's help with rank two
+ m = {{x, 1, 0},
+ {0, 0, 1},
+ {x*y, y, 1}};
+ if (m.rank() != 2) {
+ clog << "The rank of " << m << " was not computed correctly." << endl;
+ ++result;
+ }
+
+ // the 3x3 unit matrix has rank 3
+ m = ex_to<matrix>(unit_matrix(3,3));
+ if (m.rank() != 3) {
+ clog << "The rank of " << m << " was not computed correctly." << endl;
+ ++result;
+ }
+
+ return result;
+}
+
+unsigned matrix_solve_nonnormal()
+{
+ symbol a("a"), b("b"), c("c"), x("x");
+ // This matrix has a non-normal zero element!
+ matrix mx {{1,0,0},
+ {0,1/(x+1)-(x-1)/(x*x-1),1},
+ {0,0,0}};
+ matrix zero {{0}, {0}, {0}};
+ matrix vars {{a}, {b}, {c}};
+ try {
+ matrix sol_gauss = mx.solve(vars, zero, solve_algo::gauss);
+ matrix sol_divfree = mx.solve(vars, zero, solve_algo::divfree);
+ matrix sol_bareiss = mx.solve(vars, zero, solve_algo::bareiss);
+ if (sol_gauss != sol_divfree || sol_gauss != sol_bareiss) {
+ clog << "different solutions while solving "
+ << mx << " * " << vars << " == " << zero << endl
+ << "gauss: " << sol_gauss << endl
+ << "divfree: " << sol_divfree << endl
+ << "bareiss: " << sol_bareiss << endl;
+ return 1;
+ }
+ } catch (const exception & e) {
+ clog << "exception thrown while solving "
+ << mx << " * " << vars << " == " << zero << endl;
+ return 1;
+ }
+ return 0;
+}
+
+static unsigned matrix_misc()