-3
$\begingroup$

I want to solve the equation
$$2^a - 2^b = 2^x,$$

where $a$ and $b$ are extremely large numbers, for example $a =10^{10000 G}$, $B=10^{100G}$ with $G=10^{10^{100}}$, and I don't want to calculate the value of 2 to the power of $a$ or $b$ while solving the equation.

$\endgroup$
15
  • 1
    $\begingroup$ Welcome to Mathematica StackExchange! Can you please give a real example of your $A$ and $B$ so that we see what you interpret as big numbers? $\endgroup$
    – Domen
    Sep 28, 2023 at 14:54
  • 1
    $\begingroup$ Could divide both sides by 2^a, take logs and solve symbolically. In[126]:= SolveValues[Log[1 - 2^(b - a)] == x - a, x] Out[126]= {a + Log[1 - 2^(-a + b)]} Still an awkward exponent but it should behave ok if approximate values are substituted for a,b. $\endgroup$ Sep 28, 2023 at 15:05
  • $\begingroup$ I now realize that math.stackexchange.com was a better place for my question but I don't know how to move this question there? $\endgroup$
    – Maria
    Sep 28, 2023 at 15:32
  • $\begingroup$ @Domen, a real example : A or B=10^1000Googolplex $\endgroup$
    – Maria
    Sep 28, 2023 at 15:36
  • $\begingroup$ @Domen,en.wikipedia.org/wiki/Googolplex $\endgroup$
    – Maria
    Sep 28, 2023 at 15:36

2 Answers 2

6
$\begingroup$

Assuming $a>b>0$:

$$ 2^a-2^b=2^x\\ x=\frac{\ln(2^a-2^b)}{\ln2} =\frac{\ln(2^b(2^{a-b}-1))}{\ln2} =\frac{\ln(2^b)+\ln(2^{a-b}-1)}{\ln2} =b+\frac{\ln(2^{a-b}-1)}{\ln2}\\ =b+\log_2(2^{a-b}-1) $$ where $\log_2(z)=\ln z/\ln 2$ is the binary logarithm. From here there are two cases: if you're able to compute $2^{a-b}$ then you're done,

With[{a = 1000, b = 993}, b + Log2[2^(a - b) - 1]]
(*    993 + Log[127]/Log[2]    *)

On the other hand, if $2^{a-b}$ is still too large to compute, you can do a series-expansion to get an approximate result: for $q\gg1$ we have $$ \log_2(2^q-1) =q-\sum_{k=1}^{\infty}\frac{1}{2^{k q}\cdot k\ln2} =q-\frac{1}{2^q\cdot\ln2} -\frac{1}{2^{2q}\cdot 2\ln2}+\cdots $$ which converges very rapidly for large $q$. Setting $q=a-b$ we get $$ x=b+\log_2(2^{a-b}-1) =a-\frac{1}{\ln 2}\sum_{k=1}^{\infty}\frac{1}{k\cdot 2^{k(a-b)}} = a-\frac{1}{2^{a-b}\ln2}-\ldots $$ (use more terms in the series expansion if this approximation is not accurate enough).

Let's try it out for $a=123$ and $b=45$:

With[{a = 123, b = 45},
  x1 = SolveValues[2^a - 2^b == 2^x, x, Reals][[1]];
  x2 = a - 1/(2^(a - b) Log[2]);
  x3 = a - 1/(2^(a - b) Log[2]) - 1/(2^(2 (a - b)) 2 Log[2]);]

N[x1, 75]
(*    122.999999999999999999999995226522529401007762572299599002776841803125665871    *)

N[x2, 75]
(*    122.999999999999999999999995226522529401007762572307496058813118106229976092    *)

N[x3, 75]
(*    122.999999999999999999999995226522529401007762572299599002776841803125665888    *)
$\endgroup$
18
  • 1
    $\begingroup$ It does not work for {a = 10^6, b = 10^5 + 10^4}. $\endgroup$
    – user64494
    Sep 28, 2023 at 17:13
  • $\begingroup$ @user64494 With[{a = 10^6, b = 10^5 + 10^4}, x1 = Log[2^a - 2^b]/Log[2]; x2 = a - 1/(2^(a - b) Log[2])]; evaluates fine! $\endgroup$ Sep 28, 2023 at 17:55
  • 1
    $\begingroup$ @Roman Nice answer, but it doesn't avoid the calculation 2^(a-b). QP's expectation can't be fullfilled I think $\endgroup$ Sep 28, 2023 at 17:59
  • $\begingroup$ @Roman, Thanks for your answer ,but as Ulrich said it doesn't avoid the calculation 2^(a-b), I asked this question here too: math.stackexchange.com/questions/4777274/… $\endgroup$
    – Maria
    Sep 28, 2023 at 18:28
  • $\begingroup$ I now realize that using 2^A or 2^B is problematic for the performance I need to run on the computer, but 2^(a-b) is fine, so let me try your answer with different numbers. $\endgroup$
    – Maria
    Sep 28, 2023 at 18:58
0
$\begingroup$

Take Log of your equation (or Solve[2^x == 2^a - 2^b, x])

X=Log[2^A-2^B]/Log[2]

X/.{A->5.257,B->5}   (*2.64148*)
$\endgroup$
10
  • $\begingroup$ Note: A and B are very big numbers and I don't want to calculate the value of 2 to the power of A or B while solving the equation. $\endgroup$
    – Maria
    Sep 28, 2023 at 14:36
  • $\begingroup$ I need a method that can get C using only A and B, because the base always is 2. $\endgroup$
    – Maria
    Sep 28, 2023 at 14:40
  • $\begingroup$ You have a nonlinear equation in a,b,x , no chance to eliminate the base 2. I only see a solution using Log $\endgroup$ Sep 28, 2023 at 15:16
  • $\begingroup$ What is known about a,b? a>b && a>>1&& b>>1 $\endgroup$ Sep 28, 2023 at 15:27
  • $\begingroup$ a always is bigger than b $\endgroup$
    – Maria
    Sep 28, 2023 at 15:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.