Question concerning a list sorting problem

84 Views Asked by At

I have the following question:

Let $a,b,c,d$ be four natural numbers with $a \leq b$ and $c\leq d$.

I have written a program that produces a list, which has as entries all 2-tuples $(x,y)$ with $x\in [a..b]$ and $y \in [c..d]$.

Now, I have a new list, let's call it list_1. It consists of elements indexed by the $(x,y)$.

For example, let a=3, b=4, c=7, d=8.

Then my programm produces list=[[3,7],[3,8],[4,7],[4,8]].

Now, my list_1 is [M_{3,7},M_{3,8},M_{4,7},M_{4,8}].

Then I take the direct sum of all modules in list_1 and call this direct sum $M$.

I would like to have a new list, call it list_2, which has exactly all direct summands of $M$ as entries.

In our example, list_2 looks like this:

$[(M_{3,7}),(M_{3,8}),(M_{4,7}),(M_{4,8}), (M_{3,7}\oplus M_{3,8}),(M_{3,7} \oplus M_{4,7}),(M_{3,7} \oplus M_{4,8}),(M_{3,8} \oplus M_{4,7}),(M_{3,8} \oplus M_{4,8}),(M_{4,7} \oplus M_{4,8}), (M_{3,7} \oplus M_{3,8} \oplus M_{4,7}),(M_{3,7} \oplus M_{3,8} \oplus M_{4,8}),(M_{3,7} \oplus M_{4,7} \oplus M_{4,8}),(M_{3,8} \oplus M_{4,7} \oplus M_{4,8}),(M_{3,7}\oplus M_{3,8} \oplus M_{4,7} \oplus M_{4,8})]$.

I would like to have this in general for arbitrary natural numbers $a,b,c,d$ with $a \leq b$ and $c\leq d$.

I would be very grateful, if somebody was able to send me a pseudo-code. I would like to implement this in GAP, or, more specifically, with the GAP package qpa.

Thanks for the help!

1

There are 1 best solutions below

2
On BEST ANSWER

Expanding my former comment, first we create a cartesian product of ranges:

gap> list1:=Cartesian([3..4],[7..8]);
[ [ 3, 7 ], [ 3, 8 ], [ 4, 7 ], [ 4, 8 ] ]

Then we may enumerate all non-empty combinations of k elements of list1 as follows:

gap> for k in [1..Length(list1)] do
>      iter:=IteratorOfCombinations(list1,k);
>      for c in iter do
>        Print(c,"\n");
>      od;
>    od;
[ [ 3, 7 ] ]
[ [ 3, 8 ] ]
[ [ 4, 7 ] ]
[ [ 4, 8 ] ]
[ [ 3, 7 ], [ 3, 8 ] ]
[ [ 3, 7 ], [ 4, 7 ] ]
[ [ 3, 8 ], [ 4, 7 ] ]
[ [ 3, 7 ], [ 4, 8 ] ]
[ [ 3, 8 ], [ 4, 8 ] ]
[ [ 4, 7 ], [ 4, 8 ] ]
[ [ 3, 7 ], [ 3, 8 ], [ 4, 7 ] ]
[ [ 3, 7 ], [ 3, 8 ], [ 4, 8 ] ]
[ [ 3, 7 ], [ 4, 7 ], [ 4, 8 ] ]
[ [ 3, 8 ], [ 4, 7 ], [ 4, 8 ] ]
[ [ 3, 7 ], [ 3, 8 ], [ 4, 7 ], [ 4, 8 ] ]

Hope it should be now easy to adapt this code to perform calculations that you have in mind.