Skip to content

The Modular Group ​

The modular group PSL(2,Z)\mathrm{PSL}(2,\mathbb{Z}) is the group of 2×22×2 integer matrices of determinant 11, taken up to overall sign. It acts on the upper half-plane by Möbius transformations z↦az+bcz+dz ↦ \frac{az+b}{cz+d}, and the quotient is the modular surface — the object that continued fractions, binary quadratic forms, the Farey tree and the jj-invariant are all secretly about.

What makes it a good fit here is that it is a free product, Z/2∗Z/3\mathbb{Z}/2 * \mathbb{Z}/3. A free product has no relations to speak of, so every element is a word, and questions about the group become questions about words — which is combinatorics this catalogue already knows how to count.

The payoff at the end of the page: a conjugacy class in this group is a closed orbit of a flow, that orbit is a knot in the complement of a trefoil, and the knot's linking number with that trefoil is something you can read off the word by counting letters.

Two generators, three alphabets ​

The group is generated by

S=(0−110),T=(1101),S = \begin{pmatrix} 0 & -1 \\ 1 & 0\end{pmatrix}, \qquad T = \begin{pmatrix} 1 & 1 \\ 0 & 1\end{pmatrix},

with SS the inversion z↦−1/zz ↦ -1/z and TT the translation z↦z+1z ↦ z+1. In PSL\mathrm{PSL}, SS has order 22 and U=STU = ST has order 33; those two are the free factors.

But there are three useful alphabets, and they name the same elements:

alphabetletterswhat a word is
S, TS,\ Tthe geometric generatorsan alternating product Te0STe1S⋯T^{e_0}ST^{e_1}S\cdots — the exponents are a continued fraction
L, RL,\ R(1011)\begin{pmatrix}1&0\\1&1\end{pmatrix}, (1101)\begin{pmatrix}1&1\\0&1\end{pmatrix}a positive word, unique for any matrix with non-negative entries — and it is a path down the Stern–Brocot tree
necklaceL,RL,R up to rotationa conjugacy class — i.e. a closed geodesic

A matrix is a word

The peel is the subtractive Euclidean algorithm, so it never has to search.

InModularWord(ModularMatrix(1,1,1,2))\mathrm{ModularWord}(\mathrm{ModularMatrix}(1, 1, 1, 2))OutLR\text{LR}InModularWord(ModularMatrix(5,3,3,2))\mathrm{ModularWord}(\mathrm{ModularMatrix}(5, 3, 3, 2))OutRLRL\text{RLRL}InModularTrace(LRLR)\mathrm{ModularTrace}(\text{LRLR})Out77InModularSTWord(ModularMatrix(3,2,4,3))\mathrm{ModularSTWord}(\mathrm{ModularMatrix}(3, 2, 4, 3))Out[0,−2,−2,−2,0]\bigl\lbrack0, -2, -2, -2, 0\bigr\rbrack
source · editable

Why the peel never needs a search is worth a sentence: R−1MR^{-1}M subtracts row 2 from row 1 and L−1ML^{-1}M subtracts row 1 from row 2, so RR comes off when a≥ca ≥ c and b≥db ≥ d, and LL when c≥ac ≥ a and d≥bd ≥ b. Both conditions at once would force a=ca=c and b=db=d, hence determinant 00 — impossible. There is never a choice to make.

The trace sorts elements into three kinds, and the trichotomy is the whole geometry: elliptic elements (∣tr∣<2|\mathrm{tr}| < 2) are rotations of finite order, parabolic ones (=2=2) fix a single point on the boundary, and hyperbolic ones (>2>2) translate along a geodesic. Only the last kind has a closed geodesic, and a positive LRLR word is hyperbolic exactly when it uses both letters.

The trichotomy

All-L or all-R is parabolic: a word has to turn both ways to close up.

InModularKind(LR)\mathrm{ModularKind}(\text{LR})OutHyperbolic\text{Hyperbolic}InModularKind(ModularMatrix(1,5,0,1))\mathrm{ModularKind}(\mathrm{ModularMatrix}(1, 5, 0, 1))OutParabolic\text{Parabolic}InModularKind(ModularMatrix(0,−1,1,0))\mathrm{ModularKind}(\mathrm{ModularMatrix}(0, -1, 1, 0))OutElliptic\text{Elliptic}
source · editable

Words are continued fractions ​

The LL/RR word of a positive rational is its path down the Stern–Brocot tree, and the runs of that path are its continued fraction — with the last run one short, because the final step is the arrival rather than a turn. Three objects, one description.

One object, three names

π's famous convergent: three rights, seven lefts, fifteen rights.

InContinuedFraction(355113)\mathrm{ContinuedFraction}(\frac{355}{113})Out[3,7,16]\bigl\lbrack3, 7, 16\bigr\rbrackInSternBrocotPath(355,113)\mathrm{SternBrocotPath}(355, 113)OutRRRLLLLLLLRRRRRRRRRRRRRRR\text{RRRLLLLLLLRRRRRRRRRRRRRRR}InFromSternBrocotPath(RLR)\mathrm{FromSternBrocotPath}(\text{RLR})Out53\frac{5}{3}InFromContinuedFraction([3,7,16])\mathrm{FromContinuedFraction}(\bigl\lbrack3, 7, 16\bigr\rbrack)Out355113\frac{355}{113}
source · editable

The Fibonacci fractions alternate perfectly — RLRLR…R L R L R \ldots — which is the sense in which the golden ratio is the "most irrational" number: its path never commits to a direction, so no convergent is ever unusually good.

Farey

Consecutive Farey fractions satisfy ps − qr = ±1 — a determinant, i.e. a group element.

InFareySequence(5)\mathrm{FareySequence}(5)Out[0,15,14,13,25,12,35,23,34,45,1]\bigl\lbrack0, \frac{1}{5}, \frac{1}{4}, \frac{1}{3}, \frac{2}{5}, \frac{1}{2}, \frac{3}{5}, \frac{2}{3}, \frac{3}{4}, \frac{4}{5}, 1\bigr\rbrackInFareyNeighbours(1,3,1,2)\mathrm{FareyNeighbours}(1, 3, 1, 2)OutTrue\mathrm{True}InFareyNeighbours(1,3,2,3)\mathrm{FareyNeighbours}(1, 3, 2, 3)OutFalse\mathrm{False}
source · editable

Closed geodesics are necklaces ​

Here is the step that turns geometry into counting. Conjugating a positive word by its own first letter rotates it: x−1(xw)x=wxx^{-1}(xw)x = wx. So a conjugacy class of positive words is precisely a word up to cyclic rotation — a binary necklace.

And a hyperbolic conjugacy class is a closed geodesic on the modular surface. So:

closed geodesics of symbolic length nn   =  \;=\; binary necklaces of length nn, less the two constant ones (which are parabolic, not hyperbolic).

That is a closed form, 1n∑d∣nφ(d) 2n/d−2\frac{1}{n}\sum_{d \mid n} \varphi(d)\,2^{n/d} - 2, and the primitive geodesics — those not a repeat of a shorter one — are counted by the aperiodic necklaces, the Lyndon words: 1n∑d∣nμ(d) 2n/d\frac{1}{n}\sum_{d \mid n} μ(d)\,2^{n/d}.

Every geodesic of a given length

Named by the least rotation, which is the canonical name of a necklace.

InModularClasses(4)\mathrm{ModularClasses}(4)Out[LLLR,LLRR,LRLR,LRRR]\bigl\lbrack\text{LLLR}, \text{LLRR}, \text{LRLR}, \text{LRRR}\bigr\rbrackInModularClass(RLL)\mathrm{ModularClass}(\text{RLL})OutLLR\text{LLR}InModularClass(LRL)\mathrm{ModularClass}(\text{LRL})OutLLR\text{LLR}InIsPrimitiveClass(LRLR)\mathrm{IsPrimitiveClass}(\text{LRLR})OutFalse\mathrm{False}
source · editable

The word length is the geodesic's symbolic period — how many times it crosses the fundamental domain. Its geometric length is ℓ=2 arccosh(∣tr∣/2)ℓ = 2\,\mathrm{arccosh}(|\mathrm{tr}|/2), so the trace is the real weight, and the two orderings do not agree: LLLRLLLR and LRLRLRLR have the same word length but traces 55 and 77. The shortest closed geodesic on the modular surface is LRLR, with trace 33; its fixed point is the golden ratio.

The same cycles, as quadratic forms ​

Gauss got to these cycles from a completely different direction, and it is worth seeing that they are the same ones.

A binary quadratic form is ax2+bxy+cy2ax^2 + bxy + cy^2, carried by its triple (a,b,c)(a,b,c), with discriminant D=b2−4acD = b^2 - 4ac. The modular group acts on forms by substituting (x,y)↦(px+qy,  rx+sy)(x,y) ↦ (px+qy,\; rx+sy), the discriminant is invariant, and the orbits are the classes — the objects class numbers count.

When D>0D > 0 and is not a perfect square the form is indefinite, and the thing that makes it belong here happens: a class does not contain one distinguished reduced form but a whole cycle of them. Step round that cycle with ρρ and you are running the continued fraction of the form's root; it closes because that expansion is periodic. So

a class of indefinite forms == a cycle of reduced forms == a periodic continued fraction == a closed geodesic.

A class is a cycle

The cycle length is always even — ρ flips the sign of the leading coefficient.

InFormCycle(QuadraticForm(1,1,−1))\mathrm{FormCycle}(\mathrm{QuadraticForm}(1, 1, -1))Out[QuadraticForm(1,1,−1),QuadraticForm(−1,1,1)]\bigl\lbrack\mathrm{QuadraticForm}(1, 1, -1), \mathrm{QuadraticForm}(-1, 1, 1)\bigr\rbrackInReducedForms(60)\mathrm{ReducedForms}(60)Out[QuadraticForm(−6,6,1),QuadraticForm(−3,6,2),QuadraticForm(−2,6,3),QuadraticForm(−1,6,6),QuadraticForm(1,6,−6),QuadraticForm(2,6,−3),QuadraticForm(3,6,−2),QuadraticForm(6,6,−1)]\bigl\lbrack\mathrm{QuadraticForm}(-6, 6, 1), \mathrm{QuadraticForm}(-3, 6, 2), \mathrm{QuadraticForm}(-2, 6, 3), \mathrm{QuadraticForm}(-1, 6, 6), \mathrm{QuadraticForm}(1, 6, -6), \mathrm{QuadraticForm}(2, 6, -3), \mathrm{QuadraticForm}(3, 6, -2), \mathrm{QuadraticForm}(6, 6, -1)\bigr\rbrackInFormClassNumber(60)\mathrm{FormClassNumber}(60)Out44InFormClassNumber(12)\mathrm{FormClassNumber}(12)Out22
source · editable

The stabiliser of a form is generated by its automorph, built from the fundamental solution of Pell's equation t2−Du2=4t^2 - Du^2 = 4:

((t−bu)/2−cuau(t+bu)/2),\begin{pmatrix} (t - bu)/2 & -cu \\ au & (t + bu)/2 \end{pmatrix},

whose determinant is (t2−Du2)/4=1(t^2 - Du^2)/4 = 1 and whose trace is tt. Since t>2t > 2 that matrix is hyperbolic — so the form's class really is one of the closed geodesics above, and it has an LRLR word like any other.

Pell, the automorph, and back to a word

The automorph fixes the form, and its word is the geodesic the class names.

InPellSolution(5)\mathrm{PellSolution}(5)Out[3,1]\bigl\lbrack3, 1\bigr\rbrackInFormAutomorph(QuadraticForm(1,1,−1))\mathrm{FormAutomorph}(\mathrm{QuadraticForm}(1, 1, -1))OutModularMatrix(1,1,1,2)\mathrm{ModularMatrix}(1, 1, 1, 2)InFormAction(QuadraticForm(1,1,−1),FormAutomorph(QuadraticForm(1,1,−1)))\mathrm{FormAction}(\mathrm{QuadraticForm}(1, 1, -1), \mathrm{FormAutomorph}(\mathrm{QuadraticForm}(1, 1, -1)))OutQuadraticForm(1,1,−1)\mathrm{QuadraticForm}(1, 1, -1)InModularWord(FormAutomorph(QuadraticForm(1,1,−1)))\mathrm{ModularWord}(\mathrm{FormAutomorph}(\mathrm{QuadraticForm}(1, 1, -1)))OutLR\text{LR}
source · editable

That the ρρ-cycles really are the equivalence classes is the load-bearing claim, and it is checked against an oracle that never mentions ρρ: given two forms, a transforming matrix must have a first column (p,r)(p,r) with f(p,r)=a′f(p,r) = a', and along the resulting family the middle coefficient moves in steps of exactly 2a′2a' — so the matrix is solved for rather than searched, and the check is exact.

The knots they draw ​

Now the geometry. The modular flow is the geodesic flow on the unit tangent bundle of the modular surface, and its closed orbits are exactly the hyperbolic conjugacy classes above. The striking fact is what that unit tangent bundle is:

SL(2,Z)\SL(2,R)  ≅  S3∖trefoil.\mathrm{SL}(2,\mathbb{Z}) \backslash \mathrm{SL}(2,\mathbb{R}) \;≅\; S^3 ∖ \text{trefoil}.

The space the flow lives in is the complement of a trefoil knot in the 33-sphere. So every closed orbit is a closed curve in that complement — a modular knot. Étienne Ghys proved that these are precisely the Lorenz knots, the periodic orbits of the Lorenz attractor, and that their linking number with the missing trefoil has a completely elementary description:

lk(kγ,trefoil)  =  Ψ(γ)  =  #R−#L.\mathrm{lk}(k_γ, \text{trefoil}) \;=\; Ψ(γ) \;=\; \#R - \#L .

Count the letters. That is the linking number.

Ghys's theorem, as a calculation

A geodesic that turns equally both ways has linking number zero.

InLinkingWithTrefoil(LLRR)\mathrm{LinkingWithTrefoil}(\text{LLRR})Out00InLinkingWithTrefoil(LRRRR)\mathrm{LinkingWithTrefoil}(\text{LRRRR})Out33InWordSymbol(LRRRR)\mathrm{WordSymbol}(\text{LRRRR})Out33InLinkingWithTrefoil(LLLR)\mathrm{LinkingWithTrefoil}(\text{LLLR})Out−2-2
source · editable

Where the arithmetic comes in ​

Counting letters is one description of that linking number. The other comes from number theory and looks nothing like it. Rademacher's function is

Φ(abcd)=a+dc−12 sign(c) s(d,∣c∣),c≠0,Φ\begin{pmatrix} a & b \\ c & d\end{pmatrix} = \frac{a+d}{c} - 12\,\mathrm{sign}(c)\,s(d,|c|), \qquad c ≠ 0,

where s(h,k)=∑j=1k−1( ⁣(jk) ⁣)( ⁣(hjk) ⁣)s(h,k) = \sum_{j=1}^{k-1} \left(\!\left(\tfrac{j}{k}\right)\!\right)\left(\!\left(\tfrac{hj}{k}\right)\!\right) is a Dedekind sum — the same sum that appears in the transformation law of the Dedekind eta function and in the exact formula for the partition numbers. The Rademacher symbol corrects ΦΦ into a class function:

Ψ(M)=Φ(M)−3 sign(c(a+d)).Ψ(M) = Φ(M) - 3\,\mathrm{sign}\big(c(a+d)\big).

Nothing in that formula mentions words. That ΨΨ equals #R−#L\#R - \#L on every hyperbolic element is the theorem, and it is what the package's tests check — one side by brute-force Dedekind sums over the matrix, the other by counting letters in a string.

The other side of the identity

Φ alone is not conjugation-invariant; only the corrected Ψ is.

InDedekindSum(4,3)\mathrm{DedekindSum}(4, 3)Out118\frac{1}{18}InRademacherPhi(ModularMatrix(1,7,0,1))\mathrm{RademacherPhi}(\mathrm{ModularMatrix}(1, 7, 0, 1))Out77InRademacherPhi(LLLR)\mathrm{RademacherPhi}(\text{LLLR})Out11InRademacherSymbol(LLLR)\mathrm{RademacherSymbol}(\text{LLLR})Out−2-2
source · editable

The Dedekind sums are computed straight from the definition and then checked against reciprocity,

s(h,k)+s(k,h)=−14+112(hk+kh+1hk),s(h,k) + s(k,h) = -\tfrac14 + \tfrac{1}{12}\left(\tfrac{h}{k} + \tfrac{k}{h} + \tfrac{1}{hk}\right),

which is an independent enough statement to catch any slip in the sawtooth.

Things worth knowing ​

  • The sign in PSL\mathrm{PSL} is real. Rebuilding a matrix from its S/TS/T word can hand back −M-M. That is not a bug; it is the ±I± I the group quotients out, and every comparison here is up to that sign.
  • A word has to turn both ways. All-LL and all-RR words are parabolic — they fix a cusp rather than a geodesic — which is why the necklace count is always two short of the full one.
  • Word length is not geodesic length. The symbolic period counts crossings of the fundamental domain; the trace measures the actual length. Sorting geodesics by one does not sort them by the other.
  • ΦΦ is a quasimorphism, not a homomorphism. It is only almost additive, and it is only after the sign\mathrm{sign} correction that it becomes an invariant of the closed orbit. Rotating a positive word cannot show the difference — the correction is constant on the positive cone — but conjugating by SS does.

What this connects to ​

  • Numeral systems — the continued fraction here is a numeral system, and the Stern–Brocot path is its digit string.
  • Binary necklaces and Lyndon words in the enumeratio catalogue count the closed geodesics exactly.
  • Class numbers and Pell's equation — the form cycles above are the arithmetic face of the same objects, and FormClassNumber counts them.
  • Lorenz knots and braids are the natural next step: Ghys's theorem says the modular knots are Lorenz knots, which are closures of positive braids, so the braid group is what turns these words into actual knot diagrams and invariants.