> I looked into the packages of Mathematica and I found the following
> routine for calculating Stirling1numbers:
>
> StirlingFirst[n_Integer,m_Integer] := StirlingFirst1[n,m]
>
> StirlingFirst1[n_Integer,0] := If [n == 0, 1, 0]
> StirlingFirst1[0,m_Integer] := If [m == 0, 1, 0]
>
> StirlingFirst1[n_Integer,m_Integer] := StirlingFirst1[n,m] =
> (n-1) StirlingFirst1[n-1,m] + StirlingFirst1[n-1, m-1]
>
> This routine is similar to the routine I made for derive and we all know
> that it's very slow!
>
> I found this routine in the package combina2.m in the directory \discrete
> My version of mathematica is a rather old dos-version 2.2.
>
> Greetings
> Peer van de sanden
If you look closely at this you see that it is not slow (once you recall
the mathematica syntax). In fact it implements your idea of keeping the
values in matrix (although its actually a hash table). This strategy is
similar but not the same as ours. The value is stored permanently
so if you calculate StirlingFirst[200,100] twice the second time it will
return the answer immediately. This is nice but there are trade-offs:
it can take a lot of space. For S1(1000,500) there are about n^2/4 =
250000 numbers (most very large) stored. So if you were doing many
calculations with Stirling numbers their scheme would work well but if
you only calculated a few and then when on to something else, a great
deal of memory is locked up. The derive version is capable of calculating
S1(n,k) for much greater values of n and k before running out of
memory.
Also note that the timing using their scheme can be tricky:
if you calculate StirlingFirst[100,50] and then StirlingFirst[200,100],
the latter will take less time than if it were done first.
Ralph
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|