确定 n 次 Farey 序列的最有效方法是什么?

发布于 2024-12-13 11:55:40 字数 1493 浏览 1 评论 0原文

我将实现一个 Farey 分数近似,将有限精度的用户输入转换为可能重复的有理数。
http://mathworld.wolfram.com/FareySequence.html

我可以轻松找到最接近的 Farey 分数在一个序列中,我可以通过构建 Stern-Brocot 树递归搜索中位数分数来找到 Fn。
http://mathworld.wolfram.com/Stern-BrocotTree.html

但是,该方法我想出了在序列 Fn 中查找分数的方法似乎效率很低:
(伪)

For int i = 0 to fractions.count -2
{
    if fractions[i].denominator + fractions[i+1].denominator < n
    {    
        insert new fraction(
            numerator = fractions[i].numerator + fractions[i+1].numerator
            ,denominator = fractions[i].denominator + fractions[i+1].denominator)
            //note that fraction will reduce itself
        addedAnElement = true
    }
}
if addedAnElement 
    repeat

我几乎总是定义序列 Fn 其中 n = 10^m 其中 m > 1

所以也许最好一次构建序列并缓存它......但它似乎仍然存在应该是更好的导出方式。

编辑:
这篇论文有一个很有前途的算法:
http://www.math.harvard.edu/~corina/publications/farey .pdf

我会尝试实现。
问题在于他们的“最有效”算法需要知道前两个元素。我知道任何序列的第一个元素都是 1/n 但找到第二个元素似乎是一个挑战...

EDIT2:
我不知道我是如何忽略这一点的:
给定 F0 = 1/n
如果x> 2 然后
F1 = 1/(n-1)

因此对于所有 n > 1 2、前两个分数总是
1/n,1/(n-1),我可以实现 Patrascu 的解决方案。

所以现在,我们这个问题的答案应该证明这个解决方案是或不是使用基准测试的最佳解决方案。

I am going to implement a Farey fraction approximation for converting limited-precision user input into possibly-repeating rationals.
http://mathworld.wolfram.com/FareySequence.html

I can easily locate the closest Farey fraction in a sequence, and I can find Fn by recursively searching for mediant fractions by building the Stern-Brocot tree.
http://mathworld.wolfram.com/Stern-BrocotTree.html

However, the method I've come up with for finding the fractions in the sequence Fn seems very inefficient:
(pseudo)

For int i = 0 to fractions.count -2
{
    if fractions[i].denominator + fractions[i+1].denominator < n
    {    
        insert new fraction(
            numerator = fractions[i].numerator + fractions[i+1].numerator
            ,denominator = fractions[i].denominator + fractions[i+1].denominator)
            //note that fraction will reduce itself
        addedAnElement = true
    }
}
if addedAnElement 
    repeat

I will almost always be defining the sequence Fn where n = 10^m where m >1

So perhaps it might be best to build the sequence one time and cache it... but it still seems like there should be a better way to derive it.

EDIT:
This paper has a promising algorithm:
http://www.math.harvard.edu/~corina/publications/farey.pdf

I will try to implement.
The trouble is that their "most efficient" algorithm requires knowing the prior two elements. I know element one of any sequence is 1/n but finding the second element seems a challenge...

EDIT2:
I'm not sure how I overlooked this:
Given F0 = 1/n
If x > 2 then
F1 = 1/(n-1)

Therefore for all n > 2, the first two fractions will always be
1/n, 1/(n-1) and I can implement the solution from Patrascu.

So now, we the answer to this question should prove that this solution is or isn't optimal using benchmarks..

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

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

发布评论

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

评论(2

猫弦 2024-12-20 11:55:40

为什么你需要 Farey 系列?使用连分数将为您提供相同的在线近似值,而无需预先计算级数。

Why do you need the Farey series at all? Using continued fractions would give you the same approximation online without precalculating the series.

你另情深 2024-12-20 11:55:40

Farey 序列中的相邻分数在第 2 节中进行了描述。 Farey 子序列中的 3 个相邻分数,http://arxiv.org/abs/0801.1981

Neighboring fractions in Farey sequences are described in Sec. 3 of Neighboring Fractions in Farey Subsequences, http://arxiv.org/abs/0801.1981 .

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