+/** Substitute objects in an expression (syntactic substitution) and return
+ * the result as a new expression. There are two valid types of
+ * replacement arguments: 1) a relational like object==ex and 2) a list of
+ * relationals lst(object1==ex1,object2==ex2,...), which is converted to
+ * subs(lst(object1,object2,...),lst(ex1,ex2,...)). */
+ex basic::subs(const ex & e, bool no_pattern) const
+{
+ if (e.info(info_flags::relation_equal)) {
+ return subs(lst(e), no_pattern);
+ }
+ if (!e.info(info_flags::list)) {
+ throw(std::invalid_argument("basic::subs(ex): argument must be a list"));
+ }
+ lst ls;
+ lst lr;
+ for (unsigned i=0; i<e.nops(); i++) {
+ ex r = e.op(i);
+ if (!r.info(info_flags::relation_equal)) {
+ throw(std::invalid_argument("basic::subs(ex): argument must be a list of equations"));
+ }
+ ls.append(r.op(0));
+ lr.append(r.op(1));
+ }
+ return subs(ls, lr, no_pattern);
+}
+
+/** Compare objects to establish canonical ordering.
+ * All compare functions return: -1 for *this less than other, 0 equal,
+ * 1 greater. */
+int basic::compare(const basic & other) const
+{
+ unsigned hash_this = gethash();
+ unsigned hash_other = other.gethash();
+
+ if (hash_this<hash_other) return -1;
+ if (hash_this>hash_other) return 1;
+
+ unsigned typeid_this = tinfo();
+ unsigned typeid_other = other.tinfo();
+
+ if (typeid_this<typeid_other) {
+// std::cout << "hash collision, different types: "
+// << *this << " and " << other << std::endl;
+// this->print(print_tree(std::cout));
+// std::cout << " and ";
+// other.print(print_tree(std::cout));
+// std::cout << std::endl;
+ return -1;
+ }
+ if (typeid_this>typeid_other) {
+// std::cout << "hash collision, different types: "
+// << *this << " and " << other << std::endl;
+// this->print(print_tree(std::cout));
+// std::cout << " and ";
+// other.print(print_tree(std::cout));
+// std::cout << std::endl;
+ return 1;
+ }
+
+ GINAC_ASSERT(typeid(*this)==typeid(other));
+
+// int cmpval = compare_same_type(other);
+// if ((cmpval!=0) && (hash_this<0x80000000U)) {
+// std::cout << "hash collision, same type: "
+// << *this << " and " << other << std::endl;
+// this->print(print_tree(std::cout));
+// std::cout << " and ";
+// other.print(print_tree(std::cout));
+// std::cout << std::endl;
+// }
+// return cmpval;
+
+ return compare_same_type(other);
+}
+
+/** Test for equality.
+ * This is only a quick test, meaning objects should be in the same domain.
+ * You might have to .expand(), .normal() objects first, depending on the
+ * domain of your computation, to get a more reliable answer.
+ *
+ * @see is_equal_same_type */
+bool basic::is_equal(const basic & other) const
+{
+ if (this->gethash()!=other.gethash())
+ return false;
+ if (this->tinfo()!=other.tinfo())
+ return false;
+
+ GINAC_ASSERT(typeid(*this)==typeid(other));
+
+ return is_equal_same_type(other);