Re: [math-fun] Turning a fraction into an integer
If you can encode a *sequence* of integers, you can encode the continued fraction of the rational number. There are a number(!) of ways to encode sequences of integers in the binary bitstring of an integer. https://en.wikipedia.org/wiki/Gödel_numbering_for_sequences At 10:30 AM 11/19/2015, Eric Angelini wrote:
Hello Math-Funsters,
I was looking for a way to represent any fraction with one single integer. Do you know if there is a common way to do that or a paper about it? I came up with this (heavy?) idea: concatenate N and D and encode the place of the slash "/".
So, the fraction we want to represent is N/D. We build the integer NDBA with four concatenated strings of digits. Starting from the right:
A is a single digit B is a string that has length A (if A=0 then A=10) D is the denominator of the fraction N/D N is the numerator of the fraction N/D
To reconstruct the fraction N/D from NDBA we:
- read A - compute the length of B - read B - insert the symbol "/" after B digits, starting the count from the leftmost digit of NDBA - erase A and B
Examples:
The fraction 1/2 --> 1211 [or 12.1.1 --> 1/2] The fraction 113/355 --> 11335531 [113/355.3.1] The fraction 2015/1234567890 --> 2015123456789041 [2015/1234567890.4.1] The fraction 1234567890/888 --> 1234567890888102 [1234567890888.10.2] etc.
This system works for N having less than 10 billion digits, of course -- which seems ok in our everyday life (we would have an integer like ND.9999999999.0 with ten 9's)
Best, Ã.
P.-S. Many integers will not represent any fraction -- but this is another story (10211 would produce the fraction 1/02, for instance).
participants (1)
-
Henry Baker