]> www.ginac.de Git - ginac.git/blobdiff - ginac/mul.cpp
#ifndef around namespace GiNaC { }
[ginac.git] / ginac / mul.cpp
index ef0af1b732cb785f3292acf2fb112201a076d28a..9155b1a93a17f1f842e6c2fb470a1314be63d28e 100644 (file)
@@ -1,7 +1,8 @@
 /** @file mul.cpp
  *
- *  Implementation of GiNaC's products of expressions.
- *
+ *  Implementation of GiNaC's products of expressions. */
+
+/*
  *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
 #include <vector>
 #include <stdexcept>
 
-#include "ginac.h"
+#include "mul.h"
+#include "add.h"
+#include "power.h"
+#include "debugmsg.h"
+
+#ifndef NO_GINAC_NAMESPACE
+namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
 
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
@@ -33,7 +41,7 @@
 mul::mul()
 {
     debugmsg("mul default constructor",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_MUL;
+    tinfo_key = TINFO_mul;
 }
 
 mul::~mul()
@@ -79,26 +87,26 @@ void mul::destroy(bool call_parent)
 mul::mul(ex const & lh, ex const & rh)
 {
     debugmsg("mul constructor from ex,ex",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_MUL;
+    tinfo_key = TINFO_mul;
     overall_coeff=exONE();
     construct_from_2_ex(lh,rh);
-    ASSERT(is_canonical());
+    GINAC_ASSERT(is_canonical());
 }
 
 mul::mul(exvector const & v)
 {
     debugmsg("mul constructor from exvector",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_MUL;
+    tinfo_key = TINFO_mul;
     overall_coeff=exONE();
     construct_from_exvector(v);
-    ASSERT(is_canonical());
+    GINAC_ASSERT(is_canonical());
 }
 
 /*
 mul::mul(epvector const & v, bool do_not_canonicalize)
 {
     debugmsg("mul constructor from epvector,bool",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_MUL;
+    tinfo_key = TINFO_mul;
     if (do_not_canonicalize) {
         seq=v;
 #ifdef EXPAIRSEQ_USE_HASHTAB
@@ -107,43 +115,43 @@ mul::mul(epvector const & v, bool do_not_canonicalize)
     } else {
         construct_from_epvector(v);
     }
-    ASSERT(is_canonical());
+    GINAC_ASSERT(is_canonical());
 }
 */
 
 mul::mul(epvector const & v)
 {
     debugmsg("mul constructor from epvector",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_MUL;
+    tinfo_key = TINFO_mul;
     overall_coeff=exONE();
     construct_from_epvector(v);
-    ASSERT(is_canonical());
+    GINAC_ASSERT(is_canonical());
 }
 
 mul::mul(epvector const & v, ex const & oc)
 {
     debugmsg("mul constructor from epvector,ex",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_MUL;
+    tinfo_key = TINFO_mul;
     overall_coeff=oc;
     construct_from_epvector(v);
-    ASSERT(is_canonical());
+    GINAC_ASSERT(is_canonical());
 }
 
 mul::mul(epvector * vp, ex const & oc)
 {
     debugmsg("mul constructor from epvector *,ex",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_MUL;
-    ASSERT(vp!=0);
+    tinfo_key = TINFO_mul;
+    GINAC_ASSERT(vp!=0);
     overall_coeff=oc;
     construct_from_epvector(*vp);
     delete vp;
-    ASSERT(is_canonical());
+    GINAC_ASSERT(is_canonical());
 }
 
 mul::mul(ex const & lh, ex const & mh, ex const & rh)
 {
     debugmsg("mul constructor from ex,ex,ex",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_MUL;
+    tinfo_key = TINFO_mul;
     exvector factors;
     factors.reserve(3);
     factors.push_back(lh);
@@ -151,7 +159,7 @@ mul::mul(ex const & lh, ex const & mh, ex const & rh)
     factors.push_back(rh);
     overall_coeff=exONE();
     construct_from_exvector(factors);
-    ASSERT(is_canonical());
+    GINAC_ASSERT(is_canonical());
 }
 
 //////////
@@ -251,9 +259,9 @@ ex mul::eval(int level) const
     debugmsg("mul 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,mul))||
+            GINAC_ASSERT((!is_ex_exactly_of_type((*cit).rest,mul))||
                    (!(ex_to_numeric((*cit).coeff).is_integer())));
         }
 
@@ -266,9 +274,9 @@ ex mul::eval(int level) const
             do {
                 cit--;
                 if (is_ex_exactly_of_type((*cit).rest,numeric)) {
-                    ASSERT(all_numeric);
+                    GINAC_ASSERT(all_numeric);
                     if ((*cit).coeff.is_equal(exONE())) {
-                        ASSERT(all_coeff_1);
+                        GINAC_ASSERT(all_coeff_1);
                     } else {
                         all_coeff_1=false;
                     }
@@ -277,7 +285,7 @@ ex mul::eval(int level) const
                 }
             } while (cit!=seq.begin());
         }
-#endif // def DOASSERT    
+#endif // def DO_GINAC_ASSERT    
         return *this;
     }
 
@@ -315,9 +323,9 @@ ex mul::eval(int level) const
     }
     
     
-#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,mul))||
+        GINAC_ASSERT((!is_ex_exactly_of_type((*cit).rest,mul))||
                (!(ex_to_numeric((*cit).coeff).is_integer())));
     }
 
@@ -330,9 +338,9 @@ ex mul::eval(int level) const
         do {
             cit--;
             if (is_ex_exactly_of_type((*cit).rest,numeric)) {
-                ASSERT(all_numeric);
+                GINAC_ASSERT(all_numeric);
                 if ((*cit).coeff.is_equal(exONE())) {
-                    ASSERT(all_coeff_1);
+                    GINAC_ASSERT(all_coeff_1);
                 } else {
                     all_coeff_1=false;
                 }
@@ -341,7 +349,7 @@ ex mul::eval(int level) const
             }
         } while (cit!=seq.begin());
     }
-#endif // def DOASSERT
+#endif // def DO_GINAC_ASSERT
     
     if (flags & status_flags::evaluated) {
         return *this;
@@ -475,26 +483,26 @@ ex mul::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,mul))||
+        GINAC_ASSERT((!is_ex_exactly_of_type((*cit).rest,mul))||
                (!(ex_to_numeric((*cit).coeff).is_integer())));
-        ASSERT(!((*cit).is_numeric_with_coeff_1()));
+        GINAC_ASSERT(!((*cit).is_numeric_with_coeff_1()));
         if (is_ex_exactly_of_type(recombine_pair_to_ex(*cit),numeric)) {
             printtree(cerr,0);
         }
-        ASSERT(!is_ex_exactly_of_type(recombine_pair_to_ex(*cit),numeric));
+        GINAC_ASSERT(!is_ex_exactly_of_type(recombine_pair_to_ex(*cit),numeric));
         /* for paranoia */
         expair p=split_ex_to_pair(recombine_pair_to_ex(*cit));
-        ASSERT(p.rest.is_equal((*cit).rest));
-        ASSERT(p.coeff.is_equal((*cit).coeff));
+        GINAC_ASSERT(p.rest.is_equal((*cit).rest));
+        GINAC_ASSERT(p.coeff.is_equal((*cit).coeff));
         /* end paranoia */
     }
-#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(exONE()));
+        GINAC_ASSERT(seq.size()>0);
+        GINAC_ASSERT((seq.size()>1)||!overall_coeff.is_equal(exONE()));
         return *this;
     }
 
@@ -767,23 +775,23 @@ ex mul::default_overall_coeff(void) const
 
 void mul::combine_overall_coeff(ex const & c)
 {
-    ASSERT(is_ex_exactly_of_type(overall_coeff,numeric));
-    ASSERT(is_ex_exactly_of_type(c,numeric));
+    GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric));
+    GINAC_ASSERT(is_ex_exactly_of_type(c,numeric));
     overall_coeff = ex_to_numeric(overall_coeff).mul_dyn(ex_to_numeric(c));
 }
 
 void mul::combine_overall_coeff(ex const & c1, ex const & c2)
 {
-    ASSERT(is_ex_exactly_of_type(overall_coeff,numeric));
-    ASSERT(is_ex_exactly_of_type(c1,numeric));
-    ASSERT(is_ex_exactly_of_type(c2,numeric));
+    GINAC_ASSERT(is_ex_exactly_of_type(overall_coeff,numeric));
+    GINAC_ASSERT(is_ex_exactly_of_type(c1,numeric));
+    GINAC_ASSERT(is_ex_exactly_of_type(c2,numeric));
     overall_coeff = ex_to_numeric(overall_coeff).
                         mul_dyn(ex_to_numeric(c1).power(ex_to_numeric(c2)));
 }
 
 bool mul::can_make_flat(expair const & p) const
 {
-    ASSERT(is_ex_exactly_of_type(p.coeff,numeric));
+    GINAC_ASSERT(is_ex_exactly_of_type(p.coeff,numeric));
     // this assertion will probably fail somewhere
     // it would require a more careful make_flat, obeying the power laws
     // probably should return true only if p.coeff is integer
@@ -846,7 +854,7 @@ ex mul::expand(unsigned options) const
         term=expanded_seq;
         for (l=0; l<number_of_adds; l++) {
             add const & addref=ex_to_add(expanded_seq[positions_of_adds[l]].rest);
-            ASSERT(term[positions_of_adds[l]].coeff.compare(exONE())==0);
+            GINAC_ASSERT(term[positions_of_adds[l]].coeff.compare(exONE())==0);
             term[positions_of_adds[l]]=split_ex_to_pair(addref.op(k[l]));
         }
         /*
@@ -1008,4 +1016,6 @@ unsigned mul::precedence=50;
 const mul some_mul;
 type_info const & typeid_mul=typeid(some_mul);
 
-
+#ifndef NO_GINAC_NAMESPACE
+} // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE