# Spectrum of the GraphData

I'm new in using Mathematica.

I need to generate graph spectrums for line graphs of all graphs with vertices number smaller than 5.

I used this command to generate all LineGraps:

GraphData[#, "LineGraph"] & /@ GraphData["Connected", 2 ;; 5]

It generates "plots" of all line graphs.

If i try to do this:

GraphData[#, "Spectrum"] & /@ GraphData[#, "LineGraph", ] & /@
GraphData["Connected", 2 ;; 5]

it still generates only the "plots", not spectrum.

Can somebody help me how to generate spectrum of each of these line graphs?

• You have a hanging comma in GraphData[#, "LineGraph", ] & . And you probably want to us GraphData[#, "Spectrum"] & /@ GraphData["Connected", 2 ;; 5] instead. Sep 8 '18 at 16:35
• Unfortunately i removed coma and still it doesn't work and shows plots. I didn;t want GraphData[#, "Spectrum"] & /@ GraphData["Connected", 2 ;; 5] because it shows spectrums of all graphs between 2 and 5 vertices and i want their LineGraph's spectrums (en.wikipedia.org/wiki/Line_graph) Sep 8 '18 at 16:50
• Perhaps it's good to point out that the GraphData function merely queries a database. It does not compute anything. You need to pass the name of a graph to it, not the graph itself. Given a graph, you can compute it's LineGraph directly, or its spectrum using Eigenvalues@AdjacencyMatrix[graph]. Sep 8 '18 at 17:18

The problem is that the "LineGraph" is not necessarily stored in GraphData and that GraphData[#,"LineGraph"]& returns a Graph object and not a name of the graph. But one can easily compute the spectrum of any Graph as the eigenvalues if its adjacency matrix:

GraphData["Connected", 2 ;; 5]
• Thank You very much :) I started with Eigenvalues, but later i saw Property "Spectrum" so I tried to use it. Now it works! Sep 8 '18 at 17:14
• You're welcome. And enjoy Mathematica! Sep 8 '18 at 17:15

1. You were missing the "Name" subproperty
2. You need to use parentheses so that the input is parsed the way you want (& has very low precedence):

So, you could get your code working as follows:

GraphData[#, "Spectrum"] & /@ (GraphData[#, "LineGraph", "Name"] &) /@ GraphData["Connected", 2 ;; 5]

GraphData::notdef: GraphData has no value associated with the specified argument(s).

GraphData::notdef: GraphData has no value associated with the specified argument(s).

GraphData::notdef: GraphData has no value associated with the specified argument(s).

General::stop: Further output of GraphData::notdef will be suppressed during this calculation.

{{-2, -2, Root[4 - 4 #1 - 3 #1^2 + #1^3 &, 1], 0, Root[4 - 4 #1 - 3 #1^2 + #1^3 &, 2], 1, Root[4 - 4 #1 - 3 #1^2 + #1^3 &, 3]}, {-2, Root[2 - 2 #1 - 2 #1^2 + #1^3 &, 1], 0, Root[2 - 2 #1 - 2 #1^2 + #1^3 &, 2], Root[2 - 2 #1 - 2 #1^2 + #1^3 &, 3]}, {1/2 (-1 - Sqrt[5]), Root[-2 - 5 #1 - #1^2 + #1^3 &, 1], Root[-2 - 5 #1 - #1^2 + #1^3 &, 2], 1/2 (-1 + Sqrt[5]), Root[-2 - 5 #1 - #1^2 + #1^3 &, 3]}, {-2, -1, -1, 1/2 (3 - Sqrt[17]), 1, 1/2 (3 + Sqrt[17])}, {-1, -1, 2}, {-2, -2, 0, 0, 1, 3}, {-2, -2, 1/2 (3 - Sqrt[33]), 0, 0, 1, 1/2 (3 + Sqrt[33])}, {Root[2 - 5 #1 - 2 #1^2 + #1^3 &, 1], -1, -1, Root[2 - 5 #1 - 2 #1^2 + #1^3 &, 2], Root[2 - 5 #1 - 2 #1^2 + #1^3 &, 3]}, {1/2 (-1 - Sqrt[5]), 1/2 (-1 - Sqrt[5]), 1/2 (-1 + Sqrt[5]), 1/2 (-1 + Sqrt[5]), 2}, {-2, Root[4 - 4 #1 - 3 #1^2 + #1^3 &, 1], -1, 0, Root[4 - 4 #1 - 3 #1^2 + #1^3 &, 2], Root[4 - 4 #1 - 3 #1^2 + #1^3 &, 3]}, {-2, 1 - Sqrt[5], 0, 0, 1 + Sqrt[5]}, {Root[1 - 3 #1 - #1^2 + #1^3 &, 1], -1, Root[1 - 3 #1 - #1^2 + #1^3 &, 2], Root[1 - 3 #1 - #1^2 + #1^3 &, 3]}, {-2, -2, -1, Root[2 - #1 - 4 #1^2 + #1^3 &, 1], Root[2 - #1 - 4 #1^2 + #1^3 &, 2], 1, Root[2 - #1 - 4 #1^2 + #1^3 &, 3]}, {-2, 1/2 (-1 - Sqrt[5]), Root[2 - #1 - 3 #1^2 + #1^3 &, 1], 1/2 (-1 + Sqrt[5]), Root[2 - #1 - 3 #1^2 + #1^3 &, 2], Root[2 - #1 - 3 #1^2 + #1^3 &, 3]}, GraphData[Missing["NotAvailable"], "Spectrum"], GraphData[Missing["NotAvailable"], "Spectrum"], {-2, Root[4 + 2 #1 - 6 #1^2 - 2 #1^3 + #1^4 &, 1], Root[4 + 2 #1 - 6 #1^2 - 2 #1^3 + #1^4 &, 2], 0, Root[4 + 2 #1 - 6 #1^2 - 2 #1^3 + #1^4 &, 3], Root[4 + 2 #1 - 6 #1^2 - 2 #1^3 + #1^4 &, 4]}, {-2, -2, 1/2 (3 - Sqrt[33]), 0, 0, 1, 1/2 (3 + Sqrt[33])}, {0}, {-1, 1}, {-Sqrt[2], 0, Sqrt[ 2]}, {1/2 (-1 - Sqrt[5]), 1/2 (1 - Sqrt[5]), 1/2 (-1 + Sqrt[5]), 1/2 (1 + Sqrt[5])}, {1/2 (1 - Sqrt[17]), -1, 0, 1/2 (1 + Sqrt[17])}, {-2, -2, -2, -2, -2, 1, 1, 1, 1, 6}, {-2, 0, 0, 2}, {-1, -1, -1, 3}, {Root[2 + #1 - 5 #1^2 - #1^3 + #1^4 &, 1], -1, Root[2 + #1 - 5 #1^2 - #1^3 + #1^4 &, 2], Root[2 + #1 - 5 #1^2 - #1^3 + #1^4 &, 3], Root[2 + #1 - 5 #1^2 - #1^3 + #1^4 &, 4]}, {-2, -2, 0, 0, 0, 4}, {-1, -1, 2}, GraphData[Missing["NotAvailable"], "Spectrum"]}

Messages are generated because GraphData does not include all of the line graphs in its database.

• A good question would be: given a Graph, how to find it in GraphData. One can query all graphs with the same number of vertices, compute the CanonicalGraph of each, then search based on that. It's ugly though. I wonder if there's something more direct. It could be sped up by pre-filtering by basic properties, such as the edge count. Sep 8 '18 at 17:21
• Sep 10 '18 at 13:16

You don't need to use the "LineGraph" in the middle, just pass the first GraphData elements to the "Spectrum" one.

You can try

Table[GraphData[g, "Spectrum"], {g, GraphData["Connected", 2 ;; 5]}]

Explanation:

GraphData["Connected", 2 ;; 5] returns a table of elements. You can use the elements from this table to put yet in another GraphData.

Edit:

I just saw your comment about wanting LineGraph spectra, not the Graph spectra. However, when you pass a LineGraph to GraphData[#, "Spectrum"], it doesn't work.

The output looks like this:

Are you sure that you don't want this? Because, the way I see it, 2;;5 range has a collection of graphs. For each of these graphs there is a name (1st column), a line graph plot (2nd column) and a spectrum (3rd column):

P.s.: This is the code for the output above:

Table[{
g,
GraphData[g, "LineGraph"],
GraphData[g, "Spectrum"]
},
{g, GraphData["Connected", 2 ;; 5]}] // TraditionalForm