]> www.ginac.de Git - ginac.git/blobdiff - ginac/mul.cpp
- This helps mul::expand() and friends to recognize objects which have
[ginac.git] / ginac / mul.cpp
index db8b9f14acd308d76344ed57bfc44857f63e4d24..4e95a638310e313444c45736af5b1d090a8f6076 100644 (file)
@@ -34,6 +34,7 @@
 #include "lst.h"
 #include "archive.h"
 #include "utils.h"
+#include "symbol.h"
 #include "compiler.h"
 
 namespace GiNaC {
@@ -992,7 +993,22 @@ bool mul::can_be_further_expanded(const ex & e)
 
 ex mul::expand(unsigned options) const
 {
-       const bool skip_idx_rename = ! info(info_flags::has_indices);
+       {
+       // trivial case: expanding the monomial (~ 30% of all calls)
+               epvector::const_iterator i = seq.begin(), seq_end = seq.end();
+               while ((i != seq.end()) &&  is_a<symbol>(i->rest) && i->coeff.info(info_flags::integer))
+                       ++i;
+               if (i == seq_end)
+                       return (new mul(*this))->setflag(status_flags::dynallocated | status_flags::expanded);
+       }
+
+       // do not rename indices if the object has no indices at all
+       if ((!(options & expand_options::expand_rename_idx)) && 
+                       this->info(info_flags::has_indices))
+               options |= expand_options::expand_rename_idx;
+
+       const bool skip_idx_rename = !(options & expand_options::expand_rename_idx);
+
        // First, expand the children
        std::auto_ptr<epvector> expanded_seqp = expandchildren(options);
        const epvector & expanded_seq = (expanded_seqp.get() ? *expanded_seqp : seq);