]> www.ginac.de Git - ginac.git/commitdiff
Small optimization in simplify_indexed.
authorVladimir V. Kisil <kisilv@maths.leeds.ac.uk>
Sun, 25 Jan 2015 10:39:04 +0000 (11:39 +0100)
committerRichard Kreckel <kreckel@ginac.de>
Sun, 25 Jan 2015 10:39:04 +0000 (11:39 +0100)
If the new expression is product again then we call the same function return
simplify_indexed_product() rather than the its mother implify_indexed().

ginac/indexed.cpp

index e8ca5cec682a03afcb68a558a1c15d00f5932bc2..0c4103c2ef6e30b2d5be617185c17814c5c1e02e 100644 (file)
@@ -874,8 +874,16 @@ contraction_done:
                                        // Non-commutative products are always re-expanded to give
                                        // eval_ncmul() the chance to re-order and canonicalize
                                        // the product
+                                       bool is_a_product = (is_exactly_a<mul>(*it1) || is_exactly_a<ncmul>(*it1)) &&
+                                                           (is_exactly_a<mul>(*it2) || is_exactly_a<ncmul>(*it2));
                                        ex r = (non_commutative ? ex(ncmul(v, true)) : ex(mul(v)));
-                                       return simplify_indexed(r, free_indices, dummy_indices, sp);
+
+                                       // If new expression is a product we can call this function again,
+                                       // otherwise we need to pass argument to simplify_indexed() to be expanded
+                                       if (is_a_product)
+                                               return simplify_indexed_product(r, free_indices, dummy_indices, sp);
+                                       else
+                                               return simplify_indexed(r, free_indices, dummy_indices, sp);
                                }
 
                                // Both objects may have new indices now or they might