| 1 | initial version |
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
| 2 | No.2 Revision |
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
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.