]> www.ginac.de Git - ginac.git/blobdiff - ginac/ncmul.cpp
- Banned exZERO(), exONE(), exMINUSHALF() and all this from the interface.
[ginac.git] / ginac / ncmul.cpp
index 560f7151c26a069835bb2bb08ee0d5284436598b..5dce23f41fe5df2a27834798e33024f1c08a9fcd 100644 (file)
@@ -2,11 +2,38 @@
  *
  *  Implementation of GiNaC's non-commutative products of expressions. */
 
  *
  *  Implementation of GiNaC's non-commutative products 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 <algorithm>
 #include <iostream>
 #include <stdexcept>
 
 #include <algorithm>
 #include <iostream>
 #include <stdexcept>
 
-#include "ginac.h"
+#include "ncmul.h"
+#include "ex.h"
+#include "add.h"
+#include "mul.h"
+#include "debugmsg.h"
+#include "utils.h"
+
+#ifndef NO_GINAC_NAMESPACE
+namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
 
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
 
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
@@ -17,7 +44,7 @@
 ncmul::ncmul()
 {
     debugmsg("ncmul default constructor",LOGLEVEL_CONSTRUCT);
 ncmul::ncmul()
 {
     debugmsg("ncmul default constructor",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_NCMUL;
+    tinfo_key = TINFO_ncmul;
 }
 
 ncmul::~ncmul()
 }
 
 ncmul::~ncmul()
@@ -64,28 +91,28 @@ ncmul::ncmul(ex const & lh, ex const & rh) :
     exprseq(lh,rh)
 {
     debugmsg("ncmul constructor from ex,ex",LOGLEVEL_CONSTRUCT);
     exprseq(lh,rh)
 {
     debugmsg("ncmul constructor from ex,ex",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_NCMUL;
+    tinfo_key = TINFO_ncmul;
 }
 
 ncmul::ncmul(ex const & f1, ex const & f2, ex const & f3) :
     exprseq(f1,f2,f3)
 {
     debugmsg("ncmul constructor from 3 ex",LOGLEVEL_CONSTRUCT);
 }
 
 ncmul::ncmul(ex const & f1, ex const & f2, ex const & f3) :
     exprseq(f1,f2,f3)
 {
     debugmsg("ncmul constructor from 3 ex",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_NCMUL;
+    tinfo_key = TINFO_ncmul;
 }
 
 ncmul::ncmul(ex const & f1, ex const & f2, ex const & f3,
       ex const & f4) : exprseq(f1,f2,f3,f4)
 {
     debugmsg("ncmul constructor from 4 ex",LOGLEVEL_CONSTRUCT);
 }
 
 ncmul::ncmul(ex const & f1, ex const & f2, ex const & f3,
       ex const & f4) : exprseq(f1,f2,f3,f4)
 {
     debugmsg("ncmul constructor from 4 ex",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_NCMUL;
+    tinfo_key = TINFO_ncmul;
 }
 
 ncmul::ncmul(ex const & f1, ex const & f2, ex const & f3,
       ex const & f4, ex const & f5) : exprseq(f1,f2,f3,f4,f5)
 {
     debugmsg("ncmul constructor from 5 ex",LOGLEVEL_CONSTRUCT);
 }
 
 ncmul::ncmul(ex const & f1, ex const & f2, ex const & f3,
       ex const & f4, ex const & f5) : exprseq(f1,f2,f3,f4,f5)
 {
     debugmsg("ncmul constructor from 5 ex",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_NCMUL;
+    tinfo_key = TINFO_ncmul;
 }
 
 ncmul::ncmul(ex const & f1, ex const & f2, ex const & f3,
 }
 
 ncmul::ncmul(ex const & f1, ex const & f2, ex const & f3,
@@ -93,19 +120,19 @@ ncmul::ncmul(ex const & f1, ex const & f2, ex const & f3,
     exprseq(f1,f2,f3,f4,f5,f6)
 {
     debugmsg("ncmul constructor from 6 ex",LOGLEVEL_CONSTRUCT);
     exprseq(f1,f2,f3,f4,f5,f6)
 {
     debugmsg("ncmul constructor from 6 ex",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_NCMUL;
+    tinfo_key = TINFO_ncmul;
 }
 
 ncmul::ncmul(exvector const & v, bool discardable) : exprseq(v,discardable)
 {
     debugmsg("ncmul constructor from exvector,bool",LOGLEVEL_CONSTRUCT);
 }
 
 ncmul::ncmul(exvector const & v, bool discardable) : exprseq(v,discardable)
 {
     debugmsg("ncmul constructor from exvector,bool",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_NCMUL;
+    tinfo_key = TINFO_ncmul;
 }
 
 ncmul::ncmul(exvector * vp) : exprseq(vp)
 {
     debugmsg("ncmul constructor from exvector *",LOGLEVEL_CONSTRUCT);
 }
 
 ncmul::ncmul(exvector * vp) : exprseq(vp)
 {
     debugmsg("ncmul constructor from exvector *",LOGLEVEL_CONSTRUCT);
-    tinfo_key = TINFO_NCMUL;
+    tinfo_key = TINFO_ncmul;
 }
     
 //////////
 }
     
 //////////
@@ -120,6 +147,39 @@ basic * ncmul::duplicate() const
     return new ncmul(*this);
 }
 
     return new ncmul(*this);
 }
 
+void ncmul::print(ostream & os, unsigned upper_precedence) const
+{
+    debugmsg("ncmul print",LOGLEVEL_PRINT);
+    printseq(os,'(','%',')',precedence,upper_precedence);
+}
+
+void ncmul::printraw(ostream & os) const
+{
+    debugmsg("ncmul printraw",LOGLEVEL_PRINT);
+
+    os << "%(";
+    for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
+        (*it).bp->printraw(os);
+        os << ",";
+    }
+    os << ",hash=" << hashvalue << ",flags=" << flags;
+    os << ")";
+}
+
+void ncmul::printcsrc(ostream & os, unsigned upper_precedence) const
+{
+    debugmsg("ncmul print csrc",LOGLEVEL_PRINT);
+    exvector::const_iterator it;
+    exvector::const_iterator itend = seq.end()-1;
+    os << "ncmul(";
+    for (it=seq.begin(); it!=itend; ++it) {
+        (*it).bp->printcsrc(os,precedence);
+        os << ",";
+    }
+    (*it).bp->printcsrc(os,precedence);
+    os << ")";
+}
+
 bool ncmul::info(unsigned inf) const
 {
     throw(std::logic_error("which flags have to be implemented in ncmul::info()?"));
 bool ncmul::info(unsigned inf) const
 {
     throw(std::logic_error("which flags have to be implemented in ncmul::info()?"));
@@ -174,7 +234,7 @@ ex ncmul::expand(unsigned options) const
         exvector term;
         term=expanded_seq;
         for (l=0; l<number_of_adds; l++) {
         exvector term;
         term=expanded_seq;
         for (l=0; l<number_of_adds; l++) {
-            ASSERT(is_ex_exactly_of_type(expanded_seq[positions_of_adds[l]],add));
+            GINAC_ASSERT(is_ex_exactly_of_type(expanded_seq[positions_of_adds[l]],add));
             add const & addref=ex_to_add(expanded_seq[positions_of_adds[l]]);
             term[positions_of_adds[l]]=addref.recombine_pair_to_ex(addref.seq[k[l]]);
         }
             add const & addref=ex_to_add(expanded_seq[positions_of_adds[l]]);
             term[positions_of_adds[l]]=addref.recombine_pair_to_ex(addref.seq[k[l]]);
         }
@@ -243,7 +303,7 @@ ex ncmul::coeff(symbol const & s, int const n) const
 
     if (coeff_found) return (new ncmul(coeffseq,1))->setflag(status_flags::dynallocated);
     
 
     if (coeff_found) return (new ncmul(coeffseq,1))->setflag(status_flags::dynallocated);
     
-    return exZERO();
+    return _ex0();
 }
 
 unsigned ncmul::count_factors(ex const & e) const
 }
 
 unsigned ncmul::count_factors(ex const & e) const
@@ -315,7 +375,7 @@ ex ncmul::eval(int level) const
     if (assocseq.size()==1) return *(seq.begin());
 
     // ncmul() -> 1
     if (assocseq.size()==1) return *(seq.begin());
 
     // ncmul() -> 1
-    if (assocseq.size()==0) return exONE();
+    if (assocseq.size()==0) return _ex1();
 
     // determine return types
     unsignedvector rettypes;
 
     // determine return types
     unsignedvector rettypes;
@@ -340,7 +400,7 @@ ex ncmul::eval(int level) const
         }
         ++i;
     }
         }
         ++i;
     }
-    ASSERT(count_commutative+count_noncommutative+count_noncommutative_composite==assocseq.size());
+    GINAC_ASSERT(count_commutative+count_noncommutative+count_noncommutative_composite==assocseq.size());
 
     // ncmul(...,c1,...,c2,...) ->
     //     *(c1,c2,ncmul(...)) (pull out commutative elements)
 
     // ncmul(...,c1,...,c2,...) ->
     //     *(c1,c2,ncmul(...)) (pull out commutative elements)
@@ -367,7 +427,7 @@ ex ncmul::eval(int level) const
     if (count_noncommutative_composite==0) {
         // there are neither commutative nor noncommutative_composite
         // elements in assocseq
     if (count_noncommutative_composite==0) {
         // there are neither commutative nor noncommutative_composite
         // elements in assocseq
-        ASSERT(count_commutative==0);
+        GINAC_ASSERT(count_commutative==0);
 
         exvectorvector evv;
         unsignedvector rttinfos;
 
         exvectorvector evv;
         unsignedvector rttinfos;
@@ -392,15 +452,15 @@ ex ncmul::eval(int level) const
             }
         }
 
             }
         }
 
-#ifdef DOASSERT
-        ASSERT(evv.size()==rttinfos.size());
-        ASSERT(evv.size()>0);
+#ifdef DO_GINAC_ASSERT
+        GINAC_ASSERT(evv.size()==rttinfos.size());
+        GINAC_ASSERT(evv.size()>0);
         unsigned s=0;
         for (i=0; i<evv.size(); ++i) {
             s += evv[i].size();
         }
         unsigned s=0;
         for (i=0; i<evv.size(); ++i) {
             s += evv[i].size();
         }
-        ASSERT(s==assocseq.size());
-#endif // def DOASSERT
+        GINAC_ASSERT(s==assocseq.size());
+#endif // def DO_GINAC_ASSERT
         
         // if all elements are of same type, simplify the string
         if (evv.size()==1) {
         
         // if all elements are of same type, simplify the string
         if (evv.size()==1) {
@@ -485,7 +545,7 @@ unsigned ncmul::return_type(void) const
         }
     }
     // all factors checked
         }
     }
     // all factors checked
-    ASSERT(!all_commutative); // not all factors should commute, because this is a ncmul();
+    GINAC_ASSERT(!all_commutative); // not all factors should commute, because this is a ncmul();
     return all_commutative ? return_types::commutative : return_types::noncommutative;
 }
    
     return all_commutative ? return_types::commutative : return_types::noncommutative;
 }
    
@@ -559,7 +619,7 @@ ex nonsimplified_ncmul(exvector const & v)
 ex simplified_ncmul(exvector const & v)
 {
     if (v.size()==0) {
 ex simplified_ncmul(exvector const & v)
 {
     if (v.size()==0) {
-        return exONE();
+        return _ex1();
     } else if (v.size()==1) {
         return v[0];
     }
     } else if (v.size()==1) {
         return v[0];
     }
@@ -567,4 +627,6 @@ ex simplified_ncmul(exvector const & v)
                                    status_flags::evaluated);
 }
 
                                    status_flags::evaluated);
 }
 
-
+#ifndef NO_GINAC_NAMESPACE
+} // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE