GraphTheory
RelationGraph
construct graph from relation
Calling Sequence
Parameters
Options
Description
Examples
Compatibility
RelationGraph( V, f )
RelationGraph( [V1, V2], f )
V
-
list of integers, strings or symbols (vertex labels), or two-element
f
procedure of two arguments representing a relation
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.
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.
In this undirected graph, there is an edge between a and b if they are relatively prime.
with⁡GraphTheory:
G1≔RelationGraph⁡seq⁡1..25,NumberTheory:-AreCoprime
G1≔Graph 1: an undirected graph with 25 vertices and 199 edge(s)
NumberOfEdges⁡G1
199
In this directed graph there is an arc from a to b if a is divisible by b.
DivisibleBy≔p,q↦evalb⁡irem⁡p,q=0:
DivisibleBy⁡4,2
true
DivisibleBy⁡5,3
false
G2≔RelationGraph⁡seq⁡1..20,DivisibleBy
G2≔Graph 2: a directed graph with 20 vertices and 46 arc(s)
NumberOfEdges⁡G2
46
We can build a bipartite graph example using two vertex lists.
G3≔RelationGraph⁡1859,5832,6561,8192,8575,2,3,5,DivisibleBy
G3≔Graph 3: a directed graph with 8 vertices and 5 arc(s)
The GraphTheory[RelationGraph] command was introduced in Maple 2024.
For more information on Maple 2024 changes, see Updates in Maple 2024.
See Also
TransitiveClosure
TransitiveReduction
Download Help Document