Ask Your Question
0

How to get selective outputs printed

asked 2023-03-30 08:34:25 +0200

mak3521 gravatar image

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 flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2023-03-30 12:15:13 +0200

Emmanuel Charpentier gravatar image

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.
    # see https://ask.sagemath.org/question/67166/test-for-set-equality/
    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]]          
]
edit flag offensive delete link more

Comments

Thanks a lot.

mak3521 gravatar imagemak3521 ( 2023-04-05 12:37:25 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-03-30 08:34:25 +0200

Seen: 400 times

Last updated: Mar 30 '23