1 // check/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 #include <ginac/ginac.h>
19 static unsigned expand_subs1(void)
26 for (unsigned i=0; i<VECSIZE; ++i) {
30 // prepare aux so it will swallow anything but a1^2:
31 aux = -e + a[0] + a[1];
32 e = expand(subs(expand(pow(e, 2)), a[0] == aux));
35 clog << "Denny Fliegner's quick consistency check erroneously returned "
42 static unsigned expand_subs2(void)
44 symbol a("a"), b("b");
47 // Here the final expand() should be superflous. For no particular reason
48 // at all, we don't use the wrapper-functions but the methods instead:
49 e = pow(a+b,200).expand();
53 clog << "e = pow(a+b,200).expand(); f = e.subs(a == -b); erroneously returned "
54 << f << " instead of simplifying to 0." << endl;
60 unsigned expand_subs(void)
64 cout << "checking commutative expansion and substitution..." << flush;
65 clog << "---------commutative expansion and substitution:" << endl;
67 result += expand_subs1();
68 result += expand_subs2();
72 clog << "(no output)" << endl;