def ind_poly(G):
if is_complete(G):
return(G.order()*x+1)
else:
if G.is_connected():
v = G.vertices()[0]
nbhd = G.neighbors(v)
comp_nbhd = (Set(G.vertices()).difference(Set(union(nbhd,[v])))).list()
i1 = ind_poly(G.subgraph(G.vertices()[1:]))
if len(comp_nbhd) == 0:
i2 = 1
else:
i2 = ind_poly(G.subgraph(comp_nbhd))
return i1 + x*i2
else:
comps = G.connected_components_subgraphs()
return prod([ind_poly(comps[i]) for i in [0..len(comps)-1]])
G = graphs.PetersenGraph()
show(G)
ind_poly(G).expand()
|
5*x^4 + 30*x^3 + 30*x^2 + 10*x + 1
5*x^4 + 30*x^3 + 30*x^2 + 10*x + 1
|