To iterate over the power of a set, you can use itertools
as follows:
sage: itertools.product(M, repeat=3)
<itertools.product object at 0x7fa377e38f50>
Which is a generator that you can expand into al list to check its content is what you need:
sage: list(itertools.product(M, repeat=3))
[(
[1 0] [1 0] [1 0]
[0 1], [0 1], [0 1]
),
(
[1 0] [1 0] [0 1]
[0 1], [0 1], [1 0]
),
(
[1 0] [1 0] [1 1]
[0 1], [0 1], [0 1]
),
(
[1 0] [0 1] [1 0]
[0 1], [1 0], [0 1]
),
(
[1 0] [0 1] [0 1]
[0 1], [1 0], [1 0]
),
(
[1 0] [0 1] [1 1]
[0 1], [1 0], [0 1]
),
(
[1 0] [1 1] [1 0]
[0 1], [0 1], [0 1]
),
(
[1 0] [1 1] [0 1]
[0 1], [0 1], [1 0]
),
(
[1 0] [1 1] [1 1]
[0 1], [0 1], [0 1]
),
(
[0 1] [1 0] [1 0]
[1 0], [0 1], [0 1]
),
(
[0 1] [1 0] [0 1]
[1 0], [0 1], [1 0]
),
(
[0 1] [1 0] [1 1]
[1 0], [0 1], [0 1]
),
(
[0 1] [0 1] [1 0]
[1 0], [1 0], [0 1]
),
(
[0 1] [0 1] [0 1]
[1 0], [1 0], [1 0]
),
(
[0 1] [0 1] [1 1]
[1 0], [1 0], [0 1]
),
(
[0 1] [1 1] [1 0]
[1 0], [0 1], [0 1]
),
(
[0 1] [1 1] [0 1]
[1 0], [0 1], [1 0]
),
(
[0 1] [1 1] [1 1]
[1 0], [0 1], [0 1]
),
(
[1 1] [1 0] [1 0]
[0 1], [0 1], [0 1]
),
(
[1 1] [1 0] [0 1]
[0 1], [0 1], [1 0]
),
(
[1 1] [1 0] [1 1]
[0 1], [0 1], [0 1]
),
(
[1 1] [0 1] [1 0]
[0 1], [1 0], [0 1]
),
(
[1 1] [0 1] [0 1]
[0 1], [1 0], [1 0]
),
(
[1 1] [0 1] [1 1]
[0 1], [1 0], [0 1]
),
(
[1 1] [1 1] [1 0]
[0 1], [0 1], [0 1]
),
(
[1 1] [1 1] [0 1]
[0 1], [0 1], [1 0]
),
(
[1 1] [1 1] [1 1]
[0 1], [0 1], [0 1]
)]
Each element of this list is a triple of matrices, you can make the producst of each such triple as follows:
sage: [prod(i) for i in itertools.product(M, repeat=3)]
[
[1 0] [0 1] [1 1] [0 1] [1 0] [0 1] [1 1] [1 1] [1 2] [0 1]
[0 1], [1 0], [0 1], [1 0], [0 1], [1 1], [0 1], [1 0], [0 1], [1 0],
[1 0] [0 1] [1 0] [0 1] [1 1] [0 1] [1 0] [0 1] [1 1] [1 1]
[0 1], [1 1], [0 1], [1 0], [0 1], [1 1], [1 1], [1 2], [0 1], [1 0],
[1 2] [1 1] [1 1] [1 2] [1 2] [2 1] [1 ...
(more)