Binary Quadratic Forms: Introduction

Which integers can be written as x2+5y2x^2 + 5y^2 for integers x,yx, y? This question looks like a natural cousin of representing numbers as sums of two squares. Yet it behaves in a strikingly different and richer way. The expression x2+5y2x^2 + 5y^2 is a binary quadratic form: a homogeneous degree-two polynomial in two variables with integer coefficients. Studying which integers such forms represent, and how different-looking forms can secretly represent the same set of integers, was one of the great achievements of eighteenth- and nineteenth-century number theory. It was driven by Fermat, Lagrange, Legendre, and above all Gauss. The subject matters because binary quadratic forms unify and vastly generalize the theory of Sums of Two Squares. That classical theorem is really the special case of the form x2+y2x^2+y^2. Once we allow arbitrary forms ax2+bxy+cy2ax^2+bxy+cy^2, we gain a language capable of encoding questions about primes represented by x2+ny2x^2+ny^2. It also encodes the arithmetic of quadratic fields, class numbers, and eventually Pell-type equations. The single invariant that controls almost everything is the discriminant b2−4acb^2 - 4ac. This includes which integers a form can represent, how many essentially different forms exist with a given behavior, and how forms relate to each other. The big picture is this: instead of studying one Diophantine equation at a time, we study the whole family of forms sharing a discriminant. We ask how they relate under integer-linear changes of variable. Two forms connected by such a substitution represent exactly the same set of integers. So the substitutions partition all forms of a fixed discriminant into classes. This foreshadows the deeper theory of equivalence and reduction. There, each class acquires a canonical simplest representative. The number of classes (the class number) becomes a fundamental arithmetic invariant. It ties to unique factorization in quadratic fields and to the solvability of Pell's equation. This article lays the foundations: the precise definition of a binary quadratic form, its discriminant, the notion of an integer "represented" by a form, and the basic structural theorem. That theorem shows equivalent forms represent identical sets of integers. We prove everything from scratch, work through two concrete numerical examples, and show exactly why each hypothesis in the main theorem is needed.

Key takeaways
  • A binary quadratic form is f(x,y)=ax2+bxy+cy2f(x,y) = ax^2+bxy+cy^2 with a,b,c∈Za,b,c \in \mathbb{Z}.
  • Its discriminant D=b2−4acD = b^2-4ac controls the form's qualitative behavior (definite vs. indefinite).
  • An integer nn is represented by ff if f(x,y)=nf(x,y)=n has an integer solution; representation is primitive if gcd⁡(x,y)=1\gcd(x,y)=1.
  • Integer linear substitutions with determinant ±1\pm 1 transform a form into an equivalent form.
  • Equivalent forms represent exactly the same integers, with equal multiplicity of representations.
  • x2+y2x^2+y^2 (discriminant −4-4) is the simplest case, tying this theory directly to Sums of Two Squares.
  • Key idea: the discriminant is an invariant of equivalence classes, and classifying forms by discriminant is the gateway to deeper structure (reduction, class numbers, Pell's equation).

Where this lives today

The theory of binary quadratic forms is the direct classical precursor to the ideal class group of a quadratic number field: a form of discriminant DD corresponds to an ideal class in the ring of integers of Q(D)\mathbb{Q}(\sqrt D), and Gauss's composition law becomes multiplication of ideal classes. This connection underlies modern algorithmic number theory and cryptography: class groups of imaginary quadratic fields are used in cryptographic protocols (e.g., in some discrete-log-based schemes) precisely because Gauss's composition of forms gives an explicit, efficiently computable group law discovered over two centuries before the cryptographic application existed. In the study of Pell's Equation, the indefinite case D>0D>0 shows up directly: solving x2−Dy2=1x^2-Dy^2=1 is equivalent to understanding units in the ring of integers of Q(D)\mathbb{Q}(\sqrt D), which in turn is governed by the equivalence classes of forms of discriminant 4D4D (or related discriminants). The reduction theory of indefinite forms, building on the equivalence relation introduced here, produces the continued fraction expansion of D\sqrt D used to solve Pell's equation explicitly. Beyond pure number theory, quadratic forms with integer coefficients appear in the geometry of numbers (Minkowski's theorem on lattice points, sphere packings via forms like the E8E_8 lattice form), in the theory of modular forms (theta series attached to quadratic forms count representations and are themselves modular forms of weight related to the number of variables), and in coding theory, where lattice quadratic forms control the minimum distance of lattice-based error-correcting codes. The representation problem for forms like x2+ny2x^2+ny^2 also connects to class field theory, characterizing exactly which primes pp satisfy p=x2+ny2p = x^2+ny^2 in terms of congruence conditions modulo invariants built from nn.

Ask the tutor: How does the reduction algorithm pick a canonical "smallest" form in each equivalence class, and how does that lead to solving Pell's equation?

DefinitionBinary Quadratic Form, Discriminant, Representation

A binary quadratic form over Z\mathbb{Z} is a polynomial

f(x,y)=ax2+bxy+cy2,a,b,c∈Z,f(x,y) = ax^2 + bxy + cy^2, \qquad a,b,c \in \mathbb{Z},

in two indeterminates x,yx,y. We write f=(a,b,c)f = (a,b,c) for short. The form is called primitive if gcd⁡(a,b,c)=1\gcd(a,b,c)=1. The discriminant of f=(a,b,c)f=(a,b,c) is the integer

D=D(f)=b2−4ac.D = D(f) = b^2 - 4ac.

Since b2≡D(mod4)b^2 \equiv D \pmod 4, every discriminant satisfies D≡0D \equiv 0 or 1(mod4)1 \pmod 4. A form is called:

  • definite if D<0D<0 (and then ff takes only values of one sign, or is identically zero only at (0,0)(0,0) — see below),
  • indefinite if D>0D>0 (takes both positive and negative values),
  • degenerate if DD is a perfect square including 00 (in this case ff factors over Q\mathbb{Q} into two rational linear forms).

We say ff represents an integer nn if there exist x,y∈Zx,y \in \mathbb{Z} with f(x,y)=nf(x,y) = n. The representation (x,y)(x,y) is primitive if gcd⁡(x,y)=1\gcd(x,y) = 1. Two forms ff and gg are (properly) equivalent, written f∼gf \sim g, if there is a matrix

M=(pqrs),p,q,r,s∈Z,ps−qr=1,M = \begin{pmatrix} p & q \\ r & s \end{pmatrix}, \qquad p,q,r,s \in \mathbb{Z}, \quad ps-qr = 1,

such that

g(x,y)=f(px+qy,  rx+sy).g(x,y) = f(px+qy, \; rx+sy).

Equivalently, gg is obtained from ff by the invertible unimodular substitution (x,y)↦(px+qy, rx+sy)(x,y) \mapsto (px+qy,\, rx+sy).

Intuition

Think of a binary quadratic form as a machine: feed it a pair of integers (x,y)(x,y), and it outputs an integer f(x,y)f(x,y). The question "which integers does ff represent?" is really asking: as (x,y)(x,y) ranges over Z2\mathbb{Z}^2, what is the image of the machine? For f(x,y)=x2+y2f(x,y) = x^2+y^2, the image is exactly the set of integers whose prime factorization has every prime ≡3(mod4)\equiv 3 \pmod 4 appearing to an even power — this is the content of the Sums of Two Squares theorem. Changing the coefficients a,b,ca,b,c changes the machine, and generically changes the image completely. The discriminant is best understood through the associated real quadratic curve f(x,y)=nf(x,y) = n for fixed n≠0n \ne 0, or through completing the square:

4a⋅f(x,y)=(2ax+by)2−Dy2.4a \cdot f(x,y) = (2ax+by)^2 - Dy^2.

When D<0D<0 (definite case, assuming a>0a>0), the right side is a sum of two squares (after scaling), so f(x,y)f(x,y) has a fixed sign for a>0a>0: it behaves like a distorted circle, an ellipse-shaped level set. When D>0D>0 (indefinite case) the right side is a difference of squares, and the level curves f(x,y)=nf(x,y)=n are hyperbolas — the form takes both positive and negative values, and this is exactly the setting where Pell-type equations x2−Dy2=nx^2 - Dy^2 = n live. Equivalence by a unimodular substitution is a change of integer basis for the lattice Z2\mathbb{Z}^2: it relabels which lattice points we call (x,y)(x,y) without changing which values the form actually attains as we range over all of Z2\mathbb{Z}^2. This is why equivalent forms must represent the same integers — the "machine" is the same machine, just wired to a different coordinate system.

Figure
Level curves of a definite form (ellipse, D<0D<0) versus an indefinite form (hyperbola, D>0D>0)
f(x,y)=x²+5y² = 9, D=-20 y x g(x,y)=x²-5y² = 4, D=20 y x
TheoremEquivalent Forms Represent the Same Integers, with the Same Multiplicities

Let f(x,y)=ax2+bxy+cy2f(x,y) = ax^2+bxy+cy^2 and g(x,y)=a′x2+b′xy+c′y2g(x,y) = a'x^2+b'xy+c'y^2 be binary quadratic forms with integer coefficients such that f∼gf \sim g, i.e. there exists an integer matrix

M=(pqrs),ps−qr=1,M = \begin{pmatrix} p & q \\ r & s \end{pmatrix}, \qquad ps - qr = 1,

with g(x,y)=f(px+qy, rx+sy)g(x,y) = f(px+qy,\, rx+sy) for all (x,y)(x,y). Then: 1. (Equal discriminant) D(g)=D(f)D(g) = D(f). 2. (Same represented set) For every integer nn, ff represents nn if and only if gg represents nn. 3. (Bijection of representations) There is a bijection between the set of pairs (x,y)∈Z2(x,y)\in\mathbb{Z}^2 with f(x,y)=nf(x,y)=n and the set of pairs (x′,y′)∈Z2(x',y')\in\mathbb{Z}^2 with g(x′,y′)=ng(x',y')=n, for every fixed nn. 4. (Primitivity preserved) (x,y)(x,y) is a primitive representation of nn by ff if and only if the corresponding pair is a primitive representation of nn by gg.

Proof

We use direct computation with the substitution matrix, the technique of tracking a unimodular linear change of variables through the quadratic form and through the greatest common divisor.

Setup. Write g(x,y)=f(px+qy,rx+sy)g(x,y) = f(px+qy, rx+sy) where ps−qr=1ps-qr=1. Expand:

g(x,y)=a(px+qy)2+b(px+qy)(rx+sy)+c(rx+sy)2.g(x,y) = a(px+qy)^2 + b(px+qy)(rx+sy) + c(rx+sy)^2.

Collecting coefficients of x2,xy,y2x^2, xy, y^2 gives g=(a′,b′,c′)g = (a', b', c') where

a′=ap2+bpr+cr2,b′=2apq+b(ps+qr)+2crs,c′=aq2+bqs+cs2.a' = ap^2+bpr+cr^2,\quad b' = 2apq+b(ps+qr)+2crs, \quad c' = aq^2+bqs+cs^2.

(This is exactly what "g(x,y)=f(px+qy,rx+sy)g(x,y)=f(px+qy,rx+sy)" means as an identity of polynomials, so these formulas follow by direct expansion and comparison of coefficients; no further justification is required beyond high-school algebra.)

Part 1: Discriminant invariance. This is a direct algebraic identity. One computes D(g)=b′2−4a′c′D(g) = b'^2 - 4a'c' using the formulas above. Rather than expand this laboriously by hand, we use the matrix/determinant formulation, which packages the computation cleanly and rigorously. Associate to f=(a,b,c)f=(a,b,c) the symmetric matrix

Af=(ab/2b/2c),A_f = \begin{pmatrix} a & b/2 \\ b/2 & c \end{pmatrix},

so that f(x,y)=(x,y)Af(x,y)Tf(x,y) = (x,y) A_f (x,y)^T as a matrix product (with (x,y)(x,y) a row vector). Then D(f)=−4det⁡(Af)D(f) = -4\det(A_f). The substitution (x,y)↦(px+qy,rx+sy)(x,y) \mapsto (px+qy, rx+sy) is the linear map v↦Mvv \mapsto Mv where v=(x,y)Tv=(x,y)^T and M=(pqrs)M=\begin{pmatrix}p&q\\r&s\end{pmatrix}. Then

g(x,y)=(Mv)TAf(Mv)=vT(MTAfM)v,g(x,y) = (Mv)^T A_f (Mv) = v^T (M^T A_f M) v,

so Ag=MTAfMA_g = M^T A_f M (this matrix is symmetric, matching the symmetric form of AgA_g, since (MTAfM)T=MTAfTM=MTAfM(M^TA_fM)^T = M^TA_f^TM = M^TA_fM). Taking determinants,

det⁡(Ag)=det⁡(M)2det⁡(Af)=(ps−qr)2det⁡(Af)=det⁡(Af),\det(A_g) = \det(M)^2 \det(A_f) = (ps-qr)^2 \det(A_f) = \det(A_f),

since ps−qr=1ps-qr=1. Multiplying by −4-4:

D(g)=−4det⁡(Ag)=−4det⁡(Af)=D(f).D(g) = -4\det(A_g) = -4\det(A_f) = D(f).

This proves Part 1.

Part 3 (which implies Part 2): bijection of representations. Since ps−qr=1≠0ps-qr=1 \ne 0, the matrix MM has an inverse over Q\mathbb{Q}, namely

M−1=(s−q−rp),M^{-1} = \begin{pmatrix} s & -q \\ -r & p \end{pmatrix},

using the standard 2×22\times 2 inverse formula and det⁡M=1\det M = 1. Crucially, M−1M^{-1} has integer entries because s,−q,−r,p∈Zs,-q,-r,p \in \mathbb{Z}. Moreover det⁡(M−1)=1/det⁡(M)=1\det(M^{-1}) = 1/\det(M) = 1, so M−1M^{-1} is again a unimodular integer matrix. Define the map

Φ:Z2→Z2,Φ(x,y)=(px+qy, rx+sy)=M(x,y)T.\Phi: \mathbb{Z}^2 \to \mathbb{Z}^2, \qquad \Phi(x,y) = (px+qy,\, rx+sy) = M(x,y)^T.

Because MM has integer entries, Φ\Phi maps Z2\mathbb{Z}^2 into Z2\mathbb{Z}^2. Because M−1M^{-1} has integer entries, the map Φ−1(x′,y′)=M−1(x′,y′)T\Phi^{-1}(x',y') = M^{-1}(x',y')^T also maps Z2\mathbb{Z}^2 into Z2\mathbb{Z}^2, and it is a genuine two-sided inverse of Φ\Phi since M−1M=MM−1=IM^{-1}M = MM^{-1} = I. Hence Φ:Z2→Z2\Phi: \mathbb{Z}^2 \to \mathbb{Z}^2 is a bijection. By the defining relation g(x,y)=f(Φ(x,y))g(x,y) = f(\Phi(x,y)), for any fixed integer nn:

g(x,y)=n  ⟺  f(Φ(x,y))=n.g(x,y) = n \iff f(\Phi(x,y)) = n.

So Φ\Phi restricts to a bijection between

{(x,y)∈Z2:g(x,y)=n}and{(x′,y′)∈Z2:f(x′,y′)=n}.\{(x,y) \in \mathbb{Z}^2 : g(x,y) = n\} \quad \text{and} \quad \{(x',y') \in \mathbb{Z}^2 : f(x',y') = n\}.

This is exactly the assertion of Part 3.

Part 2 follows immediately from Part 3: the set on the left is nonempty if and only if the set on the right is nonempty (a bijection between two sets exists, in particular, if and only if the sets are simultaneously empty or simultaneously nonempty — a bijection cannot exist between an empty set and nonempty set, and the identity/inverse maps constructed above establish a genuine bijection whenever either side is nonempty). Hence ff represents nn if and only if gg represents nn.

Part 4: primitivity preserved. Suppose (x,y)(x,y) satisfies g(x,y)=ng(x,y)=n and corresponds under Φ\Phi to (x′,y′)=Φ(x,y)=(px+qy,rx+sy)(x',y') = \Phi(x,y) = (px+qy, rx+sy), satisfying f(x′,y′)=nf(x',y')=n. We must show gcd⁡(x,y)=1  ⟺  gcd⁡(x′,y′)=1\gcd(x,y)=1 \iff \gcd(x',y')=1. Let d=gcd⁡(x,y)d = \gcd(x,y). Since x′=px+qyx' = px+qy and y′=rx+syy'=rx+sy are integer linear combinations of x,yx,y, we have d∣x′d \mid x' and d∣y′d \mid y', so d∣gcd⁡(x′,y′)d \mid \gcd(x',y'). Conversely let d′=gcd⁡(x′,y′)d' = \gcd(x',y'). Using M−1M^{-1}: x=sx′−qy′x = sx'-qy' and y=−rx′+py′y = -rx'+py' (from (x,y)T=M−1(x′,y′)T(x,y)^T = M^{-1}(x',y')^T), which are integer linear combinations of x′,y′x',y'; hence d′∣xd' \mid x and d′∣yd' \mid y, so d′∣gcd⁡(x,y)=dd' \mid \gcd(x,y) = d. Combining d∣d′d \mid d' and d′∣dd' \mid d with d,d′≥0d,d' \ge 0 (as gcd's, they are ≥1\ge 1 unless (x,y)=(0,0)(x,y)=(0,0), a case excluded since then nn would force degenerate consideration but the divisibility argument holds regardless of sign conventions), we conclude d=d′d = d'. In particular d=1  ⟺  d′=1d=1 \iff d'=1, proving Part 4. ■\blacksquare

∎

Worked examples

Example 1: An indefinite form and a nontrivial equivalence. Let f(x,y)=2x2+6xy+3y2f(x,y) = 2x^2 + 6xy + 3y^2. Its discriminant is

D=62−4(2)(3)=36−24=12.D = 6^2 - 4(2)(3) = 36-24 = 12.

Since D=12>0D=12>0 and is not a perfect square, ff is indefinite and non-degenerate. Apply the unimodular substitution x=x′+y′x = x'+y', y=−x′y=-x' i.e. (pqrs)=(11−10)\begin{pmatrix}p&q\\r&s\end{pmatrix} = \begin{pmatrix}1&1\\-1&0\end{pmatrix}, which has determinant 1⋅0−1⋅(−1)=11\cdot 0 - 1\cdot(-1) = 1. Compute

g(x′,y′)=f(x′+y′,−x′)=2(x′+y′)2+6(x′+y′)(−x′)+3(−x′)2.g(x',y') = f(x'+y', -x') = 2(x'+y')^2 + 6(x'+y')(-x') + 3(-x')^2.

Expand term by term:

2(x′+y′)2=2x′2+4x′y′+2y′2,2(x'+y')^2 = 2x'^2+4x'y'+2y'^2,
6(x′+y′)(−x′)=−6x′2−6x′y′,6(x'+y')(-x') = -6x'^2-6x'y',
3(−x′)2=3x′2.3(-x')^2 = 3x'^2.

Summing: x′2x'^2-coefficient: 2−6+3=−12-6+3=-1; x′y′x'y'-coefficient: 4−6=−24-6=-2; y′2y'^2-coefficient: 22. So

g(x′,y′)=−x′2−2x′y′+2y′2.g(x',y') = -x'^2 -2x'y' + 2y'^2.

Check the discriminant: D(g)=(−2)2−4(−1)(2)=4+8=12D(g) = (-2)^2 - 4(-1)(2) = 4+8=12, matching D(f)=12D(f)=12 exactly as Equivalent Forms Represent the Same Integers, with the Same Multiplicities guarantees. Now test representation of n=5n=5. Try f(x,y)=5f(x,y)=5: with x=1,y=1x=1,y=1, f(1,1)=2+6+3=11≠5f(1,1) = 2+6+3=11 \ne 5. Try x=2,y=−1x=2,y=-1: f(2,−1)=2(4)+6(2)(−1)+3(1)=8−12+3=−1f(2,-1) = 2(4)+6(2)(-1)+3(1) = 8-12+3=-1. Try x=1,y=−1x=1,y=-1: 2−6+3=−12-6+3=-1. Try x=1,y=0x=1,y=0: f=2f=2. Try x=0,y=1x=0,y=1: f=3f=3. Try x=−1,y=2x=-1,y=2: 2(1)+6(−1)(2)+3(4)=2−12+12=22(1)+6(-1)(2)+3(4)=2-12+12=2. Try x=2,y=1x=2,y=1: 2(4)+6(2)(1)+3(1)=8+12+3=232(4)+6(2)(1)+3(1)=8+12+3=23. Instead, let us verify representation consistency directly rather than hunt blindly: by the theorem, whatever ff represents, gg represents identically. Take x′=1,y′=1x'=1,y'=1 in gg: g(1,1)=−1−2+2=−1g(1,1) = -1-2+2=-1. Its corresponding ff-point is Φ−1\Phi^{-1} applied, but easier: by construction g(x′,y′)=f(x′+y′,−x′)g(x',y')=f(x'+y',-x'), so at (x′,y′)=(1,1)(x',y')=(1,1) we get f(2,−1)f(2,-1), matching our computation above of f(2,−1)=−1f(2,-1)=-1. This confirms the bijection concretely: g(1,1)=−1=f(2,−1)g(1,1)=-1=f(2,-1), exactly as guaranteed, with the primitive pair (1,1)(1,1) (gcd 11) mapping to the primitive pair (2,−1)(2,-1) (gcd 11), consistent with Part 4.

Example 2: Primitivity and a specific representation for x2+5y2x^2+5y^2. Consider f(x,y)=x2+5y2f(x,y) = x^2+5y^2, discriminant D=0−4(1)(5)=−20D = 0-4(1)(5) = -20. This form is definite (since D<0D<0 and a=1>0a=1>0, f(x,y)≥0f(x,y)\ge 0 always, with equality only at (0,0)(0,0)). Does ff represent n=21n=21? We seek x,yx,y with x2+5y2=21x^2+5y^2=21. Try y=1y=1: x2=16x^2=16, so x=±4x=\pm 4. Indeed

f(4,1)=16+5=21.f(4,1) = 16+5 = 21.

Check primitivity: gcd⁡(4,1)=1\gcd(4,1)=1, so this is a primitive representation. Does ff represent n=45n=45? Try y=2y=2: x2=45−20=25x^2 = 45-20=25, x=±5x=\pm 5. So f(5,2)=25+20=45f(5,2)=25+20=45, but gcd⁡(5,2)=1\gcd(5,2)=1 — also primitive. Try y=3y=3: x2=45−45=0x^2=45-45=0, x=0x=0, giving f(0,3)=45f(0,3)=45 with gcd⁡(0,3)=3≠1\gcd(0,3)=3\ne1 — an imprimitive representation. So 4545 has both a primitive representation (5,2)(5,2) and an imprimitive one (0,3)(0,3); this shows a single integer can have representations of both types, and illustrates why Part 4 of the theorem is stated for a specific representation carried across the bijection, not as a blanket statement that "nn is primitively represented" is an invariant of nn alone — rather, primitivity of each individual representation is what transports correctly under equivalence. Finally, does ff represent n=3n=3? We would need x2+5y2=3x^2+5y^2=3 with y=0⇒x2=3y=0 \Rightarrow x^2=3 (no integer solution) or ∣y∣≥1⇒5y2≥5>3|y|\ge 1 \Rightarrow 5y^2\ge5>3 (impossible since x2≥0x^2\ge0). So 33 is not represented by ff, foreshadowing the finer theory (to be developed under reduction theory and genus theory) that determines exactly which primes are represented by x2+5y2x^2+5y^2.

CounterexampleWhy the determinant condition ps−qr=1ps-qr=1 (not just any integer matrix) is needed

Drop the hypothesis ps−qr=1ps-qr=1 and replace it with a general integer matrix, say ps−qr=2ps-qr=2, and see the conclusion fail. Let f(x,y)=x2+y2f(x,y) = x^2+y^2 (discriminant D=−4D=-4), and let

M=(2001),det⁡M=2.M = \begin{pmatrix} 2 & 0 \\ 0 & 1 \end{pmatrix}, \qquad \det M = 2.

Define g(x,y)=f(2x,y)=4x2+y2g(x,y) = f(2x, y) = 4x^2+y^2. This is again an integer binary quadratic form, (a′,b′,c′)=(4,0,1)(a',b',c')=(4,0,1), with discriminant

D(g)=0−4(4)(1)=−16≠−4=D(f).D(g) = 0 - 4(4)(1) = -16 \ne -4 = D(f).

So already the discriminant is not preserved — confirming why Part 1 of the theorem genuinely needs det⁡M=±1\det M = \pm1 (we used ps−qr=1ps-qr=1; using ps−qr=−1ps-qr=-1 works equally well by a symmetric argument, but det⁡M=±2\det M = \pm2 or any value other than ±1\pm1 breaks it). Worse, the represented sets differ: ff represents n=3n=3? No (33 is not a sum of two squares, since 3≡3(mod4)3\equiv3\pmod4 and appears to an odd power in its own factorization — by Sums of Two Squares). And gg represents 33? We need 4x2+y2=34x^2+y^2=3; trying x=0,y=±3x=0,y=\pm\sqrt3 fails, x=±1x=\pm1 gives 4+y2=34+y^2=3 impossible. So in this instance both happen to fail to represent 33, but consider n=4n=4: f(x,y)=4f(x,y)=4 has solutions (2,0),(0,2)(2,0),(0,2) — genuinely represented. Does g(x,y)=4x2+y2=4g(x,y)=4x^2+y^2=4 have a solution? Yes: x=0,y=±2x=0,y=\pm2, or x=±1,y=0x=\pm1,y=0. So both represent 44 — not yet a contradiction. Try n=1n=1: ff represents 11 via (1,0)(1,0). Does g(x,y)=4x2+y2=1g(x,y)=4x^2+y^2=1 have integer solutions? Only x=0,y=±1x=0,y=\pm1 works (since x=±1x=\pm1 forces y2=−3y^2=-3). So gg does represent 11 too, coincidentally. The cleanest failure is at the level of the bijection of representations (Part 3), which is what truly requires det⁡M=±1\det M=\pm1: the map Φ(x,y)=(2x,y)\Phi(x,y)=(2x,y) is injective but not surjective onto Z2\mathbb{Z}^2 (its image misses every point with odd first coordinate, such as (1,0)(1,0)), so it cannot be a bijection. Concretely, f(1,0)=1f(1,0)=1 is a representation of 11 by ff that does not correspond to any integer point of gg under Φ−1\Phi^{-1}, since Φ−1(1,0)=(1/2,0)∉Z2\Phi^{-1}(1,0) = (1/2, 0) \notin \mathbb{Z}^2. The clean one-to-one correspondence between representations of a fixed integer, which was the heart of the theorem, genuinely collapses once we allow det⁡M≠±1\det M \ne \pm 1.

Scope, edge cases & common traps

SituationWhat happensWhy
D<0D<0, a>0a>0f(x,y)≥0f(x,y)\ge0 for all x,yx,y, zero only at origin — "positive definite"completing the square: 4af=(2ax+by)2+∣D∣y2≥04af = (2ax+by)^2+|D|y^2 \ge 0
D<0D<0, a<0a<0f(x,y)≤0f(x,y)\le0 always — "negative definite"; usually studied via −f-fsame identity with sign flipped
DD a perfect square (incl. D=0D=0)ff factors into two integer/rational linear forms; representation theory reduces to linear Diophantine analysis4af=(2ax+by)2−Dy24af = (2ax+by)^2 - Dy^2 is a difference of squares when DD is a square
D>0D>0, not a squareff indefinite, takes both signs, connects to Pell's equationhyperbola-shaped level sets, as in the figure
gcd⁡(a,b,c)>1\gcd(a,b,c)>1ff is imprimitive; every value represented is divisible by that gcdfactor f=k⋅f0f = k \cdot f_0 with f0f_0 primitive

The mathematician behind it

Origins · 1 minCarl Friedrich Gauss and how this was discovered
CF
Carl Friedrich Gauss
1777–1855 · Göttingen, foundational work on quadratic forms in Disquisitiones Arithmeticae (1801)

Gauss developed the systematic theory of binary quadratic forms — equivalence, reduction, composition, and genus theory — as a central pillar of the Disquisitiones Arithmeticae, published when he was 24. Building on earlier work of Fermat, Euler, Lagrange, and Legendre on specific forms like x2+ny2x^2+ny^2, Gauss gave the first fully rigorous and general treatment: he proved the finiteness of the class number for each discriminant, defined the composition law making equivalence classes into what we now recognize as a finite abelian group, and introduced genus theory to organize classes further. This work directly anticipates the theory of ideal classes in quadratic number fields, developed later by Dedekind and Kummer, and remains a standard entry point into algebraic number theory.

History
- 1621: Bachet's Latin edition of Diophantus's Arithmetica spreads classical representation problems in Europe.
- 1640s: Fermat states (without full proof preserved) his theorem on primes as sums of two squares, motivating the study of x2+y2x^2+y^2.
- 1770s: Lagrange gives the first systematic reduction theory for binary quadratic forms, proving every form is equivalent to a "reduced" one.
- 1798: Legendre's Essai sur la théorie des nombres organizes known results on forms and representation.
- 1801: Gauss's Disquisitiones Arithmeticae establishes composition, genus theory, and class number finiteness, setting the modern foundation.
What exactly counts as a "binary quadratic form"?

A binary quadratic form is any homogeneous degree-two polynomial in two variables with integer coefficients, written f(x,y)=ax2+bxy+cy2f(x,y)=ax^2+bxy+cy^2. "Binary" refers to the two variables x,yx,y, and "quadratic" to the total degree 22 in each monomial. The word "form" in classical number theory specifically denotes such a homogeneous polynomial, as opposed to an inhomogeneous polynomial like ax2+bx+cax^2+bx+c. The coefficients a,b,ca,b,c can be any integers, including zero or negative values, and the form need not be primitive (i.e., gcd⁡(a,b,c)\gcd(a,b,c) can exceed 11), though primitive forms are often the main object of study since imprimitive ones reduce to primitive ones after factoring out the common divisor.

Why does the discriminant have to be congruent to 0 or 1 mod 4?

Because D=b2−4acD=b^2-4ac, and 4ac≡0(mod4)4ac\equiv0\pmod4 always, we get D≡b2(mod4)D\equiv b^2\pmod4. Squares modulo 44 are only 00 (when bb is even) or 11 (when bb is odd), since (2k)2=4k2≡0(2k)^2=4k^2\equiv0 and (2k+1)2=4k2+4k+1≡1(mod4)(2k+1)^2=4k^2+4k+1\equiv1\pmod4. Hence every discriminant of an integer binary quadratic form satisfies D≡0D\equiv0 or 1(mod4)1\pmod4, and conversely every such DD is realized by some form (e.g., (1,0,−D/4)(1,0,-D/4) if D≡0D\equiv0, or (1,1,(1−D)/4)(1,1,(1-D)/4) if D≡1D\equiv1). This congruence restriction exactly matches the discriminant congruences that arise for rings of integers of quadratic fields Q(D)\mathbb{Q}(\sqrt D).

Is every integer represented by some binary quadratic form of a given discriminant?

Not necessarily by a specific form, but this article's theorem shows representability is shared across an entire equivalence class. Whether a particular integer nn is represented by forms of discriminant DD at all is governed by deeper criteria (quadratic residue conditions on nn modulo ∣D∣|D|, and eventually genus theory), which lie beyond this introductory treatment. What is guaranteed here is only the transfer of representability between equivalent forms — if one form of discriminant DD represents nn, then every form equivalent to it also represents nn, with an explicit bijection between the representations.

How does this generalize the theorem on sums of two squares?

The classical theorem on Sums of Two Squares is precisely the representation theory of the single form f(x,y)=x2+y2f(x,y)=x^2+y^2, which has discriminant D=−4D=-4. The binary quadratic forms framework asks the analogous question for every discriminant simultaneously: for D=−20D=-20 we study x2+5y2x^2+5y^2 (among other forms of that discriminant), for D=−8D=-8 we study x2+2y2x^2+2y^2, and so on. The general machinery of equivalence, reduction, and genus theory (developed after this article) provides the tools to answer these representation questions uniformly, generalizing the specific congruence-based criterion (primes ≡1(mod4)\equiv1\pmod4) that characterizes sums of two squares.

What is the difference between "equivalent" forms and forms that merely represent the same integers?

Equivalence, as defined here via a unimodular substitution, is a strictly stronger and more structured relation than merely representing the same set of integers. Equivalent forms always represent the same integers (this article's theorem), but it is conceivable — and indeed occurs — that two inequivalent forms of different discriminants, or even the same discriminant, represent overlapping or even identical sets of integers without being related by any unimodular substitution. Equivalence tracks an actual algebraic correspondence between the forms as objects (matrices, up to SL2(Z)\mathrm{SL}_2(\mathbb{Z})-conjugation of the associated symmetric matrix), which is much more rigid than agreement of represented sets alone.

Why require ps−qr=1ps-qr=1 specifically, rather than allowing −1-1 as well?

Conventions differ across textbooks. Requiring det⁡M=1\det M=1 defines proper equivalence, the finer relation used in Gauss's original class group construction, because it corresponds to orientation-preserving changes of basis and yields exactly the composition law making equivalence classes into a group. Allowing det⁡M=±1\det M=\pm1 defines the coarser improper equivalence (sometimes just called equivalence), under which a form and its "mirror" can become identified. Both relations preserve the discriminant and the represented set (the proof given here works verbatim for det⁡M=−1\det M=-1 too, since (ps−qr)2=1(ps-qr)^2=1 regardless of sign), but only proper equivalence gives the group structure central to class number theory.

Can a binary quadratic form represent zero nontrivially, i.e. at a point other than the origin?

Yes, exactly when the discriminant DD is a perfect square (including D=0D=0). In that case 4af(x,y)=(2ax+by)2−Dy24af(x,y)=(2ax+by)^2-Dy^2 factors as a difference of squares over the integers (when DD is a perfect square), so ff factors into two integer linear forms, and setting one factor to zero gives nontrivial solutions to f(x,y)=0f(x,y)=0. When DD is negative, f(x,y)=0f(x,y)=0 forces (x,y)=(0,0)(x,y)=(0,0) by the positive/negative definiteness argument from completing the square. When D>0D>0 but not a perfect square, f(x,y)=0f(x,y)=0 also forces (x,y)=(0,0)(x,y)=(0,0), since otherwise D\sqrt D would be forced to be rational, a contradiction.

Before this