Power serious: power series in ten one-liners

Extra rules for empty lists will make the operations work also on

finite-length inputs (polynomials) and allow coerced scalars to be finite series.

Reference: M. D. McIlroy, The music of streams (.ps.gz),

Information Processing Letters 77 (2001) 189-195.

Function definitions

s

t

Coerce scalar to series

series f = f : repeat 0 fromInteger c = series(fromInteger c)

Negation

Addition

(f:ft) + (g:gt) = f+g : ft+gt

Multiplication

Division

Subtraction, integer power

recip

Composition ( # )

Reversion (compositional inverse)

Integration

int fs = 0 : zipWith (/) fs [1..] -- integral from 0 to x

Differentiation

diff (_:ft) = zipWith (*) ft [1..] -- type (Num a,Enum a)=>[a]->[a]

Examples

2

1+(0:1)^2

1:0:1

2

sins = int coss coss = 1 - int sins

[[1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1], ...]::[[Rational]]

Complete packages

take 10 tans

diff

(Sorry, package file extensions are .txt to placate some browsers.

And some browsers render minus signs in these programs as hyphens on the screen.)

Extensions to handle polynomials make a practical package, doubled in size,

not as pretty, but much faster and capable of feats like pascal .

To see the dramatic speedup, try a bigger test like take 20 tans .

Why is finite more complicated than infinite? The end must be detected, if nothing else.

Colophon