If $A\subseteq\mathbb R^n$ is compact and $f:A\rightarrow\mathbb R^m$ is continuous, then $z\mapsto d(f^{-1}(y),f^{-1}(z))$ is continuous I am working on a hard measure theory problem on which I'm stuck. I can solve it if I prove the following: let $A\subseteq\mathbb R^n$ a compact set, and let $f:A\rightarrow\mathbb R^m$ a continuous function. Then the map
$$f(A)\rightarrow[0,\infty),\quad z\mapsto d(f^{-1}(y),f^{-1}(z))$$
for some fixed $y\in f(A)$ is continuous.
Just to make some things clear; let's recall that a closed subset of a compact set is again compact, so for each $z\in f(A)\subset\mathbb R^m$, $f^{-1}(z)$ will be compact on $A$, and hence on $\mathbb R^n$. Let's also recall that we can define the distance between two compact subsets $K$ and $L$ of $\mathbb R^n$ as
$$d(K,L)=\text{inf}_{(k,l)\in K\times L}|k-l|$$
I am really stuck at this point. I want to write my function as a composition of continuous functions to conclude the result, but that seems out of my reach at this point.
By the way, it may be posible that we require $f$ to be Lipschitz so that all this works out. I don't know if that hypothesis is needed (apparently it isn't), but I can use it freely.
Thanks in advance for your answers.
 A: Here is an example. Take $n=2, m=1$, $A$ is the union of the unit segment $[-1,0]$ in the $x$-axis and the 2-point set $\{(0,1), (1,1)\}$. The map $f$ is the coordinate projection to the $x$-axis; $y:=1$. The discontinuity is at $z_0=0$. Then $f^{-1}(y)=\{(1,1)\}$. Take the sequence $z_i= -1/i$. Then your function $g(z_i)= d(f^{-1}(-1/i), (1,1))$ has the limit $\sqrt{2}$ as $i\to\infty$. At the same time, $g(0)= d(f^{-1}(0), f^{-1}(1))=1$.
What is true is that in general your function is lower semicontinuous.
A: Let's call your function $g$.
Take $A = [0,1] \cup \{3,4\}$ with $f(x) = x$ for $0 \le x \le 1$, $f(3) = 2$, $f(4) = 1$.  Thus $f^{-1}(z) = z$ for $0 \le z < 1$, $f^{-1}(1) = \{1,4\}$, and $f^{-1}(2) = \{3\}$.  With $y = 2$ we have $g(z) = 3-z$ for $0 \le z < 1$, but $g(1) = 1$, so $g$ is not continuous.
A: The answer is no. For instance, take
$A=[-2,2]$ and $f:A\to\mathbb{R}$ given by
$$f(x)=2x+|x-1|-|x+1|$$
and fix $y=-1\in f(A)=A$. We can see that $$f^{-1}(z)=\left\{ \begin{matrix} \{\frac z 2-1\}& \text{ if } z<0\\ [-1,1] & \text{ if } z=0 \\ \{\frac z 2+1\}& \text{ if } z>0 \end{matrix} \right.$$
so that the function
$$ z\mapsto d(f^{-1}(y),f^{-1}(z))= \left\{ \begin{matrix} \frac12|z+1|& \text{ if }z\leq 0\\ \frac12|z+5| & \text{ if }z>0 \end{matrix} \right.  $$
is not continuous at $z=0$.
