Ask Your Question

Revision history [back]

Here is a simple example: the vertices are elements of $\mathbb{F}_5$, and there is an edge from $a$ to $b$ if $a^2 = b^2$.

sage: from itertools import product
sage: vertices = list(GF(5))
sage: edges = [(a,b) for (a,b) in product(vertices, vertices) if a**2 == b**2 and a != b]

In the previous line, product(vertices, vertices) is an iterator consisting of all pairs (v,w) of vertices. Now construct the graph:

sage: Graph([vertices, edges])
Graph on 5 vertices

Here is a simple example: the vertices are elements of $\mathbb{F}_5$, and there is an edge from $a$ to $b$ if $a^2 = b^2$.

sage: from itertools import product
sage: vertices = list(GF(5))
sage: edges = [(a,b) for (a,b) in product(vertices, vertices) if a**2 == b**2 and a != b]

In the previous line, product(vertices, vertices) is an iterator consisting of all pairs (v,w) of vertices. I impose the condition a != b to avoid loops in the graph. Now construct the graph:

sage: Graph([vertices, edges])
Graph on 5 vertices