Karim BELABAS on Tue, 4 Jan 2000 17:12:22 +0100 (MET) |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: bug |
[James G. McLaughlin:] > I was trying to convert a magma program to gp and got a "segmentation > fault, bug in gp " message when I tried to run it. Any ideas on how to fix > it greatly appreciated. (Magma program below, followed by gp version.) Running your script on GP version 2.0.18, I get (I was trapping all errors): *** not a set in setintersect. *** Starting break loop (type 'break' to go back to GP): *** ...length(setintersect(S,[r])),TT=concat(TT,r),b ^-------------------- This I corrected by replacing all occurences of setintersect as follows: if(length(setintersect(S,[r])), becomes if(setsearch(S,r), \\ = if (r in S) I then obtained *** incorrect type in negation. *** Starting break loop (type 'break' to go back to GP): *** ...-1,r=S[ii]+se*(S[j]-S[ii]);S=Set(S);if(setsea ^-------------------- I corrected this by replacing the line S = Set(S) by TS = Set(S) and all occurences of S in "set context" by this TS (actually, I moved the assignment outside a number of enclosing loops since S was not modified in there and it is quite costly to turn an object into a set. I did the same for the other TS = Set(S) which appeared several lines below) Then I had *** array index (7) out of allowed range [1-6]: S=concat(S,[S[jj]+1+a[ *** jj]]););n=length(S); ^-------------------- Then I gave up. Some observations: * you can use v++ instead of v = v+1; ltt-- instead of ltt = ltt-1, etc. * break; is equivalent to break(1); * if( v - k,, w= w+1); is the same (but slower and more obfuscated) as if (v == k, w++); * if IsEven(n) then bnn:= Append(bnn,0); n:= Z!(n/2); end if; if IsOdd(n) then bnn:= Append(bnn,1); n:= Z!((n-1)/2); end if; was translated as: if(floor(1/gcd(n,2)), bnn=concat(bnn,[1]) , bnn=concat(bnn,[0])); if(floor(1/gcd(n,2)), n=(n-1)/2, n=n/2); To check for parity, I'd rather use IsOdd(n) = n % 2 IsEven(n) = !IsOdd(n) and I'd use a right shift to shift the digits. I.e bnn = concat(bnn, n % 2); n >>= 1; In any case, the whole loop looks like what bnn = binary(n) would produce [ except you get the bits from high to low order. To get them in the same order as the first magma loop, use bnn = extract(binary(n), "-1..1"). Which shouldn't be necessary since the next loop was intended to invert the bits anyway... ] Good luck, Karim. __ Karim Belabas email: Karim.Belabas@math.u-psud.fr Dep. de Mathematiques, Bat. 425 Universite Paris-Sud Tel: (00 33) 1 69 15 57 48 F-91405 Orsay (France) Fax: (00 33) 1 69 15 60 19 -- PARI/GP Home Page: http://hasse.mathematik.tu-muenchen.de/ntsw/pari/