+/** This structure stores the original and symmetrized versions of terms
+ * obtained during the simplification of sums. */
+class symminfo {
+public:
+ symminfo() {}
+ ~symminfo() {}
+
+ symminfo(const ex & symmterm_, const ex & orig_)
+ {
+ if (is_a<mul>(orig_)) {
+ ex tmp = orig_.op(orig_.nops()-1);
+ orig = orig_ / tmp;
+ } else
+ orig = orig_;
+
+ if (is_a<mul>(symmterm_)) {
+ coeff = symmterm_.op(symmterm_.nops()-1);
+ symmterm = symmterm_ / coeff;
+ } else {
+ coeff = 1;
+ symmterm = symmterm_;
+ }
+ }
+
+ symminfo(const symminfo & other)
+ {
+ symmterm = other.symmterm;
+ coeff = other.coeff;
+ orig = other.orig;
+ }
+
+ const symminfo & operator=(const symminfo & other)
+ {
+ if (this != &other) {
+ symmterm = other.symmterm;
+ coeff = other.coeff;
+ orig = other.orig;
+ }
+ return *this;
+ }
+
+ ex symmterm;
+ ex coeff;
+ ex orig;
+};
+
+class symminfo_is_less {
+public:
+ bool operator() (const symminfo & si1, const symminfo & si2)
+ {
+ int comp = si1.symmterm.compare(si2.symmterm);
+ if (comp < 0) return true;
+ if (comp > 0) return false;
+ comp = si1.orig.compare(si2.orig);
+ if (comp < 0) return true;
+ if (comp > 0) return false;
+ comp = si1.coeff.compare(si2.coeff);
+ if (comp < 0) return true;
+ return false;
+ }
+};
+