maths

# The joy of mathematics

I found out something interesting today. About myself as well as about an interesting maths problem. It turns out I’m slightly suspicious about maths problems in general when it comes to exact solvability. Whenever I get a problem under my nose, apparently I immediately adopt the attitude that there’s probably no exact solution. I think this is a consequence of my field, numerical analysis and scientific computing. My work focuses mainly on problems that are solvable, though not necessarily by exact means.
Interestingly, I once heard someone say that if you were to take a maths problem at random, the probability that it’s solvable is zero. Moreover, if you just restrict yourself to the problems that are solvable and you pick one at random, the probability that it’s exactly solvable is again zero. Imagine my surprise when I encountered a problem out of the blue that is exactly solvable. Imagine my joy when I actually solved it!

### A square in a square?

The problem is as follows: consider a square with vertices $(1,-1), (1,1),(-1,1),$ and $(-1,-1)$. Next, copy the square and rotate it by an arbitrary angle $\theta$. Now shrink the copied square until the vertices are on the edges of the original square. The smaller rotated square I will call an inner square. What is the shape of the intersection of all possible inner squares?

At first, you might think it’s a circle, which would be true if the original square was just rotated. However, we have to keep in mind that the inner square changes size as well as orientation as it’s rotated. Fortunately, since it’s two-dimensional problem, we can simply make a sketch or write a Matlab program to draw some examples. Here’s a plot of 100 different such inner squares at evenly distributed rotations. As you can see, the inner figure is something of a rounded square. Based on the plot, I first thought the rounded square consisted of four circular arcs. However, if you plot these together in the same figure, see below, you’ll quickly realise that this is not the case. It’s definitely similar to the actual figure, but not quite there. In fact, it’s rather a long ways away from the true answer. ### Maths time!

Alright, let’s find the actual shape of the intersection of the inner squares. To do this, we’re gonna need a neat little result: the intersection of any number of convex sets is itself a convex set. Based on the figure, we can see that the boundary of the intersection is going to be piecewise smooth. Convex curves have the nice property that any tangent line is completely on one side of the curve, discounting the intersection point, which is on the curve. We can therefore conclude that any edge of an inner square will be a tangent line to the shape we’re looking for, which will intersect the boundary only at a single point. So far so good.
Next, we should realise that if we take two inner squares whose angles are very close together, then the intersection points of their edges is going to be very close to the boundary curve. The closer the two angles are, the closer the intersection points are going to be to the curve. In the figure, this is apparent from the fact that the meshing becomes more dense closer to the boundary. This is really all we need to find the boundary curve, at least in principle. Taking the limit of the two angles approaching each other results in a boundary point.
We now have a programme to calculate the boundary curve: first, figure out what an edge for an arbitrary inner square looks like; second, take two edges of inner squares with a small difference in angles and find the intersection point; third, take the limit of vanishing angular difference.

#### Living on the edge

Step 1 is to find out what the edges of an inner square look like. To do so, we’re gonna need a bit of trigonometry. Below I’ve made a sketch of an arbitrary inner square with angle $\theta$. I’ve marked two of the angles and three line segments. First, the edge of the inner square has length $e$; second, the longer side of the original square as divided by the point where the inner square touches the bigger one is a line segment with length $a$; third, the shorter side has length $b$. We’re looking to express $e$ in terms of $\theta$, while we know that $a+b=2$ is the length of an edge of the original square. Now comes the trigonometry bit: the cosine of $\theta$ is going to be $\frac{a}{e}$, while the sine is going to be $\frac{b}{e}$. Since $a+b=2$, it is the case that $\cos \theta + \sin \theta = \frac{a+b}{e} = \frac{2}{e}$, or $e = \frac{2}{\cos \theta + \sin \theta}$.

Next, we know that the inner square is a copy of the original square, but rotated. A rotation in the plane can be represented by a rotation matrix $R_\theta = \begin{pmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{pmatrix}$

Multiplying the vertices of the original square by this matrix results in a rotated square. For instance, the vertex $(1,1)$ becomes $(\cos \theta - \sin \theta, \sin \theta + \cos \theta)$. After the rotation, we need to scale the rotated square to make sure the edges have the correct length $e$. The edges after rotation have length $2$, so we need to divide by $\cos \theta + \sin \theta$, so that the upper right vertex becomes $\frac{1}{\cos\theta + \sin\theta} \begin{pmatrix}\cos \theta - \sin \theta\\ \cos\theta + \sin\theta \end{pmatrix} = \begin{pmatrix} f_\theta\\ 1 \end{pmatrix}$,

where $f_\theta = \frac{\cos \theta - \sin \theta}{\cos\theta + \sin\theta}$.

We can further simplify this expression by employing some elementary complex analysis, in particular Euler’s identity. If we work out $e^{i \theta} + i e^{i \theta} = \cos \theta + i \sin \theta + i \cos \theta - \sin \theta$,

we see that the real part involves the numerator of $f_\theta$, while the imaginary part involves the denominator. On the other hand, if we work out the answer in the complex plane a little further, we have $(1+i)e^{i \theta} = \sqrt{2}e^{i\frac{\pi}{4}} e^{i \theta} = \sqrt{2}e^{i(\theta+\frac{\pi}{4})}$.

Using Euler’s identity again, we’re able to see that $\cos \theta - \sin \theta = \sqrt{2} \cos(\theta + \frac{\pi}{4})$ and $\cos \theta +\sin \theta = \sqrt{2} \sin(\theta + \frac{\pi}{4})$. We can then simplify $f_\theta$ to read $f_\theta = \frac{1}{\tan (\theta + \frac{\pi}{4})}$.

It turns out that $f_\theta$ is going to be the crucial quantity, and we can express the whole shape in terms of $f_\theta$. But I’m getting ahead of myself. Incidentally, the bottom right vertex of the rotated triangle is $(1,-f_\theta)$.
I find it beautiful that the mathematics works itself out so nicely. Of course the $y$-coordinate of the upper right vertex had to come out as 1, that’s how we defined the inner squares. In fact, we can use it as a sanity check. If it had come out otherwise, I’d probably guessed I’d made a mistake somewhere. Anyway, now that we have two vertices, we can get on with our plan. The other vertices and pieces of the boundary curve can be found by rotation through $\frac{\pi}{2}$.
An edge of a square is a straight line connecting two vertices. No miracles there, but that means we can find the line segment in terms of Cartesian coordinates. We know the line segment runs from $(f_\theta,1)$ to $(1,f_\theta)$, so the line segment satisfies $l_\theta(x) = \frac{\Delta y}{\Delta x} ( x - x_0) + y_0 = \frac{1+f_\theta}{f_\theta-1}(x-f_\theta)+1$.

A good sanity check is always to make sure the correct $y$-values come out when you put in the $x$-values of the endpoints. So no we’ve completed step 1, we know what an edge of an arbitrary inner square looks like, given $\theta$.

#### Baby steps

Step 2 was to take two corresponding edges of inner squares with a small angular difference and find their intersection point. To simplify matters a little bit, I’ll first introduce a shorthand for the slope: $g_\theta = \frac{1+f_\theta}{f_\theta-1}$.

Then, our programme tells us that we should find the intersection point between two corresponding edges with a small angular difference. I’ll denote this difference as $\mathrm{d} \theta$, as we already know we’re supposed to take a limit later. Since we have the Cartesian form of the line segments, we can simply equate $g_{\theta + \mathrm{d}\theta} (x - f_{\theta + \mathrm{d}\theta}) +1 = g_{\theta} (x - f_{\theta}) +1$.

The 1 cancels on both sides and we end up with $x = \frac{g_{\theta + \mathrm{d}\theta}f_{\theta + \mathrm{d}\theta}-g_{\theta}f_{\theta}}{g_{\theta + \mathrm{d}\theta} - g_{\theta}}$.

This looks an awful lot like some sort of derivative!

#### Vanishing act

This brings us squarely to step 3, taking a limit. Here we should recognise that taking the limit of vanishing $\mathrm{d} \theta$ leads to differentials. To find the differential of $g_\theta$, we have to use the chain rule: $\mathrm{d} g_\theta = \frac{\mathrm{d} g_\theta}{\mathrm{d} f_\theta} \mathrm{d} f_\theta$.

The differential of $g_{\theta}f_{\theta}$ is found using the product rule $\mathrm{d}( g_{\theta}f_{\theta} )= f_\theta \mathrm{d} g_\theta + g_\theta \mathrm{d} f_\theta = \left( f_\theta \frac{\mathrm{d} g_\theta}{\mathrm{d} f_\theta} + g_\theta \right) \mathrm{d} f_\theta$.

In the expression for $x$, the differential of $f_\theta$ cancels and we end up with $x = \frac{ f_\theta \left(\frac{\mathrm{d} g_\theta}{\mathrm{d} f_\theta}\right) + g_\theta }{ \left(\frac{\mathrm{d} g_\theta}{\mathrm{d} f_\theta}\right) } = f_\theta + \frac{g_\theta}{\left(\frac{\mathrm{d} g_\theta}{\mathrm{d} f_\theta}\right) }$.

According to our reasoning earlier, this is the $x$-coordinate of a point on the curve we’re looking for. Let’s calculate the derivative of $g_\theta$ with respect to $f_\theta$, which is given by $\frac{\mathrm{d} g_\theta}{\mathrm{d} f_\theta} = -\frac{2}{(f_\theta-1)^2}$.

This allows us to express $x$ purely in terms of $f_\theta$: $x = f_\theta + \frac{1+f_\theta}{f_\theta-1} \left( - \frac{1}{2}(f_\theta-1)^2 \right)$,

which simplifies all the way down to $x= \frac{1}{2} + f_\theta - \frac{1}{2} f_\theta^2$.

As this is the intersection point between two edges with vanishing angular difference, we can find the $y$-coordinate by plugging it back into the expression we found for the line segment: $y = \frac{1}{2} \frac{1+f_\theta}{f_\theta-1}(1-f_\theta^2) +1$.

Here, we can simplify the expression by realising that $1-f_\theta^2 = (1-f_\theta)(1+f_\theta)$. The $y$-component finally comes out as $y = \frac{1}{2} - f_\theta - \frac{1}{2} f_\theta^2$.

These expressions are valid for the upper right boundary curve, and the other ones can be found simply by rotation through $\frac{\pi}{2}$. This gives the curve we’re looking for parametrised by the rotation angle $\theta$. This is sufficient, since we can now plot it. After all, we know the angular range should be $[0,\frac{\pi}{2}]$. After a rotation by $\frac{\pi}{2}$, the inner square is once again identical to the original square.

### Finishing up

To give a complete picture, let’s also find the vertices of the rounded square. If we find those, we also know where to switch from one curve to the next. By symmetry, they have to be located on the coordinate axes. The top corner point has to be located at $x=0$, which allows us to find the value of $f_\theta$, $\frac{1}{2} + f_\theta - \frac{1}{2} f_\theta^2 = 0$,  so that $f_\theta = 1 \pm \sqrt{2}$.

We need the value that lies within $[-1,1]$, since $f_\theta$ is the $x$-coordinate of the upper right vertex of the inner square. The value for $f_\theta$ therefore becomes $1- \sqrt{2}$. Consequently, we can find the $y$-coordinate as well, which works out as $y = 2(\sqrt{2}-1)$.
The whole result is plotted in the figure below, with the red lines being the boundary curves and the red crosses being the corner points. I’m quite pleased with the result. It was a fun exercise and I was astounded to found out the problem could be solved so satisfactorily. It’s quite an interesting problem, where a lot of mathematics come together; I needed to use convexity theory, trigonometry, complex analysis, geometry, calculus and of course a lot of algebra. And besides from that, I think the pictures are quite pleasing aesthetically.