Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.9k
Description
Article:The Stern-Brocot Tree and Farey Sequences
Problem:
Surprisingly the page is missing a nice way of computing the next term in F_n without any recursion.
https://en.wikipedia.org/wiki/Farey_sequence#Next_term
Given two consecutive entries a/b and c/d, the next term p/q is given by
p = ((n + b) // d) * c - aq = ((n + b) // d) * d - bStart with a/b = 0/1 and c/d = 1/n.
I don't have a good source of this info other than wikipedia (who doesn't cite anything) but it's also here as Properties of Farey Sequences 5.https://dummit.cos.northeastern.edu/teaching_sp21_4527/4527_lecture_03_farey_sequences_v2.pdf
Also I should mention the number of terms at the end is 1 + Phi(n), where Phi is the totient summatory function, Phi(x) ~ (3 / pi^2) x^2 + O(x ln x).