NB. Some Definitions for Polynomial Arithmetic NB. The coefficients of a polynomial are written NB. in ascending order, i.e., NB. (x^3)+(2*x)+5 is represented by the list of NB. coefficients 5 2 0 1 peval =: #. |. NB. 3 peval 5 2 0 1 NB.38 NB. Polynomial sum (list args) psum =: +/ @ ,: & ,: NB. 1 2 psum 1 3 1 NB.2 5 1 NB. 3 psum 1 3 1 NB.4 3 1 NB. 1 3 1 psum 3 NB.4 3 1 NB. Polynomial sum (boxed list args) psumb =: psum &. > NB. <1 2 NB.+---+ NB.|1 2| NB.+---+ NB. <1 3 1 NB.+-----+ NB.|1 3 1| NB.+-----+ NB. (<1 2) psumb < 1 3 1 NB.+-----+ NB.|2 5 1| NB.+-----+ NB. Polynomial difference pdif =: -/ @ ,: & ,: NB. Polynomial product (list args) pprod =: +/ /. @ (*/) NB. 1 2 pprod 1 3 1 NB.1 5 7 2 NB. Polynomial product (boxed list args) pprodb =: pprod &. > NB. (<1 2) pprodb <1 3 1 NB.+-------+ NB.|1 5 7 2| NB.+-------+ NB. Polynomial derivative pderiv =: 1: }. ] * i. @ # NB. pderiv 1 3 3 1 NB.3 6 3 NB. Use box to build a matrix whose elements NB. are polynomials. For example, m =: 2 2 $ 1 2 ; 1 2 1 ; 1 3 3 1 ; 1 4 6 4 1 NB. m NB.+-------+---------+ NB.|1 2 |1 2 1 | NB.+-------+---------+ NB.|1 3 3 1|1 4 6 4 1| NB.+-------+---------+ n =: 2 3 $ 1 2 3 ; 3 2 1 ; 1 0 1 ; 3 3 3 3 ; _1 _2 3; 3 4 5 NB. n NB.+-------+-------+-----+ NB.|1 2 3 |3 2 1 |1 0 1| NB.+-------+-------+-----+ NB.|3 3 3 3|_1 _2 3|3 4 5| NB.+-------+-------+-----+ NB. Polynomial inner product (boxed args) pmp =: psumb / . pprodb NB. Then, we have NB. m pmp n NB.+---------------------+---------------+------------------+ NB.|4 13 19 18 9 3 |2 4 3 6 3 |4 12 17 16 5 | NB.+---------------------+---------------+------------------+ NB.|4 20 45 61 56 36 15 3|2 5 5 8 14 11 3|4 19 43 60 52 25 5| NB.+---------------------+---------------+------------------+ NB. Some tools for reading the data. read =: 1!:1@< from =: { drop =: }. do =: ". data =: read'data1926-97' NB. Edit the - signs to _ using ammend data1 =: '_' (('-' = data) # i. #data) } data NB. Form the lines of input cut =: ;. data2 =: < cut _2 data1 NB. Build the data matrix. get_rows =: monad define do cut _2 (>y.),' ' ) data3 =: 0 from get_rows data2 NB. First differences diff1 =: (1 drop data3) - _1 drop data3 NB. Second differences diff2 =: (1 drop diff1) - _1 drop diff1