1 | initial version |

If you remove "signed" from your question this is equivalent to the isomorphism problem of vertex and edge labeled directed graphs. To do that in Sage let us define the following auxilliary function that turns a matrix into a (edge labeled) directed graph

```
def mat_to_dig(A):
n = A.nrows()
G = DiGraph(loops=False, multiedges=False)
for i in range(n):
for j in range(n):
if A[i,j]:
G.add_edge(i, j, A[i,j])
return G
```

Now, (assuming that I care about matrix with 0 on the diagonal)

```
sage: A = matrix(4, [0,1,2,3,4,0,5,6,7,8,0,9,10,11,12,0])
sage: p = Permutation('(1,3)(2,4)')
sage: B = copy(A)
sage: B.permute_rows_and_columns(p,p)
sage: G = mat_to_dig(A)
sage: H = mat_to_dig(B)
sage: G.is_isomorphic(H, edge_labels=True, certificate=True)
(True, {0: 2, 1: 3, 2: 0, 3: 1})
```

Now, if you want to consider the signed version what you can do is to replace your graph by a "signed graph" as follows

```
def mat_to_signed_dig(A):
n = A.nrows()
G = DiGraph(loops=False, multiedges=False)
for i in range(n):
for j in range(n):
if A[i,j]:
G.add_edge(i, j, A[i,j])
G.add_edge(n+i, n+j, A[i,j])
G.add_edge(i, n+j, -A[i,j])
G.add_edge(n+i, j, -A[i,j])
return G
```

Then

```
sage: A = matrix(4, [0,1,2,3,4,0,5,6,7,8,0,9,10,11,12,0])
sage: p = matrix(Permutation('(1,3)(2,4)')) * diagonal_matrix([1,-1,-1,1])
sage: B = p * A * ~p
sage: G = mat_to_signed_dig(A)
sage: H = mat_to_signed_dig(B)
sage: G.is_isomorphic(H, edge_labels=True, certificate=True)
(True, {0: 6, 1: 3, 2: 0, 3: 5, 4: 2, 5: 7, 6: 4, 7: 1})
```

2 | No.2 Revision |

If you remove "signed" from your question this is equivalent to the isomorphism problem of vertex and edge labeled directed graphs. To do that in Sage let us define the following auxilliary function that turns a matrix into a (edge labeled) directed graph

```
def mat_to_dig(A):
n = A.nrows()
G = DiGraph(loops=False, multiedges=False)
for i in range(n):
for j in range(n):
if A[i,j]:
G.add_edge(i, j, A[i,j])
return G
```

Now, (assuming that I care about matrix with 0 on the diagonal)

```
sage: A = matrix(4, [0,1,2,3,4,0,5,6,7,8,0,9,10,11,12,0])
sage: p = Permutation('(1,3)(2,4)')
sage: B = copy(A)
sage: B.permute_rows_and_columns(p,p)
sage: G = mat_to_dig(A)
sage: H = mat_to_dig(B)
sage: G.is_isomorphic(H, edge_labels=True, certificate=True)
(True, {0: 2, 1: 3, 2: 0, 3: 1})
```

The dictionary `{0: 2, 1: 3, 2: 0, 3: 1}`

gives you the permutation to be performed namely `0 -> 2, 1 -> 3, 2 -> 0, 3 -> 1`

.

Now, if you want to consider the signed version what you can do is to replace your graph by a "signed graph" ~~as follows~~in which the vertices are doubled.

```
def mat_to_signed_dig(A):
n = A.nrows()
G = DiGraph(loops=False, multiedges=False)
for i in range(n):
for j in range(n):
if A[i,j]:
G.add_edge(i, j, A[i,j])
G.add_edge(n+i, n+j, A[i,j])
G.add_edge(i, n+j, -A[i,j])
G.add_edge(n+i, j, -A[i,j])
return G
```

Then

```
sage: A = matrix(4, [0,1,2,3,4,0,5,6,7,8,0,9,10,11,12,0])
sage: p = matrix(Permutation('(1,3)(2,4)')) * diagonal_matrix([1,-1,-1,1])
sage: B = p * A * ~p
sage: G = mat_to_signed_dig(A)
sage: H = mat_to_signed_dig(B)
sage: G.is_isomorphic(H, edge_labels=True, certificate=True)
(True, {0: 6, 1: 3, 2: 0, 3: 5, 4: 2, 5: 7, 6: 4, 7: 1})
```

3 | No.3 Revision |

If you remove "signed" from your question this is equivalent to the isomorphism problem of vertex and edge labeled directed graphs. To do that in Sage let us define the following auxilliary function that turns a matrix into a (edge labeled) directed graph

```
def mat_to_dig(A):
n = A.nrows()
G = DiGraph(loops=False, multiedges=False)
for i in range(n):
for j in range(n):
if A[i,j]:
G.add_edge(i, j, A[i,j])
return G
```

Now, (assuming that I care about matrix with 0 on the diagonal)

```
sage: A = matrix(4, [0,1,2,3,4,0,5,6,7,8,0,9,10,11,12,0])
sage: p = Permutation('(1,3)(2,4)')
sage: B = copy(A)
sage: B.permute_rows_and_columns(p,p)
sage: G = mat_to_dig(A)
sage: H = mat_to_dig(B)
sage: G.is_isomorphic(H, edge_labels=True, certificate=True)
(True, {0: 2, 1: 3, 2: 0, 3: 1})
```

The dictionary `{0: 2, 1: 3, 2: 0, 3: 1}`

gives you the permutation to be performed namely

.~~0 -> 2, 1 -> 3, 2 -> 0, 3 -> 1~~0↦2, 1↦3, 2↦0, 3↦1

Now, if you want to consider the signed version what you can do is to replace your graph by a "signed graph" in which the vertices are doubled.

```
def mat_to_signed_dig(A):
n = A.nrows()
G = DiGraph(loops=False, multiedges=False)
for i in range(n):
for j in range(n):
if A[i,j]:
G.add_edge(i, j, A[i,j])
G.add_edge(n+i, n+j, A[i,j])
G.add_edge(i, n+j, -A[i,j])
G.add_edge(n+i, j, -A[i,j])
return G
```

Then

```
sage: A = matrix(4, [0,1,2,3,4,0,5,6,7,8,0,9,10,11,12,0])
sage: p = matrix(Permutation('(1,3)(2,4)')) * diagonal_matrix([1,-1,-1,1])
sage: B = p * A * ~p
sage: G = mat_to_signed_dig(A)
sage: H = mat_to_signed_dig(B)
sage: G.is_isomorphic(H, edge_labels=True, certificate=True)
(True, {0: 6, 1: 3, 2: 0, 3: 5, 4: 2, 5: 7, 6: 4, 7: 1})
```

The dictionary now corresponds to a signed permutation where `i+4`

should be thought as `-i`

. So it should be interpreted as the signed permutation `+0↦2, +1↦+3, +2↦+0, +3↦-1, -0↦+2, -1↦-3, -2↦-0, -3->+1`

.

4 | No.4 Revision |

```
def mat_to_dig(A):
n = A.nrows()
G = DiGraph(loops=False, multiedges=False)
for i in range(n):
for j in range(n):
if A[i,j]:
G.add_edge(i, j, A[i,j])
return G
```

Now, (assuming that I care about matrix with 0 on the diagonal)

```
sage: A = matrix(4, [0,1,2,3,4,0,5,6,7,8,0,9,10,11,12,0])
sage: p = Permutation('(1,3)(2,4)')
sage: B = copy(A)
sage: B.permute_rows_and_columns(p,p)
sage: G = mat_to_dig(A)
sage: H = mat_to_dig(B)
sage: G.is_isomorphic(H, edge_labels=True, certificate=True)
(True, {0: 2, 1: 3, 2: 0, 3: 1})
```

The dictionary `{0: 2, 1: 3, 2: 0, 3: 1}`

gives you the permutation to be performed namely `0↦2, 1↦3, 2↦0, 3↦1`

.

Now, if you want to consider the signed version what you can do is to replace your graph by a "signed graph" in which the vertices are doubled.

```
def mat_to_signed_dig(A):
n = A.nrows()
G = DiGraph(loops=False, multiedges=False)
for i in range(n):
for j in range(n):
if A[i,j]:
G.add_edge(i, j, A[i,j])
G.add_edge(n+i, n+j, A[i,j])
G.add_edge(i, n+j, -A[i,j])
G.add_edge(n+i, j, -A[i,j])
return G
```

Then

```
sage: A = matrix(4, [0,1,2,3,4,0,5,6,7,8,0,9,10,11,12,0])
sage: p = matrix(Permutation('(1,3)(2,4)')) * diagonal_matrix([1,-1,-1,1])
sage: B = p * A * ~p
sage: G = mat_to_signed_dig(A)
sage: H = mat_to_signed_dig(B)
sage: G.is_isomorphic(H, edge_labels=True, certificate=True)
(True, {0: 6, 1: 3, 2: 0, 3: 5, 4: 2, 5: 7, 6: 4, 7: 1})
```

The dictionary now corresponds to a signed permutation where `i+4`

should be thought as `-i`

. So it should be interpreted as the signed permutation

.~~+0↦2, ~~+0↦-2, +1↦+3, +2↦+0, +3↦-1, -0↦+2, -1↦-3, -2↦-0, -3->+1

5 | No.5 Revision |

```
def mat_to_dig(A):
n = A.nrows()
G = DiGraph(loops=False, multiedges=False)
for i in range(n):
for j in range(n):
if A[i,j]:
G.add_edge(i, j, A[i,j])
return G
```

Now, (assuming that I care about matrix with 0 on the diagonal)

```
sage: A = matrix(4, [0,1,2,3,4,0,5,6,7,8,0,9,10,11,12,0])
sage: A
[ 0 1 2 3]
[ 4 0 5 6]
[ 7 8 0 9]
[10 11 12 0]
sage: p = Permutation('(1,3)(2,4)')
sage: B = copy(A)
sage: B.permute_rows_and_columns(p,p)
sage: B
[ 0 9 7 8]
[12 0 10 11]
[ 2 3 0 1]
[ 5 6 4 0]
sage: G = mat_to_dig(A)
sage: H = mat_to_dig(B)
sage: G.is_isomorphic(H, edge_labels=True, certificate=True)
(True, {0: 2, 1: 3, 2: 0, 3: 1})
```

The dictionary `{0: 2, 1: 3, 2: 0, 3: 1}`

gives you the permutation to be performed namely `0↦2, 1↦3, 2↦0, 3↦1`

.

Now, if you want to consider the signed version what you can do is to replace your graph by a "signed graph" in which the vertices are doubled.

```
def mat_to_signed_dig(A):
n = A.nrows()
G = DiGraph(loops=False, multiedges=False)
for i in range(n):
for j in range(n):
if A[i,j]:
G.add_edge(i, j, A[i,j])
G.add_edge(n+i, n+j, A[i,j])
G.add_edge(i, n+j, -A[i,j])
G.add_edge(n+i, j, -A[i,j])
return G
```

Then

```
sage: A = matrix(4, [0,1,2,3,4,0,5,6,7,8,0,9,10,11,12,0])
sage: p = matrix(Permutation('(1,3)(2,4)')) * diagonal_matrix([1,-1,-1,1])
sage: B = p * A * ~p
sage: B
[ 0 -9 -7 8]
[-12 0 10 -11]
[ -2 3 0 -1]
[ 5 -6 -4 0]
sage: G = mat_to_signed_dig(A)
sage: H = mat_to_signed_dig(B)
sage: G.is_isomorphic(H, edge_labels=True, certificate=True)
(True, {0: 6, 1: 3, 2: 0, 3: 5, 4: 2, 5: 7, 6: 4, 7: 1})
```

The dictionary now corresponds to a signed permutation where `i+4`

should be thought as `-i`

. So it should be interpreted as the signed permutation `+0↦-2, +1↦+3, +2↦+0, +3↦-1, -0↦+2, -1↦-3, -2↦-0, -3->+1`

.

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.