What formula will accept a real number as input and output its "reverse"?

83 Views Asked by At

We want to define the reverse of any real number $x$ to be $R(x)$ where $R(x) = \text{something}$


The reverse of $1$ is $0.1$
The reverse of $2$ is $0.2$
The reverse of $10$ is $0.01$ The reverse of $50$ is $0.05$
The reverse of $100$ is $0.001$
The reverse of $987654321$ is the decimal number $0.123456789$
The reverse of $123.456$ is the decimal number $654.321$
The reverse of $3.14159265358979325$ is the decimal number $52397985356295141.3$


What recursive formula might we use to describe $R$?


$\forall x \in \mathbb{R}$, if $10*x \in \mathbb{N}\cup \{0\}$ then $R(x) = 10^{-1}*\lfloor x \rfloor + 10*\begin{pmatrix} x - \lfloor x \rfloor \end{pmatrix}$

For example, if $x = 3.4$ then $R(3.4) = 10^{-1}*3 + 10^{+1}*4$

Let $f$ be a mapping from $\mathbb{R}$ to $\mathbb{R}$ such that $\forall x \in \mathbb{R}, f(x) = 10^{k}*\Bigl\lfloor\dfrac{x}{10^{k}}\Bigr\rfloor$

Maybe $f$ will be helpful.

if $x = 123.456$ and $k = 0$ then $10^{k}*\Bigl\lfloor\dfrac{x}{10^{k}}\Bigr\rfloor$ is $123$

if $x = 123.456$ and $k = 1$ then $10^{k}*\Bigl\lfloor\dfrac{x}{10^{k}}\Bigr\rfloor$ is $120$

if $x = 123.456$ and $k = 2$ then $10^{k}*\Bigl\lfloor\dfrac{x}{10^{k}}\Bigr\rfloor$ is $100$

1

There are 1 best solutions below

0
On

In general, it's not going to work. Most real numbers don't have terminating decimal expansions, and so when you reverse that you're going to get an infinite value. The set of numbers where it will work can be written as $\{M \times 10^N : M, N \in \mathbb{Z}\}$.

Once you've got that, it really is as simple as breaking the number into its digits and pasting them back together again, extending what you've already considered. I'm going to define a few handy functions just to keep the expression of our reversal function neat. First, the sign function:

$s(x) = \begin{cases} 1 & x > 0 \\ 0 & x = 0 \\ -1 & x < 0\end{cases}$

Second, a function to extract the units digit of a non-negative real number:

$d(x) = 10\lfloor \frac{x}{10} \rfloor - \lfloor x \rfloor$

Then we get:

$R(x) = s(x)\left( \sum_{n \in \mathbb{N}} 10^{-n-1} d(10^{-n} |x|) \right)$

and that's it. How does it work? We divide $|x|$ by $10^n$ and take the units digit of the result, which gives us the digit in the $10^n$ place of $x$. Then, we put it in the $10^{-n-1}$ position of our reversed number. And we multiply that by the sign of $x$ so that it stays on the same side of zero.