+ if (nops() == 0)
+ return *this;
+ else {
+ if (level == 1)
+ return *this;
+ else if (level == -max_recursion_level)
+ throw(std::runtime_error("max recursion level reached"));
+ else {
+ evalf_map_function map_evalf(level - 1);
+ return map(map_evalf);
+ }
+ }
+}
+
+/** Function object to be applied by basic::evalm(). */
+struct evalm_map_function : public map_function {
+ ex operator()(const ex & e) { return evalm(e); }
+} map_evalm;
+
+/** Evaluate sums, products and integer powers of matrices. */
+ex basic::evalm() const
+{
+ if (nops() == 0)
+ return *this;
+ else
+ return map(map_evalm);
+}
+
+/** Function object to be applied by basic::eval_integ(). */
+struct eval_integ_map_function : public map_function {
+ ex operator()(const ex & e) { return eval_integ(e); }
+} map_eval_integ;
+
+/** Evaluate integrals, if result is known. */
+ex basic::eval_integ() const
+{
+ if (nops() == 0)
+ return *this;
+ else
+ return map(map_eval_integ);
+}
+
+/** Perform automatic symbolic evaluations on indexed expression that
+ * contains this object as the base expression. */
+ex basic::eval_indexed(const basic & i) const
+ // this function can't take a "const ex & i" because that would result
+ // in an infinite eval() loop
+{
+ // There is nothing to do for basic objects
+ return i.hold();
+}
+
+/** Add two indexed expressions. They are guaranteed to be of class indexed
+ * (or a subclass) and their indices are compatible. This function is used
+ * internally by simplify_indexed().
+ *
+ * @param self First indexed expression; its base object is *this
+ * @param other Second indexed expression
+ * @return sum of self and other
+ * @see ex::simplify_indexed() */
+ex basic::add_indexed(const ex & self, const ex & other) const
+{
+ return self + other;
+}
+
+/** Multiply an indexed expression with a scalar. This function is used
+ * internally by simplify_indexed().
+ *
+ * @param self Indexed expression; its base object is *this
+ * @param other Numeric value
+ * @return product of self and other
+ * @see ex::simplify_indexed() */
+ex basic::scalar_mul_indexed(const ex & self, const numeric & other) const
+{
+ return self * other;
+}
+
+/** Try to contract two indexed expressions that appear in the same product.
+ * If a contraction exists, the function overwrites one or both of the
+ * expressions and returns true. Otherwise it returns false. It is
+ * guaranteed that both expressions are of class indexed (or a subclass)
+ * and that at least one dummy index has been found. This functions is
+ * used internally by simplify_indexed().
+ *
+ * @param self Pointer to first indexed expression; its base object is *this
+ * @param other Pointer to second indexed expression
+ * @param v The complete vector of factors
+ * @return true if the contraction was successful, false otherwise
+ * @see ex::simplify_indexed() */
+bool basic::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
+{
+ // Do nothing
+ return false;