Raul wrote:
> ^T.10
>
> 1 1 0.5 0.16666666666666666 0.041666666666666664 0.0083333333333333332
> 0.0013888888888888889 0.00019841269841269841 2.4801587301587302e_5
> 2.7557319223985893e_6&p.
[FYI, I'm sure you know this, but ^t.i.10 (lowercase t.) gives you the
polynomial coefficients as a noun, so you don't have to manually pull them
out the verb returned by T. (uppercase T.)]
Yes, that coefficient vector is what inspired the verb I posted earlier
this morning:
exp =: 250 & ( # +/ . % &(_1 |.!.1 */\) >:@:i.@:[ )
Check out the right-hand tine:
invFact =: [: % &(_1 |.!.1 */\) >:@:i.@:[
invFact 10
1 1 0.5 0.166667 0.0416667 0.00833333 0.00138889 0.000198413 2.48016e_5
2.75573e_6
^ t. i.10
1 1 0.5 0.166667 0.0416667 0.00833333 0.00138889 0.000198413 2.48016e_5
2.75573e_6
(^ t. i.10) -: invFact 10
1
(^ t. i.100) -: invFact 100
1
Note again the need to manually shift-in a 1 to the head of the vector;
this feels a bit forced. There might be a neater or more satisfying way to
do it (e.g. product of an empty vector). Though, along the lines of
David's post on Horner's rule, I'll point out that #. (which is closely
related to p. [1]) does manually inject a 1 into its coefficient vector,
per the DoJ [2]:
x#.y is a weighted sum of the items of y ; that is, +/w*y , where w
is the product scan */\.}.x,1
-Dan
[1] Relationship between #. and p.:
http://www.jsoftware.com/pipermail/programming/2008-October/012327.html
and rationale based on Ruf-Horn method:
http://www.jsoftware.com/pipermail/programming/2008-October/012328.html
[2] Dictionary definition of dyad #.:
http://www.jsoftware.com/help/dictionary/d401.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm