First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 3 years ago

Max Alekseyev gravatar image

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.

click to hide/show revision 2
No.2 Revision

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.