| 1 | """ |
|---|
| 2 | Database of Modular Polynomials |
|---|
| 3 | """ |
|---|
| 4 | |
|---|
| 5 | ####################################################################### |
|---|
| 6 | # |
|---|
| 7 | # SAGE: System for Algebra and Geometry Experimentation |
|---|
| 8 | # |
|---|
| 9 | # Copyright (C) 2006 William Stein <wstein@gmail.com> |
|---|
| 10 | # Copyright (C) 2006 David Kohel <kohel@maths.usyd.edu.au> |
|---|
| 11 | # |
|---|
| 12 | # Distributed under the terms of the GNU General Public License (GPL) |
|---|
| 13 | # |
|---|
| 14 | # The full text of the GPL is available at: |
|---|
| 15 | # |
|---|
| 16 | # http://www.gnu.org/licenses/ |
|---|
| 17 | ####################################################################### |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | import bz2, os |
|---|
| 21 | import sage.misc.misc |
|---|
| 22 | import sage.rings.polydict as polydict # internal representation may change!!! |
|---|
| 23 | from sage.rings.integer import Integer |
|---|
| 24 | from sage.rings.integer_ring import IntegerRing |
|---|
| 25 | from sage.rings.multi_polynomial_ring import MPolynomialRing |
|---|
| 26 | |
|---|
| 27 | DB_HOME = '%s/kohel'%sage.misc.misc.SAGE_DATA |
|---|
| 28 | |
|---|
| 29 | def _dbz_to_integer_list(name): |
|---|
| 30 | file = '%s/%s'%(DB_HOME, name) |
|---|
| 31 | if not os.path.exists(file): |
|---|
| 32 | raise RuntimeError, "Modular polynomial database file %s not available"%file |
|---|
| 33 | data = bz2.decompress(open(file).read()) |
|---|
| 34 | data = "[[" + data.replace("\n","],[").replace(" ",",")[:-2] + "]" |
|---|
| 35 | return eval(data) |
|---|
| 36 | |
|---|
| 37 | def _pad_int(s,n): |
|---|
| 38 | return "0"*(n-len(str(s))) + str(s) |
|---|
| 39 | |
|---|
| 40 | class ModularPolynomialDatabase: |
|---|
| 41 | def _dbpath(self,level): |
|---|
| 42 | return "PolMod/%s/pol.%s.dbz"%(self.model, _pad_int(level,3)) |
|---|
| 43 | |
|---|
| 44 | def __repr__(self): |
|---|
| 45 | if self.model == "Cls": |
|---|
| 46 | head = "Classical" |
|---|
| 47 | poly = "polynomial" |
|---|
| 48 | elif self.model == "Atk": |
|---|
| 49 | head = "Atkin" |
|---|
| 50 | poly = "polynomial" |
|---|
| 51 | elif self.model == "AtkCrr": |
|---|
| 52 | head = "Atkin" |
|---|
| 53 | poly = "correspondence" |
|---|
| 54 | elif self.model == "Eta": |
|---|
| 55 | head = "Dedekind eta" |
|---|
| 56 | poly = "polynomial" |
|---|
| 57 | elif self.model == "EtaCrr": |
|---|
| 58 | head = "Dedekind eta" |
|---|
| 59 | poly = "correspondence" |
|---|
| 60 | return "%s modular %s database"%(head,poly) |
|---|
| 61 | |
|---|
| 62 | def __getitem__(self,level): |
|---|
| 63 | if self.model != "Cls": |
|---|
| 64 | level = Integer(level) |
|---|
| 65 | if not level.is_prime(): |
|---|
| 66 | raise TypeError, "Argument level (= %s) must be prime."%level |
|---|
| 67 | modpol = self._dbpath(level) |
|---|
| 68 | try: |
|---|
| 69 | coeff_list = _dbz_to_integer_list(modpol) |
|---|
| 70 | except RuntimeError, msg: |
|---|
| 71 | print msg |
|---|
| 72 | raise RuntimeError, \ |
|---|
| 73 | "No database entry for modular polynomial of level %s"%level |
|---|
| 74 | if self.model == "Cls": |
|---|
| 75 | P = MPolynomialRing(IntegerRing(),2,"j") |
|---|
| 76 | else: |
|---|
| 77 | P = MPolynomialRing(IntegerRing(),2,"x,j") |
|---|
| 78 | poly = {} |
|---|
| 79 | if self.model == "Cls": |
|---|
| 80 | if level == 1: |
|---|
| 81 | return P(polydict.PolyDict({(1,0):1,(0,1):-1})) |
|---|
| 82 | for cff in coeff_list: |
|---|
| 83 | i = cff[0] |
|---|
| 84 | j = cff[1] |
|---|
| 85 | poly[(i,j)] = Integer(cff[2]) |
|---|
| 86 | if i != j: |
|---|
| 87 | poly[(j,i)] = Integer(cff[2]) |
|---|
| 88 | else: |
|---|
| 89 | for cff in coeff_list: |
|---|
| 90 | poly[(cff[0],cff[1])] = Integer(cff[2]) |
|---|
| 91 | return P(polydict.PolyDict(poly)) |
|---|
| 92 | |
|---|
| 93 | class ModularCorrespondenceDatabase(ModularPolynomialDatabase): |
|---|
| 94 | def _dbpath(self,level): |
|---|
| 95 | (Nlevel,crrlevel) = level |
|---|
| 96 | return "PolMod/%s/corr.%s.%s.dbz"%( |
|---|
| 97 | self.model, _pad_int(Nlevel,2), _pad_int(crrlevel,3)) |
|---|
| 98 | |
|---|
| 99 | class ClassicalModularPolynomialDatabase(ModularPolynomialDatabase): |
|---|
| 100 | """ |
|---|
| 101 | The database of classical modular polynomials, i.e. the polynomials |
|---|
| 102 | Phi_N(X,Y) relating the j-functions j(q) and j(q^N). |
|---|
| 103 | """ |
|---|
| 104 | def __init__(self): |
|---|
| 105 | """ |
|---|
| 106 | Initialize the database. |
|---|
| 107 | """ |
|---|
| 108 | self.model = "Cls" |
|---|
| 109 | |
|---|
| 110 | class DedekindEtaModularPolynomialDatabase(ModularPolynomialDatabase): |
|---|
| 111 | """ |
|---|
| 112 | The database of modular polynomials Phi_N(X,Y) relating a quotient |
|---|
| 113 | of Dedekind eta functions, well-defined on X_0(N), relating x(q) and |
|---|
| 114 | the j-function j(q). |
|---|
| 115 | """ |
|---|
| 116 | def __init__(self): |
|---|
| 117 | """ |
|---|
| 118 | Initialize the database. |
|---|
| 119 | """ |
|---|
| 120 | self.model = "Eta" |
|---|
| 121 | |
|---|
| 122 | class DedekindEtaModularCorrespondenceDatabase(ModularCorrespondenceDatabase): |
|---|
| 123 | """ |
|---|
| 124 | The database of modular correspondences in $X_0(p) \times X_0(p)$, where |
|---|
| 125 | the model of the curves $X_0(p) = \PP^1$ are specified by quotients of |
|---|
| 126 | Dedekind's eta function. |
|---|
| 127 | """ |
|---|
| 128 | def __init__(self): |
|---|
| 129 | """ |
|---|
| 130 | Returns the |
|---|
| 131 | """ |
|---|
| 132 | self.model = "EtaCrr" |
|---|
| 133 | |
|---|
| 134 | class AtkinModularPolynomialDatabase(ModularPolynomialDatabase): |
|---|
| 135 | """ |
|---|
| 136 | The database of modular polynomials Phi(x,j) for $X_0(p)$, where |
|---|
| 137 | x is a function on invariant under the Atkin-Lehner invariant, |
|---|
| 138 | with pole of minimal order at infinity. |
|---|
| 139 | """ |
|---|
| 140 | def __init__(self): |
|---|
| 141 | """ |
|---|
| 142 | Initialize the database. |
|---|
| 143 | """ |
|---|
| 144 | self.model = "Atk" |
|---|
| 145 | |
|---|
| 146 | class AtkinModularCorrespondenceDatabase(ModularCorrespondenceDatabase): |
|---|
| 147 | def __init__(self): |
|---|
| 148 | """ |
|---|
| 149 | Initialize the database. |
|---|
| 150 | """ |
|---|
| 151 | self.model = "AtkCrr" |
|---|