This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
projective_morphism_helper.pyx
277 lines (217 loc) · 8.54 KB
/
projective_morphism_helper.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
r"""
Morphisms on projective varieties (Cython helper)
This is the helper file providing functionality for projective_morphism.py.
AUTHORS:
- Dillon Rose (2014-01): Speed enhancements
- Ben Hutz (2015-11): subscheme iteration
"""
#*****************************************************************************
# Copyright (C) 2014 William Stein <wstein@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
#
# http://www.gnu.org/licenses/
#*****************************************************************************
from sage.rings.arith import lcm
from sage.rings.finite_rings.constructor import GF
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.sets.all import Set
from sage.misc.misc import subsets
def _fast_possible_periods(self,return_points=False):
r"""
Returns the list of possible minimal periods of a periodic point
over `\QQ` and (optionally) a point in each cycle.
ALGORITHM:
The list comes from B. Hutz. Good reduction of periodic points, Illinois Journal of
Mathematics 53 (Winter 2009), no. 4, 1109-1126..
INPUT:
- ``return_points`` - Boolean (optional) - a value of True returns the points as well as the possible periods.
OUTPUT:
- a list of positive integers, or a list of pairs of projective points and periods if ``flag`` is 1.
Examples::
sage: from sage.schemes.projective.projective_morphism_helper import _fast_possible_periods
sage: P.<x,y>=ProjectiveSpace(GF(23),1)
sage: H=Hom(P,P)
sage: f=H([x^2-2*y^2,y^2])
sage: _fast_possible_periods(f,False)
[1, 5, 11, 22, 110]
::
sage: from sage.schemes.projective.projective_morphism_helper import _fast_possible_periods
sage: P.<x,y> = ProjectiveSpace(GF(13),1)
sage: H = End(P)
sage: f = H([x^2-y^2,y^2])
sage: sorted(_fast_possible_periods(f,True))
[[(0 : 1), 2], [(1 : 0), 1], [(3 : 1), 3], [(3 : 1), 36]]
::
sage: from sage.schemes.projective.projective_morphism_helper import _fast_possible_periods
sage: PS.<x,y,z> = ProjectiveSpace(2,GF(7))
sage: H = End(PS)
sage: f = H([-360*x^3 + 760*x*z^2, y^3 - 604*y*z^2 + 240*z^3, 240*z^3])
sage: _fast_possible_periods(f,False)
[1, 2, 4, 6, 12, 14, 28, 42, 84]
.. TODO::
- more space efficient hash/pointtable
"""
cdef int i, k
cdef list pointslist
if not self._is_prime_finite_field:
raise TypeError("Must be prime field")
from sage.schemes.projective.projective_space import is_ProjectiveSpace
if is_ProjectiveSpace(self.domain()) == False or self.domain()!=self.codomain():
raise NotImplementedError("Must be an endomorphism of projective space")
PS = self.domain()
p = PS.base_ring().order()
N = PS.dimension_relative()
point_table = [[0,0] for i in xrange(p**(N + 1))]
index = 1
periods = set()
points_periods = []
for P in _enum_points(p, N):
hash_p = _hash(P, p)
if point_table[hash_p][1] == 0:
startindex = index
while point_table[hash_p][1] == 0:
point_table[hash_p][1] = index
Q = self._fast_eval(P)
Q = _normalize_coordinates(Q, p, N+1)
hash_q = _hash(Q, p)
point_table[hash_p][0] = hash_q
P=Q
hash_p=hash_q
index+=1
if point_table[hash_p][1] >= startindex:
P_proj=PS(P)
period=index-point_table[hash_p][1]
periods.add(period)
points_periods.append([P_proj,period])
l=P_proj.multiplier(self,period,False)
lorders=set()
for poly,_ in l.charpoly().factor():
if poly.degree() == 1:
eig = -poly.constant_coefficient()
if not eig:
continue # exclude 0
else:
eig = GF(p ** poly.degree(), 't', modulus=poly).gen()
if eig:
lorders.add(eig.multiplicative_order())
S = subsets(lorders)
next(S) # get rid of the empty set
rvalues=set()
for s in S:
rvalues.add(lcm(s))
rvalues=list(rvalues)
if N==1:
for k in xrange(len(rvalues)):
r=rvalues[k]
periods.add(period*r)
points_periods.append([P_proj,period*r])
if p == 2 or p == 3: #need e=1 for N=1, QQ
periods.add(period*r*p)
points_periods.append([P_proj,period*r*p])
else:
for k in xrange(len(rvalues)):
r=rvalues[k]
periods.add(period*r)
periods.add(period*r*p)
points_periods.append([P_proj,period*r])
points_periods.append([P_proj,period*r*p])
if p==2: #need e=3 for N>1, QQ
periods.add(period*r*4)
points_periods.append([P_proj,period*r*4])
periods.add(period*r*8)
points_periods.append([P_proj,period*r*8])
if return_points==False:
return sorted(periods)
else:
return(points_periods)
def _enum_points(int prime,int dimension):
"""
Enumerate points in projective space over finite field with given prime and dimension.
EXAMPLES::
sage: from sage.schemes.projective.projective_morphism_helper import _enum_points
sage: list(_enum_points(3,2))
[[1, 0, 0], [0, 1, 0], [1, 1, 0], [2, 1, 0], [0, 0, 1], [1, 0, 1], [2, 0, 1], [0, 1, 1], [1, 1, 1], [2, 1, 1], [0, 2, 1], [1, 2, 1], [2, 2, 1]]
"""
cdef int current_range
cdef int highest_range
cdef int value
current_range = 1
highest_range = prime**dimension
while current_range <= highest_range:
for value in xrange(current_range, 2*current_range):
yield _get_point_from_hash(value,prime,dimension)
current_range = current_range*prime
def _hash(list Point,int prime):
"""
Hash point given as list to unique number.
EXAMPLES::
sage: from sage.schemes.projective.projective_morphism_helper import _hash
sage: _hash([1, 2, 1], 3)
16
"""
cdef int hash_q
cdef int coefficient
Point.reverse()
hash_q = 0
for coefficient in Point:
hash_q = hash_q * prime + coefficient
Point.reverse()
return hash_q
def _get_point_from_hash(int value,int prime,int dimension):
"""
Hash unique number to point as a list.
EXAMPLES::
sage: from sage.schemes.projective.projective_morphism_helper import _get_point_from_hash
sage: _get_point_from_hash(16,3,2)
[1, 2, 1]
"""
cdef list P
cdef int i
P=[]
for i in xrange(dimension + 1):
P.append(value % prime)
value = value / prime
return P
def _mod_inv(int num, int prime):
"""
Find the inverse of the number modulo the given prime.
EXAMPLES::
sage: from sage.schemes.projective.projective_morphism_helper import _mod_inv
sage: _mod_inv(2,7)
4
"""
cdef int a, b, q, t, x, y
a = prime
b = num
x = 1
y = 0
while b != 0:
t = b
q = a/t
b = a - q*t
a = t
t = x
x = y - q*t
y = t
if y < 0:
return y + prime
else:
return y
def _normalize_coordinates(list point, int prime, int len_points):
"""
Normalize the coordinates of the point for the given prime.
EXAMPLES::
sage: from sage.schemes.projective.projective_morphism_helper import _normalize_coordinates
sage: _normalize_coordinates([1,5,1],3,3)
[1, 2, 1]
"""
cdef int last_coefficient, coefficient, mod_inverse
for coefficient in xrange(len_points):
point[coefficient] = (point[coefficient]+prime)%prime
if point[coefficient] != 0:
last_coefficient = point[coefficient]
mod_inverse = _mod_inv(last_coefficient,prime)
for coefficient in xrange(len_points):
point[coefficient] = (point[coefficient]*mod_inverse)%prime
return point