FLINT3.7.0-dev

fmpq_farey_neighbors

Synopsis#include <flint/fmpq.h>
void fmpq_farey_neighbors(fmpq_t l, fmpq_t r, const fmpq_t x, const fmpz_t Q)source

Set ll and rr to the fractions immediately below and above xx among the fractions with denominator at most QQ (the Farey sequence of order QQ, extended to all of Q\mathbb{Q}). Throws if the denominator of xx exceeds QQ. Any aliasing is allowed.

Writing x=p/qx = p/q, the neighbours are the fractions pl/ql<x<pr/qrp_l/q_l < x < p_r/q_r with pql−plq=1=prq−pqrp q_l - p_l q = 1 = p_r q - p q_r and Q−q<ql,qr≤QQ - q < q_l, q_r \le Q [HarWri2008, Chapter III]. The function computes qlq_l from p−1 mod qp^{-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-11-02).