From 8d8289bc73ebd22bd971cc58ab1db90c0e61ba52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Fri, 7 Apr 2023 23:50:32 -0300 Subject: [PATCH] Improve PolynomialSequence.connection_graph() Simplify the code; also, the previous code has to iterate over variables of the sequence twice (this is really bad before #35510) Moreover, now we add a clique between the variables of each polynomial, so it agrees with the description (the code before used to add just a spanning tree of the clique -- a star). This makes this method a little bit slower for the purposes of `connected_components()` (for which adding a star is equivalent). However, #35518 will rewrite `connected_components()` without using `connection_graph()` so this is not really a problem. --- .../rings/polynomial/multi_polynomial_sequence.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/sage/rings/polynomial/multi_polynomial_sequence.py b/src/sage/rings/polynomial/multi_polynomial_sequence.py index acf7c762e90..75eb60d0718 100644 --- a/src/sage/rings/polynomial/multi_polynomial_sequence.py +++ b/src/sage/rings/polynomial/multi_polynomial_sequence.py @@ -907,16 +907,17 @@ def connection_graph(self): sage: F = Sequence([x*y + y + 1, z + 1]) sage: F.connection_graph() Graph on 3 vertices + sage: F = Sequence([x*y*z]) + sage: F.connection_graph().is_clique() + True + sage: F = Sequence([x*y, y*z]) + sage: F.connection_graph().is_clique() + False """ - V = sorted(self.variables()) from sage.graphs.graph import Graph g = Graph() - g.add_vertices(sorted(V)) for f in self: - v = f.variables() - a,tail = v[0],v[1:] - for b in tail: - g.add_edge((a,b)) + g.add_clique(f.variables()) return g def connected_components(self):