Karim Belabas on Sat, 21 Jan 2006 09:55:19 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Two suggestions: |
* John Cremona [2006-01-18 17:31]: > (2) The elliptic curve databes holds each curve's id as a string, for > example "20160cy2". It would be convenient to be able to simply split > this into 3 components, for example [20160,"cy",2]. With Bill's help I > have written a gp function to do this: > > { > code2seq(code)=local(v,N=0,num=0,i=1,i1,class); > v=Vecsmall(code); > while(v[i]<58,N=10*N+v[i]-48;i++); > i1=i; > while(v[i]>57,i++); > class=Strchr(vector(i-i1,j,v[i1+j-1])); > while(i<=length(v),num=10*num+v[i]-48;i++); > [N,class,num] > } > > But this direct manipulation of the vector of ASCII codes is rather > awkward. Surely there would be other places in which some string > manipulation would be helpful? Can we add this to the wish-list please? An off-topic answer, which might be useful in another context; using a high-level external filter is a good alternative: code2seq(code) = { extern("echo " code "|perl -ne 'm/([0-9]+)([a-z]+)([0-9]+)/; print \"[$1,\\\"$2\\\",$3]\" ' ") } (20:16) gp > code2seq("20160cy2") %1 = [20160, "cy", 2] Cheers, Karim. P.S: for more complicated processing, an external script will be cleaner of course, it's a pain to escape all those quotes and backslashes. Also, my variant is unfortunately orders of magnitude slower than your "awkward" approach. -- Karim Belabas Tel: (+33) (0)5 40 00 26 17 Universite Bordeaux 1 Fax: (+33) (0)5 40 00 69 50 351, cours de la Liberation http://www.math.u-bordeaux.fr/~belabas/ F-33405 Talence (France) http://pari.math.u-bordeaux.fr/ [PARI/GP]