Solution (source code)

= Solution

Assume that $f(x)=0$ wherever $h(x)=0$ on the part of the space relevant to $g$. The <importance sampling> algorithm draws <independent and identically distributed random variables> $Y_1,\ldots,Y_m$ from $h$, forms the weights
$$
w(Y_i)=\frac{f(Y_i)}{h(Y_i)},
$$
and returns
$$
\widehat\mu_m=\frac1m\sum_{i=1}^m g(Y_i)w(Y_i).
$$
A <change of measure> gives
$$
\mathbb E_h[g(Y)w(Y)]
=\int_{\mathcal X}g(y)\frac{f(y)}{h(y)}h(y)\,dy
=\mathbb E_f[g(X)].
$$
\b[Hence the estimator is unbiased whenever the expectation exists, and, if $\mathbb E_h|g(Y)w(Y)|<\infty$, the <strong law of large numbers> gives $\widehat\mu_m\to\mathbb E_f[g(X)]$ almost surely.]