- non-integer powers are treated as 0 by (l)degree() and coeff()
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Wed, 25 Oct 2000 18:33:32 +0000 (18:33 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Wed, 25 Oct 2000 18:33:32 +0000 (18:33 +0000)
NEWS
ginac/mul.cpp
ginac/power.cpp

diff --git a/NEWS b/NEWS
index 4a119ee..228d5a4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,11 @@
 This file records noteworthy changes.
 
+0.6.5 ()
+* Non-integer powers of a symbol are treated as constants by (l)degree() and
+  coeff(). Using these functions on an expression containing such powers used
+  to fail with an internal error message. The side-effect is that collect()
+  can be used on expressions which are not polynomials.
+
 0.6.4 (10 August 2000)
 * Complete revamp of methods in class matrix.  Some redundant (and poor)
   implementations of elimination schemes were thrown out.  The code is now
index ee00dd4..ad7aa13 100644 (file)
@@ -310,7 +310,8 @@ int mul::degree(const symbol & s) const
 {
        int deg_sum = 0;
        for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
-               deg_sum+=(*cit).rest.degree(s) * ex_to_numeric((*cit).coeff).to_int();
+               if (ex_to_numeric(cit->coeff).is_integer())
+                       deg_sum+=cit->rest.degree(s) * ex_to_numeric(cit->coeff).to_int();
        }
        return deg_sum;
 }
@@ -319,7 +320,8 @@ int mul::ldegree(const symbol & s) const
 {
        int deg_sum = 0;
        for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
-               deg_sum+=(*cit).rest.ldegree(s) * ex_to_numeric((*cit).coeff).to_int();
+               if (ex_to_numeric(cit->coeff).is_integer())
+                       deg_sum+=cit->rest.ldegree(s) * ex_to_numeric(cit->coeff).to_int();
        }
        return deg_sum;
 }
index 53342a9..a0c6ea4 100644 (file)
@@ -282,9 +282,12 @@ ex & power::let_op(int i)
 int power::degree(const symbol & s) const
 {
        if (is_exactly_of_type(*exponent.bp,numeric)) {
-               if ((*basis.bp).compare(s)==0)
-                       return ex_to_numeric(exponent).to_int();
-               else
+               if ((*basis.bp).compare(s)==0) {
+                       if (ex_to_numeric(exponent).is_integer())
+                               return ex_to_numeric(exponent).to_int();
+                       else
+                               return 0;
+               } else
                        return basis.degree(s) * ex_to_numeric(exponent).to_int();
        }
        return 0;
@@ -293,9 +296,12 @@ int power::degree(const symbol & s) const
 int power::ldegree(const symbol & s) const 
 {
        if (is_exactly_of_type(*exponent.bp,numeric)) {
-               if ((*basis.bp).compare(s)==0)
-                       return ex_to_numeric(exponent).to_int();
-               else
+               if ((*basis.bp).compare(s)==0) {
+                       if (ex_to_numeric(exponent).is_integer())
+                               return ex_to_numeric(exponent).to_int();
+                       else
+                               return 0;
+               } else
                        return basis.ldegree(s) * ex_to_numeric(exponent).to_int();
        }
        return 0;
@@ -305,17 +311,27 @@ ex power::coeff(const symbol & s, int n) const
 {
        if ((*basis.bp).compare(s)!=0) {
                // basis not equal to s
-               if (n==0) {
+               if (n == 0)
                        return *this;
-               } else {
+               else
                        return _ex0();
+       } else {
+               // basis equal to s
+               if (is_exactly_of_type(*exponent.bp, numeric) && ex_to_numeric(exponent).is_integer()) {
+                       // integer exponent
+                       int int_exp = ex_to_numeric(exponent).to_int();
+                       if (n == int_exp)
+                               return _ex1();
+                       else
+                               return _ex0();
+               } else {
+                       // non-integer exponents are treated as zero
+                       if (n == 0)
+                               return *this;
+                       else
+                               return _ex0();
                }
-       } else if (is_exactly_of_type(*exponent.bp,numeric)&&
-                          (static_cast<const numeric &>(*exponent.bp).compare(numeric(n))==0)) {
-               return _ex1();
        }
-
-       return _ex0();
 }
 
 ex power::eval(int level) const