]> www.ginac.de Git - ginac.git/blobdiff - ginac/indexed.cpp
Don't abort if cannot find minimal dimension of indices when trying use
[ginac.git] / ginac / indexed.cpp
index e9c4fee2e56e9bd09b9c36a8bf73cb4f79d2a820..0c1c904f1295caa0c4cf98cb26f0ab649a38eb46 100644 (file)
@@ -738,6 +738,9 @@ template<class T> ex idx_symmetrization(const ex& r,const exvector& local_dummy_
        return q;
 }
 
+// Forward declaration needed in absence of friend injection, C.f. [namespace.memdef]:
+ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indices, const scalar_products & sp);
+
 /** Simplify product of indexed expressions (commutative, noncommutative and
  *  simple squares), return list of free indices. */
 ex simplify_indexed_product(const ex & e, exvector & free_indices, exvector & dummy_indices, const scalar_products & sp)
@@ -792,27 +795,29 @@ try_again:
                        bool contracted = false;
                        if (free.empty()) {
 
-                               // Find minimal dimension of all indices of both factors
-                               exvector::const_iterator dit = ex_to<indexed>(*it1).seq.begin() + 1, ditend = ex_to<indexed>(*it1).seq.end();
-                               ex dim = ex_to<idx>(*dit).get_dim();
-                               ++dit;
-                               for (; dit != ditend; ++dit) {
-                                       dim = minimal_dim(dim, ex_to<idx>(*dit).get_dim());
-                               }
-                               dit = ex_to<indexed>(*it2).seq.begin() + 1;
-                               ditend = ex_to<indexed>(*it2).seq.end();
-                               for (; dit != ditend; ++dit) {
-                                       dim = minimal_dim(dim, ex_to<idx>(*dit).get_dim());
-                               }
+                               try {
+                                       // Find minimal dimension of all indices of both factors
+                                       exvector::const_iterator dit = ex_to<indexed>(*it1).seq.begin() + 1, ditend = ex_to<indexed>(*it1).seq.end();
+                                       ex dim = ex_to<idx>(*dit).get_dim();
+                                       ++dit;
+                                       for (; dit != ditend; ++dit) {
+                                               dim = minimal_dim(dim, ex_to<idx>(*dit).get_dim());
+                                       }
+                                       dit = ex_to<indexed>(*it2).seq.begin() + 1;
+                                       ditend = ex_to<indexed>(*it2).seq.end();
+                                       for (; dit != ditend; ++dit) {
+                                               dim = minimal_dim(dim, ex_to<idx>(*dit).get_dim());
+                                       }
 
-                               // User-defined scalar product?
-                               if (sp.is_defined(*it1, *it2, dim)) {
+                                       // User-defined scalar product?
+                                       if (sp.is_defined(*it1, *it2, dim)) {
 
-                                       // Yes, substitute it
-                                       *it1 = sp.evaluate(*it1, *it2, dim);
-                                       *it2 = _ex1;
-                                       goto contraction_done;
-                               }
+                                               // Yes, substitute it
+                                               *it1 = sp.evaluate(*it1, *it2, dim);
+                                               *it2 = _ex1;
+                                               goto contraction_done;
+                                       }
+                               } catch (const std::runtime_error&) {}
                        }
 
                        // Try to contract the first one with the second one