Part 4. The same group elsewhere: starting points#
The proofs in Parts 1 and 2 did not use real numbers: they were identities of polynomials with integer coefficients and certificates from the equation of the circle. That is why they work wherever we can add and multiply. In this part we take the circle group to three places: over a finite field, onto the hyperbola (Pell’s equation), and into the primality test for Mersenne numbers. Each example is short and serves as a starting point for further work.
import time
import sympy as sp
a, b = sp.symbols("a b")
def m(P, Q, D=-1, p=None):
"""Prawo grupowe na krzywej x² - D·y² = 1 (okrąg: D = -1), ew. mod p."""
a, b = P
c, d = Q
wynik = (a * c + D * b * d, a * d + b * c)
return wynik if p is None else (wynik[0] % p, wynik[1] % p)
The circle over a finite field#
Over \(\mathbb{F}_p\) the circle \(a^2+b^2=1\) is a finite set, and the group law is the same formula computed modulo \(p\). Let us count the points and find the largest order of an element.
def punkty_okregu(p):
return [(u, v) for u in range(p) for v in range(p)
if (u * u + v * v) % p == 1]
def rzad(P, p):
Q, k = P, 1
while Q != (1, 0):
Q, k = m(Q, P, p=p), k + 1
return k
print(f"{'p':>3} {'p mod 4':>8} {'punktów':>8} {'największy rząd':>16}")
wiersze = []
for p in sp.primerange(3, 60):
pkt = punkty_okregu(p)
wiersze.append((p, p % 4, len(pkt), max(rzad(P, p) for P in pkt)))
print(f"{p:>3} {p % 4:>8} {len(pkt):>8} {wiersze[-1][3]:>16}")
p p mod 4 punktów największy rząd
3 3 4 4
5 1 4 4
7 3 8 8
11 3 12 12
13 1 12 12
17 1 16 16
19 3 20 20
23 3 24 24
29 1 28 28
31 3 32 32
37 1 36 36
41 1 40 40
43 3 44 44
47 3 48 48
53 1 52 52
59 3 60 60
The pattern is clear: there are \(p-1\) points when \(p\equiv1\pmod4\) and \(p+1\) when \(p\equiv3\pmod4\), and the largest order equals the number of points, so the group is cyclic. The explanation: when \(-1=i^2\) has a square root in \(\mathbb{F}_p\), the map \((a,b)\mapsto a+ib\) carries the circle onto the group \(\mathbb{F}_p^\times\) (of order \(p-1\)); when it does not, the circle consists of the elements of norm \(1\) in the field \(\mathbb{F}_{p^2}=\mathbb{F}_p(i)\), and there are \(p+1\) of them.
Further: this is the simplest example of an algebraic torus. The point counts \(p\mp1\) are the prototype of Hasse’s theorem for elliptic curves, where the number of points is \(p+1-t\) with \(|t|\le2\sqrt p\).
The hyperbola and Pell’s equation#
Let us replace the circle by the hyperbola \(x^2-Dy^2=1\) with \(D>0\) not a square. The group law \(m\bigl((a,b),(c,d)\bigr)=(ac+Dbd,\ ad+bc)\) is multiplication of numbers \(a+b\sqrt D\). The computation from Part 1 carries over unchanged:
c, d, D = sp.symbols("c d D")
x, y = m((a, b), (c, d), D=D)
print(sp.factor(x**2 - D * y**2))
(-D*b**2 + a**2)*(-D*d**2 + c**2)
Moreover, the powers are described by the same Chebyshev polynomials. On the hyperbola \(Db^2=a^2-1\), so we replace \(b^2\) by \((a^2-1)/D\), and the induction step from Part 2 looks like this:
T, U = sp.symbols("T U")
krok = m((T, b * U), (a, b), D=D)
nastepny = (a * T - (1 - a**2) * U, b * (T + a * U)) # rekurencja z części 2
podstaw = {b**2: (a**2 - 1) / D}
print([sp.simplify(sp.expand(krok[i] - nastepny[i]).subs(podstaw))
for i in range(2)])
[0, 0]
Hence if \((x_1,y_1)\) is the smallest solution of Pell’s equation, the subsequent solutions are \(\bigl(T_n(x_1),\ y_1U_{n-1}(x_1)\bigr)\). For \(D=2\) we start from \((3,2)\), and for the famous example \(D=61\) from \((1766319049,\ 226153980)\); this solution was already known to the Indian mathematician Bhaskara II in the 12th century.
for D_, (x1, y1) in ((2, (3, 2)), (61, (1766319049, 226153980))):
rozw = [(sp.chebyshevt(n, x1), y1 * sp.chebyshevu(n - 1, x1))
for n in range(1, 6)]
print(f"D = {D_}: rozwiązania poprawne:",
all(u * u - D_ * v * v == 1 for u, v in rozw))
for n, (u, v) in enumerate(rozw[:3], 1):
print(f" n = {n}: x = {u}, y = {v}")
D = 2: rozwiązania poprawne: True
n = 1: x = 3, y = 2
n = 2: x = 17, y = 12
n = 3: x = 99, y = 70
D = 61: rozwiązania poprawne: True
n = 1: x = 1766319049, y = 226153980
n = 2: x = 6239765965720528801, y = 798920165762330040
n = 3: x = 22042834973108102061352541449, y = 2822295814832482312327709940
Further: the smallest solution is found by the continued fraction algorithm for \(\sqrt D\)
(the function diop_DN in the module sympy.solvers.diophantine.diophantine). The group of solutions is infinite cyclic up
to sign — this is Dirichlet’s unit theorem in its simplest case.
The Lucas–Lehmer test#
The point \((2,1)\) lies on the hyperbola \(x^2-3y^2=1\). Its \(2^k\)th powers have first coordinates \(T_{2^k}(2)\), and from the composition \(T_{2^{k+1}}=T_2\circ T_{2^k}\) and \(T_2(x)=2x^2-1\) it follows that the numbers \(s_k=2\,T_{2^k}(2)\) satisfy
s_k = 4
for k in range(5):
print(k, s_k, s_k == 2 * sp.chebyshevt(2**k, 2))
s_k = s_k**2 - 2
0 4 True
1 14 True
2 194 True
3 37634 True
4 1416317954 True
The Lucas–Lehmer test (Lucas 1878, Lehmer 1930): for an odd prime \(q\), the number \(M_q=2^q-1\) is prime if and only if \(s_{q-2}\equiv0\pmod{M_q}\). Behind the proof is exactly our group: the point \((2,1)\) on the hyperbola \(x^2-3y^2=1\) over \(\mathbb{F}_{M_q}\) (or over its degree-2 extension) and its order.
def lucas_lehmer(q):
M, s = 2**q - 1, 4
for _ in range(q - 2):
s = (s * s - 2) % M
return s == 0
start = time.perf_counter()
wykladniki = [q for q in sp.primerange(3, 1300) if lucas_lehmer(q)]
czas = time.perf_counter() - start
print("q < 1300 z pierwszą M_q:", wykladniki)
print(f"czas: {czas:.2f} s; M_1279 ma {len(str(2**1279 - 1))} cyfr")
print("zgodne z isprime dla q < 130:",
[q for q in wykladniki if q < 130]
== [q for q in sp.primerange(3, 130) if sp.isprime(2**q - 1)])
q < 1300 z pierwszą M_q: [3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279]
czas: 0.21 s; M_1279 ma 386 cyfr
zgodne z isprime dla q < 130: True
\(M_{1279}\) has \(386\) digits, and testing all \(q<1300\) together takes a fraction of a second: for \(q=1279\) it is only \(1277\) squarings modulo \(M_q\). The largest known primes are Mersenne numbers, and their primality is confirmed by tests based on the same idea.
Further: a full proof of the test (it requires the order of the point \((2,1)\) in the group over \(\mathbb{F}_{M_q}\) or \(\mathbb{F}_{M_q^2}\)); Lucas tests for numbers of other forms; exponentiation in a group as a general scheme for primality tests.
Elliptic curves#
The next algebraic group after the circle and the hyperbola is an elliptic curve \(y^2=x^3+Ax+B\) with the chord-and-tangent law. Closure and commutativity are checked as in Part 1, but associativity is already a large symbolic computation and a good test of what a computer algebra system can do.
Part 5 shows what all these examples have in common: each one is an algebraic group of dimension 1, and for the circle and the hyperbola the most important properties follow from the Lie algebra and the exponential map. For elliptic curves the Lie algebra says much less, and the rest has to be found in arithmetic.
Exercises#
Check for \(p<200\) that the circle \(a^2+b^2=1\) over \(\mathbb{F}_p\) has \(p-\left(\frac{-1}{p}\right)\) points, and find a generator for \(p=13\) and \(p=19\).
Find the smallest solution of \(x^2-13y^2=1\) (searching is allowed) and list the next three using Chebyshev polynomials.
Show that the Lucas–Lehmer test can be written as exponentiation of the point \((2,1)\) in the group \(x^2-3y^2=1\) modulo \(M_q\), and check this for \(q=7\).
The curve \(x^2+xy+y^2=1\) is also a group (norms in \(\mathbb{Q}(\sqrt{-3})\)). Derive its group law and check it symbolically.
Literature and further reading#
F. Lemmermeyer, Conics — a Poor Man’s Elliptic Curves, arXiv:math/0311306 — the circle and other conics over \(\mathbb{F}_p\) as groups, with analogies to elliptic curves.
H. W. Lenstra Jr., Solving the Pell Equation, Notices of the AMS 49 (2002), 182–192 (PDF) — history, algorithms, and complexity; Pell’s equation on Wikipedia.
D. H. Lehmer, An Extended Theory of Lucas’ Functions, Annals of Mathematics 31 (1930), 419–448 (DOI); R. Crandall, C. Pomerance, Prime Numbers: A Computational Perspective, 2nd ed., Springer, 2005 (DOI); Lucas–Lehmer test; GIMPS — the project searching for Mersenne primes.
J. H. Silverman, The Arithmetic of Elliptic Curves, 2nd ed., Springer, 2009 (DOI) — the group law, points over \(\mathbb{F}_p\), and Hasse’s theorem.