Question: Quick way to find duplicates in a matrix and set the elements equal to one another

I wrote some procedures in an older version of Maple to sort through a matrix and find repeated elements, and then set the matrix elements equal to one another. As an example, consider the matrix:

Matrix(4, 4, {(1, 1) = 31774769/38880000, (1, 2) = -90858559/233280000, (1, 3) = -76547233/69984000, (1, 4) = -119275567/139968000, (2, 1) = -90858559/233280000, (2, 2) = 1506841/6480000, (2, 3) = 442249/720000, (2, 4) = 85514221/116640000, (3, 1) = -76547233/69984000, (3, 2) = 442249/720000, (3, 3) = 592249771/349920000, (3, 4) = 121562339/87480000, (4, 1) = -119275567/139968000, (4, 2) = 85514221/116640000, (4, 3) = 121562339/87480000, (4, 4) = 170546323/87480000}, datatype = anything, storage = rectangular, order = Fortran_order, shape = [])
Due to its symmetric nature the upper triangular matrix is just the same as the lower triangular. i.e. the elements are equal: (2,1)=(1,2), (3,1)=(1,3) etc...

I have attached a minimal working example Maple script, which processes an input matrix, finds repeats and sets the elements equal to one another (e.g. [1,2]=[2,1], literally printing this) and saves the output to a file using a specific format for processing by another program. The matrix in the file is numeric but the actual matrices contain a lot of algebraic terms and can get quite large. This is where my procedures struggle as they take a very, very long time to process larger algebraic matrices to group the repeats. Is there a more Maple friendly way of going about this problem rather than these "archaic" procedures?

Here is the script:

duplicates_matrix_.mw

Thank you in advance

-Yeti

Please Wait...