Friday, 30 October 2026

Minesweeper: when ILP Meets SAT

Oh hello minesweeper. It's been a while since I last talked about it even though this is something I never left it up on the shelves: I showed up playing MSN minesweeper at times (perhaps once a year), and tried minesweeper speedrunning at times but those were nothing new. 

What caught my attention is a new minesweeper like mobile game where you fill the tiles by colors. This is immediately a variant of minesweeper with the following rules:

- Colors: there can be 2, 3 or 4 colors, but let's assume we are talking about the 2 color version for simplicity since it is then equivalent to OG minesweeper.
- Difficulty: either basic or advanced.
Basic: you should be able to find tiles that solve directly. For example if you see a red-2 but there are already 6 non-red neighbors (either colored non-red or marked non-red), then you know the remaining two much be red.
Advanced: Only guarantee logical solving.
- Extra rules: some of the games are coupled by extra rules like number of tiles/chained blocks of a certain colors of a row/column, number of 2-chains on a row/column, symmetry, dominant color of a row/column...etc

Every game is composed of a color rule, basic/advanced rule set + optional extra rules and should be solvable logically.

As a minesweeper veteran you would find the basic rule set extremely satisfying to play since everything can be processed quickly. 30 seconds to solve a 8x8 board is almost routine.

However, some of the extra rule set isn't that simple yet it could appear together alongside basic rule set. Consider symmetry rule for example: instead of numbers, some tiles are filled with -> <- arrow pairs, indicating palindrome pattern between arrows.

One expected operation for symmetric rule is the ability to deduct the position of the ending arrow given a starting arrow and a few colored tiles in between. But such deduction does not sound simple at all right?

Despite how the game handles such conflict, we ask an important: how to properly define simple-ness?

And then there comes the advanced rule set.

In the tutorial the following example is given:
2 □ □
x □ 2

(□ = unrevealed tile, x = mine)

Tutorial used that as an example of 'non-simple' logic: if the right top corner is safe then we have to flag both tiles on column 2 violating the 2 at left-top corner. Thus right top corner must be flagged.

I read the whole thing in a different way though. Instead of treating it as a propositional logic problem, I see it as an linear integer programming problem. In plain terms I am looking to deduct using equations.

In the above example let us encode as
2 A C
x B 2
That gives A+B=1 and A+B+C=2 which solves to C=1.

Such approach is nothing new and I believe many are doing the same. In fact, I found this approach almost universal, meaning I can solve most problems simply using such counting trick, but is that true?

The problem here is, assuming the board is logic-solvable can we use equations derived from hints to find the answer?

Simple board

It's so hard to define what a simple rule set is, especially when it is mixed with other extra rules. But what if we separate what we can do per rules?

Define operations allowed under "basic rule set" as follows:
1. If #neighboring mines = mine number, mark all remaining neighboring tiles safe
2. If #remaining neighboring tiles = #remaining mines, mark all remaining neighboring tiles mines

We can do the same for any extra rules. Take "number of mines in a row/column" as example the rules could look like:
1. If #mines on row/column = mine number, mark all remaining tiles on row/column safe
2. If #remaining tiles on row/column = #remaining mines, mark all remaining tiles on row/column mines

Those rules could be a lot more complicated for other rules though. Imagine the rules about number of chains on row/column...

These set of operations are essentially logical inference theorems. That says, a logically solvable board is a (finite) board that at each state there is at least a tile that can be marked either safe or mine using one of the theorems.

Advanced rule set

Ok then what separates from the basic rule set then? In the above example we see that those operations is simply not enough. In fact we know that if we have finite (or polynomially many) rules, each rule has polynomially many scopes to check, each application is in P and a search invokes the rules polynomially many times, it would not be a logically complete search. 

That is unless, of course, if P equals NP (equals coNP) (!!!).

NP-completeness is proven by showing circuit-SAT reduces to minesweeper. In other words we actually have a construction of boards from logically hard problems. That says, the approach of producing a set of quick rules won't get you anywhere.

When (polynomial time) inference approach does not work anymore, the only thing we can do is to rely on the existence of solution. We can define an operation like:

1. Mark a tile safe/mine, if all possible solutions from current board state have that tile marked safe/mine.

That's pretty much it. The universal definition of solvability in one sentence, although it doesn't mean simplicity at all. Check all solutions is an exponential approach. Although the fact that propositional logic is complete means there will be a deduction from the current board if there is possible progress, but at what cost can we find the deduction? I guess you know better unless a certain equality is miraculously true again ;)

In some sense basic vs advanced is just a disguised P vs NP just like 2-SAT vs 3-SAT*.

Logical deduction vs mathematical formulation

This is another issue that looks unrelated to the above but just look at how all previous talks were focused on NP-completeness and SAT solving, how could this be an exception?

On the logical side, minesweeper is obviously a SAT problem. 

On the mathematical side, it isn't just a linear system -- it's a binary system where all variables must be 1 or 0.

The fact that all variables must be below 1 and above 0 is surely well understood as this is precisely how the basic operations work, but this is nothing spectacular. A linear system with inequalities are merely linear programs with well understood properties and polynomial algorithms. Integer programming on the other side, is a completely different beast.

We constructed an example where integrality matters:

x x 4 x x
x F x D 4
4 x x C B
A x 7 x x
2 E x x x

This is a typical successive either-or pattern. Each consecutive pair in the chain  D-F-A-E-C sums to 1 like A+F=1, F+D=1 and so on. The caveat is the head and tail are connected here and is bounded by the extra equation B+C+D = 2. 

Since we know A=C=D we substitute to get 2A+B = 2, so integrality forces (A,B) = (1,0). In logical terms, the cycle forces C and D to be either both safe or both mine but since there is at least one mine among C, D we conclude both must be mine. This would never be solved without quoting the integrality constraint.

Although all the above merely give you a feel on how minesweeper is actually a subproblem of 0-1 integer linear programming (ILP), it's still far from a complete proof that it is NP-complete. Can we reduce any 0-1 ILP problem into minesweeper board? This is actually very tricky because it is almost impossible to corporate large coefficients in minesweeper board given its geometry. That's precisely why the actual proof took the alternative track by showing circuit-SAT reduces to minesweeper in the logical sense instead, which makes Karp happy.

Nonetheless, it is much easier to prove that the universal theorem from the logic side is equivalent to the universal theorem from the math side. We may as well define the operation in the mathematical way:

1. Mark the tile $X_i = 0/1$ if every solution vector $x$ to the system satisfies $x_i = 0/1$.

That says, if you take things to the extreme and consider the complete power of logical solving and mathematical solving the two are equivalent. It will likely be all we will know unless someone start to ask question like "can we compare the strength of a set of operations in solving ILP and a set of inference rules in logical deduction?". 

For example, consider the LP relaxation $\left\{ Ax=b, 0\leq x_i \leq 1\right\}$. This is surely P-time solvable. What is the corresponding logical inference rules? The answer is surprisingly clear with the help of Farkas using duality. The unfortunate bit is that the inference rule basically looks so mathematical where we start to lose the boundary between 'logical' and 'mathematical'.

***

This minesweeper variant got me to think a lot about mathematics behind, but the deeper I go I realized all of them reduce to the basic principle of completeness with basically nothing more. Let's call it a good revision and look over it.

There is an important take away though. Logical approach and mathematical approach are deeply entwined. The deeper we try to look into, the close the they look. Instead of treating the two separately, we should learn to make use of both: we use the logical approach to perform reduction, and we use the mathematical approach to understand its formulation. Minesweeper becomes a beautiful medium where the two meet, and I hope you can appreciate it too :)

(*): to be precise this is not the most accurate comparison as inferences and solvability is coNP-complete not NP-complete but you get it.

Saturday, 17 October 2026

A possible AD4 revitalization?!?

I have been writing about ways to use AD4 in modern systems from win 7 to 10 to 11. It truly gets harder and more frustrating each time...but anymore.

The era of vibe coding has arrived, and someone did it before me. Admittedly this project isn't my priority but it's still nice to have something right? It's major enough I decide to write about this overnight despite having another AD entry half year ago.

Introducing the Long After Dark, another name that abbreviates to a loser team.

According to its description, it runs the original Windows modules through an emulated x86 and old Windows environment, with its own screensaver host and settings window. After Dark 4.0 Deluxe is among the supported releases. That covers a large part of what I had in mind, without having to rewrite every screensaver individually.

It isn't fully what I wanted which is low CPU consumption in modern standard. But for now, this is simply another possible route for those trying to bring AD back. If the old instructions no longer work for you, it may be worth checking the project before spending another evening moving files between System32 and SysWOW64.

As for my own revival plan, I can leave it further down the list until there is something specific that still needs doing. If you give LAD a try, I'd be interested to hear how it works with your favourite modules. :)


Saturday, 10 October 2026

Capturing growth rate in problem solving (3): calculus and generalization

5. Calculus problems

Example 14. (SMMC 2025 A1) A function $f: [0,\infty)\to [0,\infty)$ is max-poly if it is in the form of $f = \max (p_1,\ldots, p_n)$ where $p_i$ are real polynomials with $p_i (x) \geq 0$ for all $i = 1,\ldots , n$ and $x\geq 0$. Determine if $f = \min (x,x^2)$ is max-poly.

Remember how the growth rate of polynomials with distinct orders are completely separated? The same applies here. The growth rate of $f$ is $O(x)$ locking all polynomials to be of order at most 1 that the $x^2$ curve cannot form. 

In fact, interpolation tells us that a segment from a polynomial cannot be a piecewise combination of other polynomials. That says we can prove the other way round. The $x^2$ curve forces at least one of the polynomial quadratic which would destroy the long term growth rate.

Example 15. (Putnam 2017 A3) Let $a<b$, $f,g:[a,b]\to (0,\infty)$ be continous with $\int ^b_a f(x)dx = \int ^b_a g(x)dx$ but $f\neq g$. Define $I_n = \int ^b_a (f(x)/g(x))^n \cdot f(x) dx$ for positive integers $n$. Show that $I_n$ is increasing and diverges to infinity.

Well the diverging part is clear knowing the whole thing is exponential right? Their integral being equal but the function being equal means there exists compact set $K$ of positive measure where $f(x) \geq (1+\delta)g(x)$. Let $m = \min _K f(x)$, then $I_n \geq m(1+\delta)^n \to \infty$.

Sure we need other tricks to help us dealing with the increasing part but that isn't too hard. Here I present something not used in official solution. If we extend definition to $I_0 = \int f(x)dx$ we can prove $I_1\geq I_0$ by direct calculation, then Hölder's inequality gives 

$I_n = \int ^b_a \frac{f(x)^{n+1}}{g(x)^{n}} dx = \int ^b_a (\frac{f(x)^{n+2}}{g(x)^{n+1}})^{\frac{n}{n+1}}f(x)^{\frac{1}{n+1}} dx$
$\leq (\int ^b_a \frac{f(x)^{n+2}}{g(x)^{n+1}} dx )^{\frac{n}{n+1}} (\int ^b_a f(x)dx)^{\frac{1}{n+1}}$

But since $\int ^b_a f(x) dx = \int ^b_a g(x)dx$ that implies $I_n \leq I_{n+1}^{\frac{n}{n+1}}I_0^{\frac{1}{n+1}} \leq I_{n+1}^{\frac{n}{n+1}}I_n^{\frac{1}{n+1}}$
by induction, so $I_n\leq I_{n+1}$. Since $f\neq g$ strict inequality is achieved and we are done. The proof also indicates an exponential growth in long term.

Example 16. (Putnam 2009 B5) Let $f:(1,\infty)\to \mathbb{R}$ be differentiable with $f'(x) = \frac{x^2-f(x)^2}{x^2(f(x)^2+1)}$ for all $x>1$. Prove that $lim _{x\to \infty} f(x) = \infty$.

The derivative looks complicated but the core idea is that $f'(x)$ is slightly below 1 but not too far off, then it grows like $x$ which diverges to infinity. Qualitatively, we know $f'(x) = 1 - \frac{x^2+1}{x^2}\frac{f(x)^2}{1+f(x)^2}$. If $f(x)$ is bounded above then $f'$ is positive and bounded below which forces a contradiction.

The honorable mention here goes to 2010 A6 which like the above B6 will go into exercise. The standard first solution looks horrible but think about the growth rate of that integral...

6. Generalization

From all the questions we have solved above, we see that growth rate sometimes act as a key step, sometimes plays a crucial role, but it's never the full solution. One would be silly to think this is all you need to master functional equation of similar problems.

That does not mean the understanding of growth rate ends here. Let us reconsider what growth rate brings us.

As example 10 exhibited, a polynomial growth rate is preserved, or characterized by powers. In other words, we are filtering other possibilities by looking for functions that satisfy the characterization, rather than calculating the growth rate.

Another way to characterize growth rate is of course eigenvectors. For example we know an exponential function is an eigenvector to frequency alteration $f(\cdot)\mapsto f(a\cdot)$ in the function space. In the same sense a monomial is an eigenvector to the dilation (scaling) operator. Instead of grinding hard  on the growth rate, the implication itself could be more useful at times.

You may guess the keyword to be eigenvector which is not wrong but to me the more important takeaway is how you can understand growth rate as one of the filter which there are many more. Relate that to operators and you can see the problem in a much higher level.

This section is fully dedicated to a single problem which is arguably one of my top favourite contest problems:

Example 17. (SMMC 2025 A4) Let $V$ be a finite dimensional subspace of the space of smooth real functions. For every $f(x)\in V$, we have $f(2x)\in V$. Prove that $V$ only consists of polynomials.

There are two official solutions -- one generalized eigenvectors (what a pity they did not even mention this is generalized eigenvectors) and one by frequency filtering.

For the frequency filtering solution they quoted this lemma:

Lemma 3. Let $\theta _1, \ldots , \theta _m \in [0, 2\pi)$ be distinct angles, $h_1(x),\ldots, h_m(x)$ be polynomials (not necessarily real). Suppose the limit $\lim _{k\to \infty} \sum _{j=1}^m h_j(k) e^{ik\theta _j} = 0$
where limit is taken over integers $k$, then all $h_j$'s are zero.

The factor $e^{ik\theta _j}$ clearly screams Fourier which sparked me to think about a solution that truly utilize transformations. Unfortunately we would run into problems which we will address near the end. Yet, I still come up with an alternative solution of my taste as below.

The solution plays around the non-trivial linear relation $\sum c_jT^jf = 0$. Or rather, the whole solution is a repeated use (abuse) of it. In a pointwise version we write $f(x) = \sum c_i f(2^{-i}x)$.

We know that $f^{(k)}(0) = 0$ for all large enough $k$ as in all other solutions. This is by differentiating the linear combination $\sum c_jT^jf = 0$ and substitute $x = 0$ so get $f^{(k)}(0)\sum c_j 2^{kj} = 0$. For large enough $k$ the highest term dominates forcing the sum non-zero, hence $f^{(k)}(0)= 0$.

That says, $f$ has a finite Maclaurin polynomial $P$. Some other solution focuses on showing $f^{(k)}(x) = 0$ for other $x$, but we deal with the remainder $h = P-f$ instead.

Lemma 4. For any $f\in V$ the function is bounded by polynomial growth. More precisely, there exists a norm $ \|\cdot \|$ for $V$ and constants $C, \alpha >0$ such that $|f(x)| \leq C \| f\| |x|^{\alpha}$.

Proof. Let $M = \sup _{x\in [-1,1]}|f(x)|$ and consider the non-trivial linear recurrence $f(x) = \sum c_i f(2^{-i}x)$. Let $r = 1+\sum |c_i|$. Then induction gives $|f(x)| \leq r^nM$ for $|x| \in [2^{n-1},2^n]$, or simply that $|f(x)| \leq r^{1+\log _2 |x|} M$ which is a polynomial bound.

It is actually easier if we start with a norm although without knowing the polynomial bound it may not be trivial to pull out a norm other than the sup norm. Now we can use norms like $\|f\| = \int |f(x)|e^{-|x|}dx$. We can then have $C, \alpha >0$ that $\|Tf\| \leq c_1\|f\|$ and $\sup _{x\in [-1,1]}|f(x)| \leq  c_2 \| f\|$. For $|x|\geq 1$ write $x = 2^ky$ where $|y|<1$ then $|f(x)| = |T^kf(y)| \leq c_1^k c_2 \|f\|$ which gives the same result. 

The lemma implies that $h$ has at most polynomial growth at the far end. We combine with the fact that it shrinks faster than polynomial at zero as $h^{(k)}(0) = 0$ for all natural number $k$ to show that it is indeed zero.

Note that $h$ also satisfies the recurrence $h(x) = \sum c_i h(2^{-i}x)$. For large enough $k$ there exists $M_k$ such that $|h(x)| \leq M_k |x|^k$ for all $x$. Now we estimate

$\frac{|h(x)|}{|x|^k} \leq \sum (2^{-ik}|c_i| \frac{|h(2^{-i}x)|}{|2^{-i}x|^k}) \leq \sum (2^{-k}|c_i| \frac{|h(2^{-i}x)|}{|2^{-i}x|^k})$.

Taking supremum gives $M_k \leq M_k 2^{-k}\sum|c_i|$. We just need a large enough k where $2^{-k}\sum|c_i| <1$ to conclude $M_k = 0$. Essentially, a fixed dilation does not support nonzero remainder that decays faster than polynomial rate near zero. $\square$

I feel like this is a mix between the two official solutions which gives a clearer picture but meh.

Now back to our concern -- why can't we apply Fourier or Mellin transform and dig the frequency out of it? Usually technicalities like that would be left to readers but this is so fundamental that we shall get our hands dirty. 

The major hurdle is the lack of guarantee that a smooth real function admits a Fourier transform (and converges over where it's useful). However, functions in the big space do not necessarily admit the transform does not mean we can't apply the transforms in the finite dimensional space $V$.

Lemma 4 is very powerful as it allows us to get a well-tamed remainder to work with. Adopt the notation $f = P+h$ and assume $h(x) = O(x^{\alpha})$.

The polynomial bound at both far end and at zero means the Mellin transform 
$\mathcal{M}[h](s) = H(s) = \int ^{\infty}_0 h(x)x^{s-1}dx$
converges absolutely in the half plane $\textrm{Re}\,s < -\alpha$. It now suffices to look at the half plane.

The frequency doubling operator is easily transformed as $\mathcal{M}[T^jh](s) = 2^{-js}H(s)$, so $p(2^{-s})H(s) = 0$. Now pick a real number $\sigma < -\alpha$ that is on the left of all roots of $p$, i.e., $2^{-\sigma} > |z|$ for all $p(z) = 0$. Then $H(s) = 0$ on the vertical line $s = \sigma + i\zeta$ for real $\zeta$. 

By writing $x = e^t$ we have 
$H(\sigma + i\zeta) = \int _{\mathbb{R}} e^{\sigma t}h(e^t) e^{i\zeta t}dt = \int _{\mathbb{R}}u(t)e^{i\zeta t}dt$,
which we retrieved Fourier transform of some sort!

Absolute convergence says $u\in L^1(\mathbb{R})$ meaning this is a valid Fourier transformation on $u$. Since the transform is zero (not even distributional) we conclude that $u = 0$ and hence $h(x) = 0$ for $x>0$. Flip $h$ to repeat the argument then $h(x) = 0$ for $x<0$ then $h(0) = 0$ by continuity.

What differs from the my proposed solution is that we avoided the log-polynomial factors by limiting the reminder, and the technicalities allowed us to apply transformation where it had not been possible.

Something even more fascinating is how fascinatingly close our final trick of constructing a Fourier transform $\int _{\mathbb{R}}u(t)e^{i\zeta t}dt = 0$ to force zero looks almost the same as the lemma. They are of course child of two face, the discrete and continuous version of frequency filtering. There are so much more to talk about this, but I am afraid that such topic alone would be longer than this whole series and too hard to fit even the upper end of the taste here.

(Question - we used smoothness implicitly. Where did we use that? In particular, why do we need smoothness of infinite order? If you get stuck check the elementary solutions again.)

This question is one of my favourite in the sense it is a massive collaboration between advanced analysis and linear algebra but also allow specific branches like Fourier transform to kick in. There are so many perspectives you can look into, but each one of them is a generalization of growth rate tracing. I would even call this problem a major motivation to write this whole seminar.

7. Food for thoughts

Problems well worth mentioning but I was too lazy to fill them after all the work.

Problem 1. (Putnam 2022 B6) Find all functions $f:\mathbb{R}^+\to \mathbb{R}^+$ such that $f(xf(y)) + f(yf(x)) = 1 + f(x+y)$ for all $x,y>0$.

Problem 2. (SMMC 2021 B3) Find all real functions satifying the following two properties:
i) The Riemann integral $\int^b_a f(t)dt$ is well-defined for real $a<b$.
ii) For all real $x$ and positive integer $n$, $f(x) = \frac{n}{2}\int ^{x+1/n}_{x-1/n}f(t)dt$ holds.

Problem 3. (Putnam 2010 A6) Let $f:[0,\infty)\to \mathbb{R}$ be a strictly decreasing continuous function with $\lim _{x\to \infty}f(x) = 0$. Prove that $\int ^{\infty}_0 \frac{f(x)-f(x+1)}{f(x)}dx$ diverges.

Ask yourself -- what's the growth rate -- when you are stuck!!