]> www.ginac.de Git - ginac.git/commitdiff
synced to HEAD (expand_indexed)
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Wed, 28 Jan 2004 20:00:50 +0000 (20:00 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Wed, 28 Jan 2004 20:00:50 +0000 (20:00 +0000)
ginac/indexed.cpp

index d513db0c8e6b1eca7d26a26fd09f2ac24a394470..60d0ac4a9fbb882fd1d0d7f1c3efa97b991da729 100644 (file)
@@ -289,20 +289,24 @@ ex indexed::expand(unsigned options) const
 {
        GINAC_ASSERT(seq.size() > 0);
 
-       if ((options & expand_options::expand_indexed) && is_exactly_a<add>(seq[0])) {
-
-               // expand_indexed expands (a+b).i -> a.i + b.i
-               const ex & base = seq[0];
-               ex sum = _ex0;
-               for (size_t i=0; i<base.nops(); i++) {
+       if (options & expand_options::expand_indexed) {
+               ex newbase = seq[0].expand(options);
+               if (is_exactly_a<add>(newbase)) {
+                       ex sum = _ex0;
+                       for (size_t i=0; i<newbase.nops(); i++) {
+                               exvector s = seq;
+                               s[0] = newbase.op(i);
+                               sum += thisexprseq(s).expand(options);
+                       }
+                       return sum;
+               }
+               if (!are_ex_trivially_equal(newbase, seq[0])) {
                        exvector s = seq;
-                       s[0] = base.op(i);
-                       sum += thisexprseq(s).expand();
+                       s[0] = newbase;
+                       return ex_to<indexed>(thisexprseq(s)).inherited::expand(options);
                }
-               return sum;
-
-       } else
-               return inherited::expand(options);
+       }
+       return inherited::expand(options);
 }
 
 //////////