# ford-horocycle - The Ford circles read as horocycles of the modular surface, the closed horocycle `Im z = h` against the Farey stack, the unfolding that turns a horocycle integral into the stack's smoothed novelty, and the census of the Ford circles whose tangency point has every partial quotient at most `m`, for [apollonian](../../../notes/apollonian.md), `## The horocycle`. - `crossings` takes every reduced `a/b` in `[0, 1)` with `b <= bound`, completes `(a, b)` to a matrix of `SL(2, Z)` with bottom row `(b, d)`, maps five points of the line `Im z = 1` by it in exact rationals, one of them `-d/b + i`, and asserts that every image lies on the circle of centre `(a/b, 1/(2 b^2))` and radius `1/(2 b^2)` at height at most `1/b^2`, with equality at `x = -d/b`. It then counts, at the heights `h = Q^(-2)`, the Ford circles whose closed disc the line `Im z = h` meets, `0 <= h <= 1/b^2`, and asserts the count is `sum_(b <= Q) phi(b)`; the open-disc count is asserted to be `sum_(b < Q) phi(b)`, and the closed-disc count at `h = 1/(2 Q^2)` to be `sum_(b <= floor(Q sqrt 2)) phi(b)`. - `bridge` takes a test function `f` supported on `[1, 2]`, the `C^infinity` bump `exp(4 - 1/((u-1)(2-u)))` and the `C^2` bump `64 (u-1)^3 (2-u)^3` of `lab/py/smoothed-novelty`, forms the incomplete Eisenstein series `psi_f(z) = sum f(Im(gamma z))` over the cosets `Gamma_infinity \ SL(2, Z)`, and integrates it over the closed horocycle `x + ih`, `0 <= x < 1`, term by term: each coset with bottom row `(c, d)` contributes on `abs(x + d/c) <= sqrt(h - c^2 h^2)/c`, split at the inner hole where `Im(gamma z) > 2`, by Gauss-Legendre on each piece. It compares the sum with `h sum_(c <= h^(-1/2)) phi(c) g(c h^(1/2))`, `g(t) = int_R f(1/(t^2 (1 + v^2))) dv` by the same quadrature on the interval where the integrand is nonzero, and prints both, their gap, the main term `(3/pi) int f(w) w^(-2) dw`, the error `E` and `E/h^(3/4)`, at `h = 4^(-k)`, `k = 2..kmax`. - `census` walks the Stern-Brocot tree of `(0, 1)` from `1/2`, each node carrying its two neighbours, the direction of its last step and the length of its last run, and keeps a child only when its denominator is at most `2^jmax` and its run length at most `m`; the count `N_m(Q)` of nodes of denominator at most `Q`, the node `0/1` added, is read off a histogram. It first walks with no run bound to `2^jcontrol` and asserts `N(2^j) = sum_(b <= 2^j) phi(b)` at every `j`; then, at `m = 2` and `m = 3` to `2^jcheck`, asserts that the walk, the test "one of the two continued fraction expansions of `a/b` has every quotient at most `m`", and the rule "`a_1, ..., a_(n-1) <= m` and `a_n <= m + 1` on the expansion with `a_n >= 2`" pick the same fractions, and at every node that the mediant with its younger neighbour stays in the family while the mediant with its older neighbour stays exactly when `a_n <= m`. Then it prints, per octave `Q = 2^j`, `N_m(Q)`, `Q^(2 delta_m)`, their ratio, the octave exponent `log2(N(2Q)/N(Q))`, that exponent minus `2 delta_m`, the two-octave exponent `log4(N(4Q)/N(Q))`, and the least and greatest ratio on the quarter octaves of `[j, j + 1)`, with `delta_2 = 0.5312805062772051416` and `delta_3 = 0.705660908028` the pressure zeros of [beneath](../../../notes/beneath.md), `### The two dimensions of a run-length rule`. - The totients are sieved in numpy; the walk and the quotient tests are exact integers; the horocycle images are exact rationals. ## RUN - `uv run python mrlyprod/research/lab/py/ford-horocycle/ford_horocycle.py crossings`, `0.1` seconds. - `uv run python mrlyprod/research/lab/py/ford-horocycle/ford_horocycle.py bridge`, `21` seconds, `16` of them the two `k = 10` rows. - `uv run python mrlyprod/research/lab/py/ford-horocycle/ford_horocycle.py census`, `28` seconds, `19` of them the `m = 2` walk to `2^24`. - `uv run python mrlyprod/research/lab/py/ford-horocycle/ford_horocycle.py all`, `49` seconds. - `--bound 60`, `--kmax 10`, `--nodes 200`, `--jmax2 24`, `--jmax3 18`, `--jcontrol 10` and `--jcheck 9` are the dials. - Prints only, writes nothing, touches no network. ## WITNESSES - The lines of [apollonian](../../../notes/apollonian.md), `## The horocycle`. - `crossings`: `5510` exact image points on the `1102` Ford circles of `b <= 60`, every one on the Ford circle over `a/b` with top point `1/b^2` at `x = -d/b`; closed-disc counts `1, 2, 4, 32, 324, 542` at `Q = 1, 2, 3, 10, 32, 42` against `sum_(b <= Q) phi(b)`, open-disc counts `0, 1, 2, 28, 308, 530` against `sum_(b < Q) phi(b)`, and `1, 2, 6, 64, 628, 1086` at `h = 1/(2 Q^2)` against `sum_(b <= floor(Q sqrt 2)) phi(b)`. - `bridge`: the horocycle integral and `h sum phi(c) g(c h^(1/2))` agree to `7.7e-14` or better at every `h = 4^(-k)`, `k = 2..10`, on both bumps, `318453` cosets contributing at `k = 10`; the main terms are `0.167199591457466` and `0.201589480296982`; `E/h^(3/4)` stays between `-0.27` and `+0.46` on the smooth bump and between `-0.23` and `+0.41` on the `C^2` bump. - `census`: the unbounded walk reads `sum_(b <= Q) phi(b)` at every `Q = 2^j` to `2^10`, `318964` at the top; at `b <= 2^9` the three membership tests agree on `961` fractions at `m = 2` and `5118` at `m = 3`, the mediant with the younger neighbour stays in every case, `960` and `5117`, and the mediant with the older neighbour stays in `584` and `4026`, exactly the nodes with `a_n <= m`. - `census`, `m = 2`: `N_2(2^24) = 59104562`, `N_2/Q^(2 delta_2)` between `1.2272` and `1.2504` on the quarter octaves of `[22, 23)` and between `1.2301` and `1.2521` on `[23, 24)`; octave exponents `1.0431` and `1.0750` at `j = 22, 23`, octave exponent minus `2 delta_2` reading `+0.0475, -0.0480, +0.0477, -0.0453, +0.0405, -0.0336, +0.0265, -0.0194, +0.0124` at `j = 15` to `23`, two-octave exponents between `1.0590` and `1.0661` from `j = 15` to `j = 22`, against `2 delta_2 = 1.0625610125544`. - `census`, `m = 3`: `N_3(2^18) = 34078973`, `N_3/Q^(2 delta_3)` between `0.76762` and `0.76775` on the quarter octaves of `[17, 18)`, octave exponents `1.4113, 1.4114, 1.4112` at `j = 15, 16, 17`, two-octave exponents `1.4114, 1.4113` at `j = 15, 16`, against `2 delta_3 = 1.4113218160560`.