Does $H_0^1(\Omega)$ embed into $H_0^1(R^d)$? Given a domain $\Omega$ in $\mathbb{R}^d$ and a function $f\in H_0^1(\Omega)$, the closure of the test functions on $\Omega$, does the extension of f by 0 to all of $\mathbb{R}^d$ necessarily lie in $H_0^1(\mathbb{R}^d)$?
 A: Yes. The big picture is that for we can glue two $H^1$-functions together using continuity. 
Say let the extension be:
$$
\widetilde{f}(x) = \begin{cases}
f(x) & \text{ for } x\in \Omega,
\\[2mm] 
0 &\text{ for } x\in \mathbb{R}^d\backslash\Omega.
\end{cases}
$$
Apparently $\widetilde{f}\in L^2(\mathbb{R}^d)$. Now we want to find $\nabla \widetilde{f} = \big(\frac{\partial \widetilde{f}}{\partial x_i}\big)$, we don't know if this thing agrees with the weak derivative of $f$ in $\Omega$, and is 0 outside $\Omega$. We have to use the definition of the weak derivative:
$$
\int_{\mathbb{R}^d} \frac{\partial \widetilde{f}}{\partial x_i} \phi  = -\int_{\mathbb{R}^d} \widetilde{f}\frac{\partial\phi }{\partial x_i}  \quad \text{for any }\phi\in C^{\infty}_c(\mathbb{R}^d),
$$
now because of the integrability we can split the right hand side into two parts:
$$
-\int_{\mathbb{R}^d} \widetilde{f}\frac{\partial\phi }{\partial x_i} = -\int_{\Omega} \widetilde{f}\frac{\partial\phi }{\partial x_i} -\int_{\mathbb{R}^d\backslash\Omega} \widetilde{f}\frac{\partial\phi }{\partial x_i}
= -\int_{\Omega} f\frac{\partial\phi }{\partial x_i}.
$$
Then use boundary condition of $f$:
$$
-\int_{\Omega} f\frac{\partial\phi }{\partial x_i} = \int_{\Omega} \frac{\partial f}{\partial x_i}\phi  - \int_{\partial\Omega} f\phi \nu_{x_i}\,dS = \int_{\Omega}  \frac{\partial f}{\partial x_i}\phi.
$$
Thus we have:
$$
\int_{\mathbb{R}^d} \frac{\partial \widetilde{f}}{\partial x_i} \phi  = \int_{\Omega}  \frac{\partial f}{\partial x_i}\phi \quad \text{for any }\phi\in C^{\infty}_c(\mathbb{R}^d),
$$
and this tells us that
$$
\nabla \widetilde{f}(x) = \begin{cases}
\nabla f(x) & \text{ for } x\in \Omega,
\\[2mm] 
0 &\text{ for } x\in \mathbb{R}^d\backslash\Omega.
\end{cases}
$$
Now since $\nabla f\in L^2(\Omega)$, $\nabla \widetilde{f}\in L^2(\mathbb{R}^d)$. The extension is valid.  
