The function graph is a constructor for Graph, a type of HyperGraph. The user can input a graph in a number of different ways, which we describe below. The information describing the graph is stored in a hash table.
For the first possibility, the user inputs a polynomial ring, which specifies the vertices of graph, and a list of the edges of the graph. The edges are represented as lists.
i1 : R = QQ[a..f]; |
i2 : E = {{a,b},{b,c},{c,f},{d,a},{e,c},{b,d}} o2 = {{a, b}, {b, c}, {c, f}, {d, a}, {e, c}, {b, d}} o2 : List |
i3 : g = graph (R,E) o3 = Graph{edges => {{a, b}, {b, c}, {c, f}, {a, d}, {c, e}, {b, d}}} ring => R vertices => {a, b, c, d, e, f} o3 : Graph |
As long as the edge list is not empty, the ring can be omitted. When a ring is not passed to the constructor, the underlying hypergraph takes its ring from the first variable found.
i4 : S = QQ[z_1..z_8]; |
i5 : E1 = {{z_1,z_2},{z_2,z_3},{z_3,z_4},{z_4,z_5},{z_5,z_6},{z_6,z_7},{z_7,z_8},{z_8,z_1}} o5 = {{z , z }, {z , z }, {z , z }, {z , z }, {z , z }, {z , z }, {z , z }, 1 2 2 3 3 4 4 5 5 6 6 7 7 8 ------------------------------------------------------------------------ {z , z }} 8 1 o5 : List |
i6 : E2 = {{z_1,z_2},{z_2,z_3}} o6 = {{z , z }, {z , z }} 1 2 2 3 o6 : List |
i7 : g1 = graph E1 o7 = Graph{edges => {{z , z }, {z , z }, {z , z }, {z , z }, {z , z }, {z , z }, {z , z }, {z , z }}} 1 2 2 3 3 4 4 5 5 6 6 7 1 8 7 8 ring => S vertices => {z , z , z , z , z , z , z , z } 1 2 3 4 5 6 7 8 o7 : Graph |
i8 : g2 = graph E2 o8 = Graph{edges => {{z , z }, {z , z }} } 1 2 2 3 ring => S vertices => {z , z , z , z , z , z , z , z } 1 2 3 4 5 6 7 8 o8 : Graph |
The list of edges could also be entered as a list of square-free quadratic monomials.
i9 : T = QQ[w,x,y,z]; |
i10 : e = {w*x,w*y,w*z,x*y,x*z,y*z} o10 = {w*x, w*y, w*z, x*y, x*z, y*z} o10 : List |
i11 : g = graph e o11 = Graph{edges => {{w, x}, {w, y}, {x, y}, {w, z}, {x, z}, {y, z}}} ring => T vertices => {w, x, y, z} o11 : Graph |
Another option for defining an graph is to use an ideal or monomialIdeal.
i12 : C = QQ[p_1..p_6]; |
i13 : i = monomialIdeal (p_1*p_2,p_2*p_3,p_3*p_4,p_3*p_5,p_3*p_6) o13 = monomialIdeal (p p , p p , p p , p p , p p ) 1 2 2 3 3 4 3 5 3 6 o13 : MonomialIdeal of C |
i14 : graph i o14 = Graph{edges => {{p , p }, {p , p }, {p , p }, {p , p }, {p , p }}} 1 2 2 3 3 4 3 5 3 6 ring => C vertices => {p , p , p , p , p , p } 1 2 3 4 5 6 o14 : Graph |
i15 : j = ideal (p_1*p_2,p_1*p_3,p_1*p_4,p_1*p_5,p_1*p_6) o15 = ideal (p p , p p , p p , p p , p p ) 1 2 1 3 1 4 1 5 1 6 o15 : Ideal of C |
i16 : graph j o16 = Graph{edges => {{p , p }, {p , p }, {p , p }, {p , p }, {p , p }}} 1 2 1 3 1 4 1 5 1 6 ring => C vertices => {p , p , p , p , p , p } 1 2 3 4 5 6 o16 : Graph |
A graph can be made from any hypergraph whose edges are all of size two.
i17 : D = QQ[r_1..r_5]; |
i18 : h = hyperGraph {r_1*r_2,r_2*r_4,r_3*r_5,r_5*r_4,r_1*r_5} o18 = HyperGraph{edges => {{r , r }, {r , r }, {r , r }, {r , r }, {r , r }}} 1 2 2 4 1 5 3 5 4 5 ring => D vertices => {r , r , r , r , r } 1 2 3 4 5 o18 : HyperGraph |
i19 : g = graph h o19 = Graph{edges => {{r , r }, {r , r }, {r , r }, {r , r }, {r , r }}} 1 2 2 4 1 5 3 5 4 5 ring => D vertices => {r , r , r , r , r } 1 2 3 4 5 o19 : Graph |
Not all graph constructors are able to make the empty graph, that is, the graph with no edges. Specifically, the constructors that take only a list cannot make the empty graph because the underlying ring is not given. To define the empty graph, give an explicit polynomial ring, or give the (monomial) ideal.
i20 : E = QQ[m,n,o,p] o20 = E o20 : PolynomialRing |
i21 : graph(E, {}) o21 = Graph{edges => {} } ring => E vertices => {m, n, o, p} o21 : Graph |
i22 : graph monomialIdeal(0_E) -- the zero element of E (do not use 0) o22 = Graph{edges => {} } ring => E vertices => {m, n, o, p} o22 : Graph |
i23 : graph ideal(0_E) o23 = Graph{edges => {} } ring => E vertices => {m, n, o, p} o23 : Graph |
The object graph is a method function.