]> www.ginac.de Git - ginac.git/commitdiff
* Eliminated overloaded operator% for noncommunistic objects for good.
authorRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Thu, 22 Mar 2001 21:24:32 +0000 (21:24 +0000)
committerRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Thu, 22 Mar 2001 21:24:32 +0000 (21:24 +0000)
  End of story.  There was just too much risk involved in somebody not
  caring enough whether there are noncommutatating objects inside
  expressions to be multiplied and it could potentially end up in people
  using operator% instead of operator* all the time, just to be safe.
  In any case, it was our firm believe that noncommutatividity is a
  property of the class objects belong to and hence of the objects and
  not at all of the sign to symbol the object (as Maple, Reduce and others
  want to make us believe).  Finally we found out how to code operator*
  so that it handles both cases without any performance loss.  It couldn't
  be less intrusive!  There is no measurable performance degradation.
  (Except perhaps for the tgamma-expansion which seems to show some 3%
  loss while others mysteriously become somewhat faster -- my brain is
  melting.)  Enough, now...

NEWS
ginac/ex.cpp
ginac/ex.h
ginac/input_parser.yy
ginac/ncmul.cpp
ginac/operators.cpp
ginac/operators.h
ginsh/ginsh_parser.yy

diff --git a/NEWS b/NEWS
index 8c11cffc96ef9a4b3ffb9fbf601c3599f491374a..de39569dc4c5dfd387273bdbadb26a5212dc41c4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,8 @@ This file records noteworthy changes.
 * sqrfree() factorization fixed and improved syntactically.
 * subs() works on matrices.
 * Fixed memory leak in expand().
 * sqrfree() factorization fixed and improved syntactically.
 * subs() works on matrices.
 * Fixed memory leak in expand().
+* Operator% for objects of class ncmul has gone.  Use operator* now for that
+  case too, which is much more natural.
 
 0.7.3 (28 February 2001)
 * Several bugfixes and minor performance tunings.
 
 0.7.3 (28 February 2001)
 * Several bugfixes and minor performance tunings.
index 55482551995efcad1ce2166484dd126fc48b8f2e..7570618d16c94ee20d36235d95c622797fc41170 100644 (file)
@@ -342,19 +342,23 @@ unsigned ex::gethash(void) const
        return bp->gethash();
 }
 
        return bp->gethash();
 }
 
+/** Used internally by operator+() to add two ex objects together. */
 ex ex::exadd(const ex & rh) const
 {
        return (new add(*this,rh))->setflag(status_flags::dynallocated);
 }
 
 ex ex::exadd(const ex & rh) const
 {
        return (new add(*this,rh))->setflag(status_flags::dynallocated);
 }
 
+/** Used internally by operator*() to multiply two ex objects together. */
 ex ex::exmul(const ex & rh) const
 {
 ex ex::exmul(const ex & rh) const
 {
-       return (new mul(*this,rh))->setflag(status_flags::dynallocated);
-}
-
-ex ex::exncmul(const ex & rh) const
-{
-       return (new ncmul(*this,rh))->setflag(status_flags::dynallocated);
+       // Check if we are constructing a mul object or a ncmul object.  Due to
+       // ncmul::eval()'s rule to pull out commutative elements we need to check
+       // only one of the elements.
+       if (rh.bp->return_type()==return_types::commutative ||
+           bp->return_type()==return_types::commutative)
+               return (new mul(*this,rh))->setflag(status_flags::dynallocated);
+       else
+               return (new ncmul(*this,rh))->setflag(status_flags::dynallocated);
 }
 
 // private
 }
 
 // private
index ce0fe8c1686d30b33ae861c383ef739b438ca434..d034dec2e07f84d1f0c9eb2ea31e976eb33a4871 100644 (file)
@@ -129,7 +129,6 @@ public:
        
        ex exadd(const ex & rh) const;
        ex exmul(const ex & rh) const;
        
        ex exadd(const ex & rh) const;
        ex exmul(const ex & rh) const;
-       ex exncmul(const ex & rh) const;
 private:
        void construct_from_basic(const basic & other);
        void construct_from_int(int i);
 private:
        void construct_from_basic(const basic & other);
        void construct_from_int(int i);
index af46af0a04751e134d18c525b5d2df4349e2708a..d1e876690967227869fa4bc18007351a443f877c 100644 (file)
@@ -109,7 +109,6 @@ exp : T_NUMBER              {$$ = $1;}
        | exp '-' exp           {$$ = $1 - $3;}
        | exp '*' exp           {$$ = $1 * $3;}
        | exp '/' exp           {$$ = $1 / $3;}
        | exp '-' exp           {$$ = $1 - $3;}
        | exp '*' exp           {$$ = $1 * $3;}
        | exp '/' exp           {$$ = $1 / $3;}
-       | exp '%' exp           {$$ = $1 % $3;}
        | '-' exp %prec NEG     {$$ = -$2;}
        | '+' exp %prec NEG     {$$ = $2;}
        | exp '^' exp           {$$ = pow($1, $3);}
        | '-' exp %prec NEG     {$$ = -$2;}
        | '+' exp %prec NEG     {$$ = $2;}
        | exp '^' exp           {$$ = pow($1, $3);}
index 1433a3a883132a36a3c3e744a0bafa9ba7ce1fa7..44c5d30e074a686873f4e866a7c7a54782098bcb 100644 (file)
@@ -143,13 +143,13 @@ void ncmul::archive(archive_node &n) const
 void ncmul::print(std::ostream & os, unsigned upper_precedence) const
 {
        debugmsg("ncmul print",LOGLEVEL_PRINT);
 void ncmul::print(std::ostream & os, unsigned upper_precedence) const
 {
        debugmsg("ncmul print",LOGLEVEL_PRINT);
-       printseq(os,'(','%',')',precedence,upper_precedence);
+       printseq(os,'(','*',')',precedence,upper_precedence);
 }
 
 void ncmul::printraw(std::ostream & os) const
 {
        debugmsg("ncmul printraw",LOGLEVEL_PRINT);
 }
 
 void ncmul::printraw(std::ostream & os) const
 {
        debugmsg("ncmul printraw",LOGLEVEL_PRINT);
-       os << "%(";
+       os << "ncmul(";
        for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
                (*it).bp->printraw(os);
                os << ",";
        for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
                (*it).bp->printraw(os);
                os << ",";
@@ -344,7 +344,7 @@ ex ncmul::eval(int level) const
        //                      ncmul(ncmul(x1,x2,...),X,ncmul(y1,y2,...)
        //                      (X noncommutative_composite)
 
        //                      ncmul(ncmul(x1,x2,...),X,ncmul(y1,y2,...)
        //                      (X noncommutative_composite)
 
-       if ((level==1)&&(flags & status_flags::evaluated)) {
+       if ((level==1) && (flags & status_flags::evaluated)) {
                return *this;
        }
 
                return *this;
        }
 
@@ -353,16 +353,14 @@ ex ncmul::eval(int level) const
        // ncmul(...,*(x1,x2),...,ncmul(x3,x4),...) ->
        //     ncmul(...,x1,x2,...,x3,x4,...) (associativity)
        unsigned factors=0;
        // ncmul(...,*(x1,x2),...,ncmul(x3,x4),...) ->
        //     ncmul(...,x1,x2,...,x3,x4,...) (associativity)
        unsigned factors=0;
-       for (exvector::const_iterator cit=evaledseq.begin(); cit!=evaledseq.end(); ++cit) {
+       for (exvector::const_iterator cit=evaledseq.begin(); cit!=evaledseq.end(); ++cit)
                factors += count_factors(*cit);
                factors += count_factors(*cit);
-       }
-
+       
        exvector assocseq;
        assocseq.reserve(factors);
        exvector assocseq;
        assocseq.reserve(factors);
-       for (exvector::const_iterator cit=evaledseq.begin(); cit!=evaledseq.end(); ++cit) {
+       for (exvector::const_iterator cit=evaledseq.begin(); cit!=evaledseq.end(); ++cit)
                append_factors(assocseq,*cit);
                append_factors(assocseq,*cit);
-       }
-
+       
        // ncmul(x) -> x
        if (assocseq.size()==1) return *(seq.begin());
 
        // ncmul(x) -> x
        if (assocseq.size()==1) return *(seq.begin());
 
@@ -402,11 +400,10 @@ ex ncmul::eval(int level) const
                exvector noncommutativeseq;
                noncommutativeseq.reserve(assocseq.size()-count_commutative);
                for (i=0; i<assocseq.size(); ++i) {
                exvector noncommutativeseq;
                noncommutativeseq.reserve(assocseq.size()-count_commutative);
                for (i=0; i<assocseq.size(); ++i) {
-                       if (rettypes[i]==return_types::commutative) {
+                       if (rettypes[i]==return_types::commutative)
                                commutativeseq.push_back(assocseq[i]);
                                commutativeseq.push_back(assocseq[i]);
-                       } else {
+                       else
                                noncommutativeseq.push_back(assocseq[i]);
                                noncommutativeseq.push_back(assocseq[i]);
-                       }
                }
                commutativeseq.push_back((new ncmul(noncommutativeseq,1))->setflag(status_flags::dynallocated));
                return (new mul(commutativeseq))->setflag(status_flags::dynallocated);
                }
                commutativeseq.push_back((new ncmul(noncommutativeseq,1))->setflag(status_flags::dynallocated));
                return (new mul(commutativeseq))->setflag(status_flags::dynallocated);
@@ -454,16 +451,15 @@ ex ncmul::eval(int level) const
 #endif // def DO_GINAC_ASSERT
                
                // if all elements are of same type, simplify the string
 #endif // def DO_GINAC_ASSERT
                
                // if all elements are of same type, simplify the string
-               if (evv.size()==1) {
+               if (evv.size()==1)
                        return evv[0][0].simplify_ncmul(evv[0]);
                        return evv[0][0].simplify_ncmul(evv[0]);
-               }
                
                exvector splitseq;
                splitseq.reserve(evv.size());
                for (i=0; i<evv.size(); ++i) {
                        splitseq.push_back((new ncmul(evv[i]))->setflag(status_flags::dynallocated));
                }
                
                exvector splitseq;
                splitseq.reserve(evv.size());
                for (i=0; i<evv.size(); ++i) {
                        splitseq.push_back((new ncmul(evv[i]))->setflag(status_flags::dynallocated));
                }
-
+               
                return (new mul(splitseq))->setflag(status_flags::dynallocated);
        }
        
                return (new mul(splitseq))->setflag(status_flags::dynallocated);
        }
        
index 4e5781a692d03da8fedb28799e966dfdc3fe7b23..bd9a4425b4534cd85fff4c5d1d23e4d9aba29317 100644 (file)
@@ -55,12 +55,6 @@ ex operator/(const ex & lh, const ex & rh)
        return lh.exmul(power(rh,_ex_1()));
 }
 
        return lh.exmul(power(rh,_ex_1()));
 }
 
-ex operator%(const ex & lh, const ex & rh)
-{
-       debugmsg("operator%(ex,ex)",LOGLEVEL_OPERATOR);
-       return lh.exncmul(rh);
-}
-
 
 // binary arithmetic operators numeric with numeric
 
 
 // binary arithmetic operators numeric with numeric
 
@@ -115,12 +109,6 @@ const ex & operator/=(ex & lh, const ex & rh)
        return (lh=lh.exmul(power(rh,_ex_1())));
 }
 
        return (lh=lh.exmul(power(rh,_ex_1())));
 }
 
-const ex & operator%=(ex & lh, const ex & rh)
-{
-       debugmsg("operator%=(ex,ex)",LOGLEVEL_OPERATOR);
-       return (lh=lh%rh);
-}
-
 
 // binary arithmetic assignment operators with numeric
 
 
 // binary arithmetic assignment operators with numeric
 
index 8636e212d5922cf3ffbdfbd5af05e4caf044409a..47d1b745a3602aba91fda96b891cb337fc5ca5f2 100644 (file)
@@ -36,7 +36,6 @@ ex operator+(const ex & lh, const ex & rh);
 ex operator-(const ex & lh, const ex & rh);
 ex operator*(const ex & lh, const ex & rh);
 ex operator/(const ex & lh, const ex & rh);
 ex operator-(const ex & lh, const ex & rh);
 ex operator*(const ex & lh, const ex & rh);
 ex operator/(const ex & lh, const ex & rh);
-ex operator%(const ex & lh, const ex & rh); // non-commutative multiplication
 
 // binary arithmetic operators numeric with numeric
 numeric operator+(const numeric & lh, const numeric & rh);
 
 // binary arithmetic operators numeric with numeric
 numeric operator+(const numeric & lh, const numeric & rh);
@@ -49,7 +48,6 @@ const ex & operator+=(ex & lh, const ex & rh);
 const ex & operator-=(ex & lh, const ex & rh);
 const ex & operator*=(ex & lh, const ex & rh);
 const ex & operator/=(ex & lh, const ex & rh);
 const ex & operator-=(ex & lh, const ex & rh);
 const ex & operator*=(ex & lh, const ex & rh);
 const ex & operator/=(ex & lh, const ex & rh);
-const ex & operator%=(ex & lh, const ex & rh); // non-commutative multiplication
 
 // binary arithmetic assignment operators with numeric
 const numeric & operator+=(numeric & lh, const numeric & rh);
 
 // binary arithmetic assignment operators with numeric
 const numeric & operator+=(numeric & lh, const numeric & rh);
index 784af1cb22902a1724aaf10dad7a3c853d6ccd15..d715347677e03068c829c855cccd271595f7c784 100644 (file)
@@ -215,7 +215,6 @@ exp : T_NUMBER              {$$ = $1;}
        | exp '-' exp           {$$ = $1 - $3;}
        | exp '*' exp           {$$ = $1 * $3;}
        | exp '/' exp           {$$ = $1 / $3;}
        | exp '-' exp           {$$ = $1 - $3;}
        | exp '*' exp           {$$ = $1 * $3;}
        | exp '/' exp           {$$ = $1 / $3;}
-       | exp '%' exp           {$$ = $1 % $3;}
        | '-' exp %prec NEG     {$$ = -$2;}
        | '+' exp %prec NEG     {$$ = $2;}
        | exp '^' exp           {$$ = power($1, $3);}
        | '-' exp %prec NEG     {$$ = -$2;}
        | '+' exp %prec NEG     {$$ = $2;}
        | exp '^' exp           {$$ = power($1, $3);}