1 /** @file time_toeplitz.cpp
3 * Calculates determinants of dense symbolic Toeplitz materices.
4 * For 4x4 our matrix would look like this:
5 * [[a,b,a+b,a^2+a*b+b^2], [b,a,b,a+b], [a+b,b,a,b], [a^2+a*b+b^2,a+b,b,a]]
9 * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 static unsigned toeplitz_det(unsigned size)
31 symbol a("a"), b("b");
35 pow(a,2) + a*b + pow(b,2),
36 pow(a,3) + pow(a,2)*b - a*pow(b,2) + pow(b,3),
37 pow(a,4) + pow(a,3)*b + pow(a*b,2) + a*pow(b,3) + pow(b,4),
38 pow(a,5) + pow(a,4)*b + pow(a,3)*pow(b,2) - pow(a,2)*pow(b,3) + a*pow(b,4) + pow(b,5),
39 pow(a,6) + pow(a,5)*b + pow(a,4)*pow(b,2) + pow(a*b,3) + pow(a,2)*pow(b,4) + a*pow(b,5) + pow(b,6)
42 // construct Toeplitz matrix:
44 for (unsigned ro=0; ro<size; ++ro) {
45 for (unsigned nd=ro; nd<size; ++nd) {
46 M.set(nd-ro,nd,p[ro]);
47 M.set(nd,nd-ro,p[ro]);
51 // compute determinant:
52 ex tdet = M.determinant();
54 // dirty consistency check of result:
55 if (!tdet.subs(a==0).subs(b==0).is_zero()) {
56 clog << "Determaint of Toeplitz matrix " << endl
58 << "was miscalculated: det(M)==" << tdet << endl;
65 unsigned time_toeplitz(void)
69 cout << "timing determinant of polyvariate symbolic Toeplitz matrices" << flush;
70 clog << "-------determinant of polyvariate symbolic Toeplitz matrices:" << endl;
72 vector<unsigned> sizes;
81 for (vector<unsigned>::iterator i=sizes.begin(); i!=sizes.end(); ++i) {
84 result += toeplitz_det(*i);
85 // correct for very small times:
86 while (longines.read()<0.1) {
90 times.push_back(longines.read()/count);
96 clog << "(no output)" << endl;
101 cout << endl << " dim: ";
102 for (vector<unsigned>::iterator i=sizes.begin(); i!=sizes.end(); ++i)
103 cout << '\t' << *i << 'x' << *i;
104 cout << endl << " time/s:";
105 for (vector<double>::iterator i=times.begin(); i!=times.end(); ++i)
106 cout << '\t' << int(1000*(*i))*0.001;