Is a hard thresholding operator generating a single vector a continuous function? A Hard thresholding operator $H_k:\mathbb{R}^n\rightarrow \mathbb{R}^n$ is defined as a vector-valued function that maintains the top-k entries of a given vector in an absolute value sense and zero out the rest. As an example $H_2(x)=[-5,0,-3,0]^{\top}$ where $x=[-5,2,-3,1]^{\top}$ and $k=2$. (In a case where two entries are equal we keep the value with smallest index or any other mechanism that make the output unique to have a function)
Question: Is $H_k$ described above a continuous function?
My try:
Given $H_k:\mathbb{R}^n\rightarrow \mathbb{R}^n$, we say that $H_k$ is continuous at $a$ if $H_k(a)$ exists and for all $\epsilon > 0$, there exists a $\delta > 0$ such that $||H_k(x)- H_k(a)||_2 < \epsilon$ whenever $||x-a||_2 < \delta$. Can we satisfy it?
 A: $H_k$ is not continuous at any point where a "tie-breaker" rule is needed to decide between some coordinates with equal non-zero absolute value. Essentially, arbitrarily small changes in the input vector can force a different tie-breaker decision, which is at roughly a fixed difference in the output vectors.
For one specific counterexample, $H_1: \mathbb{R}^2 \to \mathbb{R}^2$ is discontinuous at $(1,1)$. If $\epsilon=\frac{1}{2}$, and given any $\delta>0$, define
$$\begin{align*}
\delta' &= \min\left(\frac{1}{4}, \frac{\delta}{2}\right) \\
x_1 &= (1-\delta', 1) \\
x_2 &= (1, 1-\delta')
\end{align*} $$
Then we have $\|x_1-(1,1)\| = \delta' < \delta$, $\|x_2-(1,1)\|=\delta'<\delta$, $H_1(x_1)=(0,1)$, and $H_1(x_2)=(1,0)$. By the triangle inequality,
$$\|H_1(x_1)-H_1((1,1))\| + \|H_1(x_2)-H_1((1,1))\| \geq \|H_1(x_1)-H_1(x_2)\| = \sqrt{2}$$
so it is not possible that both $\|H_1(x_1)-H_1((1,1))\| < \epsilon = \frac{1}{2}$ and $\|H_1(x_2)-H_1((1,1))\| < \epsilon = \frac{1}{2}$; $H_1$ cannot be continuous there.
