<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="/feed.xml" rel="self" type="application/atom+xml" /><link href="/" rel="alternate" type="text/html" /><updated>2025-11-22T16:33:03+00:00</updated><id>/feed.xml</id><title type="html">Leo Tappe</title><subtitle>A place of silent reflection</subtitle><entry><title type="html">Infinite Smurfs</title><link href="/riddles/smurfs/logic/compactness/infinity/2020/05/30/infinite-smurfs.html" rel="alternate" type="text/html" title="Infinite Smurfs" /><published>2020-05-30T09:00:00+00:00</published><updated>2020-05-30T09:00:00+00:00</updated><id>/riddles/smurfs/logic/compactness/infinity/2020/05/30/infinite-smurfs</id><content type="html" xml:base="/riddles/smurfs/logic/compactness/infinity/2020/05/30/infinite-smurfs.html"><![CDATA[<p>So I recently came across an interesting riddle. It comes in two flavors, a
finite version and an infinite version. The first version is well-known and
simply a little bit of a brain teaser, but I hadn’t seen the second version
before. That one’s not quite as easy and requires a bit of mathematics.</p>

<h1 id="finite-version">Finite Version</h1>

<p><a href="https://en.wikipedia.org/wiki/Gargamel">Gargamel</a> has captured \(n\)
<a href="https://en.wikipedia.org/wiki/The_Smurfs#Smurfs">smurfs</a> and forces them to
participate in a game:
He arranges the smurfs in a line and makes them all face in the same direction.
In particular, the first smurf can see all the other smurfs, the second smurf
can see all other smurfs except the first one, and so on, until finally the
\(n\)th smurf can’t see any other smurf. For visualization purposes, we set
\(n = 10\) below.</p>

<p>\[\overrightarrow{s_1 \, s_2 \, s_3 \, s_4 \, s_5 \, s_6 \, s_7 \, s_8 \, s_9 \, s_{10}} \]</p>

<p>Now, Gargamel has devised the following evil scheme: he will put a hat on every
smurf, each one either red or blue, and then he will force the smurfs to guess
the color of their own hat. And he will kill each smurf who gets it wrong!</p>

<p>\[
    \color{blue} s_1 \,
    \color{red} s_2 \,
    \color{blue} s_3 \,
    \color{blue} s_4 \,
    \color{red} s_5 \,
    \color{blue} s_6 \,
    \color{red} s_7 \,
    \color{red} s_8 \,
    \color{red} s_9 \,
    \color{blue} s_{10}
\]</p>

<p>Smurf number 1 will have to go first, then smurf number 2, and so on. Of course,
the smurfs cannot see their own hat, but they can see the hats of all the smurfs
in front of them. Moreover, each smurf can hear the answer every other smurf
gives.
Luckily, Gargamel informs the smurfs of these rules before the game starts, so
they have a little time to come up with a plan.</p>

<p>What should the smurfs do to save as many of themselves as possible?</p>

<h4 id="solution">Solution</h4>

<p>If you gave the puzzle a little thought, you probably came to the conclusion
that \(s_1\) is screwed. He has to give an answer without being able to see
his own hat, and nobody answers before him, so he has no way to obtain any
information about his own hat. So for himself, simply flipping a coin would be
as good a strategy as any.
But for the other smurfs, that would be a waste: they wouldn’t be able to gather
any information from a random answer.</p>

<p>Instead, \(s_1\) should observe the hats of all the other smurfs and base his
answer on that. And indeed, there is the following clever strategy that will
allow all other \(n - 1\) smurfs to live: \(s_1\) simply counts the number
of blue hats he sees and says <em>blue</em> if that number is even, and <em>red</em> if it is
odd. By doing so, \(s_1\) himself might, of course, die (or live, if the
answer by chance happens to be correct). But what can \(s_2\) do
with this information? Let’s revisit the example from above:</p>

<p>\[
    \color{blue} s_1 \,
    \color{red} s_2 \,
    \color{blue} s_3 \,
    \color{blue} s_4 \,
    \color{red} s_5 \,
    \color{blue} s_6 \,
    \color{red} s_7 \,
    \color{red} s_8 \,
    \color{red} s_9 \,
    \color{blue} s_{10}
\]</p>

<p>Here, \(s_1\) sees 4 blue hats: \(s_3, s_4, s_6\) and \(s_{10}\). As four
is even, \(s_1\) will answer <em>blue</em>. Now, \(s_2\) can also look at the hats
in front of him. And he, too, sees an even number of blue hats. Can he himself
then have a blue hat? No, because if he did, \(s_1\) would have seen an odd
number of blue hats, and thus wouldn’t have answered <em>blue</em>, but <em>red</em>.
So \(s_2\) can answer <em>red</em> and live. By similar reasoning, each smurf can now
successively deduce the color of their own hat.</p>

<p>So we’ve solved the finite version! That wasn’t so hard, was it? Maybe we can
make it a little more tricky.</p>

<h1 id="infinite-version">Infinite Version</h1>
<p>For the second version, the setting is basically the same, only this time,
Gargamel has captured a
<a href="https://en.wikipedia.org/wiki/Countable_set">countably infinite</a> amount of
smurfs. As markdown doesn’t support infinite lists yet, I will only indicate
the beginning of the line:</p>

<p>\[
    \color{blue} s_1 \,
    \color{red} s_2 \,
    \color{blue} s_3 \,
    \color{blue} s_4 \,
    \color{red} s_5 \,
    \color{blue} s_6 \,
    \color{red} s_7 \,
    \color{red} s_8 \,
    \color{red} s_9 \,
    \color{blue} s_{10}
    \color{black}\dots
\]</p>

<p>And it’s smurfs all the way down. So what can the smurfs do now? The parity
trick from before doesn’t work anymore: if there are infinitely many blue hats
in front of you, would you say that that’s an even number? Or an odd one?
Neither really makes sense. It seems like the smurfs need a new strategy, one a
little more abstract.</p>

<p>Try to think about it on your own if you want, and then you can check the
solution below.</p>

<h4 id="solution-part-12">Solution (Part 1/2)</h4>
<p>Observe the following: a smurf can see all of the
infinitely many hats in front of him, and he hears all the answers of the
smurfs behind him. So he has one bit of information for all smurfs except
himself before he has to make a decision. Wouldn’t it be nice if this was
enough? Indeed, let’s think about these bits as an infinite binary sequence</p>

<p>\[\alpha \in \{0, 1\}^\mathbb{N}\]</p>

<p>where a 1 represents a (seen or heard) blue hat, and a 0 represents a red hat.
What we want is that for each position \(n\), the prefix</p>

<p>\[\alpha_1, \dots, \alpha_{n - 1}\]</p>

<p>together with the (infinitely long) suffix</p>

<p>\[\alpha_{n + 1}, \alpha_{n + 2}, \dots\]</p>

<p>uniquely determines \(\alpha_n\). More formally, we would like to find a
subset of binary sequences \(A \subseteq \{0, 1\}^\mathbb{N}\) with
the property</p>

<p>\[
    \forall \alpha, \beta \in \{0, 1\}^\mathbb{N}: \alpha \text{ and } \beta
    \text{ differ in exactly one position } \implies
    (\alpha \in A \iff \beta \not\in A)
\]</p>

<p>In words, we want a set \(A\) such that for all pairs of sequences that differ
in exactly one position, exactly one of the two sequences is in \(A\). Why do
we want this again? Because when Gargamel picks a sequence \(\alpha\) for the
smurfs, the first smurf could look at the tail</p>

<p>\[\alpha_2, \alpha_3, \alpha_4, \dots\]</p>

<p>and conclude exactly for which \(\beta_1 \in \{0, 1\}\) the sequence</p>

<p>\[\beta_1, \alpha_2, \alpha_3, \alpha_4, \dots\]</p>

<p>is contained in \(A\). By answering accordingly, he could then let the second
smurf know his hat color, as the answer \(\beta_1\) of the first smurf in
conjunction with the tail \(\alpha_3, \alpha_4, \dots\) observed by the second
smurf uniquely determines the \(\beta_2\) such that the sequence</p>

<p>\[\beta_1, \beta_2, \alpha_3, \alpha_4, \dots \]</p>

<p>is in \(A\). And as this sequence couldn’t differ from</p>

<p>\[\beta_1, \alpha_2, \alpha_3, \alpha_4, \dots \]</p>

<p>in exactly one position, we would have \(\beta_2 = \alpha_2\), so the
second smurf could save himself. Continued application of this procedure would
save every smurf, except maybe the first one, who again would have to hope that
his answer is correct.</p>

<p>So have we solved the riddle? Well, we have solved it <em>if</em> we can find such
a set \(A\) satisfying the desiderata mentioned above. And that is actually
the hard part of this riddle: proving that such a set \(A\) must exist.</p>

<h4 id="solution-part-22">Solution (Part 2/2)</h4>

<p>The existence of \(A\) is not obvious. We could try a constructive approach,
but this would likely soon fail. Instead, the problem lends itself naturally to
the language of propositional logic. Essentially, we need to make
a binary decision for every \(\alpha \in \{0, 1\}^\mathbb{N}\): do we
include it in \(A\) or not? So let these decision variables be our set of
propositonal variables</p>

<p>\[X = \{x_\alpha \mid \alpha \in \{0, 1\}^\mathbb{N}\} \]</p>

<p>Note that this already is an
<a href="https://en.wikipedia.org/wiki/Uncountable_set">uncountably large</a> amount of
propositional variables! An assignment to these variables will then induce a
set \(A\) by simply including those \(\alpha\) in \(A\) for which
\(x_\alpha\) is set to 1.</p>

<p>Okay, now that we have the variables, we need some formulas. In particular,
we need to encode the constraint that for each pair of sequences that differ in
exactly one position, exactly one of them is included in \(A\). So if
\(\alpha\) and \(\beta\) are two such sequences, this can be expressed with
the formula</p>

<p>\[
    F_{\alpha, \beta} = (x_\alpha \lor x_\beta) \land
    (\lnot x_\alpha \lor \lnot x_\beta)
\]</p>

<p>And now, the existence of the desired set \(A\) is equivalent to the
satisfiability of the (uncountably large) set of formulas</p>

<p>\[\mathcal{S} = \{F_{\alpha, \beta} \mid \alpha \text{ and } \beta 
\text{ differ in exactly one position}\}\]</p>

<p>At first glance, it doesn’t seem like we’ve made much progress. How would we
know whether an infinite set of formulas is satisfiable? Fortunately, some
clever logicians already came up with the
<a href="https://en.wikipedia.org/wiki/Compactness_theorem">compactness theorem</a>,
which states the following:</p>

<blockquote>
  <p>A set of formulas is satisfiable if and only if every finite subset of it
is satisfiable.</p>
</blockquote>

<p>Aha! This lets us reason about the infinite set \(\mathcal{S}\) in terms of
its finite subsets. We now only have to prove that every finite subset
\(\mathcal{T} \subset \mathcal{S}\) is satisfiable. So why is this the
case? Well, notice that any such finite subset corresponds to a formula in
<a href="https://en.wikipedia.org/wiki/2-satisfiability">2-CNF</a>: each clause consists
of exactly two literals. And luckily, there is a nice characterization of
satisfiability for 2-CNF formulas: Precisely those 2-CNF formulas are satisfiable
whose implication graph is consistent. What does this mean? It means that if you
construct the graph whose nodes are the literals of the formula, and you
introduce for each clause of literals \(L_1 \lor L_2\) the directed edges
\(\overline{L_1} \rightarrow L_2\) and
\(\overline{L_2} \rightarrow L_1\), that then no literal \(L\) is in the
same
<a href="https://en.wikipedia.org/wiki/Strongly_connected_component">strongly connected component</a>
as its negation \(\overline{L}\).</p>

<p>Phew, that’s a lot to take in, but we’re almost there: we just need to give 
an argument why any finite subset of \(\mathcal{S}\) corresponds to a 2-CNF
formula with a consistent implication graph. So let’s take a look at what such
an implication graph looks like in our case. Our formulas are all of the
form</p>

<p>\[
    (x_\alpha \lor x_\beta) \land
    (\lnot x_\alpha \lor \lnot x_\beta)
\]</p>

<p>So we have the following edges in our graph:</p>

<p>\[
    \lnot x_\alpha \rightarrow x_\beta \newline
    \lnot x_\beta \rightarrow x_\alpha \newline
    x_\alpha \rightarrow \lnot x_\beta \newline
    x_\beta \rightarrow \lnot x_\alpha
\]</p>

<p>Notice that all edges go between positive literals and negative literals,
never between two positive literals or two negative literals. So can it be
that the implication graph is inconsistent? This would imply that there
is a path from a variable \(x_\alpha\) to its negation \(\lnot x_\alpha\).
By our observation from above that each edge goes between a negative and
a positive variable, such a path would have to have odd length. Furthermore,
we only have edges between variables that correspond to sequences that differ
in exactly one position. So each step in a path changes exactly one position
of the sequence, and thus an odd path would correspond to an odd number of
changes. But this means it is impossible for there to be a path
\(x_\alpha \rightsquigarrow \lnot x_\alpha\), as an odd number of changes
can never return the sequence \(\alpha\) back to itself. We can conclude
that the implication graph must be consistent. And as this holds for
every finite subset of \(\mathcal{S}\), by the compactness theorem,
\(\mathcal{S}\) must be satisfiable, and hence, the desired set must exist.</p>

<p>And that’s it! We have found a way to save all but possibly one smurf: simply
pick a suitable set \(A\) (the existence of which we’re now sure of) and
follow the strategy outlined above.</p>]]></content><author><name></name></author><category term="riddles" /><category term="smurfs" /><category term="logic" /><category term="compactness" /><category term="infinity" /><summary type="html"><![CDATA[So I recently came across an interesting riddle. It comes in two flavors, a finite version and an infinite version. The first version is well-known and simply a little bit of a brain teaser, but I hadn’t seen the second version before. That one’s not quite as easy and requires a bit of mathematics.]]></summary></entry><entry><title type="html">Hello World!</title><link href="/jekyll/update/2020/03/18/hello-world.html" rel="alternate" type="text/html" title="Hello World!" /><published>2020-03-18T12:16:17+00:00</published><updated>2020-03-18T12:16:17+00:00</updated><id>/jekyll/update/2020/03/18/hello-world</id><content type="html" xml:base="/jekyll/update/2020/03/18/hello-world.html"><![CDATA[<p>Hi there!</p>

<p>Due to a certain beverage-named pandemic keeping me indoors a lot these days, I decided to set up this blog using <a href="https://pages.github.com/">GitHub Pages</a>.
If I find that I have something enlightening to share with the world, I might post it on here. No promises though.</p>

<p>The rest of this post is really just about testing some stuff.
Apparently I can do code snippets?</p>

<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="k">def</span> <span class="nf">can_do_snippets</span><span class="p">()</span>
    <span class="k">print</span><span class="p">(</span><span class="s">'Why, yes!'</span><span class="p">)</span>

<span class="c1"># cool!</span></code></pre></figure>

<p>And math, too?</p>

<p>\[\pi \approx 3 \]</p>

<p>And even inline? \(\implies \) awesome!</p>

<p>Okay, that’s it for this post.</p>]]></content><author><name></name></author><category term="jekyll" /><category term="update" /><summary type="html"><![CDATA[Hi there!]]></summary></entry></feed>