## The C compiler is too forgiving! sizeof(variable_name+1) allowed?

April 28, 2022 C/C++ development and debugging. , , , ,

I carelessly passed:

sizeof(s.st_size+1)

to an allocator call, instead of:

s.st_size+1

and corrupted memory nicely.

What the hell would sizeof(variable+1) even mean, and why on earth would the compiler think that is anything close to valid? Both gcc and clang, each with -Wall, are completely quiet about this error!

## Curvilinear coordinates and reciprocal frames.

April 5, 2022 math and physics play

## Curvilinear coordinates.

Let’s start by considering a two parameter surface specified by $$\Bx = \Bx(a,b)$$. This defines a surface, for which the partials are both tangent to at each point of the surface. We write
\label{eqn:reciprocalAndTangentspace:20}
\begin{aligned}
\Bx_a &= \PD{a}{\Bx} \\
\Bx_b &= \PD{b}{\Bx}.
\end{aligned}

We call $$\text{span}\setlr{ \Bx_a, \Bx_b }$$ the tangent space of the surface at the parameter values $$a,b$$. One important role of the curvilinear vectors $$\Bx_a, \Bx_b$$ is to describe the area element for the subspace
\label{eqn:reciprocalAndTangentspace:40}
d\Bx_a \wedge d\Bx_b
=
\lr{ \Bx_a \wedge \Bx_b } da db.

Observe that for a two dimensional space, this has the form
\label{eqn:reciprocalAndTangentspace:60}
d\Bx_a \wedge d\Bx_b =
\begin{vmatrix}
\Bx_a & \Bx_b
\end{vmatrix} \Bi\, da db,

where $$\Bi$$ is the pseudoscalar for the space. The reader may be familiar with the determinant here, which is the Jacobian encountered in a change of variable context. We may generalize this idea of tangent space to more variables in an obvious fashion. For example, given
\label{eqn:reciprocalAndTangentspace:80}
\Bx = \Bx(a^1, a^2, \cdots, a^M),

we write
\label{eqn:reciprocalAndTangentspace:100}
\Bx_{a^i} = \PD{a^i}{\Bx}.

Let’s look at some examples, starting with circular coordinates in a plane
\label{eqn:reciprocalAndTangentspace:120}
\Bx(r, \theta) = r \Be_1 e^{i\theta},

where $$i = \Be_1 \Be_2$$. Our tangent space vectors are
\label{eqn:reciprocalAndTangentspace:140}
\Bx_r = \Be_1 e^{i\theta},

and
\label{eqn:reciprocalAndTangentspace:160}
\Bx_\theta
= r \Be_1 i e^{i\theta}
= r \Be_2 e^{i\theta}.

The area element in this case is
\label{eqn:reciprocalAndTangentspace:180}
d\Bx_r \wedge d\Bx_\theta
=
\Bx_r \wedge \Bx_\theta dr d\theta
=
\Be_1 e^{i\theta}
r \Be_2 e^{i\theta} }
dr d\theta
= i r dr d\theta.

Integration over a circular region gives
\label{eqn:reciprocalAndTangentspace:200}
\int_{r = 0}^R \int_{\theta=0}^{2\pi} d\Bx_r \wedge d\Bx_\theta
=
i \int_{r = 0}^R
r dr
\int_{\theta=0}^{2\pi}
d\theta
=
i \frac{R^2}{2} 2 \pi
= i \pi R^2.

This is the area of the circle, scaled by the unit bivector that represents the orientation of the plane in this two dimensional subspace.

As another example, consider a spherical parameterization, as illustrated in fig. 1.
\label{eqn:reciprocalAndTangentspace:220}
\Bx(r, \theta, \phi) = r \Be_1 e^{i\phi} \sin\theta + r \Be_3 \cos\theta.

fig. 1. Spherical coordinates.

Our curvilinear vectors in this case are
\label{eqn:reciprocalAndTangentspace:240}
\Bx_r = \Be_1 e^{i\phi} \sin\theta + \Be_3 \cos\theta,

\label{eqn:reciprocalAndTangentspace:260}
\Bx_\theta = r \Be_1 e^{i\phi} \cos\theta – r \Be_3 \sin\theta,

\label{eqn:reciprocalAndTangentspace:280}
\Bx_\phi = r \Be_2 e^{i\phi} \sin\theta.

In this case our (pseudoscalar) volume element is
\label{eqn:reciprocalAndTangentspace:300}
\begin{aligned}
d\Bx_r \wedge
d\Bx_\theta \wedge
d\Bx_\phi
&=
\lr{ \Be_1 e^{i\phi} \sin\theta + \Be_3 \cos\theta }
\lr{ \Be_1 e^{i\phi} \cos\theta – \Be_3 \sin\theta }
\Be_2 e^{i\phi}
}
\, dr d\theta d\phi \\
&=
\lr{ \Be_1 e^{i\phi} \sin\theta + \Be_3 \cos\theta }
\lr{ \Be_1 \cos\theta – \Be_3 e^{-i\phi} \sin\theta }
\Be_2
} \, dr d\theta d\phi \\
&=
\lr{ -\Be_1 \Be_3 \sin^2\theta
+
\Be_3 \Be_1 \cos^2\theta
}
\Be_2
} \, dr d\theta d\phi \\
&=
\Be_3 \Be_1 \Be_2 r^2 \sin\theta
\, dr d\theta d\phi \\
&=
I r^2 \sin \theta
\, dr d\theta d\phi.
\end{aligned}

This is just the standard spherical volume element, but scaled with the pseudoscalar. If we integrate the upper half of the volume (above the x-y plane), we would find $$\int_{r=0}^R \int_{\phi=0}^{2 \pi} \int_{\theta=0}^{\pi/2} d\Bx_r \wedge d\Bx_\theta \wedge d\Bx_\phi = (1/2) I (4/3) \pi R^3$$, half the volume of the sphere, again weighted by the pseudoscalar for the space. The sign would be negated for the lower half of plane, since our volume element is not strictly positive everywhere. This change of sign is not unique to this geometric algebra formulation, as we would have to integrate $$\int \Abs{\partial(x, y, z)/\partial(r,\theta, \phi)} \, dr d\theta d\phi$$ if we were computing the spherical volume using a standard scalar change of variables (taking the absolute value of our Jacobian.)

As a final example, let’s pick the coordinates associated with a relativistic boost and scale parameterization in spacetime, illustrated in fig. 2, with $$r = 1$$.

fig. 2. Boost worldline.

\label{eqn:reciprocalAndTangentspace:360}
x = r \gamma_0 e^{\gamma_0 \gamma_1 \alpha}.

For this surface we have
\label{eqn:reciprocalAndTangentspace:380}
\begin{aligned}
x_r &= \gamma_0 e^{\gamma_0 \gamma_1 \alpha} \\
x_\alpha &= r \gamma_1 e^{\gamma_0 \gamma_1 \alpha}.
\end{aligned}

In this case the volume element is
\label{eqn:reciprocalAndTangentspace:400}
dx_r \wedge dx_\alpha
\gamma_0 e^{\gamma_{01} \alpha}
\gamma_1 e^{\gamma_{01} \alpha}
}
\gamma_0
\gamma_1
e^{-\gamma_{01} \alpha}
e^{\gamma_{01} \alpha}
}
= \gamma_{01} r dr d\alpha.

This is cosmetically similar to the circular area element above, also weighted by a pseudoscalar, but in this case, $$\alpha$$ is not restricted to a bounded interval. We also see that the basic ideas here work for both Euclidean and non-Euclidean vector spaces.

## Reciprocal frame vectors.

Returning to a two dimensional surface, with tangent plane $$\text{span}\setlr{ \Bx_a, \Bx_b }$$, any vector in that plane has the form
\label{eqn:reciprocalAndTangentspace:320}
\By = y^a \Bx_a + y^b \Bx_b.

This is illustrated in fig. 3.

fig. 3. Tangent plane for two parameter surface.

### Coordinates.

We call $$y^a, y^b$$ the coordinates of the vector $$\By$$ with respect to the basis for the tangent space $$\text{span}\setlr{ \Bx_a, \Bx_b }$$. The computation of these coordinates is facilitated by finding the reciprocal frame $$\Bx^a, \Bx^b$$ for the tangent space that satisfies both $$\Bx^a, \Bx^b \in \text{span} \setlr{\Bx_a, \Bx_b }$$, and
\label{eqn:reciprocalAndTangentspace:340}
\Bx^\mu \cdot \Bx_\nu = {\delta^\mu}_\nu,

for all $$\mu \in \setlr{a,b}$$.

We may demonstrate that this works by example, dotting with each of our reciprocal frame vectors
\label{eqn:reciprocalAndTangentspace:420}
\begin{aligned}
y \cdot \Bx^a
&=
\lr{ y^a \Bx_a + y^b \Bx_b } \cdot \Bx^a \\
&=
y^a \lr{ \Bx_a \cdot \Bx^a } + y^b \lr{\Bx_b \cdot \Bx^a } \\
&= y^a,
\end{aligned}

and similarly
\label{eqn:reciprocalAndTangentspace:440}
\begin{aligned}
y \cdot \Bx^b
&=
\lr{ y^a \Bx_a + y^b \Bx_b } \cdot \Bx^b \\
&=
y^a \lr{ \Bx_a \cdot \Bx^b } + y^b \lr{\Bx_b \cdot \Bx^b } \\
&= y^b.
\end{aligned}

Provided we can find these reciprocal vectors, they provide the projections along each of the respective directions, allowing us to formulate the coordinate decomposition with respect to either the curvilinear or the reciprocal basis
\label{eqn:reciprocalAndTangentspace:460}
\By =
\lr{ \By \cdot \Bx^a } \Bx_a
+
\lr{ \By \cdot \Bx^b } \Bx_b
=
\lr{ \By \cdot \Bx_a } \Bx^a
+
\lr{ \By \cdot \Bx_b } \Bx^b.

For orthonornal Euclidean vectors, this reduces to the familiar sum of projections

\label{eqn:reciprocalAndTangentspace:480}
\Bx = \sum_i \lr{ \Bx \cdot \Be_i } \Be_i.

The reciprocal frame allows us to find the coordinates with respect to a oblique (non-orthonormal) basis, also not imposing a requirement for the space to be Euclidean.

### Orthogonal curvilinear coordinates.

When our tangent plane vectors are orthogonal, computation of the reciprocal frame just requires scaling. That scaling, perhaps not suprisingly, given the name reciprocal, just requires a vector inverse. For our two parameter case, that is just
\label{eqn:reciprocalAndTangentspace:500}
\Bx^a = \inv{\Bx_a} = \frac{\Bx_a}{\Bx_a \cdot \Bx_a}
\Bx^b = \inv{\Bx_b} = \frac{\Bx_b}{\Bx_b \cdot \Bx_b}.

The reader can readily verify that $$\Bx^a \cdot \Bx_a = \Bx^b \cdot \Bx_b = 1$$, and $$\Bx^a \cdot \Bx_b = \Bx^b \cdot \Bx_a = 0$$.

As an example, using the circular frame considered above, where we had
\label{eqn:reciprocalAndTangentspace:520}
\begin{aligned}
\Bx_r &= \Be_1 e^{i\theta} \\
\Bx_\theta &= r \Be_2 e^{i\theta},
\end{aligned}

the reciprocals are just
\label{eqn:reciprocalAndTangentspace:540}
\begin{aligned}
\Bx^r &= \Be_1 e^{i\theta} \\
\Bx^\theta &= \inv{r} \Be_2 e^{i\theta}.
\end{aligned}

In this specific case, the reader can also readily verify that $$\Bx^r \cdot \Bx_r = \Bx^\theta \cdot \Bx_\theta = 1$$, and $$\Bx^r \cdot \Bx_\theta = \Bx^\theta \cdot \Bx_r = 0$$.

Similarly, for the spherical frame basis (\ref{eqn:reciprocalAndTangentspace:240}, …), we have
\label{eqn:reciprocalAndTangentspace:560}
\Bx_r^2 = \Abs{e^{i\phi} \sin\theta}^2 + \cos^2\theta = 1,

\label{eqn:reciprocalAndTangentspace:580}
\Bx_\theta^2 = r^2 \lr{ \Abs{e^{i\phi} \cos\theta}^2 + \sin^2\theta } = r^2,

and
\label{eqn:reciprocalAndTangentspace:600}
\Bx_\phi^2 = r^2 \sin^2\theta,

so the spherical reciprocals are just
\label{eqn:reciprocalAndTangentspace:620}
\Bx^r = \Be_1 e^{i\phi} \sin\theta + \Be_3 \cos\theta,

\label{eqn:reciprocalAndTangentspace:640}
\Bx^\theta = \inv{r} \lr{ \Be_1 e^{i\phi} \cos\theta – \Be_3 \sin\theta},

\label{eqn:reciprocalAndTangentspace:660}
\Bx^\phi = \inv{r \sin\theta} \Be_2 e^{i\phi}.

Using straight inversion to compute the reciprocal frame vectors even works for non-Euclidean spaces. Consider the following example, using the relativisitic (Dirac) basis
\label{eqn:reciprocalAndTangentspace:680}
x(a,b) = a \lr{ \gamma_1 + \gamma_2 } + b \gamma_3,

for which we have
\label{eqn:reciprocalAndTangentspace:700}
x_a = \gamma_1 + \gamma_2,

and
\label{eqn:reciprocalAndTangentspace:720}
x_b = \gamma_3.

We have to be a bit more careful to compute the squares for this mixed metric space, but if we do that, we find
\label{eqn:reciprocalAndTangentspace:740}
x_a^2 =
\gamma_1^2 + \gamma_2^2
= -2,

and
\label{eqn:reciprocalAndTangentspace:760}
x_b^2 = -1,

so
\label{eqn:reciprocalAndTangentspace:780}
x^a = -\inv{2} \lr{ \gamma_1 + \gamma_2} ,

and
\label{eqn:reciprocalAndTangentspace:800}
x^b = -\gamma_3.

However, other than the fact that our vectors may square to either positive or negative values, the reciprocals are still trivial to calculate.

This example also serves to point out the importance of the span constraint $$x^a, x^b \in \text{span} \setlr{ x_a, x_b }$$. For example, suppose we altered one of the reciprocal frames with a vector component that is orthogonal to either of the original $$x_a, x_b$$ vectors, such as
\label{eqn:reciprocalAndTangentspace:820}
x^b = -\gamma_3 + 2 \gamma_0.

We still have $$x^a \cdot x_a = x^b \cdot x_b = 1$$, and $$x^a \cdot x_b = x^b \cdot x_a = 0$$, but can no longer write $$y = \lr{ y \cdot x_a } x^a + \lr{ y \cdot x_b } x^b$$ for any vector $$y \in \text{span} \setlr{ x_a, x_b }$$, since this would now introduce a contribution in space that no longer lies in the tangent plane.

Another gotcha to consider for non-Euclidean spaces is that we will need some other way to compute the reciprocals if we have lightlike vectors (with zero square) as in the following parameterization
\label{eqn:reciprocalAndTangentspace:840}
x(a,b) = a \lr{ \gamma_0 + \gamma_1 } + b \lr{ \gamma_0 – \gamma_1 }.

Here both of the tangent space vectors
\label{eqn:reciprocalAndTangentspace:860}
\begin{aligned}
x_a &= \gamma_0 + \gamma_1 \\
x_b &= \gamma_0 – \gamma_1,
\end{aligned}

are lightlike. This basis spans the $$ct,x$$ spacetime plane ($$\text{span} \setlr{ \gamma_0, \gamma_1 }$$), so we can reach any points on that plane. Clearly it must be possible to find the coordinates of vectors on that plane with respect to this basis, but we will have to figure out how to do so. We also do not know how to find the coordinates of vectors that lie in the tangent planes with curvilinear basis vectors that are non-orthogonal.

### Reciprocal frame for non-orthogonal coordinates.

Now let’s figure out how to compute the reciprocal vectors for the more general case where the tangent space vectors are not orthogonal. Doing so for a two parameter surface will be sufficient, as the generalization to higher degree surfaces will be clear.

Given $$\Bx^a, \Bx^b \in \text{span} \setlr{ \Bx_a, \Bx_b }$$, we set
\label{eqn:reciprocalAndTangentspace:880}
\begin{aligned}
\Bx^a &= \alpha^1 \Bx_a + \alpha^2 \Bx_b \\
\Bx^b &= \beta^1 \Bx_a + \beta^2 \Bx_b,
\end{aligned}

subject to the constraints $$\Bx^\mu \cdot \Bx_\nu = {\delta^\mu}_\nu, \forall \mu,\nu \in a,b$$. That is
\label{eqn:reciprocalAndTangentspace:900}
\begin{aligned}
\Bx^a \cdot \Bx_a &= \alpha^1 \Bx_a \cdot \Bx_a + \alpha^2 \Bx_b \cdot \Bx_a = 1 \\
\Bx^a \cdot \Bx_b &= \alpha^1 \Bx_a \cdot \Bx_b + \alpha^2 \Bx_b \cdot \Bx_b = 0 \\
\Bx^b \cdot \Bx_a &= \beta^1 \Bx_a \cdot \Bx_a + \beta^2 \Bx_b \cdot \Bx_a = 0 \\
\Bx^b \cdot \Bx_b &= \beta^1 \Bx_a \cdot \Bx_b + \beta^2 \Bx_b \cdot \Bx_b = 1.
\end{aligned}

With
\label{eqn:reciprocalAndTangentspace:920}
D =
\begin{bmatrix}
\Bx_a \cdot \Bx_a & \Bx_b \cdot \Bx_a \\
\Bx_a \cdot \Bx_b & \Bx_b \cdot \Bx_b
\end{bmatrix},

that is
\label{eqn:reciprocalAndTangentspace:940}
\begin{aligned}
D
\begin{bmatrix}
\alpha^1 \\
\alpha^2 \\
\end{bmatrix}
&=
\begin{bmatrix}
1 \\
0
\end{bmatrix} \\
D
\begin{bmatrix}
\beta^1 \\
\beta^2 \\
\end{bmatrix}
&=
\begin{bmatrix}
0 \\
1
\end{bmatrix} \\
\end{aligned}.

Since
\label{eqn:reciprocalAndTangentspace:960}
D^{-1}
=
\inv{
\begin{vmatrix}
\Bx_a \cdot \Bx_a & \Bx_b \cdot \Bx_a \\
\Bx_a \cdot \Bx_b & \Bx_b \cdot \Bx_b
\end{vmatrix}
}
\begin{bmatrix}
\Bx_b \cdot \Bx_b & -\Bx_b \cdot \Bx_a \\
-\Bx_a \cdot \Bx_b & \Bx_a \cdot \Bx_a
\end{bmatrix},

we have
\label{eqn:reciprocalAndTangentspace:980}
\begin{aligned}
\begin{bmatrix}
\alpha^1 \\
\alpha^2 \\
\end{bmatrix}
&=
\inv{
\Bx_a^2 \Bx_b^2 – \lr{ \Bx_a \cdot \Bx_b }^2
}
\begin{bmatrix}
\Bx_b \cdot \Bx_b \\
-\Bx_a \cdot \Bx_b
\end{bmatrix} \\
\begin{bmatrix}
\beta^1 \\
\beta^2 \\
\end{bmatrix}
&=
\inv{
\Bx_a^2 \Bx_b^2 – \lr{ \Bx_a \cdot \Bx_b }^2
}
\begin{bmatrix}
-\Bx_b \cdot \Bx_a \\
\Bx_a \cdot \Bx_a
\end{bmatrix}.
\end{aligned}

Back substitution gives
\label{eqn:reciprocalAndTangentspace:1000}
\begin{aligned}
\Bx^a
&=
\frac{
\Bx_b^2 \Bx_a – \lr{\Bx_a \cdot \Bx_b} \Bx_b
}
{
\Bx_a^2 \Bx_b^2 – \lr{ \Bx_a \cdot \Bx_b }^2
} \\
\Bx^b
&=
\frac{
-\lr{ \Bx_b \cdot \Bx_a } \Bx_a
+
\Bx_a^2 \Bx_b
}
{
\Bx_a^2 \Bx_b^2 – \lr{ \Bx_a \cdot \Bx_b }^2
}.
\end{aligned}

### Geometric algebra form of the reciprocal frame vectors.

The mess of dot products above is not terribly desirable. This can be cleaned up significantly, by observing that a bivector term can be factored from both the numerator and denominator. In particular, using the distribution identity, a squared bivector has the form
\label{eqn:reciprocalAndTangentspace:1020}
\begin{aligned}
\lr{ \Ba \wedge \Bb }^2
&=
\lr{ \Ba \wedge \Bb }
\cdot
\lr{ \Ba \wedge \Bb } \\
&=
\lr{ \lr{ \Ba \wedge \Bb } \cdot \Ba } \cdot \Bb \\
&=
\lr{ \lr{ \Bb \cdot \Ba } \Ba – \Ba^2 \Bb } \cdot \Bb \\
&=
\lr{ \Bb \cdot \Ba }^2 – \Ba^2 \Bb^2.
\end{aligned}

Also
\label{eqn:reciprocalAndTangentspace:1040}
\lr{ \Ba \wedge \Bb } \cdot \Bc =
\lr{ \Bb \cdot \Bc } \Ba

\lr{ \Ba \cdot \Bc } \Bb.

Using these, we can write
\label{eqn:reciprocalAndTangentspace:1060}
\begin{aligned}
\Bx^a
&=
\frac{
\Bx_b \cdot \lr{ \Bx_a \wedge \Bx_b }
}
{
\lr{ \Bx_a \wedge \Bx_b }^2
} \\
\Bx^b
&=
\frac{
-\Bx_a \cdot \lr{ \Bx_a \wedge \Bx_b }
}
{
\lr{ \Bx_a \wedge \Bx_b }^2
} \\
\end{aligned},

or
\label{eqn:reciprocalAndTangentspace:1080}
\begin{aligned}
\Bx^a
&=
\Bx_b \cdot \inv{ \lr{ \Bx_a \wedge \Bx_b } } \\
\Bx^b
&=
-\Bx_a \cdot \inv{ \lr{ \Bx_a \wedge \Bx_b } }.
\end{aligned}

It’s immediately clear why this works. Take for example
\label{eqn:reciprocalAndTangentspace:1100}
\begin{aligned}
\Bx_a \cdot \Bx^a
&=
\Bx_a \cdot \lr{ \Bx_b \cdot \inv{ \lr{ \Bx_a \wedge \Bx_b } } } \\
&=
\lr{ \Bx_a \wedge \Bx_b } \cdot \inv{ \lr{ \Bx_a \wedge \Bx_b } } \\
&=
1,
\end{aligned}

and
\label{eqn:reciprocalAndTangentspace:1120}
\begin{aligned}
\Bx_b \cdot \Bx^a
&=
\Bx_b \cdot \lr{ \Bx_b \cdot \inv{ \lr{ \Bx_a \wedge \Bx_b } } } \\
&=
\lr{ \Bx_b \wedge \Bx_b } \cdot \inv{ \lr{ \Bx_a \wedge \Bx_b } } \\
&=
0.
\end{aligned}

It’s immediately obvious that if we generalize to a three parameter surface, then we must have
\label{eqn:reciprocalAndTangentspace:1140}
\begin{aligned}
\Bx^a
&=
\lr{ \Bx_b \wedge \Bx_c } \cdot \inv{ \lr{ \Bx_a \wedge \Bx_b \wedge \Bx_c } } \\
\Bx^b
&=
-\lr{ \Bx_a \wedge \Bx_c } \cdot \inv{ \lr{ \Bx_a \wedge \Bx_b \wedge \Bx_c } } \\
\Bx^c
&=
\lr{ \Bx_a \wedge \Bx_b } \cdot \inv{ \lr{ \Bx_a \wedge \Bx_b \wedge \Bx_c } }.
\end{aligned}

How to generalize to still higher dimensions is clear. Specifically, given $$\Bx = \Bx(a^1, a^2, \cdots, a^m)$$, let’s write $$\Bx_i = \PDi{a^i}{\Bx}$$, with reciprocals $$\Bx^i$$. Then the reciprocals are given by
\label{eqn:reciprocalAndTangentspace:1300}
\Bx^i = (-1)^{i-1} \lr{ \Bx_1 \wedge \cdots \Bx_{i-1} \wedge \Bx_{i+1} \cdots \Bx_m } \cdot \inv{ \Bx_1 \wedge \Bx_2 \wedge \cdots \Bx_m }.

In the leading blade, we have a wedge of all the basis elements, except for $$\Bx_i$$, and each time we move down the line, the sign changes by a factor of one.

Let’s apply this blade dot product form of the reciprocal frame vectors to some non-orthogonal examples. For the first example, consider an elliptical parameterization illustrated in fig. 4.

fig. 4. Elliptical parameter differentials.

\label{eqn:reciprocalAndTangentspace:1320}
\Bx = a \Be_1 \cos\theta + a \epsilon \Be_2 \sin\theta.

We find that curvilinear bases vectors
\label{eqn:reciprocalAndTangentspace:1340}
\begin{aligned}
\Bx_a &= \Be_1 \cos\theta + \epsilon \Be_2 \sin\theta \\
\Bx_\theta &= -a \Be_1 \sin\theta + a \epsilon \Be_2 \cos\theta.
\end{aligned}

We can check that these are generally non-orthogonal as
\label{eqn:reciprocalAndTangentspace:1360}
\Bx_a \cdot \Bx_\theta = – a \cos\theta \sin\theta + a \epsilon^2 \cos\theta \sin\theta
= \frac{a}{2} \lr{ \epsilon^2 -1 } \sin\lr{ 2 \theta },

which shows that these vectors are orthogonal only in the limiting circular case, where the eccentricity $$\epsilon$$ goes to one, or at the specific points $$\theta = n \pi/2$$. The area element is
\label{eqn:reciprocalAndTangentspace:1380}
\begin{aligned}
d\Bx_a \wedge d\Bx_\theta
&= \lr{ \Be_1 \cos\theta + \epsilon \Be_2 \sin\theta } \wedge \lr{ -a \Be_1 \sin\theta + a \epsilon \Be_2 \cos\theta } \, da d\theta \\
&= a \epsilon \Be_1 \Be_2 \lr{ \cos^2 \theta + \sin^2 \theta } \, da d\theta \\
&= i a \epsilon da d\theta.
\end{aligned}

We can use this to find the (unit pseudoscalar scaled) area of an ellipse, which is
\label{eqn:reciprocalAndTangentspace:1400}
\begin{aligned}
A &= \int_{a = 0}^a \int_{\theta = 0}^{2\pi} d\Bx_a \wedge d\Bx_\theta \\
&= \int_{a = 0}^a \int_{\theta = 0}^{2\pi} i a \epsilon da d\theta \\
&= i \frac{a^2}{2} \epsilon \lr{ 2 \pi } \\
&= i \pi a \lr{ a \epsilon }.
\end{aligned}

As a check observe that we recover the circular area in the limit $$\epsilon \rightarrow 1$$, where $$a = a \epsilon$$ is the radius of the circle. Now let’s find our reciprocals
\label{eqn:reciprocalAndTangentspace:1420}
\begin{aligned}
\Bx^a
&= \Bx_\theta \cdot \inv{ i a \epsilon } \\
&= \inv{a \epsilon} \lr{ -a \Be_1 \sin\theta + a \epsilon \Be_2 \cos\theta } \cdot \lr{ \Be_2 \Be_1 } \\
&= \inv{\epsilon} \lr{ \Be_2 \sin\theta + \epsilon \Be_1 \cos\theta },
\end{aligned}

and
\label{eqn:reciprocalAndTangentspace:1440}
\begin{aligned}
\Bx^\theta
&= -\Bx_a \cdot \inv{ i a \epsilon } \\
&= -\inv{a \epsilon} \lr{ \Be_1 \cos\theta + \epsilon \Be_2 \sin\theta } \cdot \lr{ \Be_2 \Be_1 } \\
&= \inv{a \epsilon} \lr{ \Be_2 \cos\theta – \epsilon \Be_1 \sin\theta }.
\end{aligned}

Let’s return to the relativistic two parameter surface of \ref{eqn:reciprocalAndTangentspace:840}. Our area element is
\label{eqn:reciprocalAndTangentspace:1460}
\begin{aligned}
dx_a \wedge dx_b &=
\lr{
\gamma_0 + \gamma_1
}
\wedge
\lr{
\gamma_0 – \gamma_1
}
\, da db \\
&= 2 \gamma_1 \gamma_0\, da db.
\end{aligned}

so our reciprocals are
\label{eqn:reciprocalAndTangentspace:1480}
\begin{aligned}
x^a
&= x_b \cdot \inv{ 2 \gamma_{10} } \\
&= \inv{2} \lr{ \gamma_0 – \gamma_1 } \cdot \gamma_{01} \\
&= \inv{2} \lr{ \gamma_1 – \gamma_0 },
\end{aligned}

and
\label{eqn:reciprocalAndTangentspace:1500}
\begin{aligned}
x^b
&= -x_a \cdot \inv{ 2 \gamma_{10} } \\
&= – \inv{2} \lr{ \gamma_0 + \gamma_1 } \cdot \gamma_{01} \\
&= – \inv{2} \lr{ \gamma_1 + \gamma_0 }.
\end{aligned}

Sure enough we are able to compute a set of reciprocal frame vectors, satisfying the definition. In this case, both of those are also lightlike, even though they span the $$ct,x$$ plane.

### Matrix solution of the reciprocal frame vectors.

An alternative, one that is possibly more computationally effecient, is using matrix algebra to perform the same computation. Consider an m-parameter surface $$\Bx = \Bx(a^1, \cdots, a^m)$$, with $$\Bx_i = \PDi{a^i}{\Bx}$$, we can form a Jacobian matrix of all the partials
\label{eqn:reciprocalAndTangentspace:1160}
J^\T =
\begin{bmatrix}
\Bx_1 & \Bx_2 & \cdots & \Bx_m
\end{bmatrix}.

We can now cast each reciprocal vector into a matrix equation to be solved, say
\label{eqn:reciprocalAndTangentspace:1180}
\Bx^i = J^\T \Balpha_i,

where $$\Balpha_i$$ is an unknown column matrix to be determined for each reciprocal vector.
The m-parameter generalization of \ref{eqn:reciprocalAndTangentspace:920} is
\label{eqn:reciprocalAndTangentspace:2140}
D \Balpha_i = \Be_i,

where
\label{eqn:reciprocalAndTangentspace:1200}
D = J G J^\T,

and $$G$$ is the metric matrix for the space.  Note that for most of physics, there are really only two metrics of interest. The first is the identity matrix $$G = I$$, which we use for Euclidean spaces, and $$G = \pm \text{diag}(1,-1,-1,-1)$$, the metric for special relativity.

In block matrix form, we have
\label{eqn:reciprocalAndTangentspace:2160}
J G J^\T
\begin{bmatrix}
\Balpha_1 & \cdots & \Balpha_m
\end{bmatrix}
= I,

or
\label{eqn:reciprocalAndTangentspace:2220}
\begin{bmatrix}
\Balpha_1 & \cdots & \Balpha_m
\end{bmatrix}
=
\lr{J G J^\T}^{-1}.

Let
\label{eqn:reciprocalAndTangentspace:2180}
X =
\begin{bmatrix}
\Bx^1 & \cdots & \Bx^m
\end{bmatrix},

so
\label{eqn:reciprocalAndTangentspace:2200}
X = J^\T
\begin{bmatrix}
\Balpha_1 & \cdots & \Balpha_m
\end{bmatrix}
=
J^\T
\lr{J G J^\T}^{-1}.

In the special case where the number of parameters equals the dimension of the vector space, $$J^\T$$ is both square and (generally) invertible, so we can simplify things considerably
\label{eqn:reciprocalAndTangentspace:2100}
\begin{aligned}
X
&=
J^\T \lr{ J G J^\T }^{-1} \\
&=
J^\T (J^\T)^{-1} G^{-1} J^{-1} \\
&=
G^{-1} J^{-1} \\
&=
\lr{ J G }^{-1}.
\end{aligned}

We define the gradient $$\spacegrad$$, implicitly as a directional derivative of the following form
\label{eqn:reciprocalAndTangentspace:1520}
\Ba \cdot \spacegrad f = \evalbar{ \ddt{} f(\Bx + \Ba t) }{t = 0}.

Expanding by chain rule, this is
\label{eqn:reciprocalAndTangentspace:1540}
= \evalbar{ \PD{(x^i + a^i t)}{f} \PD{t}{(x^i + a^i t)} }{ t = 0 }
= a^i \PD{x^i}{f}
= \lr{ \Ba \cdot \Be^i} \PD{x^i}{f}
= \Ba \cdot \lr{ \Be^i \PD{x^i}{} } f,

so, the gradient with respect to the standard basis $$\setlr{ \Be_i }$$, and it’s reciprocal frame $$\setlr{\Be^i}$$, is
\label{eqn:reciprocalAndTangentspace:1560}

The reciprocal basis pairing here is an allowance for non-Euclidean spaces, and for Euclidean spaces reduces to the usual, since $$\Be^i = \Be_i$$.
Next we consider a change of coordinates, where
\label{eqn:reciprocalAndTangentspace:1580}
x^i = x^i( a^1, a^2, \cdots, a^n ).

Expressing the gradient in terms of these parameters, we have
\label{eqn:reciprocalAndTangentspace:1600}

With
\label{eqn:reciprocalAndTangentspace:1620}
\Bx^j = \Be^i \PD{x^i}{a^j} = \spacegrad a^j,

we have
\label{eqn:reciprocalAndTangentspace:1640}

a curvilinear representation of the gradient.

These parameter gradients have been written as $$\Bx^j$$’s as they are reciprocal to $$\Bx_j = \PDi{a_j}{\Bx}$$. To show this, we just have to computing the dot products of such a pair, and apply the chain rule in reverse
\label{eqn:reciprocalAndTangentspace:1660}
\begin{aligned}
\Bx^i \cdot \Bx_j &= \lr{ \Be^k \PD{x^k}{a^i} } \cdot \PD{a^j}{\Bx} \\
&= \lr{ \Be^k \PD{x^k}{a^i} } \cdot \lr{ \PD{a^j}{x^m} \Be_m } \\
&= {\delta^k}_m \PD{x^k}{a^i} \PD{a^j}{x^m} \\
&= \PD{x^m}{a^i} \PD{a^j}{x^m} \\
&= \PD{a^j}{a^i} \\
&= {\delta^i}_j.
\end{aligned}

This provides yet another way to compute our reciprocal frame. Manually computing the reciprocal frame vectors this way can be pretty hard if we try to do this in the straightforward braindead way, but we will see there is an easier way.

Illustrating by example, consider the circular parameterization again, with
\label{eqn:reciprocalAndTangentspace:1680}
\Bx = \Be_1 e^{i \theta}, \quad i = \Be_1 \Be_2.

In order to take the gradients of $$r, \theta$$, we can first write out our parameterization in coordinates
\label{eqn:reciprocalAndTangentspace:1700}
\begin{aligned}
x &= r \cos\theta \\
y &= r \sin\theta,
\end{aligned}

or
\label{eqn:reciprocalAndTangentspace:1720}
\begin{aligned}
r^2 &= x^2 + y^2 \\
\tan\theta = \frac{y}{x}.
\end{aligned}

The $$r$$ gradient is easy to compute
\label{eqn:reciprocalAndTangentspace:1740}
= 2 x \Be_1 + 2 y \Be_2,

or
\label{eqn:reciprocalAndTangentspace:1760}
= \frac{x}{r} \Be_1 + \frac{y}{r} \Be_2
= \cos\theta \Be_1 + \sin\theta \Be_2
= \Be_1 e^{i\theta}.

For the $$\theta$$ gradient we have
\label{eqn:reciprocalAndTangentspace:1780}
\frac{y}{x}
=
\Be_1 \PD{x}{} \frac{y}{x}
+
\Be_2 \PD{y}{} \frac{y}{x}
=
-\Be_1 \frac{y}{x^2} + \Be_2 \inv{x},

so
\label{eqn:reciprocalAndTangentspace:1800}
\begin{aligned}
&=
\cos^2\theta \lr{ -\Be_1 \frac{r \sin\theta}{r^2 \cos^2\theta} + \Be_2 \inv{r \cos\theta} } \\
&=
\inv{r} \lr{ -\Be_1 \sin\theta + \Be_2 \cos\theta } \\
&=
\frac{\Be_2}{r} \lr{ -\Be_2 \Be_1 \sin\theta + \cos\theta } \\
&=
\inv{r} \Be_2 e^{i\theta}.
\end{aligned}

As well as finding our reciprocals $$\Bx^r = \spacegrad r, \Bx^\theta = \spacegrad \theta$$, we now know the circular representation of the gradient
\label{eqn:reciprocalAndTangentspace:2120}
=
\Be_1 e^{i\theta}
\PD{r}{}
+
\inv{r} \Be_2 e^{i\theta} \PD{\theta}{}
= \rcap \PD{r}{} + \inv{r} \thetacap \PD{\theta}{}.

It was a lot trickier to compute the reciprocal frame vectors this way than our previous vector-bivector dot products or matrix inverse methods. That computation also only seemed possible because we could solve for $$r, \theta$$ in this specific case. What would we do when we have more complicated and unseparable parameterizations? Well, we don’t actually have to be able to solve for the parameters as functions of the coordinates, since we can use the same implicit differentiation methods used above in a more systematic fashion. Given
\label{eqn:reciprocalAndTangentspace:2240}
x^i = x^i(a^1, a^2, \cdots, a^n),

the gradients of each of these coordinates is
\label{eqn:reciprocalAndTangentspace:2260}
\begin{aligned}
=
e^j \PD{x^j}{x^i}
= e^j {\delta^i}_j
= e^i.
\end{aligned}

and
\label{eqn:reciprocalAndTangentspace:2280}
\begin{aligned}
&=
e^j \PD{x^j}{x^i} \\
&=
e^j \PD{a^k}{x^i} \PD{x^j}{a^k} \\
&=
\end{aligned}

or
\label{eqn:reciprocalAndTangentspace:2300}

In block matrix form, this is
\label{eqn:reciprocalAndTangentspace:2320}
\begin{bmatrix}
\end{bmatrix}
\begin{bmatrix}
\PD{a^1}{x^1} & \cdots & \PD{a^1}{x^n} \\
\vdots & & \\
\PD{a^n}{x^1} & \cdots & \PD{a^n}{x^n}
\end{bmatrix}
=
\begin{bmatrix}
\Be^1 & \cdots & \Be^n
\end{bmatrix}.

Note that
\label{eqn:reciprocalAndTangentspace:2340}
{
\begin{bmatrix}
\Be_1 & \cdots & \Be_n
\end{bmatrix}
}^\T
G
\begin{bmatrix}
\Be^1 & \cdots & \Be^n
\end{bmatrix}
= I,

or
\label{eqn:reciprocalAndTangentspace:2360}
\begin{bmatrix}
\Be^1 & \cdots & \Be^n
\end{bmatrix}
= G^{-1},

so
\label{eqn:reciprocalAndTangentspace:2380}
\begin{bmatrix}
\end{bmatrix}
J = G^{-1}.

This gives us
\label{eqn:reciprocalAndTangentspace:2400}
X =
G^{-1}
J^{-1}
=
\lr{J G}^{-1},

as we found previously.

Let’s write this out explicitly for the two parameter (Euclidean) case, and apply it to our circular parameterization
\label{eqn:reciprocalAndTangentspace:1960}
\begin{bmatrix}
\end{bmatrix}
=
{\begin{bmatrix}
\PD{a}{x^1} & \PD{a}{x^2} \\
\PD{b}{x^1} & \PD{b}{x^2}
\end{bmatrix}
}^{-1}
=
\frac{
\begin{bmatrix}
\PD{b}{x^2} & -\PD{a}{x^2} \\
-\PD{b}{x^1} & \PD{a}{x^1}
\end{bmatrix}
}{
\PD{a}{x^1} \PD{b}{x^2} – \PD{b}{x^1} \PD{a}{x^2}
},

or
\label{eqn:reciprocalAndTangentspace:1980}
\begin{aligned}
\spacegrad a &= \inv{\Abs{J}} \lr{ \PD{b}{x^2} \Be_1 -\PD{b}{x^1} \Be_2 } \\
\spacegrad b &= \inv{\Abs{J}} \lr{ -\PD{a}{x^2} \Be_1 + \PD{a}{x^1} \Be_2 }.
\end{aligned}

Application to the our familiar circular parameterization gives
\label{eqn:reciprocalAndTangentspace:2000}
\begin{aligned}
x &= r \cos\theta \\
y &= r \sin\theta,
\end{aligned}

so
\label{eqn:reciprocalAndTangentspace:2020}
J^\T =
\begin{bmatrix}
\cos\theta & -r \sin\theta \\
\sin\theta & r \cos\theta
\end{bmatrix},

so
\label{eqn:reciprocalAndTangentspace:2040}
\Abs{J} = r \lr{ \cos^2\theta + \sin^2 \theta } = r.

\label{eqn:reciprocalAndTangentspace:2060}
\begin{aligned}
&= \inv{r} \lr{ \Be_1 \PD{\theta}{} (r \sin\theta) – \Be_2 \PD{\theta}{} (r \cos\theta) } \\
&= \Be_1 \cos\theta + \Be_2 \sin\theta \\
&= \Be_1 e^{i\theta},
\end{aligned}

and
\label{eqn:reciprocalAndTangentspace:2080}
\begin{aligned}