Skip to main content

Discrete Math with SageMath: Learn math with open-source software

Section 5.3 Digraphs

A digraph, or directed graph, is a visual representation of a relation \(R\) on the set \(A\text{.}\) Every element in set \(A\) is shown as a node (vertex). An arrow from the node \(a\) to the node \(b\) represents the pair \((a,b)\) on the relation \(R\text{.}\)
We can add a title to the digraph with the name parameter.
If the digraph does not contain a relation from a node to itself, we can omit the loops=true parameter. If we happen to forgot to include the parameter when we need to, Sage will give us a descriptive error message.
We can also define the digraph using pair notion for relations.
Alternatively, we can define the digraph directly. The element on the left of the : is a node. The node relates to the elements in the list on the right of the :.