mpmath 和 mathmatica 输出差异

问题描述 投票:0回答:1
  • 已编辑,因为我的主要问题在于 mp.math 的结果不正确。

我最终需要对复数进行非常精确的计算,这就是我尝试使用 mp.math 中的 mp 模块的原因。 (诚然,我已经阅读了 mp 数学文档,但对它是新手)在遇到错误答案后,我将问题追溯到这样一个事实:当我对 mpmath 进行计算时(见下文),我得到的结果与我得到的结果不同对mathematica 做同样的事情。有人可以帮我找出我做错了什么吗?

mp.数学: 从 mpmath 导入 mp mp.dps = 300;

mp.exp(mp.fmul(mp.mpf(str(-64)),mp.mpf(str(.2))))

输出:mpf('0.00000276077257203720079298503881941442964716356235195837374540868148586730700359076564381986686089035467149 9863639537941586877589109924708283223778336603096859417974304 72579604476223424097045454723393291529826485166261076775808555 479838036656035924269261878257522607849410841260713806720383331539818973042529')

数学 设置精度[Exp[-64*.2], 300]

输出: 2.760772572037198646757770806314802314318512799218297004699707031250000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000*10^-6

我希望结果是相同的,但到小数点后第 20 位左右,它们开始有所不同。

precision arbitrary-precision mpmath
1个回答
0
投票

在这种情况下,我认为您似乎发现了 Mathematica 中的错误,或者没有以正确的方式提出问题。它对 exp(-12.8) 的答案对于我来说看起来不太合理,因为所有这些尾随零。

当我将计算交给 Julia 并充分提高精度时,它与我将精度提高到 1000 位时一直获得的结果一致。我不确定 Julia 的 BigFloats 的实现细节,但它们以前从未让我失望过。

julia> exp(-BigFloat(64)/BigFloat(5))

2.760772572037200792985038819414429647163562351958373745 408681485867307003590676e-06

julia> setprecision(BigFloat, 500)
500

julia> exp(-BigFloat(64)/BigFloat(5))

2.76077257203720079298503881941442964716356235195837374540868148586730700359076564381986686089035467149986363953794158 68775891099247082832237783366030938e-06

julia> setprecision(BigFloat, 1000)
1000

julia> exp(-BigFloat(64)/BigFloat(5))

2.76077257203720079298503881941442964716356235195837374540868148586730700359076564381986686089035467149986363953794158 6877589109924708283223778336603096859417974304725796044762234240970454547233932915298264851662610767758085554798380366560 35924269261878257522607849410841260713806720383331539818973042529e-06

log(BigFloat("2.7607725720372007929850388194144296471635623519583737454086814858673070035907656438198668608903546714998636395 3794158687758910992470828322377833660309685941797430472579604476223424097045454723393291529826485166261076775808555479838 036656035924269261878257522607849410841260713806720383331539818973042529e-06"))

-12.8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000003

记录 Julia 中 Mathematica 答案的对数,可以清楚地看出 Mathematica 使用标准 64 位双精度算术计算了 exp。哎呀!

julia> log(BigFloat("2.76077257203719864675777080631480231431851279921829700469970703125000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-6"))

-12.800000000000000777400967305821426105253758295325710077054275834431666979444794875005870748133034386802867032757665 7852816894936980836750044670968536044806438802211617596023783929373187330881370009468791968179640611989465169433207621738 713056795607656520114787722487328419418068321396252206120875122593

我认为 mpmath 的答案实际上是完全正确的,而 Mathematica 给了你误导性和不正确的答案(看起来可疑地像 64 位双 1/2^N 截断)。 PS 对上面的格式表示抱歉。我似乎无法缩进很长的输出行(并且将它们分解太容易出错)

© www.soinside.com 2019 - 2024. All rights reserved.