X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Fpower.cpp;h=62fc3a8ddf070bd5c02a3fe0e2b75ad0006330e6;hb=e432b3743d3d32f6060600af580e49d7033dcae9;hp=3c718027bdaa530782d063620fe75b20b440f681;hpb=3a7031219dabf8e5d15dc63ca4975c88e20abaec;p=ginac.git diff --git a/ginac/power.cpp b/ginac/power.cpp index 3c718027..62fc3a8d 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's symbolic exponentiation (basis^exponent). */ /* - * GiNaC Copyright (C) 1999-2017 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2018 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -669,7 +669,8 @@ ex power::real_part() const // basis == a+I*b, exponent == c+I*d const ex a = basis.real_part(); const ex c = exponent.real_part(); - if (basis.is_equal(a) && exponent.is_equal(c)) { + if (basis.is_equal(a) && exponent.is_equal(c) && + (a.info(info_flags::nonnegative) || c.info(info_flags::integer))) { // Re(a^c) return *this; } @@ -704,7 +705,8 @@ ex power::imag_part() const // basis == a+I*b, exponent == c+I*d const ex a = basis.real_part(); const ex c = exponent.real_part(); - if (basis.is_equal(a) && exponent.is_equal(c)) { + if (basis.is_equal(a) && exponent.is_equal(c) && + (a.info(info_flags::nonnegative) || c.info(info_flags::integer))) { // Im(a^c) return 0; } @@ -979,9 +981,9 @@ ex power::expand_add(const add & a, long n, unsigned options) // Multinomial expansion of power(+(x,...,z;0),k)*c^(n-k): // Iterate over all partitions of k with exactly as many parts as // there are symbolic terms in the basis (including zero parts). - partition_generator partitions(k, a.seq.size()); + partition_with_zero_parts_generator partitions(k, a.seq.size()); do { - const std::vector& partition = partitions.current(); + const std::vector& partition = partitions.get(); // All monomials of this partition have the same number of terms and the same coefficient. const unsigned msize = std::count_if(partition.begin(), partition.end(), [](int i) { return i > 0; }); const numeric coeff = multinomial_coefficient(partition) * binomial_coefficient; @@ -989,7 +991,7 @@ ex power::expand_add(const add & a, long n, unsigned options) // Iterate over all compositions of the current partition. composition_generator compositions(partition); do { - const std::vector& exponent = compositions.current(); + const std::vector& exponent = compositions.get(); epvector monomial; monomial.reserve(msize); numeric factor = coeff;