计算至“无限” C# 中的二进制精度

发布于 2024-08-07 00:35:15 字数 259 浏览 2 评论 0原文

到目前为止,法布里斯·贝拉德 (Fabrice Bellard) 的基数为 2 的方程似乎是可行的

alt text

讽刺的是这将需要 BigReal 类型;我们有 .Net 的这个吗? .Net 4.0 有 BigInteger。

有人有 Haskell 版本吗?

So far it looks like Fabrice Bellard's base 2 equation is the way to go

alt text

Ironically this will require a BigReal type; do we have this for .Net? .Net 4.0 has BigInteger.

Anyone have a Haskell version?

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

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

发布评论

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

评论(4

浮云落日 2024-08-14 00:35:15

由于您需要 Haskell 版本,这里有一篇 Jerzy 的论文 Karczmarczuk,被称为“世界上最不可靠的计算 π 的技术”:

这篇论文是一个非典型的练习
惰性函数编码,为
乐趣和指导。可以读取
并被任何人理解
理解编程语言
哈斯克尔。我们展示了如何实施
π 的 Bailey-Borwein-Ploue 公式
以共同递归、增量的方式
产生数字 3, 1, 4, 1,
5、9.. 。直到记忆
精疲力尽。这不是一个方法
如果有人需要很多,请继续
数字!我们的编码策略是
反常且危险的,而且它
证明崩溃了。它是基于
域上的算术
无限的数字序列
表示展开的真分数
在整数基数中。我们展示如何
操作:加、乘
整数等此类序列来自
从左到右无穷无尽,
这显然不能在所有情况下工作
由于含糊不清的情况。一些
深刻的哲学后果是
结论中进行了讨论。

它并没有真正以有效或非常实用的方式解决问题,但很有趣,并通过惰性无限精度算术展示了一些问题。

然后还有 Jeremy Gibbons 的这篇论文

Since you're asking for a Haskell version, here is a paper by Jerzy Karczmarczuk, called "The Most Unreliable Technique in the World to compute π":

This paper is an atypical exercice in
lazy functional coding, written for
fun and instruction. It can be read
and understood by anybody who
understands the programming language
Haskell. We show how to implement the
Bailey-Borwein-Ploue formula for π
in a co-recursive, incremental way
which produces the digits 3, 1, 4, 1,
5, 9. . . until the memory
exhaustion. This is not a way to
proceed if somebody needs many
digits! Our coding strategy is
perverse and dangerous, and it
provably breaks down. It is based on
the arithmetics over the domain of
infinite sequences of digits
representing proper fractions expanded
in an integer base. We show how to
manipulate: add, multiply by an
integer, etc. such sequences from the
left to the right ad infinitum,
which obviously cannot work in all
cases because of ambiguities. Some
deep philosophical consequences are
discussed in the conclusions.

It doesn't really solve the problem in an efficient or very practical way, but is entertaining and shows some of the problems with lazy infinite precision arithmetic.

Then there's also this paper by Jeremy Gibbons.

入画浅相思 2024-08-14 00:35:15

到目前为止,我最喜欢的 pi 的 Haskell spigot 来自 Jeremy Gibbons:

pi = g(1,0,1,1,3,3) where
    g(q,r,t,k,n,l) = 
        if 4*q+r-t<n*t
        then n : g(10*q,10*(r-n*t),t,k,div(10*(3*q+r))t-10*n,l)
        else g(q*k,(2*q+r)*l,t*l,k+1,div(q*(7*k+2)+r*l)(t*l),l+2)

证明该实现合理的数学背景可以在以下位置找到:

Pi 数字的插销算法

By far my favorite Haskell spigot for pi comes from Jeremy Gibbons:

pi = g(1,0,1,1,3,3) where
    g(q,r,t,k,n,l) = 
        if 4*q+r-t<n*t
        then n : g(10*q,10*(r-n*t),t,k,div(10*(3*q+r))t-10*n,l)
        else g(q*k,(2*q+r)*l,t*l,k+1,div(q*(7*k+2)+r*l)(t*l),l+2)

The mathematical background that justifies that implementation can be found in:

A Spigot Algorithm for the Digits of Pi

抠脚大汉 2024-08-14 00:35:15

维基百科详细介绍了许多获取 pi 数值近似值的方法此处。他们还提供了一些示例伪代码

编辑:如果您对此类数学问题感兴趣,但没有任何相关的现实世界问题需要解决(恕我直言,这绝对是一个好的态度),您可以访问 Euler 项目页面

Wikipedia details a lot of ways to get numerical approximations of pi here. They also give some sample pseudo-code

Edit : If you're interested in this kind of mathematical problems without having any related real-world problem to solve (which is definitely a good attitude to have, IMHO), you could visit the Euler Project page

唱一曲作罢 2024-08-14 00:35:15

在基于 DLR 的动态语言中,存在处理大有理数的可能性(例如 IronPython)。或者,您可以通过 P/Invoke 使用大实数的任何可移植 C/C++ 实现。

There exists such possibility to process big rational numbers in DLR-based dynamic languages (e.g. IronPython). Or you can use any portable C/C++ implementation of big real numbers through P/Invoke.

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