+ // Evaluate children first and add up all matrices. Stop if there's one
+ // term that is not a matrix.
+ epvector *s = new epvector;
+ s->reserve(seq.size());
+
+ bool all_matrices = true;
+ bool first_term = true;
+ matrix sum;
+
+ epvector::const_iterator it = seq.begin(), itend = seq.end();
+ while (it != itend) {
+ const ex &m = recombine_pair_to_ex(*it).evalm();
+ s->push_back(split_ex_to_pair(m));
+ if (is_a<matrix>(m)) {
+ if (first_term) {
+ sum = ex_to<matrix>(m);
+ first_term = false;
+ } else
+ sum = sum.add(ex_to<matrix>(m));
+ } else
+ all_matrices = false;
+ ++it;