ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 10 Jun 2019 18:20:47 -0500chromatic polynomial graph with loopshttp://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 07:16:04 -0500http://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>
http://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)Mon, 10 Jun 2019 18:20:47 -0500http://ask.sagemath.org/question/46808/chromatic-polynomial-graph-with-loops/?comment=46899#post-id-46899Comment 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>
http://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 03:37:52 -0500http://ask.sagemath.org/question/46808/chromatic-polynomial-graph-with-loops/?comment=46823#post-id-46823Answer 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>
http://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 03:43:54 -0500http://ask.sagemath.org/question/46808/chromatic-polynomial-graph-with-loops/?answer=46824#post-id-46824