CoCalc Shared Fileswww / cgi-bin / mfd / elliptic.py
Author: William A. Stein
1#!/usr/bin/python
2
3# elliptic.py
4# (c) William Stein, 2000
5
6import cgi  # cgi-bin
7import Documents, HTML
8
9import misc
10import constants
11# import mfd  # modular forms database
12import magma
13
14import os
15
16print "Content-Type: text/html"      # HTML is following
17print                                # blank line, end of headers
18
19form = cgi.FieldStorage()
20
21def is_numeric(c):
22    return (c >= '0' and c <='9') or c=='-' or c=='+' or c=='/'
23
24def nextnum(s):
25    if len(s) == 0:
26        return 0, 0, 0
27    i=0
28    while not is_numeric(s[i]):
29        i = i+1
30        if i >= len(s):
31            return 0, 0, 0
32    j=i+1
33    while j < len(s) and is_numeric(s[j]):
34        j = j+1
35    return 1, s[i:j], s[j:]
36
37def parse(form):
38    ERROR_MESSAGE = "Please enter either 2, 3 or 5 rational numbers in the a-invariants field.";
39    if not form.has_key("ainvariants"):
40        print "<h1>Error</h1>"
41        print ERROR_MESSAGE
42        return 0, 0
43    s = form["ainvariants"].value
44    e, n1, s = nextnum(s)
45    if not e:
46        print "<h1>Error</h1>"
47        print ERROR_MESSAGE
48        return 0,0
49    e, n2, s = nextnum(s)
50    if not e:
51        print "<h1>Error</h1>"
52        print ERROR_MESSAGE
53        return 0,0
54    e, n3, s = nextnum(s)
55    if not e:
56        return 1, ('0','0','0',n1,n2)
57    e, n4, s = nextnum(s)
58    if not e:
59        return 1, ('0',n1,'0',n2,n3)
60    e, n5, s = nextnum(s)
61    if not e:
62        print "<h1>Error</h1>"
63        print ERROR_MESSAGE
64        return 0,0
65
66    return 1, (n1,n2,n3,n4,n5)
67
68def html_curvedata(ainvs,hostname):
69    doc = Documents.Document()
70
71    doc.append(HTML.TITLE('Modular Forms Database: Curve data'))
72
74                         HREF="http://%s/mfd/mfd.css"%hostname, TITLE="was"))
75
76    body = HTML.BODY(klass="top")
77    doc.append(body)
78
79    body.append(HTML.CENTER(
80        HTML.H1("The elliptic curve defined by [%s,%s,%s,%s,%s]. &nbsp&nbsp "%ainvs)))
81
82    body.append(HTML.CENTER(HTML.A("<br>BACK<br><br>", \
83                                  href="http://%s/mfd/elliptic/index.html"%hostname)))
84
85    cmd = "function factor(x) return Factorization(Numerator(x)) cat " +\
86          "           [<a[1], -a[2]> : a in Factorization(Denominator(x))]; end function;\n "+\
87          "ainvs := [%s,%s,%s,%s,%s];  if not IsEllipticCurve(ainvs) then "%ainvs  +\
88          "ans := \"The Weierstrass equation is singular.\"; " + \
89          " else E:=EllipticCurve(ainvs); G,f:=TorsionSubgroup(E); " + \
90          "eig := qEigenform(E,100); periods := Periods(E); "+ \
91          "ans:=Sprintf(\"<center><b>The %o.</b></center><br>  <ul>" + \
92          "<li>The <b>minimal</b> Weierstrass equation for E has invariants %o<br><br>" + \
93          "<li>The curve E has <b>j-invariant</b> %o, which factors as %o.<br><br>"+\
94          "<li> It has <b>discriminant</b> %o, which factors as %o.<br><br>" +\
95          "<li>It has <b>conductor</b> %o, which factors as %o.<br><br>"+\
96          "<li>The <b>torsion</b> subgroup of E has invariants %o and elements %o.<br><br>"+\
97          "<li>The <b>newform</b> attached to E has q-expansion <pre>f = %o.</pre><br>"+\
98          "<li>The <b>periods</b> of E are <pre>omega1, omega2 = %o.</pre>" +\
99          "\",E,aInvariants(MinimalModel(E)),jInvariant(E),jInvariant(E) eq 0 select 0 else factor(jInvariant(E)), Discriminant(E)," +\
100          "factor(Discriminant(E)),Conductor(E),Factorization(Conductor(E))," +\
101          "Invariants(G),{f(g) : g in G}, eig, periods); end if;";
102
103    ans = magma.magma(cmd, "%s/gomagma_elliptic-curves"%constants.bin)
104
105    body.append(ans)
106
107    print doc
108
109# If the input is valid render the page.
110valid, ainvs = parse(form)
111if valid:
112    html_curvedata(ainvs,constants.hostname)
113
114
115
116
117
118