InfoMod: A visual and computational approach to Gauss' binary quadratic forms
Ayberk Zeytin, Hakan Ayral, A. Muhammed Uluda\u{g}

TL;DR
InfoMod is a software tool that visualizes and computes properties of Gauss' binary quadratic forms, connecting classical theories with modern graph representations for educational and research purposes.
Contribution
It introduces a novel software that integrates classical and recent theories of binary quadratic forms through visual and computational methods.
Findings
Demonstrates Gauss' reduction algorithm visually
Provides new insights into form representation and classification
Facilitates exploration of ambiguous and reciprocal forms
Abstract
InfoMod is a new software and application devoted to the modular group, PSL2(Z). It has algorithms that deals with the classical correspondences among continued fractions, geodesics on the modular surface and binary quadratic forms. In addition the software implements the recently discovered representation of Gauss' indefinite binary quadratic forms and their classes in terms of certain infinite planar graphs (dessins) called \c{c}arks. InfoMod illustrates various aspects of these forms, i.e. Gauss' reduction algorithm, the representation problem of forms, ambiguous and reciprocal forms. It can be used as an educational tool, and might be used to explore some new facts about these objects.
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
InfoMod: A visual and computational approach to Gauss’ binary quadratic forms
Ayberk Zeytin111 Galatasaray University, Çiragan Cad. No 36 Beşiktasş 34349 Istanbul, Turkey
This work is supported by the TÜBİTAK grant 113R017 and the GSU grant 15.504.002. , Hakan Ayral111 Galatasaray University, Çiragan Cad. No 36 Beşiktasş 34349 Istanbul, Turkey
This work is supported by the TÜBİTAK grant 113R017 and the GSU grant 15.504.002. , A. Muhammed Uludağ111 Galatasaray University, Çiragan Cad. No 36 Beşiktasş 34349 Istanbul, Turkey
This work is supported by the TÜBİTAK grant 113R017 and the GSU grant 15.504.002.
Abstract
InfoMod is a new software and application devoted to the modular group, . It has algorithms that deals with the classical correspondences among continued fractions, geodesics on the modular surface and binary quadratic forms. In addition the software implements the recently discovered representation of Gauss’ indefinite binary quadratic forms and their classes in terms of certain infinite planar graphs (dessins) called çarks. InfoMod illustrates various aspects of these forms, i.e. Gauss’ reduction algorithm, the representation problem of forms, ambiguous and reciprocal forms. It can be used as an educational tool, and might be used to explore some new facts about these objects.
1 Introduction
InfoMod is an innovative software which aims to visualize the deep arithmetic questions encircled by finitely generated infinite index subgroups of the modular group, which is by definition the the group consisting of integral matrices of determinant , denoted by . These lead to the study of algebraic number theory of real quadratic number fields. Its intended use is instructive as well as research-level visual explorations of the modular group, binary quadratic forms, their geodesics, form classes, class groups and some algorithms such as Gauss’ reduction algorithm.
One of the main problems of algebraic number theory is to understand factorization in the ring of integers of number field. The class group and its size, called the class number, are the prime indicators of how unique factorization in a ring of integer is. There are several important questions and conjectures about class groups and class numbers. One needs to recourse to algorithms for explicit computations of these groups. Since these problems resisted centuries of attacks, these are also important from the computational perspective and present many challenges.
The simplest case of quadratic number fields, can be understood in terms of the binary quadratic forms of Gauss. Here the main difficulty is in the real quadratic case, which corresponds to indefinite binary quadratic forms. These forms can be represented as the fixed points of the elements of the modular group, and this group is the main hero of our paper.
The modular group is isomorphic to the free product . As such its elements can be represented as the set of half-edges of an infinite rooted bipartite tree with a planar structure, called the Farey tree. In order to visualize the elements of , we broaden the branches of until they touch each other. The resulting mantra-like model of with cells representing its elements, fills the entire plane and is called the sunburst. It allows one to simultaneously represent up to approx. 1000 elements of the modular group on a computer screen with a standard resolution. By moving the centre of this sunburst (operation which is implemented in InfoMod), it is possible to represent another 1000-element portion of the modular group. By clicking over a cell, it is possible to obtain a detailed information on the group element represented by this cell. In particular, it is possible to see the corresponding binary quadratic form as well as its discriminant.
Now we alter our perspective slightly to get another representation of forms. Suppose that the element represents a reduced real binary quadratic form . As a matter of fact, every element different from identity in the subgroup also represents the same reduced form. The group acts on the tree in a natural way, and the quotient graph also represents . Given an edge of the quotient graph, it is possible to recover the form. These graphs are called çarks. They look same as except that they have exactly one circuit inside, called the spine. InfoMod makes it possible to pass, from the cell of , to its çark.
Many notions related to forms acquires a new formulation in terms of these graphs. For example, equivalent forms have isomorphic çarks. The reduction algorithm of Gauss simply moves the edge characterizing the form towards the spine of the çark. This new formulation already served the first named author to give a solution of the representation problem of forms and improve on the Gauss reduction algorithm, [20]. InfoMod makes it possible to observe how these algorithms are carried out on the graph.
Paper is organized as follows: In the next section we overview the theoretical background outlined in the above lines. More details can be found in [18]. The third section is devoted to the software implementation of InfoMod, where we present a code library which help represent and do computations on binary quadratic forms, including reductions and enumeration of other forms which share a cycle with a reduced form. Later we present an interactive visualization application to explore the mentioned sunburst and çarks visually. We plan to build into InfoMod some new features pertaining to the outer automorphism of the group PGL in the future.
2 Preliminaries
This section is devoted to recalling the basic facts around the modular group, binary quadratic forms, reduction theory and çarks. There are many beautiful texts on the subject among which we must note the first historically systematic treatment by Gauss, [8]. We refer to [2, 3] for a modern treatment of the topics related to binary quadratic forms.
2.1 Modular group, binary quadratic forms and geodesics
The modular group, , acts on the upper half plane via Möbius transformations, i.e. for and , we have . This action leaves the Poincaré metric on invariant. Hence the geodesics of this metric, i.e. lines that are vertical to the real line and half circles whose centers are on the real line, are mapped onto geodesics by .
An integral binary quadratic form (or BQF for short) is a homogeneous polynomial of degree two in two variables with integer coefficients. A BQF , is usually denoted by or its matrix form . We call primitive if the greatest common divisor of , and is .
An element has two fixed points, which are, by definition, roots of the quadratic equation . To we associate the BQF ; where is the greatest common divisor of , and , so that is by definition primitive. The discriminant of a BQF is defined as . A BQF is called degenerate if is a perfect square, positive definite if and , negative definite if and . Finally, a BQF is called indefinite if .
We may classify elements on according to their traces. Namely, is called elliptic, parabolic and hyperbolic if , and , respectively. In other words, parabolic elements have a unique real fixed point. Elliptic elements have two fixed points one in the upper half plane and the other in the lower half plane. Hyperbolic elements have two distinct real fixed points. The geodesic in joining the two fixed points of a hyperbolic element 111One may define attracting and repelling fixed points of by looking at its action along this geodesic. This distinction is unnecessary for our purposes. which is merely a half circle of center and radius is called the geodesic associated to and denoted by . Observe that the classification of elements of and BQFs are quite parallel. Namely, parabolic elements give rise to degenerate BQFs, elliptic elements give rise to definite BQFs and hyperbolic elements give rise to indefinite BQFs.
2.2 Reduction Theory of BQFs
The modular group acts on the set of non-degenerate binary quadratic forms by change of variables. More precisely, given and an element we define to be the BQF associated to the symmetric matrix ; where stands for the transpose of . In particular, we say that two forms and are equivalent if there is an so that . This action leaves the discriminant invariant, that is if and are equivalent, and the equivalence class of a form is denoted by . Therefore acts on the set of non-degenerate BQFs of the same discriminant, say a square-free integer , denoted by . In the search for a canonical representative of each class, in [8], Gauss have defined a form to be reduced whenever . It turns out that whenever is definite (positive of negative) then there is a unique reduced BQF in its class, . If is indefinite, then there are at least two reduced forms in . Gauss have also given an algorithm which takes any non-degenerate BQF as an input and produces an equivalent reduced BQF, described in [8].
One must note that there are other inequivalent notions of being reduced. For instance, Lagrange defines a BQF, say , to be reduced when and if either or . Just as in the case of Gauss, every -class of a positive definite BQF contains a unique Lagrange reduced form which can be found by the an algorithm that takes any non-degenerate BQF as input and produces an equivalent Lagrange reduced BQF, see the proof of [5, Theorem 2.8]. According to Zagier, an indefinite BQF is called reduced if both and are satisfied by . We refer to [19, § 13] for further details.
2.3 Ideal classes in quadratic number fields
A field is called a number field whenever it is a finite extension of . The dimension of as a vector space over is called the degree of the extension and denoted by . is called quadratic quadratic whenever . In this case, one can always find a square-free integer with the property that . If , then we say that the extension is real and if then the extension is called imaginary. The map sending an element to is the only non-trivial automorphism of which, together with identity, form the Galois group of .
An element is called an algebraic integer if it is a root of a monic polynomial . It is not so hard to see that the set of algebraic integers in , which will be denoted by , depends on the square-free integer in the following manner: if is congruent to modulo then , and otherwise. In particular, is a Dedekind ring. The property of being a unique factorization domain (UFD) is equivalent to being a principal ideal domain(PID). And for any given ideal, , of there are at most elements and of so that the ideal generated by and , denoted , is equal to . This means fractional ideals of , that is two dimensional -modules, , of for which there is an element so that is an ideal of , can also be generated by at most elements. Given a fractional ideal , we say that the pair is oriented if . The set of oriented fractional ideals is an abelian group under multiplication, denoted by . The subset of principal fractional ideals, that is subsets of the forms where , is a subgroup of denoted by , and the quotient is called the narrow ideal class group of . The ideal class group of , denoted , is defined as the quotient ; where is the multiplicative group of fractional ideals of . The group is naturally a subgroup of . is of index if admits an element of norm and and are isomorphic if there are no elements of norm in .
2.4 Çarks and ideal classes
The orbit of the geodesic in the upper half plane joining , marked with , to , marked with , is a bipartite ribbon graph222A bipartite graph is a graph whose vertices can be decomposed into two disjoint sets so that no two edge belonging to the same set are joined by an edge. A ribbon graph is a graph together with a cyclic ordering of edges emanating from each vertex. in , where the vertices decompose naturally into two sets and . The orientation is induced from the orientation of . This graph is called the (bipartite) Farey tree and denoted by , see Figure 1. Vertices of type are always of valency (or order or degree) and vertices of type are always of valency .
Given any element , by restricting the action of on to an action on we can consider the quotient of by the subgroup generated by . The quotient is a bipartite ribbon graph which we refer to as a çark. The classification of elements of reflects itself in its çark, see Figure 2.
When is elliptic of order or we obtain a rooted tree. If is parabolic then the corresponding çark has a unique cycle, named spine, which is assumed to be oriented counter-clock-wise and finitely many rooted trees attached to this cycle each of which is a rooted tree attached to vertices of type of the spine. Such components are called Farey components of the çark. They all point outwards. When is hyperbolic, once again the graph has a unique cycle, named spine, having finitely many vertices. To each vertex of type there is a Farey component attached. In this case, Farey components must point both inwards and outwards.
As a result of the construction the cosets correspond in a one to one fashion to edges of the çark . So we conclude that there is a one to one correspondence between the set of edges of the çark corresponding to the form and element of the equivalence class , see [18, § 2] for details.
3 Software Design
3.1 Components
InfoMod consists of a shared library coded in C for computationaly heavy functions, some convenience wrapper classes for Matlab and Python to facilitate interfacing the library, and a visualization application written in ActionScript version 3.
The native code shared library implements the computation of the two methods of reduction (çark and Gauss), enumeration of quadratic forms residing on a spine and computation of the signature of a spine. On the other hand wrapper classes to access the library from Matlab and Python environments provide an easy way to invoke library functions, while providing an Object Oriented representation for the involved quadratic forms. Source code for Matlab and Python libraries are available online https://github.com/hayral/infomod. Many functions which aren’t computationaly demanding, such as evaluating a form at a point, obtaining the matrix representation of the form, or querying the spinality, primitivity and reducedness, are implemented in the wrapper classes, as the overhead of function invocation from dynamic library outweights the benefits for those cases.
3.2 Visualization of the modular group and Sunburst
While Matlab and Python libraries are designed to be used as part of other computational code, the interactive visualization application of InfoMod is designed as an exploration tool to provide insight. It uses the same code base as the libraries, but ported to ActionScript programming language; as we planned to deploy this application to web and mobile, invoking our native code shared library or relying on Matlab/Python was not an option. Before elaborating on the visualization aspect of the software, let us define the underlying mathematical structure that visualization is designed to explore.
Modular group is generated by two torsion elements and of orders and , respectively. There are no relations among and hence we have the isomorphism . So every element in can be written as a word in , and . Without loss of generality, we assume that the length of words, denoted by , are of minimal length333The length of a word is defined to be the number of letters (, and ) appearing in the word.. Given two words and in , by we denote the word which is equal to the common initial part of the words and . For instance, for and we have .
Let us now construct the slit disk, which we denote by . We start with a standard disk, split into three equal area pieces by lines from the center of the disk. The so obtained three cells are labeled as , and . To the circumference of this disk we glue an annulus which is also divided in pieces by prolonging the lines that were used to divide the initial disk. This time, the 3 new cells are identified with , and , respectively. The next step is to attach two annuli each of which is divided evenly into 6 pieces via first prolonging the existing lines and then adding 3 more lines so that the cell labeled is neighbors with the cells and , and these are in turn neighbors with and in the second annulus. Similarly, the cell labeled is neighbors with the cells and , and these are in turn neighbors with and in the second annulus and finally the cell labeled is neighbors with the cells and , and these are in turn neighbors with and in the second annulus. Inductively, we obtain a disk, to which we will refer as the slit disk, where each cell is labeled with a word in , and see Figure 4. As a result of the construction given above we have a one to one correspondence between elements of and cells in .
If the a cell in is labeled as and ending with or then there are 4 cells surrounding it: three of them are labeled with , and . Remark that where is one of , or . The fourth neighbor, say , of satisfies with . Similarly, if is a word ending with , then there are 5 cells surrounding this cell. Three of them, which satisfies , are labeled with , and . The remaining two words and satisfy and and .
The main visualization of the application is the above described slit disc (sunburst) type diagram. When the user moves the mouse pointer over one of the cells on , a blue line indicates the path to the center of the disc as it passes by the centers of the parent cells. Due to the exponential growth of the number of child nodes on a binary tree, this sunburst type visualization can only depict eight levels of depth for common mobile device and desktop screen resolutions. Once a cell representing an element of is left clicked, a radial menu appears with options. Apart from the elements in the menu related to the visualization of the corresponding binary quadratic form along with its neighbors the button “Move to Center” is used to interact with elements of the modular group which are at depth nine or further. Namely, on click by conjugation, the chosen element becomes the center of the displayed and all the other elements are translated accordingly. In this fashion, one may travel arbitrarily far from the actual center.
Challenges implementing the web and mobile visualization app
ActionScript isn’t designed with scientific computing or high performance computing as primary concern, but it has all the features of a modern managed object oriented language [6], and provides access to hardware accelerated graphics capabilities of the underlying operating system. Flash runtime is generally deployed in the form of a browser plugin (Flash Player), but standalone applications can be deployed as independent executables without requiring being embedded in a browser.
ActionScript and the Flash Runtime has no direct access to mathematical computing libraries; therefore one of the challenges was the necessity to implement all mathematical structures and computation codes from scratch; including a class to represent a binary quadratic form, a class to represent an element from the modular group, and minimal linear algebra to operate on the matrix representation of elements of modular group444Standard ActionScript libraries do provide a native matrix class, but in our case we needed some extra functions like trace,transpose and multiplication with specific constants (i.e. generators of modular group and some of their compositions) which reduces to simple swap and sign change of values when optimized..
Another challenge was the code being run by a JIT compiling VM with automatic garbage collection which is the Flash Runtime. Even though we didn’t need C/C++ like native code speed, having numerous visual objects (up to the order of ) visible on the screen with many destroyed and some newly created at each user interaction cause a heavy burden on the garbage collector; therefore we employed some object pooling and caching methods to maintain interactive speeds and minimize stutter caused by garbage collector. Another challenge was to port the same application to mobile platforms, namely Android and iOS. AIR compiler provides platform independence to some degree, but user experience is not the same due to differences on hardware features. One of the two main manifestations of this are the resolution and aspect ratio differences of different mobile devices requiring the size and placement of visual objects to be flexible and independent of screen size (including fonts and text rendering which is not as fast and flexible on mobile platforms); and the other being the relatively limited resources in terms of computing power and memory.
3.3 Visualization of the çarks and geodesics
Let us now fix a hyperbolic element . The çark visualization consists of edges forming the spine (which are called semi-reduced) and the rooted Farey trees attached to it. The correspondence between edges of and forms that are equivalent to can be investigated by hovering the mouse cursor over, thus highlighting the edge green and updating the top left corner green label with the corresponding forms expression. The form corresponding to is indicated as a red edge, and has a label for its expression on top left.
Every non-reduced form in the equivalence class (i.e. edges not on the spine) can be clicked on to expand the child edges, and the whole graph re-scales and positions itself to fit on available screen space; yet as the trees are infinite deeper child edges get smaller angular ranges to position themselves.
Every quadratic form on the spine of the çark also corresponds to a geodesic in upper half-plane. Once an edge is selected on the çark visualization, the geodesic of the form corresponding to selected edge can be plotted, both in or in the unit disk, .
Flips
There is a close relationship between mapping class groups of surfaces of genus with punctures and the groupoid whose objects are bipartite ribbon graphs of genus with punctures and morphisms are flips (or Whitehead moves or HI moves), see Figure 8. Indeed, flips do not change the invariants and and act transitively on the set of ribbon graphs of fixed and . Then, as a result of a generalization of Dehn-Nielsen-Baer theorem, [7, Theorem 4.8], we obtain the required injection. InfoMod can make explicit computations using flips in the case of annulus.
4 Representation problem
Representation problem deals with the existence and values of integer solutions, that makes a given binary quadratic form equal to a chosen integer. For the positive definite forms if integer solutions exist, they are finitely many; on the other hand for indefinite case if an integer solution exists, then there is a family of countably infinite pairs of integers. Each solution pair can be obtained by multiplying a non-trivial solution with an automorphism of the form of appropriate order.
It must be mentioned that there is a non-exact algorithm presented on the web-page “https://www.alpertron.com.ar/quad.java”. In addition, in [14] Lagrange has put forward a method to solve similar equations which run in exponential time, which are then further optimized in [15]. Some related algorithms have been investigated in [13]. Pell equation is another class of such equations whose theory is well developed, [10]. In [9] equations of the form are discussed. Algorithms concerning the case (sometimes referred to as non-Pellian equation), have been discussed by Lagarias in [12].
In [12] Lagarias proposes a modification to classical reduction method, through which he established a worst case time complexity of with being the time complexity of the chosen n-bit multiplication algorithm, yielding in case regular multiplication is employed. In [1] Buchmann improves the complexity analysis of Lagarias to without changing the algorithm, using the observation that if for a form neither or 555with being the reduction operator, defined as and is reduced then the absolute value of the first coefficient () must be at least twice the absolute value of the last coefficient (). Eventhough a faster reduction algorithm of time complexity is presented earlier by Schönhage [16], the asymptotic acceleration surpasses the other algorithms only when the number of binary digits of the coefficients of the form to be reduced is in the order of or greater.
The representation problem is closely related to class group computations in quadratic number fields. For instance, in [17], Shanks developed a new method for the computation of class numbers of quadratic number fields, which further resulted in a new factorization of large integers. The thesis of Jacobson, [11], discusses such algorithms in detail. Similar results for general number fields are presented in [4].
Here, we present an algorithm to solve the representation problem given a binary quadratic form and an integer to solve for. The algorithm relies on two things: first to find another form which is part of a face with label equal to given integer if such a face exists (or to show that such a face doesn’t exist), and second to compute the path leading from this form found to the form given.
Equipped with reduction and graph topology of çarks, the computation of integer solutions proceeds as follows: First the software performs the reduction while recording the path down to the spine of its çark as a sequence of generators (algorithm 1,line 2), then it travels along the spine and this time it records the forms belonging to spine as a sequence (l.4). Depending on the sign of the chosen integer to solve the quadratic form for, software generates all non-spinal neighbours of recorded spinal forms, but records only those with coefficients having same sign as the chosen integer (l.8-17). This list of non-spinal neighbours of the same sign with desired integer, serves as the root nodes of a simultaneous breadth-first search along the graph of the spine (l. 18-36). This breadth-first search travels away from the spine (inwards or outwards depending on the sign). Even though every form yields two new forms once expanded on the direction of increasing distance, the number of accumulated forms does not increase exponentially; the reason for this boils down to the coefficients of neighbouring forms growing or decreasing (depending on the travel being directed towards or away from the spine) at a non-linear speed when multiple forms are traversed. At each iteration of breadth-first search software compares the absolute value of the coefficients of the newly expanded forms with the absolute value of the integer being searched, and discards the form if the first or last coefficient of the form is greater than this in absolute value (l.27-32). If all the forms on breadth-fist search list gets discarded, the loop terminates (l.19) and algorithm doesn’t return an integer pair, indicating that there are no integer solutions (l.37-38). If the search finds a form adjacent to a face with chosen label, it breaks from the loop after marking the found form (l.21-23), and the path from the found form and its entry point to spine is calculated (l.40-41). At this point as we have paths from both starting and found form to the spine; to build a continuous path from found form to starting form, we only need the path that connects the entry points of those paths to the spine. Once the complete paths missing part on the spine is calculated (l.42), they can be combined to build the path leading from found form to starting form (l.43). The rest is nothing more than converting this path which actually is a sequnce of generators on to a matrix (l.44), and then to decide which of the two orthogonal basis solves the form when multiplied with the path in matrix form (l.45-49).
For the algorithm listing of functions referenced in Algorithm.1 see Appendix, for the listing of çark reduction algorithm see [20].
5 Conclusions
In this paper we present the software package InfoMod for representing and operating on binary quadratic forms. It consists of a library identically implemented in Matlab and Python666source code available at https://github.com/hayral/infomod, which can compute reduction of binary quadratic forms and solve the representation problem. It also contains an interactive visualization application available for web 777 http://math.gsu.edu.tr/azeytin/infomod/node/3 and mobile 888 https://play.google.com/store/apps/details?id=air.com.hkn.infomod platforms, which allows to observe the intricate patterns of forms’ properties plotted according to their natural topology, and practically compute the reductions/representation problem solutions without writing code to invoke the libraries.
APPENDIX
In this section you can find the algorithm listings for the functions invoked by Algorithm 1: Representation Problem Solver.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1] Ingrid Biehl and Johannes Buchmann. An analysis of the reduction algorithms for binary quadratic forms. In Voronoi’s Impact on Modern Science , pages 71–98, 1997.
- 2[2] Johannes Buchmann and Ulrich Vollmer. Binary quadratic forms:An algorithmic approach , volume 20 of Algorithms and Computation in Mathematics . Springer, Berlin, 2007.
- 3[3] Duncan A. Buell. Binary quadratic forms. Classical theory and modern computations. New York, NY etc.: Springer-Verlag, 1989.
- 4[4] Henri Cohen, Francisco Diaz y Diaz, and Michel Olivier. Subexponential algorithms for class group and unit computations. J. Symb. Comput. , 24(3-4):433–441, 1997.
- 5[5] David A. Cox. Primes of the form x 2 + n y 2 superscript 𝑥 2 𝑛 superscript 𝑦 2 x^{2}+ny^{2} . Pure and Applied Mathematics (Hoboken). John Wiley & Sons, Inc., Hoboken, NJ, second edition, 2013. Fermat, class field theory, and complex multiplication.
- 6[6] Stewart Crawford and Elizabeth Boese. Actionscript: a gentle introduction to programming. Journal of Computing Sciences in Colleges , 21(3):156–168, 2006.
- 7[7] Benson Farb and Dan Margalit. A primer on mapping class groups. Princeton, NJ: Princeton University Press, 2011.
- 8[8] Carl Friedrich Gauss. Disquisitiones arithmeticae , volume 157. Yale University Press, 1966.
