-------------------------------------
-- Macaulay 2 sample input
-- monica (July 2011)
-------------------------------------

--- GETTING STARTED

installPackage "EdgeIdeals"
restart
loadPackage "EdgeIdeals"

--- INPUTING A GRAPH

R = QQ[x_1..x_6]
E = {{x_1,x_2},{x_2,x_3},{x_3,x_4},{x_4,x_5},{x_5,x_1},{x_1,x_6},{x_2,x_6},{x_3,x_6}}
H = graph(R,E)  -- one way to define a graph
edges H
vertices H
e = monomialIdeal(x_1*x_2,x_2*x_3,x_3*x_4,x_4*x_5,x_5*x_1,x_1*x_6,x_2*x_6,x_3*x_6)
G = graph e -- another way to define a graph
G == H -- test if two graphs are the same

--- Pay attention to the polynomial ring!
S = QQ[x_1..x_7]
--  ee same ideal as e above
ee = monomialIdeal(x_1*x_2,x_2*x_3,x_3*x_4,x_4*x_5,x_5*x_1,x_1*x_6,x_2*x_6,x_3*x_6)
GG = graph ee -- x_7 is an isolated vertex
GG == G

--- EDGE AND COVER IDEALS

i = edgeIdeal G
j = coverIdeal G
dual i == j -- check if the Alexander Dual of i is j

-- ASSOCIATED PRIMES

ass j -- associated primes 
ass i 
vertexCovers G
mingens j

--- DOCUMENTATION AND SPECIAL TYPES OF GRAPHS
viewHelp cycle 
C6 = cycle R
C6c = complementGraph C6
isChordal C6
isChordal C6c

-- FINDING CYCLES
smallestCycleSize C6
smallestCycleSize C6c  
allEvenHoles C6c  -- C6c is not chordal, so must have some cycle of size > 3

-- RANDOM GRAPHS
t = randomGraph(R,8) -- random graph on 6 vertices and 8 edges
isChordal oo
betti res edgeIdeal complementGraph t  -- Froberg's theorem

---- Make a random graph, we check if it is first (a) chordal,
---- and (b) if it is chordal, we check if R/I(G) is SCM


testChordalSCM = n->(
     for i from 1 to n do (    
       t = randomGraph(R,random(5,15));  -- random graph with 5 to 15 vertices
         << "Graph number " << i << " is chordal: " << isChordal(t) << endl;
	   if isChordal(t) == true then (
	          << "Random Chordal Graph Sequentially Cohen Macaulay: " << isSCM(t) << endl;
		         )
			   );   
     );			      
testChordalSCM(15)

R = QQ[x_1..x_10]
testChordalSCM(10)







---  You may conjecture chordal ==> SCM.  Indeed, we have
--- 
--- 
--- (THEOREM)  G chordal, then R/I(G) is SCM.