Don Guinn <[email protected]> writes:

>    x=:5 8
>
>    1 _1 1*"1 x^/i.3
> 1 _5 25
> 1 _8 64
>
> Then sum each row. Here you have to override the rank of the sum:
>
>    +/"1]1 _1 1*"1 x^/i.3
> 21 57

Ugh.  First of all, I had dropped a " from my original, and I should
have use something other than a 3-vector.  What I intended was:

   +/1 _1 1*x^"_ 0 i. 3
21 57

Is there a reason your form should be preferred over this?

My first impulse is that

   x^/i.3
1 5 25
1 8 64

has the wrong shape.  What passes for my own numerical intuition says I
want |:x^/i.3 or (i.3)^~/x, so that the first dimension matches the
polynomial coefficients.

If I do that, I can just use

   +/1 _1 1*|:x^/i.3

That works, but I have to think harder about it than for my original
solution, when I try to extend x to be a matrix or cube or other
higher-dimensional object, just to make sure that table and transpose
generalize in the right way.  

The initial answer of just setting the rank is more "obvious" to me.  Is
this just my inexperience speaking?

> But you might prefer using p. which is much cleaner.
>
>    1 _1 1 p. x
> 21 57

Oh, but using built-ins seems like cheating.  Yes, that's what I'd use
practically, but I mostly started thinking about this by wondering how
the nicely elegant +/1 _1 1*x^i.3 extends to higher-rank.

Cheers,
Johann

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to