Bill Allombert on Fri, 12 Oct 2007 00:44:45 +0200


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

Re: Functions as first-class objects


On Thu, Oct 11, 2007 at 01:45:48PM -0700, John Jones wrote:
> Hi,
> 
> I may be doing something stupid, but I couldn't successfully apply the 
> patch (I tried against 2.3.2 and against cvs and parts were rejected in 
> both cases).

It probably applied to the CVS version at the time I made it... or
not. Well I have just released a tarball there:
<http://pari.math.u-bordeaux.fr/~bill/pari-2.4.2.bill1.tar.gz>
that also include the F2x patch. That should help.

> But, this is a feature I wished gp had so I am glad to see it might be 
> incorporated.  Hopefully "map(function, vector)" and "select(vector, 
> function)" can then become standard gp functions.

And if not, you will be able to implement them in GP!

? map(f,v)=vector(#v,i,f(v[i]))
%1 = (f,v)->vector(#v,i,f(v[i]))
? map(x->x^2,[1,2,3,4])
%2 = [1, 4, 9, 16]

Note that we can finally define Church numerals in GP:

zero=f->x->x
one =f->f
two =f->x->f(f(x))
three=f->x->f(f(f(x)))
inc= n->f->x->f((n(f))(x))
add= (n,m)->f->x->(n(f))((m(f))(x))
mul= (n,m)->f->n(m(f))
pow= (n,m)->m(n)
disp=n->(n(x->1+x))(0)
disp(mul(add(two,three),add(two,two)))
disp(pow(add(two,three),add(two,two)))

Cheers,
Bill.