problem with recursive functions (erratum)



Stavros Macrakis <macrakis <at> gmail.com> writes:

> I don't know what calculation exactly you are performing, so I can't give
detailed advice.  Constructing the lambda-expressions is probably *not* the most
efficient way to do anything.  More likely to help would be using the memo'izing
recursive form f[d,x]:=...
> Maybe you could tell us more about your real problem and we can help
there.              -s

Well, I am working on a new alogrithm to create arbitrary dimensional magic
hypercubes with special properties. I don't want to reveale any details yet, but
it works in a kind of recursive way. I start with a 1 dimensional magic square,
which is simply [1,2,3,4,..n]. The algorithm can basically extend a magic square
into the next dimension by making n copies (i.e. layers) of the original one. Of
course during the process you have to manipulate the numbers in the original
square. This means that I have to do complicated calculation for each element of
the original square, that is why implementing it in a function is not feasible.
I found that what you suggested in your last post is the best solution:
f[d,n] := if d=1 then makelist(i,i,1,n) else makelist( extend(f[d-1,n],i),i,1,n )

I implemented it in C++ long ago, but found it easier to play around with maxima.

Really appreciate your help,
Norbert