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 1/2] 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): From 850c883d01a852ef4968e9f17e8fbf0e2ec431d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Sun, 16 Apr 2023 07:29:22 -0300 Subject: [PATCH 2/2] mps.connection_graph(): tests to document behavior --- .../polynomial/multi_polynomial_sequence.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/sage/rings/polynomial/multi_polynomial_sequence.py b/src/sage/rings/polynomial/multi_polynomial_sequence.py index 75eb60d0718..cb9b85d88b4 100644 --- a/src/sage/rings/polynomial/multi_polynomial_sequence.py +++ b/src/sage/rings/polynomial/multi_polynomial_sequence.py @@ -905,8 +905,28 @@ def connection_graph(self): sage: B. = BooleanPolynomialRing() sage: F = Sequence([x*y + y + 1, z + 1]) - sage: F.connection_graph() + sage: G = F.connection_graph(); G Graph on 3 vertices + sage: G.is_connected() + False + sage: F = Sequence([x]) + sage: F.connection_graph() + Graph on 1 vertex + + TESTS:: + + sage: F = Sequence([], B) + sage: F.connection_graph() + Graph on 0 vertices + sage: F = Sequence([1], B) + sage: F.connection_graph() + Graph on 0 vertices + sage: F = Sequence([x]) + sage: F.connection_graph() + Graph on 1 vertex + sage: F = Sequence([x, y]) + sage: F.connection_graph() + Graph on 2 vertices sage: F = Sequence([x*y*z]) sage: F.connection_graph().is_clique() True