Counterexample to "Measurable in each variable separately implies measurable"

Some fellow classmates are preparing for a qualifying exam on real analysis, and asked me for help on the following question:

Let $ \ f:[0,1]^2\longrightarrow\mathbb{R}$ be such that:

(i) $\ f(x,\cdot)$ is measurable for each fixed $x\in[0,1]$;

(ii) $\ f(\cdot,y)$ is continuous for each fixed $y\in[0,1]$.

Show that $\ f$ is measurable. If we only assume that $\ f(\cdot,y)$ is measurable for each $y\in[0,1]$, rather than continuous, can we still conclude that $f$ is measurable?

I was able to come up with the following simple proof (at least I hope it is a proof) of the first statement using some standard arguments:

Proof. $ \ $ Define a sequence of functions $\{f_n:[0,1]^2\longrightarrow\mathbb{R}\}_{n\geq 1}$ by:

$$ f_n(x,y)=f\bigg(\frac{i}{n},y\bigg), \qquad \text{for } x\in\bigg[\frac{i}{n},\frac{i+1}{n}\bigg], \ i=1,\cdots,n $$

Moreover, since $ \ f(\cdot,y)$ is continuous at $x=\tfrac{i}{n}$ for each $y$, for each $\epsilon>0$ there is a $\delta_y>0$ so that

$$ \bigg| \ x-\frac{i}{n}\bigg|<\delta_y \qquad\Rightarrow\qquad \bigg| \ f(x,y)-f\bigg(\frac{i}{n},y\bigg)\bigg|<\epsilon; $$

therefore, for any $n>\tfrac{1}{\delta_y}$ and any fixed $(x,y)\in[0,1]^2$ with $x\in\big[\tfrac{i}{n},\tfrac{i+1}{n}\big]$, we have

$$ \bigg| \ x-\frac{i}{n}\bigg|\leq \frac{1}{n}<\delta_y $$

and so

$$ | \ f_n(x,y)-f(x,y)|=\bigg| \ f\bigg(\frac{i}{n},y\bigg)-f(x,y)\bigg|<\epsilon. \tag{$\ast$} $$

In other words, $ \ f_n\longrightarrow f$ pointwise. Furthermore, we clearly have that

$$ A_n:=\{(x,y)\in[0,1]^2 \ | \ f_n(x,y)>\alpha\} \qquad\qquad\qquad $$

$$ \qquad\qquad \ =\bigcup_{i=1}^{n-1}\bigg(\bigg[\frac{i}{n},\frac{i+1}{n}\bigg)\times \bigg\{y\in[0,1] \ \bigg| \ \ f\bigg(\frac{i}{n},y\bigg)>\alpha \bigg\}\bigg). $$

Since $ \ f\big(\tfrac{i}{n},\cdot\big)$ is measurable for each $i=1,\cdots,n$, the latter expression is a union of measurable sets. This means that $ \ A_n$ is measurable, and therefore $ \ f_n$ is measurable for each $n\geq 1$. Finally, as the limit of measurable functions is measurable, we conclude that $ \ f$ is measurable.

$\hspace{6.25in}\square$

I'm fairly certain that the above proof is correct (anyone care to confirm?); however, that still leaves the following:

Question: If $ \ f$ is merely measurable in each variable separately, is it measurable?

The proof I gave above uses the continuity assumption in $(\ast)$, so obviously the same proof will not work in this case, but I cannot come up with any counterexamples. Any suggestions?


If $f$ is merely measurable in each variable separately, is it measurable?

Not necessarily.

For a counterexample, fix some non measurable subset $E$ of $[0,1]$ and define $f(x,y)=0$ for every $(x,y)$ in $[0,1]\times[0,1]$ with the exception that $f(x,x)=1$ if $x$ is in $E$.

Then, for every $x$, either $f(x,\ )=0$ everywhere or $f(x,\ )=0$ everywhere except at $x$, hence $f(x,\ )$ is measurable. Likewise for $f(\ ,y)$, for every $y$ in $[0,1]$.

But, if $f$ was measurable, considering the measurable function $g:x\mapsto(x,x)$, one would get a measurable function $f\circ g$ on $[0,1]$. Since $f\circ g=\mathbf 1_E$ is not measurable, $f$ is not measurable.