]> www.ginac.de Git - ginac.git/blobdiff - ginac/add.cpp
pseries::expand(): do not generate zero terms.
[ginac.git] / ginac / add.cpp
index 7cb4876dbdb43d2801273b60d4a559b317bc4e87..2f227fcf595b6c76e7b832846f0d861422de9001 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's sums of expressions. */
 
 /*
- *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2001 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
@@ -47,28 +47,6 @@ add::add()
        tinfo_key = TINFO_add;
 }
 
-add::~add()
-{
-       debugmsg("add destructor",LOGLEVEL_DESTRUCT);
-       destroy(false);
-}
-
-add::add(const add & other)
-{
-       debugmsg("add copy constructor",LOGLEVEL_CONSTRUCT);
-       copy(other);
-}
-
-const add & add::operator=(const add & other)
-{
-       debugmsg("add operator=",LOGLEVEL_ASSIGNMENT);
-       if (this != &other) {
-               destroy(true);
-               copy(other);
-       }
-       return *this;
-}
-
 // protected
 
 void add::copy(const add & other)
@@ -179,12 +157,6 @@ void add::archive(archive_node &n) const
 
 // public
 
-basic * add::duplicate() const
-{
-       debugmsg("add duplicate",LOGLEVEL_DUPLICATE);
-       return new add(*this);
-}
-
 void add::print(std::ostream & os, unsigned upper_precedence) const
 {
        debugmsg("add print",LOGLEVEL_PRINT);
@@ -220,7 +192,7 @@ void add::print(std::ostream & os, unsigned upper_precedence) const
                        }
                        os << '*';
                }
-               os << cit->rest;
+               cit->rest.print(os, precedence);
        }
        if (precedence<=upper_precedence) os << ")";
 }
@@ -468,11 +440,11 @@ ex add::thisexpairseq(epvector * vp, const ex & oc) const
 expair add::split_ex_to_pair(const ex & e) const
 {
        if (is_ex_exactly_of_type(e,mul)) {
-               const mul & mulref=ex_to_mul(e);
-               ex numfactor=mulref.overall_coeff;
-               // mul * mulcopyp=static_cast<mul *>(mulref.duplicate());
-               mul * mulcopyp=new mul(mulref);
-               mulcopyp->overall_coeff=_ex1();
+               const mul & mulref = ex_to_mul(e);
+               ex numfactor = mulref.overall_coeff;
+               // mul * mulcopyp = static_cast<mul *>(mulref.duplicate());
+               mul * mulcopyp = new mul(mulref);
+               mulcopyp->overall_coeff = _ex1();
                mulcopyp->clearflag(status_flags::evaluated);
                mulcopyp->clearflag(status_flags::hash_calculated);
                return expair(mulcopyp->setflag(status_flags::dynallocated),numfactor);
@@ -484,26 +456,24 @@ expair add::combine_ex_with_coeff_to_pair(const ex & e,
                                                                                  const ex & c) const
 {
        GINAC_ASSERT(is_ex_exactly_of_type(c, numeric));
-       ex one = _ex1();
        if (is_ex_exactly_of_type(e, mul)) {
                const mul &mulref = ex_to_mul(e);
                ex numfactor = mulref.overall_coeff;
                mul *mulcopyp = new mul(mulref);
-               mulcopyp->overall_coeff = one;
+               mulcopyp->overall_coeff = _ex1();
                mulcopyp->clearflag(status_flags::evaluated);
                mulcopyp->clearflag(status_flags::hash_calculated);
                mulcopyp->setflag(status_flags::dynallocated);
-               if (are_ex_trivially_equal(c, one)) {
+               if (are_ex_trivially_equal(c, _ex1())) {
                        return expair(*mulcopyp, numfactor);
-               } else if (are_ex_trivially_equal(numfactor, one)) {
+               } else if (are_ex_trivially_equal(numfactor, _ex1())) {
                        return expair(*mulcopyp, c);
                }
                return expair(*mulcopyp, ex_to_numeric(numfactor).mul_dyn(ex_to_numeric(c)));
        } else if (is_ex_exactly_of_type(e, numeric)) {
-               if (are_ex_trivially_equal(c, one)) {
-                       return expair(e, one);
-               }
-               return expair(ex_to_numeric(e).mul_dyn(ex_to_numeric(c)), one);
+               if (are_ex_trivially_equal(c, _ex1()))
+                       return expair(e, _ex1());
+               return expair(ex_to_numeric(e).mul_dyn(ex_to_numeric(c)), _ex1());
        }
        return expair(e, c);
 }
@@ -542,18 +512,6 @@ ex add::expand(unsigned options) const
        return (new add(vp,overall_coeff))->setflag(status_flags::expanded | status_flags::dynallocated);
 }
 
-//////////
-// new virtual functions which can be overridden by derived classes
-//////////
-
-// none
-
-//////////
-// non-virtual functions in this class
-//////////
-
-// none
-
 //////////
 // static member variables
 //////////
@@ -562,13 +520,6 @@ ex add::expand(unsigned options) const
 
 unsigned add::precedence = 40;
 
-//////////
-// global constants
-//////////
-
-const add some_add;
-const std::type_info & typeid_add = typeid(some_add);
-
 #ifndef NO_NAMESPACE_GINAC
 } // namespace GiNaC
 #endif // ndef NO_NAMESPACE_GINAC