Bill Allombert on Tue, 25 Nov 2014 20:27:14 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

New gp function fold()


Dear PARI developers,

As discuted last year,

I have added a function 'fold' to GP 

fold(f,A) Apply the function f of arity 2 to the entries of A
 to return f(..., f(f(A[1],A[2]),A[3])... ,A[\#A]).

Some examples:

? fold((x,y)->x*y, [1,2,3,4])
%1 = 24
? fold((x,y)->[x,y], [1,2,3,4])
%2 = [[[1, 2], 3], 4]
? fold((x,f)->f(x), [2,sqr,sqr,sqr])
%3 = 256
? fold((x,y)->(x+y)/(1-x*y),[1..5])
%4 = -9/19
? bestappr(tan(sum(i=1,5,atan(i))))
%5 = -9/19

Cheers,
Bill