Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
241852 views
1
"""
2
Andrew Sutherland's Probabilistic Image of Galois Algorithm
3
4
AUTHOR:
5
6
- William Stein, 2010-03 -- wrote the Cython wrapper
7
- Sutherland -- wrote the C code and designed the algorithm
8
"""
9
10
#################################################################################
11
#
12
# (c) Copyright 2010 William Stein
13
#
14
# This file is part of PSAGE
15
#
16
# PSAGE is free software: you can redistribute it and/or modify
17
# it under the terms of the GNU General Public License as published by
18
# the Free Software Foundation, either version 3 of the License, or
19
# (at your option) any later version.
20
#
21
# PSAGE is distributed in the hope that it will be useful,
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
# GNU General Public License for more details.
25
#
26
# You should have received a copy of the GNU General Public License
27
# along with this program. If not, see <http://www.gnu.org/licenses/>.
28
#
29
#################################################################################
30
31
32
include "stdsage.pxi"
33
include "cdefs.pxi"
34
35
from sage.rings.integer cimport Integer
36
37
cdef extern from "galrep.h":
38
int galrep_ecdata_load (char *filename)
39
int galrep_gl2data_load (char *filename)
40
int galrep_ec_modl_image (int ell, mpz_t A, mpz_t B, int errbnd)
41
int galrep_ec_modl_images (int *ccs, int min, int max, mpz_t A, mpz_t B, int errbnd)
42
int galrep_ec_non_surjective (int min, int max, mpz_t A, mpz_t B, int errbnd)
43
int GALREP_MAX_ELL
44
45
46
# There is no need to support pickling for this class, since it is
47
# only used for providing an API for some functions.
48
49
cdef class GalRep:
50
"""
51
Andrew Sutherland's Probabilistic Image of Galois Algorithm
52
"""
53
cdef object primes
54
55
def __init__(self, galrep_ecdata=None, galrep_gl2data=None):
56
"""
57
INPUT:
58
59
- galrep_ecdata -- (default: None); if given, specifies galrep_ecdata.dat filename
60
61
- galrep_gl2data -- (default: None); if given, specifies galrep_gl2data.dat filename
62
63
EXAMPLES::
64
65
sage: from psage.ellcurve.galrep import GalRep
66
sage: GalRep()
67
Andrew Sutherland's Probabilistic Image of Galois Algorithm
68
"""
69
import os
70
base = os.path.abspath(os.path.dirname(__file__))
71
if galrep_ecdata is None:
72
galrep_ecdata = os.path.join(base, 'galrep_ecdata.dat')
73
if galrep_gl2data is None:
74
galrep_gl2data = os.path.join(base, 'galrep_gl2data.dat')
75
for f in [galrep_ecdata, galrep_gl2data]:
76
if not os.path.exists(f):
77
raise IOError, "no file '%s'"%f
78
galrep_ecdata_load(galrep_ecdata)
79
galrep_gl2data_load(galrep_gl2data)
80
self.primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59]
81
82
def mod_ell_image(self, Integer A, Integer B, int ell):
83
"""
84
Returns the conjugacy class id of the image of the mod-ell
85
Galois representation attached to the elliptic curve
86
y^2=x^3+A*x+B. The id code 0 signifies a surjective
87
representation.
88
89
INPUT:
90
- A -- integer
91
- B -- integer
92
- ell -- prime integer (must be <= 59)
93
94
OUTPUT:
95
- integer
96
97
EXAMPLES::
98
99
sage: from psage.ellcurve.galrep import GalRep
100
sage: GalRep().mod_ell_image(-432,8208,3)
101
0
102
sage: GalRep().mod_ell_image(-432,8208,2)
103
0
104
sage: GalRep().mod_ell_image(-432,8208,5)
105
9
106
sage: GalRep().mod_ell_image(-432,8208,0)
107
Traceback (most recent call last):
108
...
109
ValueError: ell (=0) must be a prime <= 59
110
sage: GalRep().mod_ell_image(-432,8208,67)
111
Traceback (most recent call last):
112
...
113
ValueError: ell (=67) must be a prime <= 59
114
"""
115
cdef int a = galrep_ec_modl_image(ell, A.value, B.value, 0)
116
if a == -1: raise ValueError, "ell (=%s) must be a prime <= %s"%(ell, GALREP_MAX_ELL)
117
return a
118
119
def mod_ell_images(self, Integer A, Integer B, int min=2, int max=59):
120
"""
121
Returns list of the conjugacy class id's of the images of the
122
mod-ell Galois representation attached to the elliptic curve
123
y^2=x^3+A*x+B for ell in the interval [min, max]. The id code
124
0 signifies a surjective representation.
125
126
INPUT:
127
- A -- integer
128
- B -- integer
129
- min -- integer (default: 2)
130
- max -- integer (default: 59) (must be <= 59)
131
132
OUTPUT:
133
- list of primes
134
135
EXAMPLES::
136
137
sage: from psage.ellcurve.galrep import GalRep
138
sage: GalRep().mod_ell_images(-432,8208)
139
[0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
140
sage: GalRep().mod_ell_images(-432,8208,2,10)
141
[0, 0, 9, 0]
142
"""
143
if min >= max:
144
raise ValueError, "max must be bigger than min"
145
if max > GALREP_MAX_ELL:
146
raise ValueError, "max must be <= %s"%GALREP_MAX_ELL
147
cdef int* ccs = <int*> sage_malloc(sizeof(int)*len(self.primes))
148
cdef int i, a = galrep_ec_modl_images (ccs, min, max, A.value, B.value, 0)
149
cdef list v = []
150
for i in range(len(self.primes)):
151
if self.primes[i] > max: break
152
v.append(ccs[i])
153
sage_free(ccs)
154
return v
155
156
def non_surjective_primes(self, Integer A, Integer B, int min=2, int max=59):
157
"""
158
Returns a list of the primes ell in the interval [min, max]
159
(default=[2,59]) such that the mod-ell Galois representation
160
attached to y^2=x^3+A*x+B is highly likely to be
161
non-surjective.
162
163
INPUT:
164
- A -- integer
165
- B -- integer
166
- min -- integer (default: 2)
167
- max -- integer (default: 59) (must be <= 59)
168
169
OUTPUT:
170
- list of primes
171
172
EXAMPLES::
173
174
sage: from psage.ellcurve.galrep import GalRep
175
sage: GalRep().non_surjective_primes(-432,8208)
176
[5]
177
sage: GalRep().non_surjective_primes(-432,8208,7,59)
178
[]
179
sage: GalRep().non_surjective_primes(-432,8208,1,10)
180
[5]
181
"""
182
if min >= max:
183
raise ValueError, "max must be bigger than min"
184
cdef int a = galrep_ec_non_surjective (min, max, A.value, B.value, 0)
185
if a == -1: raise ValueError, "min and max must be <= %s"%GALREP_MAX_ELL
186
cdef int i, j=1
187
v = []
188
for i in range(len(self.primes)):
189
if a & j:
190
v.append(self.primes[i])
191
j = j << 1
192
return v
193
194
def __repr__(self):
195
"""
196
EXAMPLES::
197
198
sage: from psage.ellcurve.galrep import GalRep
199
sage: GalRep().__repr__()
200
"Andrew Sutherland's Probabilistic Image of Galois Algorithm"
201
"""
202
return "Andrew Sutherland's Probabilistic Image of Galois Algorithm"
203
204
205
206