Alice
Alice

Reputation: 21

Plotting an elliptic curve in SageMath

I have never used SageMath in my life and I am relying on the internet for a crash course on how to get what I want out of SageMath (to plot an elliptic curve over a finite field).

I'm using this code, pasted below:

@interact
def f(label='37a', p=tuple(prime_range(1000))):
 try: E = EllipticCurve(label)
 except:
 print "invalid label %s"%label; return
 try:
show(graphics_array([plot(E,thickness=3),plot(E.change_ring(GF(p)))]),frame=True)
 except Exception, msg:
 print msg

There seems to be a bracket missing, but I don't have the experience to know where it should go. The error message I get is:

Error in lines 1-6
Traceback (most recent call last):
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute
    exec compile(block+'\n', '', 'single') in namespace, locals
  File "<string>", line 4
    except:
          ^
IndentationError: unindent does not match any outer indentation level

Upvotes: 1

Views: 1200

Answers (1)

davidlowryduda
davidlowryduda

Reputation: 2559

The error you've given seems to indicate that the line after except: is not indented more than except: is indented. Python cares about indentation levels a lot.

You might try the following.

@interact
def f(label='37a', p=tuple(prime_range(1000))):
    try:
        E = EllipticCurve(label)
    except:
        print "invalid label %s"%label; return
    try:
        show(graphics_array([plot(E,thickness=3), plot(E.change_ring(GF(p)))]), frame=True)
    except Exception, msg:
        print msg

Aside: You should use four spaces before code to have them display as a codeblock. For more, see How do I format My Code Blocks?

Upvotes: 1

Related Questions