787有什么特别之处?

Dan*_*ner 18 haskell integer-arithmetic

在ghci中,使用arithmoi包:

Math.NumberTheory.Powers.General> :set +s
Math.NumberTheory.Powers.General> integerRoot 786 ((10^32)^786)
100000000000000000000000000000000
(0.04 secs, 227,064 bytes)
Math.NumberTheory.Powers.General> integerRoot 787 ((10^32)^787)
Run Code Online (Sandbox Code Playgroud)

五分钟后,它仍然没有回应.为什么需要这么长时间?

(从一些临时测试来看,对于大于787的所有选择来说似乎都很慢,并且对于所有选择较小的选择都很快.)

Ry-*_*Ry- 23

arithmoi 工具integerRoot通过获取初始近似根与牛顿法完善其猜测.对于(10 32)786,第二个近似得到一个非常好的起点:

> appKthRoot 786 ((10^32)^786)
100000000000000005366162204393472
Run Code Online (Sandbox Code Playgroud)

对于(10 32)787,第二个近似得到一个非常糟糕的起点.就像,非常糟糕.

> appKthRoot 787 ((10^32)^787)   
1797693134862315907729305190789024733617976978942306572734300811577326758055009
6313270847732240753602112011387987139335765878976881441662249284743063947412437
7767893424865485276302219601246094119453082952085005768838150682342462881473913
110540827237163350510684586298239947245938479716304835356329624224137216
Run Code Online (Sandbox Code Playgroud)

它实际上得到了从那里开始的一切的近似值.

> length $ nub [appKthRoot x ((10^32)^x) | x <- [787..1000]]
1
Run Code Online (Sandbox Code Playgroud)

无论如何,放入重要部分appKthRoot,我们得到:

> let h = 106; k = 786; n = (10^32)^k; !(I# s) = h * k - k in floor (scaleFloat (h - 1) (fromInteger (n `shiftRInteger` s) ** (1/fromIntegral k) :: Double))
100000000000000005366162204393472

> let h = 106; k = 787; n = (10^32)^k; !(I# s) = h * k - k in floor (scaleFloat (h - 1) (fromInteger (n `shiftRInteger` s) ** (1/fromIntegral k) :: Double))
179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137216
Run Code Online (Sandbox Code Playgroud)

并看看会发生什么scaleFloat:

> let h = 106; k = 786; n = (10^32)^k; !(I# s) = h * k - k in fromInteger (n `shiftRInteger` s) ** (1/fromIntegral k) :: Double
2.465190328815662

> let h = 106; k = 787; n = (10^32)^k; !(I# s) = h * k - k in fromInteger (n `shiftRInteger` s) ** (1/fromIntegral k) :: Double
Infinity
Run Code Online (Sandbox Code Playgroud)

是的,那就是它.(10 32)786 ÷2 82530 ≈2 1023.1配合在双,但(10 32)787 ÷2 82635 ≈2 1024.4没有.

  • 这确实令人沮丧.我有这些大的'Integer'首先躺在那里(以及我使用arithmoi的部分原因)的全部原因是因为我正在努力避免`Double` ... (2认同)