I am new to Sobolev spaces and, while trying to construct a proof, I make some subtle mistake that I cannot detect.
The setting: let $C \subset \Bbb R^n$ be a closed, measure-$0$ set. Let $U = \Bbb R ^n \setminus C$. Let $f : \Bbb R ^n \to \Bbb C$ be continuous, $f$ smooth of infinite order on $U$ but not derivable on $C$, and $f \in L^p (\Bbb R^n)$.
1) Clearly, $f \in W ^{\infty, p} (U) \ \forall p \ge 1$.
2) By defining $f_\alpha (x) = \left\{ \begin{array} {cc} (\partial _\alpha f) (x), & x \in U \\ 0, & x \in C \end{array} \right.$ for every multi-index $\alpha$, $f_\alpha$ is a weak derivative of $f$ on $\Bbb R^n$, so $f \in W^{\infty, p} (\Bbb R^n)$. Note that this seems to have nothing to do with Sobolev's extension theorem.
3) Localize: choose a small enough ball $B_x$ around every $x$. The restriction $f \big| _{B_x}$ will belong to $W ^{\infty, p} (B_x)$.
4) By Sobolev's embedding theorem, $f \big| _{B_x}$ will be smooth of infinite order on $B_x$.
5) Glueing these restrictions together, $f$ will be smooth of infinite order on $\Bbb R^n$, in particular on $C$, where is was supposed not to be so.
Where am I wrong? (There may be several mistakes above, not just one.)
(The motivation behind my question: replace $\Bbb R^n$ by a Riemannian manifold $M$, fix some $p \in M$ and let $f = d(p, \cdot)^2$ ($d$ the distance) and let $C$ be the cut locus of $p$.)
How do you deduce that $f \in W^{\infty,p}(\mathbb R^n)$ in step (2)?
As a simple illustration, take a function $f$ that satisfies $f(x) = |x|$ on a neighborhood of the origin, is $C^\infty$ away from $0$, and has compact support. Let $C = \{0\}$.
Then $f \in W^{1,p}(\mathbb R)$, $f$ is infinitely differentiable in $U = \mathbb R \setminus C$, but the weak derivatives of higher order don't extend across $C$ : $f \notin W^{2,p}(\mathbf R)$.