+ // Evaluate children first
+ exvector *s = new exvector;
+ s->reserve(seq.size());
+ exvector::const_iterator it = seq.begin(), itend = seq.end();
+ while (it != itend) {
+ s->push_back(it->evalm());
+ it++;
+ }
+
+ // If there are only matrices, simply multiply them
+ it = s->begin(); itend = s->end();
+ if (is_ex_of_type(*it, matrix)) {
+ matrix prod(ex_to<matrix>(*it));
+ it++;
+ while (it != itend) {
+ if (!is_ex_of_type(*it, matrix))
+ goto no_matrix;
+ prod = prod.mul(ex_to<matrix>(*it));
+ it++;
+ }
+ delete s;
+ return prod;
+ }
+
+no_matrix:
+ return (new ncmul(s))->setflag(status_flags::dynallocated);