Back in the early 2000s, a student of mine was writing a thesis on binary quadratic forms. To force myself to learn enough about the subject to hold up my end of our thesis discussions, I wrote a set of elementary expository notes in 2004 (originally using SageMath, now updated using pure Python) mapping out the computational dictionary between indefinite integral binary quadratic forms , ideals in real quadratic fields, and simple continued fractions.
Over twenty years later, I have returned to those notes with the help of AI. With the help of ChatGPT (mostly, but also with the help of Gemini and Claude), I’ve completed a corrected, substantially expanded rewrite: Notes on indefinite integral binary quadratic forms with Python. For more details on the AI usage, please see the Acknowledgment section at the end of the paper. The LaTeX source, PDF, and companion standard-library Python scripts are all available on GitHub at wdjoyner/alg-graph-thry/tree/main/quad-forms.
The original goal was to clarify the classical three-way correspondence for positive nonsquare discriminants —paying careful attention to leading-coefficient signs, orientation, and the distinction between the ordinary class group
and the narrow class group
. In this new edition, all computations have been rewritten in pure standard-library Python (no external computer algebra system required), and a fourth, combinatorial viewpoint has been added: finite directed reduction graphs.

For a fixed discriminant , the primitive reduced forms serve as the vertices of a finite directed graph
, with edges
given by the right-neighbor reduction step. Every component is a directed cycle corresponding to a narrow ideal class. Using
as a running example, exact enumeration produces
reduced forms partitioned into four directed cycles of lengths
, giving
and
. Assigning logarithmic edge weights
in the continued-fraction direction
turns the principal cycle into a metric circle whose circumference recovers the positive-norm regulator
.
Exploring through algebraic graph theory led to several new sections and results:
- Equivariant twisted traces and genus theory: Let
be the permutation matrix of the reduction map
on
. While the ordinary permutation spectrum of
only records cycle lengths, twisting
by the sign-change involution
and the reflection
yields exact trace formulas. In particular,
counts the
-torsion of
, while
counts classes squaring to
—which we show equals twice the number of primitive representations
with
. For fundamental discriminants, both counts recover classical genus theory.
- Isospectral reduction graphs: At
and
, the unweighted directed reduction graphs are isomorphic—both have cycle lengths
and characteristic polynomial
—yet their narrow class groups are
and
, respectively. The twisted traces immediately tell them apart.
- Harmonic morphisms between nested orders: The “nested orders” in the title is shorthand for morphisms between the reduction graphs associated with nested orders. Specifically, an order
is associated with the finite directed graph
whose vertices are the primitive reduced quadratic forms of discriminant
—or equivalently, via the form–ideal dictionary, the oriented reduced invertible fractional
-ideals—with directed edges
given by the right-neighbor reduction step. Its connected components are finite directed cycles in bijection with the narrow class group
.Comparing the order of conductor
(
, two
-cycles) with the maximal order (
, one
-cycle) shows that ideal extension need not lift to a successor-preserving map of directed reduction graphs, since
. However, passing to the weighted metric circles and subdividing yields a degree-
covering—and hence a harmonic morphism of graphs.
- Further directions: The paper concludes with open questions on character-twisted dynamical zeta functions
, entropy and moment statistics of logarithmic edge weights, and
-rank invariants.
Everything can be reproduced out of the box by cloning the repository and running python3 verify_quadratic_forms.py and python3 research_quadratic_forms.py in the quad-forms/scripts directory. Feedback, comments, and pointers to related literature are very welcome!



You must be logged in to post a comment.