]> www.ginac.de Git - ginac.git/commitdiff
Synced to HEAD:
authorJens Vollinga <vollinga@thep.physik.uni-mainz.de>
Mon, 15 Oct 2007 23:49:18 +0000 (23:49 +0000)
committerJens Vollinga <vollinga@thep.physik.uni-mainz.de>
Mon, 15 Oct 2007 23:49:18 +0000 (23:49 +0000)
- This helps mul::expand() and friends to recognize objects which have
no indices at all [Sheplyakov].

ginac/mul.cpp
ginac/power.cpp

index 5176218bec1be7d8359c90053c2a8d97f84a00f8..d6ff7cb9da51dc8677cfe0514b8601a6b313b098 100644 (file)
@@ -34,6 +34,7 @@
 #include "lst.h"
 #include "archive.h"
 #include "utils.h"
+#include "symbol.h"
 #include "compiler.h"
 
 namespace GiNaC {
@@ -940,7 +941,18 @@ 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);
+       if (skip_idx_rename)
+               ++(mul_expand_stats::n_indexless);
        // First, expand the children
        std::auto_ptr<epvector> expanded_seqp = expandchildren(options);
        const epvector & expanded_seq = (expanded_seqp.get() ? *expanded_seqp : seq);
index bbcb45368bcf6465f1409cf78d0945b2606df6a1..010af6c961847f65c2417bed3355f7476a2c52d5 100644 (file)
@@ -680,6 +680,9 @@ unsigned 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;