# Examples of non-continuous, non-piecewise-constant, idempotent map?

So a projection $$P$$ is a linear map such that $$P^2 = P$$. If we don't require linearity, then there are other examples of functions $$f$$ such that $$f^2 = f$$. For example, the floor and ceiling functions. If $$f: \mathbb{R} \to \mathbb{R}$$ and we require continuity, it seems that the image is a closed interval and $$f(x)=x$$ for all $$x$$ in the image.

I'm wondering if there are any examples of idempotent maps that are not continuous but also not piecewise constant?

How about \begin{align} f(x)=\begin{cases} 0 &\text{if x\in\mathbb{Q}}\,, \\ x &\text{otherwise}\,. \end{cases} \end{align} I'm trying to think of an injective example.

Edit: The only injective function of this kind is $$f(x)=x$$. If $$f$$ is injective and $$f(x)=y\neq x$$, then $$f(y)=y$$ but $$f(y)\neq f(x)$$, a contradiction.

• How about if we extend "piecewise constant" to allow for infinitely many pieces? Or rather, we allow for removable discontinuities. Do you have an idea what examples we may have then? – twosigma May 20 at 5:03
• @twosigma Any function that is identity on its image does the trick, so you can choose whatever image you want, and let $f$ map other points into arbitrary points in its image. – Qiyu Wen May 20 at 5:08

Pick an arbitrary $$A \subset \mathbb R$$. Pick an arbitrary function $$g :\mathbb R \backslash A \to A$$.

Define f(x)= \begin{align} \begin{cases} x &\text{if x\in A}\,, \\ g(x) &\text{otherwise}\,. \end{cases} \end{align}

Then $$f \circ f=f$$.

Conversely, if $$f \circ f=f$$ then $$A= f(\mathbb R)$$ together with $$g(x)=f(x) \forall x \notin A$$ produce $$f$$.

• Worth pointing out explicitly: this answer lists all of the idempotent functions from a set to itself. – Milo Brandt May 20 at 23:24

This a “frame challenge” answer — it seems the restrictions in the question are partly motivated by a misconception, and so this doesn’t answer the question as written, but may give another answer to its original motivation. The question says “If $$f : \newcommand{\R}{\mathbb{R}}\R \to \R$$ and we require continuity, it seems that we basically get the identity function”, and it seems this is the motivation for including “non-continuous” in the question.

However, continuous idempotents don’t really have to be close to the identity function, except to the same extent that all idempotents do. The question links the claim to a nice answer which shows that:

1. If $$f:\R \to \R$$ is continuous and idempotent then $$I=f(\R)$$ is a closed interval and $$f(x)=x$$ for all $$x\in I$$.
2. If $$f$$ is also differentiable and nonconstant, then $$I=\R$$, i.e., $$f(x)=x$$ for all $$x\in\mathbb R$$.

which is true, but a little misleading — regrouping makes the dependency of the conditions clearer:

1. Any idempotent map $$f$$ on any set $$X$$ acts as the identity on its image $$f(X) \subseteq X$$.
2. The image of any continuous idempotent $$f:\R \to \R$$ is a closed interval.
3. The image of any differentiable idempotent $$f:\R \to \R$$ is either a point (i.e. $$f$$ is constant), or the whole of $$\R$$ (in which case by (1), $$f$$ is the identity function).

That is, all idempotents are somewhat like the identity; and non-constant differentiable idempotents are precisely the identity; but continuity doesn’t force the idempotent to be any more identity-like than it already had to be. So if the original motivation was partly just “interesting, non-trivial examples of idempotents”, then there’s no need to exclude continuous ones.

A nice intuitive continuous example is the “absolute value” function, $$x \mapsto \left|x\right|$$.

Another nice one is the function $$x \mapsto \left\{ \begin{array}{lr}x & -1 \leq x \leq 1 \\ \frac{1}{x} & \text{otherwise}\end{array}\right.$$

N.S.’s answer gives a general explanation: an idempotent function on $$\mathbb{R}$$ can have an arbitrary subset $$S$$ of $$\mathbb{R}$$ as its image (and on $$S$$ it must act as the identity), and then on the rest of $$\mathbb{R}$$, it can be an arbitrary function $$\mathbb{R} \setminus S \to S$$. So for continuous examples, take $$S$$ to be any closed interval, and then $$f$$ on $$\R \setminus S$$ (which must be the union of 0, 1, or 2 half-infinite open intervals) can be any continuous function into $$S$$ that fixes the endpoints of $$S$$.

• But the absolute value function is continuous, so it doesn't fit the criteria, does it? – Tanner Swett May 20 at 14:34
• Ah, I missed that the title includes “non-continuous”. What I meant to address was how in the body, the request for continuity was motivated by “if we require continuity, it seems that we basically get the identity function”, which is not at all true. I’ll edit my answer to address this more explicitly. – Peter LeFanu Lumsdaine May 20 at 14:39
• Nice examples! Yeah I shouldn't have phrased it in a way that suggested continuity will "basically" give us the identity function. I'll edit this – twosigma May 20 at 15:47
• (@PeterLeFanuLumsdaine, thank you for correcting my mixed-up answer so quickly! I've deleted it, so I'm not sure if you can read my thanks in the comments there.) – Vectornaut May 21 at 13:36