# How can I algebraically solve $n-\log(na)=b$ for $n$

How can I algebraically solve $n-\log(na)=b$ for $n$. I figured out a simple algorithm to get arbitrary close to the solution (estimate, then negate log term and use answer in the log term, then repeat), but I want to know how I can solve this exact.

• There is no exact way of solving this-everything will eventually be an estimate. – John Dec 14 '13 at 13:08
• Hmm, well are there at least any better algorithms than the one I described? – Jori Dec 14 '13 at 13:13
• en.wikipedia.org/wiki/Lambert_W_function – mdenton8 Dec 14 '13 at 13:13
• You can use the Lambert W function- but that is just another representation of the solution. There are many different type of algorithms-some that are very complicated. Calculators use some of these algorithms. – John Dec 14 '13 at 13:14
• But does this special function evaluate faster to the solution than this simple algorithm (and are there any asymptotic bounds on how much faster)? I will look into this function though, thanks :) . – Jori Dec 14 '13 at 13:18

You can't solve this algebraically. However, you can rewrite your equation and express it in terms of a known special function, the Lambert W function:

$$n - \log(na) = b \iff n - \log n = b + \log a \iff \frac{e^n}{n} = a e^b \\ \iff n e^{-n} = \frac{1}{a e^b} \iff (-n)e^{-n} = -\frac{1}{a e^b} \implies n = -W\left(-\frac{1}{a e^b}\right)$$

If you cannot use Lambert function, the only way I can concieve is a root-finder method such as Newton. Provided a "good" guess, then the problem is quite simple. What you suggest would work but you have two manner for doing it.

The first one is the one you suggest, that is to say repeating
n = b + Log(n a)

The second one would be to repeat in the same spirit
n = Exp[n - b] / a

But both of same will be much slower than Newton iterative scheme which will write
n = n (-1 + b + Log[a] + Log[n]) / (n -1)
the rhs updating the lhs.

Hint: Use the Lambert W-function.