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).
15 * GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include <ginac/ginac.h>
37 static unsigned expand_subs1(void)
44 for (unsigned i=0; i<VECSIZE; ++i) {
48 // prepare aux so it will swallow anything but a1^2:
49 aux = -e + a[0] + a[1];
50 e = expand(subs(expand(pow(e, 2)), a[0] == aux));
53 clog << "Denny Fliegner's quick consistency check erroneously returned "
60 static unsigned expand_subs2(void)
62 symbol a("a"), b("b");
65 // Here the final expand() should be superflous. For no particular reason
66 // at all, we don't use the wrapper-functions but the methods instead:
67 e = pow(a+b,200).expand();
71 clog << "e = pow(a+b,200).expand(); f = e.subs(a == -b); erroneously returned "
72 << f << " instead of simplifying to 0." << endl;
78 unsigned expand_subs(void)
82 cout << "checking commutative expansion and substitution..." << flush;
83 clog << "---------commutative expansion and substitution:" << endl;
85 result += expand_subs1();
86 result += expand_subs2();
90 clog << "(no output)" << endl;