[PATCH] fix incorrect result: degree(c*x^(-1), x^(-1)) gives zero
Hello! degree(c*x^(-1), x^(-1)) (in ginsh notation) gives zero instead of expected 1. On the other hand, degree(x^(-1), x^(-1)) and coeff(c*x^(-1), x^(-1)) work fine. This patch makes degree (and ldegree) work correct with such arguments. --- ginac/mul.cpp | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ginac/mul.cpp b/ginac/mul.cpp index dd96a70..9bbcd61 100644 --- a/ginac/mul.cpp +++ b/ginac/mul.cpp @@ -315,7 +315,11 @@ int mul::degree(const ex & s) const epvector::const_iterator i = seq.begin(), end = seq.end(); while (i != end) { if (ex_to<numeric>(i->coeff).is_integer()) - deg_sum += i->rest.degree(s) * ex_to<numeric>(i->coeff).to_int(); + deg_sum += recombine_pair_to_ex(*i).degree(s); + else { + if (i->rest.has(s)) + throw std::runtime_error("mul::degree() undefined degree because of non-integer exponent"); + } ++i; } return deg_sum; @@ -328,7 +332,11 @@ int mul::ldegree(const ex & s) const epvector::const_iterator i = seq.begin(), end = seq.end(); while (i != end) { if (ex_to<numeric>(i->coeff).is_integer()) - deg_sum += i->rest.ldegree(s) * ex_to<numeric>(i->coeff).to_int(); + deg_sum += recombine_pair_to_ex(*i).ldegree(s); + else { + if (i->rest.has(s)) + throw std::runtime_error("mul::ldegree() undefined degree because of non-integer exponent"); + } ++i; } return deg_sum; -- 1.4.4.4 Best regards, Alexei -- All science is either physics or stamp collecting.
participants (2)
-
Alexei Sheplyakov
-
Chris Dams