diff --git a/src/sage/graphs/generators/distance_regular.pyx b/src/sage/graphs/generators/distance_regular.pyx index 570012ac3fc..4b5c8ac7657 100644 --- a/src/sage/graphs/generators/distance_regular.pyx +++ b/src/sage/graphs/generators/distance_regular.pyx @@ -488,34 +488,58 @@ def shortened_000_111_extended_binary_Golay_code_graph(): EXAMPLES:: sage: # long time, needs sage.modules sage.rings.finite_rings - sage: G = graphs.shortened_000_111_extended_binary_Golay_code_graph() # 25 s + sage: G = graphs.shortened_000_111_extended_binary_Golay_code_graph() sage: G.is_distance_regular(True) ([21, 20, 16, 9, 2, 1, None], [None, 1, 2, 3, 16, 20, 21]) ALGORITHM: - Compute the extended binary Golay code. Compute its subcode whose codewords - start with 000 or 111. Remove the first 3 entries from all the codewords - from the new linear code and compute its coset graph. + The vertices and edges of this graph have been precomputed and + pickled, so truthfully, we just unpickle them and pass them to the + Graph constructor. But the algorithm used to compute those + vertices and edges in the first place is, - REFERENCES: - - Description and construction of this graph can be found in [BCN1989]_ p. 365. - """ - from sage.coding.linear_code import LinearCode - - code = codes.GolayCode(GF(2)) - C_basis = code.basis() + #. Compute the extended binary Golay code. + #. Compute its subcode whose codewords start with 000 or 111. + #. Remove the first 3 entries from all the codewords from the + new linear code and compute its coset graph. - # now special shortening - v = C_basis[0] + C_basis[1] + C_basis[2] # v has 111 at the start - C_basis = C_basis[3:] - C_basis.append(v) - C_basis = list(map(lambda x: x[3:], C_basis)) + This construction is tested in ``generators_test.py``, where the + result is compared with the result from this method. - code = LinearCode(Matrix(GF(2), C_basis)) + REFERENCES: - G = code.cosetGraph() + The description and construction of this graph can be found in + [BCN1989]_, page 365. + """ + import lzma + from importlib.resources import as_file, files + from pickle import load + + # Path to the pickled-and-xz'd list of (vertices, edges) + ppath = files('sage.graphs.generators').joinpath( + "shortened_000_111_extended_binary_Golay_code_graph.pickle.xz" + ) + + with as_file(ppath) as p: + with lzma.open(p) as f: + vs_and_es = load(f, fix_imports=False) + + # Vertices/edges are pickled as tuples of ints, but should be + # vectors with entries in GF(2). + V = VectorSpace(GF(2), 21) + for i in range(2048): + # vertex i + vs_and_es[0][i] = V(vs_and_es[0][i]) + vs_and_es[0][i].set_immutable() + for i in range(21504): + # edge i = (v1, v2, l) + vs_and_es[1][i][0] = V(vs_and_es[1][i][0]) # v1 + vs_and_es[1][i][0].set_immutable() + vs_and_es[1][i][1] = V(vs_and_es[1][i][1]) # v2 + vs_and_es[1][i][1].set_immutable() + + G = Graph(vs_and_es, format='vertices_and_edges') G.name("Shortened 000 111 extended binary Golay code") return G diff --git a/src/sage/graphs/generators/generators_test.py b/src/sage/graphs/generators/generators_test.py new file mode 100644 index 00000000000..5b57f1cd459 --- /dev/null +++ b/src/sage/graphs/generators/generators_test.py @@ -0,0 +1,34 @@ +import pytest + + +def test_shortened_000_111_extended_binary_Golay_code_graph(): + r""" + Test that Sage produces a graph equal to the one that we get + from this construction. + + The construction itself takes a long time. + """ + from sage.coding import codes_catalog + from sage.coding.linear_code import LinearCode + from sage.graphs.generators.distance_regular import ( + shortened_000_111_extended_binary_Golay_code_graph + ) + from sage.matrix.constructor import matrix + from sage.rings.finite_rings.finite_field_constructor import FiniteField + + code = codes_catalog.GolayCode(FiniteField(2)) + C_basis = code.basis() + + # now special shortening + v = C_basis[0] + C_basis[1] + C_basis[2] # v has 111 at the start + C_basis = C_basis[3:] + C_basis.append(v) + C_basis = list(map(lambda x: x[3:], C_basis)) + + code = LinearCode(matrix(FiniteField(2), C_basis)) + G = code.cosetGraph() + G.name("Shortened 000 111 extended binary Golay code") + assert G.is_distance_regular() + + H = shortened_000_111_extended_binary_Golay_code_graph() + assert G == H diff --git a/src/sage/graphs/generators/meson.build b/src/sage/graphs/generators/meson.build index c98c2647c25..e086316e599 100644 --- a/src/sage/graphs/generators/meson.build +++ b/src/sage/graphs/generators/meson.build @@ -6,9 +6,11 @@ py.install_sources( 'classical_geometries.py', 'degree_sequence.py', 'families.py', + 'generators_test.py', 'intersection.py', 'platonic_solids.py', 'random.py', + 'shortened_000_111_extended_binary_Golay_code_graph.pickle.xz', 'smallgraphs.py', 'world_map.py', subdir: 'sage/graphs/generators', diff --git a/src/sage/graphs/generators/shortened_000_111_extended_binary_Golay_code_graph.pickle.xz b/src/sage/graphs/generators/shortened_000_111_extended_binary_Golay_code_graph.pickle.xz new file mode 100644 index 00000000000..e46e00615d7 Binary files /dev/null and b/src/sage/graphs/generators/shortened_000_111_extended_binary_Golay_code_graph.pickle.xz differ