In this paper, we study a variant of a hat guessing game. In these types of games, there are some entities—players, pirates, sages, or, as in our case, bears. A bear sits on each vertex of graph . There is some adversary (a demon in our case) that puts a colored hat on the head of each bear. A bear on a vertex sees only the hats of bears on the neighboring vertices of but he does not know the color of his own hat. Now to defeat the demon, the bears should guess correctly the color of their hats. However, the bears can only discuss their strategy before they are given the hats. After they get them, no communication is allowed, each bear can only guess his hat color. The variants of the game differ in the bears’ winning condition.
The first variant was introduced by Ebert 
. In this version, each bear gets a red or blue hat (chosen uniformly and independently) and they can either guess a color or pass. The bears see each other, i.e. they stay on vertices of a clique. They win if at least one bear guesses his color correctly and no bear guesses a wrong color. The question is what is the highest probability that the bears win achievable by some strategy. Soon, the game became quite popular and it was even mentioned in NY Times.
Winkler  studied a variant where the bears cannot pass and the objective is how many of them guess correctly their hat color. A generalization of this variant for more than two colors was studied by Feige  and Aggarwal . Butler et al.  studied a variant where the bears are sitting on vertices of a general graph, not only a clique. For a survey of various hat guessing games, we refer to theses of Farnik  or Krzywkowski .
In this paper, we study a variant of the game introduced by Farnik , where each bear has to guess and they win if at least one bear guesses correctly. He introduced a hat guessing number HG of a graph (also named as hat chromatic number and denoted in later works) which is defined as the maximum such that bears win the game with hat colors. We study a variant where each bear can guess multiple times and we consider that a bear guesses correctly if the color of his hat is included in his guesses. We introduce a parameter fractional hat chromatic number of a graph , which we define as the supremum of such that each bear has guesses and they win the game with hat colors.
Albeit the hat guessing game looks like a recreational puzzle, connections to more “serious” areas of mathematics and computer science were shown—like coding theory [8, 18], network coding [13, 22], auctions , finite dynamical systems , and circuits . In this paper, we exhibit a connection between the hat guessing game and the independence polynomial of graphs, which is our main result. This connection allows us to compute the optimal strategy of bears (and thus the value of ) of an arbitrary chordal graph in polynomial time. We also prove that the fractional hat chromatic number is asymptotically equal, up to a logarithmic factor, to the maximum degree of a graph. Finally, we compute the exact value of of graphs from some classes, like paths, cycles, and cliques.
We would like to point out that the existence of the algorithm computing of a chordal graph is far from obvious. Butler et al.  asked how hard is to compute and the optimal strategy for the bears. Note that a trivial non-deterministic algorithm for computing the optimal strategy (or just the value of or ) needs exponential time because a strategy of a bear on is a function of hat colors of bears on neighbors of (we formally define the strategy in Section 2). It is not clear if the existence of a strategy for bears would imply a strategy for bears where each bear computes his guesses by some efficiently computable function (like linear, computable by a polynomial circuit, etc.). This would allow us to put the problem of computing into some level of the polynomial hierarchy, as noted by Butler et al. . However, we are not aware of any hardness results for the hat guessing games. The maximum degree bound for does not imply an exact efficient algorithm computing as well. This phenomenon can be illustrated by the edge chromatic number of graphs. By Vizing’s theorem [6, Chatper 5], it holds for any graph that . However, it is NP-hard to distinguish between these two cases .
Organization of the Paper. We finish this section with a summary of results about the variant of the hat guessing game we are studying. In the next section, we present notions used in this paper and we define formally the hat guessing game. In Section 3, we formally define the fractional hat chromatic number and compare it to . In Section 4, we generalize some previous results to the multi-guess setting. We use these tools to prove our main result in Section 5 including the poly-time algorithm that computes for chordal graphs. The maximum degree bound for and computation of exact values of paths and cycles are provided in Section 6.
1.1 Related Works
As mentioned above, Farnik  introduced a hat chromatic number of a graph as the maximum number of colors such that the bears win the hat guessing game with colors and played on . He proved that where is the maximum degree of .
Since then, the parameter was extensively studied. The parameter for multipartite graphs was studied by Gadouleau and Georgiu  and by Alon et al. . Szczechla  proved that of cycles is equal to if and only if the length of the cycle is or it is divisible by (otherwise it is ). Bosek et al.  gave bounds of for some graphs, like trees and cliques. They also provided some connections between and other parameters like chromatic number and degeneracy. They conjectured that is bounded by some function of the degeneracy of the graph . They showed that such function has to be at least exponential as they presented a graph of . This result was improved by He and Li  who showed there is a graph such that . It follows from the maximum degree bound of that can not be bounded by any function of degeneracy as there are graph classes of unbounded maximum degree and bounded degeneracy (e.g. trees or planar graphs). Recently, Kokhas et al.  studied a non-uniform version of the game, i.e., for each bear, there could be a different number of colors of the hat. They considered cliques and almost cliques. They also provided a technique to build a strategy for a graph whenever is made up by combining and with known strategies. We generalize some of their results and use them as “basic blocks” for our main result.
We use standard notions of the graph theory. For an introduction to this topic, we refer to the book by Diestel . We denote a clique as , a cycle as , and a path as , each on vertices. The maximum degree of a graph is denoted by , where we shorten it to if the graph is clear from the context. The neighbors of a vertex are denoted by . We use to denote the closed neighborhood of , i.e. . For a set of vertices of a graph , we denote a graph induced by vertices , i.e., a graph arising from by removing the vertices in .
A hat guessing game is a triple where
is an undirected graph, called the visibility graph,
is a hatness that determines the number of different possible hat colors for each bear, and
is a guessing number that determines the number of guesses each bear is allowed to make.
The rules of the game are defined as follows. On each vertex of sits a bear. The demon puts a hat on the head of each bear. Each hat has one of colors. The only information the bear on a vertex knows are the colors of hats put on bears sitting on neighbors of . Based on this information only, the bear has to guess a set of colors according to a deterministic strategy agreed to in advance. We say bear guesses correctly if he included the color of his hat in his guesses. The bears win if at least one bear guesses correctly.
Formally, we associate the colors with natural numbers and say that each bear can receive a hat colored by a color from the set . A hats arrangement is a function . A strategy of a bear on is a function , and a strategy for is a collection of strategies for all vertices, i.e. . We say that a strategy is winning if for any possible hats arrangement there exists at least one vertex such that is contained in the image of on , i.e., . Finally, the game is winning if there exists a winning strategy of the bears.
Some of our results are stated for a non-uniform variant of the hat guessing game. A non-uniform game is a triple where and
are vectors of natural numbers indexed by the vertices ofand a bear on gets a hat of one of colors and is allowed to guess exactly colors. Other rules are the same as in the standard hat guessing game. To distinguish between the uniform and non-uniform games, we always use plain letters and for the hatness and the guessing number, respectively, and bold letters (e.g. ) for vectors indexed by the vertices of .
For our proofs we use two classical results. First one is the inclusion-exclusion principle for computing a size of a union of sets.
[folklore] For a union of sets holds that
The other one is the rational root theorem, which we use to derive an algorithm for computing an exact value of , if the value is rational.
[Rational root theorem ] If a polynomial has integer coefficients, then every rational root is of the form where and are coprimes, is a divisor of , and is a divisor of .
3 Fractional Hat Chromatic Number
From the hat guessing games, we can derive parameters of the underlying visibility graph . Namely, the hat chromatic number is the maximum integer for which the hat guessing game is winning, i.e., each bear gets a hat colored by one of colors and each bear has only one guess—we call such game a single-guessing game. In this paper, we study a parameter fractional hat chromatic number arising from the hat multi-guessing game and defined as
Observe that . Farnik  and Bosek et al.  also study multi-guessing games. They considered a parameter that is the maximum number of colors such that the bears win the game . The difference between and is the following. If , then the bears win the game and . If , then there are such that and the bears win the game . However, it does not imply that the bears would win the game . In this section, we prove that if the bears win the game then they win the game for any constant . The opposite implication does not hold—a counterexample is paths which we discuss at the end of this section. Unfortunately, this property prevents us from using our algorithm, which computes , to compute also of chordal graphs.
Moreover, by definition, the parameter does not even have to be a rational number. In such a case, for each , it holds that
If then there are such that and the bears win the game .
If then the demon wins the game .
For example, the fractional hat chromatic number of the path is irrational. We discuss path in Section 6.1. In the case of an irrational , our algorithm computing the value of
of chordal graphs outputs an estimate ofwith arbitrary precision. We finish this section with a proof that the multi-guessing game is in some sense monotone. Let . If a game is winning, then the game is winning as well.
We derive a winning strategy for the game from a winning strategy for . Each bear interprets a color in as a pair where and . Let be guesses of the bear on in the game . For the game , a strategy of the bear on is to make guesses . It is straight-forward to verify that this is a winning strategy for . ∎
Let be a winning hat guessing game. Let be a rational number such that . Then, there exist numbers such that and the hat guessing game is winning.
Let such that and . Let111GCD stands for the greatest common divisor and LCM stands for the least common multiple. .
Let . By Observation 3 for , the game is winning. Let and . Since by the assumption, it holds that . Thus, the bears have a strategy for , as we increased the number of guesses and the hatness does not change (). Moreover, . ∎
It is straight-forward to prove a generalization of Lemma 3 for the non-uniform games. However, for simplicity, we state it only for the uniform games. By the proof of the previous lemma, we know that we can use a strategy for to create a strategy for a game for arbitrary . A question is if we can do it in general: Can we derive a winning strategy if we decrease the fraction , but the hatness and the guessing number are changed arbitrarily? It is true for cliques. We show in Section 4 that the bears win the game if and only if . However, it is not true in general. For example, for large enough it holds that , as we show in Section 6 that converges to 4 when goes to infinity. However, Butler et al.  proved that for any tree . Thus, the bears lose the game .
4 Basic Blocks
In this section, we generalize some results of Kokhas et al.  about cliques and strategies for graph products, which we use for proving our main result. The single-guessing version of the next theorem (without the algorithmic consequences) was proved by Kokhas et al. . Bears win a game if and only if
Moreover, if there is a winning strategy, then there is a winning strategy such that each can be described by two linear inequalities whose coefficients can be computed in linear time.
The proof follows the proof of Kokhas et al.  for the single-guessing game. First, suppose that and fix some strategy of bears. A bear on guesses correctly the color of his hat in exactly -fraction of all possible hat arrangements. Thus, if the sum is smaller than one, there is a hat arrangement where no bear guesses the color of his hat correctly.
Now suppose the opposite inequality holds, i.e., . Let . For simplicity, we denote and . Let . and (note that ). Let the bear on get a hat of color and
The bears cover the set by disjoint intervals of length . A bear on makes his guesses according to a hypothesis that is in an interval and we will show that he guesses correctly if . More formally, for we define the interval as . Note that the union of intervals is exactly the set . A bear on computes . Then, he guesses all such colors such that is in . Since contains consecutive natural numbers and is divisible by , he makes at most guesses. If is in then the bear on guesses the color of his hat correctly, because and thus the bear on includes the color in his guesses.
Note that the union of all intervals is exactly the set
By assumption, we have that . Since by definition, it follows that has to be in some interval .
For the “moreover” part, the bear on a vertex guesses all colors such that
Observe that is a linear function of hat colors of bears sitting on the vertices different from and the coefficients and can be computed in linear time. ∎
By Theorem 4, we can conclude the following corollary. For each , it holds that .
Kokhas et al.  provided another proof of analogue of Theorem 4 for the single-guessing game, which can be generalized with similar ideas. However, the second proof does not imply a polynomial time algorithm for computing the strategy on cliques. For the interested reader, we provide the second proof of Theorem 4 in Appendix A.
Further, we generalize a result of Kokhas et al. . In particular, we provide a new way to combine two hat guessing games on graphs and into a hat guessing game on graph obtained by gluing and together in a specific way.
Let and be graphs, let be a set of vertices inducing a clique in , and let be an arbitrary vertex of . The clique join of graphs and with respect to and is the graph such that ; and contains all the edges of , all the edges of that do not contain , and an edge between every and every neighbor of in . See Figure 1 for a sketch of a clique join.
Let and be two hat guessing games and let be a set inducing a clique in and . Set to be the clique join of graphs and with respect to and . If the bears win the games and , then they also win the game where
Using winning strategies and for and respectively, let us construct a winning strategy for . For every bear , we interpret his color as a tuple where and . Moreover, we define an imaginary hat color of the bear on vertex as .
Every bear on plays according to the strategy using only the color for his every neighbor . Every bear on plays according to the strategy using the imaginary hat color of . And finally, every bear on vertex computes a set of guesses by playing the strategy and a set of guesses by playing the strategy . Since the bear on can see every other vertex of , he computes the set
Finally, the bear on guesses the set .
Fix an arbitrary hat arrangement. In the simulated hat guessing game , there is a vertex such that the bear on guessed correctly. If then it also guessed correctly in . Likewise, there is a bear on a vertex in the simulated hat guessing game that guessed correctly and we are done if . The remaining case is when and . Thus, the bear on includes the color in his guesses in the game . It follows that for each holds that if is a hat color of the bear on , then . Since , the bear on includes his hat color in his guesses . ∎
We remark that Lemma 4 generalizes Theorem 3.1 and Theorem 3.5 of  not only by introducing multiple guesses but also by allowing for more general ways to glue two graphs together. Thus, it provides new constructions of winning games even for single-guessing games. See Figure 2 for an example of an application of Lemma 4.
5 Independence Polynomial
The multivariate independence polynomial of a graph on variables is
First, we describe informally the connection between the multi-guessing game and the independence polynomial. Consider the game and fix a strategy of bears. Suppose that the demon put on the head of each bear a hat of random color (chosen uniformly and independently). Let be an event that the bear on the vertex guesses correctly. Then, the probability of is exactly . Moreover, for any independent set holds that is independent on all events for . Thus, we can use the inclusion-exclusion principle (Proposition 2) to compute the probability that occurs for at least one , i.e., at least one bear sitting on some vertex of guesses correctly.
Assume that no two bears on adjacent vertices guess correctly their hat colors at once; it turns out that if we plug into all variables of the non-constant terms of , then we get exactly the fraction of all hat arrangements on which the bears win. The non-constant terms of correspond (up to sign) to the terms of the formula from the inclusion-exclusion principle. Because of that, we have to plug into the polynomial .
To avoid confusion with the negative fraction we define signed independence polynomial as , i.e.,
We also introduce the monovariate signed independence polynomial obtained by plugging for each variable of .
Note that the constant term of any independence polynomial equals to , arising from taking in the sum from the definition of . When and no two adjacent bears guess correctly at the same time, then the bears win the game because the fraction of all hat arrangements, on which at least one bear guesses correctly, is exactly , however, the proof is far from trivial.
Slightly abusing the notation, we use to denote the independence polynomial of an induced subgraph with variables restricted to the vertices of . The independence polynomial can be expanded according to a vertex in the following way.
The analogous expansions hold for the polynomials and as well. This expansion follows from the fact that for any independent set of , it holds that either is not in (the first term of the expansion), or is in but in that case, no neighbor of is in (the second term). The formal proof of this expansion of was provided by Hoede and Li .
For a graph , we let denote the set of all vectors such that for all , where the comparison is done entry-wise. For the monovariate independence polynomial , an analogous set to would be exactly the real interval where is the smallest positive root of . (Note that and .)
Our first connection of the independence polynomial to the hat guessing game comes in the shape of a sufficient condition for bears to lose. Consider the following beautiful connection between Lovász Local Lemma and independence polynomial due to Scott and Sokal .
[ Theorem 4.1] Let be a graph and let be a family of events on some probability space such that for every , the event is independent of . Suppose that is a vector of real numbers such that for each we have and . Then
A hat guessing game is losing whenever where .
Suppose for a contradiction that is winning and fix a strategy of the bears. We let the demon assign hat to each bear uniformly at random and independently from the other bears. Let be the event that the bear on the vertex guesses correctly. Observe, that and the probability that the bears lose is precisely .
Let us show that the event is independent of all events such that . Observe, that fixing arbitrary hat arrangement on uniquely determines the guesses of bears on all vertices except for . In particular, for every vertex , we know whether the bear on guessed correctly and thus the probability of conditioned by is either 0 or 1. On the other hand, the probability of conditioned by is still . Therefore, is independent of any subset of .
The claim follows since the graph and vector satisfies the conditions of Theorem 5 and we obtain that . Therefore, there exists some hat arrangement in which all bears guess incorrectly. ∎
A strategy for a hat guessing game is perfect if it is winning and in every hat arrangement, no two bears that guess correctly are on adjacent vertices. The following proposition shows that a perfect strategy can occur only when lies in some sense just outside of .
If there is a perfect strategy for the hat guessing game then for we have that and for every .
Fix a perfect strategy and set to be the total number of possible hat arrangements. For any subset , let be the number of hat arrangements such that every bear on vertex guesses correctly (other bears are not forbidden from guessing correctly). We claim that for any independent set , we have .
Observe that by assigning the hats to the bears on , we fix the guesses of all bears on . Every bear on a vertex guesses correctly exactly out of of his hat assignments. Thus the total number of hat arrangements where every bear on the independent set guesses correctly is exactly
On the other hand, the perfect strategy guarantees that for any non-empty that is not an independent set, . This allows us to use the inclusion-exclusion principle and count the exact total amount of hat arrangements such that at least one bear guesses correctly
Finally, the total amount of hat arrangements when at least one bear guesses correctly must be exactly since the bears win. Therefore, we get .
We prove the remaining claim in two steps. First, we show that for every induced subgraph of it holds that . To that end, consider a modified hat guessing game where only bears on the vertices of are allowed to guess and they play according to the original perfect strategy. By the same argument as before, we can count the total amount of hat arrangements that are guessed correctly by this modified strategy as . It implies as the total number of hat arrangements is .
Now consider any . Let be an arbitrary ordering of the vertices of and let us define vectors for as
Notice that , , and the vectors correspond to switching the coordinates of into the coordinates of one by one. We prove by induction on that for every induced subgraph of it holds that .
We already proved the fact for . Let and let be an arbitrary induced subgraph of . If does not contain then and we are done. Otherwise, we have
where we first partition the independent sets of according to their incidence with and then replace with where the inequality holds since and from induction. Finally, we notice that we obtained the independent polynomial evaluated in and apply induction. Thus, as and is an induced subgraph of itself. ∎
Scott and Sokal [24, Corollary 2.20] proved that for every if and only if lies in the closure of . Therefore, Proposition 5 further implies that if a perfect strategy for game exists, then lies in the closure of . And since cannot lie inside due to Proposition 5, it must belong to the boundary of the set .
The natural question is what happens outside of the closure of . We proceed to answer this question for chordal graphs.
A graph is chordal if every cycle of length at least has a chord. For our purposes, it is more convenient to work with a different equivalent definition of chordal graphs. For a graph , a clique tree of is a tree whose vertex set is precisely the subsets of that induce maximal cliques in and for each the vertices of containing induces a connected subtree. Gavril  showed that is chordal if and only if there exists a clique tree of .
Let be a chordal graph and let be a vector of rational numbers from the interval . If then there are vectors such that for every and the hat guessing game is winning.
We prove the theorem by induction on the size of the clique tree of . Let be a witness that , i.e., .
If is itself a complete graph, then implies that and . Thus, if we take the minimal vectors such that for each , the assumptions of Theorem 4 are satisfied and the hat guessing game is winning.
Otherwise, the clique tree of contains at least 2 vertices and we pick its arbitrary leaf . Let be the set of vertices such that they belong only to the clique and the set of vertices . We aim to split the graph into and , apply induction to obtain winning strategies on these graphs, and then combine them into a winning strategy on .
If , then the game is winning already on the clique due to Theorem 4. Therefore, we can assume which implies . We define vectors and as
where and . Observe that and that for every we have . In other words, and are both vectors of numbers from such that .
To simplify the rest of the proof, we introduce the following notation. For any , let denote the independence polynomial restricted only to the independent sets containing , i.e.,
With this in hand, we proceed to show that .
In (1), we partition the independent sets in depending on their incidence with . The line (2) follows since every independent set intersecting in can be written as a union of and an independent set in which allows us to collect the first and third terms. At the same time, all independent sets intersecting in can be regarded as independent sets intersecting in . In (3), we replace with which scales each term in the second sum by the factor . Finally, notice that the terms in (3) describe (up to scaling by ) the independent sets in partitioned according to their incidence with . We collect them in (4).
Since and , we have which witnesses that . Therefore, we can apply induction on and to obtain functions such that the hat guessing game is winning and for each vertex .
Let be the graph obtained from the clique by contracting to a single vertex and define the vector as
Observe that is precisely the clique join of and with respect to and . Since , we can take the minimal vectors such that for every and apply Theorem 4 on to show that the hat guessing game is winning. Finally, we construct the desired winning strategy by combining the two graphs and their respective strategies using Lemma 4 since for every . ∎
Theorem 5 applied for the uniform polynomial immediately gives us the following corollary. For any chordal graph , the fractional hat chromatic number is equal to where is the smallest positive root of .
Theorem 5 implies that . For the other direction, let be a sequence of rational numbers such that for every and . Set . Scott and Sokal [24, Thereom 2.10] prove that if and only if there is a path in connecting and such that for any on the path. Taking the path , we see that and thus for every . Therefore by Proposition 5, the hat guessing game is losing for any such that and for every . It follows that . ∎
Note that the constant term of equals to 1. Thus by the previous corollary and rational root theorem (Theorem 2), it holds that is either an integer or an irational number.
We would like to remark that the proof of Theorem 5 (and also Theorem 4) is constructive in the sense that given a graph and a vector it either greedily finds vectors such that together with a succinct representation of a winning strategy on or it reaches a contradiction if . An observant reader might notice that this also relies on the constructiveness of Theorem 4 as it is invoked many times throughout the proof. Moreover, it is easy to see that it can be implemented to run in polynomial time if the clique tree of is provided. Combining it with the well-known fact that a clique tree of a chordal graph can be obtained in polynomial time (see Blair and Peyton ) we get the following corollary.
There is a polynomial-time algorithm that for a chordal graph and vector decides whether . Moreover, if it outputs vectors such that for every , together with a polynomial-size representation of a winning strategy for the hat guessing game . We finish this section by presenting an algorithm that computes of chordal graphs.
There is an algorithm such that given a chordal graph as an input, it approximates up to an additive error . The running time of is , where is the number of vertices of . Moreover, if is rational, then the algorithm outputs the exact value of .
First, suppose that is rational. Let for coprimes . By Corollary 3, is the smallest positive root of the polynomial . Let . Note that and for each holds that because is exactly the number of independent sets of size in the graph . By the rational root theorem (Theorem 2), it holds that and .
The algorithm repeats a halving procedure which works as follows. We set the initial bounds and . In a step , let