TITLE: Why is the relation "$f=g $ almost everywhere" transitive?
QUESTION [7 upvotes]: In Rudin's Real and Complex Analysis, it says on pg 27 that
If $\mu$ be a measure, define $f\sim g$ iff $\mu(\{x|f(x)≠g(x)\})=0$, where $f,g$ are measurable functions from $X$ to a topological space $Y$.
Then, $f\sim g$ is an equivalence relation.
But, I do not see why $f\sim g$ is transitive. 
If I assume $f\sim g$ and $g\sim h$, then by definition, $\{x|f(x)≠g(x)\}$ and $\{x|g(x)≠h(x)\}$ are measurable sets with measure zero.
But then, how do I know that the set $\{x|f(x)≠h(x)\} \subset \{x|f(x)≠g(x)\} \cup  \{x|g(x)≠h(x)\} $ is measurable?
Here $Y$ is a topological space, not necessarily $R$ or extended reals.

REPLY [2 votes]: So here is our example.  As noted in the other answers, we need $\mathfrak M$ not complete, and $Y$ not metrizable.
Let $X = \mathbb R$, $\mathfrak M =$ Borel sets, $\mu =$ Lebesgue measure.
Let $Y = \mathbb R$, indiscrete topology.  The only open sets are $\varnothing, \mathbb R$.  
Because $Y$ is indiscrete, every function $f \;:\; X \to Y$ is measurable.
Let $N \subseteq X$ be the Cantor set, a Borel null set;
and let $K \subseteq N$ be non-measurable.  There are $2^{\mathfrak c}$ subsets of $N$, but only $\mathfrak c$ Borel sets, so certainly there is
such a set $K$.  Now define
$$
f(x) = \begin{cases}0,\qquad x \in K
\\0,\qquad x \in N - K
\\0,\qquad x \in \mathbb R - N\end{cases}
\\
g(x) = \begin{cases}1,\qquad x \in K
\\1,\qquad x \in N - K
\\0,\qquad x \in \mathbb R - N\end{cases}
\\
h(x) = \begin{cases}0,\qquad x \in K
\\2,\qquad x \in N - K
\\0,\qquad x \in \mathbb R - N\end{cases}
$$
Then:
$f=g$ a.e. since $\{x \mid f(x) \ne g(x)\} = N$ is a measurable null set.
$g=h$ a.e. since $\{x \mid g(x) \ne h(x)\} = N$ is a measurable null set.
But not $f=h$ a.e., since $\{x \mid f(x) \ne h(x)\} = K$ is not measurable.