]> www.ginac.de Git - ginac.git/blobdiff - ginac/power.cpp
- This helps mul::expand() and friends to recognize objects which have
[ginac.git] / ginac / power.cpp
index 10de528d06ad9cf09381b4376f61ff433ca414f6..40ba3376a2af6d17d65cbc73fd992314325fe019 100644 (file)
@@ -772,6 +772,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;
        
@@ -1007,8 +1010,13 @@ ex power::expand_mul(const mul & m, const numeric & n, unsigned options, bool fr
                return _ex1;
        }
 
+       // do not bother to rename indices if there are no any.
+       if ((!(options & expand_options::expand_rename_idx)) 
+                       && m.info(info_flags::has_indices))
+               options |= expand_options::expand_rename_idx;
        // Leave it to multiplication since dummy indices have to be renamed
-       if (get_all_dummy_indices(m).size() > 0 && n.is_positive()) {
+       if ((options & expand_options::expand_rename_idx) &&
+               (get_all_dummy_indices(m).size() > 0) && n.is_positive()) {
                ex result = m;
                exvector va = get_all_dummy_indices(m);
                sort(va.begin(), va.end(), ex_is_less());