为什么 nlogn 这么难反转?
假设我有一个空间要求为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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...
正如 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.
跟进(完全明确):
两种实现在速度、准确性等方面可能存在细微差别。我还没有对它们进行广泛的测试/基准测试。 (现在我尝试了,
我发现它在所有地方都实现了:游戏包,以及一个名为 LambertW 的整个包......
Following up (being completely explicit):
There are probably minor differences in speed, accuracy, etc. of the two implementations. I haven't tested/benchmarked them extensively. (Now that I tried
I discover that it's implemented all over the place: the games package, and a whole package that's called LambertW ...