1 /** @file check_matrices.cpp
3 * Here we test manipulations on GiNaC's symbolic matrices. */
6 * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 // determinants of some sparse symbolic size x size matrices over
26 // an integral domain.
27 static unsigned integdom_matrix_determinants(void)
32 for (int size=3; size<17; ++size) {
34 for (int r=0; r<size-1; ++r) {
35 // populate one element in each row:
36 A.set(r,unsigned(rand()%size),dense_univariate_poly(a,5));
38 for (int c=0; c<size; ++c) {
39 // set the last line to a linear combination of two other lines
40 // to guarantee that the determinant vanishes:
41 A.set(size-1,c,A(0,c)-A(size-2,c));
43 if (!A.determinant().is_zero()) {
44 clog << "Determinant of " << size << "x" << size << " matrix "
46 << "was not found to vanish!" << endl;
54 static unsigned rational_matrix_determinants(void)
57 symbol a("a"), b("b"), c("c");
59 for (int size=3; size<13; ++size) {
61 for (int r=0; r<size-1; ++r) {
62 // populate one element in each row:
63 // FIXME: the line using sparse_tree() should be used:
64 // A.set(r,unsigned(rand()%size),sparse_tree(a, b, c, 3, true, true)/sparse_tree(a, b, c, 2, true, true));
65 A.set(r,unsigned(rand()%size),dense_univariate_poly(a,4)/dense_univariate_poly(a,2));
67 for (int c=0; c<size; ++c) {
68 // set the last line to a linear combination of two other lines
69 // to guarantee that the determinant vanishes:
70 A.set(size-1,c,A(0,c)-A(size-2,c));
72 if (!A.determinant().is_zero()) {
73 clog << "Determinant of " << size << "x" << size << " matrix "
75 << "was not found to vanish!" << endl;
83 unsigned check_matrices(void)
87 cout << "checking symbolic matrix manipulations" << flush;
88 clog << "---------symbolic matrix manipulations:" << endl;
90 result += integdom_matrix_determinants(); cout << '.' << flush;
91 result += rational_matrix_determinants(); cout << '.' << flush;
94 cout << " passed " << endl;
95 clog << "(no output)" << endl;
97 cout << " failed " << endl;