]> www.ginac.de Git - ginac.git/blobdiff - ginac/pseries.cpp
Print -x as -x instead of -1.0*x when printing C-source.
[ginac.git] / ginac / pseries.cpp
index bc04b1868a73663ff0dd3983df25a521133c9798..14488ba71c222b81e033379d51f61be66e94b062 100644 (file)
@@ -4,7 +4,7 @@
  *  methods for series expansion. */
 
 /*
- *  GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2006 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
@@ -18,7 +18,7 @@
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 #include <numeric>
@@ -51,7 +51,7 @@ GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(pseries, basic,
  *  Default constructor
  */
 
-pseries::pseries() : inherited(TINFO_pseries) { }
+pseries::pseries() : inherited(&pseries::tinfo_static) { }
 
 
 /*
@@ -67,7 +67,7 @@ pseries::pseries() : inherited(TINFO_pseries) { }
  *  @param rel_  expansion variable and point (must hold a relational)
  *  @param ops_  vector of {coefficient, power} pairs (coefficient must not be zero)
  *  @return newly constructed pseries */
-pseries::pseries(const ex &rel_, const epvector &ops_) : basic(TINFO_pseries), seq(ops_)
+pseries::pseries(const ex &rel_, const epvector &ops_) : basic(&pseries::tinfo_static), seq(ops_)
 {
        GINAC_ASSERT(is_a<relational>(rel_));
        GINAC_ASSERT(is_a<symbol>(rel_.lhs()));
@@ -412,21 +412,53 @@ ex pseries::evalf(int level) const
 
 ex pseries::conjugate() const
 {
+       if(!var.info(info_flags::real))
+               return conjugate_function(*this).hold();
+
        epvector * newseq = conjugateepvector(seq);
-       ex newvar = var.conjugate();
        ex newpoint = point.conjugate();
 
-       if (!newseq     && are_ex_trivially_equal(newvar, var) && are_ex_trivially_equal(point, newpoint)) {
+       if (!newseq     && are_ex_trivially_equal(point, newpoint)) {
                return *this;
        }
 
-       ex result = (new pseries(newvar==newpoint, newseq ? *newseq : seq))->setflag(status_flags::dynallocated);
+       ex result = (new pseries(var==newpoint, newseq ? *newseq : seq))->setflag(status_flags::dynallocated);
        if (newseq) {
                delete newseq;
        }
        return result;
 }
 
+ex pseries::real_part() const
+{
+       if(!var.info(info_flags::real))
+               return real_part_function(*this).hold();
+       ex newpoint = point.real_part();
+       if(newpoint != point)
+               return real_part_function(*this).hold();
+
+       epvector v;
+       v.reserve(seq.size());
+       for(epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i)
+               v.push_back(expair((i->rest).real_part(), i->coeff));
+       return (new pseries(var==point, v))->setflag(status_flags::dynallocated);
+}
+
+ex pseries::imag_part() const
+{
+       if(!var.info(info_flags::real))
+               return imag_part_function(*this).hold();
+       ex newpoint = point.real_part();
+       if(newpoint != point)
+               return imag_part_function(*this).hold();
+
+       epvector v;
+       v.reserve(seq.size());
+       for(epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i)
+               v.push_back(expair((i->rest).imag_part(), i->coeff));
+       return (new pseries(var==point, v))->setflag(status_flags::dynallocated);
+}
+
 ex pseries::eval_integ() const
 {
        epvector *newseq = NULL;
@@ -1100,12 +1132,12 @@ ex integral::series(const relational & r, int order, unsigned options) const
        fexpansion.reserve(fseries.nops());
        for (size_t i=0; i<fseries.nops(); ++i) {
                ex currcoeff = ex_to<pseries>(fseries).coeffop(i);
-               fexpansion.push_back(expair(
-                       currcoeff == Order(_ex1)
-                               ? currcoeff
-                               : integral(x, a.subs(r), b.subs(r), currcoeff),
-                       ex_to<pseries>(fseries).exponop(i)
-               ));
+               currcoeff = (currcoeff == Order(_ex1))
+                       ? currcoeff
+                       : integral(x, a.subs(r), b.subs(r), currcoeff);
+               if (currcoeff != 0)
+                       fexpansion.push_back(
+                               expair(currcoeff, ex_to<pseries>(fseries).exponop(i)));
        }
 
        // Expanding lower boundary
@@ -1118,7 +1150,7 @@ ex integral::series(const relational & r, int order, unsigned options) const
                        break;
                ex currexpon = ex_to<pseries>(fseries).exponop(i);
                int orderforf = order-ex_to<numeric>(currexpon).to_int()-1;
-               currcoeff=currcoeff.series(r, orderforf);
+               currcoeff = currcoeff.series(r, orderforf);
                ex term = ex_to<pseries>(aseries).power_const(ex_to<numeric>(currexpon+1),order);
                term = ex_to<pseries>(term).mul_const(ex_to<numeric>(-1/(currexpon+1)));
                term = ex_to<pseries>(term).mul_series(ex_to<pseries>(currcoeff));
@@ -1134,7 +1166,7 @@ ex integral::series(const relational & r, int order, unsigned options) const
                        break;
                ex currexpon = ex_to<pseries>(fseries).exponop(i);
                int orderforf = order-ex_to<numeric>(currexpon).to_int()-1;
-               currcoeff=currcoeff.series(r, orderforf);
+               currcoeff = currcoeff.series(r, orderforf);
                ex term = ex_to<pseries>(bseries).power_const(ex_to<numeric>(currexpon+1),order);
                term = ex_to<pseries>(term).mul_const(ex_to<numeric>(1/(currexpon+1)));
                term = ex_to<pseries>(term).mul_series(ex_to<pseries>(currcoeff));