* 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.
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);
}
+/** Used internally by operator*() to multiply two ex objects together. */
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
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);
| 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);}
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);
- os << "%(";
+ os << "ncmul(";
for (exvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) {
(*it).bp->printraw(os);
os << ",";
// 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;
}
// 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);
- }
-
+
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);
- }
-
+
// ncmul(x) -> x
if (assocseq.size()==1) return *(seq.begin());
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]);
- } else {
+ else
noncommutativeseq.push_back(assocseq[i]);
- }
}
commutativeseq.push_back((new ncmul(noncommutativeseq,1))->setflag(status_flags::dynallocated));
return (new mul(commutativeseq))->setflag(status_flags::dynallocated);
#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]);
- }
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 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
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
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);
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);
| 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);}