1 /** @file expand_subs.cpp
3 * The first test routine implements Denny Fliegner's quick consistency check:
4 * e = (a0 + a1 + a2 + a3 + ...)^2
6 * substitute a0 by (-a2 - a3 - ...) in e
8 * after which e should be just a1^2.
9 * In addition, a simpler modification is tested in the second test:
12 * substitute a0 by -a1 in e
13 * after which e should return 0 (without expanding). */
16 * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include <ginac/ginac.h>
36 #ifndef NO_GINAC_NAMESPACE
37 using namespace GiNaC;
38 #endif // ndef NO_GINAC_NAMESPACE
42 static unsigned expand_subs1(void)
49 for (unsigned i=0; i<VECSIZE; ++i) {
53 // prepare aux so it will swallow anything but a1^2:
54 aux = -e + a[0] + a[1];
55 e = expand(subs(expand(pow(e, 2)), a[0] == aux));
58 clog << "Denny Fliegner's quick consistency check erroneously returned "
65 static unsigned expand_subs2(void)
67 symbol a("a"), b("b");
70 // Here the final expand() should be superflous. For no particular reason
71 // at all, we don't use the wrapper-functions but the methods instead:
72 e = pow(a+b,200).expand();
76 clog << "e = pow(a+b,200).expand(); f = e.subs(a == -b); erroneously returned "
77 << f << " instead of simplifying to 0." << endl;
83 unsigned expand_subs(void)
87 cout << "checking commutative expansion and substitution..." << flush;
88 clog << "---------commutative expansion and substitution:" << endl;
90 result += expand_subs1();
91 result += expand_subs2();
95 clog << "(no output)" << endl;