Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 2011-11-29 06:20:19 -0600

DSM gravatar image

The current idiom is something like this:

n = 51
K = 720
C = EllipticCurve(Integers(n), [2, 49])
P = C([1,1])

try:
    K*P
except ZeroDivisionError as err:
    d = Integer(err.args[0].split()[2])
    g = gcd(d,n)
    print n, 'has divisor', g

You'll sometimes see "except ZeroDivisionError, e:" which is an older style. The args[0].split()[2] stuff is because the exception which is thrown has a string as the first argument of the args tuple:

sage: err.args
('Inverse of 34 does not exist (characteristic = 51 = 17*3)',)

so it's not so pretty to extract it in this case.

The relevant section of the Python tutorial covers it pretty well.

The current idiom is something like this:

n = 51
K = 720
C = EllipticCurve(Integers(n), [2, 49])
P = C([1,1])

try:
    K*P
except ZeroDivisionError as err:
    d = Integer(err.args[0].split()[2])
    g = gcd(d,n)
    print n, 'has divisor', g

You'll sometimes see "except ZeroDivisionError, e:" which is an older style. The args[0].split()[2] stuff is because the exception which is thrown has a string as the first argument of the args tuple:

sage: err.args
('Inverse of 34 does not exist (characteristic = 51 = 17*3)',)

so it's not so pretty to extract it in this case.

The relevant section of the Python tutorial covers it pretty well.