This question is of course inspired by the question How to solve f(f(x))=cosx
and Joel David Hamkins' answer, which somehow gives a formal trick for solving equations of the form $f(f(x))=g(x)$ on a bounded interval. [EDIT: actually he can do rather better than this, solving the equation away from a bounded interval (with positive measure)].

I've always found such questions ("solve $f(f(x))=g(x)$") rather vague because I always suspect that solutions are highly non-unique, but here are two precise questions which presumably are both very well-known:

Q1) Say $g:\mathbf{R}\to\mathbf{R}$ is an arbitrary function. Is there always a function $f:\mathbf{R}\to\mathbf{R}$ such that $f(f(x))=g(x)$ for all $x\in\mathbf{R}$?

Q2) If $g$ is as above but also assumed continuous, is there always a continuous $f$ as above?

The reason I'm asking is that these questions are surely standard, and perhaps even easy, but I feel like I know essentially nothing about them. Apologies in advance if there is a well-known counterexample to everything. Of course Q1 has nothing to do with the real numbers; there is a version of Q1 for every cardinal and it's really a question in combinatorics.

EDIT: Sergei Ivanov has answered both of these questions, and Gabriel Benamy has raised another, which I shall append to this one because I only asked it under an hour ago:

Q3) if $g$ is now a continuous function $\mathbf{C}\to\mathbf{C}$, is there always continuous $f$ with $f(f(x))=g(x)$ for all $x\in\mathbf{C}$?

EDIT: in the comments under his answer Sergei does this one too, and even gives an example of a continuous $g$ for which no $f$, continuous or not, can exist.

@Gabriel: in some sense I suspect that the whole point of Q1 is that you aren't meant to think of a function satisfying Q1, you're just supposed to give some stupid abstract construction, possibly starting with "let's well-order the reals" or "let's define an equivalence relation on the reals like this, and then let's now choose a bijection between R and R disjoint union R and get a new induced equivalence relation and blah blah blah". That was how I was envisaging a solution to Q1 going. As for Q2 I was sort-of expecting a classical counterexample.
–
Kevin BuzzardMar 9 '10 at 16:39

1

Given a set $E$ and a function $g \colon E \to E$, does there exist $f$ with $f(f(x)) = g(x)$? (No topology, no continuity.) To answer this for a particular $g$, examine the Ulm invariants of $g$.
–
Gerald EdgarMar 9 '10 at 17:58

1

Kevin, my trick actually works off a measure zero set, if you use a Cantor set instead of an interval. That is, for every function g on the reals, there is a function f:R to R, such that f(f(x)) = g(x) for almost all x, that is, for all x except in a measure zero set.
–
Joel David HamkinsMar 9 '10 at 18:49

1

Anonymous, in the tiny interval version, the function f is fully continuous, if g is continuous. In the measure 0 version, my function f is mapping R-I into the Cantor set I, and such a function cannot be continuous (since I is totally disconnected), but it is almost-everywhere continuous.
–
Joel David HamkinsMar 11 '10 at 2:05

A counter-example for C: let g be a quadratic polynomial such that $g(z)-z$ has distinct roots, e.g. $g(z)=z^2$. Then there are four solutions of $g(g(z))=z$: two roots of g and two points a,b such that g(a)=b and g(b)=a. But if g(z)=f(f(z)), then the point z=f(a) must be another solution to g(g(z))=z. This works for non-continuous f as well.
–
Sergei IvanovMar 9 '10 at 17:43

3

I had just logged on to this site to edit my quetsion and add Q4: what about g:C-->C continuous but no restriction on f, and I see you've answered it before I even asked it! Talk about efficient ;-) Thanks for your most excellent answers Sergei.
–
Kevin BuzzardMar 9 '10 at 18:40

Problem 6 of the Vietnam Team Selection Test (for the IMO) of 1985 states: Suppose a function $f: \mathbb R\to \mathbb R$ satisfies $f(f(x)) = - x$ for all $x\in \mathbb R$. Prove that $f$ has infinitely many points of discontinuity. Check the following link for the whole test if you're curious: mathlinks.ro/…
–
AnonymousMar 9 '10 at 16:58

Thanks Ady. Sorry---I accepted Sergei's answer because he did the first part too, but you get +1. Note that I added a Q3 now! And now $g(x)=-x$ doesn't work because $f(x)=ix$ is allowed.
–
Kevin BuzzardMar 9 '10 at 17:08

1

Passing remark: continuity is "not on the syllabus" at the IMO and so we never mention its definition to the British team during training.
–
Kevin BuzzardMar 9 '10 at 21:54

1

That's a surprise, since real analysis is part of the high school curriculum in many countries. On the other hand, the restriction on the syllabus seems to reflect on the facts that many of the recent IMO problems are rather puzzle-like, which is quite depressing.
–
AnonymousMar 9 '10 at 22:28

Surely someone still knows this? Given $f \colon A \to A$
and $g \colon B \to B$, is there a bijection $\phi \colon B \to A$
such that $f(\phi(x))=\phi(g(x))$? There is a system
of cardinal numbers, the Ulm invariants, associated with
$f$ so that the answer is ``yes'' if and only if $f$ and $g$
have the same invariants.

If $f$ is bijective, then the Ulm invariants are just counts of
how many cycles of each size there are (including the
infinite cycle size modeled by the integers with $n \mapsto n+1$).

But when not bijective, the system of invariants is more
complicated. You need to count how many points map to each
fixed point, and how many points map to each of them, and so on.
And similarly for cycles of other sizes. But I cannot tell you
the details, and this box is probably not the right place to do
it anyway.

So for a solution to the problem, consider what the Ulm invariants of $f(f(x))$ are
in terms of those of $f$. Then compare to the Ulm inveriants of $\cos$. Or whatever you
want to get.

Ulm himself may have originally done this to study isomorphism of
abelian groups. Taking products, reduce to the case of
a $p$-group for a given prime $p$, then your map for study is
$x \mapsto x^p$. Or something like that. Ulm invariants
may also be given to characterize up to isomorphism linear
transformations (on possibly infinite-dimensional vector space).

Thanks Gerald. So, because I knew your comment was visibly of some value, I tried to find out about Ulm invariants, knowing only that (a) they were called Ulm invariants and (b) they would no doubt be something to do with describing invariants of orbits under iterates of f, and how they meet. Wikipedia gave me nothing. Google gave me that there are Ulm invariants of an abelian group measuring sizes of a certain filtration, but nothing about sets. I then gave in and asked the question in a thread somewhere on this site, hoping you'd spot it :-) Thanks!
–
Kevin BuzzardMar 11 '10 at 15:28

Gerald: So if you construct the directed graph G with vertex set A and an arrow from a to b iff f(a) = b, then the "Ulm rank" of a point a in A must be something like the (ordinal-valued) foundation rank of a in this graph? Probably we should first collapse any finite cycles in the graph G before computing this rank to make it interesting. And Ulm invariants must have something to do with counting the number of points in this graph with Ulm rank alpha (for various values of alpha)? This could be interesting...
–
John GoodrickMar 11 '10 at 16:35

1

Ulm references ... $$ $$ > H. Ulm, Elementarteilertheorie unendlicher Matrizen, Math. Ann. 114 (1937) 483--505 $$ $$ > I. Kaplansky, Infinite Abelian Groups $$ $$ Ulm originally studied a linear transformation on an arbitrary vector space (strictly an algebraic question, no topology). $$ $$ Kaplansky extracts the useful part for classifying abelian groups. $$ $$ And both of these are more complicated than the case of a map of a set to itself. So hasn't that special case been written down somewhere?
–
Gerald EdgarNov 3 '10 at 17:52

I don't have a full answer, but I can offer here a small improvement on my other answer.
Namely, what was important was not that it worked on a bounded interval, but rather, that it works outside a bounded interval.

Theorem. For any function g on the reals, there are
numerous functions f such that f(f(x)) = g(x), for all x
except those in a given fixed tiny interval.

Proof. Suppose g is a function on the reals and that I is a given interval, no matter how small. Let h be a bijection of R - I with I. Let f(x) = h(x), if x is outside I,
and f(x) = g(h-1(x)), if x is in I. Thus, f
first translates x into I, if it is outside I, and
otherwise, untranslates and computes g, if it is in I. It
follows that f(f(x)) = g(x) for all x outside I. There are
2|R| many such h's, and hence also this many
f's.QED

If g is continuous, then this f can be chosen also to be continuous.

By using a Cantor set instead of an interval, one can find a function f that solves f(f(x)) = g(x) except on a set of measure zero.

This type of equation is an "iterative functional equation." A good starting point for the literature on this subject is the book Iterative Functional Equations by Kuczma, Choczewski, and Ger, Cambridge University Press, 1990.

This is a repost, and partial rewrite of an earlier deleted answer by Anixx. If you want to discuss the wisdom of that deletion, take it to the meta thread; let's keep this post focused on math only. This answer is community wiki, so that others can improve it.

If $a_k$ is any sequence of real numbers, indexed by the nonnegative integers, then define $\Delta^m(a) = \sum_{k=0}^{m} (-1)^k \binom{m}{k} a_k$. Then, for integer $n$, we have $a_n = \sum_{m=0}^{\infty} \binom{n}{m} \Delta^m(a)$. Note that the sum is finite, because all but finitely many binomial coefficients vanish. One can then try defining
$$A(x) = \sum_{m=0}^{\infty} \binom{x}{m} \Delta^m(a).$$
If this sum converges, it defines a function $A$ which interpolates $a_n$. This is sometimes called Newton's interpolation formula.

Anixx points out that, $a_n = \sin^{[n]}(x)$ this method appears to give a good answer, but for $\cos^{[n]}(x)$, it appears not to.

What does "appears to" mean here? Are we talking small error? Pointwise convergence in small intervals?
–
Andres CaicedoNov 3 '10 at 16:26

2

In my case, I mean that numerical data which Anixx presented, without stating how many terms he was using or precisely what he computed, appear to my naked eye to be converging to a solution in a fairly large interval around $0$.
–
David SpeyerNov 3 '10 at 16:29

I could have sworn that there was an old Monthly article that discussed precisely this question in some detail, but the closest that I could find in a few minutes on Mathscinet is the following article addressing the case $g(x) = 1/x$:

A variant of the question is: Suppose that $g$ is a diffeomorphism. Can you embed $g$ into a flow? If yes, then there is $f$ with $f\circ f\circ\dots\circ f=g$ ($n$ times for any $n$).

So let $Diff_c(M)$ be the regular Lie group of all diffeomorphisms of a smooth manifold $M$.
Its Lie algebra is the space $\mathfrak X_c(M)$ of all smooth vector fields with compact support, with the negative of the usual Lie bracket. The exponential mapping is the flow mapping which maps a vector field $X$ to its flow $t\mapsto Fl^X_t\in Diff_c(M)$.
It satisfies $T_0\exp = Id$ but:

It is not locally surjective near $Id_M$. This has been shown by Freifeld 1967 and by Koppell 1970. The strongest result is by Grabowski, 1988, who showed the following:
Suppose that $\dim M\ge 2$. Then there exists a smooth curve through $Id$ in $Diff_c(M)$ such that the points of this curve (sauf the identity) are free generators for a free subgroup of $Diff_c(M)$ (on $2^{\aleph_0}$ generators) which meets the image of the exponential mapping only at the identity. This free subgroup is arcwise connected.

The following is inspired by the chapter Partition Polynomials in Riordan's Combinatorial Identities where $g(x)$ is analytic and $g(0)=0$. Find the Taylor series of $f(x)$ at zero by evaluating the derivatives of $f(f(x))=g(x)$ at $0$ in succession.

Set $f(0)=0$, giving $f(f(0))=g(0)=0$.

The first derivative gives $f'(x) f'(f(x))=g'(x)$, therefore $f'(0)=\sqrt{g'(0)}$ and $f'(0)=-\sqrt{g'(0)}$. Set $f'(0)=\sqrt{g'(0)}$ for this example.

This solution is based on $g(x)$ having a fixed point. Technically the question stated is whether there is always a solution and is focused on counter examples instead of a broad general answer as I have provided. But it does raise the question of whether there is a connection between $g(x)$ not having a fixed point and the counter examples that the other authors have provided.