# Revision history [back]

Here is one (not so elegant) possibility

sage: J = IndependentSets(graphs.CycleGraph(4))
sage: t = polygen(ZZ)
sage: F = 0
sage: for x in J:
....:     N = len(set().union(G.neighbor_iterator(v) for v in x))
....:     F += t^N
sage: F
2*x^2 + 4*x + 1


It is not so elegant because it constructs the explicit list of neighbors.

Here is one (not so elegant) possibility

sage: J = IndependentSets(graphs.CycleGraph(4))
sage: t = polygen(ZZ)
polygen(ZZ, 't')
sage: F = 0
sage: for x in J:
....:     N = len(set().union(G.neighbor_iterator(v) len(set().union(*[G.neighbor_iterator(v) for v in x))
x]))
....:     F += t^N
sage: F
2*x^2 + 4*x 6t^2 + 1


It is not so elegant because it constructs the explicit list of neighbors.