Johann Hibschman-4 wrote:
> 
> [...]
> 
> Here's a simple question from a rank beginner:
> 
> Expressing polynomials as, for example,
> 
>   +/1 _1 1*x^i.3
> 
> works well, as long as x is a scalar.  If x is of higher rank, this
> stops working.  
> 
Well known efficient representation of polynomial assuming 
right-to-left order of evaluation is:

   c1+x*c2+x*c3+x*c4+...+x*cn === (+ x * ])/ c === (+ x&*)/ c

We can define an adverb P that does this kind of computation:

   P=:(&*)(+`)(`:6)/

   1 2 3 P
(+ 1 2 3&*)/

   1 2 3 P 1 2 3 4
10 49 142

   1 2 3 p.~ 1 2 3 4
10 49 142

   1 2 3 P("1) 1 2 3 4,:4 3 2 1
10 49 142
10 26  58


My somewhat brute-force solution is to manually set the
> rank used, as in:
> 
>   x=:2 3 5
>   +/1 _1 1*x^_ 0 i. 3
> 
> Is this good style?  Is there a better way?
> 
> Thanks, and pardon the pun,
> Johann
> 
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 
> 

-- 
View this message in context: 
http://old.nabble.com/simple-polynomials-tp29486977s24193p29497553.html
Sent from the J Programming mailing list archive at Nabble.com.

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

Reply via email to