RelationGraph - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


GraphTheory

  

RelationGraph

  

construct graph from relation

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

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.

withGraphTheory:

G1RelationGraphseq1..25,NumberTheory:-AreCoprime

G1Graph 1: an undirected graph with 25 vertices and 199 edge(s)

(1)

NumberOfEdgesG1

199

(2)

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

DivisibleByp,qevalbiremp,q=0:

DivisibleBy4,2

true

(3)

DivisibleBy5,3

false

(4)

G2RelationGraphseq1..20,DivisibleBy

G2Graph 2: a directed graph with 20 vertices and 46 arc(s)

(5)

NumberOfEdgesG2

46

(6)

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

G3RelationGraph1859,5832,6561,8192,8575,2,3,5,DivisibleBy

G3Graph 3: a directed graph with 8 vertices and 5 arc(s)

(7)

Compatibility

• 

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