Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Something like this will do the job:

def find(n):
  for g in graphs(n, size=n):
    if not g.is_connected():
      continue
    f = g.characteristic_polynomial()
    h = f.reverse()
    h /= h.leading_coefficient()
    if f == h:
      g.show()

find(8)

It finds 3 such graphs of size 8.

Something like this will do the job:

def find(n):
find_graphs(n):
  for g in graphs(n, size=n):
    if not g.is_connected():
      continue
graphs.nauty_geng(options=f'-c {n} {n}:{n}'):
    f = g.characteristic_polynomial()
    h = f.reverse()
    h /= h.leading_coefficient()
    if f == h:
      g.show()

find(8)
find_graphs(8)

It finds 3 such graphs of size 8.