A student of mine is trying to use Sage to prove the commutativity of the 
group law of elliptic curves.  Below is the code used when trying to show 
(P + Q) + R = P + (Q + R), when R = P + Q.  I let it run for almost 4 hours 
with no result.  The same code translated to Magma was instantaneous.  Am I 
doing something wrong with Sage?  Or is just that the implementation in 
Magma is more efficient?  (We can use Magma, but it made me curious.)

def add_EC(vE, P, Q):
    if P == 0:
        return Q
    if Q == 0:
        return P
    a = vE[0]
    b = vE[1]
    x1 = P[0]
    y1 = P[1]
    x2 = Q[0]
    y2 = Q[1]
    if P == Q:
        if y1 == 0:
            return 0
        else:
            m = (3*x1^2 + a)/(2*y1)
    else:
        if x1 == x2:
            return 0
        else:
            m = (y2 - y1)/(x2 - x1)
    c = y1 - m*x1
    x3 = m^2 - x1 - x2
    y3 = m*x3 + c
    return [x3, -y3]

R.<A, B, a, b, c, d> = PolynomialRing(QQ)

eq1 = b^2 - a^3 - A*a - B
eq2 = d^2 - c^3 - A*c - B

S = R.quo([eq1, eq2])
F = FractionField(S)

vE = [F(A), F(B)]
P = [F(a), F(b)]
Q = [F(c), F(d)]
R = add_EC(vE, P, Q)

LHS = add_EC(vE, add_EC(vE, P, Q), R)
RHS = add_EC(vE, P, add_EC(vE, Q, R))
LHS == RHS





-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/fb86fbb5-55ed-49d4-af33-a3c3c3c2f759%40googlegroups.com.

Reply via email to