-/** @file expand_subs.cpp
+/** @file exam_misc.cpp
*
- * The first test routine implements Denny Fliegner's quick consistency check:
- * e = (a0 + a1 + a2 + a3 + ...)^2
- * expand e
- * substitute a0 by (-a2 - a3 - ...) in e
- * expand e
- * after which e should be just a1^2.
- * In addition, a simpler modification is tested in the second test:
- * e = (a0 + a1)^200
- * expand e
- * substitute a0 by -a1 in e
- * after which e should return 0 (without expanding). */
-
+ */
/*
* GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
*
*/
-#include "ginac.h"
+#include "exams.h"
-#ifndef NO_NAMESPACE_GINAC
-using namespace GiNaC;
-#endif // ndef NO_NAMESPACE_GINAC
-
-#define VECSIZE 100
-
-static unsigned expand_subs1(void)
+#define VECSIZE 30
+static unsigned exam_expand_subs(void)
{
+ unsigned result = 0;
symbol a1("a1");
symbol a[VECSIZE];
ex e, aux;
-
+
a[1] = a1;
for (unsigned i=0; i<VECSIZE; ++i) {
e = e + a[i];
}
-
+
// prepare aux so it will swallow anything but a1^2:
aux = -e + a[0] + a[1];
e = expand(subs(expand(pow(e, 2)), a[0] == aux));
-
+
if (e != pow(a1,2)) {
clog << "Denny Fliegner's quick consistency check erroneously returned "
<< e << "." << endl;
- return 1;
+ ++result;
}
- return 0;
+
+ return result;
}
-static unsigned expand_subs2(void)
+/* A simple modification of Denny Fliegner's three step consistency test:
+ * 1) e = (a0 + a1)^200
+ * 2) expand e
+ * 3) substitute a0 by -a1 in e
+ * after which e should return 0 (without expanding). */
+static unsigned exam_expand_subs2(void)
{
+ unsigned result = 0;
symbol a("a"), b("b");
ex e, f;
-
- // Here the final expand() should be superflous. For no particular reason
- // at all, we don't use the wrapper-functions but the methods instead:
+
e = pow(a+b,200).expand();
f = e.subs(a == -b);
if (f != 0) {
clog << "e = pow(a+b,200).expand(); f = e.subs(a == -b); erroneously returned "
<< f << " instead of simplifying to 0." << endl;
- return 1;
+ ++result;
}
- return 0;
+
+ return result;
}
-unsigned expand_subs(void)
+unsigned exam_misc(void)
{
unsigned result = 0;
-
- cout << "checking commutative expansion and substitution..." << flush;
- clog << "---------commutative expansion and substitution:" << endl;
- result += expand_subs1();
- result += expand_subs2();
+ cout << "examining miscellaneous other things" << flush;
+ clog << "----------miscellaneous other things:" << endl;
+
+ result += exam_expand_subs(); cout << '.' << flush;
+ result += exam_expand_subs2(); cout << '.' << flush;
if (!result) {
- cout << " passed ";
+ cout << " passed " << endl;
clog << "(no output)" << endl;
} else {
- cout << " failed ";
+ cout << " failed " << endl;
}
-
+
return result;
}