Why is nlogn so hard to invert?

主宰稳场 提交于 2019-12-13 18:24:31

问题


Lets say I have a function that is nlogn in space requirements, I want to work out the maximum size of input for that function for a given available space. i.e. I want to find n where nlogn=c.

I followed an approach to calculate n, that looks like this in R:

step = function(R, z) { log(log(R)-z)} 
guess = function(R) log(log(R))

inverse_nlogn = function(R, accuracy=1e-10) {
 zi_1 = 0
 z = guess(R)
 while(abs(z - zi_1)>accuracy) { 
  zi_1 = z
  z = step(R, z)
 }
 exp(exp(z))
}

But I can't get understand why it must be solved iteratively. For the range we are interested (n>1), the function is non singular.


回答1:


There's nothing special about n log n — nearly all elementary functions fail to have elementary inverses, and so have to be solved by some other means: bisection, Newton's method, Lagrange inversion theorem, series reversion, Lambert W function...




回答2:


As Gareth hinted the Lambert W function (eg here) gets you almost there, indeed n = c/W(c)

A wee google found this, which might be helpful.




回答3:


Following up (being completely explicit):

library(emdbook)

n <- 2.5

c <- 2.5*log(2.5)
exp(lambertW(c))  ## 2.5

library(gsl)
exp(lambert_W0(c)) ## 2.5

There are probably minor differences in speed, accuracy, etc. of the two implementations. I haven't tested/benchmarked them extensively. (Now that I tried

library(sos)
findFn("lambert W")

I discover that it's implemented all over the place: the games package, and a whole package that's called LambertW ...



来源:https://stackoverflow.com/questions/4400175/why-is-nlogn-so-hard-to-invert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!