James G. McLaughlin on Mon, 27 Dec 1999 21:09:46 -0600 (CST)


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

bug


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.)
		Jimmy Mc Laughlin.

Magma Version:


for k:=4 to 7 do;
	rr:=k;
	ram:= k;
	vvv:= 0;
	print rr;
	SS:= [];
	Q:= RationalField();
	Z:= Integers(Q);
	for m:= 2^rr to 2^(rr+1)-1 do
		bnn:=[];
		n:= m;
			while n ne 0 do
				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;
			end while;
		nb:= #bnn;
		bn:= [];
		for i:= 1 to nb do
			bn:= Append(bn,bnn[nb-i+1]);
		end for;
		SS:= Append(SS,bn);
	end for;
	for a in SS do
		S:= [1];
		for jj:= 1 to rr+1 do
			S:= Append(S,S[jj]+1 + a[jj]);
		end for;
		n:= #S; 
		w:= 0;
		for i:= 1 to n-k+1 do;
			for j:= i+1 to n-k + 2 do	
				if S[j]-S[i] gt (S[n]-S[i])/(k-1) then
					break j;
				end if;
				v:= 2;
				TT:= [S[i],S[j]];
				for s:= 2 to k-1 do
					r:= S[i]+s*(S[j]-S[i]);
					if not r in S then break ;
					end if;
					if r in S then TT:= Append(TT,r);
						v:= v+1;
					end if;
				end for;
				if v eq k then w:= w+1; 
					SS:= Exclude(SS,a);				  ;
				end if;
			end for;
		end for;
		if w eq 0 then  vvv:= vvv+1                 ;
		end if;
	end for;
	for rr:= k+1 to 1000 do
		rt:=0;
		vvv:= 0;
		t:= #SS;
		for i:= 1 to t do
			b:= SS[i];
			b:= Append(b,1);
			SS[i]:= Append(SS[i],0);
			SS:= Append(SS,b);
		end for;
		for a in SS do
			S:= [1];
			for jj:= 1 to rr+1 do
				S:= Append(S,S[jj]+1 + a[jj]);
			end for;
			n:= #S; 
			w:= 0;
			for i:= 1 to n-k+1 do;
				for j:= i+1 to n-k + 2 do		
					if S[j]-S[i] gt (S[n]-S[i])/(k-1) then
						break j;
					end if;
					v:= 2;
					TT:= [S[i],S[j]];
					for s:= 2 to k-1 do
						r:= S[i]+s*(S[j]-S[i]);
						if not r in S then break ;
						end if;
						if r in S then TT:= Append(TT,r);
							v:= v+1;
						end if;
					end for;
					if v eq k then w:= w+1;
						SS:= Exclude(SS,a)  ; break i;
					end if;
				end for;
			end for;
			if w eq 0 and rt eq 0 then print  rr, #SS,S; 
				vvv:= vvv+1;    rt:= rt+1;             
			end if;
		end for;
		if vvv eq 0 then break;
		end if;
	end for;
end for;




gp version (with some modifications since certain functions such as
"Exclude" do not exist in gp and also separate if loops for each "if" 
command and also "if" conditions phrased differently since "if" commands
work differently in magma and gp )


{for( k = 4, 7,
	rr = k;
	ram = k;
	vvv = 0;
	print(rr);
	SS= [];
	for( m= 2^rr,  2^(rr+1)-1 ,
		bnn=[];
		n= m;
			while (n, 
				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);
			);
		nb = length(bnn);
		bn = [];
		for(ii = 1,  nb,
			bn = concat(bn,[bnn[nb-ii+1]]);
		);
		SS = concat(SS,[bn]);
	);
	ltt = length(SS);
	for(tu = 1, ltt ,
		a = SS[tu];
		S= [1];
		for( jj = 1,  rr+1 ,
			S = concat(S,[S[jj]+1 + a[jj]]);
		);
		n = length(S); 
		w = 0;
		for( ii = 1,  n-k+1 ,
			for( j= ii+1,  n-k + 2 ,	
				if(floor(((S[n]-S[ii])/(k-1))/(S[j]-S[ii])),,break(1));
				v= 2;
				TT= [S[ii],S[j]];
				for (se = 2,  k-1 ,
					r = S[ii]+se*(S[j]-S[ii]);
					S = Set(S);
					if(length(setintersect(S,[r])),
						TT= concat(TT,r), break(1) );
					if(length(setintersect(S,[r])),
					v= v+1, break(1) );
				);
				Tr =[];
					if( v - k,, 	for(sp = 1,ltt,
								if(a ==
							SS[sp],ltt=ltt-1,Tr = concat(Tr,[SS[sp]]));
							);
						SS = Tr
					);
					if( v - k,, w= w+1);
			);			
		); 
		if( w,,   vvv = vvv+1);   
	);
	for( rrr = ram + 1,  100 ,
		rt=0;
		vvv= 0;
		t = length(SS);
		for( ii= 1,  t ,
			b= SS[ii];
			b= concat(b,[1]);
			SS[ii] = concat(SS[ii],[0]);
			SS= concat(SS,[b]);
		);
		ltt = length(SS);
		for(ts = 1,ltt,
			a = SS[ts];
			S = [1];
			for( jj= 1,  rrr+1 ,
				S = concat(S,[S[jj]+1 + a[jj]]);
			);
			n= length(S); 
			w = 0;
			for( ii= 1,  n-k+1,
				for( j= ii+1,  n-k + 2 ,
					if(floor(((S[n]-S[ii])/(k-1))/(S[j]-S[ii])),,break(1));
					v= 2;
					TT= [S[ii],S[j]];
					for( sr = 2,  k-1 ,
						ww = S[ii]+sr*(S[j]-S[ii]);
						TS = Set(S);
						if(length(setintersect(TS,[ww])),  
							v= v+1, break(1) );	
						if(length(setintersect(TS,[ww])),  
							TT= concat(TT,r), break(1));
					);
					if( v - k,,  w= w+1);
					if( v - k,, 	for(sp = 1,ltt,
								if(a ==
								SS[sp],ltt=ltt-1,Tr = concat(Tr,[SS[sp]]));
							); 
					SS = Tr);
					if( v - k,,  break(2));
				);
			);
			if( w + rt,,print(rrr,",", length(SS),",",S));  
 			if( w + rt,,vvv= vvv+1);
  			if( w + rt,,rt= rt+1);        
		);
		if( vvv,, break(1));
	);
);}