[GAP Forum] Re: Identical objects that are indices (not lists)

mike newman m.newman at qmul.ac.uk
Fri Apr 8 13:46:16 BST 2005


Thanks to those who made suggestions. I think either the conditional test
or the function solution works fine. they probably both have quite minimal
overhead compared with the guts of the inner loop. I would rather not have
two separate inner loops for mainatenance reasons.

mike

Steve Linton wrote:

> Robert Morse has suggested a solution based on duplicating the loop
> content and one based on a function. A slight variation of the
> function-based soltuion which moves the check of flag outside the function is:
> 
> abc := function(A,flag)
>     local i,j,d,f;
> 
>     d := Length(A);
>     if flag then f := i->i; else f := i->1; fi;
>     for i in [1..d] do for j in [f(i)..d] do
> 
> 
> What I would recommend though is the simpler:
> 
> abc := function(A,flag)
> 	local i,j,jj;
> 
> 	for i in [1..d] do 
>   	  if flag then
> 		jj := i;
> 	   else
> 		jj := 1;
> 	   fi;
> 
> 	   for j in [jj..d] do
> 	
> Although this conditional is executed d times, the cost of it will be pretty 
> small. If your "various functions" in the loop are at all non-trivial they will
> certainly dominate the cost of the conditionals and loops.
> 
> 	Steve




More information about the Forum mailing list