RelationGraph - Maple Help

GraphTheory

 RelationGraph
 construct graph from relation

 Calling Sequence RelationGraph( V, f ) RelationGraph( [V1, V2], f )

Parameters

 V - list of integers, strings or symbols (vertex labels), or two-element f - procedure of two arguments representing a relation

Options

 • directed = true or false
 Specifies whether the returned graph should be directed or undirected. By default, the resulting graph is undirected when the relation f is symmetric, and directed otherwise.
 • selfloops = true or false
 Specifies whether the returned graph should contain a self-loop on vertex u when f(u,u) is true. The default is false.

Description

 • RelationGraph(V,f) constructs a graph on the given vertex list in which edges exist in the graph when a Boolean predicate f is true.
 • If V is a list of integers, strings or symbols, then a graph is built with vertex set V in which there is an edge from a to b whenever f(a,b) returns true.
 • If V is a list consisting of two lists V1 and V2 of integers, strings or symbols, then a graph is built whose vertex set is the the union of V1 and V2 in which there is an edge from a in V1 to b in V2 whenever f(a,b) returns true. If V1 and V2 are disjoint, this graph is bipartite.

Examples

In this undirected graph, there is an edge between a and b if they are relatively prime.

 > $\mathrm{with}\left(\mathrm{GraphTheory}\right):$
 > $\mathrm{G1}≔\mathrm{RelationGraph}\left(\left[\mathrm{seq}\left(1..25\right)\right],\mathrm{NumberTheory}:-\mathrm{AreCoprime}\right)$
 ${\mathrm{G1}}{≔}{\mathrm{Graph 1: an undirected graph with 25 vertices and 199 edge\left(s\right)}}$ (1)
 > $\mathrm{NumberOfEdges}\left(\mathrm{G1}\right)$
 ${199}$ (2)

In this directed graph there is an arc from a to b if a is divisible by b.

 > $\mathrm{DivisibleBy}≔\left(p,q\right)↦\mathrm{evalb}\left(\mathrm{irem}\left(p,q\right)=0\right):$
 > $\mathrm{DivisibleBy}\left(4,2\right)$
 ${\mathrm{true}}$ (3)
 > $\mathrm{DivisibleBy}\left(5,3\right)$
 ${\mathrm{false}}$ (4)
 > $\mathrm{G2}≔\mathrm{RelationGraph}\left(\left[\mathrm{seq}\left(1..20\right)\right],\mathrm{DivisibleBy}\right)$
 ${\mathrm{G2}}{≔}{\mathrm{Graph 2: a directed graph with 20 vertices and 46 arc\left(s\right)}}$ (5)
 > $\mathrm{NumberOfEdges}\left(\mathrm{G2}\right)$
 ${46}$ (6)

We can build a bipartite graph example using two vertex lists.

 > $\mathrm{G3}≔\mathrm{RelationGraph}\left(\left[\left[1859,5832,6561,8192,8575\right],\left[2,3,5\right]\right],\mathrm{DivisibleBy}\right)$
 ${\mathrm{G3}}{≔}{\mathrm{Graph 3: a directed graph with 8 vertices and 5 arc\left(s\right)}}$ (7)

Compatibility

 • The GraphTheory[RelationGraph] command was introduced in Maple 2024.