]> www.ginac.de Git - ginac.git/blobdiff - ginac/power.cpp
- (l)degree(s), coeff(s, n) and collect(s) were extended to accept expressions
[ginac.git] / ginac / power.cpp
index 72ec5aa368ae65c3bc8565309e379074e00d134e..4c7519ec9c3b75866896555dbf7bfdd5cbd2c046 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's symbolic exponentiation (basis^exponent). */
 
 /*
- *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2002 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
@@ -139,7 +139,7 @@ void power::print(const print_context & c, unsigned level) const
                        c.s << ')';
 
                // <expr>^-1 is printed as "1.0/<expr>" or with the recip() function of CLN
-               } else if (exponent.compare(_num_1) == 0) {
+               } else if (exponent.is_equal(_ex_1)) {
                        if (is_a<print_csrc_cl_N>(c))
                                c.s << "recip(";
                        else
@@ -244,7 +244,9 @@ ex power::map(map_function & f) const
 
 int power::degree(const ex & s) const
 {
-       if (is_ex_exactly_of_type(exponent, numeric) && ex_to<numeric>(exponent).is_integer()) {
+       if (is_equal(ex_to<basic>(s)))
+               return 1;
+       else if (is_ex_exactly_of_type(exponent, numeric) && ex_to<numeric>(exponent).is_integer()) {
                if (basis.is_equal(s))
                        return ex_to<numeric>(exponent).to_int();
                else
@@ -257,7 +259,9 @@ int power::degree(const ex & s) const
 
 int power::ldegree(const ex & s) const 
 {
-       if (is_ex_exactly_of_type(exponent, numeric) && ex_to<numeric>(exponent).is_integer()) {
+       if (is_equal(ex_to<basic>(s)))
+               return 1;
+       else if (is_ex_exactly_of_type(exponent, numeric) && ex_to<numeric>(exponent).is_integer()) {
                if (basis.is_equal(s))
                        return ex_to<numeric>(exponent).to_int();
                else
@@ -270,7 +274,9 @@ int power::ldegree(const ex & s) const
 
 ex power::coeff(const ex & s, int n) const
 {
-       if (!basis.is_equal(s)) {
+       if (is_equal(ex_to<basic>(s)))
+               return n==1 ? _ex1 : _ex0;
+       else if (!basis.is_equal(s)) {
                // basis not equal to s
                if (n == 0)
                        return *this;