From 8e6d6b147523487ca3166a24f4504a9791917c2c Mon Sep 17 00:00:00 2001 From: Matteo Cati Date: Sun, 29 Jan 2023 15:49:26 +0000 Subject: [PATCH 1/2] Add construction of strongly regular digraph --- src/doc/en/reference/references/index.rst | 5 +++ src/sage/graphs/digraph_generators.py | 47 +++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/doc/en/reference/references/index.rst b/src/doc/en/reference/references/index.rst index e747b14139d..2250ec93016 100644 --- a/src/doc/en/reference/references/index.rst +++ b/src/doc/en/reference/references/index.rst @@ -2174,6 +2174,11 @@ REFERENCES: .. [Duv1983] J.-P. Duval, Factorizing words over an ordered alphabet, J. Algorithms 4 (1983) 363--381. +.. [Duv1988] \A. Duval. + *A directed graph version of strongly regular graphs*, + Journal of Combinatorial Theory, Series A 47(1) (1988): 71-100. + :doi:`10.1016/0097-3165(88)90043-X` + .. [DW1995] Andreas W.M. Dress and Walter Wenzel, *A Simple Proof of an Identity Concerning Pfaffians of Skew Symmetric Matrices*, Advances in Mathematics, volume 112, Issue 1, diff --git a/src/sage/graphs/digraph_generators.py b/src/sage/graphs/digraph_generators.py index f1d88178ebb..29fbcf99614 100644 --- a/src/sage/graphs/digraph_generators.py +++ b/src/sage/graphs/digraph_generators.py @@ -349,6 +349,53 @@ def Path(self, n): g.set_pos({i: (i, 0) for i in range(n)}) return g + def StronglyRegular(self, n): + r""" + Return a Strongly Regular digraph with `n` vertices. + + The adjacency matrix of the graph is constructed from a skew Hadamard + matrix of order `n+1`. These graphs were first constructed in [Duv1988]_. + + INPUT: + + - ``n`` -- integer, the number of vertices of the digraph. + + .. SEEALSO:: + + - :func:`sage.combinat.matrices.hadamard_matrix.skew_hadamard_matrix` + - :meth:`Paley` + + EXAMPLES: + + A Strongly Regular digraph satisfies the condition `AJ = JA = kJ` where + `A` is the adjacency matrix:: + + sage: g = digraphs.StronglyRegular(7); g + Strongly regular digraph: Digraph on 7 vertices + sage: A = g.adjacency_matrix()*ones_matrix(7); B = ones_matrix(7)*g.adjacency_matrix() + sage: A == B == A[0, 0]*ones_matrix(7) + True + + TESTS: + + Wrong parameter:: + + sage: digraphs.StronglyRegular(73) + Traceback (most recent call last): + ... + ValueError: strongly regular digraph with 73 vertices not yet implemented + + """ + from sage.combinat.matrices.hadamard_matrix import skew_hadamard_matrix + from sage.matrix.constructor import ones_matrix, identity_matrix + if skew_hadamard_matrix(n+1, existence=True) is not True: + raise ValueError(f'strongly regular digraph with {n} vertices not yet implemented') + + H = skew_hadamard_matrix(n+1, skew_normalize=True) + M = H[1:, 1:] + M = (M + ones_matrix(n)) / 2 - identity_matrix(n) + return DiGraph(M, format='adjacency_matrix', name=f'Strongly regular digraph') + def Paley(self, q): r""" Return a Paley digraph on `q` vertices. From 5bd750c18590a266e95a84f44158f800ab0b2301 Mon Sep 17 00:00:00 2001 From: Matteo Cati Date: Mon, 13 Feb 2023 12:21:12 +0000 Subject: [PATCH 2/2] Fix code style --- src/sage/graphs/digraph_generators.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sage/graphs/digraph_generators.py b/src/sage/graphs/digraph_generators.py index 5270d81ed9c..2b864b54284 100644 --- a/src/sage/graphs/digraph_generators.py +++ b/src/sage/graphs/digraph_generators.py @@ -388,13 +388,13 @@ def StronglyRegular(self, n): """ from sage.combinat.matrices.hadamard_matrix import skew_hadamard_matrix from sage.matrix.constructor import ones_matrix, identity_matrix - if skew_hadamard_matrix(n+1, existence=True) is not True: + if skew_hadamard_matrix(n + 1, existence=True) is not True: raise ValueError(f'strongly regular digraph with {n} vertices not yet implemented') - H = skew_hadamard_matrix(n+1, skew_normalize=True) + H = skew_hadamard_matrix(n + 1, skew_normalize=True) M = H[1:, 1:] M = (M + ones_matrix(n)) / 2 - identity_matrix(n) - return DiGraph(M, format='adjacency_matrix', name=f'Strongly regular digraph') + return DiGraph(M, format='adjacency_matrix', name='Strongly regular digraph') def Paley(self, q): r"""