Wikipedia:Reference desk/Archives/Mathematics/2023 April 1

= April 1 =

Solving sums of powers
Consider the equation $$2^x + 3^x = 13$$. The solution, of course, is $$x = 2$$. What I am trying to understand is how to approach the general case; given $$A^x + B^x = C$$, for any known $$A, B, C$$, what is the value of $$x$$? I just can't wrap my head around a reasonable approach. I tried taking the natural log on both sides, but that didn't seem to help. Had it been a single term on the left-hand-side of the equation, I could have extracted the exponent and solved it without much fuss. Any suggestions/pointers on how to proceed? Earl of Arundel (talk) 02:17, 1 April 2023 (UTC)


 * In the following, I assume that $$A,B,$$ and $$C$$ are all positive. In only a few cases can equations with a sum of powers with the unknown $$x$$ in the exponents be solved easily, by trial and error or analytically. If $$C=2,$$ the solution is given by $$x=0.$$ If $$B=1,$$ we find $$x=\log_A(C-1).$$ But there is no analytical way to solve this in general, so we have to resort to a numerical approach. I think Newton's method will do well, using
 * $$f(x)=A^x+B^x-C,$$
 * $$f'(x)=A^x\log A+B^x\log B,$$
 * and repeatedly computing
 * $$x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}$$
 * until a desired level of convergence. For the initial estimate, we can use, assuming wlog that $$|\log A|\le|\log B|,$$
 * $$x_0=\log_AC$$ if  $$C<2,$$
 * $$x_0=\log_BC$$ otherwise.
 * Convergence is not guaranteed, though. When $$A$$ and $$B$$ are not at opposite sides of $$1$$, the equation may not have a solution or may have two solutions. The computation may also fail by dividing by $$0,$$ as when $$A=B=1.$$ If there is an integer solution, it will be found. --Lambiam 07:32, 1 April 2023 (UTC)
 * Convergence to high precision may also fail due to the lack of precision in floating point arithmetic. For $$2^x+3^x=60073,$$ which is solved by $$x=10$$, numerical computation (using exponentiation by $$z^x=\exp(x\log z)$$) results in $$x_4=10.0$$ on the dot, but then computing $$f(x_4)$$ does not result in zero but produces $$-1.309672370553017\cdot10^{{-}10}.$$ --Lambiam 08:04, 1 April 2023 (UTC)
 * In general there are several ways for Newton's method to fail; see the section "Failure analysis" in that article. I think the main point though is that the equation is not solvable in closed form and one must resort to numerical methods to get an approximate value. Of course nowadays you can plug an equation in Wolfram Alpha and get a numerical answer. --RDBury (talk) 17:00, 1 April 2023 (UTC)
 * The issue above is not among the failure modes mentioned in that section, which are mathematical in nature. Mathematically, $$2^{10}+3^{10}-60073$$ is exactly equal to $$0.$$ But the actual computed value is not; we get
 * $$3^{10.0}=\exp(10\times\log 3)=\exp(10\times 1.09861228866810956...)=$$
 * $$=\exp(10.9861228866810956...)=59048.99999999986...<59049=3^{10}.$$
 * --Lambiam 20:04, 1 April 2023 (UTC)
 * Thanks, Lambiam, I had no idea this was such a difficult problem to solve for the general case! I wonder if there is some way to guarantee convergence (for most cases anyway) by dividing through by C? Playing with that idea I even found an interesting approximation for x:
 * $$A^x + B^x = C$$
 * $$A^x/C + B^x/C = 1$$
 * $$A^x/C = 1 - B^x/C$$
 * $$x ln(A) - ln(C) = ln(C - B^x) - ln(C)$$
 * $$x ln(A) = ln(C - B^x)$$


 * And since $ln(C - B^x) \approx ln(C)$ as x approaches infinity, we get a rough estimate:
 * $x \approx ln(C)/ln(A)$
 * In the case of $2^x + 3^x = 13$, we find that
 * $x = 2 \approx ln(13)/ln(2) \approx 3.7$
 * Ignoring extreme corner cases, setting our initial value x0 using this estimated root should yield a numerical convergence in most cases, no? Earl of Arundel (talk) 18:58, 1 April 2023 (UTC)
 * Whoops, that isn't right! Earl of Arundel (talk) 19:14, 1 April 2023 (UTC)
 * You can get to faster to your fifth line without dividing by $$C$$:
 * $$A^x+B^x=C$$
 * $$A^x=C-B^x$$
 * $$\ln(A^x)=\ln(C-B^x)$$
 * $$x\ln A=\ln(C-B^x).$$
 * It appears plausible that using $$f(x)=x\ln A-\ln(C-B^x)$$ gives faster convergence, or, when $$|\log A|\le|\log B|,$$ swapping $$A$$ and $$B$$ and using $$f(x)=x\ln B-\ln(C-A^x).$$ I have not investigated this, though. If $$A$$ and $$B$$ are similar in size and not at opposite sides of $$1,$$ we can approximate $$A^x+B^x$$ by $$2\left(\tfrac{1}{2}(A+B)\right)^x$$ and use
 * $$x_0=\frac{\ln C-\ln 2}{\ln(A+B)-\ln 2}.$$
 * For the case of $$2^x + 3^x = 13$$, we then get $$x_0\approx 2.04280\,.$$ --Lambiam 19:38, 1 April 2023 (UTC)
 * Nice! That does seem to work pretty well. Where does the $$\ln{2}$$ term come from though? It seems to randomly pop up in a lot of equations, come to think of it. Why is that, I wonder? Earl of Arundel (talk) 20:58, 1 April 2023 (UTC)
 * Instead of solving $$A^x+B^x=C,$$ we set off by solving
 * $$2\left(\tfrac{1}{2}(A+B)\right)^{x_0}=C$$
 * $$\left(\tfrac{1}{2}(A+B)\right)^{x_0}=\tfrac{1}{2}C$$
 * $$x_0\ln\left(\tfrac{1}{2}(A+B)\right)=\ln(\tfrac{1}{2}C)$$
 * $$x_0(\ln(A+B)-\ln 2)=\ln C-\ln 2$$
 * --Lambiam 21:21, 1 April 2023 (UTC)
 * Ah, right. Subtracting $$\ln{2}$$ has the same effect as dividing by $$2$$ in that context. Thanks again! Earl of Arundel (talk) 21:39, 1 April 2023 (UTC)