[GiNaC-list] "Internal error..." report -- probably misused map.

Chris Dams Chris.Dams at mi.infn.it
Thu Aug 10 09:33:53 CEST 2006


Dear Warren,

On Thu, 10 Aug 2006, Warren Weckesser wrote:

> In some of my first attempts to do this, I occasionally got an
> "internal error" message.  The following code is a simplified
> version that causes the error:

Yes, this is a bug. Thanks for having submitted it. I will commit a patch 
to repair this to CVS shortly.

>     if (is_a<add>(e))
>         {
>         ex s = 0;
>         for (size_t k = 0; k < e.nops(); ++k)
>             s = s + wrap2(e.op(k));
>         return s;
>         }

Yes, this works around the bug. It is quite a bit less efficient for large 
adds though. Basically the terms of the add get sorted every time a term 
is added. A faster way would be:

	exvector v;	
	v.reserve(e.nops());
	for (size_t i = 0; i<e.nops(); ++i)
		v.push_back(wrap2(e.op(i)));
	return add(v);

And analogous code for the mul.

Best wishes,
Chris



More information about the GiNaC-list mailing list