Recursive Complexity

Thoughts and musings of a programmer and wanna be entrepreneur

Application Of Logarithms To Exponential Values And Other Integers

leave a comment »

We will be dealing with positive integers and logarithms to base 10.

How do you calculate the no of digits present in an exponential value or for that matter a very huge integer ? The answer is simple as shown below.

no of digits = floor(log (x ^ y)) + 1

Explanation : The logarithm of any number to base 10 is the number of times 10 is multiplied with itself to obtain that number. A little experimentation will show that when 10 is multiplied with itself x times or put another way, is raised to power x, we obtain an integer which contains x + 1 digits. Hence, obtaining the base 10 logarithm of any number and adding 1 to it will give you the number of digits in that number. Carefully note the floor function being used around the logarithm as logarithms generally give you floating point or decimal values.

Find the first n digits of an exponential value. Eg – Find first 5 digits of 12^13.

x = log 12^13 = 13 * log 12 = 14.0293561

y = floor(10^(x - floor(x) + n - 1)) = floor(10^(14.0293561 - 14 + 5 - 1))

= floor(10^(4.0293561)) = 10699

y is the first five digits of 12^13.

12^13 = 106993205379072.
log 12^13 = 14.0293561.
10^14.0293561 = (10^14)×(10^0.0293561) = (100000000000000)×(10^0.0293561) ≈ 106993205379072
The above argument shows that 10^0.0293561 when multiplied by 10^14 adds 06993205379072 to 100000000000000. In other words, it gives the first 15 digits of 12^13. Hence, if we want the first 5 digits of 12^13 multiply 10^0.0293561 with 10^4 which is also the same as raising 10 to power 4.0293561

NOTE: As n increases, the logarithm log x^y also needs to be calculated for more decimal places.


Written by Vivek S

May 15, 2013 at 4:53 am

Posted in Tech

Tagged with , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

TED Blog

The TED Blog shares interesting news about TED, TED Talks video, the TED Prize and more.

%d bloggers like this: