]> www.ginac.de Git - ginac.git/blobdiff - ginac/add.cpp
#ifndef around namespace GiNaC { }
[ginac.git] / ginac / add.cpp
index 0d88e329316c64b93eb5640a15983cb3ea56c43e..553b8272c4861b910e784ac6fe465512f09d9770 100644 (file)
@@ -2,10 +2,34 @@
  *
  *  Implementation of GiNaC's sums of expressions. */
 
+/*
+ *  GiNaC Copyright (C) 1999 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
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  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
+ */
+
 #include <iostream>
 #include <stdexcept>
 
-#include "ginac.h"
+#include "add.h"
+#include "mul.h"
+#include "debugmsg.h"
+
+#ifndef NO_GINAC_NAMESPACE
+namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
 
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
@@ -16,7 +40,7 @@
 add::add()
 {
     debugmsg("add default constructor",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_ADD;
+    tinfo_key = TINFO_add;
 }
 
 add::~add()
@@ -62,26 +86,26 @@ void add::destroy(bool call_parent)
 add::add(ex const & lh, ex const & rh)
 {
     debugmsg("add constructor from ex,ex",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_ADD;
+    tinfo_key = TINFO_add;
     overall_coeff=exZERO();
     construct_from_2_ex(lh,rh);
-    ASSERT(is_canonical());
+    GINAC_ASSERT(is_canonical());
 }
 
 add::add(exvector const & v)
 {
     debugmsg("add constructor from exvector",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_ADD;
+    tinfo_key = TINFO_add;
     overall_coeff=exZERO();
     construct_from_exvector(v);
-    ASSERT(is_canonical());
+    GINAC_ASSERT(is_canonical());
 }
 
 /*
 add::add(epvector const & v, bool do_not_canonicalize)
 {
     debugmsg("add constructor from epvector,bool",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_ADD;
+    tinfo_key = TINFO_add;
     if (do_not_canonicalize) {
         seq=v;
 #ifdef EXPAIRSEQ_USE_HASHTAB
@@ -90,37 +114,37 @@ add::add(epvector const & v, bool do_not_canonicalize)
     } else {
         construct_from_epvector(v);
     }
-    ASSERT(is_canonical());
+    GINAC_ASSERT(is_canonical());
 }
 */
 
 add::add(epvector const & v)
 {
     debugmsg("add constructor from epvector",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_ADD;
+    tinfo_key = TINFO_add;
     overall_coeff=exZERO();
     construct_from_epvector(v);
-    ASSERT(is_canonical());
+    GINAC_ASSERT(is_canonical());
 }
 
 add::add(epvector const & v, ex const & oc)
 {
     debugmsg("add constructor from epvector,ex",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_ADD;
+    tinfo_key = TINFO_add;
     overall_coeff=oc;
     construct_from_epvector(v);
-    ASSERT(is_canonical());
+    GINAC_ASSERT(is_canonical());
 }
 
 add::add(epvector * vp, ex const & oc)
 {
     debugmsg("add constructor from epvector *,ex",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_ADD;
-    ASSERT(vp!=0);
+    tinfo_key = TINFO_add;
+    GINAC_ASSERT(vp!=0);
     overall_coeff=oc;
     construct_from_epvector(*vp);
     delete vp;
-    ASSERT(is_canonical());
+    GINAC_ASSERT(is_canonical());
 }
 
 //////////
@@ -254,13 +278,13 @@ ex add::eval(int level) const
     debugmsg("add eval",LOGLEVEL_MEMBER_FUNCTION);
 
     if ((level==1)&&(flags & status_flags::evaluated)) {
-#ifdef DOASSERT
+#ifdef DO_GINAC_ASSERT
         for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
-            ASSERT(!is_ex_exactly_of_type((*cit).rest,add));
-            ASSERT(!(is_ex_exactly_of_type((*cit).rest,numeric)&&
+            GINAC_ASSERT(!is_ex_exactly_of_type((*cit).rest,add));
+            GINAC_ASSERT(!(is_ex_exactly_of_type((*cit).rest,numeric)&&
                      (ex_to_numeric((*cit).coeff).compare(numONE())!=0)));
         }
-#endif // def DOASSERT
+#endif // def DO_GINAC_ASSERT
         return *this;
     }
 
@@ -274,13 +298,13 @@ ex add::eval(int level) const
         return (new add(evaled_seqp))->setflag(status_flags::dynallocated);
     }
 
-#ifdef DOASSERT
+#ifdef DO_GINAC_ASSERT
     for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
-        ASSERT(!is_ex_exactly_of_type((*cit).rest,add));
-        ASSERT(!(is_ex_exactly_of_type((*cit).rest,numeric)&&
+        GINAC_ASSERT(!is_ex_exactly_of_type((*cit).rest,add));
+        GINAC_ASSERT(!(is_ex_exactly_of_type((*cit).rest,numeric)&&
                  (ex_to_numeric((*cit).coeff).compare(numONE())!=0)));
     }
-#endif // def DOASSERT
+#endif // def DO_GINAC_ASSERT
 
     if (flags & status_flags::evaluated) {
         return *this;
@@ -372,19 +396,19 @@ ex add::eval(int level) const
                    setflag(status_flags::dynallocated);
     }
 
-#ifdef DOASSERT
+#ifdef DO_GINAC_ASSERT
     for (epvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
-        ASSERT(!is_ex_exactly_of_type((*cit).rest,add));
+        GINAC_ASSERT(!is_ex_exactly_of_type((*cit).rest,add));
         if (is_ex_exactly_of_type((*cit).rest,numeric)) {
             dbgprint();
         }
-        ASSERT(!is_ex_exactly_of_type((*cit).rest,numeric));
+        GINAC_ASSERT(!is_ex_exactly_of_type((*cit).rest,numeric));
     }
-#endif // def DOASSERT
+#endif // def DO_GINAC_ASSERT
 
     if (flags & status_flags::evaluated) {
-        ASSERT(seq.size()>0);
-        ASSERT((seq.size()>1)||!overall_coeff.is_equal(exZERO()));
+        GINAC_ASSERT(seq.size()>0);
+        GINAC_ASSERT((seq.size()>1)||!overall_coeff.is_equal(exZERO()));
         return *this;
     }
 
@@ -401,9 +425,9 @@ ex add::eval(int level) const
 
 exvector add::get_indices(void) const
 {
-    // all terms in the sum should have the same indices (compatible tensors)
-    // however this is not checked, since there is no function yet which
-    // compares indices (idxvector can be unsorted) !!!!!!!!!!!
+    // FIXME: all terms in the sum should have the same indices (compatible
+    // tensors) however this is not checked, since there is no function yet
+    // which compares indices (idxvector can be unsorted)
     if (seq.size()==0) {
         return exvector();
     }
@@ -461,7 +485,7 @@ expair add::split_ex_to_pair(ex const & e) const
 {
     if (is_ex_exactly_of_type(e,mul)) {
         mul const & mulref=ex_to_mul(e);
-        ASSERT(mulref.seq.size()>1);
+        GINAC_ASSERT(mulref.seq.size()>1);
         ex const & lastfactor_rest=(*(mulref.seq.end()-1)).rest;
         ex const & lastfactor_coeff=(*(mulref.seq.end()-1)).coeff;
         if (is_ex_exactly_of_type(lastfactor_rest,numeric) &&
@@ -506,10 +530,10 @@ expair add::split_ex_to_pair(ex const & e) const
 expair add::combine_ex_with_coeff_to_pair(ex const & e,
                                           ex const & c) const
 {
-    ASSERT(is_ex_exactly_of_type(c,numeric));
+    GINAC_ASSERT(is_ex_exactly_of_type(c,numeric));
     if (is_ex_exactly_of_type(e,mul)) {
         mul const & mulref=ex_to_mul(e);
-        ASSERT(mulref.seq.size()>1);
+        GINAC_ASSERT(mulref.seq.size()>1);
         ex const & lastfactor_rest=(*(mulref.seq.end()-1)).rest;
         ex const & lastfactor_coeff=(*(mulref.seq.end()-1)).coeff;
         if (is_ex_exactly_of_type(lastfactor_rest,numeric) &&
@@ -544,7 +568,7 @@ expair add::combine_ex_with_coeff_to_pair(ex const & e,
 expair add::combine_ex_with_coeff_to_pair(ex const & e,
                                           ex const & c) const
 {
-    ASSERT(is_ex_exactly_of_type(c,numeric));
+    GINAC_ASSERT(is_ex_exactly_of_type(c,numeric));
     if (is_ex_exactly_of_type(e,mul)) {
         mul const & mulref=ex_to_mul(e);
         ex numfactor=mulref.overall_coeff;
@@ -572,11 +596,11 @@ expair add::combine_ex_with_coeff_to_pair(ex const & e,
 expair add::combine_pair_with_coeff_to_pair(expair const & p,
                                             ex const & c) const
 {
-    ASSERT(is_ex_exactly_of_type(p.coeff,numeric));
-    ASSERT(is_ex_exactly_of_type(c,numeric));
+    GINAC_ASSERT(is_ex_exactly_of_type(p.coeff,numeric));
+    GINAC_ASSERT(is_ex_exactly_of_type(c,numeric));
 
     if (is_ex_exactly_of_type(p.rest,numeric)) {
-        ASSERT(ex_to_numeric(p.coeff).is_equal(numONE())); // should be normalized
+        GINAC_ASSERT(ex_to_numeric(p.coeff).is_equal(numONE())); // should be normalized
         return expair(ex_to_numeric(p.rest).mul_dyn(ex_to_numeric(c)),exONE());
     }
 
@@ -631,5 +655,6 @@ unsigned add::precedence=40;
 const add some_add;
 type_info const & typeid_add=typeid(some_add);
 
-
-
+#ifndef NO_GINAC_NAMESPACE
+} // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE