]> www.ginac.de Git - ginac.git/commitdiff
- (l)degree(s), coeff(s, n) and collect(s) were extended to accept expressions
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Fri, 25 Jan 2002 18:33:01 +0000 (18:33 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Fri, 25 Jan 2002 18:33:01 +0000 (18:33 +0000)
  of any class (except add/mul/ncmul/numeric) for "s". They should even work
  if "s" is a "power" object, as long as the exponent is non-integer, but with
  some limitations. For example, you can "collect(a*2^x+b*2^x, 2^x)" to get
  "(a+b)*2^x", but "degree(2^(3*x), 2^x)" yields 0 instead of 3).

12 files changed:
NEWS
ginac/basic.cpp
ginac/constant.cpp
ginac/constant.h
ginac/function.pl
ginac/indexed.cpp
ginac/indexed.h
ginac/numeric.cpp
ginac/numeric.h
ginac/power.cpp
ginac/symbol.cpp
ginac/symbol.h

diff --git a/NEWS b/NEWS
index b5a706a9ae46c44fc0b09f82e7293cb24ee829f8..bd43d5aac8702437597645e1431a55641ec3a298 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,12 @@
 This file records noteworthy changes.
 
 This file records noteworthy changes.
 
+1.0.5 (<date>)
+* (l)degree(s), coeff(s, n) and collect(s) were extended to accept expressions
+  of any class (except add/mul/ncmul/numeric) for "s". They should even work
+  if "s" is a "power" object, as long as the exponent is non-integer, but with
+  some limitations. For example, you can "collect(a*2^x+b*2^x, 2^x)" to get
+  "(a+b)*2^x", but "degree(2^(3*x), 2^x)" yields 0 instead of 3).
+
 1.0.4 (24 January 2001)
 * Speedup in expand().
 * Faster Bernoulli numbers (Markus Nullmeier).
 1.0.4 (24 January 2001)
 * Speedup in expand().
 * Faster Bernoulli numbers (Markus Nullmeier).
index d77e7dc44fe3838f6e8c65765faa19fd583b8dd4..fb73096fa70a4796e301ade46306d53849d25068 100644 (file)
@@ -236,19 +236,22 @@ ex basic::map(map_function & f) const
 /** Return degree of highest power in object s. */
 int basic::degree(const ex & s) const
 {
 /** Return degree of highest power in object s. */
 int basic::degree(const ex & s) const
 {
-       return 0;
+       return is_equal(ex_to<basic>(s)) ? 1 : 0;
 }
 
 /** Return degree of lowest power in object s. */
 int basic::ldegree(const ex & s) const
 {
 }
 
 /** Return degree of lowest power in object s. */
 int basic::ldegree(const ex & s) const
 {
-       return 0;
+       return is_equal(ex_to<basic>(s)) ? 1 : 0;
 }
 
 /** Return coefficient of degree n in object s. */
 ex basic::coeff(const ex & s, int n) const
 {
 }
 
 /** Return coefficient of degree n in object s. */
 ex basic::coeff(const ex & s, int n) const
 {
-       return n==0 ? *this : _ex0;
+       if (is_equal(ex_to<basic>(s)))
+               return n==1 ? _ex1 : _ex0;
+       else
+               return n==0 ? *this : _ex0;
 }
 
 /** Sort expanded expression in terms of powers of some object(s).
 }
 
 /** Sort expanded expression in terms of powers of some object(s).
index 371902bdebdbe1cd5a3badb8310ab59ffea1a62c..5ba8475108af93ef8ccf90ff4fc5afb4fb747fc3 100644 (file)
@@ -145,24 +145,6 @@ void constant::print(const print_context & c, unsigned level) const
                c.s << name;
 }
 
                c.s << name;
 }
 
-int constant::degree(const ex & s) const
-{
-       return is_equal(ex_to<basic>(s)) ? 1 : 0;
-}
-
-int constant::ldegree(const ex & s) const
-{
-       return is_equal(ex_to<basic>(s)) ? 1 : 0;
-}
-
-ex constant::coeff(const ex & s, int n) const
-{
-       if (is_equal(ex_to<basic>(s)))
-               return n==1 ? _ex1 : _ex0;
-       else
-               return n==0 ? *this : _ex0;
-}
-
 ex constant::evalf(int level) const
 {
        if (ef!=0) {
 ex constant::evalf(int level) const
 {
        if (ef!=0) {
index 5ffe6200b2dfae88d9548501e1414885135226b6..6f3aa0fa1786bc4e924a46f3782d034a9bafa65a 100644 (file)
@@ -49,9 +49,6 @@ public:
        // functions overriding virtual functions from base classes
 public:
        void print(const print_context & c, unsigned level = 0) const;
        // functions overriding virtual functions from base classes
 public:
        void print(const print_context & c, unsigned level = 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;
        ex evalf(int level = 0) const;
 protected:
        ex derivative(const symbol & s) const;
index b827216f5db9c1bfdc710fdcd3f250fbcfc60899..ba1b02ae08a2c014f953189a91b4dc62f42b01eb 100755 (executable)
@@ -320,9 +320,6 @@ $constructors_interface
 public:
        void print(const print_context & c, unsigned level = 0) const;
        unsigned precedence(void) const {return 70;}
 public:
        void print(const print_context & c, unsigned level = 0) const;
        unsigned precedence(void) const {return 70;}
-       int degree(const ex & s) const;
-       int ldegree(const ex & s) const;
-       ex coeff(const ex & s, int n = 1) const;
        ex expand(unsigned options=0) const;
        ex eval(int level=0) const;
        ex evalf(int level=0) const;
        ex expand(unsigned options=0) const;
        ex eval(int level=0) const;
        ex evalf(int level=0) const;
@@ -719,24 +716,6 @@ ex function::expand(unsigned options) const
                return (options == 0) ? setflag(status_flags::expanded) : *this;
 }
 
                return (options == 0) ? setflag(status_flags::expanded) : *this;
 }
 
-int function::degree(const ex & s) const
-{
-       return is_equal(ex_to<basic>(s)) ? 1 : 0;
-}
-
-int function::ldegree(const ex & s) const
-{
-       return is_equal(ex_to<basic>(s)) ? 1 : 0;
-}
-
-ex function::coeff(const ex & s, int n) const
-{
-       if (is_equal(ex_to<basic>(s)))
-               return n==1 ? _ex1 : _ex0;
-       else
-               return n==0 ? ex(*this) : _ex0;
-}
-
 ex function::eval(int level) const
 {
        GINAC_ASSERT(serial<registered_functions().size());
 ex function::eval(int level) const
 {
        GINAC_ASSERT(serial<registered_functions().size());
index b852416f5a9f8edcaf38cf659002a97267694fc4..6c2683c30b715e4640cc090a660f6068d9e780e5 100644 (file)
@@ -274,24 +274,6 @@ ex indexed::eval(int level) const
        return ex_to<basic>(base).eval_indexed(*this);
 }
 
        return ex_to<basic>(base).eval_indexed(*this);
 }
 
-int indexed::degree(const ex & s) const
-{
-       return is_equal(ex_to<basic>(s)) ? 1 : 0;
-}
-
-int indexed::ldegree(const ex & s) const
-{
-       return is_equal(ex_to<basic>(s)) ? 1 : 0;
-}
-
-ex indexed::coeff(const ex & s, int n) const
-{
-       if (is_equal(ex_to<basic>(s)))
-               return n==1 ? _ex1 : _ex0;
-       else
-               return n==0 ? ex(*this) : _ex0;
-}
-
 ex indexed::thisexprseq(const exvector & v) const
 {
        return indexed(ex_to<symmetry>(symtree), v);
 ex indexed::thisexprseq(const exvector & v) const
 {
        return indexed(ex_to<symmetry>(symtree), v);
index 3f1b655e90db5d776fe0bd0cb789d0bf0c25012b..58c8bbd4ce16bda7ad563a7c3fb987610ed11317 100644 (file)
@@ -145,9 +145,6 @@ public:
        void print(const print_context & c, unsigned level = 0) const;
        bool info(unsigned inf) const;
        ex eval(int level = 0) const;
        void print(const print_context & c, unsigned level = 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:
        exvector get_free_indices(void) const;
 
 protected:
index 986070b71ad26bd57c8e9c21683593332c84c869..f2a834d2ff76527fd7d3ef7cfa74676711ac6d3c 100644 (file)
@@ -498,6 +498,21 @@ bool numeric::info(unsigned inf) const
        return false;
 }
 
        return false;
 }
 
+int numeric::degree(const ex & s) const
+{
+       return 0;
+}
+
+int numeric::ldegree(const ex & s) const
+{
+       return 0;
+}
+
+ex numeric::coeff(const ex & s, int n) const
+{
+       return n==0 ? *this : _ex0;
+}
+
 /** Disassemble real part and imaginary part to scan for the occurrence of a
  *  single number.  Also handles the imaginary unit.  It ignores the sign on
  *  both this and the argument, which may lead to what might appear as funny
 /** Disassemble real part and imaginary part to scan for the occurrence of a
  *  single number.  Also handles the imaginary unit.  It ignores the sign on
  *  both this and the argument, which may lead to what might appear as funny
index 8f7a83ede8012b65a8ba4e0ac3c412e009f07ae1..3c7dba2c37aee6b178a978bd5088bed3b104aa7a 100644 (file)
@@ -85,6 +85,9 @@ public:
        void print(const print_context & c, unsigned level = 0) const;
        unsigned precedence(void) const {return 30;}
        bool info(unsigned inf) const;
        void print(const print_context & c, unsigned level = 0) const;
        unsigned precedence(void) const {return 30;}
        bool info(unsigned inf) const;
+       int degree(const ex & s) const;
+       int ldegree(const ex & s) const;
+       ex coeff(const ex & s, int n = 1) const;
        bool has(const ex &other) const;
        ex eval(int level = 0) const;
        ex evalf(int level = 0) const;
        bool has(const ex &other) const;
        ex eval(int level = 0) const;
        ex evalf(int level = 0) const;
index 834b3afd4abb53a23f1b4c9d8ce80ec82c518ea4..4c7519ec9c3b75866896555dbf7bfdd5cbd2c046 100644 (file)
@@ -244,7 +244,9 @@ ex power::map(map_function & f) const
 
 int power::degree(const ex & s) 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
                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 
 {
 
 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
                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
 {
 
 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;
                // basis not equal to s
                if (n == 0)
                        return *this;
index f566e233ae529efec70fae37bf68073cfb167088..94d01e4cfe8cefb74f302182c27f7cb511e6cef5 100644 (file)
@@ -176,24 +176,6 @@ bool symbol::info(unsigned inf) const
                return inherited::info(inf);
 }
 
                return inherited::info(inf);
 }
 
-int symbol::degree(const ex & s) const
-{
-       return is_equal(ex_to<basic>(s)) ? 1 : 0;
-}
-
-int symbol::ldegree(const ex & s) const
-{
-       return is_equal(ex_to<basic>(s)) ? 1 : 0;
-}
-
-ex symbol::coeff(const ex & s, int n) const
-{
-       if (is_equal(ex_to<basic>(s)))
-               return n==1 ? _ex1 : _ex0;
-       else
-               return n==0 ? *this : _ex0;
-}
-
 ex symbol::eval(int level) const
 {
        if (level == -max_recursion_level)
 ex symbol::eval(int level) const
 {
        if (level == -max_recursion_level)
index bf83c36c667db118bd86116a3f33a1a90cb042f7..7c96312cf8aec70f7c0ac8141b603966e1db55d7 100644 (file)
@@ -71,9 +71,6 @@ public:
        basic * duplicate() const;
        void print(const print_context & c, unsigned level = 0) const;
        bool info(unsigned inf) const;
        basic * duplicate() const;
        void print(const print_context & c, unsigned level = 0) const;
        bool info(unsigned inf) 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 { return *this; } // overwrites basic::evalf() for performance reasons
        ex series(const relational & s, int order, unsigned options = 0) const;
        ex eval(int level = 0) const;
        ex evalf(int level = 0) const { return *this; } // overwrites basic::evalf() for performance reasons
        ex series(const relational & s, int order, unsigned options = 0) const;