44 Reputation

2 Badges

10 years, 249 days

MaplePrimes Activity

These are replies submitted by abr28

Thank you all for taking the time to test it and clear this up. Very much appreciated.

It looks like I'm better off using add() since the index variable is private. From your experience, is the inert evalf(Sum()) faster than add()?

Once again, thanks everyone.

Thanks. Your third paragraph gives a possible cause about why the result is wrong. It would be nice if the internals you speak of were made clear by maple. I understand that it is good practice to make k local to the procedure to avoid any such oddities.

Regarding your 2nd paragraph, k being reused in successive recursive calls in different places (argument, sumation indexes, etc) gives no problems as long as rec() is evaluated by itself. It always works correctly, regardles oof the number of recursive calls. It's only when i do Sum(rec()) that it fails so the outer inert Sum obviously introduces some glitches that I was trying to better understand.

Thanks again for your replies.


Thanks for your reply. The symbolic "sum" is not an issue since I don't use it at all. I see what you mean regarding a local proc variable and your examples where helpful.

However, the index k within "rec" is not assigned nor used anywhere else other than inside the rec procedure. Are you saying that, because "rec" is a recursive procedure, then k gets assigned and then reused after the first recursive call and hence causes a wrong result? That doesn't seem to be the case because evalf(rec()), which involves several recursive calls, works just fine ... and it does so with "rec" based on inert Sums and k not declared local to the procedure. It's only Sum(rec()) that fails, even though this outer Sum uses another index.



The symbolic "sum" is not an issue in this thread. I actually haven't considered or mentioned the symbolic "sum" ... the apaprent bug I'm mentioning has to do with the inert "Sum" (note the capital). Because of it, I was forced to use "add" as an alternative. I'm well aware of the differences between symbolic sum and inert Sum.

Only as a side note, but still unrelated to the symbolc sum, I was curious if there is any difference in *speed* of numeric summation between the inert "Sum" and "add". This issue is however offtopic, I shouldn't have brought it up. I'm interested in the initial apparent bug.


So are you saying this is not a bug? The procedure 'rec', and hence the inert Sums inside it with k as index, are evaluated in both cases but only one gives a correct output. Actually, for the incorrect one, the recursion goes ok except for one step, otherwise you don't get 22 ... it looks like a bug to me, unless I'm missing something.

As a side question, is there, in principle, any speed difference between add() and evalf(Sum())?



Page 1 of 1