如何使用 Arb 库获得更高的正弦精度?

问题描述

我发现 Arb library,如果有足够的时间,它 should 能够计算非常高精度的正弦值。但是,我做不到。

尝试 sine example,我可以得到预测的输出

然而,当我试图通过将位数从 4096 增加到 32768 来提高精度时,我无法:

Using    64 bits,sin(x) = [+/- 2.67e+859]
Using   128 bits,sin(x) = [+/- 1.30e+840]
Using   256 bits,sin(x) = [+/- 3.60e+801]
Using   512 bits,sin(x) = [+/- 3.01e+724]
Using  1024 bits,sin(x) = [+/- 2.18e+570]
Using  2048 bits,sin(x) = [+/- 1.22e+262]
Using  4096 bits,sin(x) = [-0.7190842207 +/- 1.20e-11]
Using  8192 bits,sin(x) = [-0.7190842207 +/- 1.20e-11]
Using 16384 bits,sin(x) = [-0.7190842207 +/- 1.20e-11]
Using 32768 bits,sin(x) = [-0.7190842207 +/- 1.20e-11]

给定的例子有 x = 2016.1

使用 x = 0.1,我们得到以下输出

Using    64 bits,sin(x) = [0.09983341665 +/- 3.18e-12]
Using   128 bits,sin(x) = [0.09983341665 +/- 3.18e-12]
Using   256 bits,sin(x) = [0.09983341665 +/- 3.18e-12]
Using   512 bits,sin(x) = [0.09983341665 +/- 3.18e-12]
Using  1024 bits,sin(x) = [0.09983341665 +/- 3.18e-12]
Using  2048 bits,sin(x) = [0.09983341665 +/- 3.18e-12]
Using  4096 bits,sin(x) = [0.09983341665 +/- 3.18e-12]
Using  8192 bits,sin(x) = [0.09983341665 +/- 3.18e-12]
Using 16384 bits,sin(x) = [0.09983341665 +/- 3.18e-12]
Using 32768 bits,sin(x) = [0.09983341665 +/- 3.18e-12]

这个精度似乎比sin的{​​{1}}函数还要小。

我想提高精度以说 math.h(或任何其他精度)。如果有人能指导我,我将不胜感激????。

代码

e-40

解决方法

使用 x*(1 - x^2/3! + x^4/5! - x^6/7! ...) 可以实现更好的初始添加和更清晰的循环终止条件。


通常的正弦泰勒级数:sine(x)x - x^3/3! + x^5/5! - x^6/7! ...,是 OP 使用的形式。

预计正弦泰勒级数的每个项具有大约相同的相对进动,只是在后面的项中失去一点精度。

然而,通过添加项(和跟踪容差),总和并不比最大 2 项的绝对精度更精确。

通过将 sine(x) 形成为 x*(1 - x^2/3! + x^4/5! - x^6/7! ...),我们在第一项 1.0 中具有无限精度,因此对于小的 x,精度受到第二项的限制并且循环可以停止在 1.0 中添加一个术语没有任何区别。


这并不能很好地解释为什么 OP 的结果停留在 0.09983341665 +/- 3.18e-12

然而,注意对最大项求和(通过将其中一项设为具有无限精度的 1.0)会有所帮助。