From: Christian Bauer Date: Thu, 5 Apr 2001 00:37:46 +0000 (+0000) Subject: degree(), ldegree(), coeff(), tcoeff(), lcoeff() and collect() work with X-Git-Tag: release_0-8-1~32 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=72c6a645189bbeacc565968753c15885f6c6829f degree(), ldegree(), coeff(), tcoeff(), lcoeff() and collect() work with functions (you can collect by powers of sin(x) etc.) --- diff --git a/ginac/function.pl b/ginac/function.pl index ae9c832f..b36df872 100755 --- a/ginac/function.pl +++ b/ginac/function.pl @@ -337,6 +337,9 @@ public: void print(std::ostream & os, unsigned upper_precedence=0) 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 expand(unsigned options=0) const; ex eval(int level=0) const; ex evalf(int level=0) const; @@ -708,6 +711,24 @@ ex function::expand(unsigned options) const return this->setflag(status_flags::expanded); } +int function::degree(const ex & s) const +{ + return is_equal(*s.bp) ? 1 : 0; +} + +int function::ldegree(const ex & s) const +{ + return is_equal(*s.bp) ? 1 : 0; +} + +ex function::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 function::eval(int level) const { GINAC_ASSERT(serial