Skip to content

Commit

Permalink
Improve PolynomialSequence.connection_graph()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tornaria committed Apr 15, 2023
1 parent eafa33c commit 8d8289b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/sage/rings/polynomial/multi_polynomial_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 8d8289b

Please sign in to comment.