# How to get selective outputs printed

After running my code

 -------------------
if................
show((x,y,z))


The output is a collection of list of triplets of square matrices of same order.

I want only those output to be printed which contain same set of three matrices, keeping the first matrix fixed.

That is, for example, suppose I am getting the following outputs:

1.[A1,P,Q]

2.[A1,Q,P]

3.[P,Q,A1]

4.[A2,L,M]

5.[A2,M,L]

6.[A2,X,Y]

7.[Q,L,A1]

Now consider the first three outputs . The first two outputs are to be considered same. But the third output is to be considered different, though all three outputs contain same set of matrices. So, first and third need only be printed.. Similarly , as fourth and fifth outputs are same, I want only fourth output to be printed and not the fifth one. And so on…

edit retag close merge delete

Sort by » oldest newest most voted

You may try this :

A1, A2, L, M, P, Q, X, Y = (MatrixSpace(QQ, 2).random_element()
for u in range(8))
LL = [[A1,P,Q], [A1,Q,P], [P,Q,A1], [A2,L,M], [A2,M,L], [A2,X,Y], [Q,L,A1]]
def is_sim(x,y):
if not bool(x[0] == y[0]): return False
# Testing for Sets equality is problematic.
if any([u not in Set(x[1:]) for u in Set(y[1:])]): return False
if any([u not in Set(y[1:]) for u in Set(x[1:])]): return False
return True
R = LL[0]
for u in LL[1:]:
if not any([is_sim(u, v) for v in R]):
R.append(u)


which gives :

sage: R

[
[[-1/2 -1/2]
[   2    0], [ 0  0]
[-1/2 -1/2]  [ 0 -1]  [ 0  0]  [ 0 -1], [ 0 -1]
[   2    0], [ 0 -2], [ 0 -1], [ 0 -2]]            ,

[[ 0 -1]              [[ 0 -1]                [[ 0 -1]
[ 0 -2], [ 0  0]      [ 0 -2], [1/2   0]      [ 0 -2], [1/2   1]
[ 0 -1], [-1/2 -1/2]  [  1  -1], [-1/2    0]  [  0  -1], [-1 -1]
[   2    0]]        , [   1   -1]]          , [ 2  0]]          ,

[[ 0  0]
[ 0 -1], [1/2   0]
[  1  -1], [-1/2 -1/2]
[   2    0]]
]

more

Thanks a lot.

( 2023-04-05 12:37:25 +0100 )edit