Is there a function that gives the same result for a number and its reciprocal?

Is there a (non-piecewise, non-trivial) function where $f(x) = f(\frac{1}{x})$?

Why?

It would be nice to compare ratios without worrying about the ordering of numerator and denominator. For example, I might want to know whether the "magnitude" of the ratio (maybe the "absolute ratio") of the widths of two objects is greater than $2$, but not care which is larger.

It occurred to me that there's a common solution for this problem when comparing the difference of two numbers: the square of a number is the same as the square of its opposite - $(a-b)^2=(b-a)^2$. This is really useful with Euclidean distances, because you don't have to worry about the order of subtraction or use absolute values. Can we get the same elegance for ratios?

Difference: $g(a-b)=g(b-a) \rightarrow g(x)=x^2$

Ratio: $f(\frac{a}{b})=f(\frac{b}{a}) \rightarrow f(x)=\ ?$


Solution 1:

$$ \frac{x}{x^2+1} $$ the inverse of Will Jagy's $x + \frac{1}{x}$.

I like $$x - \frac{1}{x} = \frac{x^2-1}{x}$$ because it contains sign information (input magnitude greater or less than one) that you may choose to ignore, and gives a nice zero for $x = \frac{1}{x} = \pm 1$. If you choose to take the absolute value of it (ignoring the sign) it gives you the desired $f(x) = f(\frac{1}{x})$

Solution 2:

For lack of a better idea, $f(x)=|\ln x|$.

Solution 3:

$$ \frac{1}{1 + x + \frac{1}{x}} = \frac{x}{x^2 + x + 1} $$ extends to the real analytic function written on the right. Notice that $x^2 + x + 1 = (x + \frac{1}{2})^2 + \frac{3}{4} \geq \frac{3}{4}. $

Solution 4:

For lack of anything worse than this, $f(x)=(x - \frac{1}{x})^2$.

Solution 5:

Let $f(x)$ be arbitrary for $-1\leqslant x\leqslant 1,$ and define $f(x):=f(1/x)$ otherwise.