math and physics play

What will be the value of k to satisfy this integral equation

January 19, 2025 math and physics play , ,

[Click here for a PDF version of this post]

Another problem from x/twitter [1]:

Find \( k \), where
\begin{equation}\label{eqn:trigProp:20}
\int_0^{2 \pi} \sin^4 x dx = k \int_0^{\pi/2} \cos^4 x dx.
\end{equation}
I initially misread the integration range in the second integral as \( 2 \pi \), not \( \pi/2 \), in which case the answer is just 1 by inspection. However, solving the stated problem, is not much more difficult.

Since sine and cosine are equal up to a shift by \( \pi/2 \)
\begin{equation}\label{eqn:trigProp:40}
\sin(u + \pi/2) = \frac{e^{i(u + \pi/2)} – e^{-i(u + \pi/2)}}{2i} = \frac{e^{i u} + e^{-i u}}{2} = \cos u,
\end{equation}
we can make an \( x = u + \pi/2 \) substitution in the sine integral.

Observe that \( \cos^4 x = \Abs{\cos x}^4 \), but the area under \( \Abs{\cos x} \) is the same for each \( \pi/2 \) interval. This is shown in fig. 1.

fig. 1. Plot of |cos x|

Of course, the area under \( \cos^4 x \), will also have the same periodicity, but those regions will be rounded out by the power operation, as shown in fig. 2.

fig. 2. Plot of cos^4 x.

Since the area under \( \cos^4 x \) is the same for each \( \pi/2 \) wide interval, we have
\begin{equation}\label{eqn:trigProp:60}
\boxed{
k = 4.
}
\end{equation}

References

[1] CalcInsights. What will be the value of k to satisfy this integral equation, 2025. URL https://x.com/CalcInsights_/status/1880932308108341443. [Online; accessed 19-Jan-2025].

A fun ellipse related integral.

January 18, 2025 math and physics play , , ,

[Click here for a PDF version of this post]

Motivation.

This was a problem I found on twitter ([2])

Find
\begin{equation}\label{eqn:ellipicalIntegral:20}
I = \int_0^\pi \frac{dx}{a^2 \cos^2 x + b^2 \sin^2 x}.
\end{equation}

I posted my solution there (as a screenshot), but had a sign wrong. Here’s a correction.

Solution.

Let’s first assume we aren’t interested in the \( a^2 = b^2 \), nor either of the \( a = 0, b = 0\) cases (if either of \( a, b \) is zero, then the integral is divergent.)

We can make a couple simple transformations to start with
\begin{equation}\label{eqn:ellipicalIntegral:40}
\begin{aligned}
\cos^2 x &= \frac{\cos(2x) + 1}{2} \\
\sin^2 x &= \frac{1 – \cos(2x)}{2},
\end{aligned}
\end{equation}
and then \( u = 2 x \), for \( dx = du/2 \)
\begin{equation}\label{eqn:ellipicalIntegral:60}
\begin{aligned}
I
&= \int_0^{2\pi} 2 \frac{du/2}{a^2 \lr{ 1 + \cos u } + b^2 \lr{1 – \cos u}} \\
&= \int_0^{2\pi} \frac{du}{ \lr{ a^2 – b^2 } \cos u + a^2 + b^2 }.
\end{aligned}
\end{equation}
There is probably a simple way to evaluate this integral, but let’s try it the fun way, using contour integration. Following examples from [1], let \( z = e^{i u} \), where \( dz = i z du \), and \( \alpha = \lr{ a^2 + b^2 }/\lr{ a^2 – b^2 } \), for
\begin{equation}\label{eqn:ellipicalIntegral:80}
\begin{aligned}
I
&= \oint_{\Abs{z} = 1} \frac{dz/(i z)}{ \lr{ a^2 – b^2 } \lr{ z + \inv{z}}/2 + a^2 + b^2 } \\
&= \frac{2}{i \lr{ a^2 – b^2 }} \oint_{\Abs{z} = 1} \frac{dz}{ z \lr{ z + \inv{z} + 2 \alpha} } \\
&= \frac{2}{i \lr{ a^2 – b^2 }} \oint_{\Abs{z} = 1} \frac{dz}{ z^2 + 2 \alpha z + 1 } \\
&= \frac{2}{i \lr{ a^2 – b^2 }} \oint_{\Abs{z} = 1} \frac{dz}{ \lr{ z + \alpha – \sqrt{\alpha^2 – 1}}\lr{ z + \alpha + \sqrt{\alpha^2 – 1}} }.
\end{aligned}
\end{equation}

There is a single enclosed pole on the real axis. For \( a^2 > b^2 \) where \( \alpha > 0 \) that pole is at \( z = -\alpha + \sqrt{ \alpha^2 – 1} \), so the integral is
\begin{equation}\label{eqn:ellipicalIntegral:100}
\begin{aligned}
I
&= 2 \pi i \frac{2}{i \lr{ a^2 – b^2 }} \evalbar{ \frac{1}{ z + \alpha + \sqrt{\alpha^2 – 1 } }}{z = -\alpha + \sqrt{ \alpha^2 – 1}} \\
&= \frac{4 \pi}{ a^2 – b^2 } \frac{1}{ 2 \sqrt{\alpha^2 – 1 } } \\
&= \frac{4 \pi }{ 2 \sqrt{\lr{a^2 + b^2}^2 – \lr{a^2 – b^2}^2 } } \\
&= \frac{2 \pi }{ \sqrt{4 a^2 b^2 } } \\
&= \frac{\pi }{ \Abs{ a b } },
\end{aligned}
\end{equation}
and for \( a^2 < b^2 \) where \( \alpha < 0 \), the enclosed pole is at \( z = -\alpha – \sqrt{ \alpha^2 – 1} \), where
\begin{equation}\label{eqn:ellipicalIntegral:120}
\begin{aligned}
I
&= 2 \pi i \frac{2}{i \lr{ a^2 – b^2 }} \evalbar{ \frac{1}{ z + \alpha – \sqrt{\alpha^2 – 1 } }}{z = -\alpha – \sqrt{ \alpha^2 – 1}} \\
&= \frac{4 \pi}{ a^2 – b^2 } \frac{1}{ -2 \sqrt{\alpha^2 – 1 } } \\
&= \frac{4 \pi}{ b^2 – a^2 } \frac{1}{ 2 \sqrt{\alpha^2 – 1 } } \\
&= \frac{4 \pi }{ 2 \sqrt{\lr{a^2 + b^2}^2 – \lr{b^2 – a^2}^2 } } \\
&= \frac{2 \pi }{ \sqrt{4 a^2 b^2 } } \\
&= \frac{\pi }{ \Abs{ a b } }.
\end{aligned}
\end{equation}
Observe that this also holds for the \( a = b \) case.

References

[1] F.W. Byron and R.W. Fuller. Mathematics of Classical and Quantum Physics. Dover Publications, 1992.

[2] CalcInsights. A decent integral problem to try out, 2025. URL https://x.com/CalcInsights_/status/1880110549146431780. [Online; accessed 18-Jan-2025].

Sum of squares and cubes, using difference calculus.

January 17, 2025 math and physics play , , , ,

[Click here for a PDF version of this post]

Motivation.

I showed Karl Gauss’s trick for summing a \( 1, 2, \cdots, n \) sequence. Add it up twice, reversing the sum and adding by columns
\begin{equation}\label{eqn:sumOfSquares:21}
\begin{array}{c|c|c|c|c}
1 & 2 & \cdots & n-1 & n \\
n & n-1 & \cdots & 2 & 1
\end{array}
\end{equation}
We get \( n + 1 \), \( n \) times, so
\begin{equation}\label{eqn:sumOfSquares:41}
\sum_{k = 1}^n k = \frac{n}{2}\lr{ n + 1 }.
\end{equation}

Karl pointed out to me that he’d looked up the formula for the sum of squares, and found
\begin{equation}\label{eqn:sumOfSquares:61}
\sum_{k = 1}^n k^2 = \frac{n}{6}\lr{ 2 n + 1 }\lr{ n + 1 }.
\end{equation}

I couldn’t think of some equivalent of the Guassian trick to sum that, but had the vague memory that we could figure it out using difference calculus. I have a little Dover book [1] on the subject that I read some of when I was in school. Without resorting to that book, I tried to dredge up the memory of how this result could be derived.

Difference operator.

The key is defining a difference operator, akin to a derivative

Definition 1.1: Difference operator (reverse.)

Given a sequence \( y_n \), let
\begin{equation*}
\Delta y_n = y_n – y_{n-1}.
\end{equation*}

It’s also possible to define forward difference operators \( \Delta y_n = y_{n+1} – y_n \), or both, and it turns out that the text uses forward differences. I’ll use reverse difference operator here, since that’s what I tried. The ideas should hold either way.

We can apply the difference operator to some simple sequences, such as \( y_n = \textrm{constant}, y_n = n, y_n = n^2, \cdots \). For those, we find
\begin{equation}\label{eqn:sumOfSquares:81}
\begin{aligned}
\Delta 1
&= 0 \\
\Delta n
&= n – \lr{ n – 1} \\
&= 1 \\
\Delta n^2
&= n^2 – \lr{ n – 1}^2 \\
&= 2 n – 1 \\
\Delta n^3
&= n^3 – \lr{ n – 1}^3 \\
&= 3 n^2 – 3 n + 1.
\end{aligned}
\end{equation}
Rearranging, we find
\begin{equation}\label{eqn:sumOfSquares:101}
\begin{aligned}
1 &= \Delta n \\
n &= \inv{2} \lr{ \Delta n^2 + 1 } \\
&= \inv{2} \lr{ \Delta n^2 + \Delta n } \\
&= \inv{2} \Delta \lr{ n^2 + n } \\
n^2
&= \inv{3} \lr{ \Delta n^3 + 3 n – 1 } \\
&= \inv{3} \lr{ \Delta n^3 + \frac{3}{2} \Delta \lr{ n^2 + n } – \Delta n } \\
&= \inv{6} \Delta \lr{ 2 n^3 + 3 \lr{ n^2 + n } – 2 n } \\
&= \inv{6} \Delta \lr{ 2 n^3 + 3 n^2 + n }.
\end{aligned}
\end{equation}

Sum of squares.

We can now proceed to find the difference of our sum of squares sequence. Let
\begin{equation}\label{eqn:sumOfSquares:121}
y_n = \sum_{k = 1}^n k^2,
\end{equation}
for which we have
\begin{equation}\label{eqn:sumOfSquares:141}
\Delta y_n = n^2 = \Delta \frac{2 n^3 + 3 n^2 + n }{6}.
\end{equation}
Akin to integrating, we’ve determined \( y_n \) up to a constant
\begin{equation}\label{eqn:sumOfSquares:161}
y_n = \frac{2 n^3 + 3 n^2 + n }{6} + C,
\end{equation}
but since \( y_1 = 1 \), and
\begin{equation}\label{eqn:sumOfSquares:181}
y_1 = \frac{2 \times 1^3 + 3 \times 1^2 + 1 }{6} + C = 1 + C,
\end{equation}
so \( C = 0 \). We need only factor to find the desired result
\begin{equation}\label{eqn:sumOfSquares:201}
\sum_{k = 1}^n k^2 = \frac{n}{6}\lr{ 2 n + 1 }\lr{ n + 1 }.
\end{equation}

Sum of cubes.

Let’s also apply this to compute a formula for the sum of cubes. We need one more difference computation

\begin{equation}\label{eqn:sumOfSquares:221}
\begin{aligned}
\Delta n^4
&= n^4 – \lr{ n – 1 }^4 \\
&= 4 n^3 – 6 n^2 + 4 n – 1,
\end{aligned}
\end{equation}
or
\begin{equation}\label{eqn:sumOfSquares:241}
\begin{aligned}
n^3 &= \inv{4} \lr{ \Delta n^4 + 6 n^2 – 4 n + 1 } \\
&= \inv{4} \lr{ \Delta n^4 + \Delta \lr{ 2 n^3 + 3 n^2 + n } – 2 \Delta \lr{ n^2 + n } + \Delta n } \\
&= \inv{4} \Delta \lr{ n^4 + 2 n^3 + n^2 },
\end{aligned}
\end{equation}
so
\begin{equation}\label{eqn:sumOfSquares:261}
\sum_{k=1}^n n^3 = \inv{4} \lr{ n^4 + 2 n^3 + n^2 } + C,
\end{equation}
but we see that \( C = 0 \) is required to satisfy the \( n = 1 \) case. That is
\begin{equation}\label{eqn:sumOfSquares:281}
\sum_{k=1}^n n^3 = \inv{4} n^2 \lr{ n + 1 }^2.
\end{equation}

Difference calculus is a pretty fun tool!

References

[1] Hyman Levy and Freda Lessman. Finite difference equations. Courier Corporation, 1992.

Evaluating a sum using a contour integral.

December 18, 2024 math and physics play , , , , , , , , ,

[Click here for a PDF version of this post]

One of my favorite Dover books, [1], is a powerhouse of a reference, and has a huge set of the mathematical tricks and techniques.  Probably most of the tricks that any engineer or physicist would ever want.

Reading it a bit today, I encountered the following interesting looking theorem for evaluating sums using contour integrals.

Theorem 1.1:

Given a meromorphic function \( f(z) \) that shares no poles with \( \cot( \pi z ) \), where \( C \) encloses the zeros of \( \sin( \pi z \), located at \( z = a, a+1, \cdots b \), then
\begin{equation*}
\sum_{m=a}^b f(m) = \inv{2 \pi i} \oint_C \pi \cot( \pi z ) f(z) dz -\quad \sum_{\mbox{poles of \( f(z) \) in \( C \)}} \mathrm{Res}\lr{ \pi \cot( \pi z ) f(z) }.
\end{equation*}

The enclosing contour may look like fig. 1.

fig. 1. Sample contour

Start proof:

We basically want to evaluate
\begin{equation}\label{eqn:sumUsingContour:20}
\oint_C \pi \cot( \pi z ) f(z) dz,
\end{equation}
using residues. To see why this works, observe that \( \cot( \pi z ) \) is periodic, as plotted in fig. 2.

fig. 2. Cotangent.

In particular, if \( z = m + \epsilon \), we have
\begin{equation}\label{eqn:sumUsingContour:40}
\begin{aligned}
\cot(\pi z)
&= \frac{\cos(\pi(m + \epsilon))}{\sin(\pi(m + \epsilon))} \\
&= \frac{(-1)^m \cos(\pi \epsilon)}{(-1)^m \sin(\pi \epsilon)} \\
&= \cot(\pi \epsilon).
\end{aligned}
\end{equation}
The residue of \( \pi \cot(\pi z) \), at \( z = 0 \), or at any other integer point, is
\begin{equation}\label{eqn:sumUsingContour:60}
\frac{\pi}{
\pi z – (\pi z)^3/6 + \cdots
}
= 1.
\end{equation}
This means that we have
\begin{equation}\label{eqn:sumUsingContour:80}
\oint_C \pi \cot( \pi z ) f(z) dz = 2 \pi i \sum_{m = a}^b f(m) + 2 \pi i \quad \sum_{\mbox{poles of \( f(z) \) in \( C \)}} \mathrm{Res}\lr{ \pi \cot( \pi z ) f(z) }.
\end{equation}
We just have to rearrange and scale to complete the proof.

End proof.

In the book the sample application was to use this to show that
\begin{equation}\label{eqn:sumUsingContour:100}
\coth x – \inv{x} = \sum_{m=1}^\infty \frac{2x}{x^2 + m^2 \pi^2}.
\end{equation}
That’s then integrated to show that
\begin{equation}\label{eqn:sumUsingContour:120}
\frac{\sinh x}{x} = \prod_{m = 1}^\infty \lr{ 1 + \frac{x^2}{m^2 \pi^2} },
\end{equation}
or with \( x = i \theta \),
\begin{equation}\label{eqn:sumUsingContour:140}
\sin \theta = \theta \prod_{m = 1}^\infty \lr{ 1 – \frac{\theta^2}{m^2 \pi^2} },
\end{equation}
and finally equating \( \theta^3 \) terms in this infinite product, we find
\begin{equation}\label{eqn:sumUsingContour:160}
\sum_{m = 1}^\infty \inv{m^2} = \frac{\pi^2}{6},
\end{equation}
which is \( \zeta(2) \), a specific value of the Riemann zeta function.

All this is done in a couple spectacularly dense pages of calculation, and illustrates the kind of gems in this book. At about 700 pages, it’s got a lot of gems.

References

[1] F.W. Byron and R.W. Fuller. Mathematics of Classical and Quantum Physics. Dover Publications, 1992.

Shortest distance between lines

December 14, 2024 math and physics play , , , , , , ,

[Click here for a PDF version of this post]

Motivation.

Having just worked one of Karl’s problems for the distance between two parallel planes, I recalled that when I was in high school, I had trouble with the intuition for the problem of shortest distance between two lines.

In this post, I’ll revisit that ancient trouble and finally come to terms with it.

Distance from origin to a line.

Before doing the two lines problem, let’s look at a similar simpler problem, the shortest distance from the origin to a line. The parametric representation of a line going through point \( \Bp \) with (unit) direction vector \( \mathbf{\hat{d}} \) is
\begin{equation}\label{eqn:shortestDistanceBetweenLines:40}
L: \Bx(r) = \Bp + r \mathbf{\hat{d}}.
\end{equation}
If we want to solve this the dumb but mechanical way, we have only to minimize a length-squared function for the distance to a point on the line
\begin{equation}\label{eqn:shortestDistanceBetweenLines:60}
\begin{aligned}
D
&= \Norm{\Bx}^2 \\
&= \Bp^2 + r^2 + 2 r \Bp \cdot \mathbf{\hat{d}}.
\end{aligned}
\end{equation}
The minimum will occur where the first derivative is zero
\begin{equation}\label{eqn:shortestDistanceBetweenLines:80}
\begin{aligned}
0
&= \PD{r}{D} \\
&= 2 r + 2 \Bp \cdot \mathbf{\hat{d}},
\end{aligned}
\end{equation}
so at the minimum we have
\begin{equation}\label{eqn:shortestDistanceBetweenLines:100}
r = -\Bp \cdot \mathbf{\hat{d}}.
\end{equation}
This means the vector to the nearest point on the line is
\begin{equation}\label{eqn:shortestDistanceBetweenLines:120}
\begin{aligned}
\Bx
&= \Bp – \lr{ \Bp \cdot \mathbf{\hat{d}} }\mathbf{\hat{d}} \\
&= \Bp \mathbf{\hat{d}}^2 – \lr{ \Bp \cdot \mathbf{\hat{d}}}\mathbf{\hat{d}} \\
&= \lr{ \Bp \wedge \mathbf{\hat{d}} } \mathbf{\hat{d}},
\end{aligned}
\end{equation}
or for \(\mathbb{R}^3\)
\begin{equation}\label{eqn:shortestDistanceBetweenLines:140}
\Bx
= -\lr{ \Bp \cross \mathbf{\hat{d}} } \cross \mathbf{\hat{d}}.
\end{equation}

fig. 1. Directed distance from origin to line.

The geometry of the problem is illustrated in fig. 1.

Observe that all the calculation above was superfluous, as observation of the geometry shows that we just wanted the rejection of \( \mathbf{\hat{d}} \) (green) from \( \Bp \) (blue), and could have stated the result directly.

Distance between two lines.

Suppose that we have two lines, specified with a point and direction vector for each line, as illustrated in fig. 2
\begin{equation}\label{eqn:shortestDistanceBetweenLines:20}
\begin{aligned}
L_1&: \Bx(r) = \Bp_1 + r \mathbf{\hat{d}}_1 \\
L_2&: \Bx(s) = \Bp_2 + s \mathbf{\hat{d}}_2 \\
\end{aligned}
\end{equation}

fig. 2. Two lines, not intersecting.

 

The geometry of the problem becomes more clear if we augment this figure, adding a line with the direction \( \mathbf{\hat{d}}_2 \) to \( L_1 \), and adding a line with the direction \( \mathbf{\hat{d}}_1 \) to \( L_2 \), as illustrated in fig. 3, and then visually extending each of those lines to planes that pass through the respective points. We can now rotate our viewpoint so that we look at those planes on edge, which shows that the problem to solve is really just the distance between two parallel planes.

fig 3a. Augmenting the lines with alternate direction vectors to form planes.

fig 3b. Rotation to view planes edge on.

The equations of these planes are just
\begin{equation}\label{eqn:shortestDistanceBetweenLines:160}
\begin{aligned}
P_1&: \Bx(r, s) = \Bp_1 + r \mathbf{\hat{d}}_1 + s \mathbf{\hat{d}}_2 \\
P_2&: \Bx(t, u) = \Bp_2 + t \mathbf{\hat{d}}_2 + u \mathbf{\hat{d}}_1,
\end{aligned}
\end{equation}
or with
\begin{equation}\label{eqn:shortestDistanceBetweenLines:180}
\mathbf{\hat{n}} = \frac{\mathbf{\hat{d}}_1 \cross \mathbf{\hat{d}}_2}{\Norm{\mathbf{\hat{d}}_1 \cross \mathbf{\hat{d}}_2}},
\end{equation}
the normal form for these planes are
\begin{equation}\label{eqn:shortestDistanceBetweenLines:200}
\begin{aligned}
P_1&: \Bx \cdot \mathbf{\hat{n}} = \Bp_1 \cdot \mathbf{\hat{n}} \\
P_2&: \Bx \cdot \mathbf{\hat{n}} = \Bp_2 \cdot \mathbf{\hat{n}}.
\end{aligned}
\end{equation}
Now we can state the distance between the planes trivially, using the results from our previous posts, finding
\begin{equation}\label{eqn:shortestDistanceBetweenLines:220}
d = \Abs{ \Bp_2 \cdot \mathbf{\hat{n}} – \Bp_1 \cdot \mathbf{\hat{n}} },
\end{equation}
or, encoding the triple product in it’s determinant form, the shortest distance between the lines (up to a sign), is
\begin{equation}\label{eqn:shortestDistanceBetweenLines:240}
\boxed{
d = \frac{
\begin{vmatrix}
\Bp_2 – \Bp_1 & \mathbf{\hat{d}}_1 & \mathbf{\hat{d}}_2
\end{vmatrix}
}{
\Norm{ \mathbf{\hat{d}}_1 \cross \mathbf{\hat{d}}_2 }
}.
}
\end{equation}

As a minimization problem.

Trying this as a minimization problem is actually kind of fun, albeit messy. Doing that calculation will give us the directed shortest distance between the lines.
We can form any number of vectors \( \Bm \) connecting the two lines
\begin{equation}\label{eqn:shortestDistanceBetweenLines:260}
\Bp_1 + s \mathbf{\hat{d}}_1 + \Bm = \Bp_2 + t \mathbf{\hat{d}}_2,
\end{equation}
or, with \( \Delta = \Bp_2 – \Bp_1 \), that directed distance is
\begin{equation}\label{eqn:shortestDistanceBetweenLines:280}
\Bm = \Delta + t \mathbf{\hat{d}}_2 – s \mathbf{\hat{d}}_1.
\end{equation}
We seek to minimize the squared length of this vector
\begin{equation}\label{eqn:shortestDistanceBetweenLines:300}
D = \Norm{\Bm}^2 = \Delta^2 + \lr{ t \mathbf{\hat{d}}_2 – s \mathbf{\hat{d}}_1 }^2 + 2 \Delta \cdot \lr{ t \mathbf{\hat{d}}_2 – s \mathbf{\hat{d}}_1 }.
\end{equation}
The minimization constraints are
\begin{equation}\label{eqn:shortestDistanceBetweenLines:320}
\begin{aligned}
0 &= \PD{s}{D} = 2 \lr{ t \mathbf{\hat{d}}_2 – s \mathbf{\hat{d}}_1 } \cdot \lr{ -\mathbf{\hat{d}}_1 } + 2 \Delta \cdot \lr{ – \mathbf{\hat{d}}_1 } \\
0 &= \PD{t}{D} = 2 \lr{ t \mathbf{\hat{d}}_2 – s \mathbf{\hat{d}}_1 } \cdot \lr{ \mathbf{\hat{d}}_2 } + 2 \Delta \cdot \lr{ \mathbf{\hat{d}}_2 }.
\end{aligned}
\end{equation}
With \( \alpha = \mathbf{\hat{d}}_1 \cdot \mathbf{\hat{d}}_2 \), our solution for \( s, t \) is
\begin{equation}\label{eqn:shortestDistanceBetweenLines:340}
\begin{bmatrix}
s \\
t
\end{bmatrix}
=
{
\begin{bmatrix}
1 & -\alpha \\
-\alpha & 1
\end{bmatrix}
}^{-1}
\begin{bmatrix}
\Delta \cdot \mathbf{\hat{d}}_1 \\
-\Delta \cdot \mathbf{\hat{d}}_2 \\
\end{bmatrix},
\end{equation}
so
\begin{equation}\label{eqn:shortestDistanceBetweenLines:360}
\begin{aligned}
t \mathbf{\hat{d}}_2 – s \mathbf{\hat{d}}_1
&=
\begin{bmatrix}
-\mathbf{\hat{d}}_1 & \mathbf{\hat{d}}_2
\end{bmatrix}
\begin{bmatrix}
s \\
t
\end{bmatrix} \\
&=
\inv{1 – \alpha^2}
\begin{bmatrix}
-\mathbf{\hat{d}}_1 & \mathbf{\hat{d}}_2
\end{bmatrix}
\begin{bmatrix}
1 & \alpha \\
\alpha & 1
\end{bmatrix}
\begin{bmatrix}
\Delta \cdot \mathbf{\hat{d}}_1 \\
-\Delta \cdot \mathbf{\hat{d}}_2 \\
\end{bmatrix} \\
&=
\inv{1 – \alpha^2}
\begin{bmatrix}
-\mathbf{\hat{d}}_1 & \mathbf{\hat{d}}_2
\end{bmatrix}
\begin{bmatrix}
\Delta \cdot \mathbf{\hat{d}}_1 – \alpha \Delta \cdot \mathbf{\hat{d}}_2 \\
\alpha \Delta \cdot \mathbf{\hat{d}}_1 -\Delta \cdot \mathbf{\hat{d}}_2 \\
\end{bmatrix} \\
&=
\inv{1 – \alpha^2}
\lr{
-\lr{ \Delta \cdot \mathbf{\hat{d}}_1} \mathbf{\hat{d}}_1 + \alpha \lr{ \Delta \cdot \mathbf{\hat{d}}_2} \mathbf{\hat{d}}_1
+
\alpha \lr{ \Delta \cdot \mathbf{\hat{d}}_1} \mathbf{\hat{d}}_2 – \lr{ \Delta \cdot \mathbf{\hat{d}}_2} \mathbf{\hat{d}}_2
} \\
&=
\inv{1 – \alpha^2}
\lr{
\lr{ \Delta \cdot \mathbf{\hat{d}}_1} \lr{
-\mathbf{\hat{d}}_1 + \alpha \mathbf{\hat{d}}_2
}
+
\lr{ \Delta \cdot \mathbf{\hat{d}}_2} \lr{
-\mathbf{\hat{d}}_2 + \alpha \mathbf{\hat{d}}_1
}
}.
\end{aligned}
\end{equation}
This might look a bit hopeless to simplify, but note that
\begin{equation}\label{eqn:shortestDistanceBetweenLines:380}
\begin{aligned}
\lr{ \mathbf{\hat{d}}_1 \wedge \mathbf{\hat{d}}_2}^2
&=
\lr{ \mathbf{\hat{d}}_1 \wedge \mathbf{\hat{d}}_2} \cdot \lr{ \mathbf{\hat{d}}_1 \wedge \mathbf{\hat{d}}_2} \\
&=
\mathbf{\hat{d}}_1 \cdot \lr{ \mathbf{\hat{d}}_2 \cdot \lr{ \mathbf{\hat{d}}_1 \wedge \mathbf{\hat{d}}_2} } \\
&=
\mathbf{\hat{d}}_1 \cdot \lr{ \alpha \mathbf{\hat{d}}_2 – \mathbf{\hat{d}}_1 } \\
&=
\alpha^2 – 1,
\end{aligned}
\end{equation}
and
\begin{equation}\label{eqn:shortestDistanceBetweenLines:400}
\begin{aligned}
\mathbf{\hat{d}}_2 \cdot \lr{ \mathbf{\hat{d}}_1 \wedge \mathbf{\hat{d}}_2} &= \alpha \mathbf{\hat{d}}_2 – \mathbf{\hat{d}}_1 \\
-\mathbf{\hat{d}}_1 \cdot \lr{ \mathbf{\hat{d}}_1 \wedge \mathbf{\hat{d}}_2} &= -\mathbf{\hat{d}}_2 + \alpha \mathbf{\hat{d}}_1.
\end{aligned}
\end{equation}
Let’s write \( B = \mathbf{\hat{d}}_1 \wedge \mathbf{\hat{d}}_2 \), and plug in our bivector expressions
\begin{equation}\label{eqn:shortestDistanceBetweenLines:420}
\begin{aligned}
t \mathbf{\hat{d}}_2 – s \mathbf{\hat{d}}_1
&=
-\inv{B^2}
\lr{
\lr{ \Delta \cdot \mathbf{\hat{d}}_1} \mathbf{\hat{d}}_2 \cdot B
-\lr{ \Delta \cdot \mathbf{\hat{d}}_2} \mathbf{\hat{d}}_1 \cdot B
} \\
&=
-\inv{B^2}
\lr{
\lr{ \Delta \cdot \mathbf{\hat{d}}_1} \mathbf{\hat{d}}_2
-\lr{ \Delta \cdot \mathbf{\hat{d}}_2} \mathbf{\hat{d}}_1
}
\cdot B \\
&=
-\inv{B^2}
\lr{
\Delta \cdot \lr{ \mathbf{\hat{d}}_1 \wedge \mathbf{\hat{d}}_2}
}
\cdot B \\
&=
-\inv{B^2} \lr{ \Delta \cdot B } \cdot B \\
&=
-\inv{B^2} \gpgradeone{ \lr{ \Delta \cdot B } B } \\
&=
-\inv{B^2} \gpgradeone{ \lr{ \Delta B – \Delta \wedge B } B } \\
&=
-\Delta + \inv{B^2} \lr{ \Delta \wedge B } \cdot B.
\end{aligned}
\end{equation}
The minimum directed distance between the lines is now reduced to just
\begin{equation}\label{eqn:shortestDistanceBetweenLines:440}
\begin{aligned}
\Bm
&= \Delta + t \mathbf{\hat{d}}_2 – s \mathbf{\hat{d}}_1 \\
&= \lr{ \Delta \wedge B } \inv{B}.
\end{aligned}
\end{equation}
Again, had we used the geometry effectively, illustrated in fig. 4, we could have skipped directly to this result. This is the rejection of the plane \( B \) from \( \Delta \), that is, rejection of both \( \mathbf{\hat{d}}_1, \mathbf{\hat{d}}_2 \) from the difference \( \Bp_2 – \Bp_1 \), leaving just the perpendicular shortest connector between the lines.

fig. 4. Projection onto the normal to the parallel planes.

We can also conceptualize this as computing the trivector volume (parallelepiped with edges \( \Bp_2 – \Bp_1, \mathbf{\hat{d}}_1, \mathbf{\hat{d}}_2 \)), and then dividing out the bivector (parallelogram with edges \(\mathbf{\hat{d}}_1, \mathbf{\hat{d}}_2 \)), to find the vector (height) of the parallelepiped.

Observe that rejecting from the plane, is equivalent to projecting onto the normal, so for \(\mathbb{R}^3\) we may translate this to conventional vector algebra, as a projection
\begin{equation}\label{eqn:shortestDistanceBetweenLines:500}
\Bm = \lr{\Delta \cdot \mathbf{\hat{n}}} \mathbf{\hat{n}},
\end{equation}
where \( \mathbf{\hat{n}} = \lr{ \mathbf{\hat{d}}_1 \cross \mathbf{\hat{d}}_2 }/\Norm{\mathbf{\hat{d}}_1 \cross \mathbf{\hat{d}}_2 } \).

If we want the magnitude of this vector, it’s just
\begin{equation}\label{eqn:shortestDistanceBetweenLines:480}
\begin{aligned}
\Norm{\Bm}^2
&=
\inv{B^4} \lr{ \lr{ \Delta \wedge B } B } \lr{ B \lr{ B \wedge \Delta } } \\
&=
\inv{B^2} \lr{ \Delta \wedge B }^2,
\end{aligned}
\end{equation}
or
\begin{equation}\label{eqn:shortestDistanceBetweenLines:460}
\boxed{
\Norm{\Bm} = \frac{ \Norm{ \lr{\Bp_2 – \Bp_1} \wedge \mathbf{\hat{d}}_1 \wedge \mathbf{\hat{d}}_2 } }{ \Norm{\mathbf{\hat{d}}_1 \wedge \mathbf{\hat{d}}_2} },
}
\end{equation}
which, for \(\mathbb{R}^3\), is equivalent to the triple product result we found above.