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