| Karim BELABAS on Wed, 4 Jun 2003 21:06:32 +0200 (MEST) |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: GEN serialisation |
On Wed, 4 Jun 2003, Gonzalo Tornaria wrote:
> As a first idea (to check my prototype implementation), I thought of
> using GENtostr and readseq.
> Question: is it guaranteed that
>
> readseq(GENtostr(x),0) == x
>
> provided GEN x is well formed?
No. Rounding problems for instance (internal is base 2^BITS_IN_LONG, output
is base 10).
Besides you should use flisexpr() [ which is documented and slightly less
cryptic ]
> I think the "lontyp" array is for this, but I'm not familiar with it. My
> understanding is the following:
>
> say we have a GEN x, and let lt=lontyp[typ(x)], len=lg(x).
>
> * if lt=0, the type is not recursive:
>
> * if lt>0, the type is recursive,
> with lt codewords, and the rest is more GENs
Correct.
> recv_GEN(GEN *data, int count)
> {
> for(int i=0; i<count; i++)
> {
> long codeword; /* a "pseudo-GEN" */
> GEN x=data[i];
> long lt, len;
>
> recv_long(&codeword, 1); /* get the type and length */
> lt=lontyp[typ(&codeword)];
That's dangerous, it assumes x[0] contains the typ() [ it's documented this
way, but it's the kind of dependency I'd rather do without. ]
> len=lg(&codeword);
Same here.
> x[0]=codeword; /* is this necesary ??? */
No it's not.
> Am I missing something???
If some machines are compiled with a GMP kernel, and some with the native
one, or if endianness or sizeof(long) differ, you'll run into trouble.
There's also a big problem with variable numbers. You have to make sure that
all processes have defined the same number of variables [ otherwise
transmiting and using a GEN involving an undefined variable number will very
probably trigger a SEGV ]
[ note that my previously posted solution only deals with the first problem
:-( ]
> Is it guaranteed that the first codeword has only length and type
> information??? I.e., after doing
>
> x=cgetg(lg(&codeword), typ(&codeword)),
>
> is it guaranteed that
>
> x[0]==codeword
No. You lose the "clone bit". In any case, it's very unsafe to act on words
without using the documented API ( there's been a few proposals to change the
internal representation already ).
Cheers,
Karim.
--
Karim Belabas Tel: (+33) (0)1 69 15 57 48
Dép. de Mathématiques, Bât. 425 Fax: (+33) (0)1 69 15 60 19
Université Paris-Sud http://www.math.u-psud.fr/~belabas/
F-91405 Orsay (France) http://www.parigp-home.de/ [PARI/GP]