Search Knowledge

© 2026 LIBREUNI PROJECT

Diophantine Equations

Diophantine Equations

Diophantine equations are polynomial equations for which only integer or rational solutions are sought.

Linear Diophantine Equations

A linear Diophantine equation has the form ax+by=cax + by = c. This has integer solutions if and only if gcd(a,b)\gcd(a, b) divides cc.

python
1def extended_gcd(a, b):
2 if a == 0: return b, 0, 1
3 gcd, x1, y1 = extended_gcd(b % a, a)
4 x = y1 - (b // a) * x1
5 y = x1
6 return gcd, x, y
7 
8def solve_linear_diophantine(a, b, c):
9 gcd, x0, y0 = extended_gcd(a, b)
10 if c % gcd != 0:
11 return None, "No solution"
12 m = c // gcd
13 return (x0 * m, y0 * m), f"gcd({a}, {b}) = {gcd}"
14 
15# Solve 12x + 15y = 9
16print(f"Solution to 12x + 15y = 9: {solve_linear_diophantine(12, 15, 9)}")
17# Solve 12x + 15y = 10
18print(f"Solution to 12x + 15y = 10: {solve_linear_diophantine(12, 15, 10)}")

Pythagorean Triples

The equation x2+y2=z2x^2 + y^2 = z^2 is one of the most famous Diophantine equations. Primitive solutions can be generated using Euclid’s formula: x=m2n2,y=2mn,z=m2+n2x = m^2 - n^2, y = 2mn, z = m^2 + n^2 for m>n>0m > n > 0.

python
1def generate_pythagorean_triples(limit):
2 triples = []
3 for m in range(2, int(limit**0.5) + 2):
4 for n in range(1, m):
5 x = m**2 - n**2
6 y = 2 * m * n
7 z = m**2 + n**2
8 if z <= limit:
9 triples.append((x, y, z))
10 return triples
11 
12print(f"Triples up to 30: {generate_pythagorean_triples(30)}")

Fermat’s Last Theorem

Fermat’s Last Theorem states that xn+yn=znx^n + y^n = z^n has no positive integer solutions for n>2n > 2. This was conjectured by Pierre de Fermat in 1637 and finally proven by Andrew Wiles in 1994 using the theory of modular forms.

When does ax + by = c have integer solutions?

Elliptic Curves

Diophantine equations of the form y2=x3+ax+by^2 = x^3 + ax + b are known as Elliptic Curves. They have profound applications in modern cryptography and were crucial in the proof of Fermat’s Last Theorem.

Which n > 2 allows for x^n + y^n = z^n in positive integers?

Previous Module Complex Numbers