The problem
A classical problem in elementary differential geometry is the following: "Given a curve $\gamma:(a,b) \to \mathbb{R}^3$, how can we tell whether there exists some sphere to which $\gamma$ remains tangent?" (As an example: think about the curve being that traced by the seam of a baseball.)
The classical answer to this problem takes the following form: let $\kappa$ and $\tau$ denote the curvature and torsion of the space curve $\gamma$ respectively. If $\kappa, \tau, \kappa'$ (where $'$ denotes the derivative with respect to arclength) are non-vanshing for the curve, and if the expression \begin{equation} \frac{(\kappa')^2 + \kappa^2 \tau^2}{\kappa^4 \tau^2} \end{equation} is constant, then there exists a unique sphere in $\mathbb{R}^3$ to which $\gamma$ is tangent.
The proof of this result is a relatively simple exercise, and a perennial favorite on qualifying / final exams. (Hint: the center of curvature of a spherical curve is immobile.) Here we discuss a generalization of the above result, and its proof.
The discussion
Let us start very generally. (This discussion is based on something I learned from Robert Bryant.)
Let $M$ be a smooth manifold, and let $\mathcal{F}$ denote a finite-dimensional vector subspace (over $\mathbb{R}$) of $C^\infty(M;\mathbb{R})$. We ask the question: when is a curve $\gamma:(a,b)\to M$ tangent to the zero set of some non-trivial function $f\in \mathcal{F}$?
The answer can be found via a little bit of linear algebra.
For convenience, we assume that $\frac{d}{ds} \gamma \neq 0$; that is, the parametrization is non-degenerate. Also let $N$ denote the $\mathbb{R}$-dimension of $\mathcal{F}$. The question we seek to answer can be re-cast as asking when can we find $f\in \mathcal{F}$ such that $f\circ\gamma$ is constant on $(a,b)$.
We will approach this question from the differential algebra point of view. For any $\sigma\in (a,b)$, and any $k\in \mathbb{N}$, we can consider the mapping \begin{equation} J^{k}_{\gamma,\sigma}: \mathcal{F} \to \mathbb{R} \end{equation} given by \begin{equation} J^k_{\gamma,\sigma}(f) = \left( \frac{d}{ds}\right)^k (f\circ \gamma) |_{s = \sigma}. \end{equation} This mapping is obviously linear.
A necessary pointwise condition for our desired $f$ is that "for every $k \geq 0$, $J^k_{\gamma,\sigma}(f) = 0$". By dimension counting, we see that this is in general overdetermined: $\mathcal{F}$ has dimension $N$ but we have infinitely many linear equations; and $f\equiv 0$ would be the only solution. We are however looking for non-trivial solutions that are unique up to scaling (remember that $f$ and $\lambda f$ have the same zero sets when $0\neq \lambda\in \mathbb{R}$), which means we want the solution space to be one dimensional. This means that we expect that the span of ${J^k_{\gamma,\sigma}}$ to be $N-1$ dimensional. Denote, for convenience, by $r^m_\gamma(\sigma)$ the dimension of the span of ${ J^0_{\gamma,\sigma}, \ldots, J^m_{\gamma,\sigma}}$ in $\mathcal{F}'$.
Note that as linear dependence is a closed condition, we have that $r^m_\gamma:(a,b) \to \mathbb{Z}$ is lower semi-continuous.
The following is a version of Frobenius's theorem.
Applications
Sphere tangency
For the spheres problem originally posed, we use the fact that the spheres can be parametrized by their centers and radii and set $\mathcal{F}$ to be the family of functions of the form \[ a |x|^2 + b\cdot x + c.\] Here $a,c\in \mathbb{R}$ and $b\in \mathbb{R}^3$. So $\mathcal{F}$ is five dimensional.
Assume now $\gamma$ is parametrized by arclength.
The operators are given by \[ \begin{aligned} J^0&: (a,b,c) \mapsto a |\gamma|^2 + b \cdot \gamma + c \newline J^1&: (a,b,c) \mapsto 2a \gamma \cdot \gamma' + b \cdot \gamma' \newline J^2&: (a,b,c) \mapsto 2a (1 + \gamma\cdot \gamma'') + b \cdot \gamma'' \newline J^3&: (a,b,c) \mapsto 2a \gamma \cdot \gamma''' + b \cdot \gamma''' \end{aligned} \] To ensure that $r^3 = 4$, it suffices that $J^1, J^2, J^3$ are linearly independent. Using the Frenet-Serret formulas, we see that as long as $\kappa\tau$ and $\kappa'$ are not simulatenously vanishing, the linear independence holds.
Finally, the linear dependence of \[ J^4: (a,b,c) \mapsto 2a (\gamma' \cdot \gamma''' + \gamma \cdot \gamma'''') + b \cdot \gamma'''' \] on $(J^1, \ldots, J^3)$ can be rewritten using the Frenet-Serret formulas in the form given at the beginning of this post.
Sphere tangency ... on spheres
Let now $M = \mathbb{S}^{d} \subset \mathbb{R}^{d+1}$ be the unit sphere. We want to ask about when is $\gamma$ contained in a hyperplane section of $M$. The hyperplane sections can be described as solutions to equations which are linear on the ambient space $\mathbb{R}^{d+1}$ of the form $a\cdot x + b$, and so $\mathcal{F}$ is a space of dimension $d+2$.
Let's compute explicitly when $d = 3$. Our $\gamma$ now satisfies $|\gamma| = 1$. The operators are \[ \begin{aligned} J^0&: (a,b) \mapsto a \cdot \gamma + b \newline J^1&: (a,b) \mapsto a \cdot \gamma' \newline J^2&: (a,b) \mapsto a \cdot \gamma'' \newline J^3&: (a,b) \mapsto a \cdot \gamma''' \end{aligned} \] The requisite linear independence is now that simply $\gamma', \gamma'', \gamma'''$ remain linearly independent, and that $\gamma''''$ sits pointwise within the span of $\gamma', \gamma'', \gamma'''$.