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, 22 Sep 2014 07:51:43 -0500How to get a list of graphs whose independence number equals to chromatic number?http://ask.sagemath.org/question/24221/how-to-get-a-list-of-graphs-whose-independence-number-equals-to-chromatic-number/1. The smallest number of colors needed to color a graph G is called its **chromatic number**, and is often denoted χ(G).
2. The **independence number** α(G) of a graph G is the size of the largest independent set of G.
Sat, 20 Sep 2014 22:13:53 -0500http://ask.sagemath.org/question/24221/how-to-get-a-list-of-graphs-whose-independence-number-equals-to-chromatic-number/Answer by kcrisman for <ol>
<li><p>The smallest number of colors needed to color a graph G is called its <strong>chromatic number</strong>, and is often denoted χ(G).</p></li>
<li><p>The <strong>independence number</strong> α(G) of a graph G is the size of the largest independent set of G.</p></li>
</ol>
http://ask.sagemath.org/question/24221/how-to-get-a-list-of-graphs-whose-independence-number-equals-to-chromatic-number/?answer=24247#post-id-24247It turns out that chromatic number is easy to find.
sage: G = graphs(6)
sage: g = G.next()
sage: g.chromatic_number()
1
By the way, to find out what you can do with a graph you can do
sage: g.?
and a list of all methods will appear, including this one.
However, I believe the syntax for your other thing is
sage: g.independent_set(value_only=True)
6
This fact is hidden [here](http://www.sagemath.org/doc/reference/graphs/sage/graphs/graph.html#sage.graphs.graph.Graph.independent_set) in the documentation. Perhaps it should be a separate command if this is a common invariant?
Anyway, then you can use a basic [filtered list comprehension](http://www.diveintopython.net/power_of_introspection/filtering_lists.html) to finish it off.
sage: [g for g in graphs(3) if g.chromatic_number()==g.independent_set(value_only=True)]
[Graph on 3 vertices, Graph on 3 vertices]Mon, 22 Sep 2014 07:51:43 -0500http://ask.sagemath.org/question/24221/how-to-get-a-list-of-graphs-whose-independence-number-equals-to-chromatic-number/?answer=24247#post-id-24247