fmpq_farey_neighbors
Synopsis
#include <flint/fmpq.h>Set l and r to the fractions immediately below and above x among the fractions with denominator at most Q (the Farey sequence of order Q, extended to all of \mathbb{Q}). Throws if the denominator of x exceeds Q. Any aliasing is allowed.
Writing x = p/q, the neighbours are the fractions p_l/q_l < x < p_r/q_r with p q_l - p_l q = 1 = p_r q - p q_r and Q - q < q_l, q_r \le Q [HarWri2008, Chapter III]. The function computes q_l from p^{-1} \bmod q and the rest from these identities.
References#
- [HarWri2008] G. H. Hardy and E. M. Wright, An Introduction to the Theory of Numbers, sixth edition, revised by D. R. Heath-Brown and J. H. Silverman, Oxford University Press, 2008.
Cite this page
The FLINT team, “fmpq_farey_neighbors (fmpq.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/fmpq/fmpq_farey_neighbors.html (generated 2026-10-20).
@misc{flint-doc-fmpq-fmpq-farey-neighbors,
author = {{The FLINT team}},
title = {{fmpq\_farey\_neighbors (fmpq.h)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/fmpq/fmpq_farey_neighbors.html},
note = {Generated 2026-10-20}
}