Inverting Integer Numbers - Is There a Formula?

  • Context: High School 
  • Thread starter Thread starter FenixDragon
  • Start date Start date
  • Tags Tags
    Formula Integer Numbers
Click For Summary

Discussion Overview

The discussion centers around the concept of inverting integer numbers, specifically whether there exists a mathematical formula to reverse the digits of an integer. Participants explore various algorithms and functions related to this concept, touching on different bases and mathematical representations.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant inquires about a mathematical formula for inverting integers, expressing familiarity with existing algorithms but seeking a more formal mathematical representation.
  • Another participant proposes a function f(x) that represents the reversal of digits in base 10, suggesting that it is not well-defined without specifying the base.
  • Discussion includes the significance of base in determining the properties of reversible strings, with references to specific numbers and their relationships.
  • A participant introduces a symbolic formula for Rb(n), which aims to represent the number formed by reversing the digits of n in base b, while noting potential simplifications and limitations of the formula.
  • Concerns are raised regarding the applicability of the proposed formula, particularly for natural powers of the base, leading to further refinement of the formula's definition.

Areas of Agreement / Disagreement

Participants express differing views on the definition of a "formula" and the implications of base selection. There is no consensus on a singular formula or method, and the discussion remains unresolved regarding the best approach to represent the reversal of digits mathematically.

Contextual Notes

Participants highlight limitations in the proposed formulas, particularly concerning the treatment of natural powers of the base and the definition of the number of digits in various bases. These aspects remain points of contention without resolution.

FenixDragon
Messages
2
Reaction score
0
hi... I was thinking... is there any formula that inverts int numbers? like 21 transforms into 12... I have found an algorithm that do this... but I want to know if exists any formula to it... thx...
 
Mathematics news on Phys.org
I will assume that you know both the given number x and the number of digits in x, n.

integer function Reverse(integer x, y)
{
y= 0; //comment: we will add parts of the answer to y
for i=1 to n
{
k= x/10^{n-i};
//comment: this is computer "integer" arithmetic : 3/2= 1, not 1.5
//comment: mathematically, k= (x- (x mod 10^{n-i}))/10^{n-i}
//comment: if x= 251, for example, n= 3, i=1, 10^{n-1}= 10^2= 100
//comment: then k= 251/100= 2 or k= (251- (251 mod 100))/100= (251- 51)/100= 2
y=y+ k*10^{i-1}
x= x- k;
}
return y;
}

With x= 251, n= 1, the first time through the loop, i= 1, k= 251/10^(3-1)= 251/100= 2 so y= 0+ 2*10^0= 2, x= 251- 200. The second time through the loop, i= 2, x= 51 now, k= 51/10^(3-2)= 51/10= 5 so y= 2+ 5*10= 52, x= 51-50. The third and last time through the loop, i= 3, x= 1, k= 1/10^(3-3)= 1/1= 1 and y= 52+ 1*100= 152, 251 reversed.

If you are given only x, not the number of digits in x, then you can find it this way.

n= 0;
k= 1;
while x>= k do
{
n= n+1
k= k*10
}

For example, if x= 251 again, we first see that 251> 1 so n= 0+ 1= 1. k= 1*10= 10. Since 251> 10, n= 1+1= 2, k= 10*10= 100. Since 251> 100, n= 2+ 1= 3, k= 10*100= 1000. Since 251< 1000, the loop terminates with n= 3, the number of digits in 251.
 
Last edited by a moderator:
sorry... but isn't exactly what I wanted... I already know this algorithm... but I want to know if exists any math function that do this... thx...
 
Yes, here is the function:

f(x)= "x written in reverse order of its digits".

That is a function. Actually, we had better call this f_10, otherwise it is not a well defined function on the integers: it depends on the choice of base, so let f_n(x)="x written in reverse order of its digits in base n".

I suspect your conflating the notion of function with a method of evaluating that function on some given input.
 
The base is important of course, because the string of digits is defined by the base you count in.

In base 10, the numbers 11 and 9 are important for reversable strings, factors of 11 tend be palindromic provided each of the digits is no greater than the base n/2. The difference between two mirror strings can be factored by 3^3.

Thats about all i know.

21 - 12 = 9
42 - 24 = 18
31 - 13 = 18
321 - 123 = 198 = 2 * 99 = 2*11*9

Think about the repeating decimal 0.99999...
 
Yes, the age old problem of what do you mean by "formula"?


I'd stick with the base 2 version of this function. You can then just turn the page upside down, or look in a mirror.
 
3trQN said:
In base 10, the numbers 11 and 9 are important for reversable strings, factors of 11 tend be palindromic


The factors of 11 are 1 and 11 so they are all palindromic... (Yes, I know you meant multiple.)
 
oops, well spotted... :redface:
 
Would this work as a symbolic formula for Rb(n), giving the number formed by reversing the digits of n in base b, when n is an integer?

[tex]R_b(n) = \sum_{k=1}^{\left \lceil log_b n \right \rceil} \left \lfloor \frac{n-b^k\left \lfloor \frac{n}{b^k} \right \rfloor}{b^{k-1}} \right \rfloor b^{\left \lceil log_b n \right \rceil - k}[/tex]

Definitely could be simplified.
 
Last edited:
  • #10
gnomedt said:
Would this work as a symbolic formula for Rb(n), giving the number formed by reversing the digits of n in base b, when n is an integer?

[tex]R_b(n) = \sum_{k=1}^{\left \lceil log_b n \right \rceil} \left \lfloor \frac{n-b^k\left \lfloor \frac{n}{b^k} \right \rfloor}{b^{k-1}} \right \rfloor b^{\left \lceil log_b n \right \rceil - k}[/tex]

Definitely could be simplified.
Your formula fails whenever n=bm for any natural 'm'.*

*Hint: the number of digits of any [itex]n \in \mathbb{N}[/itex] in any base [itex]b \in \mathbb{N} - \left\{ {1} \right\}[/itex] is [itex]\left\lfloor {\log _b n} \right\rfloor + 1[/itex], not [itex]\left\lceil {\log _b n}\right\rceil[/itex]
(since you probably don't want to exclude natural powers of 'b' from your formula :wink:...)

---------------------------------------------------------
~Anyway, a simpler formula for Rb(n) is:

[tex]R_b (n) = \sum\limits_{i = 0}^{\left\lfloor {\log _b n} \right\rfloor } {\left( {\left\lfloor {\frac{n}{{b^i }}} \right\rfloor - b\left\lfloor {\frac{n}{{b^{i + 1} }}} \right\rfloor } \right)b^{\left\lfloor {\log _b n} \right\rfloor - i} }[/tex]
 
Last edited:

Similar threads

  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 20 ·
Replies
20
Views
4K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K