- if (level==1)
- return this->hold();
-
- if (level == -max_recursion_level)
- throw(std::runtime_error("max recursion level reached"));
-
- return (new relational(lh.eval(level-1),rh.eval(level-1),o))->setflag(status_flags::dynallocated | status_flags::evaluated);
+ const ex &mapped_lh = f(lh);
+ const ex &mapped_rh = f(rh);
+
+ if (!are_ex_trivially_equal(lh, mapped_lh)
+ || !are_ex_trivially_equal(rh, mapped_rh))
+ return dynallocate<relational>(mapped_lh, mapped_rh, o);
+ else
+ return *this;
+}
+
+ex relational::subs(const exmap & m, unsigned options) const
+{
+ const ex & subsed_lh = lh.subs(m, options);
+ const ex & subsed_rh = rh.subs(m, options);
+
+ if (!are_ex_trivially_equal(lh, subsed_lh) || !are_ex_trivially_equal(rh, subsed_rh))
+ return relational(subsed_lh, subsed_rh, o).subs_one_level(m, options);
+ else
+ return subs_one_level(m, options);