---
title: "Conversion Functions"
canonical: "https://docs.magma-maths.org/v2.30-1/Combinatorics/Multigraphs/multig-conversion.html"
source: "https://docs.magma-maths.org/v2.30-1/Combinatorics/Multigraphs/multig-conversion.md"
part: "Combinatorics"
chapter: "Multigraphs"
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": "Multigraphs", "source": "https://docs.magma-maths.org/v2.30-1/Combinatorics/Multigraphs/index-multigraphs.md"}
prev: {"title": "Standard Construction for Multigraphs", "source": "https://docs.magma-maths.org/v2.30-1/Combinatorics/Multigraphs/multig-stand-constr.md"}
next: {"title": "Elementary Invariants and Predicates for Multigraphs", "source": "https://docs.magma-maths.org/v2.30-1/Combinatorics/Multigraphs/multig-elem.md"}
intrinsics:
  - {"name": "OrientatedGraph", "signature": "OrientatedGraph(G): GrphMultUnd -> GrphMultDir"}
  - {"name": "Converse", "signature": "Converse(G): GrphMultDir -> GrphMultDir"}
  - {"name": "UnderlyingGraph", "signature": "UnderlyingGraph(G): GrphMult -> GrphUnd, GrphVertSet, GrphEdgeSet"}
  - {"name": "UnderlyingGraph", "signature": "UnderlyingGraph(G): Grph -> GrphUnd, GrphVertSet, GrphEdgeSet"}
  - {"name": "UnderlyingDigraph", "signature": "UnderlyingDigraph(G): GrphMult -> GrphDir, GrphVertSet, GrphEdgeSet"}
  - {"name": "UnderlyingDigraph", "signature": "UnderlyingDigraph(G): Grph -> GrphDir, GrphVertSet, GrphEdgeSet"}
  - {"name": "UnderlyingMultiGraph", "signature": "UnderlyingMultiGraph(G): Grph -> GrphMultUnd, GrphVertSet, GrphEdgeSet"}
  - {"name": "UnderlyingMultiGraph", "signature": "UnderlyingMultiGraph(G): GrphMult -> GrphMultUnd, GrphVertSet, GrphEdgeSet"}
  - {"name": "UnderlyingMultiDigraph", "signature": "UnderlyingMultiDigraph(G): Grph -> GrphMultDir, GrphVertSet, GrphEdgeSet"}
  - {"name": "UnderlyingMultiDigraph", "signature": "UnderlyingMultiDigraph(G): GrphMult -> GrphMultDir, GrphVertSet, GrphEdgeSet"}
  - {"name": "UnderlyingNetwork", "signature": "UnderlyingNetwork(G): Grph -> GrphNet, GrphVertSet, GrphEdgeSet"}
  - {"name": "UnderlyingNetwork", "signature": "UnderlyingNetwork(G): GrphMult -> GrphNet, GrphVertSet, GrphEdgeSet"}
---

<a id="multig-conversion"></a>
<a id="multigraph-sec-conversion"></a>
# Conversion Functions

Conversion functions do not preserve a graph’s support and vertex/edge decorations. That is, the resulting graph has standard support and no vertex/edge decorations. A slight exception to this rule occurs when the resulting graph is a network (of type `GrphNet`) and is described in detail in [`UnderlyingNetwork`](https://docs.magma-maths.org/v2.30-1/Combinatorics/Multigraphs/multig-conversion.md#function-multigraph-underlyingnetwork).

<a id="multig-conv-orient"></a>
<a id="multigraph-subsec-conv-orient"></a>
## Orientated Graphs

The rules followed in building an orientated graph from an undirected graph are the same as those described for simple graphs (see Section [Converting between Graphs and Digraphs](https://docs.magma-maths.org/v2.30-1/Combinatorics/Graphs/conversion-graph-digraph.md#graph-sec-convert)).

<a id="function-orientatedgraph-grphmultund"></a>
### `OrientatedGraph(G): GrphMultUnd -> GrphMultDir`

Given a multigraph $G$, produce a multidigraph $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]$. If $G$ has a loop at $u$, then $D$ will have a directed loop at $u$.

<a id="multidig-conv"></a>
<a id="multigraph-subsec-conv-conv"></a>
## Converse

<a id="function-converse-grphmultdir"></a>
### `Converse(G): GrphMultDir -> GrphMultDir`

Given a multidigraph $G$ with edge-set $E$, produce a multidigraph $D$ whose vertex-set is the same as that of $G$ and whose edge-set is $\{ [u, v] : [v, u] \in E \}$.

<a id="multig-conv"></a>
<a id="multigraph-subsec-conv"></a>
## Converting between Simple Graphs and Multigraphs

Any simple (di)graph can be converted into a multi(di)graph and any multi(di)graph can be converted into a simple (di)graph. The resulting graph has standard support and neither vertex labels nor edge decorations, unless it is a network, in which case all the edges in the resulting graph are assigned a capacity of 1 (0 if loops).

Let $G$ be a graph and $e$ an edge of $G$ from $u$ to $v$ and let $H$ be the graph resulting from the conversion. If $G$ and $H$ are both undirected or both directed then $e$ is also an edge of $H$. If $G$ is undirected while $H$ is undirected then both edges $[u, v]$ and $[v, u]$ are edges of $H$. If $G$ is directed while $H$ is directed then the edge $\{u, v\}$ is an edge of $H$.

Since these conversion functions do not retain the original graph’s support and vertex/edge decorations, they may also be used when requiring a copy of a graph $G$ without $G$’s support and vertex/edge decorations.

<a id="function-underlyinggraph-grphmult"></a>
### `UnderlyingGraph(G): GrphMult -> GrphUnd, GrphVertSet, GrphEdgeSet`

<a id="function-underlyinggraph-grph"></a>
### `UnderlyingGraph(G): Grph -> GrphUnd, GrphVertSet, GrphEdgeSet`

The underlying simple graph of the graph $G$. The support and vertex/edge decorations of $G$ are not retained.

<a id="function-underlyingdigraph-grphmult"></a>
### `UnderlyingDigraph(G): GrphMult -> GrphDir, GrphVertSet, GrphEdgeSet`

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

The underlying simple digraph of the graph $G$. The support and vertex/edge decorations of $G$ are not retained.

<a id="function-underlyingmultigraph-grph"></a>
### `UnderlyingMultiGraph(G): Grph -> GrphMultUnd, GrphVertSet, GrphEdgeSet`

<a id="function-underlyingmultigraph-grphmult"></a>
### `UnderlyingMultiGraph(G): GrphMult -> GrphMultUnd, GrphVertSet, GrphEdgeSet`

The underlying multigraph of the graph $G$. The support and vertex/edge decorations of $G$ are not retained.

<a id="function-underlyingmultidigraph-grph"></a>
### `UnderlyingMultiDigraph(G): Grph -> GrphMultDir, GrphVertSet, GrphEdgeSet`

<a id="function-underlyingmultidigraph-grphmult"></a>
### `UnderlyingMultiDigraph(G): GrphMult -> GrphMultDir, GrphVertSet, GrphEdgeSet`

The underlying multidigraph of the graph $G$. The support and vertex/edge decorations of $G$ are not retained.

<a id="function-underlyingnetwork-grph"></a>
### `UnderlyingNetwork(G): Grph -> GrphNet, GrphVertSet, GrphEdgeSet`

<a id="function-multigraph-underlyingnetwork"></a>
### `UnderlyingNetwork(G): GrphMult -> GrphNet, GrphVertSet, GrphEdgeSet`

The underlying network of the graph $G$. The support and vertex/edge decorations of $G$ are not retained except when $G$ is a network in which case only the edge capacities are retained. If $G$ is not a network, then all the edge capacities are set to 1 (0 for loops).
