Piecewise analytic function Does there exist a smooth function $f : \mathbb{R} \to \mathbb{R}$ such that $f|_U = g|_U$ and $f|_{U^c} = h|_{U^c}$ for analytic functions $g \neq h : \mathbb{R} \to \mathbb{R}$ and an open set $U \subsetneq \mathbb{R}$? The answer is no if we ask for an analytic function $f$, since $f|_U = g|_U$ would imply $f = g$ and similarly $f = h$, leading to a contradiction $g = h$.
 A: Let's make the problem more symmetric in $g,h$:
Definition. A tuple $(f,g,h,U)$
is an example if $\emptyset\subsetneq U\subsetneq \Bbb R$ is open, $f\colon\Bbb R\to\Bbb R$ is smooth, $g,h\colon\Bbb R\to\Bbb R$ are analytic, $f|_U=g|_U$, and $f|_{U^\complement}= h|_{U^\complement}$.
Definition. A tuple $(f,g,h,U,V)$
is a superexample if $U,V\subseteq \Bbb R$ are open, $\overline U\cup \overline V=\Bbb R$, $\overline U\cap \overline V\ne\emptyset$, $f\colon\Bbb R\to\Bbb R$ is smooth, $g,h\colon\Bbb R\to\Bbb R$ are analytic, $f|_U=g|_U$, and $f|_V= h|_V$.
Let $(f,g,h,U)$ be an example. By continuity, $f|_{\overline U}=g|_{\overline U}$. Therefore, $(f,h,g,{\overline U}^\complement)$ is also an example.
Then $(f,g,h,U,{\overline U}^\complement)$ is a superexample (where $\overline U\cap \overline{{\overline U}^\complement}\ne\emptyset$ follows  because $\Bbb R$ is connected, i.e., the only clopen subsets of $\Bbb R$ are $\emptyset$ and $\Bbb R$).
If $(f,g,h,U,V)$ is a superexample, then so is $(f',g',h',U,V)$. 
If $(f,g,h,U,V)$ is a superexample, then for any fixed $a\in\overline U\cap \overline V$, we have $f(a)=g(a)=h(a)$ by continuity. By the preceding paragraph, also $f^{(n)}(a)=g^{(n)}(a)=h^{(n)}(a)$ for all $n$. As $g,h$ are analytic, this implies $g=h$. Then $f=g$ on the dense set $U\cup V$, and by continuity $f=g$, so $f$ is analytic.
