[GAP Forum] re: Generating Full Factorial Designs Using Nested Loops

John Dixon jdixon at math.carleton.ca
Fri Dec 31 15:20:00 GMT 2004

Bulutoglu Dursun A Civ AFIT/ENC wrote:

> 	Dear Gap Forum,
> 	I would like to write a function in GAP that will do the
> following computation:
> Input: g_1, g_2,  ..., g_t, a_1,a_2, ...,a_t
> 		Output: 
> 		U_{0 =<b_1=<g_1}  U_{0 =<b_2=<g_2} ... U_{0 =<b_t=<g_t}
> a_1*b_1+a_2*b_2+...+a_t*b_t
> 		Where U_{0 =<b_1=<g_1}  U_{0 =<b_2=<g_2} ... U_{0
> =<b_t=<g_t} is a nested union and the indices of the union are b_1 b_2
> ...b_t. This is a union of (g_1+1)*(g_2+1)*...*(g_t+1) numbers some of
> which could be the same. I was wondering how such a function could be
> written in GAP efficiently.

The function "addall" given below should work: the input is two 
lists a and g.  For example, addall([1,2,4],[1,1,1]) returns 
[0,1,2,3,4,5,6,7].  It uses the function "addone" so both 
programs must be loaded.

addone := function(S,a0,g0)
	local b,T;
	T := [];
	for b in [0,a0..a0*g0] do
		T := Union(T,List(S,s->s+b));
	return T;

addall := function(a,g)
	local S,i;
	S := [0];
	for i in [1..Length(a)] do
		S := addone(S, a[i], g[i]);
	return S;

- John D. Dixon

More information about the Forum mailing list