Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/schemes/affine/affine_point.py
8820 views
1
r"""
2
Points on affine varieties
3
4
Scheme morphism for points on affine varieties
5
6
7
8
AUTHORS:
9
10
- David Kohel, William Stein
11
12
- Volker Braun (2011-08-08): Renamed classes, more documentation, misc
13
cleanups.
14
15
- Ben Hutz (2013)
16
"""
17
18
# Historical note: in trac #11599, V.B. renamed
19
# * _point_morphism_class -> _morphism
20
# * _homset_class -> _point_homset
21
22
#*****************************************************************************
23
# Copyright (C) 2011 Volker Braun <[email protected]>
24
# Copyright (C) 2006 David Kohel <[email protected]>
25
# Copyright (C) 2006 William Stein <[email protected]>
26
#
27
# Distributed under the terms of the GNU General Public License (GPL)
28
# as published by the Free Software Foundation; either version 2 of
29
# the License, or (at your option) any later version.
30
# http://www.gnu.org/licenses/
31
#*****************************************************************************
32
33
from copy import copy
34
from sage.categories.number_fields import NumberFields
35
_NumberFields = NumberFields()
36
from sage.rings.integer_ring import ZZ
37
from sage.rings.number_field.order import is_NumberFieldOrder
38
from sage.rings.rational_field import QQ
39
from sage.rings.real_mpfr import RealField
40
from sage.schemes.generic.morphism import (SchemeMorphism_point, SchemeMorphism, is_SchemeMorphism)
41
from sage.structure.sequence import Sequence
42
43
############################################################################
44
# Rational points on schemes, which we view as morphisms determined
45
# by coordinates.
46
############################################################################
47
48
class SchemeMorphism_point_affine(SchemeMorphism_point):
49
"""
50
A rational point on an affine scheme.
51
52
INPUT:
53
54
- ``X`` -- a subscheme of an ambient affine space over a ring `R`.
55
56
- ``v`` -- a list/tuple/iterable of coordinates in `R`.
57
58
- ``check`` -- boolean (optional, default:``True``). Whether to
59
check the input for consistency.
60
61
EXAMPLES::
62
63
sage: A = AffineSpace(2, QQ)
64
sage: A(1,2)
65
(1, 2)
66
"""
67
def __init__(self, X, v, check=True):
68
"""
69
The Python constructor.
70
71
See :class:`SchemeMorphism_point_affine` for details.
72
73
TESTS::
74
75
sage: from sage.schemes.affine.affine_point import SchemeMorphism_point_affine
76
sage: A3.<x,y,z> = AffineSpace(QQ, 3)
77
sage: SchemeMorphism_point_affine(A3(QQ), [1,2,3])
78
(1, 2, 3)
79
"""
80
SchemeMorphism.__init__(self, X)
81
if is_SchemeMorphism(v):
82
v = list(v)
83
if check:
84
# Verify that there are the right number of coords
85
d = self.codomain().ambient_space().ngens()
86
if len(v) != d:
87
raise TypeError("Argument v (=%s) must have %s coordinates."%(v, d))
88
if not isinstance(v,(list,tuple)):
89
raise TypeError("Argument v (= %s) must be a scheme point, list, or tuple."%str(v))
90
# Make sure the coordinates all lie in the appropriate ring
91
v = Sequence(v, X.value_ring())
92
# Verify that the point satisfies the equations of X.
93
X.extended_codomain()._check_satisfies_equations(v)
94
self._coords = tuple(v)
95
96
def nth_iterate(self,f,n):
97
r"""
98
Returns the point `f^n(self)`
99
100
INPUT:
101
102
- ``f`` -- a :class:`SchemeMorphism_polynomial` with ``self`` if ``f.domain()``
103
- ``n`` -- a positive integer.
104
105
OUTPUT:
106
107
- a point in ``f.codomain()``
108
109
EXAMPLES::
110
111
sage: A.<x,y>=AffineSpace(QQ,2)
112
sage: H=Hom(A,A)
113
sage: f=H([(x-2*y^2)/x,3*x*y])
114
sage: A(9,3).nth_iterate(f,3)
115
(-104975/13123, -9566667)
116
117
::
118
119
sage: A.<x,y>=AffineSpace(ZZ,2)
120
sage: X=A.subscheme([x-y^2])
121
sage: H=Hom(X,X)
122
sage: f=H([9*y^2,3*y])
123
sage: X(9,3).nth_iterate(f,4)
124
(59049, 243)
125
"""
126
if self.codomain()!=f.domain():
127
raise TypeError("Point is not defined over domain of function")
128
if f.domain() != f.codomain():
129
raise TypeError("Domain and Codomain of function not equal")
130
if n==0:
131
return(self)
132
else:
133
Q=f(self)
134
for i in range(2,n+1):
135
Q=f(Q)
136
return(Q)
137
138
def orbit(self,f,N):
139
r"""
140
Returns the orbit of self by `f`. If `n` is an integer it returns `[self,f(self),\ldots,f^{n}(self)]`.
141
142
If `n` is a list or tuple `n=[m,k]` it returns `[f^{m}(self),\ldots,f^{k}(self)]`.
143
144
INPUT:
145
146
- ``f`` -- a :class:`SchemeMorphism_polynomial` with ``self`` in ``f.domain()``
147
- ``n`` -- a non-negative integer or list or tuple of two non-negative integers
148
149
OUTPUT:
150
151
- a list of points in ``f.codomain()``
152
153
EXAMPLES::
154
155
sage: A.<x,y>=AffineSpace(QQ,2)
156
sage: H=Hom(A,A)
157
sage: f=H([(x-2*y^2)/x,3*x*y])
158
sage: A(9,3).orbit(f,3)
159
[(9, 3), (-1, 81), (13123, -243), (-104975/13123, -9566667)]
160
161
::
162
163
sage: A.<x>=AffineSpace(QQ,1)
164
sage: H=Hom(A,A)
165
sage: f=H([(x-2)/x])
166
sage: A(1/2).orbit(f,[1,3])
167
[(-3), (5/3), (-1/5)]
168
169
::
170
171
sage: A.<x,y>=AffineSpace(ZZ,2)
172
sage: X=A.subscheme([x-y^2])
173
sage: H=Hom(X,X)
174
sage: f=H([9*y^2,3*y])
175
sage: X(9,3).orbit(f,(0,4))
176
[(9, 3), (81, 9), (729, 27), (6561, 81), (59049, 243)]
177
"""
178
Q=copy(self)
179
if type(N)==list or type(N)==tuple:
180
Bounds=list(N)
181
else:
182
Bounds=[0,N]
183
for i in range(1,Bounds[0]+1):
184
Q=f(Q)
185
Orb=[Q]
186
for i in range(Bounds[0]+1,Bounds[1]+1):
187
Q=f(Q)
188
Orb.append(Q)
189
return(Orb)
190
191
def global_height(self, prec=None):
192
r"""
193
Returns the logarithmic height of the point.
194
195
INPUT:
196
197
- ``prec`` -- desired floating point precision (default:
198
default RealField precision).
199
200
OUTPUT:
201
202
- a real number
203
204
EXAMPLES::
205
206
sage: P.<x,y>=AffineSpace(QQ,2)
207
sage: Q=P(41,1/12)
208
sage: Q.global_height()
209
3.71357206670431
210
211
::
212
213
sage: P=AffineSpace(ZZ,4,'x')
214
sage: Q=P(3,17,-51,5)
215
sage: Q.global_height()
216
3.93182563272433
217
218
::
219
220
sage: R.<x>=PolynomialRing(QQ)
221
sage: k.<w>=NumberField(x^2+5)
222
sage: A=AffineSpace(k,2,'z')
223
sage: A([3,5*w+1]).global_height(prec=100)
224
2.4181409534757389986565376694
225
226
.. TODO::
227
228
p-adic heights
229
230
add heights to integer.pyx and remove special case
231
"""
232
if self.domain().base_ring() == ZZ:
233
if prec is None:
234
R = RealField()
235
else:
236
R = RealField(prec)
237
H=max([self[i].abs() for i in range(self.codomain().ambient_space().dimension_relative())])
238
return(R(max(H,1)).log())
239
if self.domain().base_ring() in _NumberFields or is_NumberFieldOrder(self.domain().base_ring()):
240
return(max([self[i].global_height(prec) for i in range(self.codomain().ambient_space().dimension_relative())]))
241
else:
242
raise NotImplementedError("Must be over a Numberfield or a Numberfield Order")
243
244
class SchemeMorphism_point_affine_field(SchemeMorphism_point_affine):
245
pass
246
247
class SchemeMorphism_point_affine_finite_field(SchemeMorphism_point_affine_field):
248
249
def __hash__(self):
250
r"""
251
Returns the integer hash of ``self``
252
253
OUTPUT:
254
255
- integer
256
257
EXAMPLES::
258
259
sage: P.<x,y,z>=AffineSpace(GF(5),3)
260
sage: hash(P(2,1,2))
261
57
262
263
::
264
265
sage: P.<x,y,z>=AffineSpace(GF(7),3)
266
sage: X=P.subscheme(x^2-y^2)
267
sage: hash(X(1,1,2))
268
106
269
270
::
271
272
sage: P.<x,y>=AffineSpace(GF(13),2)
273
sage: hash(P(3,4))
274
55
275
276
::
277
278
sage: P.<x,y>=AffineSpace(GF(13^3,'t'),2)
279
sage: hash(P(3,4))
280
8791
281
"""
282
p=self.codomain().base_ring().order()
283
N=self.codomain().ambient_space().dimension_relative()
284
return sum(hash(self[i])*p**i for i in range(N))
285
286
def orbit_structure(self,f):
287
r"""
288
Every points is preperiodic over a finite field. This funtion returns the pair `[m,n]` where `m` is the
289
preperiod and `n` the period of the point ``self`` by ``f``.
290
291
INPUT:
292
293
- ``P`` -- a point in ``self.domain()``
294
295
OUTPUT:
296
297
- a list `[m,n]` of integers
298
299
EXAMPLES::
300
301
sage: P.<x,y,z>=AffineSpace(GF(5),3)
302
sage: H=Hom(P,P)
303
sage: f=H([x^2+y^2,y^2,z^2+y*z])
304
sage: P(1,1,1).orbit_structure(f)
305
[0, 6]
306
307
::
308
309
sage: P.<x,y,z>=AffineSpace(GF(7),3)
310
sage: X=P.subscheme(x^2-y^2)
311
sage: H=Hom(X,X)
312
sage: f=H([x^2,y^2,z^2])
313
sage: X(1,1,2).orbit_structure(f)
314
[0, 2]
315
316
::
317
318
sage: P.<x,y>=AffineSpace(GF(13),2)
319
sage: H=Hom(P,P)
320
sage: f=H([x^2-y^2,y^2])
321
sage: P(3,4).orbit_structure(f)
322
[2, 6]
323
"""
324
Orbit=[]
325
index=1
326
P=copy(self)
327
F=copy(f)
328
while not P in Orbit:
329
Orbit.append(P)
330
P=F(P)
331
index+=1
332
I=Orbit.index(P)
333
return([I,index-I-1])
334
335
336