I need help with one of the problem in Lee's introduction to smooth manifolds. the problem is :
EXTENSION LEMMA FOR VECTOR FIELDS ON SUBMANIFOLDS: Suppose $M$ is a smooth manifold and $S\subseteq M$ is an embedded submanifold with or without boundary. Given $X\in \mathfrak{X}(S)$, show that there is a smooth vector field $Y$ on a neighborhood of $S$ in $M$ such that $X=Y|_S$ . Show that every such vector field extends to all of $M$ if and only if $S$ is properly embedded.
The first part of thr ptoblem I could manage and one direction of the second part of the problem: to show that $X$ extends to whole of $M$ if $S$ is properly embedded, is easy because $S$ is closed and it follows by the first part of this problem together with the extension lemma of vector fields. It is the converse of the second part of the problem that I cannot prove: if every vector field $X\in \mathfrak{X}(S)$ extends to all of $M$ then $S$ is properly embedded.
My plan to solve this is by using extension lemma for smooth functions on submanifolds (problem 5.18 (b) Lee's introduction to smooth manifold book). If I take an arbitrary $f\in C^{\infty}(S)$ then construct a vector field $X\in \mathfrak{X}(S)$ whose local representation is roughly of the form $X=f\frac{\partial }{\partial x^i}$, then if $X$ extends to all of $M$ we can also extend $f$ to a smooth function defined on all of $M$ and hence conclude $S$ is properly embedded. My problem is how do we construct such smooth vector fields?.
Please help Im stuck at this problem for three days now.
EDIT: I have come up with the following proof. Please can anyone check if it is a valid proof.
Proof: Let $\dim M= n$ and $\dim S =k$. Let $f\in C^{\infty}(S)$ be arbitrary. We show that $f$ can be extended to a smooth function $g\in C^{\infty}(M)$. Let $p\in S$ and let $(U_p, \phi_p)$ be a smooth slice chart for $S$ in $M$ containing $p$. If $V_p= S\cap U_p$ and $\theta_p = \phi_p|_{V_p}$, then $(V_p, \theta_p)$ is a smooth chart for $S$ containing $p$. Writing $\theta_p= (\theta^1_p, \ldots, \theta^k_p)$ for the component functions of $\theta$, we define a vector field $X_p: V_p\to TS$ on $S$ by $$X_p(x) = f(x) \dfrac{\partial}{\partial \theta^1_p}\bigg|_x.$$ Clearly $X_p$ is smooth because $f$ is smooth. Choose a neighborhood $W_p$ of $p$ in $M$ such that $\overline{W_p}\subset U_p$, then $X|_{S\cap \overline{W_p}}$ is a smooth vector field on $S$ along the closed set $S\cap \overline{W_p}$ (It has a smooth extension to a neighborhood $V_p \supset S\cap \overline{W_p}$). So by extension lemma for vector fields it has a smooth extension to a vector field $\widetilde{X_p}\in \mathfrak{X}(S)$. And by hypothesis there exists a vector field $Y_p\in \mathfrak{X}(M)$ such that $$Y_p \circ i = di \circ \widetilde{X_p},$$ where $i: S \hookrightarrow M$ is the inclusion. Write $\phi_p= (\phi_p^1, \ldots, \phi_p^n)$ for the component functions of $\phi$, then $Y_p$ can be expressed locally as, $$Y_p = \sum_{i=1}^{n}a_{p, i}\dfrac{\partial }{\partial \phi_p^i},$$ for some $a_{p,i} \in C^{\infty}(U_p)$. Now for all $x\in S\cap W_p$, we have from the equation $Y_p \circ i = di \circ \widetilde{X_p}$, $$\sum_{i=1}^{n}a_{p, i}(x)\dfrac{\partial }{\partial \phi_p^i}\bigg|_x = di_x (\widetilde{X_p}(x))= di_x \left(f(x)\dfrac{\partial}{\partial \theta_p^1}\bigg|_x\right) = f(x) \dfrac{\partial}{\partial \phi_p^1}\bigg|_x.$$ Comparing the coefficients we get $$a_{p,1}(x) = f(x), \hphantom{----} \forall x\in S\cap W_p.$$
Next we extend the collection of open sets $\{W_p\}_{p\in S}$ to an open cover $\{W_p\}_{p\in S} \cup \{O_{\alpha}\}$ of $M$ such that whenever $S \cap O_{\alpha} \neq \emptyset$, $S\cap O_{\alpha}$ is a slice of $O_{\alpha}$. Since $S$ is embedded, $f$ has a smooth extension to a smooth function $\widetilde{f}$ on a neighborhood $O$ containing $S$. So, $\widetilde{f}|_{S\cap O_{\alpha}}= f|_{S\cap O_{\alpha}}$ is a smooth function on a closed subset $S\cap O_{\alpha}$ of $O_{\alpha}$ (recall $S \cap O_{\alpha}$ is a slice of $O_{\alpha}$) because it has a smooth extension $\widetilde{f}|_{O \cap O_{\alpha}}$ on a neighborhood $O\cap O_{\alpha}\supset S\cap O_{\alpha}.$ Therefore by smooth extension lemma for smooth functions there exists $f_{\alpha}\in C^{\infty}(O_{\alpha})$ such that $f_{\alpha}|_{S\cap O_{\alpha}} = f|_{S\cap O_{\alpha}}$.
Now take a partition of unity $\{\psi_p\}\cup \{\psi_{\alpha}\}$ on $M$ subordinate to an open cover $\{W_p\}_{p\in S}\cup\{O_{\alpha}\}$ and define $g:M\to \mathbb{R}$ by $$g(x) = \sum_{p\in S}\psi_p(x) a_{p,1}(x) + \sum_{\alpha: S\cap O_{\alpha}\neq \emptyset}\psi_{\alpha}(x) f_{\alpha}(x) + \sum_{\alpha: S\cap O_{\alpha}= \emptyset}\psi_{\alpha}(x).$$ Where we interpret the products $\psi_pa_{p,1}$ and $\psi_{\alpha}f_{\alpha}$ as smooth functions on $M$ by assigning the value $0$ outside the support of $\psi_p$ and $\psi_{\alpha}$ respectively. Then $g\in C^{\infty}(M)$. It remains to show that $g$ agrees with $f$ on $S$. So let $x\in S$, then as $\psi_p(x)a_{p,1}(x) =0 $ for those $p$ in which $x\notin W_p$, and also $\psi_{\alpha}(x) =0$ for those $\alpha$ in which $S\cap O_{\alpha}= \emptyset$, we get $$\begin{align} g(x) & = \sum_{p: x\in W_p}\psi_p(x) a_{p,1}(x) + \sum_{\alpha: S\cap O_{\alpha}\neq \emptyset}\psi_{\alpha}(x) f_{\alpha}(x)\\ & = \sum_{p: x\in W_p}\psi_p(x) f(x) + \sum_{\alpha: S\cap O_{\alpha}\neq \emptyset}\psi_{\alpha}(x)f(x) \\ & = \left(\sum_{p\in S}\psi_p(x) + \sum_{\alpha}\psi_{\alpha}(x)\right)f(x) \\ & = f(x). \end{align} $$ Therefore we have shown that every $f\in C^{\infty}(S)$ admits a smooth extension $g\in C^{\infty}(M)$ and thus by problem 5.18(b) (Lee's book) we conclude that $S$ is properly embedded.