<?xml version="1.0" encoding="utf-8" ?> <!-- for emacs: -*- coding: utf-8 -*- --> <!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head><title>graph -- constructor for Graph</title> <link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/> </head> <body> <table class="buttons"> <tr> <td><div><a href="_has__Good__Leaf.html">next</a> | <a href="___Graph.html">previous</a> | <a href="_has__Good__Leaf.html">forward</a> | <a href="___Graph.html">backward</a> | up | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div> </td> </tr> </table> <hr/> <div><h1>graph -- constructor for Graph</h1> <div class="single"><h2>Synopsis</h2> <ul><li><div class="list"><dl class="element"><dt class="heading">Usage: </dt><dd class="value"><div><tt>G = graph(R,E)</tt><br/><tt>G = graph(I)</tt><br/><tt>G = graph(J)</tt><br/><tt>G = graph(E)</tt><br/><tt>G = graph(H)</tt></div> </dd></dl> </div> </li> <li><div class="single">Inputs:<ul><li><span><tt>R</tt>, <span>a <a href="../../Macaulay2Doc/html/___Polynomial__Ring.html">polynomial ring</a></span>, whose variables correspond to vertices of the hypergraph</span></li> <li><span><tt>E</tt>, <span>a <a href="../../Macaulay2Doc/html/___List.html">list</a></span>, a list of edges, which themselves are lists of vertices</span></li> <li><span><tt>I</tt>, <span>a <a href="../../Macaulay2Doc/html/___Monomial__Ideal.html">monomial ideal</a></span>, which must be square-free and quadratic, and whose generators become the edges of the graph</span></li> <li><span><tt>J</tt>, <span>an <a href="../../Macaulay2Doc/html/___Ideal.html">ideal</a></span>, which must be square-free, quadratic, and monomial, and whose generators become the edges of the graph</span></li> <li><span><tt>H</tt>, <span>a <a href="___Hyper__Graph.html">hypergraph</a></span>, to be converted to a graph. The edges in <tt>H</tt> must be of size two.</span></li> </ul> </div> </li> <li><div class="single">Outputs:<ul><li><span><tt>G</tt>, <span>a <a href="___Graph.html">graph</a></span></span></li> </ul> </div> </li> </ul> </div> <div class="single"><h2>Description</h2> <div><p>The function <tt>graph</tt> is a constructor for <a href="___Graph.html" title="a class for graphs">Graph</a>, a type of <a href="___Hyper__Graph.html" title="a class for hypergraphs">HyperGraph</a>. 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.</p> <div>For the first possiblity, the user inputs a polynomial ring, which specifices the vertices of graph, and a list of the edges of the graph. The edges are represented as lists.</div> <table class="examples"><tr><td><pre>i1 : R = QQ[a..f];</pre> </td></tr> <tr><td><pre>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</pre> </td></tr> <tr><td><pre>i3 : g = graph (R,E) o3 = Graph{edges => {{a, b}, {b, c}, {c, f}, {d, a}, {e, c}, {b, d}}} ring => R vertices => {a, b, c, d, e, f} o3 : Graph</pre> </td></tr> </table> <div>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.</div> <table class="examples"><tr><td><pre>i4 : S = QQ[z_1..z_8];</pre> </td></tr> <tr><td><pre>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</pre> </td></tr> <tr><td><pre>i6 : E2 = {{z_1,z_2},{z_2,z_3}} o6 = {{z , z }, {z , z }} 1 2 2 3 o6 : List</pre> </td></tr> <tr><td><pre>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</pre> </td></tr> <tr><td><pre>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</pre> </td></tr> </table> <div>The list of edges could also be entered as a list of square-free quadratic monomials.</div> <table class="examples"><tr><td><pre>i9 : T = QQ[w,x,y,z];</pre> </td></tr> <tr><td><pre>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</pre> </td></tr> <tr><td><pre>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</pre> </td></tr> </table> <div>Another option for defining an graph is to use an <a href="../../Macaulay2Doc/html/_ideal.html" title="make an ideal">ideal</a> or <a href="../../Macaulay2Doc/html/_monomial__Ideal.html" title="make a monomial ideal">monomialIdeal</a>.</div> <table class="examples"><tr><td><pre>i12 : C = QQ[p_1..p_6];</pre> </td></tr> <tr><td><pre>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</pre> </td></tr> <tr><td><pre>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</pre> </td></tr> <tr><td><pre>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</pre> </td></tr> <tr><td><pre>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</pre> </td></tr> </table> <div>A graph can be made from any hypergraph whose edges are all of size two.</div> <table class="examples"><tr><td><pre>i17 : D = QQ[r_1..r_5];</pre> </td></tr> <tr><td><pre>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</pre> </td></tr> <tr><td><pre>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</pre> </td></tr> </table> <div>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.</div> <table class="examples"><tr><td><pre>i20 : E = QQ[m,n,o,p] o20 = E o20 : PolynomialRing</pre> </td></tr> <tr><td><pre>i21 : graph(E, {}) o21 = Graph{edges => {} } ring => E vertices => {m, n, o, p} o21 : Graph</pre> </td></tr> <tr><td><pre>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</pre> </td></tr> <tr><td><pre>i23 : graph ideal(0_E) o23 = Graph{edges => {} } ring => E vertices => {m, n, o, p} o23 : Graph</pre> </td></tr> </table> </div> </div> <div class="single"><h2>See also</h2> <ul><li><span><a href="_hyper__Graph.html" title="constructor for HyperGraph">hyperGraph</a> -- constructor for HyperGraph</span></li> <li><span><a href="___Constructor_sp__Overview.html" title="a summary of the many ways of making graphs and hypergraphs">Constructor Overview</a> -- a summary of the many ways of making graphs and hypergraphs</span></li> </ul> </div> <div class="waystouse"><h2>Ways to use <tt>graph</tt> :</h2> <ul><li>graph(HyperGraph)</li> <li>graph(Ideal)</li> <li>graph(List)</li> <li>graph(MonomialIdeal)</li> <li>graph(PolynomialRing,List)</li> </ul> </div> </div> </body> </html>