---
title: "Converting between Graphs and Digraphs"
canonical: "https://docs.magma-maths.org/v2.30-1/Combinatorics/Graphs/conversion-graph-digraph.html"
source: "https://docs.magma-maths.org/v2.30-1/Combinatorics/Graphs/conversion-graph-digraph.md"
part: "Combinatorics"
chapter: "Graphs"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Combinatorics", "source": "https://docs.magma-maths.org/v2.30-1/Combinatorics/index-combinatorics.md"}
  - {"title": "Graphs", "source": "https://docs.magma-maths.org/v2.30-1/Combinatorics/Graphs/index-graphs.md"}
prev: {"title": "Unions and Products of Graphs", "source": "https://docs.magma-maths.org/v2.30-1/Combinatorics/Graphs/union-product.md"}
next: {"title": "Construction from Groups, Codes, and Designs", "source": "https://docs.magma-maths.org/v2.30-1/Combinatorics/Graphs/group-code-design.md"}
intrinsics:
  - {"name": "OrientatedGraph", "signature": "OrientatedGraph(G): GrphUnd -> GrphDir"}
  - {"name": "UnderlyingGraph", "signature": "UnderlyingGraph(D): Grph -> GrphUnd"}
  - {"name": "UnderlyingDigraph", "signature": "UnderlyingDigraph(G): Grph -> GrphDir"}
---

<a id="conversion-graph-digraph"></a>
<a id="graph-sec-convert"></a>
# Converting between Graphs and Digraphs

Note that the two functions `UnderlyingGraph` and `UnderlyingDigraph` may also be used when one needs to get a copy of a graph $G$ without $G$’s support and vertex/edge decorations.

<a id="function-orientatedgraph-grphund"></a>
## `OrientatedGraph(G): GrphUnd -> GrphDir`

Given a graph $G$, produce a digraph $D$ whose vertex-set is the same as that of $G$ and whose edge-set consists of the edges of $G$, each given a direction. The edges of $D$ are always directed from the lower numbered vertex to the higher numbered vertex. Thus, if $G$ contains the edge $\{ u,v\rbrace$, then $D$ will have the edge $[u, v]$ if $u < v$, otherwise the edge $[u, v]$. The support and vertex/edge decorations of $G$ are not retained.

<a id="function-underlyinggraph-grph"></a>
## `UnderlyingGraph(D): Grph -> GrphUnd`

The underlying graph $G$ of the graph $D$; $G$ has the same vertex-set as $D$. If $D$ is undirected, then $G$ is a copy of $D$ without $D$’s support and vertex/edge decorations. If $D$ is directed, then two vertices $u$ and $v$ are adjacent in $G$ if and only if, in $D$, there is either an edge directed from $u$ to $v$ or from $v$ to $u$. The support and vertex/edge decorations of $G$ are not retained.

<a id="function-underlyingdigraph-grph"></a>
## `UnderlyingDigraph(G): Grph -> GrphDir`

The underlying digraph $D$ of the graph $G$; $D$ has the same vertex-set as $G$. If $G$ is directed, then $D$ is a copy of $G$ without $D$’s support and vertex/edge decorations. If $G$ is undirected, then if vertices $u$ and $v$ are adjacent in $G$ then, in $D$, there will be both an edge directed from $u$ to $v$ and an edge directed from $v$ to $u$. The support and vertex/edge decorations of $G$ are not retained.
