collect() eats fractions

Pearu Peterson pearu at cens.ioc.ee
Sat Apr 14 20:35:23 CEST 2001



On Sat, 14 Apr 2001, Richard B. Kreckel wrote:

> On Sat, 14 Apr 2001, Richard B. Kreckel got some nervous twitch in his
> left hand and sent an unfinished email to innocent ginac-devel subscribers:
> > A couple of hours ago, I wrote:
> > [...]
> > > > Btw, I have noticed that you use frequently
> > > > 
> > > >    for (int n=this->ldegree(s); n<=this->degree(s); n++)
> > > > 
> > > > instead of more efficient
> > > > 
> > > >    for (int n=this->ldegree(s), m=this->degree(s); n<=m; ++n)
> > > > 
> > > > that saves repeated calling of the degree() method.
> > > 
> > > Indeed, it does.  But where else besides in basic::collect() do you see
> > > occurences of this?

Do
	grep "for (" *.cpp | grep "()"

and there are numerous cases like
	for (unsigned i=0; i<sym_lst.nops(); i++) {
	for (unsigned i=0; i<seq.size(); ++i) {
	for (int p = 1; it!=factors.end(); ++it, ++p)
Ok, they are not as bad as above and can be left for fixing them in future
(if at all).

> No, it does not safe calls.  Please look at the assembler output, maybe

That's interesting indeed! It must be a optimization "feature" of a
compiler. I guess
	int m = this->degree(s);
	for (int n=this->ldegree(s); n<=m; ++n)
will do the job.

Pearu




More information about the GiNaC-devel mailing list