Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/schemes/generic/spec.py
4057 views
1
"""
2
Spectrum of a ring as affine scheme.
3
"""
4
5
#*******************************************************************************
6
# Copyright (C) 2006 William Stein
7
# Distributed under the terms of the GNU General Public License (GPL)
8
# http://www.gnu.org/licenses/
9
#*******************************************************************************
10
11
from sage.rings.commutative_ring import is_CommutativeRing
12
from sage.rings.integer_ring import ZZ
13
14
from sage.schemes.generic.scheme import AffineScheme
15
from sage.schemes.generic.point import SchemeTopologicalPoint_prime_ideal
16
17
18
def is_Spec(X):
19
"""
20
Test whether ``X`` is a Spec.
21
22
INPUT:
23
24
- ``X`` -- anything.
25
26
OUTPUT:
27
28
Boolean.
29
30
EXAMPLES::
31
32
sage: from sage.schemes.generic.spec import is_Spec
33
sage: is_Spec(QQ^3)
34
False
35
sage: X = Spec(QQ); X
36
Spectrum of Rational Field
37
sage: is_Spec(X)
38
True
39
"""
40
return isinstance(X, Spec)
41
42
class Spec(AffineScheme):
43
r"""
44
The spectrum of a commutative ring, as a scheme.
45
46
.. note::
47
48
Calling ``Spec(R)`` twice produces two distinct (but equal)
49
schemes, which is important for gluing to construct more
50
general schemes.
51
52
INPUT:
53
54
- ``R`` -- a commutative ring.
55
56
- ``S`` -- a commutative ring (optional, default:`\ZZ`). The base
57
ring.
58
59
EXAMPLES::
60
61
sage: Spec(QQ)
62
Spectrum of Rational Field
63
sage: Spec(PolynomialRing(QQ, 'x'))
64
Spectrum of Univariate Polynomial Ring in x over Rational Field
65
sage: Spec(PolynomialRing(QQ, 'x', 3))
66
Spectrum of Multivariate Polynomial Ring in x0, x1, x2 over Rational Field
67
sage: X = Spec(PolynomialRing(GF(49,'a'), 3, 'x')); X
68
Spectrum of Multivariate Polynomial Ring in x0, x1, x2 over Finite Field in a of size 7^2
69
sage: TestSuite(X).run(skip = ["_test_an_element", "_test_elements",
70
... "_test_some_elements"])
71
72
sage: A = Spec(ZZ); B = Spec(ZZ)
73
sage: A is B
74
False
75
sage: A == B
76
True
77
78
A ``TypeError`` is raised if the input is not a commutative ring::
79
80
sage: Spec(5)
81
Traceback (most recent call last):
82
...
83
TypeError: R (=5) must be a commutative ring
84
sage: Spec(FreeAlgebra(QQ,2, 'x'))
85
Traceback (most recent call last):
86
...
87
TypeError: R (=Free Algebra on 2 generators (x0, x1) over
88
Rational Field) must be a commutative ring
89
90
TESTS::
91
92
sage: X = Spec(ZZ)
93
sage: X
94
Spectrum of Integer Ring
95
sage: X.base_scheme()
96
Spectrum of Integer Ring
97
sage: X.base_ring()
98
Integer Ring
99
sage: X.dimension()
100
1
101
sage: Spec(QQ,QQ).base_scheme()
102
Spectrum of Rational Field
103
sage: Spec(RDF,QQ).base_scheme()
104
Spectrum of Rational Field
105
"""
106
def __init__(self, R, S=None):
107
"""
108
Construct the spectrum of the ring ``R``.
109
110
See :class:`Spec` for details.
111
112
EXAMPLES::
113
114
sage: Spec(ZZ)
115
Spectrum of Integer Ring
116
"""
117
if not is_CommutativeRing(R):
118
raise TypeError, "R (=%s) must be a commutative ring"%R
119
self.__R = R
120
if not S is None:
121
if not is_CommutativeRing(S):
122
raise TypeError, "S (=%s) must be a commutative ring"%S
123
try:
124
S.hom(R)
125
except TypeError:
126
raise ValueError, "There must be a natural map S --> R, but S = %s and R = %s"%(S,R)
127
AffineScheme.__init__(self, S)
128
129
def _cmp_(self, X):
130
"""
131
Compare ``self`` and ``X``.
132
133
Spec's are compared with self using comparison of the
134
underlying rings. If X is not a Spec, then the result is
135
platform-dependent (either self < X or X < self, but never
136
self == X).
137
138
INPUT:
139
140
- ``X`` -- anything.
141
142
OUTPUT:
143
144
``+1``, ``0``, or ``-1``.
145
146
EXAMPLES::
147
148
sage: Spec(QQ) == Spec(QQ)
149
True
150
sage: Spec(QQ) == Spec(ZZ)
151
False
152
sage: Spec(QQ) == 5
153
False
154
sage: Spec(GF(5)) < Spec(GF(7))
155
True
156
sage: Spec(GF(7)) < Spec(GF(5))
157
False
158
159
TESTS::
160
161
sage: Spec(QQ).__cmp__(Spec(ZZ))
162
1
163
"""
164
return cmp(self.__R, X.coordinate_ring())
165
166
def __hash__(self):
167
"""
168
Return the hash value.
169
170
OUTPUT:
171
172
A 32/64-bit hash value, depending on architecture.
173
174
TESTS::
175
176
sage: hash(Spec(ZZ))
177
-1667718069 # 32-bit
178
-5659298568736299957 # 64-bit
179
180
sage: hash(Spec(QQ['x','y','z']))
181
-804171295 # 32-bit
182
-4893002889606114847 # 64-bit
183
"""
184
# R is the only defining data, but we'd like to avoid collisions with it.
185
return hash("Spec") ^ hash(self.__R)
186
187
def _repr_(self):
188
"""
189
Return a string representation of ``self``.
190
191
OUTPUT:
192
193
String.
194
195
EXAMPLES::
196
197
sage: Spec(PolynomialRing(QQ, 3, 'x'))
198
Spectrum of Multivariate Polynomial Ring in x0, x1, x2 over Rational Field
199
200
TESTS::
201
202
sage: Spec(PolynomialRing(QQ, 3, 'x'))._repr_()
203
'Spectrum of Multivariate Polynomial Ring in x0, x1, x2 over Rational Field'
204
"""
205
return "Spectrum of %s"%self.__R
206
207
def _latex_(self):
208
"""
209
LaTeX representation of this Spec.
210
211
OUTPUT:
212
213
String.
214
215
EXAMPLES::
216
217
sage: S = Spec(PolynomialRing(ZZ, 2, 'x'))
218
sage: S
219
Spectrum of Multivariate Polynomial Ring in x0, x1 over Integer Ring
220
sage: S._latex_()
221
'\\mathrm{Spec}(\\Bold{Z}[x_{0}, x_{1}])'
222
"""
223
return "\\mathrm{Spec}(%s)" % self.__R._latex_()
224
225
def __call__(self, x):
226
"""
227
Call syntax for Spec.
228
229
INPUT:
230
231
- ``x`` -- a prime ideal of the coordinate ring, or an element
232
(or list of elements) of the coordinate ring which generates
233
a prime ideal.
234
235
OUTPUT:
236
237
A point of this Spec.
238
239
EXAMPLES::
240
241
sage: S = Spec(ZZ)
242
sage: P = S(3); P
243
Point on Spectrum of Integer Ring defined by the Principal ideal (3) of Integer Ring
244
sage: type(P)
245
<class 'sage.schemes.generic.point.SchemeTopologicalPoint_prime_ideal'>
246
sage: S(ZZ.ideal(next_prime(1000000)))
247
Point on Spectrum of Integer Ring defined by the Principal ideal (1000003) of Integer Ring
248
249
sage: R.<x, y, z> = QQ[]
250
sage: S = Spec(R)
251
sage: P = S(R.ideal(x, y, z)); P
252
Point on Spectrum of Multivariate Polynomial Ring
253
in x, y, z over Rational Field defined by the Ideal (x, y, z)
254
of Multivariate Polynomial Ring in x, y, z over Rational Field
255
"""
256
return SchemeTopologicalPoint_prime_ideal(self, x)
257
258
def _an_element_(self):
259
r"""
260
Return an element of the spectrum of the ring.
261
262
OUTPUT:
263
264
A point of the affine scheme ``self``.
265
266
EXAMPLES::
267
268
sage: Spec(QQ).an_element()
269
Point on Spectrum of Rational Field defined by the Principal ideal (0) of Rational Field
270
sage: Spec(ZZ).an_element() # random output
271
Point on Spectrum of Integer Ring defined by the Principal ideal (811) of Integer Ring
272
"""
273
if self.coordinate_ring() is ZZ:
274
from sage.rings.arith import random_prime
275
return self(random_prime(1000))
276
return self(0)
277
278
def coordinate_ring(self):
279
"""
280
Return the underlying ring of this scheme.
281
282
OUTPUT:
283
284
A commutative ring.
285
286
EXAMPLES::
287
288
sage: Spec(QQ).coordinate_ring()
289
Rational Field
290
sage: Spec(PolynomialRing(QQ, 3, 'x')).coordinate_ring()
291
Multivariate Polynomial Ring in x0, x1, x2 over Rational Field
292
"""
293
return self.__R
294
295
def is_noetherian(self):
296
"""
297
Test whether ``self`` is Noetherian.
298
299
OUTPUT:
300
301
Boolean. Return True if this scheme is Noetherian.
302
303
EXAMPLES::
304
305
sage: Spec(ZZ).is_noetherian()
306
True
307
"""
308
return self.__R.is_noetherian()
309
310
def dimension_absolute(self):
311
"""
312
Return the absolute dimension of this scheme.
313
314
OUTPUT:
315
316
Integer.
317
318
EXAMPLES::
319
320
sage: S = Spec(ZZ)
321
sage: S.dimension_absolute()
322
1
323
sage: S.dimension()
324
1
325
"""
326
return self.__R.krull_dimension()
327
328
dimension = dimension_absolute
329
330
def dimension_relative(self):
331
"""
332
Return the relative dimension of this scheme over its base.
333
334
OUTPUT:
335
336
Integer.
337
338
EXAMPLES::
339
340
sage: S = Spec(ZZ)
341
sage: S.dimension_relative()
342
0
343
"""
344
return self.__R.krull_dimension() - self.base_ring().krull_dimension()
345
346
def base_extend(self, R):
347
"""
348
Extend the base ring/scheme.
349
350
INPUT:
351
352
- ``R`` -- an affine scheme or a commutative ring.
353
354
EXAMPLES::
355
356
sage: Spec_ZZ = Spec(ZZ); Spec_ZZ
357
Spectrum of Integer Ring
358
sage: Spec_ZZ.base_extend(QQ)
359
Spectrum of Rational Field
360
"""
361
if is_CommutativeRing(R):
362
return Spec(self.coordinate_ring().base_extend(R), self.base_ring())
363
if not self.base_scheme() == R.base_scheme():
364
raise ValueError('The new base scheme must be a scheme over the old base scheme.')
365
return Spec(self.coordinate_ring().base_extend(new_base.coordinate_ring()),
366
self.base_ring())
367
368
def _point_homset(self, *args, **kwds):
369
"""
370
Construct a point Hom-set.
371
372
For internal use only. See :mod:`morphism` for more details.
373
374
EXAMPLES::
375
376
sage: Spec(QQ)._point_homset(Spec(QQ), Spec(ZZ))
377
Set of rational points of Spectrum of Integer Ring
378
"""
379
from sage.schemes.generic.homset import SchemeHomset_points_spec
380
return SchemeHomset_points_spec(*args, **kwds)
381
382
383
SpecZ = Spec(ZZ)
384
385