Macaulay2 » Documentation
Packages » Graphs :: cartesianProduct
next | previous | forward | backward | up | index | toc

# cartesianProduct -- Computes the cartesian product of two graphs

- Usage:
    `F = cartesianProduct(G,H)`
- Inputs:
  - G, a graph,
  - H, a graph,
- Outputs:
  - F, a graph, The Cartesian Product of G and H

## Description

This method will take in any two graphs and output the cartesian product of the two graphs. The vertex set of this new graph is the cartesian product of the vertex sets of the two input graphs. The keys for each vertex will be output as a sequence. Any two vertices (u,u') and (v,v') are adjacent in the cartesian product of G and H if and only if either u = v and u' is adjacent with v' in H, or u' = v' and u is adjacent with v in G.

    i1 : G = graph({1,2},{{1,2}});

    i2 : H = graph({3,4,5},{{3,4},{4,5}});

    i3 : G' = cartesianProduct(G,H)

    o3 = Graph{(1, 3) => {(2, 3), (1, 4)}        }
               (1, 4) => {(1, 3), (2, 4), (1, 5)}
               (1, 5) => {(2, 5), (1, 4)}
               (2, 3) => {(1, 3), (2, 4)}
               (2, 4) => {(2, 5), (2, 3), (1, 4)}
               (2, 5) => {(2, 4), (1, 5)}

    o3 : Graph

## See also

- strongProduct -- a method for taking the strong product of two graphs
- directProduct -- direct product
- graphComposition -- A method for composing two graphs

## Ways to use cartesianProduct:

- `cartesianProduct(Graph,Graph)`

## For the programmer

The object cartesianProduct is a method function.

The source of this document is in /build/macaulay2-88fgJW/macaulay2-1.25.11+ds/M2/Macaulay2/packages/Graphs.m2:4783:0.