#!/usr/bin/python
# elliptic.py
# (c) William Stein, 2000
import cgi # cgi-bin
import Documents, HTML
import misc
import constants
# import mfd # modular forms database
import magma
import os
print "Content-Type: text/html" # HTML is following
print # blank line, end of headers
form = cgi.FieldStorage()
def is_numeric(c):
return (c >= '0' and c <='9') or c=='-' or c=='+' or c=='/'
def nextnum(s):
if len(s) == 0:
return 0, 0, 0
i=0
while not is_numeric(s[i]):
i = i+1
if i >= len(s):
return 0, 0, 0
j=i+1
while j < len(s) and is_numeric(s[j]):
j = j+1
return 1, s[i:j], s[j:]
def parse(form):
ERROR_MESSAGE = "Please enter either 2, 3 or 5 rational numbers in the a-invariants field.";
if not form.has_key("ainvariants"):
print "
Error
"
print ERROR_MESSAGE
return 0, 0
s = form["ainvariants"].value
e, n1, s = nextnum(s)
if not e:
print "Error
"
print ERROR_MESSAGE
return 0,0
e, n2, s = nextnum(s)
if not e:
print "Error
"
print ERROR_MESSAGE
return 0,0
e, n3, s = nextnum(s)
if not e:
return 1, ('0','0','0',n1,n2)
e, n4, s = nextnum(s)
if not e:
return 1, ('0',n1,'0',n2,n3)
e, n5, s = nextnum(s)
if not e:
print "Error
"
print ERROR_MESSAGE
return 0,0
return 1, (n1,n2,n3,n4,n5)
def html_curvedata(ainvs,hostname):
doc = Documents.Document()
doc.append(HTML.TITLE('Modular Forms Database: Curve data'))
doc.append(HTML.LINK(rel="stylesheet", type="text/css", \
HREF="http://%s/mfd/mfd.css"%hostname, TITLE="was"))
body = HTML.BODY(klass="top")
doc.append(body)
body.append(HTML.CENTER(
HTML.H1("The elliptic curve defined by [%s,%s,%s,%s,%s].    "%ainvs)))
body.append(HTML.CENTER(HTML.A("
BACK
", \
href="http://%s/mfd/elliptic/index.html"%hostname)))
cmd = "function factor(x) return Factorization(Numerator(x)) cat " +\
" [ : a in Factorization(Denominator(x))]; end function;\n "+\
"ainvs := [%s,%s,%s,%s,%s]; if not IsEllipticCurve(ainvs) then "%ainvs +\
"ans := \"The Weierstrass equation is singular.\"; " + \
" else E:=EllipticCurve(ainvs); G,f:=TorsionSubgroup(E); " + \
"eig := qEigenform(E,100); periods := Periods(E); "+ \
"ans:=Sprintf(\"The %o.
" + \
"- The minimal Weierstrass equation for E has invariants %o
" + \
" - The curve E has j-invariant %o, which factors as %o.
"+\
" - It has discriminant %o, which factors as %o.
" +\
" - It has conductor %o, which factors as %o.
"+\
" - The torsion subgroup of E has invariants %o and elements %o.
"+\
" - The newform attached to E has q-expansion
f = %o.
"+\
" - The periods of E are
omega1, omega2 = %o.
" +\
"\",E,aInvariants(MinimalModel(E)),jInvariant(E),jInvariant(E) eq 0 select 0 else factor(jInvariant(E)), Discriminant(E)," +\
"factor(Discriminant(E)),Conductor(E),Factorization(Conductor(E))," +\
"Invariants(G),{f(g) : g in G}, eig, periods); end if;";
ans = magma.magma(cmd, "%s/gomagma_elliptic-curves"%constants.bin)
body.append(ans)
print doc
# If the input is valid render the page.
valid, ainvs = parse(form)
if valid:
html_curvedata(ainvs,constants.hostname)