Functions which are differentiable only on a prescribed subset of $\mathbb{C}$. For homework, I had to answer the question

Construct a polynomial function of $x$ and $y$ which is differentiable on the parabola $y=x^2$ but at no other point on the complex plane.  Then write the function in terms of $z=x+i y$.

(This is in Palka, $\S 3.2 \# 6.12$.)
Using Cauchy Riemann I get
$$u(x,y)=\frac{x^3}{3}+\frac{y^2}{2}$$
$$v(x,y)=-\frac{x^3}{3}+\frac{y^2}{2}$$
is differentiable if and only if $y=x^2$. This answers the question, but now I have other things I want to know.


*

*I think this solution is unique (up to adding/multiplying by constants), but I am not sure.  If so, does this fail to be unique if we drop the assumption that $u$ and $v$ should be polynomial in $x$ and $y$?  Of course it is not unique.  If $g=u'+i v'$ is holomorphic everywhere then letting $f+g=\overline{u}+i\overline{v}$, the Cauchy Riemann equations for $f+g$ are $$\left\{\begin{array}{l}\overline{u}_x=u_x+u_x^\prime=v_y+v_y^\prime=\overline{v}_y^\prime \\ \overline{u}_y=u_y+u_y^\prime=-v_x-v_x^\prime=\overline{v}_x^\prime\end{array}\right.$$ but since $u_x^\prime=v_y^\prime$ and $u_y^\prime=-v_x^\prime$ everywhere, this reduces to the condition that $u$ is differentiable which is only true iff $y=x^2$ by assumption.  So $f+g$ is differentiable only on $y=x^2$ for any holomorphic $g$.  So, my only remaining question is number 2:

*Suppose I were given some other set $\mathcal{S}\subset \mathbb{C}$ other than $y=x^2$.  How would I go about finding a function differentiable only on $\mathcal{S}$?  With a nice algebraic variety like $y=x^2$ we can just do the integration trick to make Cauchy Riemann always work there, but what if the set has a less nice closed form, like $(y=x)\vee (y=x^2)$ or the Cantor set?  Is it always possible?  If not, is there an 'only if' condition characterizing for which $\mathcal{S}$ we can find a function differentiable only on $\mathcal{S}$?
Apologies if these questions are basic.  I am not very good at analysis yet.
 A: Let $S$ be a closed subset of $\mathbb C$; we want $f:\mathbb C\to\mathbb C$  that is differentiable on $S$ only. If we don't require $f$ to be continuous, there is a cheap trick: let $f(z)=\operatorname{dist}(z,S)^2$ if $\operatorname{Re} z$ is rational and $f(z)=0$ otherwise. This function satisfies $f'(z)=0$ for all $z\in S$ and is not continuous (hence not differentiable) anywhere else. 
But the question is more interesting if we require $f$ to be nice in the real variable sense. 
Let $S$ be a closed subset of $\mathbb C$. It is well-known that there is a $C^\infty$ function $g:\mathbb C\to [0,\infty)$ such that $S=g^{-1}(0)$. Being real-valued, $g$ is complex-differentiable precisely on the set $\{\nabla g=0\}$. By construction this set contains $S$. It may contain other points, though, and I don't see an easy way to get rid of them. 
From here I give two constructions. 

Version 1. The aforementioned function $g$ can be taken to be bounded (either it is already bounded
by construction, or we change it to $g/(1+g)$). Multiply it by a smooth decaying weight such as $e^{-|z|^2}$. 
Let $h$ be this product. The Cauchy transform of $h$ is 
$$
f(z)= \frac{1}{\pi}\int_{\mathbb C}\frac{h(\zeta)}{z-\zeta} \,dA(\zeta) 
$$
where $dA$ indicates an integral with respect to area. Since this is a convolution with 
integrable kernel, $f$ is as smooth as $h$, that is infinitely smooth. And since the kernel of the Cauchy transform is the 
fundamental solution of the $\bar \partial$ operator, we have 
$$
\frac{\partial f}{\partial \bar z} = h 
$$
which means $f$ is complex differentiable precisely on the set $S$.
See Chapter 4 of this book for details of the Cauchy transform.

Version 2 uses heavier machinery of the Beltrami equation, see Chapter 5 of the same book. The equation 
$$f_{\bar z}=\frac{g}{2+g}f_z \tag{1}$$
is uniformly elliptic, and therefore its solutions are as smooth as the coefficient allows: namely, $C^\infty$ smooth. Moreover, (1) admits a solution $f$ that is a diffeomorphism of $\mathbb C$. For such a solution $f_{z}\ne 0$ everywhere, and therefore the set $\{z:f_{\bar z}= 0\}$ coincides with $\{z:g(z)=0\}$, which is $S$. 
