# Why does adding an edge to an empty graph not work as expected? [duplicate]

Bug introduced in 9.0 and fixed in 11.3

Does anybody has an idea what is wrong with adding edge to an empty graph created by my custom function?

DiscreteGraph[n_]:=GraphComplement[CompleteGraph[n]];


Note that the following works:

EdgeAdd[Graph[Range[5],{}],1<->2]


as well as the call with "graph-as-picture":

• It's just one of the outrageous Graph-bugs that Wolfram hasn't fixed for years. I reported these types of failures multiple times. Please write to Wolfram Support and report it yourself. The only way they'll do something about it is if more people report it. Or maybe they've already abandoned all the Graph stuff!? Sometimes I really have the impression that they did!! – Szabolcs Oct 11 '17 at 14:14
• The usual workaround to this kind of problem is to force the graph into another internal representation. There are many ways, such as g = Uncompress@Compress[g] or g = Graph[VertexList[g],EdgeList[g]] (loses properties). Then EdgeAdd won't fail. – Szabolcs Oct 11 '17 at 14:15
• Thanks for making clear the situation. Here I add another cherry at the tart top: T=Graph[{1<->2,1<->3,3<->4,1<->5,5<->6,6<->7}] GraphAutomorphismGroup[T] Seems not to work in version 11.2, but works in version 10!!! (and yes, reported to company) – Tomáš Madaras Oct 11 '17 at 14:20
• GraphAutomorphismGroup[T] works fine for me in 11.2 / OSX. The function is known to be buggy on the Raspberry Pi, but AFAIK it works fine on desktop platforms. The IGraph/M package has a function you can use instead: IGBlissAutomorphismGroup. Feel free to contact me with any feedback about this package (and please use the latest pre-release if you try it out). – Szabolcs Oct 11 '17 at 14:26

This is a bug.

As a workaround, you can force Mathematica to change the internal representation of the graph by passing it through a compound expression representation in some manner.

For example,

g = Uncompress@Compress[g]


or

g = Graph[VertexList[g], EdgeList[g]] (* loses properties like EdgeWeight! *)


Alternatively, create the graph in an incidence representation directly:

emptyGraph[n_Integer?NonNegative] := Graph[Range[n], {}]