# Changing symmetric elements in a matrix

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

Sort by ยป oldest newest most voted

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.

more

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

( 2021-08-19 03:58:13 +0200 )edit

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

( 2021-08-19 04:31:19 +0200 )edit

Thank you.

( 2021-08-19 04:33:45 +0200 )edit