Lorenz Minder on Thu, 01 Oct 2009 08:02:32 +0200

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

Re: experimental patch for iferr


> Please find attached a patch that add a new function iferr()

Great!  I think this is going to be very useful.

> ? ?iferr
> iferr(seq1,E,{seq2},{seq3}): evaluates the expression sequence seq1. if an
> error occurs, seq2 is evaluated with the variable E set to the error data,
> otherwise seq3 is evaluated. The arguments seq2 and seq3 are optional, and
> if
> seq3 is omitted, the preceding comma can be omitted also.
> This is a very crude ECM implementation:
> ecm(N,a,B)=
> {
>   my(E=ellinit([0,0,0,a,1]*Mod(1,N)));
>   iferr(ellpow(E,[0,1]*Mod(1,N),B),
>     err,if(err[1]==20,return(gcd(lift(err[2]),N)),error(E)));
>   0
> }
> ? ecm(2^32+1,1,100!)
> %1 = 641
> ? ecm(2^64+1,1,200!)
> %2 = 274177

Shortest ECM ever. :-)

I played around with this patch a bit, and here are a couple of things
I observed.

1) A bug I noticed:

? iferr(1/0, E, iferr(8, E, E, E), E)
  ***   lbot>ltop in gerepile.
  ***   Break loop: type <Return> three times, or Control-d, to go back to GP)

2) I'd prefer if the second argument was a reference, i.e., one would write

   iferr(whatever, &E, seq1, seq2)

Right now it seems that this is the only function in GP that
modifies an argument that was (syntactically) passed by value.  I have
no idea if this is difficult to do.  (I've no time for studying
source code ATM, unfortunately.)

Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser