How to Find the Mth Digit of 2^n?

  • Context: Undergrad 
  • Thread starter Thread starter Krypton
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around methods for finding the mth digit of the number 2 raised to the power of n (2^n). It explores various computational approaches, efficiency concerns, and the feasibility of deriving a specific equation for this task.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • Some participants suggest directly computing 2^n for small n or using modular arithmetic for larger n to find the mth digit.
  • There is a question about the possibility of finding a quick equation for the mth digit of 2^n, with some arguing it is possible but challenging to evaluate efficiently.
  • One participant expresses skepticism about the utility of creating a function for this purpose, suggesting that it is more practical to use algorithms instead.
  • Another participant presents an algorithm with a time complexity of O(mn^2) or possibly O(mn log n), relying solely on integer additions modulo 10.
  • Further details are provided about the time complexity of various multiplication methods and their implications for finding the mth digit.
  • One participant humorously notes that their algorithm may have worse time and space complexity compared to others discussed.

Areas of Agreement / Disagreement

Participants express differing views on the feasibility and practicality of finding an equation for the mth digit of 2^n. While some believe it is possible, others argue that the effort may not be worthwhile. The discussion remains unresolved regarding the best approach to take.

Contextual Notes

There are unresolved complexities regarding the efficiency of various algorithms and the memory requirements for large values of m. The discussion also highlights the dependence on definitions and assumptions about computational methods.

Krypton
Messages
13
Reaction score
0
How to find the mth digit of 2^n
 
Mathematics news on Phys.org
If n is small, compute 2^n and look at the mth digit.

If m is small, compute 2^n modulo an appropriate power of your base (e.g. mod 10^9) with binary exponentiation or another efficient method.

If [itex]n\log_{10}2-m[/itex] is small, compute a floating-point approximation of 2^n with similar methods. If you're using a binary computer, this is just a base-10 conversion. If n is sufficiently small and your algorithm is fast, i.e. quasilinear, this is a good method.

Otherwise the calculation will be difficult, both because of the speed required and the memory requirements. You may need a specialized system, because I can't think of any special way to do this.
 
Is it impossible to find an equation giving the mth digit of 2^n ?
 
Not at all. The problem is evaluating such an equation quickly.
 
What do u ment by not at all ? Is it not at all possible? Or not atall imposible?
 
It's possible, but it's silly to bother. There really isn't anything special about base ten, so picking what digit is where is nothing more than a feat of clever arithmetic. Rather, I should say, creating a function which yields a specific digit is silly. Since we define base ten, we might as well pluck the damn thing out with an algorithm.
 
Krypton said:
What do u ment by not at all ? Is it not at all possible? Or not atall imposible?

Easily possible, but pointless. The problem is how to evaluate it quickly.
 
I found an algorithm to find the mth digit of 2^n in [itex]\mathcal O(mn^2)[/itex] time (possibly [itex]\mathcal O(mn \log n)[/itex], but I haven't proven it mathematically) using only integer additions (modulo 10). I don't know how this compares to CRGreathouse's suggestions above.
 
Ben Niehoff said:
I found an algorithm to find the mth digit of 2^n in [itex]\mathcal O(mn^2)[/itex] time (possibly [itex]\mathcal O(mn \log n)[/itex], but I haven't proven it mathematically) using only integer additions (modulo 10). I don't know how this compares to CRGreathouse's suggestions above.

Adding 1 + 1, 2 + 2, 4 + 4, 8 + 8, (mod 10^m) ... takes n additions, each taking O(m) time, for a total of O(mn).

Multiplying 2 * 2 * ... * 2 (mod 10^m) takes n - 1 multiplications, each taking M(m) time, for a total of O(n^3) or [tex]O(n^{2.585})[/tex] with Karatsuba.

Binary exponentiation mod 10^m takes [tex]O(\lg n)[/tex] multiplications, each taking M(m) time, for a total of [tex]O(m\lg^2n)[/tex] or [tex]O(m\lg^{1.585}n)[/tex] with Karatsuba.

The latter two could be improved with FFT-based multiplications methods, but that would be silly here. The real problem is that all of these methods take somewhere around m bytes (m lg 10 bits per number, plus overhead). This can be substantial for large m.
 
  • #10
My algorithm uses at most 4n^2 bits, plus overhead, so I suppose it is worse in both time and space complexity. Oh well. :P

It's quick to do on paper, though.
 
  • #11
Would you like to describe your algorithm?
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 34 ·
2
Replies
34
Views
7K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K