为什么 nlogn 这么难反转?

发布于 2024-10-07 00:45:52 字数 502 浏览 6 评论 0原文

假设我有一个空间要求为 nlogn 的函数,我想计算出给定可用空间的该函数的最大输入大小。即我想找到n,其中nlogn=c。

我遵循一种方法来计算n,在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))
}

但我无法理解为什么它必须迭代解决。对于我们感兴趣的范围(n>1),该函数是非奇异的。

Let's 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无声无音无过去 2024-10-14 00:45:52

n log n 没有什么特别之处 - 几乎所有初等函数都没有初等反函数,因此必须通过其他方法来求解:二分法、牛顿法、拉格朗日反演定理、级数反演、兰伯特W函数……

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...

一桥轻雨一伞开 2024-10-14 00:45:52

正如 Gareth 暗示的 Lambert W 函数(例如这里)让你几乎到达那里,确实 n = c/ W(c)

一个小谷歌发现了这个,这可能是有帮助。

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.

情话难免假 2024-10-14 00:45:52

跟进(完全明确):

library(emdbook)

n <- 2.5

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

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

两种实现在速度、准确性等方面可能存在细微差别。我还没有对它们进行广泛的测试/基准测试。 (现在我尝试了,

library(sos)
findFn("lambert W")

我发现它在所有地方都实现了:游戏包,以及一个名为 LambertW 的整个包......

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 ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文