Macaulay2 » Documentation
Packages » EdgeIdeals :: complementGraph
next | previous | forward | backward | up | index | toc

# complementGraph -- returns the complement of a graph or hypergraph

- Usage:
    `g = complementGraph G`
    `h = complementGraph H`
- Inputs:
  - G, a graph,
  - H, a hypergraph,
- Outputs:
  - g, a graph, the complement of G, whose edges are the set of edges not in G
  - h, a hypergraph, the complement of H, whose edge set is found by taking the complement of each edge of H in the vertex set

## Description

The function complementGraph finds the complement of a graph and hypergraph. Note that this function behaves differently depending upon the type of input. When applied to a graph, complementGraph returns the graph whose edge set is the set of edges not in G. When applied to a hypergraph, the edge set is found by taking the complement of each edge of H in the vertex set.

    i1 : R = QQ[a,b,c,d,e];

    i2 : c5 = graph {a*b,b*c,c*d,d*e,e*a}; -- graph of the 5-cycle

    i3 : complementGraph c5 -- the graph complement of the 5-cycle

    o3 = Graph{"edges" => {{a, c}, {b, e}, {b, d}, {c, e}, {a, d}}}
               "ring" => R
               "vertices" => {a, b, c, d, e}

    o3 : Graph

    i4 : c5hypergraph = hyperGraph c5 -- the 5-cycle, but viewed as a hypergraph

    o4 = HyperGraph{"edges" => {{a, b}, {b, c}, {c, d}, {a, e}, {d, e}}}
                    "ring" => R
                    "vertices" => {a, b, c, d, e}

    o4 : HyperGraph

    i5 : complementGraph c5hypergraph

    o5 = HyperGraph{"edges" => {{c, d, e}, {a, d, e}, {a, b, e}, {b, c, d}, {a, b, c}}}
                    "ring" => R
                    "vertices" => {a, b, c, d, e}

    o5 : HyperGraph

## Caveat

Notice that complementGraph works differently on graphs versus hypergraphs.

## Ways to use complementGraph:

- `complementGraph(Graph)`
- `complementGraph(HyperGraph)`

## For the programmer

The object complementGraph is a method function.

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