#A latin square is an nxn matrix with n symbols in each row and each column #One can turn a latin square into an orthogonal array by making a 3 tuple(i,j,z) #such that i is the row, j is the column, and z is the ijth entry #Make from sage.combinat.matrices.latin import * K4 = LatinSquare(matrix(ZZ, [[0,1,2,3], [1,0,3,2], [2,3,0,1], [3,2,1,0]])) K4

[0 1 2 3]
[1 0 3 2]
[2 3 0 1]
[3 2 1 0]

C4 = LatinSquare(matrix(ZZ, [[0,1,2,3], [1,2,3,0], [2,3,0,1], [3,0,1,2]])) C4

[0 1 2 3]
[1 2 3 0]
[2 3 0 1]
[3 0 1 2]

#vertices are indices def MakeOrthogonalArray(M): if not M.is_latin_square(): # check M is a latin square return False n = M.nrows()#order of M array = [(i,j) for i in range(n) for j in range(n)] OA = [] for x in array: OA.append(x+(M[x],)) return OA

MakeOrthogonalArray(C4)

[(0, 0, 0), (0, 1, 1), (0, 2, 2), (0, 3, 3), (1, 0, 1), (1, 1, 2), (1, 2, 3), (1, 3, 0), (2, 0, 2), (2, 1, 3), (2, 2, 0), (2, 3, 1), (3, 0, 3), (3, 1, 0), (3, 2, 1), (3, 3, 2)]

def LatinSquareGraph(M): OA = MakeOrthogonalArray(M) G = Graph() G.add_vertices(OA) edges = [] for u in OA: for v in OA: if u!= v: if (v,u) not in edges: if u[0] == v[0]: edges.append((u,v)) elif u[1] == v[1]: edges.append((u,v)) elif u[2] == v[2]: edges.append((u,v)) G.add_edges(edges) return G

LatinSquareGraph(C4).show(figsize=3)

LatinSquareGraph(K4).show(figsize=3)

def checkLSGareIsomorphic(A,B): return LatinSquareGraph(A).is_isomorphic(LatinSquareGraph(B))

checkLSGareIsomorphic(K4,C4)

False

from sage.combinat.designs.latin_squares import mutually_orthogonal_latin_squares MOLS3 = mutually_orthogonal_latin_squares(2, 3)

checkLSGareIsomorphic(LatinSquare(MOLS3[0]),LatinSquare(MOLS3[1]))

True

from itertools import combinations def CheckSetOfMOLSIsomorphic(n): MOLS = mutually_orthogonal_latin_squares(n-1, n) k = len(MOLS) domain = combinations(range(k),2) TruthTable = [] for x in domain: boolean = checkLSGareIsomorphic(LatinSquare(MOLS[x[0]]),LatinSquare(MOLS[x[1]])) if boolean == False: break else: TruthTable.append(boolean) return set(TruthTable)

l = [3,4,5,7,8,9,11,13] for i in l: CheckSetOfMOLSIsomorphic(i)

set([True])
set([True])
set([True])
set([True])
set([True])
set([True])
set([True])

Error in lines 2-3
Traceback (most recent call last):
File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1188, in execute
flags=compile_flags), namespace, locals)
File "", line 2, in <module>
File "", line 7, in CheckSetOfMOLSIsomorphic
File "", line 2, in checkLSGareIsomorphic
File "", line 9, in LatinSquareGraph
File "src/cysignals/signals.pyx", line 320, in cysignals.signals.python_check_interrupt

#i believe these were the latin squares reffered to #https://www.sciencedirect.com/science/article/pii/0315086081900057 A = LatinSquare(matrix(ZZ,[[0,4,1,7,2,9,8,3,6,5], [8,1,5,2,7,3,9,4,0,6], [9,8,2,6,3,7,4,5,1,0], [5,9,8,3,0,4,7,6,2,1], [7,6,9,8,4,1,5,0,3,2], [6,7,0,9,8,5,2,1,4,3], [3,0,7,1,9,8,6,2,5,4], [1,2,3,4,5,6,0,7,8,9], [2,3,4,5,6,0,1,8,9,7], [4,5,6,0,1,2,3,9,7,8]])) B = LatinSquare(matrix(ZZ, [[0,7,8,6,9,3,5,4,1,2], [6,1,7,8,0,9,4,5,2,3], [5,0,2,7,8,1,9,6,3,4], [9,6,1,3,7,8,2,0,4,5], [3,9,0,2,4,7,8,1,5,6], [8,4,9,1,3,5,7,2,6,0], [7,8,5,9,2,4,6,3,0,1], [4,5,6,0,1,2,3,7,8,9], [1,2,3,4,5,6,0,9,7,8], [2,3,4,5,6,0,1,8,9,7]])) checkLSGareIsomorphic(A,B)

True

C4inverse = LatinSquare(matrix(ZZ, [[0,3,2,1], [1,0,3,2], [2,1,0,3], [3,2,1,0]]))

checkLSGareIsomorphic(C4,C4inverse)

True

A = LatinSquare(matrix(ZZ,[[0,4,1,7,2,9,8,3,6,5], [8,1,5,2,7,3,9,4,0,6], [9,8,2,6,3,7,4,5,1,0], [5,9,8,3,0,4,7,6,2,1], [7,6,9,8,4,1,5,0,3,2], [6,7,0,9,8,5,2,1,4,3], [3,0,7,1,9,8,6,2,5,4], [1,2,3,4,5,6,0,7,8,9], [2,3,4,5,6,0,1,8,9,7], [4,5,6,0,1,2,3,9,7,8]])) B = LatinSquare(matrix(ZZ, [[0,7,8,6,9,3,5,4,1,2], [6,1,7,8,0,9,4,5,2,3], [5,0,2,7,8,1,9,6,3,4], [9,6,1,3,7,8,2,0,4,5], [3,9,0,2,4,7,8,1,5,6], [8,4,9,1,3,5,7,2,6,0], [7,8,5,9,2,4,6,3,0,1], [4,5,6,0,1,2,3,7,8,9], [1,2,3,4,5,6,0,9,7,8], [2,3,4,5,6,0,1,8,9,7]])) checkLSGareIsomorphic(A,B)

True

z3z3 = LatinSquare(matrix(ZZ, [ [0,1,2,3,4,5,6,7,8], [1,2,0,4,5,3,7,8,6], [2,0,1,5,3,4,8,6,7], [3,4,5,6,7,8,0,1,2], [4,5,3,7,8,6,1,2,0], [5,3,4,8,6,7,2,0,1], [6,7,8,0,1,2,3,4,5], [7,8,6,1,2,0,4,5,3], [8,6,7,2,0,1,5,3,4]])) patchedgalois = LatinSquare(matrix(ZZ, [[0,1,2,3,4,5,6,7,8], [2,0,1,6,8,7,3,5,4], [3,6,0,4,7,1,8,2,5], [4,8,7,0,2,3,5,6,1], [5,7,1,3,0,8,2,4,6], [6,3,8,5,2,0,4,1,7], [7,5,2,6,4,1,0,8,3], [8,4,5,1,6,7,3,0,2], [8,4,5,1,6,7,3,0,2]])) checkLSGareIsomorphic(z3z3,patchedgalois)

False

LatinSquareGraph(z3z3)

Graph on 64 vertices

LatinSquareGraph(patchedgalois)

Graph on 64 vertices