Ask Your Question
0

Changing symmetric elements in a matrix

asked 2021-08-18 17:15:32 +0100

phcosta gravatar image

Hello, I hope you are doing fine. I have the matrix below:

def p(*t):
   return SR.var(('p' + '_{}'*len(t)).format(*[str(i) for i in t]))
S = FiniteEnumeratedSet([1,2]) 
P = cartesian_product([S]*2)
M = {}
for (row, (i,j)) in enumerate(P):
   for (col, (k,l)) in enumerate(P):
      if i<=j:
         M[(row, col)] = p(i,j,k,l)
      elif i!=j:
         M[(row, col)] = p(i,j,k,l)
m = matrix(M)

This return the matrix:

m
[p_1_1_1_1 p_1_1_1_2 p_1_1_2_1 p_1_1_2_2]
[p_1_2_1_1 p_1_2_1_2 p_1_2_2_1 p_1_2_2_2]
[p_2_1_1_1 p_2_1_1_2 p_2_1_2_1 p_2_1_2_2]
[p_2_2_1_1 p_2_2_1_2 p_2_2_2_1 p_2_2_2_2]

I would like to apply the symmetry property that I have in the system which guarantees p(i,j,k,l) = p(j,i,l,k). In this case, M = {1,2} it is easy to do manually, but if M = {1,2,3}, for instance, it is much more complicated.

So basically, I would like to exchange the elements in such a way that:

m
[p_1_1_1_1 p_1_1_1_2 p_1_1_1_2 p_1_1_2_2]
[p_1_2_1_1 p_1_2_1_2 p_1_2_2_1 p_1_2_2_2]
[p_1_2_1_1 p_1_2_1_2 p_1_2_1_2 p_1_2_2_2]
[p_2_2_1_1 p_2_2_1_2 p_2_2_1_2 p_2_2_2_2]

Any suggestions?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-08-18 22:25:37 +0100

Max Alekseyev gravatar image

Change function p to:

def p(*t):
   t = min( (t[1],t[0],t[3],t[2]), t )
   return SR.var(('p' + '_{}'*len(t)).format(*[str(i) for i in t]))

which will use the symmetry and use lexicographically smallest indices.

edit flag offensive delete link more

Comments

Thanks. it is possible to assign values to ps, for example p(1,1,1,1) = 1.

phcosta gravatar imagephcosta ( 2021-08-19 03:58:13 +0100 )edit

Yes - for example, m.subs({p(1,1,1,1):1}).

Max Alekseyev gravatar imageMax Alekseyev ( 2021-08-19 04:31:19 +0100 )edit

Thank you.

phcosta gravatar imagephcosta ( 2021-08-19 04:33:45 +0100 )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: 2021-08-18 17:15:32 +0100

Seen: 150 times

Last updated: Aug 18 '21