1 /** @file time_dennyfliegner.cpp
3 * The first test routine implements Denny Fliegner's quick consistency check:
4 * 1) e = (a0 + a1 + a2 + a3 + ...)^2, in expanded form
5 * 2) substitute a0 by (-a2 - a3 - ...) in e
7 * after which e should be just a1^2. */
10 * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 static unsigned expand_subs(unsigned size)
32 // create a vector of size symbols named "a0", "a1", ...
35 for (unsigned i=0; i<size; ++i) {
36 #if defined(HAVE_SSTREAM)
38 buf << "a" << i << ends;
39 a.push_back(symbol(buf.str()));
41 char buf[5]; // 'a' + 3 decimal digits + '\n'
42 ostrstream(buf,sizeof(buf)) << "a" << i << ends;
43 a.push_back(symbol(buf));
49 // prepare aux so it will swallow anything but a1^2:
50 aux = -e + a[0] + a[1];
51 e = pow(e,2).expand().subs(a[0]==aux).expand();
53 if (e != pow(a[1],2)) {
54 clog << "Denny Fliegner's quick consistency check erroneously returned "
62 unsigned time_dennyfliegner(void)
66 cout << "timing commutative expansion and substitution" << flush;
67 clog << "-------commutative expansion and substitution:" << endl;
69 vector<unsigned> sizes;
78 for (vector<unsigned>::iterator i=sizes.begin(); i!=sizes.end(); ++i) {
80 result += expand_subs(*i);
81 times.push_back(breitling.read());
87 clog << "(no output)" << endl;
92 cout << endl << " size: ";
93 for (vector<unsigned>::iterator i=sizes.begin(); i!=sizes.end(); ++i)
95 cout << endl << " time/s:";
96 for (vector<double>::iterator i=times.begin(); i!=times.end(); ++i)
97 cout << '\t' << int(1000*(*i))*0.001;