7

Click here to load reader

Maple Worksheet

Embed Size (px)

Citation preview

Page 1: Maple Worksheet

Subject Computation of Chromatic PolynomialsDate 4/1/05Author(s) Gary Haggard and Thomas R. Mathies, Bucknell UniversityTechnical Assistance Wade Hutchinson, Bucknell UniversityAbstract An effective algorithm for computing chromatic polynomials of con-nected graphs is presented. The range and speed of this algorithm are substan-tially beyond other algorithms for this purpose.Animations NoVersion Maple 9Viewed

Keywords: Graph, complete graph, coloring of a graph, chromatic polynomial,spanning tree, planar graph, planar dual, edge deletion graph, edge contractiongraph, computation tree, tree basis, standard basis

Computing Chromatic Polynomials Using chromial

Let G = (V, E) be a graph with vertex set V and edge set E. A chromaticpolynomial for G is a polynomial P (G, λ) of degree |V | with the values at λ beingthe number of ways to color the graph G using λ colors, where λ = 0, 1, 2, . . ..An edge deletion graph is formed by simply removing an edge e from the graph.The edge deletion graph is denoted as G − e. The edge contraction graphinvolves first deleting an edge e from the graph and then identifying the ends ofthat edge as a single vertex. The edge contraction graph is denoted as G/e Thepaper [5] gives a very good introduction to chromatic polynomials and describesproperties that can be proven by induction using the recursion of Theorem 1.Theorem 1 gives a method for recursively computing a chromatic polynomial.

Theorem 1 [5]. Let G = (V, E) be a graph. Let e ∈ E. Then,

P (G, λ) = P (G − e, λ) − P (G/e, λ),

where G − e is the edge deletion graph and G/e is the edge contraction graph.

The computation of a chromatic polynomial for any graph would seem to befairly straightforward using Theorem 1. It has, however, only been quite recentlythat the hand computation of Hall, Siry, and Vanderslice [3] that resulted in thecomputation of the chromatic polynomial of the planar dual of the truncatedicosahedron was carried out by computer using this software, see [1] and [2].

1

Page 2: Maple Worksheet

Representations

The chromatic polynomial has several common representations. The most ob-vious one is to use the simple powers of λ : 1, λ, λ2, λ3, . . . as a basis for thepolynomial. This basis is called the standard basis. A representation for graphswith at lest one edge that is particularly useful for implementation purposes isa representation in terms of the tree basis: λ(λ − 1), λ(λ − 1)2, λ(λ − 1)3, . . . .The chromatic polynomial of complete(4) can be written either as

P (complete(4), λ) = λ4 − 6λ3 + 11λ2 − 6λ

orP (complete(4), λ) = λ(λ − 1)3 − 3λ(λ − 1)2 + 2λ(λ − 1).

The Maple functions that expand polynomials can easily transform a chromaticpolynomial expressed in terms of the tree basis into a chromatic polynomialexpressed in the standard basis. The use of the tree basis has a benefit in thecomputation process. The termination of a branch of the computation tree canoccur when a tree is detected since all trees with the same number of verticeshave the same chromatic polynomial (see Theorem 5 [5]).

The computation identifies a spanning tree so that for a graph that is not atree, there is a way to choose an edge for the deletion/contraction process thatwill not disconnect the graph. Dealing with connected graphs is a conveniencerather than a necessity since the chromatic polynomial of a disconnected graphis the product of the chromatic polynomials of its connected components.

The Algorithm

The fundamental operation to carry out in computing a chromatic polynomialis choosing an edge and applying the recursion described in Theorem 1. Therecursion reduces the problem to two smaller subproblems that are viewed asnodes at the next level of the computation tree. This process is repeated foreach node of the computation tree until the graph occurring can actually haveits chromatic polynomial computed. The chromatic polynomials computed toterminate branches of the computation tree are then used to compute the chro-matic polynomial of the graphs occurring above them in the computation tree.This process continues until the original graph has its chromatic polynomialcomputed from the chromatic polynomials of the two graphs immediately belowit in the computation tree. The general idea of the algorithm will be describedand then some of the ideas used to optimize the computations will be described.Additional details about the computation can be found in [1] and [2].

2

Page 3: Maple Worksheet

chromial(graphG, polynomialP )Determine a spanning tree in GPut G on the graph stackCall the computational procedure deleteContractPrint the chromatic polynomial returned from deleteContract

deleteContract(graph G, polynomial P)While the graph stack is not empty

If G satisfies the threshold conditionIf a graph isomorphic to G has previously been encountered

Look up the chromatic polynomial for Gelse

Determine if it is time to compute P(G, x)or call deleteContract with this graph

Get a new graph off the graph stackelse

Carry out delete and contract process for some edge

The ordering of the input edges uses the system random number generator topermute them before the graph data structure is built by the program. This stepallows different computation trees to be used and hence a level of correctness isimplicit since the computation tree depends directly on the data structure for thegraph that is determined by the order of input of the edges. The computationscan be different because the order in which the edges are input determineshow a spanning tree is constructed and the order of the edges used in thedelete/contract process. The chromatic polynomial is independent of the wayin which it is computed.

The isomorphism test is implemented using Brendan McKay’s software nauty[4]. At a number of predetermined values for the size of the vertex set of thegraph, the isomorphism test is made. The occurrence of a graph in the hashtable indicates that it has had its chromatic polynomial computed in some otherbranch of the computation tree. The isomorphic graph can then just use theresult of the previous computation and not repeat the computation. The hashtable is allocated dynamically by the program and increased in size as needarises.

The termination conditions are twofold. If the graph is a tree, then thechromatic polynomial is just x(x− 1)(n−1), where n is the number of vertices inthe tree. This polynomial is the same for all trees with n vertices. The secondtest is whether the graph has seven or fewer vertices. In this case, a sequenceof invariants are tested to identify the isomorphism class of the graph. Thechromatic polynomial of each isomorphism class is included in the program.

Examples

The data structure that represents a graph in this algorithm requires that2 ∗ |E| + |V | < 950 and |V | < 65. At this point the algorithm is not designed

3

Page 4: Maple Worksheet

for complete graphs with more than 30 vertices. The algorithm is designedonly for connected graphs. Disconnected graphs cause erroneous output. Fordisconnected graphs the algorithm can be run for each component and then theresulting chromatic polynomials can be multiplied together using other Maplefunctions.

The graph of the planar dual of the truncated icosahedron (TI) had itschromatic polynomial computed in about one second in contrast to the timerequired for the hand calculation of [3].

P (TI, λ) = +1 λ ∗ (λ − 1)31

−59 λ ∗ (λ − 1)30

+1710 λ ∗ (λ − 1)29

−32450 λ ∗ (λ − 1)28

+453403 λ ∗ (λ − 1)27

−4973197 λ ∗ (λ − 1)26

+44583400 λ ∗ (λ − 1)25

−335797000 λ ∗ (λ − 1)24

+2167755011 λ ∗ (λ − 1)23

−12175221281 λ ∗ (λ − 1)22

+60183865818 λ ∗ (λ − 1)21

−264193106900 λ ∗ (λ − 1)20

+1037166520075 λ ∗ (λ − 1)19

−3661052024851 λ ∗ (λ − 1)18

+11665962055746 λ ∗ (λ − 1)17

−33646105485699 λ ∗ (λ − 1)16

+87942380056419 λ ∗ (λ − 1)15

−208269347521537 λ ∗ (λ − 1)14

+446095183473635 λ ∗ (λ − 1)13

−861047769728938 λ ∗ (λ − 1)12

+1489229660477423 λ ∗ (λ − 1)11

−2289676883015802 λ ∗ (λ − 1)10

+3096554498357805 λ ∗ (λ − 1) 9

−3633794047947863 λ ∗ (λ − 1) 8

+3636161286009548 λ ∗ (λ − 1) 7

−3033198826142253 λ ∗ (λ − 1) 6

+2046265622980682 λ ∗ (λ − 1) 5

−1069414679790850 λ ∗ (λ − 1) 4

+405031279488050 λ ∗ (λ − 1) 3

−98611241495930 λ ∗ (λ − 1) 2

+11551226205884 λ ∗ (λ − 1) 1

The computation of the chromatic polynomial of the complete graph on30 vertices carried out on a Sun Blade 200 took one and a half seconds ofcomputation time. The result is

4

Page 5: Maple Worksheet

P (complete(30), λ) =+1 λ ∗ (λ − 1)29

−406 λ ∗ (λ − 1)28

+78561 λ ∗ (λ − 1)27

−9642906 λ ∗ (λ − 1)26

+843041745 λ ∗ (λ − 1)25

−55880640270 λ∗ (λ − 1)24

+2918785153245 λ∗ (λ − 1)23

−123268226851770 λ∗ (λ − 1)22

+4285624815406935 λ∗ (λ − 1)21

−124243455209483610 λ∗ (λ − 1)20

+3031400077459516035 λ∗ (λ − 1)19

−62656135265695354110 λ∗ (λ − 1)18

+1101911578045922391915 λ∗ (λ − 1)17

−16532187926098943672490 λ∗ (λ − 1)16

+211821088794711294496815 λ∗ (λ − 1)15

−2316762871029690607422990 λ∗ (λ − 1)14

+21590257290787088602515180 λ∗ (λ − 1)13

−170857232541629621904997080 λ∗ (λ − 1)12

+1142413073615783087483702480 λ∗ (λ − 1)11

−6409259592413089839517170080 λ∗ (λ − 1)10

+29891934088703915048808047424 λ∗ (λ − 1) 9

−114481515057741551880042390144 λ∗ (λ − 1) 8

+354237722035840197377888292864 λ∗ (λ − 1) 7

−866422974395414742142363398144 λ∗ (λ − 1) 6

+1625014498326371300452283596800 λ∗ (λ − 1) 5

−2236045380156380112643362816000 λ∗ (λ − 1) 4

+2105684281550279072336117760000 λ∗ (λ − 1) 3

−1197348677077520393310044160000 λ∗ (λ − 1) 2

+304888344611713860501504000000 λ∗ (λ − 1) 1

Run Time Hints

There are always decisions to make about the size of the data structures usedin a program so that the typical example can be dealt with. The number ofedges in the data structure defined allows for complete(30) to have its chromaticpolynomial computed (as well as all its subgraphs). Since the computationdepends on the computation tree determined for the particular computation, itis likely that computing the chromatic polynomial for the same graph severaltimes will result in quite different run times. Graphs with a larger number ofvertices must still satisfy the condition

2 ∗ |E| + |V | < 950.

These requirements are confirmed by two assertions in the program:

assert((TWO ∗ |E| + |V |) < EDGESIZE);

5

Page 6: Maple Worksheet

assert(|V | < V ERTEXSIZE);

To check that the original graph is connected, the vertices are numbered duringan initial depth first search. The final depth first search number is comparedwith the number of vertices in the assertion:

assert(dfsNumberedV ertices == verticesInGraph);

The assertion indicates the number of vertices in first connected component ofthe graph. When the assertion is true, the graph is connected. The assertion

assert(!loopPresent);

checks to see that the original graph has no loops. If this asssertion is false, it islikely there was an error in entering the edges of the graph. The next internalcheck is the assertion:

assert(C >= 0);

that is true as long as the internal stack that manages the graphs that are notthe focus of the computation, has not run out of space. It is not possible topredict what a particular computation tree will look like and so there has to bean estimate of the expected size of a large computation tree. The computationtree depends on the order of the input of the edges of the graph. Since thefirst step in the program is to permute the edges of the graph being entered,one strategy when this assertion is false is to run the graph again and hope youhave better luck in the choice of a computation tree. The data structure canbe made to allow larger computation trees. It is suggested that you [email protected] to work out the details.

One additional assertion verifies that the dynamic allocation of memeroy forthe hash table does not exceed its limits:

assert(currentBlock < MAXBLOCKS)

The hash table has access to over 1gig of memory and seems to be large enough.iClearly, this can be increased if needed.

Runtime for graphs with large numbers of vertices can take hours. It is notdifficult to enter a graph for which one run takes seconds and another run ofthe same graph takes hours to complete. The impact of the computation treeis very marked and not very well understood.

Bibliography

[1] Haggard, G. and T.R. Mathies, Note: The computation of chromatic poly-nomials, Discrete Mathematics 199 (1999) 227–231.

[2] Haggard, G. and T.R. Mathies, Using Thresholds to Compute ChromaticPolynomials, Ars Combinatoria 58 (2001) 85–95.

6

Page 7: Maple Worksheet

[3] Hall, D.W., J.W. Siry, and B.R. Vanderslice, The Chromatic Polynomialof the Truncated Icosahedron, it Proceedings of the American MathematicalSociety (1965), 620–628.

[4] McKay, B.D., nauty User’s Guide (Version 1.5), Technical Report TR-CS-90-02, Australian National University, Department of Computer Science, 1990.

[5] Read, R.C., An introduction to chromatic polynomials, J. Comb. Theory B13 (1972) 52–71.

7