# How to solve $x + 3^x = 4$ analytically?

I tried to solve the problem of $x + 3^x = 4$. I know that we can find it that $x = 1$ intuitively. I just want to know how to solve it using mathematic formula.

I have learned a little bit about Lambert W function. I've tried to rewrite the formula to become: \begin{align} 1 &= (4-x) \, e ^{-x \ln(3)} \\ 1 &= 4 \, e ^{-x \ln(3)} - x \, e ^{-x \ln(3)} \\ 1 &- 4 \, e ^{-x \ln(3)} = -x \, e ^{-x \ln(3)} \\ \ln(3) & - 4 \, \ln(3) \, e ^{-x \ln(3)} = -x \ln(3) \, e ^{-x \, \ln(3)} \end{align}

Until that last part, I got confused how to combine the $x$ variables at both sides. That's why I got stuck. Any idea how to combine it? Or is there any part of my solution need to be corrected? Thank you.

• You could find the 2 graphs intersect, like $3^x$ and $4-x$ – Tony Hellmuth May 28 '18 at 1:18
• For now, I don't want to use graphs analysis since it's too obvious. Since I met several problems similar like this one, I want to know how to solve this kind of form using analytical method. – Aroli Marcellinus May 28 '18 at 1:22
• Well, you can rearrange the equation to make one side zero and apply Newton's Method: $x + 3^x - 4 = 0$ I would also recommend solving for the turning points of the equation as the number of roots cannot be more than one greater than the number of turning points. – ray lin May 28 '18 at 1:25
• I can do that, but I just curious whether this problem can be solved analytically. – Aroli Marcellinus May 28 '18 at 1:29
• That is the analytical method, you use calculus to find the derivative and solve for the number of turning points and this in turn gives you maximum amount of roots there are. – ray lin May 28 '18 at 1:30

By the methods started by the proposer one can show that the equation in question is part of a more general set given by $x + a^{x} = b$ which has the soltion $$x = b - \frac{W_{0}(a^{b} \, \ln(a))}{\ln(a)}.$$

The proof of which can be seen by use of $a^{x} = e^{x \, \ln(a)}$ and $x \, e^{x} = t$ has the solution $t = W(x)$, where $W(z)$ is the Lambert W-function, where $W_{0}(x)$ is defined as th ereal solution for $x \geq -1/e$, and is: \begin{align} x + a^{x} &= b \\ (x - b) &= - a^x = - e^{(x-b) \, \ln(a) + b \, \ln(a)} \\ -(x - b) \, \ln(a) \, e^{- (x-b) \, \ln(a)} &= a^{b} \, \ln(a) \\ - (x-b) \, \ln(a) &= W_{0}(a^{b} \, \ln(a)) \\ x &= b - \frac{W_{0}(a^{b} \, \ln(a))}{\ln(a)}. \end{align}

For this particular problem one can use the property $W(x \, \ln(x)) = \ln(x)$ in such a way that $W(3^{4} \, \ln(3)) = W(27 \, \ln(27)) = \ln(27) = 3 \, \ln(3)$. For the equation $x + 3^{x} = 4$, which from the general solution is $a=3$ and $b=4$ yields \begin{align} x &= 4 - \frac{W_{0}(81 \, \ln(3))}{\ln(3)} \\ &= 4 - \frac{3 \, \ln(3)}{\ln(3)} \\ &= 1. \end{align}

• thanks for the solution. Well, actually I still don't understand about the 2nd line of the proof. I will try to find it out anyway. – Aroli Marcellinus May 28 '18 at 1:51
• btw, after I got the x, how can I interpret W into a real number?? I hear about using W0, W1, W-1, and so on, but I still cannot understand the underlying process. – Aroli Marcellinus May 28 '18 at 2:19
• @AroliMarcellinus The defining factor is $x = -1/e$ as in $W(x) = W_{0}(x)$ for $x \geq -1/e$ and $W(x) = W_{-1}(x)$ for $x < -1/e$. – Leucippus May 28 '18 at 3:27
• @AroliMarcellinus An interesting property applies for the original equation proposed. The solution has been updated to include this. – Leucippus May 28 '18 at 3:34

To get a solution using the Lambert $W$ function which has $z=W(ze^z)$:

$$x+3^x=4$$

$$x-4 = -81\cdot3^{x-4}$$

$$\log_e(3)(x-4) = -81\log_e(3)\cdot e^{\log_e(3)(x-4)}$$

$$-\log_e(3)(x-4)\cdot e^{-\log_e(3)(x-4)}= 81\log_e(3)$$

$$-\log_e(3)(x-4) = W\left(81\log_e(3)\right)$$

$$x=4 - \dfrac{W\left(81\log_e(3)\right)}{\log_e(3)}$$

• Yeah and know you have to use Newton's method or some other root-finding algorithm to solve for the decimal approximation of the Lambert-W function. – ray lin May 28 '18 at 1:39
• thanks for another insight. Well, I thought z in the Lambert W only used for the complex functions. – Aroli Marcellinus May 28 '18 at 1:52
• @AroliMarcellinus It is still a complex number you can apporoximate different complex solutions by picking different branches. Here are a few for this problem: \begin{align} 1.00000000000000&\\ 1.52439343037426 &- 4.72842447548978i\\ 2.12680606985956 &- 10.1743310889208i\\ 2.51699892083798 &- 15.8129217973205i\\ 2.79400810610809 &- 21.4980154824886i\\ 3.00730389732917 &- 27.1994144714842i\\ 3.18040146485558 &- 32.9080754310449i\\ 3.32595534594473 &- 38.6204965286917i\\ 3.45149300751107 &- 44.3350742152033i\\ 3.56183934313710 &- 50.0509834707177i\\ \end{align} – N8tron May 28 '18 at 2:07

To hell with the formulas. As the function $x+3^x$ is increasing the solution $x=1$ is unique.

• dude, if I just want the answer, I can answer it intuitively (as I wrote in the question). – Aroli Marcellinus May 28 '18 at 2:09
• I proved Minz statement in my answer – ray lin May 28 '18 at 2:22
• @N8tron Newton's method is way more efficient than bisection method – ray lin May 28 '18 at 2:46
• @raylin of course it is, but it's not always an option. It is definitely better for this function, and given a suitably good guess for quartic and cubic equations sure it's usually better (sometimes repeated roots need a bit of adjusting). But my point is even though it's less efficient, exact solutions can sometimes be worse to compute and much worse than newtons method. There is a compelling reason to use the lambert -w function here, to take solutions along other branches and it already has built-in routines so someone has taken the time to optimize them. – N8tron May 28 '18 at 3:00
• @raylin I haven't personally gone through all this myself, but I looked up my CAS of choice: sagemath's implementation which is really a wrapper for scipy. Scipy's documentation references the following article, section 4 is about branches apmaths.uwo.ca/~djeffrey/Offprints/W-adv-cm.pdf – N8tron May 28 '18 at 3:27

I am assuming we are dealing with the Real domain i.e. $\{x|x \in \mathbb{R} \}$

Rearrange equation $x + 3^x = 4$ so that there is a zero on one side: $$x + 3^x - 4 = 0$$ Let $f(x) = x + 3^x - 4 = 0$

Find potential turning points by solving for the derivative $\frac{d}{dx} [f(x)]$ and then solving for $\frac{d}{dx} [f(x)] = 0$

Apply addition rule: $\frac{d}{dx} [x + 3^x - 4] = \frac{d}{dx}[x] + \frac{d}{dx} [3^x] - \frac{d}{dx} $

Use properties $\frac{d}{dx}[kx] = k \: and \: \frac{d}{dx}[c] = 0$

$= 1 + \frac{d}{dx} [3^x] - 0$

$= 1 + \frac{d}{dx} [e^{\ln(3)*x}]$ , using the fact that $\frac{d}{dx} [e^x] = e^x$ and applying the chain rule $\frac{d}{dx}[f(g(x))] = f'g(x) * g'(x)$

$1 + \frac{d}{dx}[e^{\ln(3)*x}] = 1 + e^{\ln(3)*x} * \ln(3)$

$= 1 + 3^x * \ln(3)$

Now solve for $1 + 3^x * ln(3) = 0$ :

$3^x * \ln(3) = -1$

$3^x = -\frac{1}{\ln(3)}$ , negative number, no solutions in the real domain thus there are no stationary points and no turning points.

As a consequence of Rolle's Theorem: $\text{#Roots} \leq \text{#turningPoints} + 1$

Thus, $\text{max#OfRoots} = 0 + 1 = 1$

Therefore, the only solution in the real domain is $x = 1$