Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/schemes/generic/ambient_space.py
4091 views
1
"""
2
Ambient Spaces
3
"""
4
5
#*****************************************************************************
6
# Copyright (C) 2006 William Stein <[email protected]>
7
#
8
# Distributed under the terms of the GNU General Public License (GPL)
9
#
10
# http://www.gnu.org/licenses/
11
#*****************************************************************************
12
13
from sage.rings.all import Integer, is_CommutativeRing, ZZ
14
15
from sage.schemes.generic.scheme import Scheme
16
17
def is_AmbientSpace(x):
18
"""
19
Return True if `x` is an ambient space.
20
21
EXAMPLES::
22
23
sage: from sage.schemes.generic.ambient_space import is_AmbientSpace
24
sage: is_AmbientSpace(ProjectiveSpace(3, ZZ))
25
True
26
sage: is_AmbientSpace(AffineSpace(2, QQ))
27
True
28
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
29
sage: is_AmbientSpace(P.subscheme([x+y+z]))
30
False
31
"""
32
return isinstance(x, AmbientSpace)
33
34
class AmbientSpace(Scheme):
35
"""
36
Base class for ambient spaces over a ring.
37
38
INPUT:
39
40
41
- ``n`` - dimension
42
43
- ``R`` - ring
44
"""
45
def __init__(self, n, R=ZZ):
46
"""
47
TEST::
48
49
sage: from sage.schemes.generic.ambient_space import AmbientSpace
50
sage: A = AmbientSpace(5, ZZ)
51
sage: TestSuite(A).run() # not tested (abstract scheme with no elements?)
52
"""
53
if not is_CommutativeRing(R):
54
raise TypeError, "R (=%s) must be a commutative ring"%R
55
n = Integer(n)
56
if n < 0:
57
raise ValueError, "n (=%s) must be nonnegative"%n
58
self._dimension_relative = n
59
Scheme.__init__(self, R)
60
61
# NT: this seems to set improperly self._base_scheme to X instead of Spec(X)????
62
# scheme.Scheme.__init__(self, R)
63
# This should be cleaned up by someone who knows about schemes (not me!)
64
#from sage.categories.schemes import Schemes
65
#Parent.__init__(self, R, category = Schemes(self.base_scheme()))
66
67
#######################################################################
68
# Derived classes must overload all of the following functions
69
#######################################################################
70
def __cmp__(self, right):
71
"""
72
TEST::
73
74
sage: from sage.schemes.generic.ambient_space import AmbientSpace
75
sage: A = AmbientSpace(5, ZZ)
76
sage: A.__cmp__(ProjectiveSpace(2, QQ))
77
Traceback (most recent call last):
78
...
79
NotImplementedError
80
"""
81
raise NotImplementedError
82
83
def _latex_(self):
84
"""
85
TEST::
86
87
sage: from sage.schemes.generic.ambient_space import AmbientSpace
88
sage: A = AmbientSpace(5, ZZ)
89
sage: A._latex_()
90
Traceback (most recent call last):
91
...
92
NotImplementedError
93
"""
94
raise NotImplementedError
95
96
def _repr_(self):
97
"""
98
TEST::
99
100
sage: from sage.schemes.generic.ambient_space import AmbientSpace
101
sage: A = AmbientSpace(5, ZZ)
102
sage: A._repr_()
103
Traceback (most recent call last):
104
...
105
NotImplementedError
106
"""
107
raise NotImplementedError
108
109
def _repr_generic_point(self, coords=None):
110
"""
111
TEST::
112
113
sage: from sage.schemes.generic.ambient_space import AmbientSpace
114
sage: A = AmbientSpace(5, ZZ)
115
sage: A._repr_generic_point([1, 2, 3, 4, 5])
116
Traceback (most recent call last):
117
...
118
NotImplementedError
119
"""
120
raise NotImplementedError
121
122
def _latex_generic_point(self, coords=None):
123
"""
124
TEST::
125
126
sage: from sage.schemes.generic.ambient_space import AmbientSpace
127
sage: A = AmbientSpace(5, ZZ)
128
sage: A._latex_generic_point([1, 2, 3, 4, 5])
129
Traceback (most recent call last):
130
...
131
NotImplementedError
132
"""
133
raise NotImplementedError
134
135
def _check_satisfies_equations(self, v):
136
"""
137
Verify that the coordinates of v define a point on this scheme, or
138
raise a TypeError.
139
140
TEST::
141
142
sage: from sage.schemes.generic.ambient_space import AmbientSpace
143
sage: A = AmbientSpace(5, ZZ)
144
sage: A._check_satisfies_equations([1, 2, 3, 4, 5])
145
Traceback (most recent call last):
146
...
147
NotImplementedError
148
"""
149
raise NotImplementedError
150
151
def _validate(self, polynomials):
152
"""
153
If ``polynomials`` is a tuple of valid polynomial functions on self,
154
return ``polynomials``, otherwise raise TypeError.
155
156
INPUT:
157
158
- ``polynomials`` -- tuple of polynomials in the coordinate ring of
159
self
160
161
OUTPUT:
162
163
- tuple of polynomials in the coordinate ring of self
164
165
TESTS::
166
167
sage: from sage.schemes.generic.ambient_space import AmbientSpace
168
sage: A = AmbientSpace(3, ZZ)
169
sage: A._validate((x + 1, 1))
170
Traceback (most recent call last):
171
...
172
NotImplementedError: ambient spaces must override "_validate" method!
173
"""
174
raise NotImplementedError('ambient spaces must override "_validate" '
175
'method!')
176
177
def change_ring(self, R):
178
r"""
179
Return an ambient space over ring `R` and otherwise the same as self.
180
181
INPUT:
182
183
- ``R`` -- commutative ring
184
185
OUTPUT:
186
187
- ambient space over ``R``
188
189
.. NOTE::
190
191
There is no need to have any relation between `R` and the base ring
192
of self, if you want to have such a relation, use
193
``self.base_extend(R)`` instead.
194
195
TESTS::
196
197
sage: from sage.schemes.generic.ambient_space import AmbientSpace
198
sage: A = AmbientSpace(5)
199
sage: A.change_ring(QQ)
200
Traceback (most recent call last):
201
...
202
NotImplementedError: ambient spaces must override "change_ring" method!
203
"""
204
raise NotImplementedError(
205
'ambient spaces must override "change_ring" method!')
206
207
#######################################################################
208
# End overloads
209
#######################################################################
210
211
def is_projective(self):
212
"""
213
Return whether this ambient space is projective n-space.
214
215
EXAMPLES::
216
217
sage: AffineSpace(3,QQ).is_projective()
218
False
219
sage: ProjectiveSpace(3,QQ).is_projective()
220
True
221
"""
222
# overloaded in the projective space derived class
223
return False
224
225
def base_extend(self, R):
226
"""
227
Return the natural extension of ``self`` over ``R``.
228
229
INPUT:
230
231
- ``R`` -- a commutative ring, such that there is a natural map from
232
the base ring of self to ``R``.
233
234
OUTPUT:
235
236
- an ambient space over ``R`` of the same structure as ``self``.
237
238
.. NOTE::
239
240
A ``ValueError`` is raised if there is no such natural map. If
241
you need to drop this condition, use ``self.change_ring(R)``.
242
243
EXAMPLES::
244
245
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
246
sage: PQ = P.base_extend(QQ); PQ
247
Projective Space of dimension 2 over Rational Field
248
sage: PQ.base_extend(GF(5))
249
Traceback (most recent call last):
250
...
251
ValueError: no natural map from the base ring (=Rational Field)
252
to R (=Finite Field of size 5)!
253
"""
254
if is_CommutativeRing(R):
255
if self.base_ring() == R:
256
return self
257
if not R.has_coerce_map_from(self.base_ring()):
258
raise ValueError(
259
"no natural map from the base ring (=%s) to R (=%s)!"
260
% (self.base_ring(), R))
261
return self.change_ring(R)
262
else:
263
raise NotImplementedError(
264
"extension of spaces over %s to %s is not implemented!"
265
% (self.base_ring(), R))
266
267
def ambient_space(self):
268
"""
269
Return the ambient space of the scheme self, in this case self
270
itself.
271
272
EXAMPLES::
273
274
sage: P = ProjectiveSpace(4, ZZ)
275
sage: P.ambient_space() is P
276
True
277
278
sage: A = AffineSpace(2, GF(3))
279
sage: A.ambient_space()
280
Affine Space of dimension 2 over Finite Field of size 3
281
"""
282
return self
283
284
def defining_polynomials(self):
285
"""
286
Return the defining polynomials of the scheme self. Since
287
self is an ambient space, this is an empty list.
288
289
EXAMPLES::
290
291
sage: ProjectiveSpace(2, QQ).defining_polynomials()
292
()
293
sage: AffineSpace(0, ZZ).defining_polynomials()
294
()
295
"""
296
return ()
297
298
######################################################################
299
# Associated MPolynomial ring generators
300
######################################################################
301
302
def gen(self, n=0):
303
"""
304
Return the `n`-th generator of the coordinate ring of the
305
scheme self.
306
307
EXAMPLES::
308
309
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
310
sage: P.gen(1)
311
y
312
"""
313
return self.coordinate_ring().gen(n)
314
315
def gens(self):
316
"""
317
Return the generators of the coordinate ring of the scheme
318
self.
319
320
EXAMPLES::
321
322
sage: AffineSpace(0, QQ).gens()
323
()
324
325
sage: P.<x, y, z> = ProjectiveSpace(2, GF(5))
326
sage: P.gens()
327
(x, y, z)
328
"""
329
return self.coordinate_ring().gens()
330
331
def ngens(self):
332
"""
333
Return the number of generators of the coordinate ring of the
334
scheme self.
335
336
EXAMPLES::
337
338
sage: AffineSpace(0, QQ).ngens()
339
0
340
341
sage: ProjectiveSpace(50, ZZ).ngens()
342
51
343
"""
344
return len(self.gens())
345
346
## def assign_names(self, names=None):
347
## """
348
## EXAMPLES:
349
## sage: A = AffineSpace(2, QQ, 'ab'); A
350
## Affine Space of dimension 2 over Rational Field
351
## sage: A.coordinate_ring()
352
## Polynomial Ring in a, b over Rational Field
353
## sage: A._assign_names('xy'); A.coordinate_ring()
354
## Polynomial Ring in x, y over Rational Field
355
## """
356
## self.coordinate_ring()._assign_names(names)
357
358
def dimension_absolute(self):
359
"""
360
Return the absolute dimension of this scheme.
361
362
EXAMPLES::
363
364
sage: A2Q = AffineSpace(2, QQ)
365
sage: A2Q.dimension_absolute()
366
2
367
sage: A2Q.dimension()
368
2
369
sage: A2Z = AffineSpace(2, ZZ)
370
sage: A2Z.dimension_absolute()
371
3
372
sage: A2Z.dimension()
373
3
374
"""
375
base = self.base_scheme()
376
if base.is_noetherian():
377
return self.dimension_relative() + base.dimension()
378
raise NotImplementedError, "Cannot compute the dimension of this scheme."
379
380
dimension = dimension_absolute
381
382
def dimension_relative(self):
383
"""
384
Return the relative dimension of this scheme over its base.
385
386
EXAMPLES::
387
388
sage: A2Q = AffineSpace(2, QQ)
389
sage: A2Q.dimension_relative()
390
2
391
sage: A2Z = AffineSpace(2, ZZ)
392
sage: A2Z.dimension_relative()
393
2
394
"""
395
return self._dimension_relative
396
397