I have a function $f$ that is continuous over the set of variables, $f: \ K \times M \to \mathbb{R}$, where $K$ is a compact domain of a metric space and $M$ is a metric space. And I want to prove that the function $g(y)=\sup_{x\in K} f(x,y)$ is continuous.
As $K$ is a compact, $f$ is uniformly continuous with respect to its first argument. Also, for the same reason, $g(y)=\sup_{x\in K} f(x,y)=\max_{x\in K} f(x,y)$.
For now, I know that for the case of $f$ is continuous with respect of each variable separately, this doesn't work (see an example here Is supremum over a compact domain of separately continuous function continuous?) and there is a proof for the case when $M$ is also a compact, or $f$ is just uniformly continuous on $M$, too (How prove this $g(x)=\sup{\{f(x,y)|0\le y\le 1\}}$ is continuous on $[0,1]$), which I personally doubt as there is no guatantee that y-s will be close there (in my notations they are x-s).
All my tries fail when I come to the point where I need to say something about argmaxes of even close y-s. For example:
I consider a sequence $y_n \to y_0$ with $n\to\infty$. For each $y_n$ there exists $x_n$ such that $g(y_n)=\max_{x\in K} f(x,y_n)=f(x_n,y_n).$ Then, I try to estimate the difference $$|g(y_{n+k})-g(y_n)|=|f(x_{n+k},y_{n+k})-f(x_n,y_n)|=|f(x_{n+k},y_{n+k})-f(x_{n+k},y_{n})+f(x_{n+k},y_{n})-f(x_n,y_n)|\le|f(x_{n+k},y_{n+k})-f(x_{n+k},y_{n})|+|f(x_{n+k},y_{n})-f(x_n,y_n)|.$$ One can easily see that the first component tends to zero with $k\to\infty$, but I have no idea what to do with the second one...
Any help would be very appreciated!
Consider a sequence $(y_n)_{n\in\mathbb{N}}$ in $M$ that converges to some $y \in M$. We will show that
Step 1. We first show that $\liminf_{n\to\infty} g(y_n) \geq g(y)$.
This is an immediate consequence of the general fact that the supremum of a family of lower-semicontinuous functions is again lower-semicontinuous. (In particular, this fact does not require any structure on $K$.) Nevertheless, we write out the proof for self-containedness.
Let $\alpha$ be an arbitrary real satisfying $\alpha < g(y)$. Then there exists $x \in K$ such that $f(x, y) > \alpha$. So by the continuity of $f$, there exists $\delta > 0$ such that $f(x, y') > \alpha$ whenever $d(y', y) < \delta$. This then implies that
$$ g(y_n) \geq f(x, y_n) > \alpha \qquad \text{whenever } d(y_n, y) < \delta, $$
and so, we have $\liminf_{n\to\infty} g(y_n) \geq \alpha$. Since this is true for any $\alpha < g(y)$, the desired assertion follows by letting $\alpha \uparrow g(y)$.
Step 2. Next, we show that $\limsup_{n\to\infty} g(y_n) \leq g(y)$.
Indeed, for each $n$, use the compactness of $K$ to choose $x_n \in K$ so that $f(x_n, y_n) = g(y_n)$. Also,
find a subsequence $I \subseteq \mathbb{N}$ so that $(g(y_n))_{n\in I} \to \limsup_{n\to\infty} g(y_n)$, and then
find a further subsequence $J \subseteq I$ such that $(x_n)_{n\in J} \to x $ for some $x \in K$. This is possible by the sequential compactness of $K$.
Then
$$ \limsup_{n\to\infty} g(y_n) = \lim_{J \ni n \to \infty} g(y_n) = \lim_{J \ni n \to \infty} f(x_n, y_n) = f(x, y) \leq g(y). $$
Conclusion. Combining step 1 and 2, the desired claim follows. $\square$
Discussion. The above proof works whenever $K$ is both compact and sequentially compact. When $K$ is a compact metric space, sequential compactness comes for free. I am not sure if we can come up with a proof that does not rely on sequential compactness.