CoCalc Public Fileswww / cgi-bin / mfd / heegner.py
Author: William A. Stein
Compute Environment: Ubuntu 18.04 (Deprecated)
1# heegner.py -- computing heegner points stuff in support of mfd.py
2
3# william stein
4
5import constants, os, pari, time
6
7def compute_heegner_indexes_odd_rank1(E):
8    reg = E.regulator()
9    if reg == constants.not_computed:
10        return E.heegner_indexes_odd()
11    heights = E.heegner_heights()[1]
12    if heights == constants.not_computed:
13        return constants.not_computed
14    cmd = "indexes(reg, heights) = "\
15          "ans = [];"\
16          "for(i=1,length(heights),"\
17          "   w = heights[i]/reg;"\
18          "   x = round(w); if(abs(w-x)>0.01, return(0));"\
19          "   if(x != 0, x = x/(2^valuation(x,2)));"\
20          "   y = round(sqrt(x)); if(abs(y-sqrt(x))>0.01, return(0));"\
21          "   ans=concat(ans,y)"\
22          ");"\
23          "return(ans);\n"\
24          "indexes(%s,%s)"%(reg,heights)
25    indexes = pari.pari(cmd)
26    if indexes == '0':
27        print "compute_heegner_indexes_odd: WARNING: precision not good enough!"
28        return E.heegner_indexes_odd()
29    proofs = []
30    for i in range(len(heights)):
31        proofs.append(E.level <= 1000)
32    E.set_heegner_indexes_odd(indexes, proofs)
33    return E.heegner_indexes_odd()
34
35def mwrank_regulator(a_invariants):
36    t0 = time.time()
37    print "Computing regulator of ", a_invariants
38    cmd = "echo %s 0 0 0 0 0 | mwrank 2>/dev/null |grep Regulator "%a_invariants
39    cmd = cmd.replace("'","")
40    ans = os.popen2(cmd)[1].read()
41    print "time = ", time.time()-t0
42    return ans[ans.find("= ")+2:-1]
43
45    cmd = 'read("/var/www/%s/heegner.gp"); quadratic_twist(%s, %s);'%(constants.CGIROOT,invs, D)
46    ans = pari.pari(cmd)
47    j = 0
48    for i in range(5):
49        j = j + ans[j:].find(",")+1
50    return ans[:j-1]+"]"
51
52
53def compute_heegner_indexes_odd_rank0(E):
54    num_discs = 1
55    a = E.heegner_heights()
56    if a == constants.not_computed or a[0] == constants.not_computed or \
57       a[1] == constants.not_computed:
58        return constants.not_computed
59    ainvs = ("%s"%E.a_invariants()).replace("'","")
60    disc = a[0]
61    heights = a[1]
62    regs = range(num_discs)
63    for i in range(num_discs):
64        # compute regulators of twists
65        D = disc[i]
66        hyD = heights[i]
67        invs = quadratic_twist_invariants(ainvs,D)
68        regs[i] = mwrank_regulator(invs)
69    cmd = "indexes(regs, heights) = " +\
70          "ans = [];" +\
71          "for(i=1,length(regs)," +\
72          "   w = heights[i]/regs[i];" +\
73          "   x = round(w); if(abs(w-x)>0.01, return(0));" +\
74          "   if(x != 0, x = x/(2^valuation(x,2)));"+\
75          "   y = round(sqrt(x)); if(abs(y-sqrt(x))>0.01, return(0));" +\
76          "   ans=concat(ans,y)" +\
77          ");" +\
78          "return(ans);\n" +\
79          "indexes(%s,%s)"%(regs,heights)
80    cmd = cmd.replace("'","")
81    indexes = pari.pari(cmd)
82    regs = ("%s"%regs).replace("'","")
83    print "indexes = ", indexes, " regs = ", regs
84    if indexes == '0':
85        print "compute_heegner_indexes_odd: WARNING: precision not good enough!"
86        return E.heegner_indexes_odd()
87    E.set_heegner_indexes_odd(indexes,regs)
88    return E.heegner_indexes_odd()
89
90def compute_heegner_indexes_odd(E):
91    if E.mwrank() == 1:
92        return compute_heegner_indexes_odd_rank1(E)
93    if E.mwrank() == 0:
94        return compute_heegner_indexes_odd_rank0(E)
95
96