]> www.ginac.de Git - ginac.git/commitdiff
Synced to HEAD:
authorJens Vollinga <vollinga@thep.physik.uni-mainz.de>
Mon, 15 Oct 2007 23:43:50 +0000 (23:43 +0000)
committerJens Vollinga <vollinga@thep.physik.uni-mainz.de>
Mon, 15 Oct 2007 23:43:50 +0000 (23:43 +0000)
- Apparently, in ~ 30% of calls to mul::expand the expression is monomial.
Expanding monomials should be done as fast as possible [Sheplyakov].

ginac/mul.cpp
ginac/power.cpp

index db8b9f14acd308d76344ed57bfc44857f63e4d24..298715b33fd2eabfd28ea9390229fb3f5b90b39d 100644 (file)
@@ -34,6 +34,7 @@
 #include "lst.h"
 #include "archive.h"
 #include "utils.h"
+#include "symbol.h"
 #include "compiler.h"
 
 namespace GiNaC {
@@ -992,6 +993,15 @@ bool mul::can_be_further_expanded(const ex & e)
 
 ex mul::expand(unsigned options) const
 {
+       {
+       // 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);
+       }
+
        const bool skip_idx_rename = ! info(info_flags::has_indices);
        // First, expand the children
        std::auto_ptr<epvector> expanded_seqp = expandchildren(options);
index fe7132a9ea4b480c4a3c469d835e8e4f74435f68..cc003bce437e185d31d7095e7c0bfedc6ead8c1a 100644 (file)
@@ -771,6 +771,9 @@ tinfo_t power::return_type_tinfo() const
 
 ex power::expand(unsigned options) const
 {
+       if (is_a<symbol>(basis) && exponent.info(info_flags::integer))
+               return (new power(*this))->setflag(status_flags::dynallocated | status_flags::expanded);
+
        if (options == 0 && (flags & status_flags::expanded))
                return *this;