]> www.ginac.de Git - ginac.git/commitdiff
degree(), ldegree(), coeff(), lcoeff(), tcoeff() and collect() can now
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Mon, 2 Apr 2001 20:57:32 +0000 (20:57 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Mon, 2 Apr 2001 20:57:32 +0000 (20:57 +0000)
be used with constants and indexed expressions as well, so you can use
it to collect by powers of Pi or find the coefficient of gamma~0.
Limitations:
 - it only works with symbols, constants and indexed expressions;
   trying to find the coefficient of, e.g., "x^2" or "x+y" won't work
 - it does not know about dummy index summations; the coefficient of
   gamma~0 in p.mu*gamma~mu should be p.0 but is returned as 0
 - using the functions on elements of noncommutative products might
   return wrong or surprising results

22 files changed:
NEWS
doc/tutorial/ginac.texi
ginac/add.cpp
ginac/add.h
ginac/basic.cpp
ginac/basic.h
ginac/constant.cpp
ginac/constant.h
ginac/ex.cpp
ginac/ex.h
ginac/indexed.cpp
ginac/indexed.h
ginac/mul.cpp
ginac/mul.h
ginac/ncmul.cpp
ginac/ncmul.h
ginac/power.cpp
ginac/power.h
ginac/pseries.cpp
ginac/pseries.h
ginac/symbol.cpp
ginac/symbol.h

diff --git a/NEWS b/NEWS
index 934d6caa9392c747be30feb95379f8a3bd2ac448..d68d427b2fbd3044b52af538999ed394ca631e62 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,21 @@
 This file records noteworthy changes.
 
+0.8.1 (<date>)
+* degree(), ldegree(), coeff(), lcoeff(), tcoeff() and collect() can now
+  be used with constants and indexed expressions as well, so you can use
+  it to collect by powers of Pi or find the coefficient of gamma~0.
+  Limitations:
+   - it only works with symbols, constants and indexed expressions;
+     trying to find the coefficient of, e.g., "x^2" or "x+y" won't work
+   - it does not know about dummy index summations; the coefficient of
+     gamma~0 in p.mu*gamma~mu should be p.0 but is returned as 0
+   - using the functions on elements of noncommutative products might
+     return wrong or surprising results
+* Added preliminary (re)implementations of color and clifford classes.
+* simplify_indexed(): contraction of symmetric and antisymmetric tensors
+  is zero.
+* Some bugfixes (indexed objects, archive writing).
+
 0.8.0 (24 March 2001)
 * Complete revamp of indexed objects. Instead of multiple classes for
   indexed things and their indices there is now only one "indexed" class
index bb8c5cbf4f3c3de417662648fed591108accadd0..d3a4d992beb56c90b726a9185f896a39874c8271 100644 (file)
@@ -2083,7 +2083,7 @@ being polynomials in the remaining variables.  The method
 @code{collect()} accomplishes this task:
 
 @example
-ex ex::collect(const symbol & s);
+ex ex::collect(const ex & s);
 @end example
 
 Note that the original polynomial needs to be in expanded form in order
@@ -2098,8 +2098,8 @@ The degree and low degree of a polynomial can be obtained using the two
 methods
 
 @example
-int ex::degree(const symbol & s);
-int ex::ldegree(const symbol & s);
+int ex::degree(const ex & s);
+int ex::ldegree(const ex & s);
 @end example
 
 which also work reliably on non-expanded input polynomials (they even work
@@ -2107,14 +2107,14 @@ on rational functions, returning the asymptotic degree). To extract
 a coefficient with a certain power from an expanded polynomial you use
 
 @example
-ex ex::coeff(const symbol & s, int n);
+ex ex::coeff(const ex & s, int n);
 @end example
 
 You can also obtain the leading and trailing coefficients with the methods
 
 @example
-ex ex::lcoeff(const symbol & s);
-ex ex::tcoeff(const symbol & s);
+ex ex::lcoeff(const ex & s);
+ex ex::tcoeff(const ex & s);
 @end example
 
 which are equivalent to @code{coeff(s, degree(s))} and @code{coeff(s, ldegree(s))},
index 150b4f8222d0df346dd357b104656f9fd70aaf15..7d73c306e980340cb1a52a50cbdb6a7a1938cc21 100644 (file)
@@ -240,7 +240,7 @@ bool add::info(unsigned inf) const
        return inherited::info(inf);
 }
 
-int add::degree(const symbol & s) const
+int add::degree(const ex & s) const
 {
        int deg = INT_MIN;
        if (!overall_coeff.is_equal(_ex0()))
@@ -255,7 +255,7 @@ int add::degree(const symbol & s) const
        return deg;
 }
 
-int add::ldegree(const symbol & s) const
+int add::ldegree(const ex & s) const
 {
        int deg = INT_MAX;
        if (!overall_coeff.is_equal(_ex0()))
@@ -269,7 +269,7 @@ int add::ldegree(const symbol & s) const
        return deg;
 }
 
-ex add::coeff(const symbol & s, int n) const
+ex add::coeff(const ex & s, int n) const
 {
        epvector coeffseq;
        coeffseq.reserve(seq.size());
index 8738bdf3d8b6d405ba0587cfd6e0a3011e741c7b..738d09b337ca5565b3f3ab246bc2fa1db6357b7a 100644 (file)
@@ -50,9 +50,9 @@ public:
        void printraw(std::ostream & os) const;
        void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence=0) const;
        bool info(unsigned inf) const;
-       int degree(const symbol & s) const;
-       int ldegree(const symbol & s) const;
-       ex coeff(const symbol & s, int n=1) const;
+       int degree(const ex & s) const;
+       int ldegree(const ex & s) const;
+       ex coeff(const ex & s, int n=1) const;
        ex eval(int level=0) const;
        ex series(const relational & r, int order, unsigned options = 0) const;
        ex normal(lst &sym_lst, lst &repl_lst, int level=0) const;
index 42d1f86632c436b8e9bafde8d53d07065e1d7350..fe1d4ea121f1c4bedebd5309fc17058a1b4ca2ad 100644 (file)
@@ -242,26 +242,26 @@ bool basic::has(const ex & other) const
 }
 
 /** Return degree of highest power in symbol s. */
-int basic::degree(const symbol & s) const
+int basic::degree(const ex & s) const
 {
        return 0;
 }
 
 /** Return degree of lowest power in symbol s. */
-int basic::ldegree(const symbol & s) const
+int basic::ldegree(const ex & s) const
 {
        return 0;
 }
 
 /** Return coefficient of degree n in symbol s. */
-ex basic::coeff(const symbol & s, int n) const
+ex basic::coeff(const ex & s, int n) const
 {
        return n==0 ? *this : _ex0();
 }
 
 /** Sort expression in terms of powers of some symbol.
  *  @param s symbol to sort in. */
-ex basic::collect(const symbol & s) const
+ex basic::collect(const ex & s) const
 {
        ex x;
        for (int n=this->ldegree(s); n<=this->degree(s); n++)
index 2e1aefdff859567a4da9605f91c04e42dcb17203..1f4a4fdc69039cf0ee530b693fbe822b0ae695dd 100644 (file)
@@ -114,10 +114,10 @@ public: // only const functions please (may break reference counting)
        virtual ex operator[](const ex & index) const;
        virtual ex operator[](int i) const;
        virtual bool has(const ex & other) const;
-       virtual int degree(const symbol & s) const;
-       virtual int ldegree(const symbol & s) const;
-       virtual ex coeff(const symbol & s, int n = 1) const;
-       virtual ex collect(const symbol & s) const;
+       virtual int degree(const ex & s) const;
+       virtual int ldegree(const ex & s) const;
+       virtual ex coeff(const ex & s, int n = 1) const;
+       virtual ex collect(const ex & s) const;
        virtual ex eval(int level = 0) const;
        virtual ex evalf(int level = 0) const;
        virtual ex series(const relational & r, int order, unsigned options = 0) const;
index 5b2bfebe89c0dbfadcfb54fe2337c9e9631bd94b..5aad78d096ee0e86e11e56778f8c5dc67ed3bd78 100644 (file)
@@ -154,6 +154,24 @@ void constant::printcsrc(std::ostream & os, unsigned type, unsigned upper_preced
        os << name;
 }
 
+int constant::degree(const ex & s) const
+{
+       return is_equal(*s.bp) ? 1 : 0;
+}
+
+int constant::ldegree(const ex & s) const
+{
+       return is_equal(*s.bp) ? 1 : 0;
+}
+
+ex constant::coeff(const ex & s, int n) const
+{
+       if (is_equal(*s.bp))
+               return n==1 ? _ex1() : _ex0();
+       else
+               return n==0 ? *this : _ex0();
+}
+
 ex constant::evalf(int level) const
 {
        if (ef!=0) {
index b30fc26257a24b72e14b4faa0b8b931d3e8dfc2d..d56f2bc861389e3e29ae236bd24f209350b29d6a 100644 (file)
@@ -52,6 +52,9 @@ public:
        void printraw(std::ostream & os) const;
        void printtree(std::ostream & os, unsigned indent) const;
        void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence = 0) const;
+       int degree(const ex & s) const;
+       int ldegree(const ex & s) const;
+       ex coeff(const ex & s, int n = 1) const;
        ex evalf(int level = 0) const;
 protected:
        ex derivative(const symbol & s) const;
index 7570618d16c94ee20d36235d95c622797fc41170..f2dab641892e2c56678224ac6b0a845f375f3918 100644 (file)
@@ -179,25 +179,25 @@ bool ex::has(const ex & other) const
        return bp->has(other);
 }
 
-int ex::degree(const symbol & s) const
+int ex::degree(const ex & s) const
 {
        GINAC_ASSERT(bp!=0);
        return bp->degree(s);
 }
 
-int ex::ldegree(const symbol & s) const
+int ex::ldegree(const ex & s) const
 {
        GINAC_ASSERT(bp!=0);
        return bp->ldegree(s);
 }
 
-ex ex::coeff(const symbol & s, int n) const
+ex ex::coeff(const ex & s, int n) const
 {
        GINAC_ASSERT(bp!=0);
        return bp->coeff(s,n);
 }
 
-ex ex::collect(const symbol & s) const
+ex ex::collect(const ex & s) const
 {
        GINAC_ASSERT(bp!=0);
        return bp->collect(s);
index d034dec2e07f84d1f0c9eb2ea31e976eb33a4871..3358c2806464d7b68d8f72a7a39324be00dcbef8 100644 (file)
@@ -86,11 +86,11 @@ public:
        unsigned nops() const;
        ex expand(unsigned options=0) const;
        bool has(const ex & other) const;
-       int degree(const symbol & s) const;
-       int ldegree(const symbol & s) const;
-       ex coeff(const symbol & s, int n=1) const;
-       ex lcoeff(const symbol & s) const { return coeff(s, degree(s)); }
-       ex tcoeff(const symbol & s) const { return coeff(s, ldegree(s)); }
+       int degree(const ex & s) const;
+       int ldegree(const ex & s) const;
+       ex coeff(const ex & s, int n=1) const;
+       ex lcoeff(const ex & s) const { return coeff(s, degree(s)); }
+       ex tcoeff(const ex & s) const { return coeff(s, ldegree(s)); }
        ex numer(void) const;
        ex denom(void) const;
        ex unit(const symbol &x) const;
@@ -102,7 +102,7 @@ public:
        ex to_rational(lst &repl_lst) const;
        ex smod(const numeric &xi) const;
        numeric max_coefficient(void) const;
-       ex collect(const symbol & s) const;
+       ex collect(const ex & s) const;
        ex eval(int level = 0) const;
        ex evalf(int level = 0) const;
        ex diff(const symbol & s, unsigned nth = 1) const;
@@ -338,13 +338,13 @@ inline ex expand(const ex & thisex, unsigned options = 0)
 inline bool has(const ex & thisex, const ex & other)
 { return thisex.has(other); }
 
-inline int degree(const ex & thisex, const symbol & s)
+inline int degree(const ex & thisex, const ex & s)
 { return thisex.degree(s); }
 
-inline int ldegree(const ex & thisex, const symbol & s)
+inline int ldegree(const ex & thisex, const ex & s)
 { return thisex.ldegree(s); }
 
-inline ex coeff(const ex & thisex, const symbol & s, int n=1)
+inline ex coeff(const ex & thisex, const ex & s, int n=1)
 { return thisex.coeff(s, n); }
 
 inline ex numer(const ex & thisex)
@@ -359,7 +359,7 @@ inline ex normal(const ex & thisex, int level=0)
 inline ex to_rational(const ex & thisex, lst & repl_lst)
 { return thisex.to_rational(repl_lst); }
 
-inline ex collect(const ex & thisex, const symbol & s)
+inline ex collect(const ex & thisex, const ex & s)
 { return thisex.collect(s); }
 
 inline ex eval(const ex & thisex, int level = 0)
index e27a7f62acaa6f96a2029c41e0a8674a6f35cca7..3e333e3f5806563dd28f32b4cd5cb24ebe6c413c 100644 (file)
@@ -350,6 +350,24 @@ ex indexed::eval(int level) const
        return base.bp->eval_indexed(*this);
 }
 
+int indexed::degree(const ex & s) const
+{
+       return is_equal(*s.bp) ? 1 : 0;
+}
+
+int indexed::ldegree(const ex & s) const
+{
+       return is_equal(*s.bp) ? 1 : 0;
+}
+
+ex indexed::coeff(const ex & s, int n) const
+{
+       if (is_equal(*s.bp))
+               return n==1 ? _ex1() : _ex0();
+       else
+               return n==0 ? ex(*this) : _ex0();
+}
+
 ex indexed::thisexprseq(const exvector & v) const
 {
        return indexed(symmetry, v);
index 301f2d748669091813efc21b3011f8ca7110ac2c..e98375d38165d56610fe1e72a111e8412f705711 100644 (file)
@@ -156,6 +156,9 @@ public:
        void print(std::ostream & os, unsigned upper_precedence=0) const;
        bool info(unsigned inf) const;
        ex eval(int level = 0) const;
+       int degree(const ex & s) const;
+       int ldegree(const ex & s) const;
+       ex coeff(const ex & s, int n = 1) const;
        exvector get_free_indices(void) const;
 
 protected:
index e156a0fff00c5ad50ff05a91cd77e2fcde1721ea..a00c9c928ed96436cc3d932a3479fc97897014ce 100644 (file)
@@ -247,7 +247,7 @@ bool mul::info(unsigned inf) const
        return inherited::info(inf);
 }
 
-int mul::degree(const symbol & s) const
+int mul::degree(const ex & s) const
 {
        int deg_sum = 0;
        for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
@@ -257,7 +257,7 @@ int mul::degree(const symbol & s) const
        return deg_sum;
 }
 
-int mul::ldegree(const symbol & s) const
+int mul::ldegree(const ex & s) const
 {
        int deg_sum = 0;
        for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
@@ -267,7 +267,7 @@ int mul::ldegree(const symbol & s) const
        return deg_sum;
 }
 
-ex mul::coeff(const symbol & s, int n) const
+ex mul::coeff(const ex & s, int n) const
 {
        exvector coeffseq;
        coeffseq.reserve(seq.size()+1);
index c531fd6fa4ec36e2172b482c2dbda9e01db86eca..81459a4439d4033f6de5cc1645abd2516b29b240 100644 (file)
@@ -51,9 +51,9 @@ public:
        void printraw(std::ostream & os) const;
        void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence) const;
        bool info(unsigned inf) const;
-       int degree(const symbol & s) const;
-       int ldegree(const symbol & s) const;
-       ex coeff(const symbol & s, int n = 1) const;
+       int degree(const ex & s) const;
+       int ldegree(const ex & s) const;
+       ex coeff(const ex & s, int n = 1) const;
        ex eval(int level=0) const;
        ex evalf(int level=0) const;
        ex series(const relational & s, int order, unsigned options = 0) const;
index 12c1d5e41fcf799eae4485967196222989a282a1..9892670fccd4aafb0f243d98b9dc21899a4f66bf 100644 (file)
@@ -218,7 +218,7 @@ ex ncmul::expand(unsigned options) const
                                                                                status_flags::expanded);
 }
 
-int ncmul::degree(const symbol & s) const
+int ncmul::degree(const ex & s) const
 {
        int deg_sum=0;
        for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
@@ -227,7 +227,7 @@ int ncmul::degree(const symbol & s) const
        return deg_sum;
 }
 
-int ncmul::ldegree(const symbol & s) const
+int ncmul::ldegree(const ex & s) const
 {
        int deg_sum=0;
        for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
@@ -236,7 +236,7 @@ int ncmul::ldegree(const symbol & s) const
        return deg_sum;
 }
 
-ex ncmul::coeff(const symbol & s, int n) const
+ex ncmul::coeff(const ex & s, int n) const
 {
        exvector coeffseq;
        coeffseq.reserve(seq.size());
index dd96a89132fdba32bf24eebd0e386350d243ad63..ec8e5612e414a508687cfb0da400f9e9dc47be96 100644 (file)
@@ -57,10 +57,10 @@ public:
        void printraw(std::ostream & os) const;
        void printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence = 0) const;
        bool info(unsigned inf) const;
-       int degree(const symbol & s) const;
-       int ldegree(const symbol & s) const;
+       int degree(const ex & s) const;
+       int ldegree(const ex & s) const;
        ex expand(unsigned options=0) const;
-       ex coeff(const symbol & s, int n=1) const;
+       ex coeff(const ex & s, int n=1) const;
        ex eval(int level=0) const;
        ex subs(const lst & ls, const lst & lr) const;
        exvector get_free_indices(void) const;
index 14fac0ad1dce7b3202a9b741656500a12966b482..f5d877e65a5baef61dc29f2f67c415b855038acd 100644 (file)
@@ -236,10 +236,10 @@ ex & power::let_op(int i)
        return i==0 ? basis : exponent;
 }
 
-int power::degree(const symbol & s) const
+int power::degree(const ex & s) const
 {
        if (is_exactly_of_type(*exponent.bp,numeric)) {
-               if ((*basis.bp).compare(s)==0) {
+               if (basis.is_equal(s)) {
                        if (ex_to_numeric(exponent).is_integer())
                                return ex_to_numeric(exponent).to_int();
                        else
@@ -250,10 +250,10 @@ int power::degree(const symbol & s) const
        return 0;
 }
 
-int power::ldegree(const symbol & s) const 
+int power::ldegree(const ex & s) const 
 {
        if (is_exactly_of_type(*exponent.bp,numeric)) {
-               if ((*basis.bp).compare(s)==0) {
+               if (basis.is_equal(s)) {
                        if (ex_to_numeric(exponent).is_integer())
                                return ex_to_numeric(exponent).to_int();
                        else
@@ -264,9 +264,9 @@ int power::ldegree(const symbol & s) const
        return 0;
 }
 
-ex power::coeff(const symbol & s, int n) const
+ex power::coeff(const ex & s, int n) const
 {
-       if ((*basis.bp).compare(s)!=0) {
+       if (!basis.is_equal(s)) {
                // basis not equal to s
                if (n == 0)
                        return *this;
index 2c7486162c8fe11d6129ce7784305efa0dd6fbfd..94602911b4de82b73d89a897e7dc413a464c9c29 100644 (file)
@@ -55,9 +55,9 @@ public:
        bool info(unsigned inf) const;
        unsigned nops() const;
        ex & let_op(int i);
-       int degree(const symbol & s) const;
-       int ldegree(const symbol & s) const;
-       ex coeff(const symbol & s, int n = 1) const;
+       int degree(const ex & s) const;
+       int ldegree(const ex & s) const;
+       ex coeff(const ex & s, int n = 1) const;
        ex eval(int level=0) const;
        ex evalf(int level=0) const;
        ex series(const relational & s, int order, unsigned options = 0) const;
index 5a92218335a0689777b518f54815bbad044d81de..7264d933c068bb03a9b3659a318218e43cbb510c 100644 (file)
@@ -248,7 +248,7 @@ ex &pseries::let_op(int i)
 /** Return degree of highest power of the series.  This is usually the exponent
  *  of the Order term.  If s is not the expansion variable of the series, the
  *  series is examined termwise. */
-int pseries::degree(const symbol &s) const
+int pseries::degree(const ex &s) const
 {
        if (var.is_equal(s)) {
                // Return last exponent
@@ -276,7 +276,7 @@ int pseries::degree(const symbol &s) const
  *  series is examined termwise.  If s is the expansion variable but the
  *  expansion point is not zero the series is not expanded to find the degree.
  *  I.e.: (1-x) + (1-x)^2 + Order((1-x)^3) has ldegree(x) 1, not 0. */
-int pseries::ldegree(const symbol &s) const
+int pseries::ldegree(const ex &s) const
 {
        if (var.is_equal(s)) {
                // Return first exponent
@@ -306,7 +306,7 @@ int pseries::ldegree(const symbol &s) const
  *  If s is not the expansion variable, an attempt is made to convert the
  *  series to a polynomial and return the corresponding coefficient from
  *  there. */
-ex pseries::coeff(const symbol &s, int n) const
+ex pseries::coeff(const ex &s, int n) const
 {
        if (var.is_equal(s)) {
                if (seq.size() == 0)
@@ -338,7 +338,7 @@ ex pseries::coeff(const symbol &s, int n) const
 }
 
 /** Does nothing. */
-ex pseries::collect(const symbol &s) const
+ex pseries::collect(const ex &s) const
 {
        return *this;
 }
@@ -489,7 +489,7 @@ ex basic::series(const relational & r, int order, unsigned options) const
        numeric fac(1);
        ex deriv = *this;
        ex coeff = deriv.subs(r);
-       const symbol *s = static_cast<symbol *>(r.lhs().bp);
+       const symbol &s = static_cast<symbol &>(*r.lhs().bp);
        
        if (!coeff.is_zero())
                seq.push_back(expair(coeff, numeric(0)));
@@ -497,7 +497,7 @@ ex basic::series(const relational & r, int order, unsigned options) const
        int n;
        for (n=1; n<order; ++n) {
                fac = fac.mul(numeric(n));
-               deriv = deriv.diff(*s).expand();
+               deriv = deriv.diff(s).expand();
                if (deriv.is_zero()) {
                        // Series terminates
                        return pseries(r, seq);
@@ -508,7 +508,7 @@ ex basic::series(const relational & r, int order, unsigned options) const
        }
        
        // Higher-order terms, if present
-       deriv = deriv.diff(*s);
+       deriv = deriv.diff(s);
        if (!deriv.expand().is_zero())
                seq.push_back(expair(Order(_ex1()), numeric(n)));
        return pseries(r, seq);
@@ -522,9 +522,9 @@ ex symbol::series(const relational & r, int order, unsigned options) const
        epvector seq;
        const ex point = r.rhs();
        GINAC_ASSERT(is_ex_exactly_of_type(r.lhs(),symbol));
-       const symbol *s = static_cast<symbol *>(r.lhs().bp);
+       ex s = r.lhs();
        
-       if (this->is_equal(*s)) {
+       if (this->is_equal(*s.bp)) {
                if (order > 0 && !point.is_zero())
                        seq.push_back(expair(point, _ex0()));
                if (order > 1)
@@ -680,19 +680,18 @@ ex pseries::mul_series(const pseries &other) const
        // Series multiplication
        epvector new_seq;
        
-       const symbol *s = static_cast<symbol *>(var.bp);
-       int a_max = degree(*s);
-       int b_max = other.degree(*s);
-       int a_min = ldegree(*s);
-       int b_min = other.ldegree(*s);
+       int a_max = degree(var);
+       int b_max = other.degree(var);
+       int a_min = ldegree(var);
+       int b_min = other.ldegree(var);
        int cdeg_min = a_min + b_min;
        int cdeg_max = a_max + b_max;
        
        int higher_order_a = INT_MAX;
        int higher_order_b = INT_MAX;
-       if (is_order_function(coeff(*s, a_max)))
+       if (is_order_function(coeff(var, a_max)))
                higher_order_a = a_max + b_min;
-       if (is_order_function(other.coeff(*s, b_max)))
+       if (is_order_function(other.coeff(var, b_max)))
                higher_order_b = b_max + a_min;
        int higher_order_c = std::min(higher_order_a, higher_order_b);
        if (cdeg_max >= higher_order_c)
@@ -702,8 +701,8 @@ ex pseries::mul_series(const pseries &other) const
                ex co = _ex0();
                // c(i)=a(0)b(i)+...+a(i)b(0)
                for (int i=a_min; cdeg-i>=b_min; ++i) {
-                       ex a_coeff = coeff(*s, i);
-                       ex b_coeff = other.coeff(*s, cdeg-i);
+                       ex a_coeff = coeff(var, i);
+                       ex b_coeff = other.coeff(var, cdeg-i);
                        if (!is_order_function(a_coeff) && !is_order_function(b_coeff))
                                co += a_coeff * b_coeff;
                }
@@ -712,7 +711,7 @@ ex pseries::mul_series(const pseries &other) const
        }
        if (higher_order_c < INT_MAX)
                new_seq.push_back(expair(Order(_ex1()), numeric(higher_order_c)));
-       return pseries(relational(var,point), new_seq);
+       return pseries(relational(var, point), new_seq);
 }
 
 
@@ -785,18 +784,17 @@ ex pseries::power_const(const numeric &p, int deg) const
                        return *this;
        }
        
-       const symbol *s = static_cast<symbol *>(var.bp);
-       int ldeg = ldegree(*s);
+       int ldeg = ldegree(var);
        
        // Compute coefficients of the powered series
        exvector co;
        co.reserve(deg);
-       co.push_back(power(coeff(*s, ldeg), p));
+       co.push_back(power(coeff(var, ldeg), p));
        bool all_sums_zero = true;
        for (int i=1; i<deg; ++i) {
                ex sum = _ex0();
                for (int j=1; j<=i; ++j) {
-                       ex c = coeff(*s, j + ldeg);
+                       ex c = coeff(var, j + ldeg);
                        if (is_order_function(c)) {
                                co.push_back(Order(_ex1()));
                                break;
@@ -805,7 +803,7 @@ ex pseries::power_const(const numeric &p, int deg) const
                }
                if (!sum.is_zero())
                        all_sums_zero = false;
-               co.push_back(sum / coeff(*s, ldeg) / numeric(i));
+               co.push_back(sum / coeff(var, ldeg) / numeric(i));
        }
        
        // Construct new series (of non-zero coefficients)
@@ -875,10 +873,10 @@ ex pseries::series(const relational & r, int order, unsigned options) const
 {
        const ex p = r.rhs();
        GINAC_ASSERT(is_ex_exactly_of_type(r.lhs(),symbol));
-       const symbol *s = static_cast<symbol *>(r.lhs().bp);
+       const symbol &s = static_cast<symbol &>(*r.lhs().bp);
        
-       if (var.is_equal(*s) && point.is_equal(p)) {
-               if (order > degree(*s))
+       if (var.is_equal(s) && point.is_equal(p)) {
+               if (order > degree(s))
                        return *this;
                else {
                        epvector new_seq;
index 20005473baada848c5e8306a85bd4bb450bc0639..1dd37ffda21d4e0ece86327c0ee533b7ef13f26f 100644 (file)
@@ -48,10 +48,10 @@ public:
        unsigned nops(void) const;
        ex op(int i) const;
        ex &let_op(int i);
-       int degree(const symbol &s) const;
-       int ldegree(const symbol &s) const;
-       ex coeff(const symbol &s, int n = 1) const;
-       ex collect(const symbol &s) const;
+       int degree(const ex &s) const;
+       int ldegree(const ex &s) const;
+       ex coeff(const ex &s, int n = 1) const;
+       ex collect(const ex &s) const;
        ex eval(int level=0) const;
        ex evalf(int level=0) const;
        ex series(const relational & r, int order, unsigned options = 0) const;
index 4328d19bfd59634b34e079c805dff796c2e4ab02..b905a9a9346c5f75ee871a95b49059c19717ebfa 100644 (file)
@@ -187,19 +187,19 @@ bool symbol::has(const ex & other) const
                return false;
 }
 
-int symbol::degree(const symbol & s) const
+int symbol::degree(const ex & s) const
 {
-       return compare_same_type(s)==0 ? 1 : 0;
+       return is_equal(*s.bp) ? 1 : 0;
 }
 
-int symbol::ldegree(const symbol & s) const
+int symbol::ldegree(const ex & s) const
 {
-       return compare_same_type(s)==0 ? 1 : 0;
+       return is_equal(*s.bp) ? 1 : 0;
 }
 
-ex symbol::coeff(const symbol & s, int n) const
+ex symbol::coeff(const ex & s, int n) const
 {
-       if (compare_same_type(s)==0)
+       if (is_equal(*s.bp))
                return n==1 ? _ex1() : _ex0();
        else
                return n==0 ? *this : _ex0();
index 425f85b953d427685b20975d2e74337b569f8671..16dcab0cd8b308bf027a96e6800f08d28680cadc 100644 (file)
@@ -79,9 +79,9 @@ public:
        bool info(unsigned inf) const;
        ex expand(unsigned options = 0) const;
        bool has(const ex & other) const;
-       int degree(const symbol & s) const;
-       int ldegree(const symbol & s) const;
-       ex coeff(const symbol & s, int n = 1) const;
+       int degree(const ex & s) const;
+       int ldegree(const ex & s) const;
+       ex coeff(const ex & s, int n = 1) const;
        ex eval(int level = 0) const;
        ex series(const relational & s, int order, unsigned options = 0) const;
        ex normal(lst &sym_lst, lst &repl_lst, int level = 0) const;
@@ -126,10 +126,10 @@ inline const symbol &ex_to_symbol(const ex &e)
 inline void unassign(symbol & symarg)
 { symarg.unassign(); }
 
-inline int degree(const symbol & a, const symbol & s)
+inline int degree(const symbol & a, const ex & s)
 { return a.degree(s); }
 
-inline int ldegree(const symbol & a, const symbol & s)
+inline int ldegree(const symbol & a, const ex & s)
 { return a.ldegree(s); }
 
 } // namespace GiNaC