Finite dimensional real function spaces closed under composition I’m interested in classifying all finite dimensional vector subspaces of $V=C^\infty(\mathbb{R})$ which are closed under composition: $f,g \in V$ implies $f\circ g\in V$. The only such subspaces which come to mind are $0$, the space of all constant functions, the space of all linear functions $x\mapsto mx$, and the space of all affine functions $x\mapsto mx+b$. I believe this list may be complete, but I can’t think of an easy proof. Is it true that these are the only four such spaces?
 A: EDIT I finally have a proof of the whole classification. I'll leave my original work for posterity, and if you want to skip to the solution simply look after the final horizontal rule.

After thinking about this far too much in the past few days, I have a partial result. To skip the potentially boring introduction, go to the next horizontal rule.
Definition I will use the term composition space to refer to a finite-dimensional $\mathbb{R}$-subspace of $C^\infty(\mathbb{R})$ which is closed under composition.
Definition Let $A \subseteq C^\infty(\mathbb{R})$ be the space $\{x \mapsto ax + b : a,b \in \mathbb{R}\}$ of affine linear functions. We say that a composition space $V$ is affine if $V \subseteq A$ and non-affine otherwise.
Lemma The only $1$-dimensional composition spaces are $\{x \mapsto a : a \in \mathbb{R}\}$ and $\{x \mapsto ax : a \in \mathbb{R}\}$ (in particular, every $1$-dimensional composition space is affine).
Proof Let $V$ be a $1$-dimensional composition space. Choose some nonzero $f \in V$. Since $f \neq 0$, $X := f^{-1}(\mathbb{R}\setminus\{0\})$ is a nonempty open subset of $\mathbb{R}$. Now, for each $\alpha \in \mathbb{R}$, we must have $f \circ \alpha f \in V$, whence $f \circ \alpha f = \lambda(\alpha) f$ where $\lambda : \mathbb{R} \to \mathbb{R}$ is some function. Choose some $x_0 \in X$ and set $y := f(x_0) \neq 0$. Then $$f(\alpha y) = f(\alpha f(x_0)) = \lambda(\alpha) f(x_0) = \lambda(\alpha) y$$ so $\lambda(\alpha) = f(\alpha y) / y$. Since $f$ is smooth, this shows that $\lambda$ is smooth. In fact, we have $\lambda'(\alpha) = f'(\alpha y)$. Since we could have chosen $y$ to be any element of $f(X)$, this means that $f'$ is constant on each nonempty open set $\alpha f(X) = \{\alpha f(x) : x \in X\}$. These sets cover $\mathbb{R}$, so $f'$ is constant. This means that $f \in A$, whence it is easy to conclude that $V$ is as desired. $\square$
Corollary The only affine composition spaces are the four you listed: $0$, $\{x \mapsto a : a \in \mathbb{R}\}$, $\{x \mapsto ax : a \in \mathbb{R}\}$, and $A$.
Proof $A$ is $2$-dimensional, so any nontrivial proper subspace must have dimension $1$.
Of course, your hopeful classification can be restated as the following conjecture.
Conjecture All composition spaces are affine.

Proposition If there exists any non-affine composition space, then there exists a non-affine composition space $V$ such that


*

*For all $f \in V$ and all $i \geq 0$, $f^{(i)}(0) = 0$.

*If $f, g \in V$ and there is some open neighborhood $U$ of $0$ such that $f|_U = g|_U$, then $f = g$.

*$V$ is spanned by $\{f \circ g : f, g \in V\}$.

*$\dim V > 1$ is minimal among all non-affine composition spaces.


Proving this requires a few not-so-elegant reduction arguments. Let's begin by supposing $V$ is a non-affine composition space of minimal dimension (by the earlier lemma, $\dim V > 1$). Our goal is to show that $V$ satisfies the other three properties.
First, suppose for contradiction that there is some $F \in V$ such that $F(0) \neq 0$. Then the linear functional $f \mapsto f(0) : V \to \mathbb{R}$ is nontrivial, so $W := \ker (f \mapsto f(0))$ is a proper subspace of $V$ (of codimension $1$). $W$ is closed under composition, so minimality of $\dim V$ tells us that $W$ is affine. Since $V$ is closed under composition, it contains the nonzero constant function $F \circ 0 = x \mapsto F(0)$. Since the codimension of $W$ is $1$, $V$ is spanned by $W \cup \{F \circ 0\} \subseteq A$, whence $V$ is affine, a contradiction. We conclude that $f(0) = 0$ for all $f \in V$.
Now, for any $f, g \in V$, we find that $(f \circ g)'(0) = f'(g(0)) g'(0) = f'(0) g'(0)$. Thus, $W' := \{f \in V : f'(0) = 0\}$ is a subspace of $V$ which is closed under composition; again minimality of $\dim V$ tells us that $W' = V$ or $W'$ is affine. If $W'$ is affine, then (by the prior classification of affine composition spaces) $W' = 0$. Since again $W'$ has codimension $1$ (it is the kernel of $f \mapsto f'(0) : V \to \mathbb{R}$), this would mean that $\dim V = 1$, contradicting the earlier lemma. Thus, $W'$ is not affine, so $V = W'$, i.e. $f'(0) = 0$ for all $f \in V$.
Next, we will show that $V$ is spanned by $\{f \circ g : f,g \in V\}$. Let $L$ be the span of $\{f \circ g : f,g \in V\}$. $L$ is closed under composition, so by minimality of $\dim V$ we get that either $L$ is affine or $L = V$. Suppose first that $L$ is affine. Since we have already shown that all elements of $V$ send $0$ to $0$, we know that $L$ consists only of linear functions. Now let $F \in V \setminus \{0\}$ be arbitrary, and choose $x_0 \in \mathbb{R}$ such that $F(x_0) \neq 0$. Then $(F \circ \frac{x_0}{F(x_0)} F)(x_0) = F(x_0) \neq 0$, so $F \circ \frac{x_0}{F(x_0)} F \in L$ is a nonzero linear function $x \mapsto ax : \mathbb{R} \to \mathbb{R}$. Since $a \neq 0$, we have that the identity function is an element of $V$, whence $L = V$. Thus, in either case, $L = V$, as desired.
Now one can show by induction that $f^{(i)}(0) = 0$ for all $f \in V$ and all $i \geq 0$: use Taylor's theorem or Faà di Bruno's formula to show in the inductive step that $(f \circ g)^{(i+1)}(0) = 0$ whenever $f^{(j)}(0) = g^{(j)}(0)$ for all $0 \leq j \leq i$. Then since $\{f \circ g : f,g \in V\}$ spans $V$, we get that $f^{(i+1)}(0) = 0$ for all $f \in V$.
We have only left to show that the elements of $V$ are determined by their germs at $0$. So, let $V_0$ be the space of germs of elements of $V$ at $0$. Let $K$ be the kernel of the surjection $V \to V_0$, so that $K$ consists of those elements of $V$ which are identically $0$ in some neighborhood of $0$. Suppose for contradiction that $K = V$. Since $\{f \circ g : f,g \in V\}$ generates $V$, pick a basis $F_1 \circ G_1, F_2 \circ G_2, \dots, F_n \circ G_n$ for $V$. For each function $F_1, \dots, F_n, G_1, \dots, G_n$, there is a closed interval of maximum length whose interior contains $0$ on which the function is identically $0$. Intersecting these intervals, we get a closed interval $[a,b]$ such that:


*

*$a < 0 < b$,

*$F_i|_{[a,b]}$ and $G_i|_{[a,b]}$ are identically $0$ for all $1 \leq i \leq n$,

*If $U$ is an open set containing $a$ or $b$ then there is some $x \in U$ and some $1 \leq i \leq n$ such that $F_i(x) \neq 0$ or $G_i(x) \neq 0$.


Now $Z := \bigcap_{i=1}^n G_i^{-1}((a,b))$ is an open set containing $[a,b]$, hence there is some $x \in Z$ and some $1 \leq i_0 \leq n$ such that $F_{i_0}(x) \neq 0$ or $G_{i_0}(x) \neq 0$. On the other hand, each $F_i \circ G_i$ is identically $0$ on $Z$, meaning all elements of $V$ are identically $0$ on $Z$ (since the functions $F_i \circ G_i$ span $V$). This is a contradiction, so $K \neq V$. It's clear that $K$ is closed under composition, so by minimality of $\dim V$ we conclude that $K$ is affine. By the prior classification of affine composition spaces, $K = 0$. Thus, the map $V \to V_0$ is injective, so two elements of $V$ with the same germ at $0$ must be equal.

Ok, I have completed a proof of the conjecture. It's much simpler than I expected!
Theorem All composition spaces are affine.
Proof. Suppose for contradiction that there exists a non-affine composition space. By the previous work, let $V$ be a non-affine composition space of minimal dimension, so that $\dim V > 1$ and $f(0) = 0$ for all $f \in V$. Now, I claim that for all $F, G \in V \setminus \{0\}$, $(F')^{-1}(0) = (G')^{-1}(0)$. To see this, let $x_0 \in \mathbb{R}$ such that $F(x_0) \neq 0$ and define $F_1 := \frac{x_0}{F(x_0)} F$. Now $T := f \mapsto f \circ F_1$ is a linear endomorphism of $V$, and $T \neq 0$ since $T(F)(x_0) = F(F_1(x_0)) = F(x_0) \neq 0$. Thus, $\ker T$ has strictly smaller dimension than $V$. Moreover, $\ker T$ is closed under composition, since $f \circ F_1 = g \circ F_1 = 0$ implies $f \circ g \circ F_1 = f \circ 0 = 0$ (using the fact that $f(0) = 0$). By minimality of $\dim V$, $\ker T$ must be affine. Since each element of $V$ sends $0$ to $0$, we know that $\ker T$ consists only of linear functions. Now if $x \mapsto ax \in \ker T$, we have that $\frac{ax_0}{F(x_0)} F = aF_1 = 0$. Since $F \neq 0$, $\frac{ax_0}{F(x_0)} = 0$, so $a = 0$. Thus, $\ker T = 0$, so $T$ is an injective endomorphism of the finite-dimensional vector space $V$. This implies that $T$ is surjective. Thus, $G = T(H) = H \circ F_1$ for some $H \in V$. Now, whenever $F'(x) = 0$, we have $F_1'(x) = \frac{x_0}{F(x_0)} F'(x) = 0$, so $G'(x) = (H \circ F_1)'(x) = H'(F_1(x)) F_1'(x) = 0$. This shows that $(F')^{-1}(0) \subseteq (G')^{-1}(0)$. Symmetrically, $(G')^{-1}(0) \subseteq (F')^{-1}(0)$, so $(F')^{-1}(0) = (G')^{-1}(0)$, as desired.
Now, since $\dim V > 1$, let $f, g \in V$ be linearly independent. Since $f \neq 0$ and $f(0) = 0$, $f$ is not constant, so choose some $s \in \mathbb{R}$ such that $f'(s) \neq 0$. Since $(f')^{-1}(0) = (g')^{-1}(0)$, we also have that $g'(s) \neq 0$. Now set $h := f + \frac{-f'(s)}{g'(s)} g$. Since $f$ and $g$ are linearly independent, $h \neq 0$, so $(h')^{-1}(0) = (f')^{-1}(0)$; in particular, $h'(s) \neq 0$. But $h'(s) = 0$ by construction, so we have a contradiction. $\square$
