Skip to content

Instantly share code, notes, and snippets.

@tkmharris
Last active October 14, 2018 15:12
Show Gist options
  • Save tkmharris/a2b05d2254726f1c19e12e79b60e4841 to your computer and use it in GitHub Desktop.
Save tkmharris/a2b05d2254726f1c19e12e79b60e4841 to your computer and use it in GitHub Desktop.
Get integer solutions of the Mordell equation y^2 = x^3 - d for certain special values of d.
## Mordell's equation
'''
Get integer solutions of the Mordell equation
y^2 = x^3 - d
for certain special values of d.
See mordell.txt for details.
'''
def mordell_test(d, x,y):
'''Tests whether (x,y) satisfy y^2 = x^3 - d'''
return y^2 == x^3 - d
def dividesCG(a,d):
'''Tests whether a divides the ideal class group of
Q[sqrt(-d)].
This is the only place where we really *use* Sage'''
K.<y> = NumberField(x^2 + d)
return K.class_group().cardinality() % a == 0
def admissible(d):
'''Check whether d satisfies the hypotheses of any of the theorems in mordell.txt'''
if (not Integer(d).is_squarefree() or dividesCG(3,d)) and d > 0:
return False
if d == 3:
return False
if d%3 != 0 and d%4 != 3:
cases = [(d-1)/3, (d+1)/3]
for a in cases:
if isqrt(a)**2 == a:
return True
if d%8 == 3 and d > 8:
cases = [(d-8)/3, (d+8)/3]
for a in cases:
if isqrt(a)**2 == a:
return True
return False
def mordell_special_case(d):
solutions = []
if not admissible(d):
raise ValueError('%d does not satisfy the conditions of the theorem' %d)
if (d%3 != 0) and d%4 != 3:
for e in [-1,1]:
a2 = (d-e)/3
a = isqrt(a2)
if a**2 == a2:
x1, y1 = 4*a^2 + e, 8*a^3 + 3*e*a
solutions += [(x1, y1), (x1,-y1)]
if d%8 == 3 and d > 8:
for e in [-1,1]:
a2 = (d-e)/3
a = isqrt(a2)
if a**2 == a2:
x1, y1 = 4*a^2 + e, 8*a^3 + 3*e*a
solutions += [(x1, y1), (x1,-y1)]
for e in [-1,1]:
a2 = (d- 8*e)/3
a = isqrt(a2)
if a**2 == a2:
x1, y1 = a^2 + 2*e, a^3 + 3*e*a
solutions += [(x1, y1), (x1,-y1)]
return solutions
for i in range(50):
if admissible(i):
print i, mordell_special_case(i)
Theorem 1
If d > 0 satisfies:
i) d is squarefree
ii) 3 does not divide the order of h(Q(sqrt(-d)))
(the ideal class group)
iii) d != -1 mod 4
If y^2 = x^3 - d has an integral solution then:
d = 3a^2 + e for some a >= 0 and e = +- 1
and the solution pair is:
(x,y) = (4a^2 + e, +-(8a^3 + 3ea))
Theorem 2
If d > 0 satisfies:
i) d is squarefree
ii) 3 does not divide the order of h(Q(sqrt(-d)))
(the ideal class group)
iii) d == 3 mod 8
Then one or both of the following hold:
If y^2 = x^3 - d has an integral solution then either:
d = 3a^2 + e for some a >= 0 and e = +- 1
and the solution pair is:
(x,y) = (4a^2 + e, +-(8a^3 + 3ea))
or:
d = 3a^2 + 8e for some a >= 0 and e = +- 1
and the solution pair is:
(x,y) = (a^2 + 2e, +-(a^3 + 3ea))
or both (e.g. d = 11), in which case both of the above pairs are solutions.
Outline proofs of these theorems can be found in my "Glass beads" document.
There is room for stronger conclusions:
for example d=47 doesn't satisfy hypothesis iii) of Theorem 1, but setting
(x,y) = (4a^2 - 1, +-(8a^3 - 3a)) with 47 = 3a^2 - 1
gives (63, +-500) as a solution to y^2 = x^3 - 47, which we can verify. Tighten up the proof of the theorems?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment