Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!utnut!cs.utexas.edu!uunet!decwrl!csus.edu!sfsuvax1.sfsu.edu!vpcsc4
From: vpcsc4@sfsuvax1.sfsu.edu (__)
Subject: Recent J stuff
Message-ID: <1993Apr10.032727.22785@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
  
Date: Sat, 10 Apr 1993 03:27:27 GMT
Lines: 53

   sort =. /:~
   transpose =. |:
   fc =.  sort"1 &. transpose"2

NB.   Usage is:
   fc ? 3 3 3 $ 30

NB. By the way, although I did not find a gerund for multiplying
NB. polynomials, I found that the outter product efficiently does.
NB. You'll find this implementation in polyProd below, used in an improved
NB. version of lagrange. This verb works both monadically and
NB. dyadically and has the coefficent of x^0 on the left.

   setDiff =. -.
   right =. ]
   left  =. [
   multInsert =. */
   sumInsert =. +/
   sumOblique =. +//.
   botRow =.  1&{
   topRow =.  0&{
   neg =. -
   integers =. i. 
   transpose =. |:
   append =.  ,.
   9!:3(5)
   
   NB. Now write the verbs :
   polyProd =. (sumOblique@multInsert/)"2
   vTermsMonad =. polyProd@(setDiff"2 1~)@(neg append"(0 1) 1:)@topRow
   cTermsMonad =.  botRow % multInsert"1@(neg (setDiff"1 0~))@topRow
   lagrangeMonad =. sumInsert@(cTermsMonad * vTermsMonad)@transpose@right
 
   vTermsDyad =. polyProd@(setDiff"2 1~)@(neg (append"0 1) 1:)@left
   cTermsDyad =.  right % multInsert"1@(neg setDiff"1 0~)@left
   lagrangeDyad =. sumInsert@(cTermsDyad * vTermsDyad)

   lagrange =. lagrangeMonad : lagrangeDyad 

   NB. Useage:
   (_1 0 1) lagrange (12 6 2)
6 _5 1
   lagrange  _1 0 1 append 12 6 2
6 _5 1

   shape =. $
   lagrange"2 s =. 2 3 2 shape 0 6 1 12 2 20 _1 12 0 6 1 2
6  5 1
6 _5 1
   (0 1 2 ,: _1 0 1) lagrange"(1 1) (6 12 20 ,: 12 6 2)
6  5 1
6 _5 1
   
