]> www.ginac.de Git - ginac.git/blobdiff - ginac/power.cpp
* Forward declare simplify indexed for GCC 4.1 [Sheplyakov Alexei].
[ginac.git] / ginac / power.cpp
index 8a0156e4d8627d4e7cf5bcb28e72e1aaa572375f..f9dfafbfb80c55a5856195a4be9127a0f538c0fc 100644 (file)
@@ -381,6 +381,10 @@ ex power::eval(int level) const
        if (ebasis.is_equal(_ex1))
                return _ex1;
 
+       // power of a function calculated by separate rules defined for this function
+       if (is_exactly_a<function>(ebasis))
+               return ex_to<function>(ebasis).power(eexponent);
+
        if (exponent_is_numerical) {
 
                // ^(c1,c2) -> c1^c2  (c1, c2 numeric(),
@@ -858,10 +862,13 @@ ex power::expand_mul(const mul & m, const numeric & n, unsigned options, bool fr
        }
 
        // Leave it to multiplication since dummy indices have to be renamed
-       if (get_all_dummy_indices(m).size() > 0) {
+       if (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());
+
                for (int i=1; i < n.to_int(); i++)
-                       result *= rename_dummy_indices_uniquely(m,m);
+                       result *= rename_dummy_indices_uniquely(va, m);
                return result;
        }