ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 11 Jun 2019 01:20:47 +0200chromatic polynomial graph with loopshttps://ask.sagemath.org/question/46808/chromatic-polynomial-graph-with-loops/Since there are no proper colorings of graphs with loops,
their chromatic polynomial should be zero.
SageMath 8.6 however seems to ignore the loops
and returns a nonzero chromatic polynomial for the
graph on one vertex with one loop edge.
sage: Graph([[1, 1]], multiedges=True, loops=True).chromatic_polynomial()
xWed, 05 Jun 2019 14:16:04 +0200https://ask.sagemath.org/question/46808/chromatic-polynomial-graph-with-loops/Comment by slelievre for <p>Since there are no proper colorings of graphs with loops,
their chromatic polynomial should be zero.</p>
<p>SageMath 8.6 however seems to ignore the loops
and returns a nonzero chromatic polynomial for the
graph on one vertex with one loop edge.</p>
<pre><code>sage: Graph([[1, 1]], multiedges=True, loops=True).chromatic_polynomial()
x
</code></pre>
https://ask.sagemath.org/question/46808/chromatic-polynomial-graph-with-loops/?comment=46823#post-id-46823This indeed looks like a bug. Thanks for reporting!
Would you like to open a ticket for it on the Sage Trac server?
- [https://trac.sagemath.org](https://trac.sagemath.org)
Would you like to suggest a fix? The relevant file is
- [https://github.com/sagemath/sage/blob/develop/src/sage/graphs/chrompoly.pyx](https://github.com/sagemath/sage/blob/develop/src/sage/graphs/chrompoly.pyx)
(If not, I can take care of it.)Thu, 06 Jun 2019 10:37:52 +0200https://ask.sagemath.org/question/46808/chromatic-polynomial-graph-with-loops/?comment=46823#post-id-46823Comment by slelievre for <p>Since there are no proper colorings of graphs with loops,
their chromatic polynomial should be zero.</p>
<p>SageMath 8.6 however seems to ignore the loops
and returns a nonzero chromatic polynomial for the
graph on one vertex with one loop edge.</p>
<pre><code>sage: Graph([[1, 1]], multiedges=True, loops=True).chromatic_polynomial()
x
</code></pre>
https://ask.sagemath.org/question/46808/chromatic-polynomial-graph-with-loops/?comment=46899#post-id-46899Now tracked at
- [Sage Trac ticket 27966: set chromatic number of looped graph to zero](https://trac.sagemath.org/ticket/27966)Tue, 11 Jun 2019 01:20:47 +0200https://ask.sagemath.org/question/46808/chromatic-polynomial-graph-with-loops/?comment=46899#post-id-46899Answer by slelievre for <p>Since there are no proper colorings of graphs with loops,
their chromatic polynomial should be zero.</p>
<p>SageMath 8.6 however seems to ignore the loops
and returns a nonzero chromatic polynomial for the
graph on one vertex with one loop edge.</p>
<pre><code>sage: Graph([[1, 1]], multiedges=True, loops=True).chromatic_polynomial()
x
</code></pre>
https://ask.sagemath.org/question/46808/chromatic-polynomial-graph-with-loops/?answer=46824#post-id-46824This indeed looks like a bug.
As a workaround, test whether the graph has loops before computing the chromatic polynomial.
sage: G = Graph([[1, 1]], multiedges=True, loops=True)
sage: G.has_loops()
True
Fixing the bug should just amount to special-casing graphs with loops
(testing for loops as above) and including a doctest (to prevent the
bug from reappearing).Thu, 06 Jun 2019 10:43:54 +0200https://ask.sagemath.org/question/46808/chromatic-polynomial-graph-with-loops/?answer=46824#post-id-46824