The digit at position $n$ of the number $x$ in base $m$

193 Views Asked by At

As a solution to this question, we can define a function $f_b(x, n)$ which finds the digit in the $n$th position of $x$ in base $b$.

$$ f_b(x, n) = \left\lfloor \frac{x}{b^n} \right\rfloor \bmod b $$

It even works for decimals, for example:

e = 2 . 7  1  8  2  8  1  8  2  8 ...
    0  -1 -2 -3 -4 -5 -6 -7 -8 -9 th position

$$ f_{10}(e, -8) = 2 \quad \checkmark $$

However, when using a non-integer base, all the digits are fractional.

$$ f_\pi(e, [0,-1,-2,\dots]) = [2, 1.717, 0.867, 2.319, \dots] $$

For reference, Wolfram Alpha states that $e$ in base $\pi$ is actually 2.2021201002111...

Additionally, for negative bases, all the digits of $f$ are negative. Wolfram Alpha states that $e$ in base $-10$ is 3.3223222325590...

Furthermore, the function also screws up if $x_b$ is negative. So I am also looking for a function to have a way of differentiating positive and negative numbers (especially important in negative bases, since for example, 21 in decimal would be -39 in negadecimal).

My question is if there is a function which does this but is also valid even for non-integer and negative bases. I'm sure there would be, but I don't know what we need to modify such that this would happen. In other words, is there a function such that

$$ f_b\left(\sum_{k=-\infty}^\infty a_k b^k, n \right) = a_n \qquad b\in\mathbb{R} $$

?


I have since then found a recursive method for non-integer but not negative bases :

Start by calculating $A=\lfloor\log_b n\rfloor$, then

$$ U_1 = f_b(n, A) = \left\lfloor\frac{n}{b^A}\right\rfloor $$ $$ U_2 = f_b(n, A-1) = \left\lfloor\frac{n-U_1b^A}{b^{A-1}}\right\rfloor $$ $$ U_3 = f_b(n, A-2) = \left\lfloor\frac{n-U_1b^A-U_2b^{A-1}}{b^{A-2}}\right\rfloor $$

etc. The simple problem with this one is when it deals with a negative base, it returns negative digits.

1

There are 1 best solutions below

2
On

Hint: for starters, try to extract $a$, $b$, $c$ from $ \ a \pi^2 + b\pi +c \ $ or, more generally, the digits from $$ a_1/\pi + a_2/\pi^2 + a_3/\pi^3 + a_4/\pi^4 + a_5/\pi^5 + \cdots $$ The traditional mod function is not enough, because $$ a\pi^2 + b\pi +c \pmod {\pi} = a \pi^2 +c \neq c $$ since $a\pi^2$ isn't an (integer!) multiple of $\pi$.

Edit: Instead of $\!\bmod{\!\! }$, the function $\bmod{\!\! _b}$ that yields $$ \bmod_b \,\! : \ (A_k b^k + \cdots + A_2 b^2 + A_1 b + A_0) \mapsto A_0 $$ for any nonnegative integers $A_j \leq |b|$, seems to do the trick. But I have no definite formula for now. $% \mod\!\!\!_b: \ (A_k b^k + \cdots + A_2 b^2 + A_1 b + A_0) \mapsto A_0 $