6
$\begingroup$

According to Mathworld there is an undocumented function

GraphComputation`GraphProduct[G1, G2, "Cartesian"]

To compute the cartesian graph product.

Now in line with the example shown:

enter image description here

I would expect

GraphComputation`GraphProduct[PathGraph[Range[2]], PathGraph[Range[3]], "Cartesian"]

To product the ladder graph shown on the right. Yet, the end result seems to be enter image description here which doesn't even have the right number of nodes.

Is the function just unfinished (and presumably the reason for its undocumented nature), or is there some way to coax it into providing the correct answer?

$\endgroup$
  • 1
    $\begingroup$ It does have 6 nodes but two nodes overlap as you can see by adding the options VertexLabels -> "Name" and ImagePadding -> 20. $\endgroup$ – kglr Aug 7 '18 at 4:34
  • 2
    $\begingroup$ ... You can set the layout using GraphLayout -> {"GridEmbedding", "Dimension" -> {2, 3}} . $\endgroup$ – kglr Aug 7 '18 at 4:35
4
$\begingroup$

For the given inputs GraphProduct produces a graph with 6 vertices, but, somehow, vertices 1 and 6 overlap:

GraphComputation`GraphProduct[PathGraph[Range[2]], PathGraph[Range[3]], "Cartesian", 
 ImagePadding -> 20, VertexLabels -> "Name"]

enter image description here

VertexList @ %

{1, 2, 3, 4, 5, 6}

You can use the option GraphLayout to specify the layout you would like to have, e.g.,

GraphComputation`GraphProduct[PathGraph[Range[2]], PathGraph[Range[3]], "Cartesian",
 ImagePadding -> 20, 
 VertexLabels -> "Name", 
 GraphLayout -> {"GridEmbedding", "Dimension" -> {2, 3}}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.