现充|junyu33

Diophantine equations and elliptic curves

In the previous post, we introduced the Weil pairing and Tate pairing on elliptic curves. In this article, we explore some applications of elliptic curves in Diophantine equations.

Problem Zero

In middle school mathematics, we learned that right triangles satisfy the Pythagorean theorem. Let the two legs be a and b, and the hypotenuse be c. The formula is:

a2+b2=c2

So, are there infinitely many right triangles with all three sides being integers?


This is a classic example of a Diophantine equation. Generally, Diophantine equations are equations with one or more variables and integer coefficients, and their solutions are sought only within the integer domain.

The simplest equations we learn are linear Diophantine equations, which take the form:

ax+by=c

where a,b,c are integers, and x,y are unknowns. This equation can be solved using the extended Euclidean algorithm.

Of course, the above problem does not require the use of elliptic curves for analysis (which is why it's called "Problem Zero").

Below is the solution to Problem Zero. Note that:

(x2y2x2+y2)2+(2xyx2+y2)2=1

This was actually noticed in one of my middle school math teacher's classes.

Therefore, there are infinitely many right triangles with all three sides being integers. Let x>y>0,x,yZ, and simply take a=x2y2, b=2xy, c=x2+y2 to satisfy the condition.

For example: x=2,y=1(3,4,5)

x=3,y=1(6,8,10)

x=3,y=2(5,12,13)

Question 1

In elementary school mathematics, we learned that the area of a right triangle is:

S=12ab

So the question is: can we find a right triangle with area S=5 and all side lengths rational? If such a triangle exists, are there infinitely many such right triangles?


This problem is equivalent to solving a Diophantine equation with two conditions:

{a2+b2=c2ab=10

We are to find its rational solutions. If we try to substitute a and b with x and y as before, the equation becomes:

(x2y2)xy=5

The degree of the equation becomes 4, which seems more difficult to solve than the previous one. So let's try a different approach:

We observe that:

(a±b2)2=a2±2ab+b24=(c2)2±5

This is noted in the textbook, and it should be more obvious than the previous one.

Therefore, let x=(c2)2. The problem can be transformed into:

As long as we find a solution where (x5,x,x+5) are all rational squares, we can find the corresponding (a,b,c) that satisfy the conditions.

If x5, x, and x+5 are all rational squares, then their product x325x is also a rational square. This leads us to the main character of this problem—the elliptic curve:

E:y2=x325x

We aim to find non-trivial rational points on this curve.

Finding the First Solution

We can first identify three rational points: (0,0) and (±5,0). However, the area of the triangle cannot be zero, so this set of solutions is trivial. (Moreover, 5 and 5 are not squares of rational numbers.)

Through a simple search, we can find a non-trivial rational point (4,6). Although this point is non-trivial, there is no real number c such that (c2)2=4, so no such real c exists.

But we can use this point to draw a tangent to E and find other rational points (essentially performing a point doubling operation on the elliptic curve).

We attempt to draw the tangent to E at the point (4,6). First, we use implicit differentiation:

2yy=3x225y=3x2252y

Substituting the point (4,6) gives y=2312, so the tangent function is:

y=2312(x+4)+6

Substituting this function into the equation of E, we get:

(2312(x+4)+6)2=x325x

Expanding this yields a constant term of 4129. By Vieta's formulas, x1x2x3=C=4129 (where C is the constant term of the cubic equation). Since the tangent touches E at x=4, the equation has a double root x1,2=4, so x3=4129÷(4)2=(4112)2.

With the corresponding x3, we can compute c=416. Previously, we had:

(a±b2)2=a2±2ab+b24=(c2)2±5

Therefore:

(a±b2)2=(4112)2±5

We observe that (4112)2±5 are also squares of rational numbers, allowing us to solve for a=203,b=32.

In summary, we obtain a solution (a,b,c)=(203,32,416), which can be verified to satisfy the Pythagorean theorem and yield an area of 5.

Proving There Are Infinitely Many Solutions

The next question is: are there infinitely many such triples (a,b,c)? The answer is yes, and we can simply repeat this process (though it becomes inconvenient to do by hand):

Since y=((x5)x(x+5))1/2=(ab)c(a+b)8=(a2b2)c8, we have a2b2=8y/c. Combined with a2+b2=c2, we get a=(8y/c+c2)/2,b=(8y/c+c2)/2.

Thus, we obtain the next triple (49201519,1519492,3344161747348). We can continue generating other valid triples by drawing tangents in this way. Here is a brief explanation of why this iterative method always ensures that a,b,c are rational numbers:

We consider a general equation of the form:

E:y2=x3n2x

with a non-trivial rational point (x0,y0) (i.e., x00,±n). We prove that by drawing the tangent at this point, the other intersection point (x1,y1) with E satisfies that x1n,x1,x1+n are all rational squares:

First, we find the tangent line:

y=(3x02n22y0)(xx0)+y0

By Vieta's formulas, we have:

xaxbxc=(y0(3x02n2)x02y0)2=(2y023x03+n2x02y0)2=(2x032n2x03x03+n2x02y0)2=(x03n2x02y0)2

Since xa and xb are both x0 (a double root), we have x1=xc=(x02+n22y0)2, proving that x1 is a rational square, and thus c is rational.

Note that:

x1±n=((x02+n2)2±4ny024y02)=(x02±2nx0n22y0)2

This was noticed by DeepSeek R1—my attention wasn't sharp enough (

Thus, x1±n are also rational squares. As mentioned earlier:

(a±b2)2=(c2)2±n=x±n

That is, a±b2 are also rational numbers. Ultimately, we conclude that a and b are rational.

We can generate x2,x3, in this iterative manner, ensuring that the corresponding a,b,c are all rational. Therefore, if the elliptic curve E corresponding to n has a non-trivial rational point, then there are infinitely many right triangles with rational sides and area n. Q.E.D.

Question Two

This is a fishing question a classmate gave me in middle school:

I tried it back then and realized that probably less than 5% of people could solve it. Later, my classmate told me those three extremely long answers, and I began to appreciate the charm of some number theory problems:

A seemingly simple problem statement can have incredibly complex solutions and answers.

Transforming into Weierstrass Form

First, this equation is homogeneous, meaning that once we find a solution (a,b,c), then for any tN+, (ta,tb,tc) is also a solution.

Following the idea from Problem 1, we should first consider how to transform the given equation:

ab+c+ba+c+ca+b=4,a,b,cN+

into the form of an elliptic curve—this is significantly more challenging than Problem 1.

First, attempt to combine the fractions:

a3+b3+c33a2b3a2c3ab23b2c3ac23bc25abc=0

Then, we need to express x and y using linear combinations of a,b,c to transform the original expression F into the long Weierstrass form:

y2+a1xy+a3y=x3+a2x2+a4x+a6

A zero point P=(1,1,0) of F can be found through enumeration. We then draw the tangent line to F at P. First, compute the partial derivatives of F:

{Fa=3a26ab6ac3b23c25bcFb=3b26ab6bc3a23c25acFc=3c26ac6bc3a23b25ab

Substitute (1,1,0) to obtain the specific gradient vector (6,6,1), which gives the tangent line Z=6a+6bc.

Set Z=0, substitute c=6a+6b into F, and obtain F=91(a+b)3. Since point P satisfies a+b=0, the multiplicity of the zero point P is 3. According to Reference 6, we need to find a transformation matrix Mβ such that:

Mβ=(QxPx.QyPy.QzPz.)

is an invertible matrix. A simple approach is to take point Q as another point on Z, and the third column as (1,0,0), (0,1,0), or (0,0,1).

For example, take Mβ as:

Mβ=(110010601)

Let a=u+v, b=v, c=6u+w. Transform F(a,b,c) into F(u,v,w):

91u3+69u2wuvwv2w+15uw2+w3=0v2w+uvw=91u3+69u2w+15uw2+w3191v2w+191uvw=u3+6991u2w+1591uw2+191w3

Let w=w/91 to obtain an integer-coefficient long Weierstrass form:

v2w+uvw=u3+69u2w+1365uw2+8281w3

Divide both sides by w3, and let X=u/w, Y=v/w to obtain:

Y2+XY=X3+69X2+1365X+8281

These are the projective and affine forms mentioned at the beginning of Reference 6.

Now, express (u,v,w) in terms of (a,b,c):

{u=a+bv=bw=6a6b+c

Then, we can express (X,Y) in terms of (a,b,c):

{X=91(a+b)6a+6bcY=91b6a+6bc

Similarly, we can compute the inverse transformation (omitting the free variable k):

{a=XYb=Yc=6X91

Finding a Set of Positive Integer Solutions

Attempting a brute-force enumeration to find integer solutions for the new equation, a script can iterate over X,Y[100,100], yielding the following sets:

(-39, 52)
(-39, -13)
(-28, 63)
(-28, -35)
(-15, 11)
(-15, 4)
(-14, 7)
(-13, 13)
(-13, 0)
(0, 91)
(0, -91)

Substituting these solutions back into (a,b,c) and excluding cases where the denominator of the original expression is zero, the following integer solutions are obtained:

(x, y) = (-39, 52) -> (a, b, c) = (-13, 52, 143) [Valid]
(x, y) = (-39, -13) -> (a, b, c) = (52, -13, 143) [Valid]
(x, y) = (-28, 63) -> (a, b, c) = (-35, 63, 77) [Valid]
(x, y) = (-28, -35) -> (a, b, c) = (63, -35, 77) [Valid]
(x, y) = (-15, 11) -> (a, b, c) = (4, 11, -1) [Valid]
(x, y) = (-15, 4) -> (a, b, c) = (11, 4, -1) [Valid]

The fifth and sixth rows correspond to the special solutions used in Reference 4.

However, the corresponding (a,b,c) values are not all positive integers. Taking the last solution (x,y)=(15,4), we attempt to use the tangent method from Problem 1 to find other rational points and then solve back for (a,b,c) to determine if they are positive integers.

This process is relatively straightforward, involving a brute-force loop for judgment. To avoid reinventing the wheel, I directly used GPT to write a script leveraging SageMath's elliptic curve library:

E = EllipticCurve(QQ, [1, 69, 0, 1365, 8281])  # [a1, a2, a3, a4, a6]

def compute_abc(x, y):
    a = -x-y
    b = y
    c = -6*x-91
    return a, b, c

def is_positive_integer(a, b, c):
    return (a > 0 and b > 0 and c > 0)

def find_positive_abc(P, max_iterations):
    iteration = 1
    
    while iteration < max_iterations:
        try:
            Q = (iteration * P)
            x, y = Q.xy()
        except Exception as e:
            print(f"Error in point doubling: {e}. Stopping.")
            break
        
        a, b, c = compute_abc(x, y)

        if is_positive_integer(a, b, c):
            print(f"Found positive integer solution when iteration = {iteration}")
            return Q, a, b, c
        
        iteration += 1
    
    print("No positive integer (a, b, c) found within max iterations.")
    return None


point = E([-15, 4])
result = find_positive_abc(point, max_iterations=10)
if result:
    Q, a, b, c = result
    print(f"Solution: (a, b, c) = ({a}, {b}, {c})")

As in Reference 4, when the iteration count iteration=9, the output is:

a=15447680210874616644195131501991983748566432566956543170002663489825320203527799912568549348783827476450917658335170150704695563440250577574035123362243258771752b=3687513179412999982719781156522547482549297996897197099628313747163722463405557912568549348783827476450917658335170150704695563440250577574035123362243258771752c=940550111466071662553451842159541718466493792941778127028800585432577024141815890005886705385156000813842

Multiplying by their least common multiple yields the positive integer solutions:

a=154476802108746166441951315019919837485664325669565431700026634898253202035277999b=36875131794129999827197811565225474825492979968971970996283137471637224634055579c=4373612677928697257861252602371390152816537558161613618621437993378423467772036

Question 3

Inspired by the meme in Question 2, a curious individual turned an apparently simpler problem into this seemingly harmless form:

This is the famous "sums of three cubes problem," which seeks integer solutions (x,y,z) to the equation:

x3+y3+z3=k

The problem depicted in the image corresponds to the case where k=33, which was not solved until 2019 by Andrew Booker (Question 2 was solved in 2014, which is also relatively recent). In the following year, Andrew Sutherland collaborated with Booker to solve the Diophantine equation for k=42. With this, all positive integers up to 100 that admit solutions have been found with at least one set of solutions.

Since this equation is not homogeneous, the doubling method from Question 2 is not applicable. The approach described in Andrew's paper involves reducing the time complexity of brute-force enumeration (from O(N1+o(1)) down to Ok(N(loglogN)(logloglogN))), followed by a month of supercomputing (equivalent to 23 core-years of computation) to obtain a solution for 33, with a magnitude on the order of N=1016. Therefore, it is impractical to write code for this problem; instead, a general explanation of the idea will suffice.

Algorithm with O(N1+o(1)) Complexity

First, consider a simplified version of the problem—the two-cube-sum problem. A relatively straightforward conclusion is that for a prime p satisfying:

x3+y3=p,

the integer solutions exist only when p=2 or when p takes the form 3n23n+1. The proof is as follows:

Since x3+y3=(x+y)(x2xy+y2) and p is prime, we have:

x+y=1x2xy+y2=1.

First, consider the right-hand condition: only x=1,y=1 satisfies it, corresponding to p=2.

Next, consider the left-hand condition: let y=1x, then the expression becomes 3x23x+1 (which must also be prime).

We now attempt to generalize p to any integer k. Let k=rs, so we have r=x+y and s=x2xy+y2. Let y=rx, which gives:

s=3x23rx+r2.

This is a standard quadratic equation in x. The discriminant Δ=(3r)243(r2s)=12s3r2 must be a perfect square for the solution to be an integer. Let Δ=t, then we obtain x=(3r+t)/6 and y=(3rt)/6. It suffices to verify whether x and y are integers.

Returning to the original three-cube-sum problem, we can move z3 to the right-hand side:

x3+y3=kz3.

We can then apply the algorithm for the two-cube-sum problem described above. By enumerating z and performing prime factorization, we achieve a time complexity of O(N1+o(1)).

Transformation to an Elliptic Curve

Assume x3+y3+z3=k>0, with |x|>|y|>|z|k. Let d=|x+y|. Then z is a cube root of k modulo d, and we can solve for:

x,y=sgn(kz3)2(d±4|kz3|d33d)

Here, sgn(x) denotes the sign function of x, satisfying sgn(0)=0 and sgn(x)=x|x|.

Then,

Δ=4|kz3|d33d=

Here, the symbol indicates that the computed value must be a perfect square. Therefore, this is equivalent to:

3d(4sgn(z)(z3k)d3)=z3kmodd

For a given search range N, such as N=1016 in this problem, we need to enumerate d[0,(231)N] such that d is coprime with 3. For each d, we also need to enumerate z[N,N] satisfying z3kmodd. Once we find a solution pair (d,z), it can be mapped back to the original solution (x,y,z).

For a specified integer k, we can construct the corresponding elliptic curve Ed:

Ed:Y2=X32(6d)3(d3+4sgn(z)k)

such that the integer points on it correspond exactly to the integer solutions of the above equation. The specific mapping is:

{X=12d|z|Y=(6d)2|xy|

Thus, the problem is transformed into finding integer points on an elliptic curve over Q.

This algebraic transformation is effective for relatively small d. For example, before the year 2000, the values of k for which no integer solution (x,y,z) had been found included:

33,42,114,165,390,579,627,633,732,795,906,921,975.

Booker used the integer point finding functionality for elliptic curves in the algebraic software Magma and verified that for d40, among all integer pairs (k,d), only {(579,29),(579,34),(975,22)} yield integer points on Ed. In other words, except for k=579 and k=975, none of the other listed k values have integer solutions for d40.

However, the parameter d for the elliptic curve is on the order of 1016, and there are 1016 such elliptic curves Ed. Therefore, simply transforming the problem into finding integer points on an elliptic curve does not reduce the inherent complexity of the problem. Further optimization is still required.

Further Optimization

Returning to the previous section, in order to find pairs (d,z) satisfying:

3d(4sgn(z)(z3k)d3)=

where d[0,αN] (α is the same as before, i.e., 231), there are two time complexity bottlenecks:

  • To compute z such that z3kmodd, we need the prime factorization of d.
  • The number of possible (d,z) pairs is Ω(NlogN).

Apart from using elliptic curves to exclude a portion of integers d, the paper primarily employs Montgomery's Batch Inversion Trick for batch computing cubic residues and a space-time trade-off sieve using the Legendre symbol to reduce the number of (d,z) pairs that need to be traversed.


First, let's discuss batch inversion. Given k numbers a1,a2,akmodn, we need to compute a11,a21,,ak1modn simultaneously. If done separately using the extended Euclidean algorithm, the time complexity would be O(klogn). Montgomery's approach is as follows:

  1. Compute pi=a1a2aimodn. Calculating from p1 to pk requires only k1 modular multiplications.
  2. Use the extended Euclidean algorithm to compute pk1, with time complexity O(logn).
  3. When i=k, compute ai1=pi1pi1, then compute pi11=pi1ai.
  4. Let p0=1, and perform the same operation for i=k1,k2,,2.

Thus, the time complexity is reduced from O(klogn) to O(k+logn).

Returning to bottleneck one, factorize d to obtain d=p1e1p2e2pmem, then solve each cubic residue zi3=kmodpi.

Then, use Hensel's lemma to extend to zi3=kmodpiei, and use the Chinese Remainder Theorem (CRT) to extend to z3modd.

If the modular inverses are stored during batch inversion and d is enumerated using "linear combinations" of the primes, the inverses do not need to be recalculated during CRT. This reduces the total time complexity for computing cubic roots for dαB to O(N).


Considering bottleneck two, let:

Δ=3d(4sgn(z)(z3k)d3)

Select P=3(loglogN)(logloglogN), and compute M as the product of all primes in [5,P]. If Δ is a perfect square, then for any prime pM (here the parentheses denote the Legendre symbol):

(Δp)=(3dp)(|z|3sgn(z)kd3/4p)

If the residue classes of |z|modM are precomputed, and those residue classes for which the above equality holds for all primes pM are selected, the Hasse bound can be used to prove that the number of residue classes does not exceed N(loglogN)(logloglogN). Thus, the final complexity is reduced to Ok(N(loglogN)(logloglogN)).

In addition to the reduction in complexity, Andrew mentioned in subsequent work Sums of three cubes that for specific k (e.g., k=33), using the cubic reciprocity law as a sieve reduces the number of residue classes to 163.6 of the original. This means only 5.5×109 values of z need to be traversed, significantly reducing the workload.

In terms of implementation, the paper used Intel intrinsics and leveraged supercomputing parallelism (with 106 subtasks) to enumerate d. After a month of computation (equivalent to 23 core-years), the paper found the first solution for k=33:

33=88661289752875283+(8778405442862239)3+(2736111468807040)3.

References

https://baike.baidu.com/item/丢番图方程/5466939

https://zhuanlan.zhihu.com/p/354425450

Elliptic curves: number theory and cryptography

https://zhuanlan.zhihu.com/p/33853851

https://www.zhihu.com/question/267427508/answer/323883323

Transforming a general cubic elliptic curve equation to Weierstrass form

An unusual cubic representation problem

Cracking the problem with 33

Sums of three cubes (Andrew Sutherland)

https://zh.wikipedia.org/wiki/亨泽尔引理