[seqfan] Rant on Maple code
peter.luschny at googlemail.com
Mon Aug 10 11:43:03 CEST 2009
Just one example, out of many, which explains why I do not
like most of the Maple code presented in the database:
A001147 Double factorial numbers: (2n-1)!!
(1) f := n->(2*n)!/(n!*2^n);
(2) with(finance):seq(mul(cashflows([k, k, 1], 0), k=0..n), n=-1..22);
# [From Zerinvary Lajos (zerinvarylajos(AT)yahoo.com), Dec 22 2008]
(3) restart: G(x):=(1-2*x)^(-1/2): f:=G(x): for n from 1 to 29 do
f[n]:=diff(f[n-1], x) od: x:=0: seq(f[n], n=0..19);
# [From Zerinvary Lajos (zerinvarylajos(AT)yahoo.com), Apr 03 2009]
(4) A001147 := proc(n) doublefactorial(2*n-1); end:
[From R. J. Mathar (mathar(AT)strw.leidenuniv.nl), Jul 04 2009]
(1) is the best out of the four. It reflects the formula and
is simple. Of course it is not computationally efficient.
(2) A nightmare. I did not even know that Maple comes with a
package 'finance'. So I looked it up in the Maple help pages
what cashflows are. It says:
finance[cashflows] - present value of a list of cash flows
Aha. But we are talking about the double factorial. And why
does n starts at '-1'? I found no hint in the references,
in the links or in the formula section which explains this
implementation. Well, I stopped further investigations as I
think that this formula was invented by employees of the
Lehman Brothers bank. Hopefully Maple will not collapse also.
(3) Well, there are many ways to do it... The 'restart'
command is a good general advice -- in a Maple beginners
book. What why put it here?
(4) Not really helpful. 'doublefactorial' is not implemented
in the older versions of Maple. And there are many Maple V
still out there just because they are not so buggy as the
Maple can of course compute the double factorial numbers
since the early days in an efficient manner. Moreover,
this way also reflects the way the double factorial numbers
are used in the world of hypergeometric summation where
they occur frequently. And reflects the mathematical
meaning of these numbers better than (1).
A001147 := n -> 2^n*pochhammer(1/2, n);
More information about the SeqFan